import sys input = sys.stdin.readline from collections import defaultdict,deque,Counter N=int(input()) S=input().strip() T=input().strip() cnt = Counter([s+t for s,t in zip(S,T) if s!=t]) def solve(cnt): # (B,A) (C,A) があったらNo if "BA" in cnt or "CA" in cnt or "CB" in cnt: return False # (A,C), (B,C) -> (B,C),(C,C) if cnt["AC"]>0 and cnt["BC"]==0: return False n = cnt["AC"] cnt[""] # (A,B),(B,C) -> (B,B),(C,C) return cnt["AB"]==cnt["BC"] print("Yes" if solve(cnt) else "No")