No.185 Japanese Style
Problem Statement
In other countries, there seem to be problems with many answers, such as ○+□=8, but they must be a pain to grade, right?
So, in true Japanese style, let's add conditions so that the answer is uniquely determined.
Oh dear, we may have added too many conditions.
You are given $N$ $2$-tuples of positive integers $(X_1, Y_1),(X_2, Y_2), \ldots ,(X_N, Y_N)$.
□ $+ X_k = Y_k, \quad k=1,2,\ldots,N$
Find the positive integer that goes in □ and satisfies the above simultaneously.
Input
$N$ $X_1$ $Y_1$ $X_2$ $Y_2$ $\vdots$ $X_N$ $Y_N$
$1 \leq N \leq 1000$
$1 \leq X_i, Y_i \leq 1000000 = 10^6$
Output
Output the positive integer that goes in □.
However, if no such integer exists, output $\verb|-1|$ instead.
Incidentally, it seems that advanced mathematics shows there can never be $2$ or more positive integers that go in □.
Sample
Sample 1
Input
2 3 5 7 9
Output
2
Adding $3$ to □ gives $5$, and adding $7$ gives $9$, so □ must be $2$.
Sample 2
Input
2 3 5 7 10
Output
-1
Sample 3
Input
1 8 2
Output
-1
I only know positive integers, so I have no idea what would give $2$ when you add $8$ to it.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
LayCurse