Canada Cup 2016
F
Family Photos
Codeforces
2900
原题
← EG →
翻译中…

Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first.

翻译中…

There are $*n*$ stacks of photos. Each stack contains exactly two photos. In each turn, a player may take only a photo from the top of one of the stacks.

翻译中…

Each photo is described by two non-negative integers $*a*$ and $*b*$, indicating that it is worth $*a*$ units of happiness to Alice and $*b*$ units of happiness to Bonnie. Values of $*a*$ and $*b*$ might differ for different photos.

翻译中…

It's allowed to pass instead of taking a photo. The game ends when all photos are taken or both players pass consecutively.

翻译中…

The players don't act to maximize their own happiness. Instead, each player acts to maximize the amount by which her happiness exceeds her sister's. Assuming both players play optimal, find the difference between Alice's and Bonnie's happiness. That is, if there's a perfectly-played game such that Alice has $*x*$ happiness and Bonnie has $*y*$ happiness at the end, you should print $*x* - *y*$.

翻译中…

Input

翻译中…

The first line of input contains a single integer $*n*$ ($1 ≤ *n* ≤ 100 000$) — the number of two-photo stacks. Then follow $*n*$ lines, each describing one of the stacks. A stack is described by four space-separated non-negative integers $*a*_{1}$, $*b*_{1}$, $*a*_{2}$ and $*b*_{2}$, each not exceeding $10^{9}$. $*a*_{1}$ and $*b*_{1}$ describe the top photo in the stack, while $*a*_{2}$ and $*b*_{2}$ describe the bottom photo in the stack.

翻译中…

Output

翻译中…

Output a single integer: the difference between Alice's and Bonnie's happiness if both play optimally.

翻译中…

样例

Input #1
2
12 3 4 7
1 15 9 1
Output #1
1
InputCopy OutputCopy
Input #2
2
5 4 8 8
4 12 14 0
Output #2
4
InputCopy OutputCopy
Input #3
1
0 10 0 10
Output #3
-10
InputCopy OutputCopy
题目信息
题号
725F
所属比赛
时间限制
2 s
内存限制
256 MB
标签
博弈论
贪心

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