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.

Source: codeforces | Difficulty: EASY
Tags: Implementation


Solutions:
import sys
t = 'NO'
r = []
for i in range(4):
	r.append(list(map(int, sys.stdin.readline().split())))
for i in range(4):
	for j in range(3):
		if r[i][j] == 1:
			if j == 0:
				if r[i][3] == 1:
					t = 'YES'
					break
				if r[i - 1][3] == 1:
					t = 'YES'
					break
			elif j == 1:
				if r[i][3] == 1:
					t = 'YES'
					break
				if r[(i + 2) % 4][3] == 1:
					t = 'YES'
					break
			else:
				if r[(i + 1) % 4][3] == 1:
					t = 'YES'
					break
				if r[i][3] == 1:
					t = 'YES'
					break
sys.stdout.write(t)


read = lambda : map(int, input().split())
a = [list(read()) for i in range(4)]
for i in range(4):
	if a[i][3] and (sum(a[i][:3]) or sum((a[(i + j + 1) % 4][j] for j in range(3)))):
		print('YES')
		break
else:
	print('NO')


import sys
ls = []
ss = []
rs = []
ps = []
for __ in range(4):
	(l, s, r, p) = map(lambda elem: int(elem) == 1, 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')


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


(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())
e = 0
if p1 == 1:
	if l1 == 1 or s1 == 1 or r1 == 1 or (l2 == 1) or (s3 == 1) or (r4 == 1):
		e = 1
if p2 == 1:
	if l2 == 1 or s2 == 1 or r2 == 1 or (l3 == 1) or (s4 == 1) or (r1 == 1):
		e = 1
if p3 == 1:
	if l3 == 1 or s3 == 1 or r3 == 1 or (s1 == 1) or (r2 == 1) or (l4 == 1):
		e = 1
if p4 == 1:
	if l4 == 1 or s4 == 1 or r4 == 1 or (l1 == 1) or (s2 == 1) or (r3 == 1):
		e = 1
if e == 1:
	print('YES')
else:
	print('NO')


a = []
for i in range(4):
	a.append(input().replace(' ', ''))
for i in range(4):
	if a[i][3] == '1' and a[i][:3].count('1') > 0:
		print('YES')
		exit()
for i in range(4):
	if a[i][3] == '1':
		for j in range(1, 4):
			if a[(i + j) % 4][j - 1] == '1':
				print('YES')
				exit()
print('NO')


import sys
arr = list(map(int, input().split()))
(l1, s1, r1, p1) = (arr[0], arr[1], arr[2], arr[3])
arr1 = list(map(int, input().split()))
(l2, s2, r2, p2) = (arr1[0], arr1[1], arr1[2], arr1[3])
arr2 = list(map(int, input().split()))
(l3, s3, r3, p3) = (arr2[0], arr2[1], arr2[2], arr2[3])
arr3 = list(map(int, input().split()))
(l4, s4, r4, p4) = (arr3[0], arr3[1], arr3[2], arr3[3])
if p1 == 1 and (l1 == 1 or s1 == 1 or r1 == 1 or (l2 == 1) or (s3 == 1) or (r4 == 1)):
	print('YES')
elif p2 == 1 and (l2 == 1 or s2 == 1 or r2 == 1 or (r1 == 1) or (l3 == 1) or (s4 == 1)):
	print('YES')
elif p3 == 1 and (l3 == 1 or s3 == 1 or r3 == 1 or (s1 == 1) or (r2 == 1) or (l4 == 1)):
	print('YES')
elif p4 == 1 and (l4 == 1 or s4 == 1 or r4 == 1 or (l1 == 1) or (s2 == 1) or (r3 == 1)):
	print('YES')
else:
	print('NO')


(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')
elif 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')


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)


def checkColl(r):
	global r1, r2, r3, r4
	list = [r1, r2, r3, r4]
	if r[::-1][1:].count(1) > 0 and r[len(r) - 1] == 1:
		return True
	for i in range(1, 4):
		if r[3 - i] == 1 and list[(list.index(r) + i) % 4][::-1][0] == 1:
			return True
	return False
r1 = [int(z) for z in input().split()]
r2 = [int(z) for z in input().split()]
r3 = [int(z) for z in input().split()]
r4 = [int(z) for z in input().split()]
list = [r1, r2, r3, r4]
for i in range(4):
	if checkColl(list[i]):
		print('YES')
		exit(0)
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) = 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)


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')


(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())
f = 'NO'
if p1 == 1 and (s1 == 1 or l1 == 1 or r1 == 1 or (r4 == 1) or (l2 == 1) or (s3 == 1)):
	f = 'YES'
if p2 == 1 and (s2 == 1 or l2 == 1 or r2 == 1 or (r1 == 1) or (l3 == 1) or (s4 == 1)):
	f = 'YES'
if p3 == 1 and (s3 == 1 or l3 == 1 or r3 == 1 or (r2 == 1) or (l4 == 1) or (s1 == 1)):
	f = 'YES'
if p4 == 1 and (s4 == 1 or l4 == 1 or r4 == 1 or (r3 == 1) or (l1 == 1) or (s2 == 1)):
	f = 'YES'
print(f)


def parse(inp):
	return list(map(int, inp.split()))
a = []
for i in range(4):
	a.append(parse(input()))
if a[0][3] and a[0][1] + a[0][0] + a[0][2] + a[2][1] + a[1][0] + a[3][2]:
	print('YES')
	exit()
if a[1][3] and a[1][1] + a[1][0] + a[1][2] + a[3][1] + a[0][2] + a[2][0]:
	print('YES')
	exit()
if a[2][3] and a[2][1] + a[2][0] + a[2][2] + a[0][1] + a[1][2] + a[3][0]:
	print('YES')
	exit()
if a[3][3] and a[3][1] + a[3][0] + a[3][2] + a[1][1] + a[0][0] + a[2][2]:
	print('YES')
	exit()
print('NO')


M = [list(map(int, input().split())) for i in range(4)]
c = 0
if M[0][3] == 1:
	if M[0][2] == 1 or M[0][1] == 1 or M[0][0] == 1 or (M[2][1] == 1) or (M[1][0] == 1) or (M[3][2] == 1):
		c = 1
if M[1][3] == 1:
	if M[1][2] == 1 or M[1][1] == 1 or M[1][0] == 1 or (M[2][0] == 1) or (M[3][1] == 1) or (M[0][2] == 1):
		c = 1
if M[2][3] == 1:
	if M[2][2] == 1 or M[2][1] == 1 or M[2][0] == 1 or (M[0][1] == 1) or (M[3][0] == 1) or (M[1][2] == 1):
		c = 1
if M[3][3] == 1:
	if M[3][2] == 1 or M[3][1] == 1 or M[3][0] == 1 or (M[1][1] == 1) or (M[0][0] == 1) or (M[2][2] == 1):
		c = 1
if c == 1:
	print('YES')
else:
	print('NO')


l = []
for i in range(4):
	l.append(list(map(int, input().split())))
flag = False
for i in range(4):
	if l[i][3] == 1:
		if l[i][0] == 1 or l[i][1] == 1 or l[i][2] == 1 or (l[(i + 1) % 4][0] == 1) or (l[(i + 2) % 4][1] == 1) or (l[(i + 3) % 4][2] == 1):
			print('YES')
			flag = True
			break
if not flag:
	print('NO')


sz = 4
r = []
for i in range(sz):
	r.append(input().split(' '))
for i in range(sz):
	for j in range(sz):
		r[i][j] = int(r[i][j])
ans = True
for i in range(sz):
	if (r[i][0] == 1 or r[i][1] == 1 or r[i][2] == 1) and r[i][3] == 1:
		ans = False
	if r[i][0] == 1 and r[(i + 3) % 4][3] == 1:
		ans = False
	if r[i][1] == 1 and r[(i + 2) % 4][3] == 1:
		ans = False
	if r[i][2] == 1 and r[(i + 1) % 4][3] == 1:
		ans = False
if ans:
	print('NO')
else:
	print('YES')


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')


a = []
for i in range(4):
	a.append(input().split(' '))
for i in range(4):
	if a[i][0] == '1' and (a[i][3] == '1' or a[(i + 3) % 4][3] == '1'):
		print('YES')
		exit()
	if a[i][1] == '1' and (a[i][3] == '1' or a[(i + 2) % 4][3] == '1'):
		print('YES')
		exit()
	if a[i][2] == '1' and (a[i][3] == '1' or a[(i + 1) % 4][3] == '1'):
		print('YES')
		exit()
print('NO')


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = 4
dic = {}
while n:
	n -= 1
	l = list(map(int, input().split()))
	dic[4 - n] = l
ch = 1
if dic[1][3] == 1:
	kk = dic[1]
	if kk.count(1) != 1:
		ch = 0
	if dic[3][1] == 1:
		ch = 0
	if dic[4][2] == 1:
		ch = 0
	if dic[2][0] == 1:
		ch = 0
if ch:
	if dic[2][3] == 1:
		kk = dic[2]
		if kk.count(1) != 1:
			ch = 0
		if dic[4][1] == 1:
			ch = 0
		if dic[1][2] == 1:
			ch = 0
		if dic[3][0] == 1:
			ch = 0
	if ch:
		if dic[3][3] == 1:
			kk = dic[3]
			if kk.count(1) != 1:
				ch = 0
			if dic[1][1] == 1:
				ch = 0
			if dic[2][2] == 1:
				ch = 0
			if dic[4][0] == 1:
				ch = 0
		if ch:
			if dic[4][3] == 1:
				kk = dic[4]
				if kk.count(1) != 1:
					ch = 0
				if dic[2][1] == 1:
					ch = 0
				if dic[3][2] == 1:
					ch = 0
				if dic[1][0] == 1:
					ch = 0
			if ch:
				print('NO')
			else:
				print('YES')
		else:
			print('YES')
	else:
		print('YES')
else:
	print('YES')


def solve():
	lights = []
	for i in range(4):
		lights.append(list(map(int, input().split())))
	for i in range(len(lights)):
		if lights[i][-1]:
			problematicCandidates = lights[i][:-1] + [lights[(i + x) % 4][x - 1] for x in range(1, 4)]
			if any(problematicCandidates):
				return 'YES'
	return 'NO'
print(solve())


(flag, lights) = (False, [])
for i in range(4):
	lights.append([int(x) for x in input().split()])
for i in range(4):
	if lights[i][3]:
		if any(lights[i][0:3]):
			flag = True
		else:
			k = (i + 1) % 4
			for l in range(3):
				if lights[k][l]:
					flag = True
					break
				k = (k + 1) % 4
	if flag:
		break
if flag:
	print('YES')
else:
	print('NO')


drgs = []
for i in range(4):
	drgs.append([int(i) for i in input().split()])
ok = 1
for i in range(4):
	cur = drgs[i]
	for j in range(3):
		if cur[j]:
			if cur[3] or drgs[(3 + i - j) % 4][3]:
				ok = 0
				break
	if not ok:
		break
if ok:
	print('NO')
else:
	print('YES')


from sys import stdin, stdout

def l(crossroad, i):
	real_i = (i + 1) % len(crossroad)
	return crossroad[real_i][0]

def r(crossroad, i):
	real_i = (i + 3) % len(crossroad)
	return crossroad[real_i][2]

def s(crossroad, i):
	real_i = (i + 2) % len(crossroad)
	return crossroad[real_i][1]

def calculate(crossroad, i):
	return crossroad[i][0] + crossroad[i][1] + crossroad[i][2] + r(crossroad, i) + s(crossroad, i) + l(crossroad, i)
sides = 4
crossroad = []
for i in range(sides):
	crossroad.append([int(x) for x in stdin.readline().rstrip().split(' ')])
for i in range(sides):
	if crossroad[i][3] == 1:
		danger_level = calculate(crossroad, i)
		if danger_level > 0:
			print('YES')
			exit()
print('NO')


a = [list(map(int, input().split())) for _ in range(4)]
f = False
for i in a:
	if i[3]:
		f = True
if not f:
	print('NO')
else:
	p = []
	if a[0][3]:
		if a[1][0] or a[2][1] or a[3][2] or (not a[0].count(1) == 1):
			f = False
	if a[1][3]:
		if a[0][2] or a[2][0] or a[3][1] or (not a[1].count(1) == 1):
			f = False
	if a[2][3]:
		if a[0][1] or a[1][2] or a[3][0] or (not a[2].count(1) == 1):
			f = False
	if a[3][3]:
		if a[0][0] or a[1][1] or a[2][2] or (not a[3].count(1) == 1):
			f = False
	if f:
		print('NO')
	else:
		print('YES')


l = []
r = []
s = []
p = []
for i in range(4):
	d = list(map(int, input().split()))
	l.append(d[0])
	s.append(d[1])
	r.append(d[2])
	p.append(d[3])
t = 'NO'
if p[0] and (r[3] or s[2] or l[1] or s[0] or l[0] or r[0]):
	t = 'YES'
if p[1] and (r[0] or s[3] or l[2] or s[1] or l[1] or r[1]):
	t = 'YES'
if p[2] and (r[1] or s[0] or l[3] or s[2] or l[2] or r[2]):
	t = 'YES'
if p[3] and (r[2] or s[1] or l[0] or s[3] or l[3] or r[3]):
	t = 'YES'
print(t)


matrix = [list(map(int, input().split())) for _ in range(4)]
p1 = any([matrix[0][1], matrix[0][2], matrix[0][0], matrix[1][0], matrix[2][1], matrix[3][2]])
p2 = any([matrix[0][2], matrix[1][0], matrix[1][2], matrix[1][1], matrix[2][0], matrix[3][1]])
p3 = any([matrix[0][1], matrix[1][2], matrix[2][0], matrix[2][1], matrix[2][2], matrix[3][0]])
p4 = any([matrix[0][0], matrix[1][1], matrix[2][2], matrix[3][0], matrix[3][1], matrix[3][2]])
if matrix[0][3] and p1 or (matrix[1][3] and p2) or (matrix[2][3] and p3) or (matrix[3][3] and p4):
	print('Yes')
else:
	print('NO')


from sys import stdin as fin
arr = [list(map(int, fin.readline().split())) for i in range(4)]
for i in range(4):
	if (arr[i][0] or arr[i][1] or arr[i][2] or arr[i - 1][2] or arr[i - 2][1] or arr[i - 3][0]) and arr[i][3]:
		print('YES')
		break
else:
	print('NO')


p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
s = list(map(int, input().split()))
flag = 0
if p[3] == 1:
	if p.count(1) > 1 or r[1] == 1 or q[0] == 1 or (s[2] == 1):
		flag = 1
if q[3] == 1:
	if q.count(1) > 1 or s[1] == 1 or r[0] == 1 or (p[2] == 1):
		flag = 1
if r[3] == 1:
	if r.count(1) > 1 or p[1] == 1 or s[0] == 1 or (q[2] == 1):
		flag = 1
if s[3] == 1:
	if s.count(1) > 1 or q[1] == 1 or p[0] == 1 or (r[2] == 1):
		flag = 1
if flag == 0:
	print('NO')
else:
	print('YES')


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')
main()


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')


R = lambda : list(map(int, input().split()))
x = [[4, 3, 2, 1], [1, 4, 3, 2], [2, 1, 4, 3], [3, 2, 1, 4]]
dic = {0: [(1, 0), (2, 1), (3, 2)], 1: [(0, 2), (2, 0), (3, 1)], 2: [(0, 1), (1, 2), (3, 0)], 3: [(0, 0), (1, 1), (2, 2)]}
l = [R(), R(), R(), R()]
ans = 0
for i in range(4):
	if l[i][-1] == 1:
		for j in dic[i]:
			if l[j[0]][j[1]]:
				ans = 1
				break
		for k in range(3):
			if l[i][k]:
				ans = 1
				break
	if ans:
		break
if ans:
	print('YES')
else:
	print('NO')


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')


liste1 = [int(x) for x in input().split()]
liste2 = [int(x) for x in input().split()]
liste3 = [int(x) for x in input().split()]
liste4 = [int(x) for x in input().split()]
if (liste1[0] == 1 or liste4[2] == 1) and (liste1[3] == 1 or liste4[3] == 1) or ((liste1[1] == 1 or liste3[1] == 1) and (liste1[3] == 1 or liste3[3] == 1)) or ((liste1[2] == 1 or liste2[0] == 1) and (liste1[3] == 1 or liste2[3] == 1)) or ((liste2[1] == 1 or liste4[1] == 1) and (liste2[3] == 1 or liste4[3] == 1)) or ((liste2[2] == 1 or liste3[0] == 1) and (liste2[3] == 1 or liste3[3] == 1)) or ((liste3[2] == 1 or liste4[0] == 1) and (liste3[3] == 1 or liste4[3] == 1)):
	print('YES')
else:
	print('NO')


inp = lambda a: map(int, a)
inp_list = lambda a: [int(x) for x in a]

def f():
	print('YES')
a = []
l = [0, 1, 2, 3]
for _ in range(4):
	a.append(inp_list(input().split()))
for i in range(4):
	z = 0
	for j in range(3):
		if a[i][j] == 1:
			if j == 0:
				if a[(i + 3) % 4][3] == 1 or a[i][3] == 1:
					f()
					z = 1
					break
			elif j == 1:
				if a[(i + 2) % 4][3] == 1 or a[i][3] == 1:
					f()
					z = 1
					break
			elif j == 2:
				if a[(i + 1) % 4][3] == 1 or a[i][3] == 1:
					f()
					z = 1
					break
	if z == 1:
		break
if z == 0:
	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')


__author__ = 'artyom'

def main():
	r = []
	for _ in range(4):
		r.append(read(3))
	for i in range(4):
		if r[i][-1] == 1:
			if 1 in r[i][:-1]:
				return 1
			for j in range(3):
				k = i + j + 1
				if k >= 4:
					k -= 4
				if r[k][j] == 1:
					return 1
	return 0

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s)
write(['NO', 'YES'][main()])


L = []
for i in range(4):
	a = input().split()
	L.append(a)

def main():
	for i in range(4):
		if L[i][3] == '1':
			if L[i][0] == '1' or L[i][1] == '1' or L[i][2] == '1':
				print('YES')
				return
			elif L[(i + 1) % 4][0] == '1' or L[(i + 2) % 4][1] == '1' or L[(i + 3) % 4][2] == '1':
				print('YES')
				return
	print('NO')
	return
main()


roads = []
for i in range(4):
	roads.append(list(map(int, input().split())))
for i in range(4):
	if roads[i][3] == 1:
		if roads[i][0] == 1 or roads[i][1] == 1 or roads[i][2] == 1:
			print('YES')
			break
		elif roads[(i + 1) % 4][0] == 1 or roads[(i + 2) % 4][1] == 1 or roads[(i + 3) % 4][2] == 1:
			print('YES')
			break
else:
	print('NO')


def check(a, c):
	if a[(c + 1) % 4][0] == 0 and a[(c + 2) % 4][1] == 0 and (a[(c + 3) % 4][2] == 0):
		return False
	else:
		return True

def src(a):
	f = False
	k = True
	for i in range(4):
		if a[i][3] == 1:
			if a[i][0] == 1 or a[i][1] == 1 or a[i][2] == 1:
				return 'YES'
			k = False
			f = f or check(a, i)
	if k:
		return 'NO'
	if f:
		return 'YES'
	else:
		return 'NO'

def test():
	s = []
	a = [[], [], [], []]
	for i in range(4):
		s.append(input())
	for i in range(4):
		for j in range(len(s[i])):
			if s[i][j] != ' ':
				a[i].append(int(s[i][j]))
	return src(a)
print(test())


lights = {}
ped = {}
l_map = {1: 2, 2: 3, 3: 4, 4: 1}
s_map = {1: 3, 2: 4, 3: 1, 4: 2}
r_map = {1: 4, 2: 1, 3: 2, 4: 3}

def L(t):
	return t[0]

def S(t):
	return t[1]

def R(t):
	return t[2]
for i in range(1, 5):
	(l, s, r, p) = map(int, input().split())
	lights[i] = (l, s, r)
	ped[i] = p
for i in range(1, 5):
	if not ped[i]:
		continue
	if any(lights[i]) or L(lights[l_map[i]]) or S(lights[s_map[i]]) or R(lights[r_map[i]]):
		print('YES')
		exit()
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')


a = []
n = 4
for i in range(4):
	temp = list(map(int, input().split()))
	a.append(temp)
cnt = True
if a[0][3] == 1:
	if a[0][0] == 1 or a[0][1] == 1 or a[0][2] == 1 or (a[1][0] == 1) or (a[2][1] == 1) or (a[3][2] == 1):
		cnt = False
if a[1][3] == 1:
	if a[1][0] == 1 or a[1][1] == 1 or a[1][2] == 1 or (a[0][2] == 1) or (a[2][0] == 1) or (a[3][1] == 1):
		cnt = False
if a[2][3] == 1:
	if a[2][0] == 1 or a[2][1] == 1 or a[2][2] == 1 or (a[0][1] == 1) or (a[1][2] == 1) or (a[3][0] == 1):
		cnt = False
if a[3][3] == 1:
	if a[3][0] == 1 or a[3][1] == 1 or a[3][2] == 1 or (a[0][0] == 1) or (a[1][1] == 1) or (a[2][2] == 1):
		cnt = False
if cnt == False:
	print('YES')
else:
	print('NO')


import sys

def main():
	p = [False] * 4
	v = [False] * 4
	x = [[3, 2, 1], [0, 3, 2], [1, 0, 3], [2, 1, 0]]
	for i in range(4):
		(a, b, c, d) = map(int, sys.stdin.readline().split())
		if d != 0:
			p[i] = True
		if a != 0:
			v[x[i][0]] = True
			v[i] = True
		if b != 0:
			v[x[i][1]] = True
			v[i] = True
		if c != 0:
			v[x[i][2]] = True
			v[i] = True
	ans = False
	for i in range(4):
		ans = ans or (v[i] and p[i])
	if ans:
		print('YES')
	else:
		print('NO')
main()


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()


from collections import namedtuple

def main():
	lights = []
	Light = namedtuple('Light', ['l', 's', 'r', 'p'])
	for i in range(4):
		(l, s, r, p) = (e == 1 for e in map(int, input().split()))
		lights.append(Light(l, s, r, p))
	cond0 = lights[0].p and (lights[0].l or lights[0].s or lights[0].r or lights[1].l or lights[2].s or lights[3].r)
	cond1 = lights[1].p and (lights[1].l or lights[1].s or lights[1].r or lights[2].l or lights[3].s or lights[0].r)
	cond2 = lights[2].p and (lights[2].l or lights[2].s or lights[2].r or lights[3].l or lights[0].s or lights[1].r)
	cond3 = lights[3].p and (lights[3].l or lights[3].s or lights[3].r or lights[0].l or lights[1].s or lights[2].r)
	print('YES' if cond0 or cond1 or cond2 or cond3 else 'NO')
main()


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())


t = []
for i in range(4):
	t.append(list(map(int, input().split())))
type = False
if t[0][3] == 1:
	for i in range(3):
		if t[0][i] == 1:
			type = True
	if t[1][0] == 1:
		type = True
	if t[2][1] == 1:
		type = True
	if t[3][2] == 1:
		type = True
if t[1][3] == 1:
	for i in range(3):
		if t[1][i] == 1:
			type = True
	if t[2][0] == 1:
		type = True
	if t[3][1] == 1:
		type = True
	if t[0][2] == 1:
		type = True
if t[2][3] == 1:
	for i in range(3):
		if t[2][i] == 1:
			type = True
	if t[3][0] == 1:
		type = True
	if t[0][1] == 1:
		type = True
	if t[1][2] == 1:
		type = True
if t[3][3] == 1:
	for i in range(3):
		if t[3][i] == 1:
			type = True
	if t[0][0] == 1:
		type = True
	if t[1][1] == 1:
		type = True
	if t[2][2] == 1:
		type = True
if type:
	print('YES')
else:
	print('NO')


a = [list(map(int, input().split())) for i in range(4)]
print(('NO', 'YES')[any(((i[0] or i[1] or i[2]) and i[3] for i in a)) or any((any((a[i][j] and a[(i - j + 3) % 4][3] for i in range(4))) for j in range(3)))])


s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
s3 = list(map(int, input().split()))
s4 = list(map(int, input().split()))
flag = 0
if s1[3] == 1:
	if s1.count(1) > 1:
		flag = 1
if s2[3] == 1:
	if s2.count(1) > 1:
		flag = 1
if s3[3] == 1:
	if s3.count(1) > 1:
		flag = 1
if s4[3] == 1:
	if s4.count(1) > 1:
		flag = 1
if s1[0] == 1 and s4[3] == 1:
	flag = 1
if s1[1] == 1 and s3[3] == 1:
	flag = 1
if s1[2] == 1 and s2[3] == 1:
	flag = 1
if s2[0] == 1 and s1[3] == 1:
	flag = 1
if s2[1] == 1 and s4[3] == 1:
	flag = 1
if s2[2] == 1 and s3[3] == 1:
	flag = 1
if s3[0] == 1 and s2[3] == 1:
	flag = 1
if s3[1] == 1 and s1[3] == 1:
	flag = 1
if s3[2] == 1 and s4[3] == 1:
	flag = 1
if s4[0] == 1 and s3[3] == 1:
	flag = 1
if s4[1] == 1 and s2[3] == 1:
	flag = 1
if s4[2] == 1 and s1[3] == 1:
	flag = 1
if flag == 1:
	print('YES')
else:
	print('NO')


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')


conf = [[int(num) for num in input().split()] for i in range(4)]
bad = False
for ind in range(4):
	bad |= conf[ind][3] and (1 in conf[ind][:3] or conf[(ind + 1) % 4][0] or conf[(ind + 2) % 4][1] or conf[(ind + 3) % 4][2])
print('YES' if bad else 'NO')


mat = [list(map(int, input().split())) for i in range(4)]
p1 = sum([mat[0][1], mat[0][2], mat[0][0], mat[1][0], mat[2][1], mat[3][2]])
p2 = sum([mat[0][2], mat[1][0], mat[1][2], mat[1][1], mat[2][0], mat[3][1]])
p3 = sum([mat[0][1], mat[1][2], mat[2][0], mat[2][1], mat[2][2], mat[3][0]])
p4 = sum([mat[0][0], mat[1][1], mat[2][2], mat[3][0], mat[3][1], mat[3][2]])
if mat[0][3] == 1 and p1 >= 1:
	print('YES')
elif mat[1][3] == 1 and p2 >= 1:
	print('YES')
elif mat[2][3] == 1 and p3 >= 1:
	print('YES')
elif mat[3][3] == 1 and p4 >= 1:
	print('YES')
else:
	print('NO')


import sys
A = []
for i in range(4):
	s = list(map(int, input().split()))
	A.append(s)
B = [A[i][3] for i in range(4)]
for i in range(4):
	for j in range(3):
		if A[i][j] == 1:
			if j == 0:
				if B[i] or B[(i - 1) % 4]:
					print('YES')
					sys.exit()
			elif j == 2:
				if B[i] or B[(i + 1) % 4]:
					print('YES')
					sys.exit()
			elif i < 2:
				if B[i] or B[i + 2]:
					print('YES')
					sys.exit()
			elif B[i] or B[i - 2]:
				print('YES')
				sys.exit()
print('NO')


def test(li, err):
	if li.count('1') != 0:
		err = err + 1
	return err
p1s = input()
p2s = input()
p3s = input()
p4s = input()
p1 = {}
p2 = {}
p3 = {}
p4 = {}
for q in range(4):
	p1[q + 1] = p1s.split()[-(q + 1)]
for q in range(4):
	p2[q + 1] = p2s.split()[-(q + 1)]
for q in range(4):
	p3[q + 1] = p3s.split()[-(q + 1)]
for q in range(4):
	p4[q + 1] = p4s.split()[-(q + 1)]
allp = {1: p1, 2: p2, 3: p3, 4: p4}
err = 0
for i in range(4):
	if int(allp[i + 1][1]) == 1:
		if i + 1 == 1:
			li = [allp[1][4], allp[2][4], allp[1][3], allp[3][3], allp[1][2], allp[4][2]]
			err = test(li, err)
		if i + 1 == 2:
			li = [allp[2][4], allp[3][4], allp[2][3], allp[4][3], allp[1][2], allp[2][2]]
			err = test(li, err)
		if i + 1 == 3:
			li = [allp[3][4], allp[4][4], allp[1][3], allp[3][3], allp[2][2], allp[3][2]]
			err = test(li, err)
		if i + 1 == 4:
			li = [allp[1][4], allp[4][4], allp[2][3], allp[4][3], allp[3][2], allp[4][2]]
			err = test(li, err)
	else:
		continue
if err != 0:
	print('YES')
else:
	print('NO')


a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
c = [int(x) for x in input().split(' ')]
d = [int(x) for x in input().split(' ')]
if (a[0] == 1 or b[1] == 1 or c[2] == 1 or (d[:3].count(1) > 0)) and d[3] == 1:
	print('YES')
	exit(0)
if (a[1] == 1 or b[2] == 1 or d[0] == 1 or (c[:3].count(1) > 0)) and c[3] == 1:
	print('YES')
	exit(0)
if (a[2] == 1 or d[1] == 1 or c[0] == 1 or (b[:3].count(1) > 0)) and b[3] == 1:
	print('YES')
	exit(0)
if (d[2] == 1 or b[0] == 1 or c[1] == 1 or (a[:3].count(1) > 0)) and a[3] == 1:
	print('YES')
	exit(0)
print('NO')


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')


mat = []
for i in range(0, 4):
	mat.append(list(map(int, input().split())))
valid = True
if mat[0][3] == 1:
	if sum(mat[0]) > 1:
		valid = False
	if mat[1][0] + mat[2][1] + mat[3][2] > 0:
		valid = False
if mat[1][3] == 1:
	if sum(mat[1]) > 1:
		valid = False
	if mat[3][1] + mat[2][0] + mat[0][2] > 0:
		valid = False
if mat[2][3] == 1:
	if sum(mat[2]) > 1:
		valid = False
	if mat[0][1] + mat[3][0] + mat[1][2] > 0:
		valid = False
if mat[3][3] == 1:
	if sum(mat[3]) > 1:
		valid = False
	if mat[0][0] + mat[1][1] + mat[2][2] > 0:
		valid = False
if valid:
	print('NO')
else:
	print('YES')


p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
p3 = list(map(int, input().split()))
p4 = list(map(int, input().split()))
flag = False
lists = list([p1, p2, p3, p4])
for (k, items) in enumerate(lists):
	for (i, val) in enumerate(items[0:3]):
		if val == 1 and items[3] == 1:
			flag = True
		if i == 0 and val == 1 and (lists[(k - 1) % 4][3] == 1):
			flag = True
		if i == 1 and val == 1 and (lists[(k + 2) % 4][3] == 1):
			flag = True
		if i == 2 and val == 1 and (lists[(k + 1) % 4][3] == 1):
			flag = True
if flag:
	print('YES')
else:
	print('NO')


class block:

	def __init__(self, l, s, r, p, no):
		self.id = no
		self.l = l
		self.s = s
		self.r = r
		self.p = p
		self.opposite = (no + 2) % 4
		self.right = (no + 1) % 4
		self.left = (no - 1) % 4
		self.attacking = []
		if l:
			self.attacking.append(self.left)
		if r:
			self.attacking.append(self.right)
		if s:
			self.attacking.append(self.opposite)
		if len(self.attacking) > 0:
			self.attacking.append(no)

	def hits(self, a):
		if a.p and a.id in self.attacking:
			return True
		else:
			return False

	def display(self):
		print('self.id =', self.id)
		print('self.l =', self.l)
		print('self.s =', self.s)
		print('self.r =', self.r)
		print('self.p =', self.p)
		print('self.opposite =', self.opposite)
		print('self.right =', self.right)
		print('self.left =', self.left)
		print('self.attacking =', self.attacking)

	def selfHit(self):
		if self.p and (self.l or self.s or self.r):
			return True
		else:
			return False
A = []
for i in range(1, 5):
	(l, s, r, p) = map(int, input().split())
	a = block(l, s, r, p, i % 4)
	A.append(a)
for i in range(4):
	for j in range(4):
		if A[i].hits(A[j]):
			print('YES')
			exit()
print('NO')


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


from sys import stdin
data = []
for _ in range(0, 4):
	data.append(list(map(int, stdin.readline().rstrip().split())))
(l, s, r, p) = (0, 1, 2, 3)
for i in range(0, 4):
	pval = data[i][p]
	if pval == 1 and (pval == data[(i + 1) % 4][l] or pval == data[(i + 2) % 4][s] or pval == data[(i + 3) % 4][r] or (1 == data[i][l]) or (1 == data[i][s]) or (1 == data[i][r])):
		print('YES')
		exit()
print('NO')


from sys import *
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
if l1[-1]:
	if sum(l1[:-1]) or l4[2] or l2[0] or l3[1]:
		print('YES')
		exit()
if l2[-1]:
	if sum(l2[:-1]) or l1[2] or l4[1] or l3[0]:
		print('YES')
		exit()
if l3[-1]:
	if sum(l3[:-1]) or l2[2] or l1[1] or l4[0]:
		print('YES')
		exit()
if l4[-1]:
	if sum(l4[:-1]) or l3[2] or l2[1] or l1[0]:
		print('YES')
		exit()
print('NO')


rows = [list(map(int, input().split())) for x in range(4)]
turns = [[0, 1, 2], [0], [1], [2]]
results = 'NO'
for x in range(4):
	if rows[x][3]:
		for y in range(4):
			for z in turns[y]:
				if rows[y][z]:
					results = 'YES'
					break
	if results == 'YES':
		break
	turns.insert(0, turns[-1])
	del turns[-1]
print(results)


p2 = [0, 0, 0, 0]
p1 = [0, 0, 0, 0]
t = False
for i in range(4):
	(l, s, r, p) = map(int, input().split())
	p1[i] = p
	p2[(i + 1) % 4] += r
	p2[(i - 1) % 4] += l
	p2[(i + 2) % 4] += s
	p2[i] += r + s + l
for i in range(4):
	if p2[i] != 0 and p1[i] != 0:
		t = True
if t:
	print('YES')
else:
	print('NO')


l = []
for _ in range(4):
	i = list(map(int, input().split()))
	if i[3] == 1 and 1 in i[:3]:
		print('YES')
		quit()
	l.append(i)
for x in range(4):
	if l[x][3] == 1:
		try:
			if l[(x + 1) % 4][0] == 1:
				print('YES')
				break
		except IndexError:
			pass
		try:
			if l[(x + 2) % 4][1] == 1:
				print('YES')
				break
		except IndexError:
			pass
		try:
			if l[(x + 3) % 4][2] == 1:
				print('YES')
				break
		except IndexError:
			pass
		if x >= 1 and l[x - 1][2] == 1:
			print('YES')
			break
else:
	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 = [list(map(int, input().split())) for i in range(4)]
for i in range(4):
	if a[i][3] and any((a[i][j - 1] or a[(i + j) % 4][j - 1] for j in range(1, 4))):
		print('YES')
		exit()
print('NO')


a = []
for i in range(4):
	a.append(list(map(int, input().split())))
state = 0
for i in range(4):
	if a[i][3] == 1:
		if a[i - 1][2] or a[i - 2][1] or a[i - 3][0]:
			state = 1
		if a[i][2] or a[i][1] or a[i][0]:
			state = 1
if state:
	print('YES')
else:
	print('NO')


flag = False
a1 = a2 = a3 = a4 = 0
p1 = p2 = p3 = p4 = 0
(l, s, r, p1) = map(int, input().split(' '))
a1 = max(a1, l, s, r)
a2 = max(a2, r)
a3 = max(a3, s)
a4 = max(a4, l)
(l, s, r, p2) = map(int, input().split(' '))
a2 = max(a2, l, s, r)
a3 = max(a3, r)
a4 = max(a4, s)
a1 = max(a1, l)
(l, s, r, p3) = map(int, input().split(' '))
a3 = max(a3, l, s, r)
a4 = max(a4, r)
a1 = max(a1, s)
a2 = max(a2, l)
(l, s, r, p4) = map(int, input().split(' '))
a4 = max(a4, l, s, r)
a1 = max(a1, r)
a2 = max(a2, s)
a3 = max(a3, l)
flag = a1 and p1 or (a2 and p2) or (a3 and p3) or (a4 and p4)
print('YES' if flag else 'NO')


p1 = tuple(map(int, input().split()))
p2 = tuple(map(int, input().split()))
p3 = tuple(map(int, input().split()))
p4 = tuple(map(int, input().split()))
if p1[3] and (p1[0] or p1[1] or p1[2] or p4[2] or p2[0] or p3[1]) or (p2[3] and (p2[0] or p2[1] or p2[2] or p3[0] or p4[1] or p1[2])) or (p3[3] and (p3[0] or p3[1] or p3[2] or p4[0] or p1[1] or p2[2])) or (p4[3] and (p4[0] or p4[1] or p4[2] or p1[0] or p2[1] or p3[2])):
	print('YES')
else:
	print('NO')


S = list((list(map(int, input().split())) for i in range(4)))
for i in range(4):
	if S[i][3] == 0:
		continue
	for j in range(4):
		for k in range(3):
			if S[j][k] == 0:
				continue
			if (j - k - 1) % 4 == i or j == i:
				exit(print('YES'))
print('NO')


accident = False
l = []
s = []
r = []
p = []
for i in range(4):
	(a, b, c, d) = map(int, input().split())
	l.append(a)
	s.append(b)
	r.append(c)
	p.append(d)
for i in range(4):
	if p[i] == 1 and l[i] + s[i] + r[i] + l[(i + 1) % 4] + s[(i + 2) % 4] + r[(i - 1) % 4] != 0:
		accident = True
		break
if accident:
	print('YES')
else:
	print('NO')


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')
				exit()
		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')
				exit()
		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')
				exit()
		elif 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')
			exit()
print('NO')


answer = 'NO'
array = []
for i in range(4):
	(l, s, r, p) = map(int, input().split())
	new = (l, s, r, p)
	array.append(new)
	if p == 1:
		if l != 0 or s != 0 or r != 0:
			answer = 'YES'
if array[0][3] == 1:
	if array[1][0] == 1 or array[2][1] == 1 or array[3][2] == 1:
		answer = 'YES'
if array[1][3] == 1:
	if array[0][2] == 1 or array[2][0] == 1 or array[3][1] == 1:
		answer = 'YES'
if array[2][3] == 1:
	if array[1][2] == 1 or array[0][1] == 1 or array[3][0] == 1:
		answer = 'YES'
if array[3][3] == 1:
	if array[2][2] == 1 or array[1][1] == 1 or array[0][0] == 1:
		answer = 'YES'
print(answer)


a = [[int(num) for num in input().split()] for i in range(4)]
b = False
for j in range(4):
	b |= a[j][3] and (1 in a[j][:3] or a[(j + 1) % 4][0] or a[(j + 2) % 4][1] or a[(j + 3) % 4][2])
print('YES' if b 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')


def main():
	a = [[y for y in range(4)] for x in range(4)]
	for i in range(4):
		s = input().split()
		for j in range(4):
			a[i][j] = int(s[j])
	for i in range(4):
		if a[i][3]:
			if a[i][0] or a[i][1] or a[i][2]:
				print('YES')
				break
			if a[(i + 1) % 4][0] or a[(i + 2) % 4][1] or a[(i + 3) % 4][2]:
				print('YES')
				break
	else:
		print('NO')
main()


ans = False
parts = [[bool(int(x)) for x in input().split()] for j in range(4)]
for (index, part) in enumerate(parts):
	(l, s, r, p) = part
	if (l or s or r) and p:
		ans = True
	if p:
		for i in range(3):
			next_part = parts[(index + i + 1) % 4]
			if next_part[i]:
				ans = True
print('YES' if ans else 'NO')


def int_map():
	return map(int, input().split(' '))
sem = []
for _ in range(4):
	sem.append(list(int_map()))
for i in range(4):
	if sem[i][3] * (sem[i][0] + sem[i][1] + sem[i][2] + sem[(i + 1) % 4][0] + sem[(i + 2) % 4][1] + sem[(i + 3) % 4][2]) != 0:
		print('YES')
		exit()
print('NO')


import sys
firstline = True
secondline = True
thirdline = True
fourthline = True
numlines = 3
for line in sys.stdin:
	if firstline:
		line = line[:7]
		list1 = line.split(' ')
		numlines -= 1
		firstline = False
		continue
	if secondline:
		line = line[:7]
		list2 = line.split(' ')
		numlines -= 1
		secondline = False
		continue
	if thirdline:
		line = line[:7]
		list3 = line.split(' ')
		numlines -= 1
		thirdline = False
		continue
	if fourthline:
		line = line[:7]
		list4 = line.split(' ')
		numlines -= 1
		fourthline = False
		continue
	if numlines == -1:
		break
if list1[0] == list4[3] == '1' or list1[1] == list3[3] == '1' or list1[2] == list2[3] == '1' or (list1[0] == list1[3] == '1') or (list1[1] == list1[3] == '1') or (list1[2] == list1[3] == '1'):
	print('YES')
elif list2[0] == list1[3] == '1' or list2[1] == list4[3] == '1' or list2[2] == list3[3] == '1' or (list2[0] == list2[3] == '1') or (list2[1] == list2[3] == '1') or (list2[2] == list2[3] == '1'):
	print('YES')
elif list3[0] == list2[3] == '1' or list3[1] == list1[3] == '1' or list3[2] == list4[3] == '1' or (list3[0] == list3[3] == '1') or (list3[1] == list3[3] == '1') or (list3[2] == list3[3] == '1'):
	print('YES')
elif list4[0] == list3[3] == '1' or list4[1] == list2[3] == '1' or list4[2] == list1[3] == '1' or (list4[0] == list4[3] == '1') or (list4[1] == list4[3] == '1') or (list4[2] == list4[3] == '1'):
	print('YES')
else:
	print('NO')


m = []
for i in range(4):
	m.append([int(s) for s in input().split()])
f = False
for i in m:
	if (i[0] == 1 or i[1] == 1 or i[2] == 1) and i[3] == 1:
		f = True
if m[0][3] == 1 and (m[1][0] == 1 or m[2][1] == 1 or m[3][2] == 1):
	f = True
if m[1][3] == 1 and (m[2][0] == 1 or m[3][1] == 1 or m[0][2] == 1):
	f = True
if m[2][3] == 1 and (m[3][0] == 1 or m[0][1] == 1 or m[1][2] == 1):
	f = True
if m[3][3] == 1 and (m[0][0] == 1 or m[1][1] == 1 or m[2][2] == 1):
	f = True
print('YES' if f else 'NO')


def judge():
	for i in range(4):
		if a[i][3] == 0:
			continue
		left = (i + 3) % 4
		right = (i + 1) % 4
		mid = (i + 2) % 4
		if a[i][0] or a[i][1] or a[i][2] or a[left][2] or a[mid][1] or a[right][0]:
			return True
	return False
while True:
	try:
		a = []
		for i in range(4):
			a.append(list(map(int, input().split(' '))))
		print('YES' if judge() else 'NO')
	except:
		break


(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 any([l2, s3, r4, l1, s1, r1]):
	print('Yes')
	exit()
if p2 and any([l3, s4, r1, l2, s2, r2]):
	print('Yes')
	exit()
if p3 and any([l4, s1, r2, l3, s3, r3]):
	print('Yes')
	exit()
if p4 and any([l1, s2, r3, l4, s4, r4]):
	print('Yes')
	exit()
print('No')


def main():
	laneOne = input().split()
	laneTwo = input().split()
	laneThree = input().split()
	laneFour = input().split()
	outputcase = 'NO'
	if laneOne[3] == '1':
		if laneOne[0] == '0' and laneOne[1] == '0' and (laneOne[2] == '0'):
			if laneTwo[0] == '1' or laneThree[1] == '1' or laneFour[2] == '1':
				outputcase = 'YES'
		else:
			outputcase = 'YES'
	if laneTwo[3] == '1':
		if laneTwo[0] == '0' and laneTwo[1] == '0' and (laneTwo[2] == '0'):
			if laneThree[0] == '1' or laneFour[1] == '1' or laneOne[2] == '1':
				outputcase = 'YES'
		else:
			outputcase = 'YES'
	if laneThree[3] == '1':
		if laneThree[0] == '0' and laneThree[1] == '0' and (laneThree[2] == '0'):
			if laneTwo[2] == '1' or laneFour[0] == '1' or laneOne[1] == '1':
				outputcase = 'YES'
		else:
			outputcase = 'YES'
	if laneFour[3] == '1':
		if laneFour[0] == '0' and laneFour[1] == '0' and (laneFour[2] == '0'):
			if laneTwo[1] == '1' or laneThree[2] == '1' or laneOne[0] == '1':
				outputcase = 'YES'
		else:
			outputcase = 'YES'
	print(outputcase)
main()


def editor():
	import sys
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	m = [[int(i) for i in input().split()] for j in range(4)]
	acc = False
	for i in range(4):
		if m[i][3] == 1:
			for j in range(3):
				if m[i][j] == 1:
					acc = True
			if m[(i + 2) % 4][1] == 1 or m[(i + 3) % 4][2] == 1 or m[(i + 1) % 4][0] == 1:
				acc = True
	if acc is True:
		print('YES')
	else:
		print('NO')
solve()


n = 4
rec = [0, 0, 0, 0]
P = [0, 0, 0, 0]
for i in range(n):
	(l, s, r, p) = map(int, input().split())
	rec[i] += l + s + r
	P[i] += p
	il = i - 1 if i - 1 >= 0 else 3
	ir = (i + 1) % 4
	ss = (i + 2) % 4
	rec[il] += l
	rec[ir] += r
	rec[ss] += s
for i in range(n):
	if rec[i] >= 1 and P[i] >= 1:
		print('YES')
		exit()
print('NO')


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
ans = 'NO'
if a[3]:
	if a[0] + a[1] + a[2] + b[0] + c[1] + d[2] > 0:
		ans = 'YES'
if b[3]:
	if b[0] + b[1] + b[2] + c[0] + d[1] + a[2] > 0:
		ans = 'YES'
if c[3]:
	if c[0] + c[1] + c[2] + d[0] + a[1] + b[2] > 0:
		ans = 'YES'
if d[3]:
	if d[0] + d[1] + d[2] + a[0] + b[1] + c[2] > 0:
		ans = 'YES'
print(ans)


TN = 1

def solution():
	(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())
	ans = 'NO'
	if p1 == 1 and (p1 == l1 or p1 == s1 or p1 == r1 or (p1 == l2) or (p1 == s3) or (p1 == r4)):
		ans = 'YES'
	elif p2 == 1 and (p2 == l2 or p2 == s2 or p2 == r2 or (p2 == l3) or (p2 == s4) or (p2 == r1)):
		ans = 'YES'
	elif p3 == 1 and (p3 == l3 or p3 == s3 or p3 == r3 or (p3 == l4) or (p3 == s1) or (p3 == r2)):
		ans = 'YES'
	elif p4 == 1 and (p4 == l4 or p4 == s4 or p4 == r4 or (p4 == l1) or (p4 == s2) or (p4 == r3)):
		ans = 'YES'
	print(ans)
while TN != 0:
	solution()
	TN -= 1


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
en = lambda x: list(enumerate(x))
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
arr = [rr() for _ in range(4)]
for i in range(4):
	if arr[i][3] and (arr[i][0] or arr[i][1] or arr[i][2] or arr[(i + 2) % 4][1] or arr[(i + 1) % 4][0] or arr[(i + 3) % 4][2]):
		exit(print('YES'))
print('NO')


lights = []
for i in range(4):
	temp = input().split()
	lights.append(temp)
ans = 0
for i in range(4):
	if lights[i][3] == '1':
		if '1' in lights[i][:3]:
			ans = 1
			break
		elif lights[(i + 1) % 4][0] != '0' or lights[(i + 2) % 4][1] != '0' or lights[(i + 3) % 4][2] != '0':
			ans = 1
			break
if ans:
	print('YES')
else:
	print('NO')


import sys

def solve():
	traffic = [[int(j) for j in input().split()] for i in range(4)]
	ans = 'NO'
	for i in range(4):
		for j in range(3):
			if traffic[i][j]:
				if traffic[i][3]:
					ans = 'YES'
				if j == 0 and traffic[(i - 1) % 4][3]:
					ans = 'YES'
				elif j == 1 and traffic[(i + 2) % 4][3]:
					ans = 'YES'
				elif j == 2 and traffic[(i + 1) % 4][3]:
					ans = 'YES'
	print(ans)
solve()


a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
d = list(map(int, input().split()))
(l, s, r, p) = (0, 1, 2, 3)
w = False
if a[p]:
	if a.count(1) > 1 or b[l] or c[s] or d[r]:
		w = True
if b[p]:
	if b.count(1) > 1 or c[l] or d[s] or a[r]:
		w = True
if c[p]:
	if c.count(1) > 1 or d[l] or a[s] or b[r]:
		w = True
if d[p]:
	if d.count(1) > 1 or a[l] or b[s] or c[r]:
		w = True
if w == True:
	print('YES')
else:
	print('NO')


import math as mt
import sys, string, bisect
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
l1 = L()
l2 = L()
l3 = L()
l4 = L()
if sum(l1) >= 2 and l1[-1] or (sum(l2) >= 2 and l2[-1]) or (sum(l3) >= 2 and l3[-1]) or (sum(l4) >= 2 and l4[-1]):
	print('YES')
	exit()
if l1[-1] == 1:
	if l4[2] or l2[0] or l3[1]:
		print('YES')
		exit()
if l2[-1] == 1:
	if l4[1] or l3[0] or l1[2]:
		print('YES')
		exit()
if l3[-1] == 1:
	if l4[0] or l1[1] or l2[2]:
		print('YES')
		exit()
if l4[-1] == 1:
	if l3[2] or l2[1] or l1[0]:
		print('YES')
		exit()
print('NO')


l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
l3 = list(map(int, input().split()))
l4 = list(map(int, input().split()))
count = 0
if l1[3] == 1 and (l1[0] == 1 or l1[1] == 1 or l1[2] == 1 or (l2[0] == 1) or (l3[1] == 1) or (l4[2] == 1)):
	count = 1
elif l2[3] == 1 and (l1[2] == 1 or l2[0] == 1 or l2[1] == 1 or (l2[2] == 1) or (l3[0] == 1) or (l4[1] == 1)):
	count = 1
elif l3[3] == 1 and (l1[1] == 1 or l2[2] == 1 or l3[0] == 1 or (l3[1] == 1) or (l3[2] == 1) or (l4[0] == 1)):
	count = 1
elif l4[3] == 1 and (l1[0] == 1 or l2[1] == 1 or l3[2] == 1 or (l4[0] == 1) or (l4[1] == 1) or (l4[2] == 1)):
	count = 1
if count == 1:
	print('YES')
else:
	print('NO')


(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())

def die():
	print('YES')
	exit(0)

def ch1():
	if p1 and (r1 or s1 or l1 or l2 or s3 or r4):
		die()

def ch2():
	if p2 and (r2 or s2 or l2 or l3 or s4 or r1):
		die()

def ch3():
	if p3 and (r3 or s3 or l3 or l4 or s1 or r2):
		die()

def ch4():
	if p4 and (r4 or s4 or l4 or l1 or s2 or r3):
		die()
ch1()
ch2()
ch3()
ch4()
print('NO')


lanes = [1] * 4
com = {0: [4, 2, 3], 1: [1, 3, 4], 2: [2, 4, 1], 3: [3, 1, 2]}
p = []
for x in range(4):
	a = input().split()
	if a[0] == '1':
		lanes[com[x][0] - 1] = 0
		lanes[x] = 0
	if a[1] == '1':
		lanes[x] = 0
		lanes[com[x][2] - 1] = 0
	if a[2] == '1':
		lanes[com[x][1] - 1] = 0
		lanes[x] = 0
	if a[3] == '1':
		p += [1]
	else:
		p += [0]
for x in range(4):
	if lanes[x] == 0 and p[x] == 1:
		print('YES')
		break
else:
	print('NO')


import sys
a = [[int(x) for x in input().split()] for _ in range(4)]
if a[0][3] and (a[1][0] or a[2][1] or a[3][2]):
	print('YES')
elif a[1][3] and (a[2][0] or a[3][1] or a[0][2]):
	print('YES')
elif a[2][3] and (a[3][0] or a[0][1] or a[1][2]):
	print('YES')
elif a[3][3] and (a[0][0] or a[1][1] or a[2][2]):
	print('YES')
else:
	for i in range(4):
		if a[i][3] and (a[i][0] or a[i][1] or a[i][2]):
			print('YES')
			sys.exit(0)
	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')


m = [list(map(int, input().split())) for _ in range(4)]

def acc(i):
	l = m[i][0] and (m[i][3] or m[i - 1][3])
	s = m[i][1] and (m[i][3] or m[i - 2][3])
	r = m[i][2] and (m[i][3] or m[i - 3][3])
	return any([l, s, r])
print('YES' if any((acc(i) for i in range(4))) else 'NO')


y = []
check = 1
x1 = input()
x2 = input()
x3 = input()
x4 = input()
y1 = [x1.split()]
y2 = [x2.split()]
y3 = [x3.split()]
y4 = [x4.split()]
y = y1 + y2 + y3 + y4 + y
if y[0][3] == '1':
	if y[0][0] == '1' or y[0][1] == '1' or y[0][2] == '1':
		check = 0
	elif y[1][0] == '1' or y[2][1] == '1' or y[3][2] == '1':
		check = 0
if y[1][3] == '1':
	if y[1][0] == '1' or y[1][1] == '1' or y[1][2] == '1':
		check = 0
	elif y[2][0] == '1' or y[3][1] == '1' or y[0][2] == '1':
		check = 0
if y[2][3] == '1':
	if y[2][0] == '1' or y[2][1] == '1' or y[2][2] == '1':
		check = 0
	elif y[3][0] == '1' or y[0][1] == '1' or y[1][2] == '1':
		check = 0
if y[3][3] == '1':
	if y[3][0] == '1' or y[3][1] == '1' or y[3][2] == '1':
		check = 0
	elif y[0][0] == '1' or y[1][1] == '1' or y[2][2] == '1':
		check = 0
if check == 0:
	print('YES')
else:
	print('NO')


lista = []
for i in range(4):
	st = input()
	lista.append(st.split(' '))

def ff(n):
	if n == 0:
		return 2
	elif n == 1:
		return 3
	elif n == 2:
		return 0
	elif n == 3:
		return 1

def rec(lista):
	lolo = 0
	for i in range(len(lista)):
		for j in range(len(lista[i]) - 1):
			if lista[i][3] == lista[i][j] == '1':
				lolo = 1
				break
		momo = ff(i)
		if momo == 3:
			hoho = 0
		else:
			hoho = momo + 1
		if momo == 0:
			hoho2 = 3
		else:
			hoho2 = momo - 1
		if lista[i][0] == lista[hoho][3] == '1':
			lolo = 1
			break
		elif lista[i][1] == lista[momo][3] == '1':
			lolo = 1
			break
		elif lista[i][2] == lista[hoho2][3] == '1':
			lolo = 1
			break
	if lolo == 1:
		print('YES')
	else:
		print('NO')
rec(lista)


b = []
for i in range(4):
	t = input()
	a = list(map(int, t.strip().split()))
	b.append(a)
flag = 0
for i in range(4):
	if b[i][0] == 1:
		temp = (i + 3) % 4
		if b[temp][3] == 1 or b[i][3] == 1:
			flag = 1
			break
if b[0][3] == 1 or b[2][3] == 1:
	if b[0][1] == 1 or b[2][1] == 1:
		flag = 1
if b[1][3] == 1 or b[3][3] == 1:
	if b[1][1] == 1 or b[3][1] == 1:
		flag = 1
for i in range(4):
	if b[i][2] == 1:
		temp = (i + 5) % 4
		if b[temp][3] == 1 or b[i][3] == 1:
			flag = 1
			break
if flag:
	print('YES')
else:
	print('NO')


def f():
	l = [list(map(int, input().split())) for i in range(4)]
	for i in range(4):
		if l[i][0]:
			if l[(i + 3) % 4][3] or l[i][3]:
				print('YES')
				return
		if l[i][1]:
			if l[(i + 2) % 4][3] or l[i][3]:
				print('YES')
				return
		if l[i][2]:
			if l[(i + 1) % 4][3] or l[i][3]:
				print('YES')
				return
	print('NO')
f()


def poss_acc(lista, front, left, right, road):
	flag = False
	if lista[road - 1][3]:
		if lista[road - 1].count(1) > 1:
			flag = True
		elif lista[front - 1][1]:
			flag = True
		elif lista[left - 1][2]:
			flag = True
		elif lista[right - 1][0]:
			flag = True
	return flag
info = []
values = [[3, 4, 2, 1], [2, 3, 1, 4], [1, 2, 4, 3], [4, 1, 3, 2]]
accident = False
for i in range(4):
	street = [int(x) for x in input().split()]
	info.append(street)
for val in values:
	if poss_acc(info, val[0], val[1], val[2], val[3]):
		accident = True
		break
if accident:
	print('YES')
else:
	print('NO')


accident = False
a = []
b = 0
for i in range(4):
	a.append([])
	(x, y, z, w) = map(int, input().split())
	a[i].append(x)
	a[i].append(y)
	a[i].append(z)
	a[i].append(w)
for i in range(4):
	b = i
	if a[i][3] == 1:
		for j in range(3):
			b = (b + 1) % 4
			if a[i][j] == 1 or a[b][j] == 1:
				print('yes')
				accident = True
				break
		if accident:
			break
if accident == False:
	print('no')


import array
ar = {}
for i in range(0, 4):
	ar[i] = input().split()
for i in range(0, 4):
	for j in range(0, 4):
		ar[i][j] = int(ar[i][j])
flag = 0
if ar[0][3] == 1:
	if ar[0][0] == 1 or ar[0][1] == 1 or ar[0][2] == 1 or (ar[3][2] == 1) or (ar[2][1] == 1) or (ar[1][0] == 1):
		flag = 1
if ar[1][3] == 1:
	if ar[1][0] == 1 or ar[1][1] == 1 or ar[1][2] == 1 or (ar[0][2] == 1) or (ar[3][1] == 1) or (ar[2][0] == 1):
		flag = 1
if ar[2][3] == 1:
	if ar[2][0] == 1 or ar[2][1] == 1 or ar[2][2] == 1 or (ar[1][2] == 1) or (ar[0][1] == 1) or (ar[3][0] == 1):
		flag = 1
if ar[3][3] == 1:
	if ar[3][0] == 1 or ar[3][1] == 1 or ar[3][2] == 1 or (ar[2][2] == 1) or (ar[1][1] == 1) or (ar[0][0] == 1):
		flag = 1
if flag == 0:
	print('NO')
else:
	print('YES')


(l, x) = ([[int(c) for c in input()[::2]] for _ in range(4)], 0)
for (i, r) in enumerate(l, -3):
	x |= r[3] and any([*r[:3], *[l[i + j][j] for j in range(3)]])
print(('NO', 'YES')[x])


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')


ar = []
result = 0
for i in range(4):
	ar += [list(map(int, input().split()))]
for i in range(4):
	if ar[i][3] == 1 and (ar[i][0] == 1 or ar[i][1] == 1 or ar[i][2] == 1):
		result = 'YES'
	else:
		if ar[i][0] == 1 and ar[(i - 1) % 4][3] == 1:
			result = 'YES'
		if ar[i][1] == 1 and ar[(i + 2) % 4][3] == 1:
			result = 'YES'
		if ar[i][2] == 1 and ar[(i + 1) % 4][3] == 1:
			result = 'YES'
if result == 0:
	result = 'NO'
print(result)


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')


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')


arr = []
for i in range(4):
	arr.append(input().split())
arr *= 3
flag = True
for i in range(4, 8):
	if arr[i][0] == '1':
		if arr[i - 1][3] == '1' or arr[i][3] == '1':
			print('YES')
			flag = False
			break
	if arr[i][1] == '1':
		if arr[i][3] == '1' or arr[i + 2][3] == '1':
			print('YES')
			flag = False
			break
	if arr[i][2] == '1':
		if arr[i][3] == '1' or arr[i + 1][3] == '1':
			print('YES')
			flag = False
			break
if flag:
	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):
	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')


r1 = list(map(int, input().split()))
r2 = list(map(int, input().split()))
r3 = list(map(int, input().split()))
r4 = list(map(int, input().split()))
if sum(r1[:3]) > 0 and r1[3] == 1:
	print('YES')
elif sum(r2[:3]) > 0 and r2[3] == 1:
	print('YES')
elif sum(r3[:3]) > 0 and r3[3] == 1:
	print('YES')
elif sum(r4[:3]) > 0 and r4[3] == 1:
	print('YES')
elif r1[0] == 1 and r4[3] == 1 or (r1[1] == 1 and r3[3] == 1) or (r1[2] == 1 and r2[3] == 1):
	print('YES')
elif r2[0] == 1 and r1[3] == 1 or (r2[1] == 1 and r4[3] == 1) or (r2[2] == 1 and r3[3] == 1):
	print('YES')
elif r3[0] == 1 and r2[3] == 1 or (r3[1] == 1 and r1[3] == 1) or (r3[2] == 1 and r4[3] == 1):
	print('YES')
elif r4[0] == 1 and r3[3] == 1 or (r4[1] == 1 and r2[3] == 1) or (r4[2] == 1 and r1[3] == 1):
	print('YES')
else:
	print('NO')


(l, s, r, p) = ([None] * 5, [None] * 5, [None] * 5, [None] * 5)
(l[1], s[1], r[1], p[1]) = map(int, input().split())
(l[2], s[2], r[2], p[2]) = map(int, input().split())
(l[3], s[3], r[3], p[3]) = map(int, input().split())
(l[4], s[4], r[4], p[4]) = map(int, input().split())
if l[1] and p[4] or (s[1] and p[3]) or (r[1] and p[2]) or ((l[1] or s[1] or r[1]) and p[1]):
	print('YES')
	exit(0)
if l[2] and p[1] or (s[2] and p[4]) or (r[2] and p[3]) or ((l[2] or s[2] or r[2]) and p[2]):
	print('YES')
	exit(0)
if l[3] and p[2] or (s[3] and p[1]) or (r[3] and p[4]) or ((l[3] or s[3] or r[3]) and p[3]):
	print('YES')
	exit(0)
if l[4] and p[3] or (s[4] and p[2]) or (r[4] and p[1]) or ((l[4] or s[4] or r[4]) and p[4]):
	print('YES')
	exit(0)
print('NO')


a = []
for i in range(4):
	a.append(list(map(int, input().split())))
crash = False
for i in range(4):
	if a[i][3] == 1:
		if a[(i + 1) % 4][0] or a[(i + 2) % 4][1] or a[(i - 1) % 4][2] or (sum(a[i]) > 1):
			crash = True
			break
if crash:
	print('YES')
else:
	print('NO')


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

def OK(i):
	if mas[i][3] == 0:
		return True
	if mas[i][0] + mas[i][1] + mas[i][2] + mas[(i + 3) % 4][2] + mas[(i + 1) % 4][0] + mas[(i + 2) % 4][1] > 0:
		return False
	return True
while i < 4 and OK(i):
	i += 1
if i == 4:
	print('NO')
else:
	print('YES')


def check(one, four, three, two):
	if one[0] == '1':
		if one[3] == '1' or four[3] == '1':
			print('YES')
			exit()
	if one[1] == '1':
		if one[3] == '1' or three[3] == '1':
			print('YES')
			exit()
	if one[2] == '1':
		if one[3] == '1' or two[3] == '1':
			print('YES')
			exit()
one = input().split(' ')
two = input().split(' ')
three = input().split(' ')
four = input().split(' ')
check(one, four, three, two)
check(two, one, four, three)
check(three, two, one, four)
check(four, three, two, one)
print('NO')


arr = [list(map(int, input().split())) for _ in range(4)]
flag = False
for i in range(4):
	f = False
	if arr[i][3] == 1:
		s = sum([arr[i][j] for j in range(3)]) + arr[(i + 2) % 4][1] + arr[(i + 1) % 4][0] + arr[(i + 3) % 4][2]
		if s > 0:
			f = True
	if f:
		flag = True
		break
if flag:
	print('YES')
else:
	print('NO')


a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
ans = False
if a[3]:
	ans = c[1] or b[0] or d[2] or a[0] or a[1] or a[2]
if not ans and b[3]:
	ans = d[1] or c[0] or a[2] or b[0] or b[1] or b[2]
if not ans and c[3]:
	ans = a[1] or d[0] or b[2] or c[0] or c[1] or c[2]
if not ans and d[3]:
	ans = b[1] or a[0] or c[2] or d[0] or d[1] or d[2]
print('YES' if ans else 'NO')


def plu(n):
	if n < 3:
		return n + 1
	else:
		return 0
f = 0
m = [[0 for i in range(4)] for j in range(4)]
for i in range(4):
	m2 = [int(i) for i in input().split()]
	for j in range(4):
		m[i][j] = m2[j]
for i in range(4):
	k = i
	if m[i][3] == 1:
		for j in range(3):
			if m[i][j] == 1:
				f = 1
		for j in range(3):
			k = plu(k)
			if m[k][j] == 1:
				f = 1
if f == 0:
	print('NO')
else:
	print('YES')


a = []
for i in range(4):
	tmp = list(map(int, input().split()))
	a.append(tmp)
crash = False
for i in range(4):
	for j in range(4):
		if a[i][j] == 1 and j < 3:
			if a[i][3] == 1:
				crash = True
				break
			elif j == 0:
				if a[i - 1 if i - 1 > -1 else 3][3] == 1:
					crash = True
					break
			elif j == 1:
				if a[i + 2 if i < 2 else i - 2][3] == 1:
					crash = True
					break
			elif j == 2:
				if a[i + 1 if i + 1 < 4 else 0][3] == 1:
					crash = True
					break
if crash:
	print('YES')
else:
	print('NO')


dat = list()
for i in range(4):
	dat.append(list(map(int, input().split())))
for i in range(4):
	if dat[i][3] == 1:
		a = (i + 1) % 4
		b = (i + 2) % 4
		c = (i + 3) % 4
		if dat[i][0] == 1 or dat[i][1] == 1 or dat[i][2] == 1 or (dat[a][0] == 1) or (dat[b][1] == 1) or (dat[c][2] == 1):
			print('YES')
			exit(0)
print('NO')