Problem1042--CARD

1042: CARD

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Alice is a card dealer at the poker table in newly opened ResortWorld casino. As a strange
personal quirk, she has two ways of moving a card when she shuffles the deck:
A: She takes the card at the top of the deck and moves it to the bottom.
B: She takes the second card from the top of the deck and moves it to the bottom.
Initially, Alice has m cards (note that m can be very much more than the standard 52 cards
found in a deck) which are labeled consecutively: the card at the top is labeled 0 and the card at
the bottom is labeled m - 1. Consider a sequence of moves like:
ABBABA
The table below shows the deck after each move in the sequence is applied.

In this question we want to know: given a sequence of moves and a k, where 0 < k < m-1,
what is the label of the (k - 1)–th, k–th and (k + 1)–th cards from the top of the deck after
the entire sequence is applied? Here, we treat top-most card as the 0–th card. In our example
above, if k = 3, then the answer is “3 1 5”.

Input

Your program must read from the standard input. The input consists of m and k, where
0 < k < m  - 1, and 3 <= m <= 1; 000; 000, and the sequence of moves in a single line. The
last character in the input is the period “.”, indicating the end of input. The total number of
moves is at least 1 and at most 100,000. In our example above, the input is:
6 3 ABBABA

Output

Your program must write to the standard output the (k - 1)–th, k–th and (k + 1)–th cards from
the top of the deck after the entire sequence of card moves have been applied. In our example
above, the output will be:
3 1 5

Sample Input Copy

6 3 ABBABA

Sample Output Copy

3 1 5

Source/Category

NOI