CSES - Aalto Competitive Programming 2024 - wk2 - Wed - Old legos
  • Time limit: 1.00 s
  • Memory limit: 512 MB

Uolevi and Maija are visiting their parents. While the blueberry pie is cooking in the oven, they go explore the attic. They find their old legos and decide to build castles from them. There are nn legos in a box numbered 1,2,,n1,2,\dots,n, the ii-th of which has uiu_i nostalgic value to Uolevi and mim_i to Maija. The siblings then take turns in picking legos from the box and placing them to their castles. Naturally, both try to maximize the value difference between their own castle and their opponents castle.

Formally, the legos will be divided into two sets UU and MM at the end of the process. Uolevi's castle has value x=iUuix = \sum_{i \in U}{u_i} and Maija's castle has value y=iMmiy = \sum_{i \in M}{m_i}. Maija tries to minimize xyx-y while Uolevi tries to maximize it. Calculate xyx-y if Uolevi gets to pick the first lego and both pick the legos optimally.

Input

First line contain a single integer nn.

The 𝑖𝑖-th of the next nn lines contains two integers uiu_i and m𝑖m_𝑖.

Output

Output a single integer xyx-y.

Constraints

  • 1n1051 \leq n \leq 10^5
  • 1ui,mi1091 \leq u_i, m_i \leq 10^9

Example 1

Input:

5
3 1
9 3
6 3
2 10
1 7

Output:

1

Explanation:

The sequence of picks would be:
Uolevi picks lego 22
Maija picks lego 44
Uolevi picks lego 33
Maija picks lego 55
Uolevi picks lego 11

Example 2

Input:

2
10 2
1 1000

Output:

-1