Hawk Eyes
InterviewTime limit1sMemory limit512 MB
Given a sequence of cup swaps among four positions, track where the small ball (initially at position 1) and big ball (initially at position 4) end up.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Jaeyeol is good at the shell game, and he plans to earn some money by running a booth in front of Hongmungwan during the festival.
Jaeyeol places four cups in a row on a table. He puts a small ball in the leftmost cup and a big ball in the rightmost cup. He will then mix the cups many times, each time swapping the positions of two cups. When he is done, he will ask his opponent which cups hold the balls. With 4 cups there are 6 ways to swap two positions, shown in the figures below.






Number the positions 1, 2, 3, 4 from the left. Each way swaps these two positions:
Jaeyeol practiced for 3 months to make a fortune, and almost nobody can beat him. By chance, Yeongbeom, who has extraordinary dynamic visual acuity, is walking past Hongmungwan. Yeongbeom proposes a bet, and Jaeyeol, unaware of anything, silently starts mixing the cups. However fast Jaeyeol's hands are, they cannot fool Yeongbeom's eyes. Yeongbeom also has an excellent memory and remembers the entire order in which Jaeyeol mixed the cups. Jaeyeol does not know this, and his fate depends on the program you write.
Given the ways Jaeyeol mixed the cups in order, write a program that prints the position of the cup holding the small ball and then the position of the cup holding the big ball.
Input
The first line contains the order in which Jaeyeol mixes the cups, as a string without spaces. Each character is one of A, B, C, D, E, F from the figures above. Jaeyeol mixes the cups at most 200 times.
Output
Print the position of the small ball on the first line and the position of the big ball on the second line. Positions are numbered 1, 2, 3, 4 from the left.