Under construction

Still being built. Things may change

Sky and Pink

Interview

Time limit1sMemory limit1024 MB

Summary
Given two lists of positive integers, find nonzero a and b with absolute value at most 1000000 that make |a·sum(A) - b·sum(B)| as small as possible.
Level

Easy3 of 10

Topics
Math, Number theory
Solved
No attempts yet

Problem

Shihyun found NN pink hair strands and NN sky-blue hair strands lying in a corner of his room!

Shihyun was sure that all of them belonged to Danbi.

Shihyun measured the strands. The length of the ii-th pink strand was AiA_i, and the length of the ii-th sky-blue strand was BiB_i. (1≤i≤N)(1 \leq i \leq N)

After measuring every strand, Shihyun wondered which nonzero integers aa and bb, each between −1 000 000-1\,000\,000 and 1 000 0001\,000\,000 inclusive, minimize ∣a∑i=1NAi−b∑i=1NBi∣\left| a\sum_{i=1}^N A_i - b\sum_{i=1}^N B_i \right|.

Answer his question!

Input

The first line contains the number of hair pairs NN. (1≤N≤1 000)(1 \leq N \leq 1\,000)

The second line contains A1,A2,⋯ ,ANA_1, A_2, \cdots, A_N, and the third line contains B1,B2,⋯ ,BNB_1, B_2, \cdots, B_N, separated by spaces. (1≤Ai,Bi≤100)(1 \leq A_i, B_i \leq 100)

All numbers in the input are integers.

Output

On the first line, print aa and bb that minimize ∣a∑i=1NAi−b∑i=1NBi∣\left| a\sum_{i=1}^N A_i - b\sum_{i=1}^N B_i \right|, separated by a space.

If there are several such pairs (a,b)(a, b), print any of them.

Examples1

  1. Example 1

    Input
    1
    3
    3
    
    Expected output
    1 1