NOI Contest Archive

Archive / 2021 / Final Round — Day 1

Motorway

Medium · National Olympiad in Informatics Sri Lanka 2021 - Day 1

King Unumagudut ruled Aknalirs in 150 BC. One day he woke out of bed discovering motorways. He wanted to build a motorway from the south of the country to the north connecting N cities, and the motorway consists of 2 one way roads. The travellers can enter the motorway from each city to travel either north or south. Cities are numbered from 1 to N starting from the southern city to the northern city.

King Unumagudut wanted to be perceived as generous to the citizens and came up with a new way of giving money to travellers:

Given N and above values of the cities, you are asked to calculate the number of pairs of cities where traveling from the northern city to the southern city (in the southbound road) is more beneficial than traveling from the southern city to the northern city (in the northbound road).

Input Format

First line contains a single integer, N
Next N lines contain associated values of city 1 to N, in that order. Each of those lines will contain 2 integers separated by a space

Output Format

Print a single integer representing the number of city pairs whether travelling in the northbound road is more beneficial than the southbound road.

Constraints

Subtasks

  1. (30 points) - 1 \(\leq\) N \(\leq\) 104
  2. (20 points) - 1 \(\leq\) N \(\leq\) 5 * 105
  3. (50 points) - No additional constraints.

Limits

Sample Input 0

4
4 1
3 4
5 2
7 3

Sample Output 0

5