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

#GL0000092. Tối đa hóa BCNN của hai ƯCLN (LCM of GCDs)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tối đa hóa BCNN của hai ƯCLN (LCM of GCDs)

LCM of GCDs

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN packs, each containing two cards labeled aia_i and bib_i. Two bags, red and blue, are initially empty. For each pack, place exactly one card into the red bag and the other into the blue bag. After processing all packs, let XX be the GCD of the NN numbers in the red bag and YY the GCD of the NN numbers in the blue bag. The score is lcm⁡(X,Y)\operatorname{lcm}(X,Y). Find the maximum possible score.

Input

The first line contains NN, followed by NN lines; line ii contains ai,bia_i,b_i.

Output

Print the maximum achievable score.

Subtasks

  • Subtask 1 (20 points): 1≤N≤81\le N\le8; 1≤ai,bi≤1001\le a_i,b_i\le100.
  • Subtask 2 (30 points): 1≤N≤251\le N\le25; 1≤ai,bi≤1051\le a_i,b_i\le10^5.
  • Subtask 3 (50 points): 1≤N≤501\le N\le50; 1≤ai,bi≤1091\le a_i,b_i\le10^9.

Examples

Input

2
2 15
10 6

Output

10

Explanation

Put 22 and 66 into the red bag, and 1515 and 1010 into the blue bag. Then X=gcd⁡(2,6)=2X=\gcd(2,6)=2, Y=gcd⁡(15,10)=5Y=\gcd(15,10)=5, so the score is lcm⁡(2,5)=10\operatorname{lcm}(2,5)=10, which is optimal.