Time Limit: | Memory Limit: | 64bit IO Format: |
Description
Today the «Z» city residents enjoy a shell game competition. Theresidents are gathered on the main square to watch thebreath-taking performance. The performer puts 3 non-transparentcups upside down in a row. Then he openly puts a small ball underone of the cups and starts to shuffle the cups around very quicklyso that on the whole he makes exactly 3 shuffles. After that thespectators have exactly one attempt to guess in which cup theythink the ball is and if the answer is correct they get a prize.Maybe you can try to find the ball too?
Input
The first input line contains an integer from 1 to 3 — index ofthe cup which covers the ball before the shuffles. The followingthree lines describe the shuffles. Each description of a shufflecontains two distinct integers from 1 to 3 — indexes of the cupswhich the performer shuffled this time. The cups are numbered fromleft to right and are renumbered after each shuffle from left toright again. In other words, the cup on the left always has index1, the one in the middle — index 2 and the one on the right — index3.
Output
In the first line output an integer from 1 to 3 — index of thecup which will have the ball after all the shuffles.
Sample Input
1 1 2 2 1 2 1
2
1 2 1 3 1 1 3
2
#include<iostream>
using namespace std;
int main()
{
int n,a1,b1,a2,b2,a3,b3;
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
while(cin>>n)
{
cin>>a1>>b1;
cin>>a2>>b2;
cin>>a3>>b3;
if(a1==n||b1==n)
{
if(a1==n) n=b1;
else n=a1;
}
if(a2==n||b2==n)
{
if(a2==n) n=b2;
else n=a2;
}
if(a3==n||b3==n)
{
if(a3==n) n=b3;
else n=a3;
}
cout<<n<<endl;
}
return 0;
}