Codeforces Round 378 (Div. 2)
B
Parade
Codeforces
1100
原题
← AC →
翻译中…

Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civilian population also poorly understands from which leg recruits begin to march, so it is only important how many soldiers march in step.

翻译中…

There will be $*n*$ columns participating in the parade, the $*i*$-th column consists of $*l*_{*i*}$ soldiers, who start to march from left leg, and $*r*_{*i*}$ soldiers, who start to march from right leg.

翻译中…

The beauty of the parade is calculated by the following formula: if $*L*$ is the total number of soldiers on the parade who start to march from the left leg, and $*R*$ is the total number of soldiers on the parade who start to march from the right leg, so the beauty will equal $|*L* - *R*|$.

翻译中…

No more than once you can choose one column and tell all the soldiers in this column to switch starting leg, i.e. everyone in this columns who starts the march from left leg will now start it from right leg, and vice versa. Formally, you can pick no more than one index $*i*$ and swap values $*l*_{*i*}$ and $*r*_{*i*}$.

翻译中…

Find the index of the column, such that switching the starting leg for soldiers in it will maximize the the beauty of the parade, or determine, that no such operation can increase the current beauty.

翻译中…

Input

翻译中…

The first line contains single integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$) — the number of columns.

翻译中…

The next $*n*$ lines contain the pairs of integers $*l*_{*i*}$ and $*r*_{*i*}$ ($1 ≤ *l*_{*i*}, *r*_{*i*} ≤ 500$) — the number of soldiers in the $*i*$-th column which start to march from the left or the right leg respectively.

翻译中…

Output

翻译中…

Print single integer $*k*$ — the number of the column in which soldiers need to change the leg from which they start to march, or $0$ if the maximum beauty is already reached.

翻译中…

Consider that columns are numbered from 1 to $*n*$ in the order they are given in the input data.

翻译中…

If there are several answers, print any of them.

翻译中…

Note

翻译中…

In the first example if you don't give the order to change the leg, the number of soldiers, who start to march from the left leg, would equal $5 + 8 + 10 = 23$, and from the right leg — $6 + 9 + 3 = 18$. In this case the beauty of the parade will equal $|23 - 18| = 5$.

翻译中…

If you give the order to change the leg to the third column, so the number of soldiers, who march from the left leg, will equal $5 + 8 + 3 = 16$, and who march from the right leg — $6 + 9 + 10 = 25$. In this case the beauty equals $|16 - 25| = 9$.

翻译中…

It is impossible to reach greater beauty by giving another orders. Thus, the maximum beauty that can be achieved is 9.

翻译中…

样例

Input #1
3
5 6
8 9
10 3
Output #1
3
InputCopy OutputCopy
Input #2
2
6 5
5 6
Output #2
1
InputCopy OutputCopy
Input #3
6
5 9
1 3
4 8
4 5
23 54
12 32
Output #3
0
InputCopy OutputCopy
题目信息
题号
733B
时间限制
1 s
内存限制
256 MB
标签
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。