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

#GL0000136. Hai ước số (Two Divisors)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Hai ước số (Two Divisors)

Two Divisors

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

You are given an array of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n. For each aia_i, find two divisors d1,i>1d_{1,i}>1 and d2,i>1d_{2,i}>1 of aia_i such that

gcd⁡(d1,i+d2,i,ai)=1.\gcd(d_{1,i}+d_{2,i},a_i)=1.

Either valid pair is acceptable. If no valid pair exists for aia_i, place −1-1 at the corresponding position in both output rows. Each element is considered independently; the two divisors need not be distinct.

Input

The first line contains nn. The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print two lines of nn integers each. Their ii-th values are d1,id_{1,i} and d2,id_{2,i} respectively, or −1-1 on both lines if no pair exists.

Subtasks

  • Subtask 1 (20 points): 1≤n≤301\le n\le 30; 2≤ai≤1 0002\le a_i\le 1\,000.
  • Subtask 2 (30 points): 1≤n≤5 0001\le n\le 5\,000; 2≤ai≤1 000 0002\le a_i\le 1\,000\,000.
  • Subtask 3 (50 points): 1≤n≤500 0001\le n\le 500\,000; 2≤ai≤10 000 0002\le a_i\le 10\,000\,000.

Examples

Input

6
2 6 10 8 24 72

Output

-1 2 2 -1 8 8
-1 3 5 -1 3 9

Explanation

For 66, the pair (2,3)(2,3) gives gcd⁡(5,6)=1\gcd(5,6)=1; for 1010, (2,5)(2,5) gives gcd⁡(7,10)=1\gcd(7,10)=1. The displayed choices for 2424 and 7272 also satisfy the condition. The numbers 22 and 88 have only one distinct prime factor, so no pair exists.