Ants’ Movements


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Anumber of ants are located on a two-dimensional plane, and each ant moves either upward or rightward. In each step, each ant moves one unit forward in its direction. More precisely, consider an ant located at coordinates (xi,yi)(x_i,y_i) before the ithi-th step. If the ant moves upward, its coordinates after the ithi-th step will be (xi,yi+1)(x_i,y_i + 1), and if it moves rightward, its coordinates after the ithi-th step will be (xi+1,yi)(x_i + 1,y_i). Initially, no two ants are located at the same coordinates. If two ants collide at the same coordinate in a step, before the next step begins, their movement direction changes from up to right and from right to up. Sara is curious to know the total number of collisions. Given the initial coordinates of the ants and their directions of movement, calculate the total number of collisions for Sara.

ورودی🔗

The first line of the input contains an integer nn (2n2105)(2 \leq n \leq 2*10^5), which is the the number of ants. Then, for each 1in1 \leq i \leq n, the (i+1)th(i+1)th line of the input contains two space-separated integers xix_i and yiy_i (1xi,yi109)(1 \leq x_i,y_i \leq 10^9), and one of the letters U or R. The integers denote the initial coordinates of the ithi-th ant, and the letter indicates the initial direction of movement. The letter U represents upward movement, and the letter R represents rightward movement.

خروجی🔗

In the only line of output, print the total number of collisions if it is finite, and the word inf otherwise.

ورودی نمونه 1🔗

3 
1 2 R
2 1 U
3 1 U
Plain text

خروجی نمونه 1🔗

1
Plain text

ورودی نمونه 2🔗

4 
1 4 U 
1 2 U 
1 3 U 
1 1 U
Plain text

خروجی نمونه 2🔗

0
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.