G - Tuning Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MiB

配点 : 600 点

問題文

長さ N の整数列 A=(A_1,A_2,\dots,A_N), B=(B_1,B_2,\dots,B_N) が与えられます。
長さ N の 有理数 の列 c=(c_1,c_2,\dots,c_N), d=(d_1,d_2,\dots,d_N) であって、以下の条件を満たすものを考えます。

  • 全ての 1 \le i,j \le N について、 (A_i+c_i)(B_j+d_j)=(A_j+c_j)(B_i+d_i)

\displaystyle \sum_{i=1}^{N} \left ( |c_i|+|d_i| \right ) としてありうる最小値を求めてください。

本問題の答えは、分母が正・分子が非負である既約分数 p/q としてただ一通りに表現できることが証明できます。
この p,q を出力してください。

制約

  • 入力は全て整数
  • 2 \le N \le 2 \times 10^5
  • |A_i|, |B_i| \le 10^6

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N

出力

本問題の答えが、分母が正・分子が非負である既約分数 p/q として表現されるとき、以下の形式で出力せよ。

p q

入力例 1

3
4 1 -8
3 1 -6

出力例 1

1 4

例えば、 c=(0,0,0),d=(0,-\frac{1}{4},0) とすることができ、 \sum_{i=1}^{N} \left ( |c_i|+|d_i| \right ) = \frac{1}{4} を達成します。
また、これより \sum_{i=1}^{N} \left ( |c_i|+|d_i| \right ) を小さくすることはできません。


入力例 2

2
2 2
3 3

出力例 2

0 1

答えが 0 である場合は 0/1 と表現されるため、 0 1 と出力してください。


入力例 3

10
855263 -919070 120736 -779959 -789624 789495 -541451 139160 -406547 32421
-612084 -707431 843213 834659 -424146 549941 -799392 -553082 732456 357127

出力例 3

635454493436 120459

Score : 600 points

Problem Statement

You are given length-N integer sequences A=(A_1,A_2,\dots,A_N) and B=(B_1,B_2,\dots,B_N).
Consider length-N sequences of rational numbers c=(c_1,c_2,\dots,c_N) and d=(d_1,d_2,\dots,d_N) that satisfy the following condition.

  • (A_i+c_i)(B_j+d_j)=(A_j+c_j)(B_i+d_i) for all 1 \le i,j \le N.

Find the minimum possible value of \displaystyle \sum_{i=1}^{N} \left ( |c_i|+|d_i| \right ).

It can be proved that the answer to this problem can be uniquely represented as an irreducible fraction p/q with a positive denominator and a non-negative numerator.
Output these p and q.

Constraints

  • All input values are integers.
  • 2 \le N \le 2 \times 10^5
  • |A_i|, |B_i| \le 10^6

Input

The input is given from Standard Input in the following format:

N
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N

Output

When the answer to this problem is represented as an irreducible fraction p/q with a positive denominator and a non-negative numerator, output it in the following format:

p q

Sample Input 1

3
4 1 -8
3 1 -6

Sample Output 1

1 4

For example, you can set c=(0,0,0),d=(0,-\frac{1}{4},0), which achieves \sum_{i=1}^{N} \left ( |c_i|+|d_i| \right ) = \frac{1}{4}.
Also, \sum_{i=1}^{N} \left ( |c_i|+|d_i| \right ) cannot be made smaller than this.


Sample Input 2

2
2 2
3 3

Sample Output 2

0 1

If the answer is 0, it is represented as 0/1, so output 0 1.


Sample Input 3

10
855263 -919070 120736 -779959 -789624 789495 -541451 139160 -406547 32421
-612084 -707431 843213 834659 -424146 549941 -799392 -553082 732456 357127

Sample Output 3

635454493436 120459