N=int(input()) S=input() T=input() firstBC=0 ab=0 bc=0 for i in range(N): if S[i]=='A' and T[i]=='B': ab+=1 elif S[i]=='B' and T[i]=='C': firstBC+=1 bc+=1 elif S[i]=='A' and T[i]=='C': ab+=1 bc+=1 elif S[i]!=T[i]: print('No') exit(0) if (ab==bc and firstBC>0) or ab==bc==0: print('Yes') else: print('No')