#include <iostream>
using namespace std;
int main() {
int n, a, b, c;
while (cin >> n >> a >> b >> c) { // ← 读到 EOF 会直接跳出
long long best_price = -1;
int best_i = -1, best_j = -1;
for (int i = 1; i <= 9; ++i) {
for (int j = 0; j <= 9; ++j) {
long long total = 1LL*i*10000 + a*1000 + b*100 + c*10 + j;
if (total % n == 0) {
long long price = total / n;
if (price > best_price) {
best_price = price;
best_i = i;
best_j = j;
}
}
}
}
if (best_price == -1) // 无解
cout << "0\n";
else // 输出最贵方案
cout << best_i << ' ' << best_j << ' ' << best_price << '\n';
}
return 0;
}