CF777A.Shell Game

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

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.).

Let's number shells from 00 to 22 from left to right. Thus the left shell is assigned number 00 , the middle shell is 11 and the right shell is 22 . Bomboslav has missed the moment when the ball was placed beneath the shell, but he knows that exactly nn movements were made by the operator and the ball was under shell xx at the end. Now he wonders, what was the initial position of the ball?

输入格式

The first line of the input contains an integer nn ( 1<=n<=21091<=n<=2·10^{9} ) — the number of movements made by the operator.

The second line contains a single integer xx ( 0<=x<=20<=x<=2 ) — the index of the shell where the ball was found after nn movements.

输出格式

Print one integer from 00 to 22 — the index of the shell where the ball was initially placed.

输入输出样例

  • 输入#1

    4
    2
    

    输出#1

    1
    
  • 输入#2

    1
    1
    

    输出#2

    0
    

说明/提示

In the first sample, the ball was initially placed beneath the middle shell and the operator completed four movements.

  1. During the first move operator swapped the left shell and the middle shell. The ball is now under the left shell.
  2. During the second move operator swapped the middle shell and the right one. The ball is still under the left shell.
  3. During the third move operator swapped the left shell and the middle shell again. The ball is again in the middle.
  4. Finally, the operators swapped the middle shell and the right shell. The ball is now beneath the right shell.
首页