Codeforces 777A Shell Game

Source: Internet
Author: User

A. Shell GameTime limit per test:0.5 secondsmemory limit per test:256 megabytesinput:standard inputoutput:standard output

Bomboslav likes to look out of the windows in his and watch lads outside playing famous shell game. The game is played by Persons:operator and player. Operator takes three similar opaque shells and places a ball beneath one of the them. Then he shuffles the shells by swapping some pairs and the player have to guess the current position of the ball.

Bomboslav noticed that guys is 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, fou Rth, etc.).

Let's number shells from 0 through 2 from left to right . Thus the left shell is assigned number 0, the middle shell was 1 and the right shell is 2. Bomboslav have missed the moment when the ball is placed beneath the shell, but he knows that exactly n movem Ents were made by the operator and the ball were under Shell x at the end. Now he wonders, what is the initial position of the ball?

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 is found after n movements.

Output

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

Examplesinput
4
2
Output
1
Input
1
1
Output
0
Note

In the first sample, the ball is 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 was now under the left shell.
    2. During the second move operator swapped the middle shell and the right one. The ball was still under the left shell.
    3. During the third move operator swapped the left shell and the middle shell again. The ball was again in the middle.
    4. Finally, the operators swapped the middle shell and the right shell. The ball was now beneath the right shell.

Title Link: Http://codeforces.com/problemset/problem/777/A

Analysis: Find the law, purely to find the law, you say enumeration is OK! I had the opposite, even the sample did not have, tangled for 20 minutes only to find the problem, AC!

The AC code is given below:

1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5 6     intn,m;7     inta[3]={0,1,2};8      while(SCANF ("%d", &n)! =EOF)9     {Tenscanf"%d",&m); One         if(n%2==0) A         { -             intk=n/2; -             if(k%3==0) the             { -                 if(m==0) -printf"0\n"); -                 Else if(m==1) +printf"1\n"); -                 Else if(m==2) +printf"2\n"); A             } at             Else if(k%3==1) -             { -                 if(m==2) -printf"0\n"); -                 Else if(m==0) -printf"1\n"); in                 Else if(m==1) -printf"2\n"); to             } +             Else if(k%3==2) -             { the                 if(m==1) *printf"0\n"); $                 Else if(m==2)Panax Notoginsengprintf"1\n"); -                 Else if(m==0) theprintf"2\n"); +             } A         } the         Else +         { -             intT= (n+1)/2; $             if(t%3==0) $             { -                 if(m==0) -printf"0\n"); the                 Else if(m==2) -printf"1\n");Wuyi                 Else if(m==1) theprintf"2\n"); -             } Wu             Else if(t%3==1) -             { About                 if(m==1) $printf"0\n"); -                 Else if(m==0) -printf"1\n"); -                 Else if(m==2) Aprintf"2\n"); +             } the             Else if(t%3==2) -             { $                 if(m==2) theprintf"0\n"); the                 Else if(m==1) theprintf"1\n"); the                 Else if(m==0) -printf"2\n"); in             } the         } the     } About     return 0; the}

Codeforces 777A Shell Game

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.