PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000343. Lật thẻ để các số đôi một nguyên tố cùng nhau (Coprime Solitaire)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Lật thẻ để các số đôi một nguyên tố cùng nhau (Coprime Solitaire)

Coprime Solitaire

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN cards. Card ii has AiA_i on its front and BiB_i on its back; initially every card is face up.

You may flip any subset of the cards, including none. Each card then displays exactly one of its two values.

Determine whether the displayed numbers can be made pairwise coprime: for every 1≤i<j≤N1\le i<j\le N, the chosen values Ci,CjC_i,C_j must satisfy gcd⁡(Ci,Cj)=1\gcd(C_i,C_j)=1.

Input

The first line contains NN, followed by NN lines each with Ai,BiA_i,B_i.

Output

Print Yes if a valid selection exists; otherwise print No.

Subtasks

  • Subtask 1 (20 points): 1≤N≤101\le N\le 10, 1≤Ai,Bi≤1001\le A_i,B_i\le100.
  • Subtask 2 (30 points): 1≤N≤5001\le N\le 500, 1≤Ai,Bi≤1041\le A_i,B_i\le 10^4.
  • Subtask 3 (50 points): 1≤N≤3⋅1041\le N\le 3\cdot10^4, 1≤Ai,Bi≤2⋅1061\le A_i,B_i\le 2\cdot10^6.

Examples

Example 1

Input

3
2 5
10 9
4 8

Output

Yes

Explanation

Flip cards 1 and 2, leaving card 3 unchanged. The displayed numbers (5,9,4)(5,9,4) have pairwise GCD equal to 1.

Example 2

Input

2
10 100
1000 10000

Output

No

Explanation

Every face value is divisible by 10, so any two chosen values have GCD at least 10.