'''Author : seraph14'''
import sys, io, os
import heapq
if 'PyPy' in sys.version:
from _continuation import continulet
else:
import threading
input = sys.stdin.readline
hqp = heapq.heappop
hqs = heapq.heappush
def _print(*argv, sep=" "):
sys.stdout.write(sep.join(map(str, argv)) + "\n")
def inp():
return (int(input()))
def inlt():
return (list(map(int, input().split())))
def insr():
if input == sys.stdin.readline:
s = input()
return list(s.strip())
else:
s = input().decode()
return (list(s[:len(s)-2]))
def invr():
return (map(int, input().split()))
def get_bool(right):
return "YES" if right else "NO"
def solve():
pass
def main():
n = inp()
can = True
x = inp()
candidates = set(range(1, 7))
candidates.discard(7-x)
for _ in range(n):
a, b = invr()
if not can:
continue
for c in [a, b, 7-a, 7-b]:
candidates.discard(c)
can &= len(candidates) == 1
top = candidates.pop() if candidates else x
candidates = set(range(1, 7))
candidates.discard(7-top)
_print(get_bool(can))
if __name__ == '__main__':
if 'PyPy' in sys.version:
def bootstrap(cont):
call, arg = cont.switch()
while True:
call, arg = cont.switch(
to=continulet(lambda _, f, args: f(*args), call, arg))
cont = continulet(bootstrap)
cont.switch()
main()
else:
sys.setrecursionlimit(1 << 30)
threading.stack_size(1 << 27)
main_thread = threading.Thread(target=main)
main_thread.start()
main_thread.join()
#include <bits/stdc++.h>
using namespace std;
int check[7]{};
int main()
{
int n,x,a,b,sum=0;
cin>>n>>x;
for(int i=0 ; i<n ; i++)
{
cin>>a>>b;
check[a]=1;
check[7-a]=1;
check[b]=1;
check[7-b]=1;
}
for(int i=0 ; i<=6 ; i++)
sum+=check[i];
if(sum==4)
cout<<"YES";
else
cout<<"NO";
}
1302. Deepest Leaves Sum | 1209. Remove All Adjacent Duplicates in String II |
994. Rotting Oranges | 983. Minimum Cost For Tickets |
973. K Closest Points to Origin | 969. Pancake Sorting |
967. Numbers With Same Consecutive Differences | 957. Prison Cells After N Days |
946. Validate Stack Sequences | 921. Minimum Add to Make Parentheses Valid |
881. Boats to Save People | 497. Random Point in Non-overlapping Rectangles |
528. Random Pick with Weight | 470. Implement Rand10() Using Rand7() |
866. Prime Palindrome | 1516A - Tit for Tat |
622. Design Circular Queue | 814. Binary Tree Pruning |
791. Custom Sort String | 787. Cheapest Flights Within K Stops |
779. K-th Symbol in Grammar | 701. Insert into a Binary Search Tree |
429. N-ary Tree Level Order Traversal | 739. Daily Temperatures |
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |