import java.io.*;
public class g {
public static void main(String args[]) throws IOException{
int num[]=new int[4];
int flag1=0,flag2=0,i,j;
int rnum[]=new int[4];
int A=0,B=0;
int MAX=9;
String result="";
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int f=0;
int a=0,b=0,c=0,d=0;
a=(int)(Math.random()*10);
while(f!=1){
b=(int)(Math.random()*10);
if(a!=b){f=1;}
}
f=0;
while(f!=1){
c=(int)(Math.random()*10);
if(c!=a&&c!=b){f=1;}
}
f=0;
while(f!=1){
d=(int)(Math.random()*10);
if(d!=a&&d!=b&&d!=c){f=1;}
}
num[0]=a;
num[1]=b;
num[2]=c;
num[3]=d;
for(i=0;i<4;i++){
result+=num[i];
}
System.out.println("Please input your numbers:");
while(flag1<=MAX){
String s = br.readLine();
int snum=Integer.parseInt(s);
rnum[0]=snum/1000;
rnum[1]=(snum-rnum[0]*1000)/100;
rnum[2]=(snum-rnum[0]*1000-rnum[1]*100)/10;
rnum[3]=snum-rnum[0]*1000-rnum[1]*100-rnum[2]*10;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(rnum[i]==num[i]) {A++;break;}
if(rnum[i]==num[j]) {B++;break;}
}
}
if(A==4) {flag2=1;flag1=MAX+1;System.out.println("Succeed!Number is:"+result);break;}
System.out.println("A:"+A+" B:"+B);
flag1++;
A=B=0;
}
if(flag2==0){System.out.print("Failed! Number is:"+result);}
}
}