#include <iostream>

using namespace std;

int w[] = {0,1,2,5,6,8,9};

int t(int x)
{
     if(x==6)
        return 9;
     else
     if(x== 9)
         return 6;
     else
        return x;
}
void f(int x,int p)
{ 

   for(int a = 1; a <= 6; a ++)
     for(int b = 0; b <= 6; b ++)
       for(int c = 0; c <= 6; c++)
         for(int d = 1; d <= 6; d++)
         {
                 int y = t(w[d])*1000+t(w[c])*100+t(w[b])*10+t(w[a])-(w[a]*1000+w[b]*100+w[c]*10+w[d]);
                 if((y > 800 && y < 900) && (y - x == 558))
                    cout << x << ' ' << y << ' ' << p << ' ' <<  w[a]*1000+w[b]*100+w[c]*10+w[d] << endl;
                    
         }
}                    
                  
int main()
{
    for(int a = 1; a <= 6; a ++)
     for(int b = 0; b <= 6; b ++)
       for(int c = 0; c <= 6; c++)
         for(int d = 1; d <= 6; d++)
           {
                 int x = w[a]*1000+w[b]*100+w[c]*10+w[d]-t(w[d])*1000-t(w[c])*100-t(w[b])*10-t(w[a]);
                 if(x > 200&&x < 300)
                   f(x,w[a]*1000+w[b]*100+w[c]*10+w[d]);
                   }
                   system("pause"); 
                   return 0;
                   }