#include <iostream> #include <algorithm> #include <cstdio> #include <string> using namespace std; int n, x, y, z; int main() { cin >> n >> x >> y >> z; int fir = 1, las = 0; int ma = 0, count = 0; for (int i = 1; i < 10; i++) { for (int j = 0; j < 10; j++) { if ((i * 10000 + x * 1000 + y * 100 + z * 10 + j) % n == 0){ count++; if((i * 10000 + x * 1000 + y * 100 + z * 10 + j) > ma) { ma = i * 10000 + x * 1000 + y * 100 + z * 10 + j; fir = i; las = j; } } } } if (count > 0) cout << fir << " " << las << " " << ma / n << endl; else cout << 0 << endl; return 0; }