Problem:
 Score : 200 points    Problem Statement There are four towns, numbered 1,2,3 and 4 .
Also, there are three roads. The i -th road connects different towns a_i and b_i bidirectionally.
No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads.  Determine if we can visit all the towns by traversing each of the roads exactly once.      Constraints  1 \leq a_i,b_i \leq 4(1\leq i\leq 3)  a_i and b_i are different. (1\leq i\leq 3)  No two roads connect the same pair of towns.  Any town can be reached from any other town using the roads.         Input Input is given from Standard Input in the following format:  a_1  b_1  a_2  b_2  a_3  b_3       Output If we can visit all the towns by traversing each of the roads exactly once, print YES ; otherwise, print NO .        Sample Input 1 4 2
1 3
2 3      Sample Output 1 YES  We can visit all the towns in the order 1,3,2,4 .       Sample Input 2 3 2
2 4
1 2      Sample Output 2 NO       Sample Input 3 2 1
3 2
4 3      Sample Output 3 YES

Solution (Python):
a1, b1=map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

listR = [a1, b1, a2, b2, a3, b3]
listR.sort()

flag=0
if 1 in listR and 2 in listR and  3 in listR and 4 in listR:
    listD=[]
    bef=0
    count=0
    index=0
    while index < len(listR):
        if index==0:
            bef=listR[index]
            count=1
        else:
            if listR[index]!=bef:
                if count!=1 and count!=2:
                    print("NO")
                    flag=1
                    break
                else:
                    if count==2:
                        listD.append(bef)
                    bef=listR[index]
                    count=1
            else:
                count+=1
        index+=1
    if count != 1 and count != 2 and flag==0:
        print("NO")
        flag = 1
    else:
        if count==2:
            listD.append(bef)
    if len(listD) == 2 and flag == 0:
        print("YES")
    else:
        if flag==0:
            print("NO")
else:
    print("NO")

Solution (Python):
def flatten(lst):
    result=[]
    for i in lst:
        if type(i) != list:
            result.append(i)
        else:
            
            result.extend(flatten(i))
    return result

import numpy as np
from sys import stdin
a=[]
for i in range(3):
    a.append([(x) for x in stdin.readline().rstrip().split()])

if len(set(flatten(a))) !=4:
    print("NO")

else:
    if flatten(a).count("1") < 3 and flatten(a).count("2") < 3 and flatten(a).count("3") < 3 and flatten(a).count("4") < 3 :
        print ("YES")
    else:
        print("NO")

Solution (Python):

a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

l = [a1, b1, a2, b2, a3, b3]
flag = True

for i in range(1, 5):
    if not(1 <= l.count(i) and l.count(i) <= 2):
        flag = False

if flag:
    print("YES")
else:
    print("NO")

Solution (Python):
miti={}
for k in range(3):
    b, c = map(int, input().split())
    miti.setdefault(b,[]).append(c)
    miti.setdefault(c,[]).append(b)
    
miti_count=[]
memo=[]

a_mati=len(miti[1])
miti_count.append(a_mati)
if a_mati==2:
    memo.append(1)
    
b_mati=len(miti[2])
miti_count.append(b_mati)
if b_mati==2:
    memo.append(2)

c_mati=len(miti[3])
miti_count.append(c_mati)
if c_mati==2:
    memo.append(3)

d_mati=len(miti[4])
miti_count.append(d_mati)
if d_mati==2:
    memo.append(4)
    
if len(memo)==2 and miti_count.count(1)==2:
    if (memo[1] in miti[memo[0]])==True and (memo[0] in miti[memo[1]])==True:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Solution (Python):
a=input().split()
b=a[0]
c=a[1]
d=input().split()
e=d[0]
f=d[1]
g=input().split()
h=g[0]
i=g[1]
L=[b,c,e,f,h,i]
if L.count('1')==3 or L.count('2')==3 or L.count('3')==3 or L.count('4') ==3:
    print('NO')
else:
    print('YES')

Solution (Python):
import collections
l = []
for i in range(3):
 l.extend(list(map(int,input().split())))
print('NO' if max(collections.Counter(l).values()) >= 3 else 'YES')

Solution (Python):
A= []
for _ in range(3):
    a,b=map(int,input().split())
    A.append(a)
    A.append(b)
B = []
for i in range(1,5):
    B.append(A.count(i))
if B.count(1) == 2 and B.count(2) == 2:
    print("YES")
else:
    print("NO")

Solution (Python):
p_str = input().split()
p = [int(s) for s in p_str]
p_str = input().split()
p.extend([int(s) for s in p_str])
p_str = input().split()
p.extend([int(s) for s in p_str])

count_list = []
for i in range(4):
   count =  p.count(i+1)
   count_list.append(count)

if(count_list.count(1)==2 and count_list.count(2)==2):
   print("YES")
else:
   print("NO")

Solution (Python):
a_1, b_1 = map(int, input().split())
a_2, b_2 = map(int, input().split())
a_3, b_3 = map(int, input().split())
list_r = list([a_1,a_2,a_3,b_1,b_2,b_3])
a = list_r.count(1)
b = list_r.count(2)
c = list_r.count(3)
d = list_r.count(4)
list_count = list([a,b,c,d])
count = list_count.count(2)
if count == 2:
    print('YES')
else:
    print('NO')

Solution (Python):
path = [[], [], [], []]
for i in range(3):
    a, b = list(map(int, input().split()))
    path[a-1].append(b-1)
    path[b-1].append(a-1)
    
re = 'YES'
for i in range(4):
    if len(path[i]) == 0 or len(path[i]) == 3:
        re = 'NO'
        break
        
print(re)

Solution (Python):

check = []
for i in range(4):
    check.append(0)


for i in range(3):
    inp = input().split()
    a = int(inp[0])
    b = int(inp[1])
    check[a-1] += 1
    check[b-1] += 1

odd_count = 0
for i in range(4):
    if (check[i]%2 == 1):
        odd_count += 1

if (odd_count==0 or odd_count==2):
    print("YES")
else:
    print("NO")

Solution (Python):
nodes = [[] for i in range(4)]

a = [int(i) for i in input().split()]
nodes[a[0]-1].append(a[1]-1)
nodes[a[1]-1].append(a[0]-1)

b = [int(i) for i in input().split()]
nodes[b[0]-1].append(b[1]-1)
nodes[b[1]-1].append(b[0]-1)

c = [int(i) for i in input().split()]
nodes[c[0]-1].append(c[1]-1)
nodes[c[1]-1].append(c[0]-1)

ok = 0

ct = [0]*5

for i in range(1,5):
    ct[i] = a.count(i) + b.count(i) + c.count(i)

ct.sort(reverse=True)

ct = ct[:-1]

if ct[0]==2 and ct[1]==2 and ct[2]==1 and ct[3]==1:
    ok = 1

if ok:
    print('YES')
else:
    print('NO')

Solution (Python):
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())


path = [[a1, b1], [a2, b2], [a3, b3]]
pos = [2]*4



for pth in path:
    pos[pth[0]-1] -= 1
    pos[pth[1]-1] -= 1



if pos.count(1) == 2 and pos.count(0) == 2:
    print("YES")
else:
    print("NO")

Solution (Python):
from copy import copy
def dfs_visit(node, roads, visited, used):
    if all(visited) and all(used):
        return True
    elif all(used):
        return False
    okay = False
    for i, (a, b) in enumerate(roads):
        if used[i]:
            continue
        elif node == a:
            cp_visited = copy(visited)
            cp_used = copy(used)
            cp_used[i] = True
            cp_visited[b] = True
            okay |= dfs_visit(b, roads, cp_visited, cp_used)
        elif node == b:
            cp_visited = copy(visited)
            cp_used = copy(used)
            cp_used[i] = True
            cp_visited[a] = True
            okay |= dfs_visit(a, roads, cp_visited, cp_used)
    return okay

roads = sorted([sorted([int(elem) - 1 for elem in input().split()]) for _ in range(3)])

for start in range(4):
    visited = [False] * 4
    used = [False] * 3
    visited[start] = True
    if dfs_visit(start, roads, visited, used):
        print("YES")
        exit(0)
else:
    print("NO")

Solution (Python):
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())
line = [a1, b1, a2, b2, a3, b3]
cnt = [0,0,0,0]
for i in range(6):
    if line[i] == 1:
        cnt[0] += 1
    elif line[i] == 2:
        cnt[1] += 1
    elif line[i] == 3:
        cnt[2] += 1
    else:
        cnt[3] += 1
cnt1 = 0
for j in range(4):
    if 0 < cnt[j] and cnt[j] < 3:
        cnt1 += 1
if cnt1 == 4:
    print("YES")
else:
    print("NO")

Solution (Python):
a = [list(map(str,input().split())) for i in range(3)]
a_conv = []
for i in range(3):
    for j in range(2):
        a_conv.append(a[i][j])

judge = 0
for i in range(1,5):
    temp = a_conv.count(str(i))
    if temp == (0 or 3):
        print('NO')
        exit()
    elif temp == 2:
        judge += 1

if judge == 2:
    print('YES')
else:
    print('NO')

Solution (Python):
a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

l = [a1, a2, a3, b1, b2, b3]

res = [sum([1 for _ in l if _ == __]) for __ in [1,2,3,4]]

if 3 in res:
    print("NO")
else:
    print("YES")

Solution (Python):
li = []
n = 3
import collections
for i in range(n):
    a,b = input().split()
    li.append(a)
    li.append(b)
    
c = collections.Counter(li)

def cole(di):
    i = 0
    for k in di.keys():
        if di[k] != 0 and di[k] <= 2:
            i += 1
        else:
            i -= 1
    if i == 4:
        return True
    else:
        return False

if cole(c):
    print("YES")
else:
    print("NO")

Solution (Python):
a_i = []

for i in range(3):
	a_1, b_1 = map(int, input().split())
	a_i.append(a_1)
	a_i.append(b_1)

count1 = a_i.count(1)
count2 = a_i.count(2)
count3 = a_i.count(3)
count4 = a_i.count(4)
if(count1 == 3 or count2 == 3 or count3 == 3 or count4 == 3):
	print("NO")
else:
	print("YES")

Solution (Python):


def function():
    count=[0] * 5

    for i in range(3):
        data = input().split()  
        for j in range(2):
            n = int(data[j])
            count[n]+=1
            if(count[n] == 3):
                print('NO')
                return
    print('YES')

function()

Solution (Python):
path = [list(map(int, input().split(" "))) for i in range(3)]

yes = False
for i in range(3):
    for j in range(2):
        passed = [path[i][j], path[i][1-j]]
        for k in range(3):
            if i == k: continue
            if path[k][0] == passed[1]:
                passed.append(path[k][1])
            elif path[k][1] == passed[1]:
                passed.append(path[k][0])
            else: 
                continue
            last = list({0, 1, 2} - set([i, k]))[0]
            if passed[-1] in path[last] and set(passed + path[last]) == set(range(1, 5)):
                yes = True
                
if yes:
    print('YES')
else:
    print("NO")

Solution (Python):
a = [0,0,0,0,0,0]
b = [0,0,0,0]
for i in range(3):
  a[2*i],a[2*i+1] = map(int, input().split())
for i in range(6):
  for j in range(4):
    if a[i] == j+1:
      b[j] += 1
flag = 0
for i in range(4):
  if b[i] > 2:
    print("NO")
    flag = 1
if flag == 0:
  print("YES")

Solution (Python):
x = []
f  = 1
for _ in range(3):
    x.extend(list(map(int,input().split())))
cnt = [0]*4
for i in range(6):
    cnt[x[i]-1] += 1
for a in cnt:
    if a > 2:
        f = 0
if f:
    print("YES")
else:
    print("NO")

Solution (Python):
check = [0, 0, 0, 0]
for i in range(3):
    a, b = map(int, input().split())
    check[a-1] += 1
    check[b-1] += 1

check.sort()

if check[0] == 1 == check[1] and check[2] == 2  == check[3]:
    print('YES')
else:
    print('NO')

Solution (Python):
loads = [input().split() for i in range(3)]

town = {
  "1":0,
  "2":0,
  "3":0,
  "4":0
}

hub_town = []
for load in loads:
  for t in load:
    town[t] += 1
    if town[t] == 2:
      if t not in hub_town:
        hub_town.append(t)


if len(hub_town) == 2:
  print("YES")
else:
  print("NO")

Solution (Python):




r = []
for i in range(3):
    ai,bi = map(int,input().split())
    r.append((ai,bi))


f = False


for p in range(1,5):
    cr = r[:]
    for i in range(3):
        for cai,cbi in cr:
            if cai == p :
                p = cbi
                cr.remove((cai,cbi))
                break
            elif cbi == p:
                p = cai
                cr.remove((cai,cbi))
                break
    if not cr :
        f = True
        break
if f:print("YES")
else:print("NO")

Solution (Python):
cnt = [0, 0, 0, 0]

for i in range(3):
    ab = list(map(int, input().split()))
    for j in ab:
        cnt[j-1] += 1

ans = 'YES'
if (cnt.count(2) == 2) and (cnt.count(1) == 2):
    print('YES')
else:
    print('NO')

Solution (Python):
aa=[list(map(int,input().split())) for _ in range(3)]

count=[0,0,0,0]
for i in range(1,5):
    for a in aa:
        count[i-1] += a.count(i)
print('YES' if count.count(0)==0 and count.count(3)==0 else 'NO')

Solution (Python):
t=[0,0,0,0,0]
for c in "123":
	a,b=map(int,input().split())
	t[a]+=1
	t[b]+=1
print("NO"if 3 in t else "YES")

Solution (Python):
l = [0, 0, 0, 0, 0]

for _ in range(3):
  for s in input().split():
    l[int(s)] += 1
    
l = sorted(l)
ans = [0, 1, 1, 2, 2]
if ans == l:
  print("YES")
else:
  print("NO")

Solution (Python):
import itertools

dests = set()
for i in range(3):
    a, b = map(int, input().split())
    dests.add((a, b))
    dests.add((b, a))

for routes in itertools.permutations(dests, 3):
    routes = list(routes)
    visited = {
        1: False,
        2: False,
        3: False,
        4: False,
    }
    last = None
    ok = True
    for route in routes:
        a, b = route
        if last is not None and last != a:
            ok = False
            break
        else:
            visited[a] = True
            visited[b] = True
            last = b
    if ok and False not in visited.values():
        print('YES')
        exit()

print('NO')
exit()

Solution (Python):
from collections import defaultdict

nodes = defaultdict(list)

for _ in [0]*3:
    node1, node2 = map(int, input().split())
    nodes[node1].append(node2)
    nodes[node2].append(node1)

for i in range(1, 5):
    stack = []
    visited = [False]*4
    stack.append(i)
    while len(stack) != 0:
        now = stack.pop(-1)
        visited[now-1] = True
        for i in nodes[now]:
            if not visited[i-1]:
                stack.append(i)
                break
    if all(visited):
        print('YES')
        exit(0)

print('NO')

Solution (Python):
a1, b1 = list(map(int, input().split()))
a2, b2 = list(map(int, input().split()))
a3, b3 = list(map(int, input().split()))

freq_dict = {'1': 0, '2': 0, '3': 0, '4': 0}
for value in [a1, b1, a2, b2, a3, b3]:
    freq_dict[str(value)] += 1



freq_2_count = 0
freq_1_count = 0
for value in freq_dict.values():
    if value == 2:
        freq_2_count += 1
    elif value == 1:
        freq_1_count += 1
if freq_1_count == 2 and freq_2_count == 2:
    print('YES')
else:
    print('NO')

Solution (Python):
L = list(map(int, input().split()))
L.extend(list(map(int, input().split())))
L.extend( list(map(int, input().split())))
num1 = L.count(1)
num2 = L.count(2)
num3 = L.count(3)
num4 = L.count(4)
LIST = [num1 %2,num2 %2,num3 %2,num4 %2]
if num1 / 2==0 and num2 / 2==0 and num3 /2==0 and num4 /2 == 0:
   print("YES")
elif  LIST.count(1)==2:
   print("YES")
else:
   print("NO")

Solution (Python):
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())

lis=[a1,a2,a3,b1,b2,b3]
n1=lis.count(1)
n2=lis.count(2)
n3=lis.count(3)
n4=lis.count(4)
lis2=(n1,n2,n3,n4)
if 3 in lis2:
    print("NO")
else:
    print("YES")

Solution (Python):
s = input()
s += input()
s += input()

q = [0,0,0,0]
q[0] = s.count("1")
q[1] = s.count("2")
q[2] = s.count("3")
q[3] = s.count("4")
q.sort()

if(q == [1,1,2,2]):
    print("YES")
else:
    print("NO")

Solution (Python):
import numpy as np
from collections import defaultdict

a1,b1=map(int, input().split())  
a2,b2=map(int, input().split())  
a3,b3=map(int, input().split())  



map_dict  = defaultdict(list)
map_dict[a1].append(b1)
map_dict[b1].append(a1)
map_dict[a2].append(b2)
map_dict[b2].append(a2)
map_dict[a3].append(b3)
map_dict[b3].append(a3)


res = 0
cnt = 0
for m in map_dict:
    if len(map_dict[m]) >= 3:
        res = -1
        break
    if len(map_dict[m]) >= 2:
        cnt += 1
        pass
    
if cnt >= 3:  res = -1

if res == -1:
    print("NO")
else:
    print("YES")

Solution (Python):
x=[]
x=input().split(" ")
a1=int(x[0])
b1=int(x[1])
y=[]
y=input().split(" ")
a2=int(y[0])
b2=int(y[1])
z=[]
z=input().split(" ")
a3=int(z[0])
b3=int(z[1])
X=[]
X.append(a1)
X.append(a2)
X.append(a3)
X.append(b1)
X.append(b2)
X.append(b3)
import collections
c=len(collections.Counter(X)) 
x1=X.count(1)
x2=X.count(2)
x3=X.count(3)
x4=X.count(4)
Z=x1*x2*x3*x4
if Z==4 :
    print("YES")
else :
    print("NO")

Solution (Python):
load = list()
for i in range(3):
  a, b = list(map(int, input().split()))
  load.append(a)
  load.append(b)
error = 0
for i in range(1, 5):
  if load.count(i) >= 3:
    error += 1
if error >= 1:
  print("NO")
else:
  print("YES")

Solution (Python):
city={}
result=True

for i in range(4):
    city[i]=0

for i in range(3):
    a,b=map(int,input().split())
    a-=1
    b-=1
    city[a]+=1
    city[b]+=1

for i in range(4):
    if(2<city[i]):
        result=False

if(result):
    print('YES')
else:
    print('NO')

Solution (Python):
town = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]

for i in range(3):
    path = list(map(int,input().split()))
    town[path[0]-1][path[1]-1] = 1
    town[path[1]-1][path[0]-1] = 1

ans = 0
for i in town:
    cnt = 0
    for t in i:
        if t == 1:
            cnt += 1
    if cnt == 2:
        ans += 1
if ans == 2:
    print("YES")
else:
    print("NO")

Solution (Python):


ab = [None] * 3
for i in range(3):
    ab[i] = input().split()

a = ab[0][0]
b = ab[0][1]

if (a in ab[1] and a in ab[2]) or (b in ab[1] and b in ab[2]):
    print("NO")
else:
    print("YES")

Solution (Python):
counter = []
for i in range(3):
    a, b = map(int, input().split())
    counter.append(a)
    counter.append(b)
ans = "YES"
if counter.count(1) >= 3 or counter.count(2) >= 3 or counter.count(3) >= 3 or counter.count(4) >= 3:
    ans = "NO"
print(ans)

Solution (Python):
a=""

for i in range(3):
    a+=(str(input()))

error=0
for i in range(4):
    if a.count(str(i+1))>2:
        error=1
    

    
    
if error==0:
    print("YES")
else:
    print("NO")

Solution (Python):
path = []
for _ in range(3):
	a, b = map(int, input().split(" "))
	path.append([a,b])


a = [0, 0, 0, 0]
for line in path:
	for d in line:
		a[d - 1] += 1

if sorted(a) == [1,1,2,2]:
	print('YES')
else:
	print('NO')

Solution (Python):
path1 = list(map(int, input().split()))
path2 = list(map(int, input().split()))
path3 = list(map(int, input().split()))

path = path1 + path2 + path3
path.sort()

S = []
for i in range(5):
    if path[i] == path[i+1]:
            S += [path[i]]

if len(S) != 2:
    print('NO')
elif S[0] == S[1]:
    print('NO')
else:
    path.pop(S[0])
    path.pop(S[1])
    if path != [1,2,3,4]:
        print('NO')
    else:
        print('YES')

Solution (Python):
S = [input().split() for _ in range(3)]
count1 = 0
count2 = 0
count3 = 0
count4 = 0
for i in range(3):
    count1 += S[i].count('1')
    count2 += S[i].count('2')
    count3 += S[i].count('3')
    count4 += S[i].count('4')
set = {count1,count2,count3,count4}
if set == {1,1,2,2}:
    print('YES')
else:
    print('NO')

Solution (Python):
from itertools import permutations
Road = [[int(i) for i in input().split()] for j in range(3)]

graph = [[float('inf')] * 4 for _ in range(4)]
for a, b in Road:
    graph[a - 1][b - 1] = 1
    graph[b - 1][a - 1] = 1

ans = 'NO'
for v in permutations([0, 1, 2, 3], 4):
    for i in range(3):
        if graph[v[i]][v[i + 1]] != 1:
            break
    else:
        ans = 'YES'
        break
print(ans)

Solution (Python):
X = []
for i in range(3):
    X.append(input().split())
a1 = 0
a2 = 0
a3 = 0
a4 = 0
for i in X:
    for j in i:
        if j == "1":
            a1 += 1
        elif j == "2":
            a2 += 1
        elif j == "3":
            a3 += 1
        elif j == "4":
            a4 += 1
if 1<= a1 <= 2 and 1<= a2 <= 2 and 1<= a3 <= 2 and 1<= a4 <= 2:
    print("YES")
else:
    print("NO")

Solution (Python):
a = []
result = "YES"
for i in range(3) :
    a.extend(input().split(" "))

for i in range(1,5) :
    if a.count(str(i)) >= 3 or a.count(str(i)) == 0:
        result = "NO"
        break
    
print(result)

Solution (Python):
A,B = map(int, input().split(" "))

C,D = map(int, input().split(" "))

E,F = map(int, input().split(" "))


cnt1=0
cnt2=0
cnt3=0
cnt4=0

if A==1:
    cnt1 = cnt1 + 1
elif A==2:
    cnt2 = cnt2 + 1
elif A == 3:
    cnt3 = cnt3 + 1
elif A == 4:
    cnt4 = cnt4 + 1

if B==1:
        cnt1 = cnt1 + 1
elif B==2:
    cnt2 = cnt2 + 1
elif B == 3:
    cnt3 = cnt3 + 1
elif B == 4:
    cnt4 = cnt4 + 1

if C==1:
        cnt1 = cnt1 + 1
elif C==2:
    cnt2 = cnt2 + 1
elif C == 3:
    cnt3 = cnt3 + 1
elif C == 4:
    cnt4 = cnt4 + 1

if D==1:
        cnt1 = cnt1 + 1
elif D==2:
    cnt2 = cnt2 + 1
elif D == 3:
    cnt3 = cnt3 + 1
elif D == 4:
    cnt4 = cnt4 + 1

if E==1:
        cnt1 = cnt1 + 1
elif E==2:
    cnt2 = cnt2 + 1
elif E == 3:
    cnt3 = cnt3 + 1
elif E == 4:
    cnt4 = cnt4 + 1

if F==1:
        cnt1 = cnt1 + 1
elif F==2:
    cnt2 = cnt2 + 1
elif F == 3:
    cnt3 = cnt3 + 1
elif F == 4:
    cnt4 = cnt4 + 1









flg = 1

if cnt1 >=3:
    flg = 0

if cnt2 >=3:
    flg = 0

if cnt3 >=3:
    flg = 0

if cnt4 >=3:
    flg = 0

if flg ==0:
    print("NO")
else:
    print("YES")

Solution (Python):
d = [0 for _ in range(4)]

for i in range(3):
    a, b = map(int, input().split())
    d[a-1] += 1
    d[b-1] += 1

count = 0
for i in range(4):
    if d[i] % 2 == 1:
        count += 1

if count > 2:
    print('NO')
else:
    print('YES')

Solution (Python):
x = [0]*6
x[0],x[1] = [int(_) for _ in input().split()]
x[2],x[3] = [int(_) for _ in input().split()]
x[4],x[5] = [int(_) for _ in input().split()]

if 1 <= x.count(1) <=2 and 1 <= x.count(2) <=2 and 1 <= x.count(3) <=2 and 1 <= x.count(4) <=2:
    print("YES")
else:
    print("NO")

Solution (Python):
a, b = map(int,input().split())
c, d = map(int,input().split())
e, f = map(int,input().split())
lst = []
lst.extend([a, b, c, d, e, f])
lst.sort()
count = 0
for i in range(1, 5, 1):
    if lst[i - 1] == lst[i] and lst[i] != lst[i + 1]:
        count += 1
if count == 2:
    print("YES")
else:
    print("NO")

Solution (Python):
t = [0, 0, 0, 0]
for i in range(3):
    (a, b) = map(int, input().split())
    t[a-1] += 1
    t[b-1] += 1
if t.count(1)==2 and t.count(2)==2:
    print('YES')
else:
    print('NO')

Solution (Python):
import numpy as np

def judge(c,s_g):

    start=s_g[0]
    goal=s_g[1]
    second=-2
    third=-7

    for i in range(6):
        if c[i]==start:
            c[i]=-1
            if i%2==0:
                second=c[i+1]
                c[i+1]=-1
            else:
                second=c[i-1]
                c[i-1]=-1
            break
    else:
        print("No")
        return 0

    for i in range(6):
        if c[i]==second:
            c[i]=-1
            if i%2==0:
                third=c[i+1]
                c[i+1]=-1
            else:
                third=c[i-1]
                c[i-1]=-1
            break
    else:
        print("No")
        return 0
            
    for i in range(6):
        if c[i]==third:
            if i%2==0:
                if c[i+1]==goal:
                    print("YES")
                    return 0
                else:
                    print("NO")
                    return 0
            else:
                if c[i-1]==goal:
                    print("YES")
                    return 0
                else:
                    print("NO")
                    return 0
            break
    else:
        print("NO")
        return 0
                
    if second==-2 or third==-7:
        print("NO")
        return 0

a=np.zeros(3)
b=np.zeros(3)
c=np.zeros(6)
for i in range(3):
    s,t=list(map(int,input().split()))
    a[i]=s
    b[i]=t
    c[2*i]=s
    c[2*i+1]=t
    
s_g=[]
for i in range(1,5):
    if np.sum(c==i)==1:
        index=np.where(c==i)
        s_g.append(i) 
i=judge(c,s_g)

Solution (Python):
array = [input().split() for l in range(3)]
list =[0, 0, 0, 0]

for i in range(3):
    for j in range(2):
        list[int(array[i][j])-1] += 1

if max(list) == 3:
    print("NO")
else:
    print("YES")

Solution (Python):
import sys

ab = [[False] * 5 for _ in range(5)]
for _ in range(3):
    a, b = map(int, input().split())
    ab[a][b] = True
    ab[b][a] = True

for i in (1, 2, 3, 4):
    for j in (1, 2, 3, 4):
        for k in (1, 2, 3, 4):
            for l in (1, 2, 3, 4):
                if len(set((i, j, k, l))) < 4:
                    continue
                if not ab[i][j]:
                    continue
                if not ab[j][k]:
                    continue
                if not ab[k][l]:
                    continue
                print("YES")
                sys.exit()
print("NO")

Solution (Python):
a = input().split()
b = input().split()
c = input().split()

road = [a,b,c]
c = [0,0,0,0]

for r in road:
    if "1" in r:
        c[0] += 1

    if "2" in r:
        c[1] += 1

    if "3" in r:
        c[2] += 1

    if "4" in r:
        c[3] += 1

c.sort()

if c == [1,1,2,2]:
    print("YES")
else:
    print("NO")

Solution (Python):
path = []
for _ in range(3):
    a, b = map(int, input().split())
    path.append((a, b))

def g(cur, lt, lp):
    if not lp or not lt:
        return not lp and not lt

    for nt in lt:
        if (cur, nt) in lp:
            lpc = lp.copy()
            lpc.remove((cur, nt))
            ltc = lt.copy()
            ltc.remove(nt)
            if g(nt, ltc, lpc):
                return True
        elif (nt, cur) in lp:
            lpc = lp.copy()
            lpc.remove((nt, cur))
            ltc = lt.copy()
            ltc.remove(nt)
            if g(nt, ltc, lpc):
                return True
    return False

def f():
    for i in range(1, 5):
        lt = list(range(1, 5))
        lt.remove(i)
        if g(i, lt, path):
            return True
    return False

print("YES" if f() else "NO")

Solution (Python):


ANS=[0]*4
ans='NO'
for i in range(3):
    a,b=map(int,input().split())
    if a==1:
        ANS[0]+=1
    elif a==2:
        ANS[1]+=1
    elif a==3:
        ANS[2]+=1
    elif a==4:
        ANS[3]+=1

    if b==1:
        ANS[0]+=1
    elif b==2:
        ANS[1]+=1
    elif b==3:
        ANS[2]+=1
    elif b==4:
        ANS[3]+=1

if ANS.count(1)==2 and ANS.count(2)==2:
    ans='YES'

print(ans)

Solution (Python):
city = [0, 0, 0, 0]
for i in range(3):
    a, b = ([int(x)-1 for x in input().split()])
    city[a] += 1
    city[b] += 1
    if city[a] > 2 or city[b] > 2:
        print('NO')
        exit()

print('YES')

Solution (Python):

a1, b1 = map(int, input().split())
a2, b2 = map(int, input().split())
a3, b3 = map(int, input().split())

patterns = [[(a1, a2, a3), (b1, b2, b3)],
            [(b1, a2, a3), (a1, b2, b3)],
            [(a1, b2, a3), (b1, a2, b3)],
            [(a1, a2, b3), (b1, b2, a3)],
            [(b1, b2, a3), (a1, a2, b3)],
            [(b1, a2, b3), (a1, b2, a3)],
            [(a1, b2, b3), (b1, a2, a3)],
            [(b1, b2, b3), (a1, a2, a3)]]

for pattern in patterns:
    set1 = set(pattern[0])
    set2 = set(pattern[1])
    if len(set1) == 3 and len(set2) == 3:
        print('YES')
        exit()

print('NO')

Solution (Python):
path = []
for i in range(3):
    path.extend(list(map(int, input().split())))
res = []
for i in range(1,5):
    res.append(path.count(i))
if res.count(1) == 2 and res.count(2) == 2:
    print("YES")
else:
    print("NO")

Solution (Python):
from collections import Counter
road = Counter([j for i in range(3) for j in input().split()])
print("YNEOS"[road.most_common(1)[0][1] > 2::2])

Solution (Python):
a = [0 for i in range(6)]
b = [0 for i in range(6)]

for i in range(3):
    a[i], b[i] = map(int, input().split())
    a[i + 3] = b[i]
    b[i + 3] = a[i]

yes = False
for i in range(6):
    for j in range(6):
        for k in range(6):
            if i == j or j == k or i == k:
                continue
            
            if set([a[i],b[i],a[j],b[j],a[k],b[k]]) == {1,2,3,4}:
                if b[i] == a[j] and b[j] == a[k] and a[i] != b[k]:
                    yes = True
                    break

if yes:
    print("YES")
else:
    print("NO")

Solution (Python):
one=0
two=0
three=0
four=0
cnt=[]
for _ in range(3):
  ab=list(map(int,input().split()))
  one+=ab.count(1)
  two+=ab.count(2)
  three+=ab.count(3)
  four+=ab.count(4)
cnt+=[one,two,three,four]
if cnt.count(1)==2 and cnt.count(2)==2:
  print("YES")
else:
  print("NO")

Solution (Python):
path1 = [int(x) for x in input().split(' ')]
path2 = [int(x) for x in input().split(' ')]
path3 = [int(x) for x in input().split(' ')]

path1.sort()
path2.sort()
path3.sort()

result = True

allpath = path1 + path2 + path3
for i in [1,2,3,4]:
    if i not in allpath:
        result = False
    if allpath.count(i) == 3:
        result = False

if result:
    print('YES')
else:
    print('NO')

Solution (Python):
l=[]
for i in range(3):
    a,b=map(int,input().split())
    l.append(a)
    l.append(b)
l.sort()
if l[0]!=l[1] and l[1]!=l[2] and l[2]==l[3] and l[3]!=l[4] and l[4]==l[5]:
    print("YES")
elif l[0]!=l[1] and l[1]==l[2] and l[2]!=l[3] and l[3]==l[4] and l[4]!=l[5]:
    print("YES")
elif l[0]==l[1] and l[1]!=l[2] and l[2]==l[3] and l[3]!=l[4] and l[4]!=l[5]:
    print("YES")
else:
    print("NO")

Solution (Python):

import itertools
N = [1, 2, 3, 4]
abn = [list(map(int, input().split())) for _ in range(3)]
map = [[0 for _ in range(4)] for _ in range(4)]

for a,b in abn:
    map[a-1][b-1] = 1
    map[b-1][a-1] = 1

for path in itertools.permutations(N, 4):
    ans = True
    for i in range(3):
        if map[path[i]-1][path[i+1]-1] == 0:
            ans = False

    if ans == True:
        print("YES")
        exit()

print("NO")

Solution (Python):
A = sorted([int(i) for i in input().split()])
B = sorted([int(i) for i in input().split()])
C = sorted([int(i) for i in input().split()])
k = 0
if A[1] - A[0] == 2:
    k += 1
if B[1] - B[0] == 2:
    k += 1
if C[1] - C[0] == 2:
    k += 1

if k == 1:
    print("NO")
else:
    print("YES")

Solution (Python):

"""
https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_a
"""

from collections import defaultdict
def sol(a1, b1, a2, b2, a3, b3):
    S = [a1, b1, a2, b2, a3, b3]
    d = defaultdict(int)
    for s in S:
        d[s] += 1
    if len(d) == 4:
        num2 = 0
        for k, v in d.items():
            if v == 2:
                num2 += 1
        if num2 == 2:
            return 'YES'
    return 'NO'


test = False

if test:

    print(sol(4, 2, 1, 3, 2, 3))
    print(sol(3, 2, 2,4,1,2))
    print(sol(2,1,3,2,4,3))


    
    
    
    
    
    
    
    
    
    
    

else:
    
    a1, b1 =list( map(int, input().split()))
    a2, b2 =list( map(int, input().split()))
    a3, b3 =list( map(int, input().split()))
    print(sol(a1, b1, a2, b2, a3, b3))

Solution (Python):
A = [[0, 0]] + [[int(i) for i in input().split()] for j in range(3)]
V = [[] for i in range(5)]

for a, b in A:
    V[a].append(b)
    V[b].append(a)

print('NO' if any(len(v) == 3 for v in V) else 'YES')

Solution (Python):
AB = [[int(i) for i in input().split()] for i in range(3)] 
A =[]
for i in range(3):
    A.append(AB[i][0])
    A.append(AB[i][1])
A.sort()
flag = 0
X = 0
tmp = 0
for i in A:
    if tmp == i:
        flag += 1
        if flag == 2:
            X = -1
    else:
        flag=0
    tmp = i

if X == -1:
    print("NO")
else:
    print("YES")