import sys input = sys.stdin.readline import math N=int(input()) AB=[tuple(map(int,input().split())) for i in range(N)] x=10**6+10 L=math.floor(math.sqrt(x)) # 平方根を求める Primelist=[i for i in range(x+1)] Primelist[1]=0 # 1は素数でないので0にする. for i in Primelist: if i>L: break if i==0: continue for j in range(2*i,x+1,i): Primelist[j]=0 Primes=[Primelist[j] for j in range(x+1) if Primelist[j]!=0] Primes=set(Primes) EDGE=[[] for i in range(2*N)] EDGE_INV=[[] for i in range(2*N)] # 0...N-1: x # N...2N-1: ¬x for i in range(N): a,b=AB[i] for j in range(N): c,d=AB[j] if int(str(a)+str(c)) in Primes: # ¬(x ⋀ y) EDGE[i].append(j) EDGE[j].append(i) EDGE_INV[j].append(i) EDGE_INV[i].append(j) if int(str(a)+str(d)) in Primes: # ¬(x ⋀ ¬y) EDGE[i].append(j+N) EDGE[j+N].append(i) EDGE_INV[j+N].append(i) EDGE_INV[i].append(j+N) if int(str(b)+str(c)) in Primes: # ¬(¬x ⋀ y) EDGE[i+N].append(j) EDGE[j].append(i+N) EDGE_INV[j].append(i+N) EDGE_INV[i+N].append(j) if int(str(b)+str(d)) in Primes: # ¬(¬x ⋀ ¬y) EDGE[i+N].append(j+N) EDGE[j+N].append(i+N) EDGE_INV[j+N].append(i+N) EDGE_INV[i+N].append(j+N) QUE = list(range(2*N)) check=[0]*(2*N) TOP_SORT=[] def dfs(x): if check[x]==1: return check[x]=1 for to in EDGE[x]: if check[to]==0: dfs(to) TOP_SORT.append(x) # 全ての点からDFSを行い, 帰りがけに点を答えに入れる check[x]=1 while QUE: x=QUE.pop() dfs(x) USE=[0]*(2*N) SCC=[] def dfs2(x): Q=[x] USE[x]=1 ANS=[] while Q: x=Q.pop() ANS.append(x) for to in EDGE_INV[x]: if USE[to]==0: USE[to]=1 Q.append(to) return ANS for x in TOP_SORT[::-1]: if USE[x]==0: SCC.append(dfs2(x)) for scc in SCC: SET=set(scc) for x in scc: if x+N in SET or x-N in SET: print("No") exit() print("Yes")