Codeforces Round 401 (Div. 2)
A
Shell Game
Codeforces
1000
原题
←B →
翻译中…

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 $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?

翻译中…

Input

翻译中…

The first line of the input contains an integer $*n*$ ($1 ≤ *n* ≤ 2·10^{9}$) — the number of movements made by the operator.

翻译中…

The second line contains a single integer $*x*$ ($0 ≤ *x* ≤ 2$) — the index of the shell where the ball was found after $*n*$ movements.

翻译中…

Output

翻译中…

Print one integer from $0$ to $2$ — the index of the shell where the ball was initially placed.

翻译中…

Note

翻译中…

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.
翻译中…

样例

Input #1
4
2
Output #1
1
InputCopy OutputCopy
Input #2
1
1
Output #2
0
InputCopy OutputCopy
题目信息
题号
777A
时间限制
0.5 s
内存限制
256 MB
标签
构造
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。