Shell Game
time limit per test 0.5 second memory limit per test 256 megabytes
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?

传送门:CF777A

Input

The first line of the input contains an integer n (1≤n≤2·109) — 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.

Sample Input

1
2
4
2

Sample Output

1
1

题解

纸上模拟一下就知道是6次一个循环 那么只要模拟模6后的余数就好了
## AC code:(不包含输入类)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import java.io.*;  
import java.util.*;
public class Main {

public static void main(String[] args) {
FastScanner sc=new FastScanner();
PrintWriter pw=new PrintWriter(System.out);
while(sc.hasNext()){
int n=sc.nextInt();
int x=sc.nextInt();
n=n-n/6*6; //模6的余数
for(int i=n;i>=1;i--){
if(i%2==0){
if(x==2)x=1;
else if(x==1)x=2;
}else{
if(x==0)x=1;
else if(x==1)x=0;
}
}
pw.println(x);
pw.flush();
}
}

}