#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int n, x, y, z;
    while (scanf("%d%d%d%d", &n, &x, &y, &z) != EOF) {
        bool isOutput = false;
        for (int i = 9; i > 0; i--) {
            for (int j = 9; j >= 0; j--) {
                if ((i * 10000 + x * 1000 + y * 100 + z * 10 + j) % n == 0) {
                    isOutput = true;
                    printf("%d %d %d", i, j, (i * 10000 + x * 1000 + y * 100 + z * 10 + j) / n);
                    break;
                }
            }
            if (isOutput) {
                break;
            }
        }
        if (!isOutput) {
            printf("0");
        }
    }
    return 0;
//    sort(arr,arr+i,compare);
}