codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

777A.md (2272B)


      1 Source: https://codeforces.com/problemset/problem/777/A
      2 
      3 A. Shell Game
      4 
      5 time limit per test
      6 
      7 0.5 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Bomboslav likes to look out of the window in his room and watch lads outside playing famous shell game. The game is played by two persons: operator and player. Operator takes three similar opaque shells and places a ball beneath one of them. Then he shuffles the shells by swapping some pairs and the player has to guess the current position of the ball.
     22 
     23 Bomboslav noticed that guys are not very inventive, so the operator always swaps the left shell with the middle one during odd moves (first, third, fifth, etc.) and always swaps the middle shell with the right one during even moves (second, fourth, etc.).
     24 
     25 Let's number shells from 0 to 2 from left to right. Thus the left shell is assigned number 0, the middle shell is 1 and the right shell is 2. Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly *n* movements were made by the operator and the ball was under shell *x* at the end. Now he wonders, what was the initial position of the ball?
     26 
     27 Input
     28 
     29 The first line of the input contains an integer *n* (1 ≤ *n* ≤ 2·109) — the number of movements made by the operator.
     30 
     31 The second line contains a single integer *x* (0 ≤ *x* ≤ 2) — the index of the shell where the ball was found after *n* movements.
     32 
     33 Output
     34 
     35 Print one integer from 0 to 2 — the index of the shell where the ball was initially placed.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 4  
     43 2
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 1
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 1  
     56 1
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 0
     63 ```
     64 
     65 Note
     66 
     67 In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.
     68 
     69 1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
     70 2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
     71 3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
     72 4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.