#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int turn(int x){
if(x==6) return 9;
if(x==9) return 6;
return x;
}
int a[7]={0,1,2,5,6,8,9};
int main(){
for(int i=1;i<7;i++){
for(int j=0;j<7;j++){
for(int k=0;k<7;k++){
for(int l=1;l<7;l++){
int tmp = a[i]*1000+a[j]*100+a[k]*10+a[l];
int rmp = turn(a[l])*1000+turn(a[k])*100+turn(a[j])*10+turn(a[i]);
if(tmp-rmp>200 && tmp-rmp<300){
for(int i=1;i<7;i++)
for(int j=0;j<7;j++)
for(int k=0;k<7;k++)
for(int l=1;l<7;l++){
int tmp1 = a[i]*1000+a[j]*100+a[k]*10+a[l];
int rmp1 = turn(a[l])*1000+turn(a[k])*100+turn(a[j])*10+turn(a[i]);
if(rmp1-tmp1>800 && rmp1-tmp1<900 && (rmp+rmp1)-(tmp+tmp1)==558){
cout<<tmp<<" "<<rmp<<endl;
cout<<tmp1<<" "<<rmp1<<endl;
return 0;
}
}
}
}
}
}
}
}