import sys import time f1=open('in.txt','r') f2=open('out.txt','w') a=[] for i in range(0,6): a.append(f1.readline().split(" ")) print a mark=[0]*len(a) mark[4]=1 stack=[] stack.append(4) r=len(a) c=len(a) i=4 j=0 x=0 ans=[4] while len(stack) != 0: for j in range(0,c): if ( len(stack)==0): break if (mark.count(1)== r): x=1 break if(mark[j]==1 ): continue if(int(a[i][j])==1): mark[j]=1 stack.append(j) ans.append(j) i=j break if(j==r-1): stack.pop() print len(stack) i=stack[len(stack)-1] break if(x==1): break res='' for i in range (0, 6): if ans[i]==0: res=res+"A " elif ans[i]==1: res=res+"B " elif ans[i]==2: res=res+"C " elif ans[i]==3: res=res+"D " elif ans[i]==4: res=res+"E " elif ans[i]==5: res=res+"F" f2.write(res) f1.close() f2.close()