N = int(input()) S = input() T = input() ans = 'Yes' B = [] C = [] for i in range(N): if S[i] == T[i]: continue if T[i] == 'A': ans = 'No' elif T[i] == 'B': if S[i] == 'A': B.append((0,i)) else: ans = 'No' else: if S[i] == 'A': B.append((1,i)) else: C.append(i) while len(B) and len(C): f,i = B.pop() j = C.pop() if f: C.append(i) if len(B): ans = 'No' if len(C): ans = 'No' print(ans)