#include<iostream>
using namespace std;

int main(void) {
    int n;
    while (cin >> n) {
        int x, y, z;
        cin >> x >> y >> z;
        bool flag = true;
        for (int i = 9; i >= 1; i--) {
            for (int j = 9; j >= 0; j--) {
                int ans = i * 10000 + x * 1000 + y * 100 + z * 10 + j;
                if (ans / n * n == ans) {
                    flag = false;
                    cout << i << ' ' << j << ' ' << ans / n << endl;
                    break;
                }
            }
            if (!flag) break;
        }
        if (flag)    cout << 0 << endl;
    }
    return 0;
}