#include <iostream>
#include <cstdio>

using namespace std;

void bill(int n,int x,int y,int z)
{
    int test;
     int c=0;
    for(int a=9; a>0; --a)
    {
        for(int b=9; b>-1; --b)
        {
            test = (a*10000+x*1000+y*100+z*10+b)%n;


            if (test==0)
            {

                c=(a*10000+x*1000+y*100+z*10+b)/n;

                printf("%d %d %d\n",a,b,c);
                return;
            }

        }
    }
    if (c==0){
        printf("0\n");
        return;
    }
}


int main()
{
    int n,x,y,z;
    while(scanf("%d %d %d %d",&n,&x,&y,&z)!=EOF)
    {
        bill(n,x,y,z);
    }
}