def decompose_to_single(S): #(A|B)(C|D)->[(A|B),(C|D)] ret=[] pre=0 depth=0 for i,c in enumerate(S): if c=="(": depth+=1 if c==")": depth-=1 if depth==0: ret.append(S[pre:i+1]) pre=i+1 return ret def split(S): #(A|B)->[A,B] depth=0 for i,c in enumerate(S): if c=="(": depth+=1 if c==")": depth-=1 if depth==1 and c=="|": return (S[1:i],S[i+1:-1]) pre=i def cmp_single(S,T,cmp): #return S<=>T if S=="": if T=="": return 0 return -1 if T=="": return 1 SL,SR=split(S) TL,TR=split(T) flag=cmp(SL,TL) if flag==-1: return cmp(SR,T) if flag==1: return cmp(S,TR) return cmp(SR,TR) def normalize(S_list): ret=[] for s in S_list: while ret and cmp_single(ret[-1],s,cmp)==-1: ret.pop() ret.append(s) return ret def cmp(S,T): #return S<=>T S_list=normalize(decompose_to_single(S)) T_list=normalize(decompose_to_single(T)) for s,t in zip(S_list,T_list): ret=cmp_single(s,t,cmp) if ret: return ret if len(S_list)len(T_list): return 1 return 0 S=input() T=input() print(0 if cmp(S,T)>0 else 1)