n = int(input()) S = input() T = input() f = False ab = 0 bc = 0 for s, t in zip(S, T): if s == "A" and t == "B": ab += 1 elif s == "B" and t == "C": bc += 1 f = True elif s == "A" and t == "C": ab += 1 bc += 1 elif s != t: print("No") exit() if (f or ab == 0) and ab == bc: print("Yes") else: print("No")