問題一覧 > 通常問題

No.185 Japanese Style

レベル : / AI推定難易度 : 115 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 128 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 677
作問者 : LayCurse / テスター : yuki2006
お気に入りにしたユーザー ProblemId : 446 / 自分の提出
問題文最終更新日: 2026-06-25 18:29:33
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 98 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。