Big Round Table
Time limit1sMemory limit512 MB
Masha sits at a round table of n seats and makes exactly k swaps with a left or right neighbor; count the seats she could occupy at the end.
- Level
Easy3 of 10
- Topics
- Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
Today Masha is hosting guests. Including Masha, people take part in the celebration and sit in a circle at a big round table.
Masha wants to talk with many guests, of course, but shouting across the whole table is inconvenient. So she quickly came up with a solution: sometimes she asks the neighbor on her left or on her right to swap places with her. The guests gladly agree to her request, of course.
After seeing the guests off, Masha remembered that she left her phone at the seat where she was sitting at the end of the event. Masha does not remember which seat she sat in at the end, but she does remember which seat she sat in at the beginning, and she also remembers that she swapped places with one of her neighbors exactly times. Now she wants to know the number of seats where she could have ended up at the end of the evening.
Input
The input contains two positive integers and : the number of seats at the table and the number of times Masha swapped places with one of her neighbors (, ).
Output
Print a single number: the number of seats where Masha could have ended up at the end of the event.
Hint
In the first example, after swapping places with one of her neighbors twice, Masha could end up either at her original seat or at one of the two seats located one seat away from the original one.
In the second example, Masha could end up at any seat.