You have a list of
numbers, each of the form for some non-negative integers and . You want to perform operations on these numbers.
Each operation acts on two numbers and of your choice from the list,
replacing them with a new number . After each
operation, your list has one fewer number.
In this task, an operation can be or (they stand for
greatest common divisor and least common multiple,
respectively). There are a total of scenarios: You may apply
“” operations
times and
“”
operations
times. For each of the
scenarios, what is the largest possible outcome after these
operations? What
about the smallest possible outcome?
Input
The first line consists of a single integer (). The following lines each contains a pair of
integers and
(),
indicating that the th
number in your initial list is .
Output
Output lines in
total. On line
(),
output four space-separated integers and . The first pair of integers
and indicate that the largest possible
outcome is with
“” operations (and therefore
“” operations). The
second pair of integers and indicate that the smallest
possible outcome is , again with
“” operations.
Explanation for sample data
The three numbers are , , and .
-
When , we
can only take . .
-
When , the
largest outcome is , and the smallest outcome is .
-
When , we
can only take .
.
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
|