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 if f and ab == bc: print("Yes") else: print("No")