| HPI 2024 Novice |
|---|
| Finished |
Recently, Sparkle has been interested in vehicles, so she has set up a number line and placed $$$N$$$ ($$$1 \le N \le 5000$$$) trucks with equal mass on it. The $$$i$$$-th truck is initially located at position $$$x_i$$$ ($$$1 \le x_i \le 10^9$$$) with velocity $$$v_i$$$ ($$$-10^9 \le v_i \le 10^9$$$). Since this is all a dream, when two trucks collide, they will not explode, but rather undergo a perfectly elastic collision, ie. if two trucks collide, their velocities will be swapped. Sparkle is now curious about the number of times the trucks will collide, and she wants you to find this number or tell her that there will be infinite collisions. Note that if $$$k$$$ trucks collide at the same time, then this will be counted as $$$\frac{k(k - 1)}{2}$$$ collisions.
The first line contains a single integer $$$N$$$ ($$$1 \le N \le 5000$$$).
Each of the next $$$N$$$ lines contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i \le 10^9$$$, $$$-10^9 \le v_i \le 10^9$$$). It is guaranteed that all $$$x_i$$$ are distinct.
Output a single integer denoting the total number of collisions or $$$-1$$$ if there will be infinite collisions.
21 12 -1
1
The two trucks will move towards each other and collide once before going into opposite directions and never colliding again.
| Name |
|---|


