A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left).
Alice and Bob play dice. Alice has built a tower from n dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees).
Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not.
输入描述:
输出描述:
样例输入:
3 6 3 2 5 4 2 4
样例输出:
YES
#include<string>
#include<string.h>
#include <iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
int a,b;
int flag=0;
for(int i=0; i<n; i++)
{
scanf("%d%d",&a,&b);
if(a==m||a==7-m||b==m||b==7-m)
flag=1;
}
if(flag)
printf("NO\n");
else
printf("YES\n");
}