Hide

Problem C
Playing with Numbers

You have a list of N numbers, each of the form 2a3b for some non-negative integers a and b. You want to perform N1 operations on these numbers. Each operation acts on two numbers X and Y of your choice from the list, replacing them with a new number op(X,Y). After each operation, your list has one fewer number.

In this task, an operation op can be gcd or lcm (they stand for greatest common divisor and least common multiple, respectively). There are a total of N scenarios: You may apply “gcd” operations k times and “lcm” operations N1k times. For each of the N scenarios, what is the largest possible outcome after these N1 operations? What about the smallest possible outcome?

Input

The first line consists of a single integer N (1N50000). The following N lines each contains a pair of integers ai and bi (0ai,bi1000), indicating that the ith number in your initial list is 2ai3bi.

Output

Output N lines in total. On line i (i=1,,N), output four space-separated integers a,b,a and b. The first pair of integers a and b indicate that the largest possible outcome is 2a3b with i1gcd” operations (and therefore Nilcm” operations). The second pair of integers a and b indicate that the smallest possible outcome is 2a3b, again with i1gcd” operations.

Explanation for sample data

The three numbers are 2030=1, 2132=18, and 2230=4.

  1. When i=0, we can only take lcm. lcm(1,18,4)=36=2232.

  2. When i=1, the largest outcome is lcm(18,gcd(1,4))=18=2132, and the smallest outcome is gcd(1,lcm(18,4))=1=2030.

  3. When i=2, we can only take gcd. gcd(1,18,4)=1=2030.

Sample Input 1 Sample Output 1
3
0 0
1 2
2 0
2 2 2 2
1 2 0 0
0 0 0 0
Hide

Please log in to submit a solution to this problem

Log in