#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;

int main() {
    int n = 0, x = 0, y = 0, z = 0;
    int i, j, ci, cj;
    int value = 0, max = 0;
    while (scanf("%d %d %d %d", &n, &x, &y, &z) != EOF) {
        for (i = 1; i <= 9; ++i) {
            for (j = 0; j <= 9; ++j) {
                value = i * 10000 + x * 1000 + y * 100 + z * 10 + j;
                if (value % n == 0) {
                    ci = i;
                    cj = j;
                    if (value > max) {
                        max = value;
                    }
                }
            }
        }
        if (max == 0 || max % n != 0) {
            printf("0\n");
        } else {
            printf("%d %d %d", ci, cj, max / n);
        }
    }
    return 0;
}
// 64 位输出请用 printf("%lld")