Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane getting into the intersection (l — left, s — straight, r — right) and a light p for a pedestrian crossing.  [Image] 

An accident is possible if a car can hit a pedestrian. This can happen if the light of a pedestrian crossing of some part and the light of a lane that can get to or from that same part are green at the same time.

Now, Sagheer is monitoring the configuration of the traffic lights. Your task is to help him detect whether an accident is possible.


-----Input-----

The input consists of four lines with each line describing a road part given in a counter-clockwise order.

Each line contains four integers l, s, r, p — for the left, straight, right and pedestrian lights, respectively. The possible values are 0 for red light and 1 for green light.


-----Output-----

On a single line, print "YES" if an accident is possible, and "NO" otherwise.


-----Examples-----
Input
1 0 0 1
0 1 0 0
0 0 1 0
0 0 0 1

Output
YES

Input
0 1 1 0
1 0 1 0
1 1 0 0
0 0 0 1

Output
NO

Input
1 0 0 0
0 0 0 1
0 0 0 0
1 0 1 0

Output
NO



-----Note-----

In the first example, some accidents are possible because cars of part 1 can hit pedestrians of parts 1 and 4. Also, cars of parts 2 and 3 can hit pedestrians of part 4.

In the second example, no car can pass the pedestrian crossing of part 4 which is the only green pedestrian light. So, no accident can occur.

Difficulty: interview

Starter code:

Solutions:
lanes = []

for i in range(4):
    lanes.append(list(map(int, input().split())))

lanes.extend(lanes)

for i in range(4):
    ln = lanes[i]
    if (ln[3] and (ln[0] or ln[1] or ln[2])) or \
            (ln[0] and lanes[i + 3][3]) or \
            (ln[1] and lanes[i + 2][3]) or \
            (ln[2] and lanes[i + 1][3]):
        print('YES')
        break
else:
    print('NO')

L = [0, 4, 1, 2, 3]
R = [0, 2, 3, 4, 1]
S = [0, 3, 4, 1, 2]

H = [0, 0, 0, 0, 0]
P = H[:]
for i in range(1, 5):
    l, s, r, p = list(map(int, input().split()))
    P[i] = p
    if 1 in [l, s, r]:
        H[i] = 1
    if l:
        H[L[i]] = 1
    if s:
        H[S[i]] = 1
    if r:
        H[R[i]] = 1
ans = "NO"
for i in range(1, 5):
    if P[i] and H[i]:
        ans = "YES"
print(ans)



def booly(s):
    return bool(int(s))

a = [None]*4;
a[0] = list(map(booly, input().split()))
a[1] = list(map(booly, input().split()))
a[2] = list(map(booly, input().split()))
a[3] =list( map(booly, input().split()))

acc = False

for i in range(4):
    if (a[i][3] and (a[i][0] or a[i][1] or a[i][2])):
        acc = True

    if (a[i][3] and a[(i+1)%4][0]):
        acc = True
        
    if (a[i][3] and a[(i-1)%4][2]):
        acc = True

    if (a[i][3] and a[(i+2)%4][1]):
        acc = True

if acc:
    print("YES");
else:
    print("NO");


p = [list(map(int, input().split())) for i in range(4)]
log = False
for i in range(4):
    if p[i][3] == 1 and (p[i - 1][2] + p[(i + 1) % 4][0] + p[(i + 2) % 4][1] + p[i][1] + p[i][0] + p[i][2] > 0):
        log = True
if log:
    print("YES")
else:
    print("NO")



a, b, c, d = [], [], [], []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
st = False
if a[3] == 1:
    if 1 in a[:3] or b[0] or c[1] or d[2]:
        st = True
if b[3] == 1:
    if 1 in b[:3] or a[2] or c[0] or d[1]:
        st = True
if c[3] == 1:
    if 1 in c[:3] or a[1] or b[2] or d[0]:
        st = True
if d[3] == 1:
    if 1 in d[:3] or a[0] or b[1] or c[2]:
        st = True
print('YES' if st else 'NO')


arr = [list() for i in range(4)]
arrp = []
for i in range(4):
    l, s, r, p = [int(i) for i in input().split()]
    arr[i].extend([l, s, r])
    arr[[3, i - 1][i > 0]].append(l)
    arr[[0, i + 1][i < 3]].append(r)
    arr[(i + 2) % 4].append(s)
    arrp.append(p)
for i in range(4):
    if arrp[i]:
        if 1 in arr[i]:
            print('YES')
            break
else:
    print('NO')


l = []
for i in range(4):
    l.append(list(map(int, input().split())))

def go():
    for i in range(4):
        if l[i][3] and (l[(i + 1) % 4][0] or l[(i + 3) % 4][2] or l[(i + 2) % 4][1] or l[i][0] or l[i][1] or l[i][2]):
            return False
    return True

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


import sys

input = sys.stdin.readline

roads = []

for i in range(4):
    roads.append([int(x) for x in input().split()])

clock = {}
cclock = {}
opp = {}

clock[0] = 1
clock[1] = 2
clock[2] = 3
clock[3] = 0

cclock[1] = 0
cclock[2] = 1
cclock[3] = 2
cclock[0] = 3

opp[0] = 2
opp[1] = 3
opp[2] = 0
opp[3] = 1

for i in range(4):
    road = roads[i]
    if road[3] == 1:
        if road[0] == 1 or road[1] == 1 or road[2] == 1:
            print("YES")
            break
        left = roads[cclock[i]]
        right = roads[clock[i]]
        straight = roads[opp[i]]
        if left[2] == 1 or right[0] == 1 or straight[1] == 1:
            print("YES")
            break
else:
    print("NO")

def main():
    l1, s1, r1, p1 = map(int, input().split())
    l2, s2, r2, p2 = map(int, input().split())
    l3, s3, r3, p3 = map(int, input().split())
    l4, s4, r4, p4 = map(int, input().split())
    if p1 == 1:
        if s1 == 1 or l1 == 1 or r1 == 1 or s3 == 1 or l2 == 1 or r4 == 1:
            return "YES"
    if p2 == 1:
        if s2 == 1 or l2 == 1 or r2 == 1 or s4 == 1 or l3 == 1 or r1 == 1:
            return "YES"
    if p3 == 1:
        if s3 == 1 or l3 == 1 or r3 == 1 or s1 == 1 or l4 == 1 or r2 == 1:
            return "YES"
    if p4 == 1:
        if s4 == 1 or l4 == 1 or r4 == 1 or s2 == 1 or l1 == 1 or r3 == 1:
            return "YES"
    return "NO"
print(main())

L = [list(map(int, input().split())) for _ in range(4)]
for i in range(4):
    p = L[i][3]
    if p == 1:
        if i == 0:
            if L[0][0] == 1 or L[0][1] == 1 or L[0][2] == 1 or L[1][0] == 1 or L[2][1] == 1 or L[3][2] == 1:
                print("YES")
                return
        elif i == 1:
            if L[0][2] == 1 or L[1][0] == 1 or L[1][1] == 1 or L[1][2] == 1 or L[2][0] == 1 or L[3][1] == 1:
                print("YES")
                return
        elif i == 2:
            if L[0][1] == 1 or L[1][2] == 1 or L[2][0] == 1 or L[2][1] == 1 or L[2][2] == 1 or L[3][0] == 1:
                print("YES")
                return
        else:
            if L[0][0] == 1 or L[1][1] == 1 or L[2][2] == 1 or L[3][0] == 1 or L[3][1] == 1 or L[3][2] == 1:
                print("YES")
                return
print("NO")


def main():
    a = []
    for i in range(4):
        a.append(tuple(map(int, input().split())))

    car = [0] * 4

    for i, (l, s, r, p) in enumerate(a):

        car[i] += l
        car[(i - 1) % 4] += l

        car[i] += r
        car[(i + 1) % 4] += r

        car[i] += s
        car[(i + 2) % 4] += s

    for i in range(4):
        if car[i] > 0 and a[i][3] == 1:
            print("YES")
            return

    print("NO")


def __starting_point():
    main()

__starting_point()

a = [[int(i) for i in input().split()] for j in range(4)]

pesh = [0] * 4
avt = [0] * 4

for i in range(len(a)):
    if a[i][3]:
        pesh[i] = True
    if a[i][0]:
        avt[(i - 1) % 4] = True
        avt[i] = True
    if a[i][1]:
        avt[(i + 2) % 4] = True
        avt[i] = True
    if a[i][2]:
        avt[(i + 1) % 4] = True
        avt[i] = True

for i in range(4):
    if avt[i] and pesh[i]:
        print("YES")
        break
else:
    print("NO")


#!/usr/bin/env python3
import sys

ls = []
ss = []
rs = []
ps = []

for __ in range(4):
    l, s, r, p = [int(elem) == 1 for elem in sys.stdin.readline().split()]
    ls.append(l)
    ss.append(s)
    rs.append(r)
    ps.append(p)

def get(ary, indx):
    return ary[indx % 4]

accident = False

for indx in range(4):
    accident |= (ls[indx] or rs[indx] or ss[indx]) and ps[indx]
    accident |= ls[indx] and get(ps, indx - 1)
    accident |= ss[indx] and get(ps, indx + 2)
    accident |= rs[indx] and get(ps, indx + 1)

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


L, S, R, P = 0, 1, 2, 3
tr = []

for i in range(4):
	tr.append([int(x) for x in input().split()])

acc = False

for i in range(4):
	# check l 
	if tr[i][L] == 1 and (tr[i][P] == 1 or tr[(i+3)%4][P] == 1):
		acc = True
		break
	if tr[i][S] == 1 and (tr[i][P] == 1 or tr[(i+2)%4][P] == 1):
		acc = True
		break
	if tr[i][R] == 1 and (tr[i][P] == 1 or tr[(i+1)%4][P] == 1):
		acc = True
		break

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

# 500

S=[]
for i in range(0,4):
    S.append([bool(int(x)) for x in input().split()])
def check():
    for i in range (0,4):
        for x in range(0,3):
            if S[i][x] and (S[(i+abs(x-3))%4][3] or S[i][3]):
                print("YES")
                return

    print("NO")

check()


l,s,r,p = list(map(int,input().split()))
l2,s2,r2,p2 = list(map(int,input().split()))
l3,s3,r3,p3 = list(map(int,input().split()))
l4,s4,r4,p4 = list(map(int,input().split()))
if (l + s + r > 0 and p == 1) or (l2 + s2 + r2 > 0 and p2 == 1) or (l3 + s3 + r3 > 0 and p3 == 1) or (l4 + s4 + r4 > 0 and p4 == 1):
    print("YES")
else:
    if(l2 + s3 + r4 > 0 and p == 1) or (l3 + s4 + r > 0 and p2 == 1) or (l4 + s + r2 > 0 and p3 == 1) or (l + s2 + r3 > 0 and p4 == 1):
        print("YES")
    else:
        print("NO")


l = [0] * 4
s = [0] * 4
r = [0] * 4
p = [0] * 4
for i in range(4):
    l[i], s[i], r[i], p[i] = map(int ,input().split())
error = 0
for i in range(4):
    if (l[i] + s[i] + r[i] > 0) and (p[i] == 1):
        error += 1
for i in range(4):
    j = 0
    if p[j] == 1:
        if (r[j + 3] == 0) and (s[j + 2] == 0) and (l[j + 1] == 0):
            error += 0
        else:
            error += 1
    l.append(l[j])
    l.pop(0)
    s.append(s[j])
    s.pop(0)
    r.append(r[j])
    r.pop(0)
    p.append(p[j])
    p.pop(0)
if error > 0:
    print('YES')
else:
    print('NO')

S = []
res = "NO"
for i in range(4):
    S.append(list(map(int, input().split())))
for i in range(4):
    p = sum(S[i]) - S[i][3] + S[(i + 1) % 4][0] + S[(i + 2) % 4][1] + S[(i + 3) % 4][2]
    if p > 0 and S[i][3] == 1:
        res = "YES"
        break
print(res)

#A

a=input().split()
b=input().split()
c=input().split()
d=input().split()

lights=[a, b, c, d]

for i in range(0, 4):
    if int(lights[i][3])==1:
        if int(lights[i][0])==1 or int(lights[i][1])==1 or int(lights[i][2])==1:
            print("YES")
            break
        if i==0:
            if int(lights[1][0])==1 or int(lights[2][1])==1 or int(lights[3][2])==1:
                print("YES")
                break
        if i==1:
            if int(lights[2][0])==1 or int(lights[3][1])==1 or int(lights[0][2])==1:
                print("YES")
                break
        if i==2:
            if int(lights[3][0])==1 or int(lights[0][1])==1 or int(lights[1][2])==1:
                print("YES")
                break
        if i==3:
            if int(lights[0][0])==1 or int(lights[1][1])==1 or int(lights[2][2])==1:
                print("YES")
                break
    if i==3:
        print("NO")


actual_vals = [0 for x in range(4)]
required_vals = [1 for x in range(4)]
l1,s1,r1,p1 = list(map(int,input().split()))
if(l1==1):
	required_vals[3] = 0
if(s1==1):
	required_vals[2] = 0
if(r1==1):
	required_vals[1] = 0
if(l1==1 or r1==1 or s1==1):
	required_vals[0] = 0
actual_vals[0] = p1

l2,s2,r2,p2 = list(map(int,input().split()))
if(l2==1):
	required_vals[0] = 0
if(s2==1):
	required_vals[3] = 0
if(r2==1):
	required_vals[2] = 0
if(l2==1 or r2==1 or s2==1):
	required_vals[1] = 0
actual_vals[1] = p2

l3,s3,r3,p3 = list(map(int,input().split()))
if(l3==1):
	required_vals[1] = 0
if(s3==1):
	required_vals[0] = 0
if(r3==1):
	required_vals[3] = 0
if(l3==1 or r3==1 or s3==1):
	required_vals[2] = 0
actual_vals[2] = p3

l4,s4,r4,p4 = list(map(int,input().split()))
if(l4==1):
	required_vals[2] = 0
if(s4==1):
	required_vals[1] = 0
if(r4==1):
	required_vals[0] = 0
if(l4==1 or r4==1 or s4==1):
	required_vals[3] = 0
actual_vals[3] = p4

for i in range(4):
	if(required_vals[i]==0 and actual_vals[i]==1):
		print('YES')
		return
print('NO')


a=[]
for i in range(4):
    a.append([int(i) for i in input().split()])
for i in range(4):
    if a[i][3]==1:
        if any([a[i][0],a[i][1],a[i][2],a[(i+1)%4][0],a[(i+2)%4][1],a[(i+3)%4][2]]):
            print("YES")
            break
else:
    print("NO")


l1, s1, r1, p1 = list(map(int, input().split()))
l2, s2, r2, p2 = list(map(int, input().split()))
l3, s3, r3, p3 = list(map(int, input().split()))
l4, s4, r4, p4 = list(map(int, input().split()))

if (p1 and (r1 or s1 or l1 or r4 or l2 or s3)) or (p2 and (r2 or s2 or l2 or l3 or r1 or s4)) or \
   (p3 and (r3 or s3 or l3 or l4 or r2 or s1)) or\
   (p4 and (r4 or s4 or l4 or l1 or r3 or s2)):
    print('YES')
else:
    print('NO')


list2=[]
for i in range(4):
    list1=list(map(int,input().strip().split(' ')))
    list2.append(list1)
if list2[0][3]==1:
    if list2[1][0]==1 or list2[2][1]==1 or list2[3][2]==1 or list2[0][1]==1 or list2[0][2]==1 or list2[0][0]==1:
        print("YES")
        return
if list2[1][3]==1:
    if list2[0][2]==1 or list2[2][0]==1 or list2[3][1]==1 or list2[1][1]==1 or list2[1][2]==1 or list2[1][0]==1:
        print("YES")
        return
if list2[2][3]==1:
    if list2[0][1]==1 or list2[1][2]==1 or list2[3][0]==1 or list2[2][1]==1 or list2[2][2]==1 or list2[2][0]==1:
        print("YES")
        return
if list2[3][3]==1:
    if list2[0][0]==1 or list2[1][1]==1 or list2[2][2]==1 or list2[3][1]==1 or list2[3][2]==1 or list2[3][0]==1:
        print("YES")
        return
print("NO")

# left, strait, right, pedastrian
#   3
#4     2
#   1
def check_if_safe(curr_part, left_part, right_part, opposite_part):
    curr_left, curr_straight, curr_right, curr_pedastrian = curr_part
    if curr_pedastrian == 0:
        return True
    elif (curr_left + curr_right + curr_straight) > 0:
        return False
    left_left, left_straight, left_right, left_pedastrian = left_part
    if left_right == 1:
        return False
    right_left, right_straight, right_right, right_pedastrian = right_part
    if right_left == 1:
        return False
    opposite_left, opposite_straight, opposite_right, opposite_pedastrian = opposite_part
    if opposite_straight == 1:
        return False
    return True


part_one = [int(x) for x in input().split()]
part_two = [int(x) for x in input().split()]
part_three = [int(x) for x in input().split()]
part_four = [int(x) for x in input().split()]

ans = ( check_if_safe(part_one, part_four, part_two, part_three)
      + check_if_safe(part_two, part_one, part_three, part_four)
      + check_if_safe(part_three, part_two, part_four, part_one)
      + check_if_safe(part_four, part_three, part_one, part_two)
      )
if ans != 4:
    print('YES')
else:
    print('NO')