## Girls Invitational '19 S5 - Dodgeball Club

View as PDF

Points: 15 (partial)
Time limit: 4.0s
Memory limit: 512M

Author:
Problem type

Kstar has found a new dodgeball club called the Anonymous Dodgeball Association (or ADA). The ADA loves laces, but more importantly, they love dodgeball, so let's focus on that.

The ADA has members, who each have a unique ID from to . Person has a dodgeball skill level of . Some people are so bad that their skill level is negative.

There are two types of meetings: training meetings and game meetings.

At a training meeting, everyone practices and has fun. No one takes it seriously. As a result, exactly one member's skill level will change. In other words, for some and some , will change to .

At a game meeting, every member comes and lines up in increasing order of their ID (). Then the coach comes and numbers them off into teams, numbered from to . The number of teams changes from meeting to meeting.

The coach always numbers them off as follows:

1. The coach walks down the line from Person to Person .
2. She starts by putting Person in Team .
3. For every person after, she puts them in the team that comes after the previous person's team, except if the previous person is in Team , in which case she wraps around to Team .

For example, if there are people and teams, the coach would number them off as such:

Person Number Team Number
1 1
2 2
3 3
4 1
5 2
6 3
7 1

The skill level of a team is defined as the sum of the skill levels of the members of that team.

Kstar's official opinion on the ADA is ewww exercise, so she decides to join as an executive instead of a member. As the head of the Fairness Committee at ADA, Kstar's job is to make sure that no team is too strong.

In order to gather information, Kstar attends meetings. Every game meeting, she notices that the coach has numbered everyone off into teams, and she want to know specifically the skill level of Team . The values of and change from meeting to meeting. She must also take into account the changes in skill level caused by training meetings. At each training meeting, for some and , is set to .

Since Kstar would much rather be watching the games instead of tediously adding numbers, can you write a program to help her?

#### Constraints

• For game meetings,

There are no training meetings, and Kstar will only ask for the skill level of Team 1.

There are no training meetings.

No further constraints.

#### Input Specification

The first line of input will contain and .

The second line of input will contain numbers: , , , .

For the next lines of input, the first character is either a T, indicating a training meeting or a G, indicating a game meeting.

If it is a T, two numbers follow: and , indicating that the skill level of Member has their skill level changed to . In other words, is changed to .

If it is a G, two numbers follow: and , indicating that the coach has numbered everyone off into teams, and you must output the skill level of Team .

#### Output Specification

For every game meeting, output the corresponding answer.

#### Sample Input

7 4
2 3 5 7 11 13 17
G 2 1
G 2 2
T 2 10
G 3 2

#### Sample Output

35
23
21

#### Explanation For Sample

The first line of input tells us that there are people, and meetings you attend. The skill levels of the members are , , , , , , and , respectively.

• In the first meeting, the ADA is arranged into teams. Team has Person , , , and , who respectively have skill levels of , , , and . Their sum is .
• In the second meeting, the ADA is arranged into teams. Team has Person , , and , who respectively have skill levels of , , and . Their sum is .
• In the third meeting, Person 's skill level becomes .
• In the fourth meeting, the ADA is arranged into teams. Team has Person and Person , who respectively have skill levels of and . Their sum is .