In a smart city, there are n autonomous cars driving along a highway. Each car starts at…
- User
In a smart city, there are n autonomous cars driving along a highway. Each car starts at a unique point and has a different destination. The i-th car starts at position si and heads toward its destination di. The positions si and di are distinct for every car, and all cars travel at a constant speed of 1 unit per second.
All cars begin their journey simultaneously, and whenever two cars cross paths at the same point, they share sensor data to enhance their navigation systems. Even after a car has reached its destination, it can continue to exchange sensor data with other cars passing by.
Your task is to compute the total number of data exchanges (greetings) that occur during the journey for each test case.
| Input Format
The first line contains an integer n (1 sns 200,000) - the number of cars.
Next n lines contain two integers s_i and d_i (-10^9 s s_i < d_is 10^9) - the starting and destination positions of each car.
All 2n numbers are distinct.
Output Format
Output a single integer representing the number of data exchanges (greetings) that occur.
| Constraints
15 n ≤ 200,000
-10^9 s s_i < d_i ≤ 10^9 in c++
- Assistant