Тавсифи масъала
There are people standing in a circle, numbered from to . For each person , we are given a direction and a target number of handshakes The process consists of turns, taken in order
There are people standing in a circle, numbered from to . For each person , we are given a direction and a target number of handshakes The process consists of turns, taken in order
At the start, every person has made handshakes. Let denote the current total number of handshakes of person at any moment. On the -th turn:
If , the -th person does nothing on this turn.
Otherwise, the -th person leaves their position and starts moving around the circle in the direction given by :
Visiting people one by one in that order, each time they meet a person and still have , they perform a handshake with (this increases both and by ). They continue until , then return to their original position.
Note. The target refers to the overall number of handshakes for person . Handshakes received during other people's turns count toward . If, by the start of turn , , person skips their turn entirely.
Determine the final number of handshakes after all turns are completed.
First line contains one integer .
Second line contains one string consisting of characters, .
Third line contains space-separated integers .
Print one line containing space-separated integers, the answer.
| Subtasks | Additional restrictions | Points | Required Subtasks |
|---|---|---|---|
| 0 | Sample | 0 | - |
| 1 | 10 | - | |
| 2 | 10 | - | |
| 3 | 22 | 0 | |
| 4 | 18 | 0, 1, 3 | |
| 5 | - | 40 | 0, 1, 2, 3, 4 |