## Algorithm

B. Weakened Common Divisor
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.

For a given list of pairs of integers (a1,b1)(�1,�1)(a2,b2)(�2,�2), ..., (an,bn)(��,��) their WCD is arbitrary integer greater than 11, such that it divides at least one element in each pair. WCD may not exist for some lists.

For example, if the list looks like [(12,15),(25,18),(10,24)][(12,15),(25,18),(10,24)], then their WCD can be equal to 223355 or 66 (each of these numbers is strictly greater than 11 and divides at least one number in each pair).

You're currently pursuing your PhD degree under Ildar's mentorship, and that's why this problem was delegated to you. Your task is to calculate WCD efficiently.

Input

The first line contains a single integer n (1n1500001≤�≤150000) — the number of pairs.

Each of the next n lines contains two integer values ai��bi�� (2ai,bi21092≤��,��≤2⋅109).

Output

Print a single integer — the WCD of the set of pairs.

If there are multiple possible answers, output any; if there is no answer, print 1−1.

Examples
input
Copy
317 1815 2412 15
output
Copy
6
input
Copy
210 167 17
output
Copy
-1
input
Copy
590 10845 10575 40165 17533 30
output
Copy
5
Note

In the first example the answer is 66 since it divides 1818 from the first pair, 2424 from the second and 1212 from the third ones. Note that other valid answers will also be accepted.

In the second example there are no integers greater than 11 satisfying the conditions.

In the third example one of the possible answers is 55. Note that, for example, 1515 is also allowed, but it's not necessary to maximize the output.

## Code Examples

### #1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int const N = 2e5 + 1;
int n;
pair<int, int> a[N];
vector<int> d;
set<int> st;

void calc_div(int x) {
d.clear();
int sqrtx = sqrt(x) + 1;
for(int i = 1; i <= sqrtx; ++i) {
if(x % i == 0) {
d.push_back(i);

if(x / i != i)
d.push_back(x / i);
}
}
}

void solve() {
for(int i = 0, cur, dd; i < d.size(); ++i) {
if(d[i] == 1)
continue;
cur = 0;
dd = d[i];

if(st.count(dd) == 1)
continue;
st.insert(dd);

for(int j = 1; j < n; ++j)
if(a[j].first % dd == 0 || a[j].second % dd == 0)
++cur;
else
break;

if(cur == n - 1) {
printf("%d\n", dd);
exit(0);
}
}
}

int main() {
scanf("%d", &n);
for(int i = 0; i < n; ++i)
scanf("%d %d", &a[i].first, &a[i].second);

sort(a, a + n);
reverse(a, a + n);

calc_div(a[0].first);
solve();

calc_div(a[0].second);
solve();

puts("-1");

return 0;
}
Copy The Code &

Input

cmd
3
17 18
15 24
12 15

Output

cmd
6