Beondegi

Given A players in a circle and a chant pattern by rounds, find who makes the T-th call of a chosen word (ppeon or degi), counting only that word.

Easy3MathImplementationSimulationBinary searchInterviewNo attempts yetTime limit1sMemory limit128 MB

Problem

Ilgu, a freshman who just entered the software department at Chung-Ang University, learned several drinking games at the freshman orientation. The one he liked most is Beondegi.

The rules are these. The first round chant is 'ppeon, degi, ppeon, degi, ppeon, ppeon, degi, degi'. The second round chant is 'ppeon, degi, ppeon, degi, ppeon, ppeon, ppeon, degi, degi, degi'. In general, round nn starts with 'ppeon, degi, ppeon, degi', then says 'ppeon' n+1n+1 times, then says 'degi' n+1n+1 times. Every single call passes the turn to the next person. One round runs straight into the next one, and the game keeps going after the circle comes back around to Ilgu.

Ilgu, his classmates and the seniors, AA people in total, sit in a circle as shown below.

Ilgu is person 0 and the game runs counterclockwise. Counting from the start of the first round, find the number of the person who makes the TTth call of a given word. A freshman is carried out the moment the count reaches 10000, so TT is a natural number no larger than 10000.

Input

The first line has the number of players AA. AA is a natural number no larger than 2,000.

The second line has the ordinal TT you are asked about. TT is a natural number no larger than 10000.

The third line has the word you are asked about: 0 for 'ppeon', 1 for 'degi'.

Output

Print the number of the person who makes that call, as an integer, on the first line.

Hint

The TTth call counts only the word given on the third line. The two words are never counted together.

Ilgu is person 0, and the numbering continues counterclockwise as person 1, person 2, and so on.