n = int(input()) s = input() t = input() ok = True ab = 0 bc = 0 ac = 0 for i in range(n): if s[i] == t[i]: continue elif s[i] == "A" and t[i] == "B": ab += 1 elif s[i] == "B" and t[i] == "C": bc += 1 elif s[i] == "A" and t[i] == "C": ac += 1 else: ok = False if ok: if ab == 0 and bc == 0 and ac == 0: print("Yes") elif ab*bc == 0 or ab != bc: print("No") else: print("Yes") else: print("No")