/*
习题2-3 Old Bill(上海交通大学复试上机题)
题目描述:
输入:
输出:
分析:如何输入换行的数据
提交网址:http://t.cn/E9jqijR
*/
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
    int n, x, y, z;
    while (cin >> n >> x >> y >> z) {
        int total, i, j;
        for (i = 9; i != 0; --i) {
            total = 10000 * i + 1000 * x + 100 * y + 10 * z + 10;
            for (j = 9; j != -1; --j) {
                if ((--total) % n == 0) {
                    cout << i << ' ' << j << ' ' << total / n << endl;
                    break;
                }
            }
            if (j != -1)
                break;
        }
        if (i == 0)
            cout << 0 << endl;
    }
    return 0;
}