|
|||
Game of ThrownsDaenerys frequently invents games to help teach her second-grade Computer Science class about various aspects of the discipline. For this week's lesson, she has the children form a circle and (carefully) throw around a petrified dragon egg. The n children are numbered from 0 to n – 1 (it is a Computer Science class after all) clockwise around the circle. Child 0 always starts with the egg. Daenerys will call out one of two things:
For example, if there are 5 children, and the teacher calls out the four throw commands
Daenerys would like a little program that determines where the egg should end up if her commands are executed correctly. Don't ask what happens to the children if this isn't the case. Input Specification
The input consists of two lines. The first line contains two positive integers n and
k (1 ≤ n ≤ 30,
1 ≤ k ≤ 100), indicating the number of students and
how many throw commands Daenerys calls out, respectively. The following line contains the
k throw commands. Each command is either an integer p
(–10 000 ≤ p ≤ 10 000), indicating
how many positions to throw the egg clockwise, or Output SpecificationDisplay the number of the child with the egg at the end of the game. Sample Input 1
Output for Sample Input 1
Sample Input 2
Output for Sample Input 2
|
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |