#P7748. [COCI 2013/2014 #2] VOLIM

[COCI 2013/2014 #2] VOLIM

Description

There are 88 people sitting in a circle, as shown in the figure.

One of them is holding a box, and the box will explode 210210 seconds after the game starts.

The host will ask the box holder questions. The box holder may do one of the following:

  • If they skip or answer incorrectly, the host will continue by asking the next question.
  • If they answer correctly, the box holder passes the box to the first person on their left. That person becomes the new box holder.

Now you know, for each question, the time the respondent spent and whether the answer was correct.

Given the initial box holder’s number at the start of the game and the number of questions, find the number of the person holding the box when it explodes.

The time to pass the box and the time between two questions are ignored. The testdata guarantees that when the box explodes, the box is in someone’s hands, and the questions have not all been asked.

Input Format

The first line contains an integer KK, the number of the person holding the box at the start of the game.

The second line contains an integer NN, the number of questions.

The next NN lines each contain an integer TT and a character, representing the time spent answering that question and the result:

  • The character is T\tt T, meaning the answer is correct.
  • The character is N\tt N, meaning the answer is incorrect.
  • The character is P\tt P, meaning the question is skipped.

Output Format

Output one integer in a single line: the number of the person holding the box when it explodes.

1 
5 
20 T 
50 T 
80 T 
50 T 
30 T
5
3 
5 
100 T 
100 N 
100 T 
100 T 
100 N
4
5
6
70 T
50 P
30 N
50 T
30 P
80 T
7

Hint

Constraints

For 100%100\% of the testdata, 1K81\le K\le 8, 1N,T1001\le N,T\le 100.

Source

This problem is translated from COCI2013-2014 CONTEST 2 T1 VOLIM.

According to the original problem’s scoring settings, the full score for this problem is 5050 points.

Translated by ChatGPT 5