Award Ceremony
Contest: 2016-2017 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
Difficulty rating: 2200
Tags: greedy, implementation

All-Berland programming contest comes to an end. In total, n teams participated in it. Like in ACM-ICPC, current results stopped refreshing one hour before the contest ends. So at the Award Ceremony, results are partially known. For each team the value ai is given — the number of points the i-th team has earned before the last hour of the contest. Besides that, the Jury has evaluated all submissions sent during the last hour and knows values di — the number of points earned by the i-th team during the last hour (these values can be negative, which means that a team can lose points).

Before the contest, each team got unique id from 1 to n. According to the contest rules, a team with more points takes a higher place. If two or more teams have equal number of points, the team with lower id will take the higher place. So no two teams can share the same place.

The Award Ceremony proceeds in the following way. At the beginning of the ceremony, a large screen shows the results for the time moment "one hour before the end", which means that the i-th team has ai points. Then the Jury unfreezes results of the teams one by one in some order. When result of the j-th team is unfrozen, its score changes from aj to aj + dj. At this time the table of results is modified and the place of the team can change. The unfreezing of the j-th team is followed by the applause from the audience with duration of |xj - yj| seconds, where xj is the place of the j-th team before unfreezing and yj is the place right after the unfreezing. For example, if the team does not change the place, there is no applause from the audience. As you can see, during the Award Ceremony, each team will be unfrozen exactly once.

Your task is to find such an order to unfreeze all the teams that the total duration of applause is maximum possible.

Input format:
The first line of the input file contains a single integer n (1 ≤ n ≤ 100) — the number of teams.

Each of the next n lines contains two integers ai and di (1 ≤ ai ≤ 100,  - 100 ≤ di ≤ 100) — the number of points the i-th team has earned before the last hour of the contest and the number of points earned by this team during the last hour. It is possible that after unfreezing a team will have a negative score.

Output format:
Print the only integer — maximal total applause duration in seconds if the Jury can choose any order of the teams to unfreeze.

Constraints:
Time limit: 2.0 s
Memory limit: 512.0 MB

Note:
In the first example the initial standings are:

1. Team 2, 52 points
2. Team 1, 17 points
3. Team 4, 6 points
4. Team 3, 1 point

Here any order of unfreezing the teams leads to 4 seconds of applause in total. For example, let's unfreeze teams in their order from the Team 1 to the Team 4.

After the Team 1 became unfrozen the standings are:

1. Team 2, 52 points
2. Team 4, 6 points
3. Team 1, 3 points
4. Team 3, 1 point

So there is 1 second of applause, because the difference between old and new places |2 - 3| = 1.

After the Team 2 became unfrozen the standings are:

1. Team 2, 47 points
2. Team 4, 6 points
3. Team 1, 3 points
4. Team 3, 1 point

The place of the Team 2 has not changed, so no applause during unfreezing.

After the Team 3 became unfrozen the standings are:

1. Team 3, 53 point
2. Team 2, 47 points
3. Team 4, 6 points
4. Team 1, 3 points

The place of the Team 3 has changed from 4 to 1, so the duration of applause is |4 - 1| = 3.

The unfreezing of the Team 4 has not changed any place because d4 = 0.

Therefore, the total duration of applause is 1 + 0 + 3 + 0 = 4 seconds.

Example input:
4
17 -14
52 -5
1 52
6 0

Example output:
4

Example input:
5
4 5
3 2
5 -3
6 -2
4 3

Example output:
14

Editorial:
There are three type of teams:
• with zero di = 0,
• with positive di > 0,
• with negative di < 0.
It is easy to see that teams of the first type do not affect the answer.
Also you can separately unfreeze teams of the second the the third types: if two teams of different types will cause inversion, the inversion will be regardless of unfreezing order.
Now the problem is to solve situation where all di > 0. The case with di < 0 is symmetric.
Look on two teams i and j where di > 0 and dj > 0. The best way to unfreeze them is to unfreeze at first the team who is currently lower in the current ranklist. You can try both orders and find that unfreeze in order "lower first" is always not worse.
So the algorithm is:
• Unfreeze all positive teams (which have di > 0), each time unfreezing lowerest team.
• Unfreeze all negative teams (which have di < 0), each time unfreezing highest team.
• ???
• PROFIT