Alice has a birthday today, so she invited home her best friend Bob. Now Bob needs to find a way to commute to the Alice's home.

In the city in which Alice and Bob live, the first metro line is being built. This metro line contains $n$ stations numbered from $1$ to $n$. Bob lives near the station with number $1$, while Alice lives near the station with number $s$. The metro line has two tracks. Trains on the first track go from the station $1$ to the station $n$ and trains on the second track go in reverse direction. Just after the train arrives to the end of its track, it goes to the depot immediately, so it is impossible to travel on it after that.

Some stations are not yet open at all and some are only partially open — for each station and for each track it is known whether the station is closed for that track or not. If a station is closed for some track, all trains going in this track's direction pass the station without stopping on it.

When the Bob got the information on opened and closed stations, he found that traveling by metro may be unexpectedly complicated. Help Bob determine whether he can travel to the Alice's home by metro or he should search for some other transport.


-----Input-----

The first line contains two integers $n$ and $s$ ($2 \le s \le n \le 1000$) — the number of stations in the metro and the number of the station where Alice's home is located. Bob lives at station $1$.

Next lines describe information about closed and open stations.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($a_i = 0$ or $a_i = 1$). If $a_i = 1$, then the $i$-th station is open on the first track (that is, in the direction of increasing station numbers). Otherwise the station is closed on the first track.

The third line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($b_i = 0$ or $b_i = 1$). If $b_i = 1$, then the $i$-th station is open on the second track (that is, in the direction of decreasing station numbers). Otherwise the station is closed on the second track.


-----Output-----

Print "YES" (quotes for clarity) if Bob will be able to commute to the Alice's home by metro and "NO" (quotes for clarity) otherwise.

You can print each letter in any case (upper or lower).


-----Examples-----
Input
5 3
1 1 1 1 1
1 1 1 1 1

Output
YES

Input
5 4
1 0 0 0 1
0 1 1 1 1

Output
YES

Input
5 2
0 1 1 1 1
1 1 1 1 1

Output
NO



-----Note-----

In the first example, all stations are opened, so Bob can simply travel to the station with number $3$.

In the second example, Bob should travel to the station $5$ first, switch to the second track and travel to the station $4$ then.

In the third example, Bob simply can't enter the train going in the direction of Alice's home.

Source: codeforces | Difficulty: EASY
Tags: Graph algorithms


Solutions:
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s -= 1
if a[0] == 0:
	print('NO')
elif a[s] == 1:
	print('YES')
elif any([a[i] and b[i] for i in range(s, n)]) and b[s] == 1:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
d = list(map(int, input().split()))
x = 0
if l[0]:
	if l[s - 1] == 1:
		x = 1
		print('YES')
	else:
		for i in range(s - 1, n):
			if (l[i] == 1 and d[i] == 1) and d[s - 1] == 1:
				print('YES')
				x = 1
				break
		if x == 0:
			print('NO')
else:
	print('NO')


def backward_possible(backward, s):
	if backward[s] == 0:
		return False
	count = 0
	for (i, j) in zip(forward[s + 1:], backward[s + 1:]):
		if i == 1 and j == 1:
			break
		else:
			count += 1
	if count == len(forward[s + 1:]):
		return False
	else:
		return True
(n, s) = list(map(int, input().split()))
forward = list(map(int, input().split()))
backward = list(map(int, input().split()))
s -= 1
if forward[0] == 0 or forward[s] + backward[s] == 0:
	print('NO')
	exit()
if forward[s]:
	print('YES')
	exit()
elif backward_possible(backward, s):
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = False
if a[0] == 1 and a[s - 1] == 1:
	print('YES')
elif a[0] == 0:
	print('NO')
elif a[s - 1] == 0 and b[s - 1] == 0:
	print('NO')
elif a[s - 1] == 0:
	for i in range(s, n):
		if a[i] == 1 and b[i] == 1:
			print('YES')
			t = True
			break
	if not t:
		print('NO')


(n, s) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = 'NO'
if a[0]:
	if a[s - 1]:
		ans = 'YES'
	elif b[s - 1]:
		for i in range(s, n):
			if a[i] and b[i]:
				ans = 'YES'
				break
print(ans)


(n, m) = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
if l1[0] == 0:
	print('NO')
elif l1[m - 1] == 1:
	print('YES')
elif l2[m - 1] == 0:
	print('NO')
else:
	for i in range(m, n):
		if l1[i] == 1 and l2[i] == 1:
			print('YES')
			exit()
	print('NO')


(n, s) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
if a[0] == 0:
	print('NO')
	exit()
if a[s - 1] == 1:
	print('YES')
	exit()
if b[s - 1] == 0:
	print('NO')
	exit()
for i in range(s, n):
	if a[i] == b[i] == 1:
		print('YES')
		exit()
print('NO')


(n, s) = tuple(map(int, input().split()))
p1 = list(map(int, input().split()))
p2 = list(map(int, input().split()))
if p1[0] == 0 or (p1[s - 1] == 0 and p2[s - 1] == 0):
	print('NO')
	exit()
if p1[s - 1]:
	print('YES')
	exit()
for i in range(s - 1, n):
	if p1[i] and p2[i] and p2[s - 1]:
		print('YES')
		exit()
print('NO')


(N, S) = map(int, input().split())
a = []
b = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ok = 0
if a[0] == 0:
	ok = 0
elif a[S - 1] == 1:
	ok = 1
elif b[S - 1] == 1:
	for i in range(S, N):
		if a[i] == b[i] and a[i] == 1:
			ok = 1
else:
	ok = 0
if ok:
	print('YES')
else:
	print('NO')


(N, S) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
flag = False
for i in range(1, N):
	if a[i] == 1 and i == S - 1:
		flag = True
	elif a[i] == 1 and i > S - 1 and (b[i] == 1) and (b[S - 1] == 1):
		flag = True
if a[0] == 0:
	flag = False
if flag:
	print('YES')
else:
	print('NO')


(n, s) = [int(x) for x in input().split()]
lst1 = [int(x) for x in input().split()]
lst2 = [int(x) for x in input().split()]
if lst1[0] == 1 and lst1[s - 1] == 1:
	print('YES')
	exit()
elif lst1[0] == 0 or (lst1[s - 1] == 0 and lst2[s - 1] == 0):
	print('NO')
	exit()
for i in range(s, n):
	if lst1[i] == 1 and lst2[i] == 1:
		print('YES')
		exit()
print('NO')


(n, s) = list(map(int, input().split()))
s -= 1
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
elif a[s] == 1:
	print('YES')
elif b[s] == 0:
	print('NO')
elif any([x[0] == x[1] == 1 for x in zip(a[s:], b[s:])]):
	print('YES')
else:
	print('NO')


def solver(x, m, n):
	if x[0][0] ^ 1:
		return 'NO'
	if x[0][m - 1]:
		return 'YES'
	if x[1][m - 1] ^ 1:
		return 'NO'
	for i in range(m, n):
		if x[0][i] and x[1][i]:
			return 'YES'
	return 'NO'
(n, m) = map(int, input().split())
x = []
x.append([int(i) for i in input().split()])
x.append([int(j) for j in input().split()])
print(solver(x, m, n))


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
elif b[s - 1] == 0:
	print('NO')
else:
	f = 'NO'
	for i in range(s, n):
		if a[i] == b[i] == 1:
			f = 'YES'
			break
	print(f)


(n, s) = input().split()
(n, s) = (int(n), int(s))
line1 = list(map(int, input().split()))
line2 = list(map(int, input().split()))
if line1[0] != 1:
	print('NO')
	exit(0)
if line1[s - 1] == 1:
	print('YES')
	exit(0)
if line2[s - 1] != 1:
	print('NO')
	exit(0)
for i in range(s, len(line1)):
	if line1[i] == 1 and line2[i] == 1:
		print('YES')
		exit(0)
print('NO')


def inint():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def main():
	(n, s) = inlist()
	a = inlist()
	b = inlist()
	if a[0] == 0:
		print('NO')
		return
	if a[s - 1] == 0:
		ch = 0
		for i in range(s - 1, n):
			if a[i] == 1 and b[i] == 1:
				ch = 1
		if ch == 0:
			print('NO')
			return
	if a[s - 1] == 1 or b[s - 1] == 1:
		print('YES')
	else:
		print('NO')
main()


def solve(a, b, s):
	s = s - 1
	if a[0] == 0:
		return False
	if a[s] == 1:
		return True
	if s == len(a) - 1:
		return False
	if b[s] == 0:
		return False
	for k in range(s + 1, len(a)):
		if a[k] == b[k] == 1:
			return True
	return False

def main():
	(n, s) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	ok = solve(a, b, s)
	if ok:
		print('YES')
	else:
		print('NO')
main()


import sys
line = sys.stdin.readline().split()
(n, s) = (int(line[0]), int(line[1]))
line = sys.stdin.readline().split()
ascd = list(map(int, line))
line = sys.stdin.readline().split()
desc = list(map(int, line))
possible = False
if ascd[0] == 1:
	if ascd[s - 1] == 1:
		possible = True
	elif sum([1 for i in range(s, n) if ascd[i] + desc[i] > 1]) > 0 and desc[s - 1]:
		possible = True
if possible:
	print('YES')
else:
	print('NO')


from sys import stdin, stdout

def main():
	line = stdin.readline()
	parts = line.split()
	n = int(parts[0])
	s = int(parts[1])
	a = stdin.readline()
	b = stdin.readline()
	a = a.split()
	b = b.split()
	ans = 'NO'
	if int(a[0]) == 0:
		ans = 'NO'
	else:
		for i in range(len(a)):
			if i == s - 1 and int(a[i]) == 1:
				ans = 'YES'
				break
			if i > s - 1 and int(a[i]) == 1 and (int(b[i]) == 1) and (int(b[s - 1]) == 1):
				ans = 'YES'
				break
	stdout.write(ans)
main()


from sys import maxsize
(N, A) = list(map(lambda x: int(x), input().strip().split()))
inc = list(map(lambda x: int(x), input().strip().split()))
dec = list(map(lambda x: int(x), input().strip().split()))
inc.insert(0, maxsize)
dec.insert(0, maxsize)
if inc[1] == 0:
	print('NO')
elif inc[A]:
	print('YES')
elif inc[A] == 0 and dec[A] == 0:
	print('NO')
elif inc[A] == 0 and dec[A] == 1:
	for i in range(A, N + 1):
		if inc[i] == 1 and dec[i] == 1:
			print('YES')
			break
	else:
		print('NO')


inp = list(map(int, input().split()))
n = inp[0]
s = inp[1]
forward = list(map(int, input().split()))
backward = list(map(int, input().split()))
stacja = -1
if forward[0] == 0:
	print('NO')
elif forward[s - 1] == 1:
	print('YES')
else:
	for stacje in range(s, n):
		if forward[stacje] == 1 and backward[stacje] == 1:
			stacja = stacje
			break
	if stacja == -1:
		print('NO')
	elif backward[s - 1] == 1:
		print('YES')
	else:
		print('NO')


def compute():
	(n, s) = map(int, input().split(' '))
	s -= 1
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a[0] == 0:
		print('NO')
		return
	if a[s] == 1 or (b[s] == 1 and any((a[i] == 1 and b[i] == 1 for i in range(s + 1, n)))):
		print('YES')
	else:
		print('NO')
	return
compute()


(n, s) = map(int, input().split())
s1 = list(map(int, input().split()))
s2 = list(map(int, input().split()))
f = False
if s == 1:
	f = True
if s1[0] and (s1[s - 1] or s2[s - 1]):
	if s1[s - 1] == 1:
		f = True
	for i in range(s - 1, n):
		if s1[i] and s2[i]:
			f = True
			break
print('YES' if f else 'NO')


(n, s) = map(int, input().split())
forward_stations = list(map(lambda x: int(x) == 1, input().split()))
backward_stations = list(map(lambda x: int(x) == 1, input().split()))
if forward_stations[0]:
	if forward_stations[s - 1] or s == 1:
		print('YES')
	elif not backward_stations[s - 1]:
		print('NO')
	else:
		done = False
		for i in range(s - 1, n):
			if backward_stations[i] and forward_stations[i]:
				print('YES')
				done = True
				break
		if not done:
			print('NO')
else:
	print('NO')


import sys

def spitAnswer(numStations, alice, forward, backward):
	current = 0
	alice = alice - 1
	if not alice:
		return 'YES'
	if not forward[0]:
		return 'NO'
	if not forward[alice] and (not backward[alice]):
		return 'NO'
	elif forward[alice]:
		return 'YES'
	else:
		for i in range(alice, numStations):
			if forward[i] and backward[i]:
				return 'YES'
	return 'NO'
(numStations, alice) = [int(x) for x in input().split()]
forward = [int(x) for x in input().split()]
backward = [int(x) for x in input().split()]
print(spitAnswer(numStations, alice, forward, backward))


def solve(a, b, s):
	if a[s] == 0 and b[s] == 0:
		return 'NO'
	if a[0] == 0:
		return 'NO'
	if a[s] == 1:
		return 'YES'
	if any((a[i] == b[i] == 1 for i in range(s, len(a)))):
		return 'YES'
	return 'NO'
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
print(solve(a, b, s - 1))


(s, n) = map(int, input().split())
tuda = list(map(int, input().split()))
obratno = list(map(int, input().split()))
n -= 1
doexal = False
if tuda[0] == 1:
	if tuda[n] == 1:
		print('YES')
	elif obratno[n] == 0:
		print('NO')
	else:
		check = False
		for i in range(n, s):
			if tuda[i] == 1 and obratno[i] == 1:
				check = True
		if check:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


import sys
(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
	return
if a[s - 1]:
	print('YES')
	return
if b[s - 1]:
	for i in range(s, n):
		if a[i] and b[i]:
			print('YES')
			return
print('NO')


(b, a) = map(int, input().split())
(s1, s2) = (list(map(int, input().split())), list(map(int, input().split())))
if a == 1:
	print('YES')
	quit()
elif s1[0] == 0:
	print('NO')
	quit()
if s1[a - 1] == 1:
	print('YES')
	quit(0)
elif s1[-1] == 1 and s2[-1] == 1 and (s2[a - 1] == 1):
	print('YES')
	quit(0)
else:
	for i in range(a - 1, a - 1 + len(s1[a:])):
		if s1[i] == 1 and s2[i] == 1 and (s2[a - 1] != 0):
			print('YES')
			quit()
	else:
		print('NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0 or (b[s - 1] == 0 and a[s - 1] == 0):
	print('NO')
elif a[s - 1] == 1:
	print('YES')
elif s < n:
	for i in zip(a[s:], b[s:]):
		if i == (1, 1):
			print('YES')
			break
	else:
		print('NO')
else:
	print('NO')


chislo_stanzii_S = input()
Lchislo_stanzii_S = [int(t) for t in chislo_stanzii_S.split()]
N = Lchislo_stanzii_S[0]
S = Lchislo_stanzii_S[1]
stanzii_1_vetki = input()
stanzii_2_vetki = input()
Lstanzii_1_vetki = [int(a) for a in stanzii_1_vetki.split()]
Lstanzii_2_vetki = [int(a) for a in stanzii_2_vetki.split()]
if Lstanzii_1_vetki[0] == 0:
	print('NO')
	exit(0)
elif Lstanzii_1_vetki[S - 1] == 0 and Lstanzii_2_vetki[S - 1] == 0:
	print('NO')
	exit(0)
elif Lstanzii_1_vetki[S - 1] == 1:
	print('YES')
	exit(0)
else:
	for j in range(S, N):
		if Lstanzii_2_vetki[j] == 1 and Lstanzii_1_vetki[j] == 1:
			print('YES')
			exit(0)
	print('NO')


(n, s) = map(int, input().split(' '))
cima = input().split(' ')
baixo = input().split(' ')
if cima[0] == '0':
	print('NO')
elif cima[s - 1] == '0' and baixo[s - 1] == '0':
	print('NO')
elif cima[0] == '1' and cima[s - 1] == '1':
	print('YES')
elif cima[s - 1] == '0' and baixo[s - 1] == '1':
	for i in range(s, n):
		if cima[i] == '1' and baixo[i] == '1':
			print('YES')
			break
	else:
		print('NO')


(n, s) = map(int, input().split())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
s -= 1
flag = False
if first[0] == 0:
	flag = True
	print('NO')
if not flag:
	if first[s] == 1:
		print('YES')
	elif second[s] == 0:
		print('NO')
	else:
		aux = False
		for i in range(s, n):
			if first[i] == 1 and second[i] == 1:
				aux = True
		if aux:
			print('YES')
		else:
			print('NO')


import sys
(n, s) = map(int, input().split())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
if ai[0] == 0:
	print('NO')
elif (ai[s - 1] == 0) & (bi[s - 1] == 1):
	if (bi[-1] == 1) & (ai[-1] == 1):
		print('YES')
		sys.exit()
	for i in range(s, len(ai)):
		if ai[i] == bi[i] == 1:
			print('YES')
			sys.exit()
		else:
			h = 0
	if h == 0:
		print('NO')
elif ai[s - 1] == 1:
	print('YES')
elif (ai[s - 1] == 0) & (bi[s - 1] == 0):
	print('NO')
else:
	print('NO')


data = input().split()
n = int(data[0])
s = int(data[1])
up = input().split()
down = input().split()
if up[0] == '0':
	print('NO')
elif up[s - 1] == '1':
	print('YES')
elif down[s - 1] == '0':
	print('NO')
else:
	i = s - 1
	while i < n:
		if up[i] == '1' and down[i] == '1':
			break
		i += 1
	if i == n:
		print('NO')
	else:
		print('YES')


data = input().split()
n = int(data[0])
s = int(data[1])
first_line = input().split()
second_line = input().split()
first_line = [int(x) for x in first_line]
second_line = [int(x) for x in second_line]

def trace(n, s, first_line, second_line):
	forward = 1
	i = s - 1
	while i < n and i >= s - 1:
		if first_line[0] and (first_line[s - 1] or (i == s - 1 and (first_line[s - 1] and forward is 1 or (second_line[s - 1] and forward is -1)))):
			return 'YES'
		elif first_line[i] and second_line[i]:
			forward = -1
		i = i + 1 * forward
	return 'NO'
print(trace(n, s, first_line, second_line))


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def func(n, s, a, b):
	if a[0] == 0:
		return 'NO'
	elif a[s - 1] == 1:
		return 'YES'
	for i in range(s, n):
		if a[i] == 1 and b[i] == 1 and (b[s - 1] == 1):
			return 'YES'
	return 'NO'
print(func(n, s, a, b))


def reachable(s, l, r):
	if not r[0]:
		return False
	if r[s]:
		return True
	if not l[s]:
		return False
	return any(map(lambda arg: arg[0] == 1 and arg[1] == 1, zip(r[s:], l[s:])))
(n, s) = map(int, input().split(' '))
r = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
print('YES' if reachable(s - 1, l, r) else 'NO')


n = input().split()
n[0] = int(n[0])
n[1] = int(n[1])
lane_one = [int(i) for i in input().split()]
lane_two = [int(i) for i in input().split()]
if lane_one[0] == 0:
	print('NO')
elif lane_one[n[1] - 1] == 0 and lane_two[n[1] - 1] == 0:
	print('NO')
elif lane_one[0] == 1 and lane_one[n[1] - 1] == 1:
	print('YES')
else:
	for i in range(n[1], n[0]):
		if lane_one[i] and lane_two[i]:
			print('YES')
			break
	else:
		print('NO')


(n, m) = map(int, input().split())
(a, g) = (list(map(int, input().split())), list(map(int, input().split())))
if a[0] == 0 or (a[m - 1] == 0 and g[m - 1] == 0):
	print('NO')
elif len([g[q] for q in range(m, n) if g[q] and a[q]]) == 0 and a[m - 1] != 1:
	print('NO')
else:
	print('YES')


arr = list(map(int, input().strip().split()))
numOfStat = arr[0] - 1
position = arr[1] - 1
line1 = list(map(int, input().strip().split()))
line2 = list(map(int, input().strip().split()))
var = 0
if line1[0] is 1 and line1[position] is 1:
	answer = 'YES'
	print(answer)
elif line1[0] is 0:
	answer = 'NO'
	print(answer)
elif line2[position] is 1:
	accept = 0
	for i in range(arr[1], arr[0], 1):
		var = line1[i] + line2[i]
		if var == 2:
			accept += 1
		i += 1
	if accept == 0:
		answer = 'NO'
		print(answer)
	else:
		answer = 'YES'
		print(answer)
else:
	answer = 'NO'
	print(answer)


import math as mt
import sys, string
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda : list(map(int, input().split()))

def printARR(arr):
	for e in arr:
		print(e, end=' ')
	print()

def main():
	(n, s) = M()
	a = ARR()
	b = ARR()
	if a[0] == 0:
		print('NO')
		return
	if a[s - 1] == 1:
		print('YES')
		return
	if b[s - 1] == 0:
		print('NO')
		return
	for i in range(s, n):
		if a[i] & b[i]:
			print('YES')
			return
	print('NO')
tc = 1
for _ in range(tc):
	main()


from collections import defaultdict

def bfs(graph, s, d, l):
	visited = [False] * (2 * l - 1)
	q = []
	q.append(s)
	visited[s] = True
	while q:
		n = q.pop(0)
		if n == d:
			return True
		for i in graph[n]:
			if visited[i] == False:
				q.append(i)
				visited[i] = True
	return False
graph = defaultdict(list)
(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for i in range(n):
	for j in range(i + 1, n):
		if a[i] == 1 and a[j] == 1:
			graph[i].append(j)
for i in range(n):
	for j in range(i + 1, n):
		if b[n - i - 1] == 1 and b[n - j - 1] == 1:
			graph[n + i].append(n + j)
for i in range(n):
	graph[i].append(2 * n - i - 1)
	graph[2 * n - 1 - i].append(i)
if a[m - 1] != 1 and b[m - 1] != 1 or a[0] != 1:
	print('NO')
elif bfs(graph, 0, m - 1, 2 * n):
	print('YES')
else:
	print('NO')


def bfs(x):
	visited = [1 for _ in range(2 * n)]
	queue = [0]
	while queue:
		v = queue.pop(0)
		if v == x or v == 2 * n - x - 1:
			return 'YES'
		for next in G[v]:
			if visited[next]:
				visited[next] = 0
				queue.append(next)
	return 'NO'
(n, x) = map(int, input().split())
lineUp = list(map(int, input().split()))
lineDown = list(map(int, input().split()))
G = [[] for _ in range(n * 2)]
for i in range(n):
	if lineUp[i]:
		try:
			G[last1].append(i)
		except:
			None
		last1 = i
	if lineDown[n - i - 1]:
		try:
			G[last2].append(n + i)
		except:
			None
		last2 = n + i
	if lineUp[i] and lineDown[i]:
		G[i].append(2 * n - i - 1)
		G[2 * n - i - 1].append(i)
print(bfs(x - 1))


(n, ind) = map(int, input().split())
a = input().split()
b = input().split()
if a[0] == '0':
	print('NO')
elif a[ind - 1] == '1':
	print('YES')
elif b[ind - 1] != '1':
	print('NO')
else:
	can = False
	for i in range(ind, len(a)):
		if a[i] == '1' and b[i] == '1':
			can = True
			break
	if can:
		print('YES')
	else:
		print('NO')


(n, alice) = list(map(int, input().split()))
first_track = [0]
first_track.extend(list(map(int, input().split())))
second_track = [0]
second_track.extend(list(map(int, input().split())))

def fun():
	if first_track[1] == 0:
		print('NO')
		return
	elif first_track[alice] == 1:
		print('YES')
		return
	elif second_track[alice] == 1:
		for i in range(alice + 1, n + 1):
			if first_track[i] == 1 and second_track[i] == 1:
				print('YES')
				return
		print('NO')
		return
	else:
		print('NO')
		return
fun()


(tam, loc) = list(map(int, input().split()))
metro_ida = list(map(int, input().split()))
metro_volta = list(map(int, input().split()))
if metro_ida[0] != 0:
	if metro_ida[loc - 1] != 0:
		print('YES')
	elif metro_volta[loc - 1] == 0:
		print('NO')
	else:
		for i in range(loc, tam):
			if metro_ida[i] == 1:
				if metro_volta[i] == 1:
					print('YES')
					break
		else:
			print('NO')
else:
	print('NO')


(a, b) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
S1 = set()
S2 = set()
if A[0] == 0 or (A[b - 1] == 0 and B[b - 1] == 0):
	print('NO')
	exit()
if A[b - 1] == 1:
	print('YES')
	exit()
for i in range(b - 1, a):
	if B[i] == 1:
		S1.add(i)
for i in range(0, a):
	if A[i] == 1:
		S2.add(i)
if len(S1.intersection(S2)) > 0:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
a = [i for i in input().split()]
b = [i for i in input().split()]
a.insert(0, '0')
b.insert(0, '0')
if a[1] == '0':
	print('NO')
	exit()
if a[1] == '1' and a[s] == '1':
	print('YES')
	exit()
if a[s] == '0' and b[s] == '0':
	print('NO')
	exit()
left = False
right = False
for i in range(1, s):
	if a[i] == '1' and b[i] == '1':
		left = True
for i in range(s + 1, len(a)):
	if a[i] == '1' and b[i] == '1':
		right = True
if right and b[s] == '1':
	print('YES')
else:
	print('NO')
	exit()


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = 0
d = a[s:]
t = b[s:]
for i in range(len(d)):
	if d[i] == 1:
		for j in t:
			if t[i] == 1 and b[s - 1] == 1:
				c = 1
if a[0] == 1:
	if a[s - 1] == 1 or c == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(num_estacoes, estacao_destino) = map(int, input().split())
primeira_faixa = list(map(int, input().split()))
segunda_faixa = list(map(int, input().split()))
if primeira_faixa[0] and primeira_faixa[estacao_destino - 1]:
	print('YES')
	exit()
if primeira_faixa[0]:
	flag = True
else:
	flag = False
aux = [0]
for i in range(1, num_estacoes):
	if primeira_faixa[i] and segunda_faixa[i]:
		aux.append(i)
if max(aux) >= estacao_destino and segunda_faixa[estacao_destino - 1] and flag:
	print('YES')
else:
	print('NO')


(sta1, sta2, inp) = ([], [], [])
inp = input().split(' ')
n = int(inp[0])
s = int(inp[1])
sta1 = input().split()
sta2 = input().split()
if sta1[0] == '1' and sta1[s - 1] == '1':
	print('YES')
elif sta1[0] == '1' and sta1[s - 1] != '1':
	if sta2[s - 1] == '0':
		print('NO')
	else:
		for i in range(s, n):
			if sta1[i] == '1' and sta2[i] == '1':
				print('YES')
				break
		else:
			print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
array = []
for _ in range(2):
	array.append([int(i) for i in input().split()])
if array[0][0] == 0:
	print('NO')
	exit()
if array[0][s - 1] == 1:
	print('YES')
	exit()
if array[1][s - 1] == 0:
	print('NO')
	exit()
for i in range(s, n):
	if array[0][i] == array[1][i] and array[0][i] == 1:
		print('YES')
		exit()
print('NO')


(n, s) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
if l1[0] == 1 and l1[s - 1] == 1:
	print('YES')
elif l2[s - 1] == 1 and l1[0] == 1:
	ans = 'NO'
	for i in range(s - 1, n):
		if l1[i] and l2[i]:
			ans = 'YES'
	print(ans)
else:
	print('NO')


X = list(map(int, input().split()))
(Metro1, Metro2) = (list(map(int, input().split())), list(map(int, input().split())))
if Metro1[0] == 0 and X[1] != 1 or (Metro1[X[1] - 1] == 0 and Metro2[X[1] - 1] == 0):
	print('NO')
	exit()
i = X[1] - 1
while i < X[0]:
	if Metro1[X[1] - 1] == 1 or Metro1[i] == Metro2[i] == 1:
		print('Yes')
		exit()
	i += 1
print('NO')


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
k = list(map(int, input().split()))
if l[0] == 0:
	print('NO')
elif l[s - 1] == 1:
	print('Yes')
else:
	p = []
	for i in range(s, n):
		if l[i] == 1:
			p.append(i)
	if len(p) == 0:
		print('No')
	else:
		f = 0
		for i in p:
			if k[i] == 1:
				for j in range(i, s - 1, -1):
					if k[j] == 1:
						f = 1
						break
		if f == 1 and k[s - 1] == 1:
			print('Yes')
		else:
			print('No')


class CodeforcesTask1055ASolution:

	def __init__(self):
		self.result = ''
		self.n_s = []
		self.line1 = []
		self.line2 = []

	def read_input(self):
		self.n_s = [int(x) for x in input().split(' ')]
		self.line1 = [int(x) for x in input().split(' ')]
		self.line2 = [int(x) for x in input().split(' ')]

	def process_task(self):
		if self.line1[0]:
			if self.line1[self.n_s[1] - 1]:
				self.result = 'YES'
			elif self.line2[self.n_s[1] - 1]:
				can = False
				for x in range(self.n_s[1], self.n_s[0]):
					if self.line1[x] and self.line2[x]:
						can = True
						break
				self.result = 'YES' if can else 'NO'
			else:
				self.result = 'NO'
		else:
			self.result = 'NO'

	def get_result(self):
		return self.result
Solution = CodeforcesTask1055ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


(n, s) = map(int, input().split())
first_track = list(map(int, input().split()))
second_track = list(map(int, input().split()))
if first_track[0] == 0:
	print('NO')
	exit()
if first_track[s - 1] == 1:
	print('YES')
	exit()
if second_track[s - 1] == 0:
	print('NO')
	exit()
for i in range(s, n):
	if second_track[i] * first_track[i] == 1:
		print('YES')
		exit()
print('NO')


(n, s) = map(int, input().split())
side1 = list(map(int, input().split()))
side2 = list(map(int, input().split()))
possible = False
if side1[0] and side1[s - 1]:
	possible = True
else:
	for i in range(s, n):
		if side1[0] and side1[i] and side2[i] and side2[s - 1]:
			possible = True
			break
if possible:
	print('YES')
else:
	print('NO')


from collections import defaultdict
rpta = False
grafo = defaultdict(list)
item = [int(x) for x in input().split()]
item[1] -= 1
dir1 = [int(x) for x in input().split()]
dir2 = [int(x) for x in input().split()]
flag = [0] * item[0]
dir1 = [x for x in range(item[0]) if dir1[x] == 1]
dir2 = [x for x in range(item[0]) if dir2[x] == 1]
for idx in range(len(dir1) - 1):
	grafo[dir1[idx]].append(dir1[idx + 1])
for idx in range(len(dir2) - 1, 0, -1):
	grafo[dir2[idx]].append(dir2[idx - 1])
cola = [0]
while len(cola) != 0:
	if flag[cola[0]] == 0:
		flag[cola[0]] = 1
		if cola[0] == item[1]:
			rpta = True
			break
		for idx in grafo[cola[0]]:
			if flag[idx] == 0:
				cola.append(idx)
	cola = cola[1:len(cola)]
if rpta:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
a = [*map(int, input().split())]
b = [*map(int, input().split())]
s -= 1
if a[0] == 0:
	print('NO')
	exit(0)
if a[s] == 1:
	print('YES')
else:
	i = -1
	for j in range(s + 1, n):
		if a[j] == b[j] == 1:
			i = j
	if i == -1 or b[s] == 0:
		print('NO')
	else:
		print('YES')


def check():
	if s == 1:
		print('YES')
		return
	else:
		if As[s - 1] == 1 and As[0] != 0:
			print('YES')
			return
		elif As[0] != 0 and As[s - 1] == 0 and (Bs[s - 1] == 1):
			for i in range(s - 1, n):
				if As[i] == 1 and Bs[i] == 1:
					print('YES')
					return
		print('NO')
(n, s) = map(int, input().split(' '))
As = list(map(int, input().split(' ')))
Bs = list(map(int, input().split(' ')))
check()


(l, a) = list(map(int, input().split(' ')))
(s1, s2) = (list(map(int, input().split(' '))), list(map(int, input().split(' '))))
if s1[0] == 0 or (s1[a - 1] == 0 and s2[a - 1] == 0):
	print('NO')
	raise SystemExit(0)
elif s1[a - 1] == 1:
	print('YES')
	raise SystemExit(0)
else:
	for i in range(a, l):
		if s1[i] == 1 and s2[i] == 1:
			print('YES')
			raise SystemExit(0)
print('NO')


def solve(a, d, s):
	if a[0] == '0':
		return 'NO'
	if a[s] == '1':
		return 'YES'
	for i in range(len(a) - 1, -1, -1):
		if a[i] == '1' and d[i] == '1':
			break
	else:
		return 'NO'
	if s <= i and d[s] == '1':
		return 'YES'
	return 'NO'
s = int(input().split()[1]) - 1
a = input().split()
d = input().split()
print(solve(a, d, s))


(n, m) = map(int, input().split())
m -= 1
a = list(map(int, input().split()))
b = list(map(int, input().split()))
x = 0
v = 0
if a[0] == 0 or (b[m] == 0 and a[m] == 0):
	print('NO')
else:
	while x != n:
		if x == m and a[x] == 1:
			print('YES')
			break
		if x > m:
			if a[x] == b[x] == 1:
				v = 0
				print('YES')
				break
		x += 1
	else:
		print('NO')


(n, s) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
for i in range(n):
	if a[0] == 0 or (a[s - 1] == 0 and b[s - 1] == 0):
		print('NO')
		exit()
	elif a[i] == 1 and i == s - 1:
		print('YES')
		exit()
	elif s < i + 1:
		if a[i] == 1 and b[i] == 1:
			j = i - 1
			while j >= 0:
				if b[j] == 1:
					print('YES')
					exit()
				j -= 1
else:
	print('NO')


(n, s) = map(int, input().split())
opened = []
for i in range(2):
	opened.append(list(map(int, input().split())))
if opened[0][0] == 0:
	print('NO')
elif opened[0][s - 1] == 1:
	print('YES')
elif opened[1][s - 1] == 0:
	print('NO')
else:
	flag = False
	for t in range(s, n):
		if opened[0][t] == 1 and opened[1][t] == 1:
			print('YES')
			flag = True
			break
	if flag == False:
		print('NO')


import sys

def rint():
	return map(int, sys.stdin.readline().split())
(n, s) = rint()
a = list(rint())
b = list(rint())
a = [0] + a
b = [0] + b
if a[1] == 1:
	if a[s] == 1:
		print('YES')
	elif b[s] == 1:
		for j in range(s + 1, n + 1):
			if a[j] * b[j]:
				print('YES')
				break
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
ia = input().split()
result = 'NO'
a = []
for i in ia:
	a.append(int(i))
ib = input().split()
b = []
for i in ib:
	b.append(int(i))
if a[0] == 1:
	if a[s - 1] == 1:
		result = 'YES'
	if a[s - 1] == 0 and b[s - 1] == 1 and (s != n):
		for i in range(s, n):
			if a[i] == 1 and b[i] == 1:
				result = 'YES'
				break
print(result)


(n, s) = [int(s) for s in input().split(' ')]
a = [True if int(s) == 1 else False for s in input().split(' ')]
b = [True if int(s) == 1 else False for s in input().split(' ')]
if not a[0]:
	print('NO')
	exit()
if a[s - 1]:
	print('YES')
	exit()
if not b[s - 1]:
	print('NO')
	exit()
for i in range(s, n):
	if a[i] == b[i] == True:
		print('YES')
		exit()
print('NO')


def dfs(graph, i, s, n, mark):
	mark[i] = 1
	if mark[s - 1] == 1:
		return
	for j in range(n):
		if graph[i][j] == 1 and mark[j] == 0:
			dfs(graph, j, s, n, mark)
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
mark = [0] * n
graph = []
for _ in range(n):
	temp = [0] * n
	graph.append(temp)
prev = -1
for i in range(len(a)):
	if a[i] == 1:
		if prev == -1:
			prev = i
		else:
			graph[prev][i] = 1
			prev = i
prev = -1
for i in range(len(b) - 1, -1, -1):
	if b[i] == 1:
		if prev == -1:
			prev = i
		else:
			graph[prev][i] = 1
			prev = i
dfs(graph, 0, s, n, mark)
if mark[s - 1]:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
is_ = True
if first[0] == 0 or (first[s - 1] == 0 and second[s - 1] == 0):
	is_ = False
elif first[s - 1] == 0:
	for i in range(s, n):
		if first[i] == 1 and second[i] == 1:
			is_ = True
			break
		else:
			is_ = False
print('YES' if is_ else 'NO')


(n, s) = list(map(int, input().split()))
first_track = list(map(int, input().split()))
second_track = list(map(int, input().split()))
if first_track[0] and first_track[s - 1]:
	print('YES')
elif first_track[0]:
	change_track = False
	for k in range(s, n):
		if first_track[k] and second_track[k]:
			change_track = True
	if second_track[s - 1] and change_track:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


def depthFirstSearch(root, visited, s, graph):
	if root == s:
		visited[root] = 1
		return True
	else:
		try:
			visited[root] = 1
			for i in graph[root]:
				if visited[i] == 0:
					boolReturn = depthFirstSearch(i, visited, s, graph)
					if boolReturn == True:
						return True
			return False
		except:
			return False
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
graph = {}
if s == 1:
	print('YES')
elif a[0] == 0:
	print('NO')
else:
	visited = [0] * (n + 1)
	temp = 1
	for i in range(1, n):
		if a[i] == 1:
			try:
				graph[temp].append(i + 1)
			except:
				graph[temp] = [i + 1]
			temp = i + 1
	temp = -1
	for i in range(n - 1, -1, -1):
		if b[i] == 1:
			if temp == -1:
				temp = i + 1
			else:
				try:
					graph[temp].append(i + 1)
				except:
					graph[temp] = [i + 1]
				temp = i + 1
	result = depthFirstSearch(1, visited, s, graph)
	if result == False:
		print('NO')
	else:
		print('YES')


import sys
import string
from math import gcd
import getpass
import math
from decimal import Decimal
import pprint

def ria():
	return [int(i) for i in input().split()]
if getpass.getuser() != 'frohenk':
	filename = 'half'
else:
	sys.stdin = open('input.txt')
(n, s) = ria()
s -= 1
ar1 = ria()
ar2 = ria()
if ar1[0] == 0:
	print('NO')
	return
if ar1[s] == 1:
	print('YES')
	return
if ar2[s] == 1:
	for i in range(s, n):
		if ar2[i] == 1 and ar1[i] == 1:
			print('YES')
			return
print('NO')


(n, s) = map(int, input().split())
n1 = list(map(int, input().split()))
n2 = list(map(int, input().split()))
if n1[0] == 0:
	print('NO')
elif n1[s - 1] == 1:
	print('YES')
elif n2[s - 1] == 0:
	print('NO')
else:
	ans = 'NO'
	for i in range(s - 1, n):
		if n1[i] == 1 and n2[i] == 1:
			ans = 'YES'
			break
	print(ans)


import sys
from math import ceil, floor, log2, sqrt
GLOBALMAX = 0
adj = [list() for i in range(10000)]

def readall():
	return [int(x) for x in sys.stdin.read().split()]

def u():
	return [int(i) for i in sys.stdin.readline().split()]

def primeCheck(x):
	if x == 2:
		return True
	if x % 2 == 0:
		return False
	i = 3
	while i ** 2 <= x:
		if x % i == 0:
			return False
		i += 2
	return True

def adjDFS(nod, count=0):
	global GLOBALMAX
	count += 1
	for slave in adj[nod]:
		adjDFS(slave, count)
	GLOBALMAX = max(GLOBALMAX, count)
(n, k) = u()
l1 = u()
l2 = u()
if not l1[0]:
	print('nO')
	exit()
if l1[k - 1]:
	print('yes')
	exit()
if not l2[k - 1]:
	print('no')
	exit()
for i in range(k - 1, n):
	if l1[i] and l2[i]:
		print('yEs')
		exit()
print('no')
exit()


(n, s) = input().split()
n = int(n)
s = int(s)
a = input().split()
b = input().split()
for j in range(n):
	a[j] = int(a[j])
	b[j] = int(b[j])
if a[0] == 1:
	if a[s - 1] == 1:
		print('YES')
	elif b[s - 1] == 1:
		for i in range(s, n):
			if a[i] == 1 and b[i] == 1:
				print('YES')
				break
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


R = lambda : list(map(int, input().split()))
(n, s) = R()
(a, b) = (R(), R())
if a[0] == 0:
	print('nO')
elif a[0] == 1 and a[s - 1] == 1:
	print('yES')
elif b[s - 1] == 0:
	print('No')
else:
	for i in range(s - 1, n):
		if b[i] == 1 and a[i] == 1:
			print('YES')
			break
	else:
		print('No')


gcd = lambda a, b: gcd(b, a % b) if b else a

def main():
	(n, m) = list(map(int, input().split()))
	arr = [0] + list(map(int, input().split()))
	brr = [0] + list(map(int, input().split()))
	if not arr[1]:
		print('NO')
		return
	if arr[m]:
		print('YES')
		return
	if brr[m]:
		for i in range(m + 1, n + 1):
			if arr[i] and brr[i]:
				print('YES')
				return
	print('NO')
	return
main()


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
elif b[s - 1] == 1:
	x = s
	y = n - 1
	flag = 1
	while x < n:
		if a[x] == b[x] and a[x] == 1:
			flag = 0
			print('YES')
			break
		x += 1
	if flag == 1:
		print('NO')
else:
	print('NO')


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
if l[0] == 0:
	print('NO')
	exit()
if l[m - 1] == 1:
	print('YES')
	exit()
for i in range(m, n):
	if l[i] == 1 == l1[i] == l1[m - 1]:
		print('YES')
		exit()
print('NO')


t = 1
while t:
	t -= 1
	ok = False
	(n, s) = map(int, input().split())
	a = [list(map(int, input().split())) for _ in range(2)]
	for i in range(n - 1, -1, -1):
		if a[0][i] and a[1][i] and (i >= s - 1):
			ok = True
	if not a[0][0]:
		print('NO')
	elif ok and a[1][s - 1] or a[0][s - 1]:
		print('YES')
	else:
		print('NO')


(n, s) = map(int, input().split())
g = list(map(int, input().split()))
c = list(map(int, input().split()))
if g[s - 1] == 1 and g[0] == 1:
	print('YES')
elif c[s - 1] == 1 and g[0] == 1:
	flag = 0
	for i in range(s, n):
		if g[i] == 1 and c[i] == 1:
			flag = 1
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
a = input().split()
b = input().split()
pa = False
ans = True
if int(a[0]) == 0:
	ans = False
for i in range(n):
	if not pa:
		if int(b[n - 1 - i]) == 1 and int(a[n - 1 - i]) == 1:
			pa = True
	if int(b[n - 1 - i]) == 1 and pa:
		a[n - 1 - i] = '1'
if int(a[s - 1]) == 1 and ans:
	print('YES')
else:
	print('NO')


def find_route():
	a = input().split()
	track_1 = input().split()
	track_2 = input().split()
	if int(track_1[0]) == 0:
		print('NO')
	elif int(track_1[int(a[1]) - 1]) == 1:
		print('YES')
	elif int(track_2[int(a[1]) - 1]) == 0 and int(track_1[int(a[1]) - 1]) == 0:
		print('NO')
	elif a[0] == a[1]:
		print('NO')
	else:
		i = int(a[1])
		while i < int(a[0]):
			if int(track_1[i]) * int(track_2[i]) == 1:
				break
			else:
				i += 1
		if i < int(a[0]):
			print('YES')
		else:
			print('NO')
find_route()


input1 = list(map(int, input().split()))
track1 = list(map(int, input().split()))
track2 = list(map(int, input().split()))
numStations = input1[0]
targetIndex = input1[1] - 1
flag = False
lastStationTransfer = 0
for i in range(0, numStations):
	if track1[i] == 1:
		if i == targetIndex:
			flag = True
			break
for i in range(0, numStations):
	if track1[i] == 1 and track2[i] == 1:
		lastStationTransfer = max(lastStationTransfer, i)
if not flag:
	for i in range(lastStationTransfer, 0, -1):
		if track2[i] == 1:
			if i == targetIndex:
				flag = True
				break
if track1[0] == 0:
	flag = False
if flag:
	print('YES')
else:
	print('NO')


(n, s) = [int(x) for x in input().split()]
t1 = [int(x) for x in input().split()]
t2 = [int(x) for x in input().split()]
resp = 'NO'
if t1[0]:
	if t1[s - 1]:
		resp = 'YES'
	elif t2[s - 1]:
		for i in range(s, n):
			if t1[i] and t2[i]:
				resp = 'YES'
				break
print(resp)


(n, s) = map(int, input().split(' '))
a = [None]
b = [None]
a.extend(list(map(int, input().split(' '))))
b.extend(list(map(int, input().split(' '))))
f = 0
if a[1] != 0 and (a[s] != 0 or b[s] != 0):
	i = s
	if a[i] == 1:
		f = 1
	else:
		i += 1
		while i <= n:
			if a[i] == 1:
				if b[i] == 1:
					f = 1
					break
				i += 1
				continue
			i += 1
if f == 0:
	print('NO')
else:
	print('YES')


(n, s) = map(int, input().split())
go = list(map(int, input().split()))
come = list(map(int, input().split()))
if go[0] == 0:
	print('NO')
	exit()
if go[s - 1] == 0 and come[s - 1] == 0:
	print('NO')
	exit()
if go[s - 1] == 1:
	print('YES')
	exit()
for i in range(s, n):
	if go[i] == 1 and come[i] == 1:
		print('YES')
		exit()
print('NO')


import math
import sys

class Graph:

	def __init__(self, Nodes, is_directed=False):
		self.nodes = Nodes
		self.adj_list = {}
		self.is_directed = is_directed
		for node in self.nodes:
			self.adj_list[node] = []

	def add_edge(self, u, v):
		if v not in self.adj_list[u]:
			self.adj_list[u].append(v)
		if self.is_directed == False:
			if u not in self.adj_list[v]:
				self.adj_list[v].append(u)

	def print_graph(self):
		for node in self.nodes:
			print(node, '->', self.adj_list[node])

	def degree_node(self, node):
		return len(self.adj_list[node])

	def dfsUTIL(self, v, visited, parents=[]):
		parents.append(v)
		visited[v] = True
		for i in self.adj_list[v]:
			if visited[i] == False:
				self.dfsUTIL(i, visited, parents)

	def dfs(self, v):
		visited = [False] * (max(self.adj_list) + 5)
		parents = []
		self.dfsUTIL(v, visited, parents)
		return parents

def dict_sort(ans):
	ans = sorted(ans.items(), reverse=True, key=lambda kv: kv[1])

def is_prime(n):
	if n == 1:
		return 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			return False
	return True

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def seive_primes(n):
	flag = [0] * (n + 10)
	flag[1] = flag[0] = 1
	i = 2
	while i * i <= n + 1:
		if flag[i] == 0:
			j = i * i
			while j <= n + 1:
				flag[j] = 1
				j += i
		i += 1
	return flag

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def alphabates():
	return 'abcdefghijklmnopqrstuvwxyz'

def binary_search(ls, n, flag):
	low = 0
	hi = n - 1
	while low <= hi:
		mid = (low + hi) // 2
		if ls[mid] == flag:
			return mid
		elif ls[mid] > flag:
			hi = mid - 1
		else:
			low = mid + 1
	return -1

def qdrt(x, a, b, c):
	return a * x * x + b * x + c

def inp():
	ls = list(map(int, input().split()))
	return ls

def mult_inp():
	return map(int, input().split())
(n, d) = mult_inp()
graph = Graph([i + 1 for i in range(n)], True)
samne = inp()
pisone = inp()
if samne[0] == 0:
	print('no')
else:
	for i in range(n):
		if samne[i] == 1:
			graph.add_edge(1, i + 1)
	if pisone[d - 1] == 1:
		for j in range(d, n):
			if samne[j] == pisone[j] == 1:
				graph.add_edge(1, j + 1)
				graph.add_edge(1, d)
	ls = graph.dfs(1)
	if d in ls:
		print('yes')
	else:
		print('no')


(n, s) = map(int, input().split())
a = [int(el) for el in input().split()]
b = [int(el) for el in input().split()]
s -= 1
if a[0] == 0 or (a[s] == 0 and b[s] == 0):
	print('NO')
elif a[s] == 1:
	print('YES')
else:
	ss = 'NO'
	for i in range(s, n):
		if a[i] + b[i] == 2:
			ss = 'YES'
	print(ss)


(n, s) = map(int, input().split())
s -= 1
a = list(map(int, input().split()))
b = list(map(int, input().split()))

def stop():
	print('NO')
	exit(0)
if a[0] == 1:
	if a[s] == 0:
		if b[s] == 1:
			for j in range(s, n, 1):
				if a[j] == 1 and b[j] == 1:
					print('YES')
					exit(0)
			stop()
		else:
			stop()
	else:
		print('YES')
		exit()
else:
	stop()


(n, s) = [int(x) for x in input().split()]
forward = [int(x) for x in input().split()]
count_forward = forward.count(1)
backward = [int(x) for x in input().split()]
count_backward = backward.count(1)
if not forward[0] or (not forward[s - 1] and (not backward[s - 1])):
	print('NO')
elif forward[s - 1]:
	print('YES')
elif not forward[s - 1]:
	if backward[s - 1]:
		for x in range(s, n):
			if forward[x] and backward[x]:
				print('YES')
				break
		else:
			print('NO')


ns = input().split(' ')
n = int(ns[0])
s = int(ns[1])
mas1 = input().split(' ')
for i in range(n):
	mas1[i] = int(mas1[i])
mas2 = input().split(' ')
for i in range(n):
	mas2[i] = int(mas2[i])
if s == 1:
	print('YES')
elif mas1[0] == 0:
	print('NO')
elif mas1[s - 1] == 1 or mas2[s - 1] == 1:
	if mas1[s - 1] == 1:
		print('YES')
	else:
		for i in range(s, n):
			if mas1[i] == 1 and mas2[i] == 1:
				print('YES')
				exit()
		print('NO')
else:
	print('NO')


(n, s) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = 0
c = 0
if a[0] == 0:
	print('NO')
elif a[s - 1] == 0:
	for station in a[s:]:
		if station == 1 and b[a.index(station, s + c)] == 1:
			if b[s - 1] == 1:
				ans = 1
		c += 1
	if ans == 1:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


(s, n) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
f = 0
if l1[0] == 1:
	if l1[n - 1] == 1:
		print('YES')
	else:
		for i in range(n, s):
			if l1[i] == 1 and l2[n - 1] == 1 and (l2[i] == 1):
				f = 1
				break
		if f == 1:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


from sys import stdin, stdout
from math import sin, tan, cos, pi, atan2, sqrt, acos, atan, factorial
(n, s) = map(int, stdin.readline().split())
(a, b) = (list(map(int, stdin.readline().split())), list(map(int, stdin.readline().split())))
s -= 1
if not a[0] or (not a[s] and (not b[s])):
	stdout.write('NO\n')
elif a[s]:
	stdout.write('YES\n')
else:
	for i in range(s, n):
		if a[i] and b[i]:
			stdout.write('YES\n')
			break
	else:
		stdout.write('NO\n')


(n, s) = map(int, input().split())
d1 = [int(i) for i in input().split()]
d2 = [int(i) for i in input().split()]
s -= 1
if d1[0] == 0:
	print('NO')
else:
	f = 0
	ind = -1
	for i in range(n):
		if d1[s] == 1:
			f = 1
			break
		elif i > s:
			if d2[i] == 1 and d1[i] == 1:
				ind = i
				break
	if f == 0 and ind != -1:
		for i in range(ind, -1, -1):
			if d2[s] == 1:
				f = 1
				break
			elif i < s:
				break
	if f == 0:
		print('NO')
	else:
		print('YES')


from collections import deque

def solve(n, s, a, b):
	if a[0] == 0:
		return False
	check = deque([0])
	processed = set()
	while len(check) > 0:
		current = check.pop()
		if current == s - 1:
			return True
		if a[current] == 1:
			for i in range(current + 1, n):
				if a[i] == 1 and i not in processed:
					check.append(i)
					break
		if b[current] == 1:
			for i in range(current - 1, -1, -1):
				if b[i] == 1 and i not in processed:
					check.append(i)
					break
		processed.add(current)
	return False
(n, s) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
result = solve(n, s, a, b)
if result:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
s = s - 1
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if a[0] == 0:
	print('NO')
elif (a[s], b[s]) == (0, 0):
	print('NO')
elif a[s] == 1:
	print('YES')
elif b[s] == 0:
	print('NO')
else:
	for i in range(s + 1, n):
		if (a[i], b[i]) == (1, 1):
			print('YES')
			exit(0)
	print('NO')


def metro(a, b, n, x):
	if a[0] == 0:
		return 'NO'
	if a[x] == 0 and b[x] == 0:
		return 'NO'
	if a[x] == 1:
		return 'YES'
	for i in range(x, n):
		if a[i] == 1 and b[i] == 1:
			return 'YES'
	return 'NO'
(n, s) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
print(metro(a, b, n, s - 1))


t = list(map(int, input().split()))
n = t[0]
s = t[1]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
i = s
if a[0] == 1:
	if a[s - 1] == 1:
		print('YES')
		i = n
	elif i == n and a[n - 1] == 0:
		print('NO')
	else:
		while i < n:
			if a[i] == 1 and b[i] == 1 and (b[s - 1] == 1):
				print('YES')
				i = n + 1
			else:
				i += 1
			if i == n:
				print('NO')
elif s == 1:
	print('YES')
else:
	print('NO')


try:
	(n, s) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a[0] == True:
		if a[s - 1] == True:
			print('YES')
		elif b[s - 1] == True:
			flag = 0
			for i in range(s, n):
				if a[i] and b[i]:
					flag = 1
			if flag:
				print('YES')
			else:
				print('NO')
		else:
			print('NO')
	else:
		print('NO')
except:
	print(a)
	print(b)


(n, s) = [int(x) for x in input().split(' ')]
a = [int(x) for x in input().split(' ')]
b = [int(x) for x in input().split(' ')]
if a[0] == 0:
	print('NO')
elif a[s - 1] == 0 and b[s - 1] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
else:
	matched = False
	for i in range(s, len(a)):
		if a[i] == 1 and b[i] == 1:
			print('YES')
			matched = True
			break
	if not matched:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newLines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def readline(self):
		while self.newLines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newLines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newLines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
(n, s) = map(int, input().split())
track1 = list(map(int, input().split()))
track2 = list(map(int, input().split()))

def solve(track1, track2, n, s):
	if track1[0] == 0:
		return 'NO'
	elif track1[s - 1] == 1:
		return 'YES'
	else:
		for i in range(s - 1, n):
			if track1[i] == 1 and track2[i] == 1 and (track2[s - 1] == 1):
				return 'YES'
	return 'NO'
print(solve(track1, track2, n, s))


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s -= 1
transaction = []
for i in range(n):
	if a[i] == 1 and b[i] == 1:
		transaction.append(1)
	else:
		transaction.append(0)
if a[0] == 0 or (a[s] == 0 and b[s] == 0):
	print('NO')
elif a[s] == 1:
	print('YES')
elif b[s] == 1 and transaction[s + 1:].__contains__(1):
	print('YES')
else:
	print('NO')


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
except Exception:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N, S) = getIntList()
z1 = getIntList()
z2 = getIntList()
if z1[0] == 0:
	print('NO')
	sys.exit()
if z1[S - 1] == 1:
	print('YES')
	sys.exit()
if z2[S - 1] == 0:
	print('NO')
	sys.exit()
for i in range(S - 1, N):
	if z1[i] == 1 and z2[i] == 1:
		print('YES')
		sys.exit()
print('NO')


(n, s) = map(int, input().split())
first_way = [int(i) for i in input().split()]
second_way = [int(i) for i in input().split()]
if not first_way[0] or (not first_way[-1] and s == n):
	print('NO')
elif first_way[s - 1]:
	print('YES')
elif second_way[s - 1] and any([first_way[i] and second_way[i] for i in range(s, n)]):
	print('YES')
else:
	print('NO')


(stations, Alisa) = [int(x) for x in input().split()]
Alisa -= 1
forw = [int(x) for x in input().split()]
backw = [int(x) for x in input().split()]
if forw[0] == 0:
	print('NO')
	exit()
elif forw[Alisa] == 1:
	print('YES')
	exit()
elif backw[Alisa] == 0:
	print('NO')
	exit()
else:
	for i in range(Alisa, stations):
		if forw[i] * backw[i] == 1:
			print('YES')
			exit()
			break
print('NO')


def isone(a, b, s):
	for i in range(s, len(a)):
		if a[i] == 1 and b[i] == 1:
			return True
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
elif b[s - 1] == 1:
	if isone(a, b, s):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, s) = list(map(int, input().strip().split()))
ab = list(map(int, input().strip().split()))
bb = list(map(int, input().strip().split()))
s -= 1
if ab[0] == 0:
	print('NO')
elif ab[s] == 1:
	print('YES')
elif bb[s] == 1:
	for i in range(s + 1, n):
		if ab[i] == 1 and bb[i] == 1:
			print('YES')
			break
	else:
		print('NO')
else:
	print('NO')


import sys
inp0 = [int(x) for x in input().split()]
inp1 = [int(x) for x in input().split()]
inp2 = [int(x) for x in input().split()]
s = inp0[1] - 1
answer = 0
if inp1[0] == 0:
	if answer == 0:
		print('NO')
		answer = 1
if inp1[s] == 1:
	if answer == 0:
		print('YES')
		answer = 1
if inp2[s] == 0:
	if answer == 0:
		print('NO')
		answer = 1
for j in range(s, inp0[0]):
	if inp1[j] == 1 and inp2[j] == 1:
		if answer == 0:
			print('YES')
			answer = 1
			break
if answer == 0:
	print('NO')
	answer = 1


from collections import deque

def initialize(dist, graph, vertices):
	for i in range(vertices):
		dist[i] = -1
	for i in range(vertices):
		graph[i] = set()

def bfs(start, graph, dist):
	fila = deque()
	dist[start] = 0
	fila.append(start)
	while fila:
		v = fila.popleft()
		for w in graph[v]:
			if dist[w] == -1:
				dist[w] = dist[v] + 1
				fila.append(w)
(graph, dist) = (dict(), dict())
(vertices, final) = map(int, input().split())
initialize(dist, graph, vertices)
estacoes = list(map(int, input().split()))
for i in range(vertices):
	for j in range(i + 1, vertices):
		if estacoes[i] == 1 and estacoes[j] == 1:
			graph[i].add(j)
estacoes = list(map(int, input().split()))
for i in range(vertices - 1, -1, -1):
	for j in range(i - 1, -1, -1):
		if estacoes[i] == 1 and estacoes[j] == 1:
			graph[i].add(j)
bfs(0, graph, dist)
print('NO' if dist[final - 1] == -1 else 'YES')


(n, s) = map(int, input().split())
forward = list(map(int, input().split()))
backw = list(map(int, input().split()))
to = set()
back = set()
for i in range(len(forward)):
	if forward[i] == 1:
		to.add(i)
	if backw[i] == 1:
		back.add(i)

def ans():
	if 0 not in to:
		return False
	if s - 1 in to:
		return True
	elif s - 1 in back:
		for j in to.intersection(back):
			if j >= s - 1:
				return True
	return False
if ans():
	print('YES')
else:
	print('NO')


f = input().split(' ')
a = [int(x) for x in f]
n = a[0]
s = a[1]
k = 0
s2 = input().split(' ')
a2 = [int(x) for x in s2]
s3 = input().split(' ')
a3 = [int(x) for x in s3]
for i in range(s, n):
	if a2[i] == 1 and a3[i] == 1:
		k = 1
if a2[0] != 0 and a2[s - 1] == 0 and (k == 1) and (a3[s - 1] == 1) or (a2[0] != 0 and a2[s - 1] == 1):
	print('Yes')
else:
	print('NO')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
e = []
for j in range(a - 1, -1, -1):
	e.append(int(d[j]))
if c[0] == 1:
	if c[b - 1] == 1:
		print('YES')
	elif d[b - 1] == 1 and c[b - 1] == 0:
		k = 0
		for i in range(b, a):
			if d[i] == 1 and c[i] == 1:
				k = 1
		if k == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
else:
	print('NO')


(n, s) = tuple(map(int, input().split()))
m1 = list(map(int, input().split()))
m2 = list(map(int, input().split()))
s -= 1

def isok():
	if not m1[0]:
		return False
	if m1[s]:
		return True
	for i in range(s, n):
		if m1[i] and m2[i] and m2[s]:
			return True
	return False
print(('NO', 'YES')[isok()])


l1 = [int(x) for x in input().split()]
(n, s) = (l1[0], l1[1])
l2 = [int(x) for x in input().split()]
l3 = [int(x) for x in input().split()]
if l2[0] == 0 or (l3[s - 1] == 0 and l2[s - 1] == 0):
	print('NO')
elif l2[s - 1] == 1:
	print('YES')
elif l3[s - 1] == 1:
	done = 0
	for x in range(s - 1, n):
		if l3[x] == 1 and l2[x] == 1:
			done = 1
			break
	if done:
		print('YES')
	else:
		print('NO')


I = lambda : list(map(int, input().split()))
(n, s) = I()
(A, B) = (I(), I())
if A[0] and (A[s - 1] or (B[s - 1] and any((A[i] * B[i] for i in range(s, n))))):
	print('YES')
else:
	print('NO')


(n, s) = list(map(int, input().split(' ')))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
s -= 1

def check():
	for i in range(s + 1, n):
		if a[i] != 0 and a[i] == b[i]:
			return True
	return False
flag = True
if a[0] == 0:
	print('NO')
elif a[s] == 1:
	print('YES')
elif b[s] == 0:
	print('NO')
elif check():
	print('YES')
else:
	print('NO')


import math
import collections
import bisect
import heapq
import time
import itertools
import sys
(N, M) = list(map(int, input().split()))
A = [True if int(x) == 1 else False for x in input().split()]
B = [True if int(x) == 1 else False for x in input().split()]
if not A[M - 1] and (not B[M - 1]):
	print('NO')
elif not A[0]:
	print('NO')
elif A[M - 1]:
	print('YES')
else:
	if B[M - 1]:
		for i in range(M, N):
			if A[i] and B[i]:
				print('YES')
				return
	print('NO')


entrada = input().split()
s = int(entrada[1])
ida = input().split()
ida.insert(0, '-1')
volta = input().split()
volta.insert(0, '-1')
alcancavel = False
if ida[1] == '1':
	if ida[s] == '1':
		alcancavel = True
	elif volta[s] == '1':
		for i in range(s, len(ida)):
			if ida[i] == '1' and volta[i] == '1':
				alcancavel = True
if alcancavel:
	print('YES')
else:
	print('NO')


def readint():
	return int(input())

def readline():
	return [int(c) for c in input().split()]

def main():
	(n, s) = readline()
	a = readline()
	b = readline()
	if a[0] == 0:
		print('NO')
		return
	if a[s - 1] == 1:
		print('YES')
		return
	else:
		for i in range(s, n):
			if a[i] == 1 and b[i] == 1 and (b[s - 1] == 1):
				print('YES')
				return
	print('NO')
main()


import sys
(n, s) = map(int, sys.stdin.readline().split())
l1 = list(map(int, sys.stdin.readline().split()))
l2 = list(map(int, sys.stdin.readline().split()))
good = False
done = False
if l1[0] == 0 or (l1[s - 1] == 0 and l2[s - 1] == 0):
	print('NO')
	done = True
else:
	for i in range(n):
		if l1[i] == 1 and l2[i] == 1:
			if l1[0] == 1 and i >= s - 1 and (l2[s - 1] == 1):
				good = True
			if l2[0] == 1 and i <= s - 1 and (l1[s - 1] == 1):
				good = True
if good or (l1[s - 1] == 1 and l1[0] == 1):
	print('YES')
elif not good and (not done):
	print('NO')


def solve():
	(n, s) = map(int, input().split())
	track1 = [int(x) for x in input().split()]
	track2 = [int(x) for x in input().split()]
	if not track1[0]:
		print('NO')
		return
	if track1[s - 1]:
		print('YES')
		return
	hasReverseTravelStation = False
	for i in range(s + 1, n + 1):
		if track1[i - 1] and track2[i - 1]:
			hasReverseTravelStation = True
			break
	if not hasReverseTravelStation:
		print('NO')
		return
	if not track2[s - 1]:
		print('NO')
		return
	print('YES')
solve()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
elif a[m - 1] == 1:
	print('YES')
elif b[m - 1] == 0:
	print('NO')
else:
	for i in range(m, n):
		if a[i] == b[i] == 1:
			print('YES')
			exit()
	print('NO')


def read_int_arr():
	return list(map(int, input().split()))

def solve():
	(n, s) = read_int_arr()
	sa = read_int_arr()
	sb = read_int_arr()
	reach = set()
	s -= 1
	if sa[0] == 0:
		return 'NO'
	for (i, (a, b)) in enumerate(zip(sa, sb)):
		if b:
			reach.add(i)
		if a and i == s or (a and b and (s in reach)):
			return 'YES'
	return 'NO'
print(solve())


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s -= 1
f = 0
if a[0] == 1:
	for i in range(n):
		if a[i] == 1 and i == s:
			print('YES')
			f = 1
			break
		if i > s:
			if a[i] == 1 and b[i] == 1 and (b[s] == 1):
				print('YES')
				f = 1
				break
	if f == 0:
		if a[-1] == 1 and b[-1] == 1:
			for j in range(n - 2, 0, -1):
				if b[j] == 1 and j == s:
					print('YES')
					f = 1
					break
			if f == 0:
				print('NO')
		else:
			print('NO')
else:
	print('NO')


(n, s) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))

def task_A(n, s, a, b):
	if not a[0]:
		return 'NO'
	elif a[0] and a[s - 1]:
		return 'YES'
	elif not b[s - 1]:
		return 'NO'
	else:
		for i in range(s - 1, n):
			if a[i] == b[i] == 1:
				return 'YES'
				break
	return 'NO'
print(task_A(n, s, a, b))


k = list(map(int, input().split()))
chek = False
n = k[0]
s = k[1]
stations1 = list(map(int, input().split()))
stations2 = list(map(int, input().split()))
if stations1[0] == 0:
	print('NO')
elif stations1[s - 1] == 1:
	print('YES')
elif stations1[s - 1] == 0 and stations2[s - 1] == 0:
	print('NO')
else:
	for i in range(s, n):
		if stations1[i] == 1 and stations2[i] == 1:
			print('YES')
			chek = True
			break
	if chek == False:
		print('NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
max1 = 0
if a[0] == 0:
	print('NO')
else:
	for i in range(n):
		if a[i] == 1:
			max1 = i
		if max1 == s - 1:
			print('YES')
			exit()
	if max1 < s - 1:
		print('NO')
	else:
		for i in range(s - 1, max1 + 1):
			if a[i] == 1 and b[i] == 1 and (b[s - 1] == 1):
				print('YES')
				break
		else:
			print('NO')


(n, s) = list(map(int, input().split(' ')))
up = list(map(int, input().split(' ')))
down = list(map(int, input().split(' ')))
if up[0] == 0:
	print('NO')
elif up[s - 1] == 1:
	print('YES')
elif down[s - 1] == 0:
	print('NO')
else:
	cunt = 0
	for i in range(s + 1, n + 1):
		if up[i - 1] == 1 and up[i - 1] == down[i - 1]:
			print('YES')
			cunt = 1
			break
	if cunt != 1:
		print('NO')


x = input()
y = input()
z = input()
a = x.split()
b = y.split()
c = z.split()
if b[int(a[1]) - 1] == '1' and b[0] == '1':
	print('YES')
	exit(0)
elif b[int(a[1]) - 1] != '1' and b[0] == '1':
	for i in range(int(a[1]) - 1, int(a[0])):
		if b[i] == c[i] and b[i] == '1':
			if c[int(a[1]) - 1] == '1':
				print('YES')
				exit(0)
			else:
				print('NO')
				exit(0)
		else:
			pass
else:
	print('NO')
	exit(0)
print('NO')


import sys

def main():
	(n, s) = sys.stdin.readline().split()
	a = sys.stdin.readline().split()
	b = sys.stdin.readline().split()
	n = int(n)
	s = int(s) - 1
	a = [int(el) for el in a]
	b = [int(el) for el in b]
	if a[0] == 0:
		return 'NO'
	if a[s] == 1:
		return 'YES'
	p = None
	for i in range(s + 1, n):
		if a[i] == b[i] == 1:
			p = i
			break
	if not p:
		return 'NO'
	if b[s] == 1:
		return 'YES'
	return 'NO'
print(main())


def int_input():
	return map(int, input().split())

def possible(n, s, forward, reverse):
	forward = [0] + forward
	reverse = [0] + reverse
	if forward[1] == 0 or forward[s] == reverse[s] == 0:
		return False
	if forward[s] == 1:
		return True
	try:
		next((i for i in range(s + 1, n + 1) if forward[i] == reverse[i] == 1))
		return True
	except StopIteration:
		return False

def main():
	[n, s] = int_input()
	forward = list(int_input())
	reverse = list(int_input())
	print('YES' if possible(n, s, forward, reverse) else 'NO')
main()


def solve(a, b, s, n):
	if not a[0]:
		return 'NO'
	if a[s - 1]:
		return 'YES'
	if b[s - 1]:
		for i in range(s, n):
			if a[i] and b[i]:
				return 'YES'
	return 'NO'

def main():
	(n, s) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	print(solve(a, b, s, n))
main()


(end, alice) = map(int, input().split())
end = end - 1
alice = alice - 1
mark = 0
first = [int(n) for n in input().split()]
second = [int(n) for n in input().split()]
if first[0] == 0:
	print('NO')
	exit()
if first[alice] == 1:
	print('YES')
	exit()
for i in range(alice + 1, end + 1):
	if (first[i] == 1) & (second[i] == 1):
		mark = 1
if (first[alice] == 0) & (second[alice] == 1) & (mark == 1):
	print('YES')
	exit()
else:
	print('NO')
	exit()


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
r = list(map(int, input().split()))
ans = 0
if l[0] == 1:
	if l[s - 1] == 1:
		print('YES')
	else:
		for j in range(s, n):
			if l[j] == 1 and r[j] == 1:
				ans = 1
		if ans and r[s - 1] == 1:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
if a[0] and a[s - 1]:
	print('YES')
elif a[0] and 1 in a[s - 1:] and b[s - 1]:
	flag = 0
	for i in range(s - 1, len(a[s - 1:]) + s - 1):
		flag = 0
		if a[i] and b[i]:
			flag = 1
			break
	if flag:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
ans = 'NO'
if l1[0]:
	if l1[k - 1]:
		ans = 'YES'
	if l2[k - 1]:
		for i in range(k - 1, n):
			if l1[i] and l2[i]:
				ans = 'YES'
print(ans)


(n, s) = map(int, input().strip().split(' '))
l1 = list(map(int, input().strip().split(' ')))
l2 = list(map(int, input().strip().split(' ')))
c = l1.count(1)
q = 0
for i in range(1, n):
	if i >= s:
		if l1[i] == 1 and l2[i] == 1:
			q = 1
if l1[0] == 0:
	print('NO')
elif l1[s - 1] == 1:
	print('YES')
elif l2[s - 1] == 1 and q == 1:
	print('YES')
else:
	print('NO')


from bisect import bisect, bisect_left

def linp():
	return list(map(int, input().split(' ')))

def slinp():
	return sorted(linp())

def inp():
	return int(input())

def fnp():
	return float(input())

def dinp():
	s = linp()
	return (s[0], s[1])

def tinp():
	s = linp()
	return (s[0], s[1], s[2])

def main():
	(s, d) = dinp()
	d -= 1
	sa = linp()
	da = linp()
	hash = [0 for i in range(s)]
	if sa[0] == 0 or (da[d] == 0 and sa[d] == 0):
		print('NO')
		return
	for i in range(d, s):
		if da[i] == 0:
			continue
		hash[i] = 1
	for i in range(s):
		if sa[i] == 0:
			continue
		if hash[i] == 1 or i == d:
			print('YES')
			return
	print('NO')
t = 1
for i in range(t):
	main()


def metro():
	home = list(map(int, input().split()))
	metroA = list(map(int, input().split()))
	metroB = list(map(int, input().split()))
	if home[1] == 1:
		return 'YES'
	elif metroA[0] == 0:
		return 'NO'
	elif metroA[home[1] - 1] == 0 and metroB[home[1] - 1] == 0:
		return 'NO'
	i = home[1] - 1
	if metroA[i] == 1:
		return 'YES'
	i += 1
	while i != len(metroA):
		if metroA[i] == 1 and metroB[i] == 1:
			return 'YES'
		i += 1
	return 'NO'
A = metro()
print(A)


(n, k) = map(int, input().split())
ai = list(map(int, input().split()))
aj = list(map(int, input().split()))
c = 0
if ai[0] == 0 or ai[k - 1] == aj[k - 1] == 0:
	print('NO')
elif ai[k - 1] == 0:
	for i in range(k, n):
		if ai[i] == aj[i] == 1:
			c = c + 1
	if c > 0 and aj[k - 1] == 1:
		print('YES')
	else:
		print('NO')
else:
	print('YES')


(n, s) = input().split()
(n, s) = (int(n), int(s))
s -= 1
first = list(map(int, input().split()))
second = list(map(int, input().split()))
if first[0] == 0:
	print('NO')
elif first[s] == 1:
	print('YES')
elif second[s] == 0:
	print('NO')
else:
	per = -1
	for i in range(s + 1, n):
		if first[i] == 1 and second[i] == 1:
			per = i
			break
	if per == -1:
		print('NO')
	else:
		print('YES')


(n, s) = map(int, input().split())
l1 = input().split()
l2 = input().split()
l1 = [int(x) for x in l1]
l2 = [int(x) for x in l2]
r = ''
if l1[0] == 0:
	r = 'NO'
elif l1[s - 1] == 0 and l2[s - 1] == 0:
	r = 'NO'
elif l1[0] == 1 and l1[s - 1] == 1:
	r = 'YES'
elif l1[s - 1] == 0 and l2[s - 1] == 1:
	for i in range(s, n):
		if l1[i] == 1 and l2[i] == 1:
			r = 'YES'
			break
		else:
			r = 'NO'
print(r)


def main():
	(n, s) = map(int, input().split(' '))
	ip = [int(item) for item in input().split(' ')]
	ipReverse = [int(item) for item in input().split(' ')]
	if ip[0] == 0:
		ret(0)
	if s == 1 or ip[s - 1] == 1:
		ret(1)
	if ip[s - 1] == 0 and ipReverse[s - 1] == 0:
		ret(0)
	curr = s
	while curr < len(ip):
		if ip[curr] == 1 and ipReverse[curr] == 1:
			ret(1)
		curr += 1
	ret(0)

def ret(e):
	if e == 1:
		print('YES')
		exit()
	print('NO')
	exit()
main()


(stations, Alice) = [int(x) for x in input().split()]
Alice -= 1
flag = True
forward = [int(x) for x in input().split()]
backward = [int(x) for x in input().split()]
if forward[0] == 0:
	print('NO')
	flag = False
elif forward[Alice] == 1:
	print('YES')
	flag = False
elif backward[Alice] == 0:
	print('NO')
	flag = False
else:
	for i in range(Alice, stations):
		if forward[i] * backward[i] == 1:
			print('YES')
			flag = False
			break
if flag:
	print('NO')


def siOrNo(a, b):
	for i in range(s, n):
		if a[i] and b[i]:
			if b[s - 1]:
				return 'YES'
	return 'NO'

def num(x):
	return [int(x[i]) for i in range(len(x))]

def main():
	global n, s
	(n, s) = num(input().split())
	a = num(input().split())
	b = num(input().split())
	if not a[0]:
		print('NO')
	elif a[s - 1]:
		print('YES')
	else:
		print(siOrNo(a, b))
main()


a = input().split()
a = [int(i) for i in a]
line1 = input().split()
line2 = input().split()
if line1[0] == '0':
	print('NO')
elif line1[a[1] - 1] == '1':
	print('YES')
else:
	done = False
	if line2[a[1] - 1] == '1':
		for i in range(a[1], len(line1)):
			if line1[i] == '1' and line2[i] == '1':
				print('YES')
				done = True
				break
	if done == False:
		print('NO')


inp = input().split()
s = int(inp[0])
n = int(inp[1])
seq1 = input().split(' ')
seq2 = input().split(' ')
if seq1[0] == '0':
	print('NO')
elif seq1[n - 1] == '1':
	print('YES')
else:
	end = False
	for i in range(n, s):
		if seq1[i] == '1' and seq2[i] == '1':
			if seq2[n - 1] == '1':
				print('YES')
				end = True
				break
	if end == False:
		print('NO')


def solve(a, b, n, s):
	if a[0] == '0':
		return False
	if a[s - 1] == '1':
		return True
	if b[s - 1] == '0':
		return False
	for i in range(s, len(a)):
		if a[i] == b[i] == '1':
			return True
	return False

def test():
	n = 5
	s = 3
	a = '1 1 0 1 1'.split()
	b = '1 1 0 1 1'.split()
	assert solve(a, b, n, s) == False
	n = 3
	s = 4
	a = '1 1 1 0'.split()
	b = '1 1 1 1'.split()
	assert solve(a, b, n, s) == False
	n = 2
	s = 2
	a = '1 1'.split()
	b = '1 1'.split()
	assert solve(a, b, n, s) == True
	n = 4
	s = 2
	a = '1 0 1 1'.split()
	b = '1 1 1 1'.split()
	assert solve(a, b, n, s) == True
	print('tests passed!')
	exit(0)
(n, s) = map(int, input().split())
a = input().split()
b = input().split()
print('YES' if solve(a, b, n, s) else 'NO')


import math
(n, s) = map(int, input().strip().split(' '))
a = list(map(int, input().strip().split(' ')))
b = list(map(int, input().strip().split(' ')))
if a[0] == 0:
	print('NO')
elif a[s - 1] == 0 and b[s - 1] == 0:
	print('NO')
elif a[0] != 0 and a[s - 1] != 0:
	print('YES')
else:
	f = 0
	for j in range(s - 1, n):
		if a[j] == 1 and b[j] == 1:
			f = 1
	if f == 0:
		print('NO')
	elif b[s - 1] == 1:
		print('YES')
	else:
		print('NO')


def calc(n, s, a, b):
	if not a[0]:
		return False
	if a[s - 1]:
		return True
	if not b[s - 1]:
		return False
	for i in range(s, n):
		if a[i] and b[i]:
			return True
	return False

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]

def seq2str(seq):
	return ' '.join((str(item) for item in seq))
a = get_ints()
assert len(a) == 2
(n, s) = (a[0], a[1])
a = get_ints()
assert len(a) == n
b = get_ints()
assert len(b) == n
res = calc(n, s, a, b)
print('YES' if res else 'NO')


import sys
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
	sys.exit()
if a[s - 1] == 1 and a[0] == 1:
	print('YES')
	sys.exit()
if a[s - 1] == 0 and b[s - 1] == 0:
	print('NO')
	sys.exit()
if a[0] == 1 and a[s - 1] == 0 and (b[s - 1] == 1):
	for x in range(s, len(b)):
		if a[x] == b[x] == 1:
			print('YES')
			sys.exit()
	else:
		print('NO')


(n, s) = map(int, input().split())
first = list(map(int, input().split()))
second = list(map(int, input().split()))
l = zip(first[s:], second[s:])
if first[0] != 0 and (first[s - 1] == 1 or ((1, 1) in l and second[s - 1] == 1)):
	print('YES')
else:
	print('NO')


(n, m) = map(int, input().split())
(a, b) = (input().split(), input().split())
print('YES' if a[0] == '1' and (a[m - 1] == '1' or (b[m - 1] == '1' and any((i + j == '11' for (i, j) in zip(a[m:], b[m:]))))) else 'NO')


(n, s) = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
b = [int(s) for s in input().split()]
s = s - 1

def solve(n, s, a, b):
	if a[0] == 1:
		if a[s] == 1:
			return True
		elif b[s] == 0:
			return False
		else:
			for i in range(s, n):
				if a[i] == 1 and b[i] == 1:
					return True
	else:
		return False
	return False
if solve(n, s, a, b):
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
st = input().split()
nd = input().split()
used = []
sec = []
max_ = 0
for i in range(n):
	if nd[i] == '1':
		sec.append(i)
	if st[i] == '1':
		used.append(i)
	if st[i] == '1' and nd[i] == '1':
		max_ = i
used += [k for k in sec if 0 < k <= max_]
print(['NO', 'YES'][0 in used and s - 1 in used])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0 or (a[k - 1] == 0 and b[k - 1] == 0):
	print('NO')
	exit()
if a[k - 1] == 1:
	print('YES')
	exit()
ans = 'NO'
for i in range(k, n):
	if a[i] == b[i] == 1:
		ans = 'YES'
		break
print(ans)


def solve():
	(n, s) = list(map(int, input().split(' ')))
	s -= 1
	a = list(map(lambda x: bool(int(x)), input().split(' ')))
	b = list(map(lambda x: bool(int(x)), input().split(' ')))
	if not a[0]:
		print('NO')
		return
	elif a[s]:
		print('YES')
		return
	elif not b[s]:
		print('NO')
		return
	else:
		for i in range(s + 1, n):
			if a[i] and b[i]:
				print('YES')
				return
	print('NO')
solve()


from sys import stdin, stdout
import cProfile, math
from collections import Counter
from bisect import bisect_left, bisect, bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
printHeap = str()
memory_constrained = False
P = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10000000)

class Operation:

	def __init__(self, name, function, function_on_equal, neutral_value=0):
		self.name = name
		self.f = function
		self.f_on_equal = function_on_equal

def add_multiple(x, count):
	return x * count

def min_multiple(x, count):
	return x

def max_multiple(x, count):
	return x
sum_operation = Operation('sum', sum, add_multiple, 0)
min_operation = Operation('min', min, min_multiple, 1000000000.0)
max_operation = Operation('max', max, max_multiple, -1000000000.0)

class SegmentTree:

	def __init__(self, array, operations=[sum_operation, min_operation, max_operation]):
		self.array = array
		if type(operations) != list:
			raise TypeError('operations must be a list')
		self.operations = {}
		for op in operations:
			self.operations[op.name] = op
		self.root = SegmentTreeNode(0, len(array) - 1, self)

	def query(self, start, end, operation_name):
		if self.operations.get(operation_name) == None:
			raise Exception('This operation is not available')
		return self.root._query(start, end, self.operations[operation_name])

	def summary(self):
		return self.root.values

	def update(self, position, value):
		self.root._update(position, value)

	def update_range(self, start, end, value):
		self.root._update_range(start, end, value)

	def __repr__(self):
		return self.root.__repr__()

class SegmentTreeNode:

	def __init__(self, start, end, segment_tree):
		self.range = (start, end)
		self.parent_tree = segment_tree
		self.range_value = None
		self.values = {}
		self.left = None
		self.right = None
		if start == end:
			self._sync()
			return
		self.left = SegmentTreeNode(start, start + (end - start) // 2, segment_tree)
		self.right = SegmentTreeNode(start + (end - start) // 2 + 1, end, segment_tree)
		self._sync()

	def _query(self, start, end, operation):
		if end < self.range[0] or start > self.range[1]:
			return None
		if start <= self.range[0] and self.range[1] <= end:
			return self.values[operation.name]
		self._push()
		left_res = self.left._query(start, end, operation) if self.left else None
		right_res = self.right._query(start, end, operation) if self.right else None
		if left_res is None:
			return right_res
		if right_res is None:
			return left_res
		return operation.f([left_res, right_res])

	def _update(self, position, value):
		if position < self.range[0] or position > self.range[1]:
			return
		if position == self.range[0] and self.range[1] == position:
			self.parent_tree.array[position] = value
			self._sync()
			return
		self._push()
		self.left._update(position, value)
		self.right._update(position, value)
		self._sync()

	def _update_range(self, start, end, value):
		if end < self.range[0] or start > self.range[1]:
			return
		if start <= self.range[0] and self.range[1] <= end:
			self.range_value = value
			self._sync()
			return
		self._push()
		self.left._update_range(start, end, value)
		self.right._update_range(start, end, value)
		self._sync()

	def _sync(self):
		if self.range[0] == self.range[1]:
			for op in self.parent_tree.operations.values():
				current_value = self.parent_tree.array[self.range[0]]
				if self.range_value is not None:
					current_value = self.range_value
				self.values[op.name] = op.f([current_value])
		else:
			for op in self.parent_tree.operations.values():
				result = op.f([self.left.values[op.name], self.right.values[op.name]])
				if self.range_value is not None:
					bound_length = self.range[1] - self.range[0] + 1
					result = op.f_on_equal(self.range_value, bound_length)
				self.values[op.name] = result

	def _push(self):
		if self.range_value is None:
			return
		if self.left:
			self.left.range_value = self.range_value
			self.right.range_value = self.range_value
			self.left._sync()
			self.right._sync()
			self.range_value = None

	def __repr__(self):
		ans = '({}, {}): {}\n'.format(self.range[0], self.range[1], self.values)
		if self.left:
			ans += self.left.__repr__()
		if self.right:
			ans += self.right.__repr__()
		return ans

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def primeFactors(n):
	factors = dict()
	for i in range(2, math.ceil(math.sqrt(n)) + 1):
		while n % i == 0:
			if i in factors:
				factors[i] += 1
			else:
				factors[i] = 1
			n = n // i
	if n > 2:
		factors[n] = 1
	return factors

def isprime(n):
	if n < 4:
		return True
	if n % 2 == 0:
		return False
	if n % 3 == 0:
		return False
	i = 5
	w = 2
	while i * i <= n:
		if n % i == 0:
			return False
		i += w
		w = 6 - w
	return True

def test_print(*args):
	if test:
		print(args)

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result
TestCases = False
test = False

def main():
	(n, s) = get_tuple()
	ai = get_list()
	bi = get_list()
	if ai[0] != 1:
		print('NO')
		return
	if ai[s - 1] == 1:
		print('YES')
		return
	if bi[s - 1] != 1:
		print('NO')
	else:
		for i in range(s, n):
			if ai[i] == 1 and bi[i] == 1:
				print('YES')
				return
		print('NO')
if TestCases:
	for _ in range(get_int()):
		cProfile.run('main()') if test else main()
else:
	cProfile.run('main()') if test else main()


def main():
	buf = input()
	buflist = buf.split()
	n = int(buflist[0])
	s = int(buflist[1]) - 1
	buf = input()
	buflist = buf.split()
	a = list(map(int, buflist))
	buf = input()
	buflist = buf.split()
	b = list(map(int, buflist))
	start = 0
	if not a[0]:
		print('NO')
		return
	if not a[s] and (not b[s]):
		print('NO')
		return
	if a[s]:
		print('YES')
		return
	for i in range(s + 1, n):
		if a[i] and b[i]:
			print('YES')
			return
	print('NO')
	return
main()


(n, s) = [int(x) for x in input().split(' ')]
first_line = [int(x) for x in input().split(' ')]
second_line = [int(x) for x in input().split(' ')]
if first_line[0] == 0 or first_line[s - 1] + second_line[s - 1] == 0:
	print('NO')
elif first_line[0] == 1 and first_line[s - 1] == 1:
	print('YES')
else:
	yes = False
	for i in range(s - 1, n):
		if second_line[i] == first_line[i] == 1:
			print('YES')
			yes = True
			break
	if not yes:
		print('NO')


(n, s) = [int(x) for x in input().split()]
lf = [int(x) for x in input().split()]
lb = [int(x) for x in input().split()]
n -= 1
s -= 1
if lf[0] == 0:
	print('NO')
	exit(0)
if lf[s] == 1:
	print('YES')
	exit(0)
ra = False
for i in range(s + 1, n + 1):
	if lf[i] == 1 and lb[i] == 1:
		ra = True
		break
if lb[s] == 1 and ra:
	print('YES')
	exit(0)
print('NO')


(n, s) = map(int, input().split())
left = list(map(int, input().split()))
right = list(map(int, input().split()))
if left[0] == 0:
	print('NO')
elif left[s - 1] == 1:
	print('YES')
elif right[s - 1] == 1:
	for i in range(s, n):
		if left[i] == right[i] == 1:
			print('YES')
			break
	else:
		print('NO')
else:
	print('NO')


(n, s) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
import copy

def solution(n, s, a, b):
	answer = []
	if a[0] == 0:
		return 'NO'
	answer = copy.deepcopy(a)
	max_index = 0
	for i in range(len(a)):
		if a[i] == 1 and b[i] == 1:
			max_index = i
	for i in range(max_index):
		if b[i] == 1:
			answer[i] = 1
	return 'YES' if answer[s - 1] == 1 else 'NO'
print(solution(n, s, a, b))


(n, s) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

def able_to_commute(n, s, a, b):
	if a[0] == 0:
		return False
	if a[s - 1] == 1:
		return True
	if b[s - 1] == 0:
		return False
	for i in range(s, n):
		if a[i] + b[i] == 2:
			return True
	return False
if able_to_commute(n, s, a, b):
	print('YES')
else:
	print('NO')


(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, dgraphs, mod) = (lambda : sorted(zz()), {}, 10 ** 9 + 7)
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
(n, m) = zz()
l1 = zz()
l2 = zz()
if l1[0] == 0:
	print('NO')
	exit()
if l1[m - 1] == 1:
	print('YES')
	exit()
if l2[m - 1] == 0:
	print('NO')
	exit()
for i in range(m, n):
	if l1[i] == l2[i] == 1:
		print('YES')
		exit()
print('NO')


from collections import deque

def get_neighbors(node, direction, increasing, decreasing):
	res = []
	if direction == '+':
		for i in range(node + 1, len(increasing)):
			if increasing[i] == 1:
				res.append((i, '+'))
		if decreasing[node] == 1:
			res.append((node, '-'))
	if direction == '-':
		for i in range(node, -1, -1):
			if decreasing[i] == 1:
				res.append((i, '-'))
	return res

def solve(start, increasing, decreasing, target):
	if increasing[start] == 0:
		print('NO')
		return
	visited = {'+': set(), '-': set()}

	def _bfs(src):
		q = deque()
		q.append((src, '+'))
		visited['+'].add(src)
		while len(q):
			(pos, direction) = q.popleft()
			if pos == target - 1:
				print('YES')
				return
			neighbors = get_neighbors(pos, direction, increasing, decreasing)
			for (new_pos, new_direction) in neighbors:
				if new_pos not in visited[new_direction]:
					visited[new_direction].add(new_pos)
					q.append((new_pos, new_direction))
		print('NO')
		return
	_bfs(start - 1)
target = list(map(int, input().split(' ')))[1]
increasing = list(map(int, input().split(' ')))
decreasing = list(map(int, input().split(' ')))
solve(0, increasing, decreasing, target)


(n, s) = map(int, input().split())
x = input().split()
x1 = input().split()
men = 8
if x1[s - 1] == '1' and x[0] == '1':
	for i in range(s - 1, n):
		if x[i] == '1' == x1[i]:
			print('YES')
			men -= 1
			break
if men == 8:
	if x[0] == '0' or x[s - 1] == x1[s - 1] == '0' or (x[s - 1] == '0' and (x[n - 1] == '0' or x1[n - 1] == '0')):
		print('NO')
	else:
		print('YES')


(n, s) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
flag = True
if A[0] != 1:
	flag = False
ori = -1
for i in range(s - 1, n):
	if A[i] == 1 and B[i] == 1:
		ori = i
		break
if ori == -1:
	flag = False
elif B[s - 1] != 1:
	flag = False
if A[s - 1] == 1 and A[0] == 1:
	flag = True
if flag:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
a = input().split()
b = input().split()
e = 0
if b[s - 1] == '1' and a[0] == '1':
	for i in range(s - 1, n):
		if a[i] == '1' == b[i]:
			print('YES')
			e = 1
			break
if e == 0:
	if a[0] == '0' or a[s - 1] == b[s - 1] == '0' or (a[s - 1] == '0' and (a[n - 1] == '0' or b[n - 1] == '0')):
		print('NO')
	else:
		print('YES')


ns_list = list(map(int, input().split()))
if ns_list[0] >= 2 and ns_list[0] <= 1000:
	n = ns_list[0]
if ns_list[1] >= 2 and ns_list[1] <= n:
	s = ns_list[1]
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
sizeA = len(a_list)
sizeB = len(b_list)
if a_list[0] == 0:
	print('NO')
elif a_list[s - 1] == 1:
	print('YES')
else:
	flag = False
	for i in range(s, n):
		if a_list[i] == 1 and b_list[i] == 1:
			if b_list[s - 1] == 1:
				print('YES')
				flag = True
				break
	if not flag:
		print('NO')


(n, s) = map(int, input().split())
d = {}
for i in range(1, n + 1):
	d[i] = set()
up = list(map(int, input().split()))
down = list(map(int, input().split()))
for i in range(n):
	if up[i] == 1:
		for j in range(i + 1, n):
			if up[j] == 1:
				d[i + 1].add(j + 1)
for i in range(n - 1, 0, -1):
	if down[i] == 1:
		for j in range(i - 1, 0, -1):
			if down[j] == 1:
				d[i + 1].add(j + 1)
visited = [0] * (n + 1)
q = []
p = 0

def bfs(s):
	global visited, d, q, p
	q = []
	q.append(s)
	visited[s] = 1
	while q:
		p = q.pop(0)
		for i in d[p]:
			if visited[i] == 0:
				visited[i] = 1
				q.append(i)
bfs(1)
if visited[s] == 1:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
t1 = list(map(int, input().split()))
t2 = list(map(int, input().split()))
if t1[0] and t1[s - 1]:
	print('YES')
	exit(0)
if not (t1[0] and t2[s - 1]):
	print('NO')
	exit(0)
t = [_ for _ in range(n)]
for i in range(n):
	t[i] = t1[i] and t2[i]
ans = False
for i in range(s - 1, n):
	if t[i]:
		ans = True
		break
print('YES' if ans else 'NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
a.insert(0, 0)
b = list(map(int, input().split()))
b.insert(0, 0)

def porA(alice, pos, res):
	pos1 = pos
	while True:
		if pos + 1 < len(a):
			if a[pos + 1] == 1:
				pos1 = pos + 1
				if pos + 1 == alice:
					pos = pos1
					res = 'YES'
					break
				elif pos1 > alice and b[pos1] == 1:
					res = 'NO'
					pos = pos1
					break
		elif pos + 1 >= len(a):
			res = 'NO'
			pos = pos1
			break
		pos += 1
	return [pos, res]

def porB(alice, pos, res):
	if b[pos] == 0:
		return 'NO'
	while True:
		if pos - 1 >= 1:
			if b[pos - 1] == 1:
				if pos - 1 == alice:
					res = 'YES'
					break
		elif pos - 1 < 1:
			res = 'NO'
			break
		pos -= 1
	return res
if a[1] == 0:
	print('NO')
else:
	ret = porA(s, 1, '')
	if ret[1] == 'YES':
		print('YES')
	else:
		pos = ret[0]
		res = porB(s, pos, ret[1])
		print(res)


def main():
	(n, s) = map(int, input().strip().split())
	a = [int(x) for x in input().strip().split()]
	b = [int(x) for x in input().strip().split()]
	if a[0] == 0:
		print('NO')
		return
	if a[s - 1] == 1:
		print('YES')
		return
	if b[s - 1] == 0:
		print('NO')
		return
	for i in range(s, n):
		if a[i] == 1 and b[i] == 1:
			print('YES')
			return
	print('NO')
	return
main()


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

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

def btod(n):
	return int(n, 2)

def solution():
	(n, a) = Mint()
	l = List()
	r = List()
	p = 0
	if l[a - 1] == 0 and r[a - 1] == 1 and (l[0] == 1):
		for i in range(a, n):
			if l[i] == r[i] == 1:
				print('YES')
				break
		else:
			print('NO')
	elif l[0] == 1 and l[a - 1] == 1:
		print('YES')
	else:
		print('NO')
solution()


from collections import defaultdict

def read_line():
	return [int(x) for x in input().split()]
(n, s) = read_line()
s -= 1
up = read_line()
down = read_line()

def ok(up, down):
	Open_UP = [i for (i, up_ok) in enumerate(up) if up_ok]
	open_DOWN = [i for (i, down_ok) in enumerate(down) if down_ok]
	if s == 0:
		return True
	if not up[0]:
		return False
	if s in Open_UP:
		return True
	open_both = [x for x in range(n) if x in Open_UP and x in open_DOWN]
	if open_both:
		max_open_both = max(open_both)
		if s <= max_open_both and s in open_DOWN:
			return True
	return False
print('YES' if ok(up, down) else 'NO')


(estacao, metro) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))

def result(estacao, metro):
	for i in range(metro, estacao):
		if arr1[i] == 1 and arr2[i] == 1:
			return 'YES'
			exit()
	return 'NO'
if arr1[0] == 0:
	print('NO')
elif arr1[metro - 1] == 1:
	print('YES')
elif arr2[metro - 1] == 0:
	print('NO')
else:
	saida = result(estacao, metro)
	print(saida)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x) + '\n')
(n, k) = get_int_list()
lst1 = get_int_list()
lst2 = get_int_list()
if lst1[0] == 1:
	if lst1[k - 1] == 1:
		print('YES')
	elif lst2[k - 1] == 0:
		print('NO')
	else:
		flag = False
		for i in range(k, n):
			if lst1[i] == lst2[i] == 1:
				flag = True
				break
		if flag:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


(a, b) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if A[0] != 0 and (B[b - 1] == 0 and A[b - 1] == 1 or B[b - 1] == 1):
	x = False
	z = b - 1
	while x != True and z < a:
		if A[z] == 1:
			if B[z] == 1:
				x = True
			elif z == b - 1:
				x = True
		z += 1
	if x == True:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(s, n) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
flag = 0
if arr1[0] == 0:
	flag = 1
elif arr1[n - 1] == 0 and arr2[n - 1] == 0:
	flag = 1
elif arr1[n - 1] == 0:
	temp = 0
	for j in range(n, s):
		if arr1[j] == 1 and arr2[j] == 1:
			temp = 1
			break
	if temp == 0:
		flag = 1
if flag == 0:
	print('YES')
else:
	print('NO')


(n, s) = list(map(int, input().split()))
a = input()
b = input()
a = ''.join(a.split())
b = ''.join(b.split())
dd = 10 ** (n - s)
a1 = int(a) % dd
b1 = int(b) % dd
A = int(str(a1), 2)
B = int(str(b1), 2)
kk = int(bin(A & B)[2:])
if a[0] == '0':
	print('NO')
elif a[s - 1] == '1':
	print('YES')
elif b[s - 1] == '0':
	print('NO')
elif kk > 0:
	print('YES')
else:
	print('NO')


def dfs(u, dest):
	if u == dest:
		return True
	visited[u] = True
	if u in G.keys():
		for v in G[u]:
			if not visited[v] and dfs(v, dest):
				return True
	return False
(n, s) = map(int, input().split())
a = [int(x) for x in input().split()]
prev = -1
G = {}
for i in range(len(a)):
	if a[i] == 1:
		if prev == -1:
			prev = i
		else:
			if prev in G.keys():
				G[prev].append(i)
			else:
				G[prev] = [i]
			prev = i
b = [int(x) for x in input().split()]
prev = -1
for i in range(len(b) - 1, -1, -1):
	if b[i] == 1:
		if prev == -1:
			prev = i
		else:
			if prev in G.keys():
				G[prev].append(i)
			else:
				G[prev] = [i]
			prev = i
visited = [False] * n
if dfs(0, s - 1):
	print('YES')
else:
	print('NO')


(a, b) = map(int, input().split())
b -= 1
a -= 1
p1 = list(input().split())
p2 = list(input().split())
z = 0
for j in range(b + 1, a + 1):
	if p1[j] == '1' and p2[j] == '1':
		z += 1
if p1[0] == '0':
	print('NO')
elif p1[b] == '0' and p2[b] == '0':
	print('NO')
elif p1[b] == '0' and z > 0:
	print('YES')
elif p1[b] == '0' and p1[a] == '0' or (p1[b] == '0' and p2[a] == '0'):
	print('NO')
else:
	print('YES')


from collections import defaultdict
(n, s) = map(int, input().split())
a = input().split()
b = input().split()
G = defaultdict(list)
prev = -1
for (idx, el) in enumerate(a):
	if el == '1':
		if prev != -1:
			G[prev].append(idx)
		prev = idx
prev = -1
for (idx, el) in enumerate(b):
	if el == '1':
		if prev != -1:
			G[idx].append(prev)
		prev = idx

def bfs(v, G, used):
	used[v] = True
	for u in G[v]:
		if not used[u]:
			bfs(u, G, used)
used = [False] * n
bfs(0, G, used)
print('YES' if used[s - 1] else 'NO')


(n, s) = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
if arr1[0] == 0:
	print('NO')
elif arr1[s - 1] == 1:
	print('YES')
elif arr2[s - 1] == 1:
	for (idx, num) in enumerate(arr1):
		if idx < s - 1:
			continue
		if arr1[idx] == 1 and arr2[idx] == 1:
			print('YES')
			break
	else:
		print('NO')
else:
	print('NO')


s = input().split()
n = int(s[0])
k = int(s[1]) - 1
t1 = []
s = input().split()
for i in range(n):
	t1.append(int(s[i]))
t2 = []
s = input().split()
for i in range(n):
	t2.append(int(s[i]))

def solve():
	global t1, t2, n, k
	if t1[0] == 0:
		print('NO')
		return
	if t1[k] == 1:
		print('YES')
		return
	elif t2[k] == 0:
		print('NO')
		return
	else:
		for i in range(k + 1, n):
			if t1[i] == 1 and t2[i] == 1:
				print('YES')
				return
		print('NO')
		return
solve()


(n, s) = map(int, input().split())
mas = [[], []]
for i in range(2):
	mas[i] = list(map(int, input().split()))
if mas[0][0] == 1:
	answer = 1
	for i in range(n):
		if mas[0][i] == 1 and mas[1][i] == 1 and (s - 1 <= i) and (mas[1][s - 1] == 1) or (mas[0][i] == 1 and s == i + 1):
			answer = 0
			print('YES')
			break
	if answer == 1:
		print('NO')
else:
	print('No')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0 or a[s - 1] == b[s - 1] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
else:
	pa = a[s:n]
	pb = b[s:n]
	for i in range(0, len(pa)):
		if pa[i] == pb[i] == 1:
			print('YES')
			exit()
	print('NO')


inputt = lambda : map(int, input().split())
(N, s) = inputt()
s -= 1
right = list(inputt())
left = list(inputt())
for i in range(N):
	if i == 0 and right[i] == 0 or (i == s and left[i] == 0 and (right[i] == 0)):
		print('NO')
		break
	if i == s and right[i] == 1:
		print('YES')
		break
	if i > s and left[i] == 1 and (right[i] == 1):
		print('YES')
		break
else:
	print('NO')


x = input().split(' ')
y = input().split(' ')
z = input().split(' ')
a = False
if y[int(x[1]) - 1] == '1' and y[0] == '1':
	a = True
if y[0] == '1' and z[int(x[1]) - 1] == '1':
	for i in range(int(x[0]) - int(x[1])):
		if y[int(x[1]) + i] == z[int(x[1]) + i] and z[int(x[1]) + i] == '1':
			a = True
if a:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
ans = ai[0]
num4 = bi[s - 1]
for i in range(s - 1, n):
	bi[i] = min(bi[i], ai[i])
num = max(bi[s - 1:])
num3 = min(num4, num)
num2 = max(num3, ai[s - 1])
ans = min(ans, num2)
print('YES' * ans + 'NO' * (1 - ans))


import sys
input = sys.stdin.readline
(n, s) = map(int, input().split())
s -= 1
right = list(map(int, input().split()))
left = list(map(int, input().split()))
if right[0] == 0:
	print('NO')
elif right[s]:
	print('YES')
elif left[s]:
	for i in range(s, n):
		if right[i] and left[i]:
			print('Yes')
			sys.exit()
	print('NO')
else:
	print('NO')


cnt = lambda s, i: s.count(i)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
(n, m) = f()
l1 = il()
l2 = il()
fg = 0
for i in range(m, n):
	if l1[i] == l2[i] == 1:
		fg = 1
if l1[0] == 0:
	print('NO')
elif l1[m - 1] == 1:
	print('YES')
elif l2[m - 1] == 1 and fg == 1:
	print('YES')
else:
	print('NO')


def main():
	(n_stations, dest) = list(map(lambda x: int(x), input().strip().split()))
	dest -= 1
	dir1_open = list(map(lambda x: int(x), input().strip().split()))
	dir2_open = list(map(lambda x: int(x), input().strip().split()))
	if dir1_open[0] == 0:
		print('no')
	elif dir1_open[dest] == 1:
		print('yes')
	else:
		for n in range(dest + 1, n_stations):
			if dir1_open[n] == 1 and dir2_open[n] == 1 and (dir2_open[dest] == 1):
				print('yes')
				return
		print('no')
main()


x = input().split()
n = int(x[0])
s = int(x[1])
forward = input().split()
backward = input().split()
for i in range(0, n):
	forward[i] = int(forward[i])
	backward[i] = int(backward[i])
if forward[0] == 1:
	if forward[s - 1] == 1:
		print('YES')
	elif backward[s - 1] == 0:
		print('NO')
	else:
		for j in range(s, n):
			check = False
			if forward[j] == backward[j] and forward[j] == 1:
				print('YES')
				check = True
				break
		if check == False:
			print('NO')
else:
	print('NO')


(Sta, Des) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if A[0] == 0:
	print('NO')
elif A[Des - 1] == 1:
	print('YES')
elif B[Des - 1] == 0:
	print('NO')
else:
	f = False
	for i in range(Des, Sta):
		if A[i] == 1 and B[i] == 1:
			f = True
			break
	if f:
		print('YES')
	else:
		print('NO')


(n, q) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
t = False
if a[0] == 1 and a[q - 1] == 1:
	print('YES')
elif a[0] == 0:
	print('NO')
else:
	for x in range(q, n):
		if a[x] == 1 and b[x] == 1 and (b[q - 1] == 1):
			t = True
			break
	if t:
		print('YES')
	else:
		print('NO')


from sys import stdin
input = stdin.readline
(n, s) = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
back = False
possible = False
for i in range(s, n):
	if f[i] == 1 and b[i] == 1:
		back = True
if f[0] == 1:
	if f[s - 1] == 1:
		possible = True
	elif f[s - 1] == 0 and back and (b[s - 1] == 1):
		possible = True
print('YES' if possible == True else 'NO')


(n, s) = map(int, input().split())
s -= 1
a = list(map(int, input().split()))
b = list(map(int, input().split()))
flag = False
for i in range(s, n):
	if a[i] == b[i] == 1:
		flag = True
		break
if a[0] == 0 or (a[s] == 0 and flag == False) or a[s] == b[s] == 0:
	print('NO')
else:
	print('YES')


(n, s) = list(map(int, input().split()))
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
if arr1[0] == 0:
	print('NO')
	exit()
if arr1[s - 1] == 1:
	print('YES')
	exit()
if arr2[s - 1] == 1:
	for m in range(s, n):
		if arr1[m] == 1 and 1 == arr2[m]:
			print('YES')
			exit()
print('NO')


a = list(map(int, input().split()))
ida = list(map(int, input().split()))
volta = list(map(int, input().split()))
possivel = False
if ida[0] and ida[a[1] - 1]:
	possivel = True
else:
	for i in range(a[1], len(ida)):
		if ida[0] and ida[i] and volta[i] and volta[a[1] - 1]:
			possivel = True
			break
if possivel == True:
	print('YES')
else:
	print('NO')


def func(n, s, a, b):
	if a[0] == '0':
		return 0
	if a[s - 1] == '1':
		return 1
	if b[s - 1] == '0':
		return 0
	for i in range(s, n):
		if a[i] == b[i] == '1':
			return 1
	return 0
ns = input().split()
n = int(ns[0])
s = int(ns[1])
a = input().split()
b = input().split()
answer = func(n, s, a, b)
if answer == 1:
	print('YES')
else:
	print('NO')


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
(nb_tracks, dest) = read_ints()
dest -= 1
track_up = read_ints()
track_dn = read_ints()
ans = 'NO'
if not track_up[0]:
	ans = 'NO'
elif track_up[dest]:
	ans = 'YES'
elif any((track_up[i] and track_dn[i] and track_dn[dest] for i in range(dest, nb_tracks))):
	ans = 'YES'
print(ans)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
elif a[s - 1] != 0:
	print('YES')
elif b[s - 1] == 0:
	print('NO')
else:
	out = False
	for i in range(s, n):
		if a[i] + b[i] == 2:
			out = True
			break
	print('YES' if out else 'NO')


(n, s) = list(map(int, input().split()))
B = list(map(int, input().split()))
A = list(map(int, input().split()))
if B[0] == 1:
	if B[s - 1] == 1:
		print('YES')
	elif A[s - 1] == 0:
		print('NO')
	elif A[s - 1] == 1:
		p = B[s:]
		q = A[s:]
		r = len(p)
		flag = 0
		for i in range(r):
			if p[i] + q[i] == 2:
				flag = flag + 1
		if flag != 0:
			print('YES')
		else:
			print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()][::-1]
w = b[::-1]
x = 0
if a[s - 1] == 1 and a[0] == 1:
	x = 1
for i in range(s - 1, n):
	if a[i] == 1 and b[n - s] == 1 and (a[0] != 0) and (w[i] == 1):
		x = 1
		break
if x == 1:
	print('YES')
else:
	print('NO')


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
(n, s) = get_ints()
a = get_list()
b = get_list()
if a[0] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
else:
	ye = False
	i = s
	for i in range(s, n):
		if a[i] == 1 and b[i] == 1 and (b[s - 1] == 1):
			print('YES')
			ye = True
			break
	if not ye:
		print('NO')


(n, s) = map(int, input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if a[0] == 0:
	print('NO')
	exit(0)
if a[s - 1] == 1:
	print('YES')
	exit(0)
if b[s - 1] == 0:
	print('NO')
	exit(0)
if a[s - 1] == 0 and b[s - 1] == 0:
	print('NO')
	exit(0)
for j in range(s, n):
	if a[j] == b[j] and a[j] == 1:
		print('YES')
		exit(0)
print('NO')


s = input().split()
(N, B) = (int(s[0]), int(s[1]))
B = B - 1
lasts = [-1] * (N + 1)
nexts = [-1] * (N + 1)
s1 = input()
last = -1
for (i, open) in enumerate(s1.split()):
	open = int(open)
	if open == 1:
		if last != -1:
			lasts[last] = i
		last = i
next = -1
s2 = input()[::-1]
for (i, open) in enumerate(s2.split()):
	open = int(open)
	if open == 1:
		if next != -1:
			nexts[next] = N - 1 - i
		next = N - 1 - i
arrived = [-1] * N
queues = [0]

def add(x):
	if arrived[x] != -1 or x == -1:
		return
	queues.append(x)
while queues:
	v = queues.pop()
	arrived[v] = 1
	a = lasts[v]
	b = nexts[v]
	add(a)
	add(b)
	if a == B or b == B:
		print('YES')
		exit()
print('NO')


(n, s) = list(map(int, input().rstrip().split()))
from_zero = list(map(int, input().rstrip().split()))
from_n = list(map(int, input().rstrip().split()))
if from_zero[0] == 0:
	print('NO')
	exit()
if from_zero[0] == 1 and from_zero[s - 1] == 1:
	print('YES')
	exit()
else:
	go_station = []
	for i in range(s, n):
		if from_zero[i] == 1:
			go_station.append(i)
	can_reach = False
	for st in go_station:
		if from_n[st] == 1 and from_n[s - 1] == 1:
			can_reach = True
			break
	if can_reach:
		print('YES')
	else:
		print('NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 'NO'
if a[0] == 1:
	if a[s - 1] == 1:
		ans = 'YES'
	elif b[s - 1] == 1:
		for i in range(s, n):
			if a[i] + b[i] == 2:
				ans = 'YES'
				break
print(ans)


(n, s) = map(int, input().split())
s -= 1
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if A[0] and A[s]:
	print('YES')
elif A[0] and B[s]:
	for i in range(s, n):
		if A[i] and B[i]:
			print('YES')
			exit()
	print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
s = s - 1
t1 = list(map(int, input().split()))
t2 = list(map(int, input().split()))
if t1[0] == 1:
	if t1[s] == 1:
		print('YES')
	elif t2[s] == 1:
		count = 0
		for i in range(s, n):
			if t1[i] == 1 and t2[i] == 1:
				count += 1
		if count == 0:
			print('NO')
		else:
			print('YES')
	else:
		print('NO')
else:
	print('NO')


tmp = input().split(' ')
n = int(tmp[0])
s = int(tmp[1])
a = input().split(' ')
b = input().split(' ')
tmp = 0
if a[0] == '0':
	print('NO')
elif a[s - 1] == '1':
	print('YES')
elif b[s - 1] == '1':
	for i in range(s, n):
		if (a[i] == '1') & (b[i] == '1'):
			print('YES')
			tmp = 1
			break
	if not tmp:
		print('NO')
else:
	print('NO')


(n, s) = map(int, input().split(' '))
u = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))

def chk():
	global u, l
	k = 0
	for a in range(s - 1, n):
		if u[a] == 1 and l[a] == 1:
			k = 1
	return k
if u[0] == 1:
	if u[s - 1] == 1:
		print('YES')
	elif chk() == 1 and l[s - 1] == 1:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, s) = [int(x) for x in input().split()]
Increasing = [int(x) for x in input().split()]
Decreasing = [int(x) for x in input().split()]
flag = 0
if Increasing[0] == 0:
	print('NO')
elif Increasing[s - 1] == 0:
	Signal = 0
	for i in range(s, n):
		if Increasing[i] == Decreasing[i] == 1:
			Signal = 1
			break
	if Signal == 0:
		flag = 1
	elif Decreasing[s - 1] == 0:
		print('NO')
	else:
		print('YES')
else:
	print('YES')
if flag == 1:
	print('NO')


(n, s) = map(int, input().split())
way1 = input().split()
way2 = input().split()
result = 'YES'
if way1[s - 1] == '0' and way2[s - 1] == '0':
	result = 'NO'
if way1[0] == '0':
	result = 'NO'
elif way1[s - 1] == '0':
	count = 0
	for i in range(s, n):
		if way1[i] == '1' and way2[i] == '1':
			count = 1
	if count == 0:
		result = 'NO'
print(result)


(n, s) = map(int, input().split())
one = input().replace(' ', '')
two = input().replace(' ', '')

def exe(one, two, s):
	if one[0] == '0':
		return 0
	if one[s - 1] == '1':
		return 1
	if two[s - 1] == '0':
		return 0
	x = one[s:]
	y = two[s:]
	for i in range(len(x)):
		if x[i] == '1' and y[i] == '1':
			return 1
	return 0
print('YES' if exe(one, two, s) else 'NO')


def main():
	p = 0
	(n, s) = map(int, input().strip(' ').split(' '))
	a = list(map(int, input().strip(' ').split(' ')))
	b = list(map(int, input().strip(' ').split(' ')))
	if a[0] == 0:
		print('NO')
	elif a[s - 1] == 1:
		print('YES')
	else:
		for i in range(s, n):
			if a[i] == 1 and b[i] == 1:
				p = 1
				break
		if p == 0:
			print('NO')
		elif a[s - 1] == 0 and b[s - 1] == 0:
			print('NO')
		else:
			print('YES')
main()


SUCCESS = 'YES'
FAILURE = 'NO'

def cross_exist(dir1, dir2, size, target):
	for i in range(size):
		if dir1[i] == 1 and dir2[i] == 1 and (target < i):
			return True
	return False
n = 0
s = 0
(n, s) = map(int, input().split())
s -= 1
dir_left = list(map(int, input().split()))
dir_right = list(map(int, input().split()))
if s == 0:
	result = True
elif dir_left[0] == 0:
	result = False
elif dir_left[s] == 1:
	result = True
elif dir_left[s] == 0 and dir_right[s] == 0:
	result = False
elif dir_right[s] == 1 and cross_exist(dir_left, dir_right, n, s):
	result = True
else:
	result = False
answer = SUCCESS if result else FAILURE
print(answer)


from sys import stdin, stdout

def main():
	line = stdin.readline()
	line2 = stdin.readline()
	line3 = stdin.readline()
	parts = line.split()
	parts2 = line2.split()
	parts3 = line3.split()
	n = int(parts[0])
	s = int(parts[1])
	rta = False
	if int(parts2[0]) == 1:
		for i in range(1, n + 1):
			if i == s and int(parts2[s - 1]) == 1:
				rta = True
				break
			if i > s and int(parts2[i - 1]) == 1 and (int(parts3[i - 1]) == 1) and (int(parts3[s - 1]) == 1):
				rta = True
				break
	if rta == True:
		stdout.write('YES')
	else:
		stdout.write('NO')
main()


(N, C) = list(map(int, input().split()))
forw = input().split()
back = input().split()
C -= 1
canGo = True
if forw[0] != '1':
	canGo = False
elif forw[C] == '0' and back[C] == '0':
	canGo = False
elif forw[C] == '0' and back[C] == '1':
	canGo = False
	for j in range(C + 1, N):
		if forw[j] + back[j] == '11':
			canGo = True
			break
if canGo:
	print('YES')
else:
	print('NO')


(a, b) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
if l1[0] == 1 and l1[b - 1] == 1:
	print('YES')
elif l2[b - 1] == 1 and l1[0] == 1:
	ans = 'NO'
	for f in range(b - 1, a):
		if l1[f] == 1 and l2[f] == 1:
			ans = 'YES'
	print(ans)
else:
	print('NO')


(x, n) = map(int, input().split())
l = list(map(int, input().split()))
t = list(map(int, input().split()))
if l[0] == 0 and (l[n - 1] or t[n - 1]):
	print('NO')
	exit()
elif l[0] == 1 and l[n - 1] == 1:
	print('YES')
	exit()
elif t[n - 1] == 0:
	print('NO')
	exit()
else:
	for i in range(n, x):
		if l[i] == 1 and t[i] == 1:
			print('YES')
			exit()
print('NO')


(n, s) = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
K = 0
arr = [0]
if A[0]:
	K = 1
for i in range(1, n):
	if A[i] and B[i]:
		arr.append(i)
if max(arr) >= s and B[s - 1] and K or (A[0] and A[s - 1]):
	print('YES')
else:
	print('NO')


def metro(n, m, lst1, lst2):
	if lst1[0] != 1:
		return 'NO'
	if lst1[m - 1] == 1:
		return 'YES'
	if lst2[m - 1] == 1:
		for i in range(m, n):
			if lst1[i] == 1 and lst2[i] == 1:
				return 'YES'
	return 'NO'
(N, M) = [int(j) for j in input().split()]
a = [int(x) for x in input().split()]
b = [int(y) for y in input().split()]
print(metro(N, M, a, b))


(n, s) = map(int, input().split())
s -= 1
forward = list(map(int, input().split()))
back = list(map(int, input().split()))
ans = False
if forward[0]:
	if forward[s]:
		ans = True
	elif back[s]:
		for i in range(s + 1, n):
			if forward[i] and back[i]:
				ans = True
				break
if ans:
	print('YES')
else:
	print('NO')


def sol():
	(n, m) = map(int, input().split())
	x = []
	x.append([int(i) for i in input().split()])
	x.append([int(i) for i in input().split()])
	if x[0][0] ^ 1:
		return False
	if x[0][m - 1]:
		return True
	if x[1][m - 1] ^ 1:
		return False
	for i in range(m, n):
		if x[0][i] and x[1][i]:
			return True
	return False
print('YES' if sol() else 'NO')


(n, s) = map(int, input().split())
to = list(map(int, input().split()))
tt = list(map(int, input().split()))
if to[0] == 1 and to[s - 1] or (to[0] == 1 and tt[s - 1] == 1 and any([all(i) for i in list(zip(to[s - 1:n], tt[s - 1:n]))])):
	print('YES')
else:
	print('NO')


n = input()
n = n.split()
s = int(n[1])
n = int(n[0])
l1 = input()
l1 = l1.split()
l2 = input()
l2 = l2.split()
x = False
o = l1[s - 1] == '1' or l2[s - 1] == '1'
if l1[0] == '1' and o:
	if l1[s - 1] == '1':
		x = True
	else:
		for i in range(s - 1, n):
			if l2[i] == '1' and l1[i] == '1':
				x = True
if x == True:
	print('YES')
else:
	print('NO')


def ii():
	return int(input())

def mi():
	return list(map(int, input().split()))

def li():
	return list(mi())
(n, s) = mi()
a = li()
b = li()
s -= 1
ok = 1
if s == 0:
	ok = 1
elif a[0] == 0:
	ok = 0
elif a[s]:
	ok = 1
elif b[s] == 0:
	ok = 0
else:
	ok = any((a[i] == 1 and b[i] == 1 for i in range(s + 1, n)))
print('YES' if ok else 'NO')


(n, s) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
if a[0] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
elif b[s - 1] == 1:
	i = s
	while i < n:
		if a[i] == 1 and b[i] == 1:
			print('YES')
			break
		i += 1
	else:
		print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
flag = 'YES'
if a[0] != 1:
	flag = 'NO'
else:
	c = 0
	for i in range(s, n):
		if a[i] == 1 and b[i] == 1:
			c = 1
	if a[s - 1] != 1 and b[s - 1] != 1 and (c == 1):
		flag = 'NO'
	if c == 0 and a[s - 1] != 1:
		flag = 'NO'
print(flag)


(a, b) = map(int, input().split())
tr1 = list(map(int, input().split()))
tr2 = list(map(int, input().split()))
t = False
if tr1[0] == 1:
	t = True
	if tr1[b - 1] == 0:
		t = False
		if tr2[b - 1] == 1:
			for i in range(a - b):
				if tr1[i + b] == 1 and tr2[i + b] == 1:
					t = True
					break
if t == True:
	print('YES')
else:
	print('NO')


(n, s) = input().split()
n = int(n)
s = int(s)
a = input().split()
b = input().split()

def main():
	smth(a, b)

def smth(a, b):
	if a[0] == '0':
		print('NO')
		return
	elif b[s - 1] == '0' and a[s - 1] == '1':
		print('YES')
		return
	else:
		if b[s - 1] == '0':
			print('NO')
			return
		for i in range(s - 1, n):
			if a[i] == '1' and b[i] == '1':
				print('YES')
				return
		print('NO')
main()


(n, s) = map(int, input().split())
s -= 1
a = input().split()
b = input().split()
if a[0] == '1' and (a[s] == '1' or (b[s] == '1' and ('1', '1') in tuple(zip(a[s + 1:], b[s + 1:])))):
	print('YES')
else:
	print('NO')


ns = [int(i) for i in input().strip().split()]
n = ns[0]
s = ns[1]
ft = [int(i) for i in input().strip().split()]
st = [int(i) for i in input().strip().split()]
if ft[0] == 0:
	print('NO')
elif ft[s - 1] == 1:
	print('YES')
elif ft[s - 1] == 0 and st[s - 1] == 0:
	print('NO')
elif st[s - 1] == 1:
	x = []
	for i in range(s - 1, n):
		x.append(ft[i] + st[i])
	if 2 in x:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


x = list(map(int, input().split()))
n = x[0]
s = x[1] - 1
go = list(map(int, input().split()))
back = list(map(int, input().split()))
if go[0] == 0 or (go[s] == 0 and back[s] == 0):
	print('NO')
elif go[s] == 1:
	print('YES')
else:
	i = s + 1
	f = True
	while i < n:
		if go[i] == 1 and back[i] == 1:
			print('YES')
			f = False
			break
		i += 1
	if f:
		print('NO')


class Metro:

	def metro(self, first, second, s):
		if first[0] == 0:
			return 'NO'
		if first[s] == 1:
			return 'YES'
		if first[s] == 0 and second[s] == 0:
			return 'NO'
		if first[s] == 0 and second[s] == 1:
			for i in range(s + 1, len(first)):
				if first[i] == 1 and second[i] == 1:
					return 'YES'
		return 'NO'
m = Metro()
ns = list(map(int, input().split()))
first = list(map(int, input().split()))
second = list(map(int, input().split()))
print(m.metro(first, second, ns[1] - 1))


I = lambda : map(int, input().split())
(n, s) = I()
a = list(I())
b = list(I())
if a[0] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
elif b[s - 1] == 1:
	pn = True
	for i in range(s, n):
		if a[i] == 1 and b[i] == 1:
			print('YES')
			pn = False
			break
	if pn:
		print('NO')
else:
	print('NO')


(n, m) = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
ans = 'No'
if a[0]:
	if a[m - 1]:
		ans = 'Yes'
	elif b[m - 1]:
		for i in range(m, n):
			if a[i] == b[i] == 1:
				ans = 'Yes'
				break
print(ans)


(n, s) = map(int, input().split())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
if ai[0] == 0:
	print('NO')
elif ai[s - 1] == 1:
	print('YES')
elif bi[s - 1] == 1:
	for i in range(0, n - s):
		if bi[s + i] == 1 and ai[s + i] == 1:
			print('YES')
			exit(0)
	print('NO')
else:
	print('NO')


from typing import Dict, List, Tuple

def input_lst() -> List[int]:
	return [int(x) for x in input().split()]

def print_out(res: List[int]):
	print(' '.join([str(x) for x in res]))

def main():
	(m, s) = (int(x) for x in input().split())
	s -= 1
	a = input_lst()
	b = input_lst()
	res = True
	if a[0] == 0:
		print('NO')
		return
	if a[s] == 0 and b[s] == 0:
		print('NO')
		return
	if a[s] == 1:
		print('YES')
		return
	if res is True:
		for i in range(s, m):
			if a[i] != 0 and b[i] != 0:
				print('YES')
				return
	print('NO')
main()


(n, s) = list(map(int, input().split()))
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
b = 0
s = s - 1
if l1[0] == 0:
	print('NO')
elif l1[s] == 1:
	print('YES')
elif l1[s] * l2[s] == 1:
	print('YES')
elif l2[s] == 1:
	fl = False
	for i in range(s, n):
		if l1[i] * l2[i] == 1:
			fl = True
			break
	if fl:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(N, S) = [int(i) - 1 for i in input().split()]
Bob = [int(i) for i in input().split()]
Alice = [int(i) for i in input().split()]
answer = False
if Bob[0] == 0:
	print('NO')
	answer = True
elif Alice[S] == 0 and Bob[S] == 0:
	print('NO')
	answer = True
else:
	for (x, station) in enumerate(Bob):
		if station == 0:
			continue
		elif x == S and station == 1:
			print('YES')
			answer = True
			break
		elif S <= x and Alice[x] == 1:
			print('YES')
			answer = True
			break
if answer is False:
	print('NO')


def ans(a, b):
	if sum(a[:s]) == s:
		return 'YES'
	if a[0] == 0:
		return 'NO'
	if a[s - 1] == 1:
		return 'YES'
	elif a[s - 1] == 0 and b[s - 1] == 0:
		return 'NO'
	elif a[s - 1] == 0 and b[s - 1] == 1 or (a[s - 1] == 1 and b[s - 1] == 0):
		for i in range(s, n):
			if a[i] == 1 and b[i] == 1:
				return 'YES'
		return 'NO'
	return 'YES'
ns = list(map(int, input().strip().split()))
(n, s) = (ns[0], ns[1])
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
print(ans(a, b))


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
s -= 1

def solve():
	if solve_tf():
		print('YES')
	else:
		print('NO')

def solve_tf():
	if a[0] == 0:
		return False
	if a[s] == 1:
		return True
	if b[s] == 0:
		return False
	for (ac, bc) in zip(a[s:], b[s:]):
		if ac == 1 and bc == 1:
			return True
	else:
		return False
solve()


(n, s) = map(int, input().split())
ida = list(map(int, input().split()))
volta = list(map(int, input().split()))
if ida[0] == 0:
	print('NO')
elif ida[s - 1] == 1:
	print('YES')
else:
	achou = False
	for i in range(s - 1, len(ida)):
		if ida[i] == 1 and volta[i] == 1:
			achou = True
	if achou == True:
		if volta[s - 1] == 1:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if s == 1:
	print('YES')
elif a[0] == 0:
	print('NO')
elif a[s - 1] == 0 and b[s - 1] == 0:
	print('NO')
elif a[0] == 1 and a[s - 1] == 1:
	print('YES')
elif a[0] == 1 and a[s - 1] == 0:
	i = s
	while i < len(a):
		if a[i] == 1 and b[i] == 1:
			break
		i += 1
	if i == len(a):
		print('NO')
	else:
		j = i
		while j >= 0:
			if b[j] == 1:
				break
			j -= 1
		if j < 0:
			print('NO')
		elif b[j] == 1:
			print('YES')


s1 = input()
s2 = input()
s3 = input()
(n, s) = map(int, s1.split())
a = list(map(int, s2.split()))
b = list(map(int, s3.split()))
if a[0] != 1:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
elif b[s - 1] != 1:
	print('NO')
else:
	err = True
	for i in range(s, n):
		if b[i] == 1 and a[i] == 1:
			err = False
			break
	if err:
		print('NO')
	else:
		print('YES')


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
r = list(map(int, input().split()))
if l[0] == 0:
	print('NO')
	exit()
if l[s - 1] == 1:
	print('YES')
	exit()
if r[s - 1] == 0:
	print('NO')
	exit()
i = s
while i < n:
	if r[i] == 1 and l[i] == 1:
		print('YES')
		exit()
	i += 1
print('NO')


(n, s) = map(int, input().split())
arrup = list(map(int, input().split()))
arrdown = list(map(int, input().split()))
if arrup[0] == 0 and arrdown[0] == 0:
	print('NO')
	exit(0)
if arrup[s - 1] == 0 and arrdown[s - 1] == 0:
	print('NO')
	exit(0)
if arrup[0] == 0:
	print('NO')
	exit(0)
if arrup[s - 1] == 1:
	print('YES')
	exit(0)
for i in range(s - 1, n):
	if arrup[i] == 1 and arrdown[i] == 1:
		print('YES')
		exit(0)
print('NO')


def fun():
	(_, dest) = input().split()
	dest = int(dest)
	dest -= 1
	forward = list()
	back = list()
	forward = [int(i) for i in input().split()]
	back = [int(i) for i in input().split()]
	if forward[0] == 0:
		return 'NO'
	if forward[dest] == 0 and back[dest] == 0:
		return 'NO'
	if forward[0] == 1 and forward[dest] == 1:
		return 'YES'
	if forward[dest] == 0:
		count = []
		for (index, i) in enumerate(forward[dest:]):
			if i == 1:
				count.append(dest + index)
		if not len(count):
			return 'NO'
		else:
			possible = False
			for i in count:
				if back[i] == 1:
					possible = True
					break
			if not possible:
				return 'NO'
	return 'YES'
print(fun())


(n, s) = map(int, input().split(' '))
ino = input().split(' ')
vino = input().split(' ')
if ino[0] == '0':
	print('NO')
elif ino[s - 1] == '0' and vino[s - 1] == '0':
	print('NO')
elif ino[0] == '1' and ino[s - 1] == '1':
	print('YES')
elif ino[s - 1] == '0' and vino[s - 1] == '1':
	for i in range(s, n):
		if ino[i] == '1' and vino[i] == '1':
			print('YES')
			break
	else:
		print('NO')


import sys
(amount, number) = [int(s) for s in input().split()]
first_array = [int(s) for s in input().split()]
second_array = [int(s) for s in input().split()]
if first_array[0] == 0:
	print('NO')
	sys.exit(0)
elif first_array[0] == 1 and first_array[number - 1] == 1:
	print('YES')
	sys.exit(0)
else:
	for i in range(number, len(first_array)):
		if first_array[i] and second_array[i] and second_array[number - 1]:
			print('YES')
			sys.exit(0)
	print('NO')


def a():
	(n, s) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	new = []
	for i in range(n):
		new.append(a[i] & 1 and b[i] & 1)
	if a[0]:
		if a[s - 1]:
			print('YES')
		elif b[s - 1] and 1 in new[s - 1:]:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')
a()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 1:
	if a[m - 1] == 1:
		print('YES')
	elif b[m - 1] == 1:
		t = False
		for (i, j) in zip(a[m:], b[m:]):
			if i == j == 1:
				t = True
				print('YES')
				break
		if t == False:
			print('NO')
	else:
		print('NO')
elif m == 1:
	print('YES')
else:
	print('NO')


(n, s) = map(int, input().split())
way1 = [int(i) for i in input().split()]
way2 = [int(i) for i in input().split()]
if way1[0] == 0:
	print('NO')
else:
	if way1[s - 1] == 0 and way2[s - 1] == 0:
		print('NO')
	if way1[s - 1] == 1:
		print('YES')
	if way1[s - 1] == 0 and way2[s - 1] == 1:
		q = False
		for i in range(s, n):
			if way1[i] == 1 and way2[i] == 1:
				q = True
		if q == True:
			print('YES')
		else:
			print('NO')


def check_way():
	global graph, s
	used = set()
	dfs_for_way(1, used)
	if s in used:
		return True
	return False

def dfs_for_way(vertex, used):
	global s
	if s in used:
		return
	used.add(vertex)
	if vertex in graph:
		for neighbour in graph[vertex]:
			if neighbour not in used:
				used.add(neighbour)
				dfs_for_way(neighbour, used)
(n, s) = map(int, input().split())
first_way = [int(i) for i in input().split()]
second_way = [int(i) for i in input().split()]
if not first_way[0] or (not first_way[-1] and s == n):
	print('NO')
else:
	graph = {i: [] for i in range(1, n + 1)}
	for i in range(n):
		if first_way[i]:
			for j in range(1, i + 1):
				if first_way[j - 1]:
					graph[j].append(i + 1)
		if second_way[i]:
			for j in range(i + 2, n + 1):
				if second_way[j - 1]:
					graph[j].append(i + 1)
	print('YES' if check_way() else 'NO')


def main():
	(n, s) = map(int, input().split())
	a = tuple(map(int, input().split()))
	b = tuple(map(int, input().split()))
	edges = [[] for _ in range(n)]
	temp = []
	i = n
	while i:
		i -= 1
		if a[i]:
			edges[i] += temp
			temp.append(i)
	temp = []
	while n - i:
		if b[i]:
			edges[i] += temp
			temp.append(i)
		i += 1
	boo = [1] + [0] * n
	for i in range(n):
		temp = []
		for edge in edges[0]:
			if not boo[edge]:
				boo[edge] = 1
				edges[0] += edges[edge]
		edges[0] = list(set(edges[0]))
	if s - 1 in edges[0]:
		print('YES')
	else:
		print('NO')
	return 0
main()


from bisect import bisect_right as br
from bisect import bisect_left as bl
import sys
MAX = sys.maxsize
MAXN = 10 ** 6 + 10

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN():
	return map(int, sys.stdin.readline().strip().split())

def charIN():
	return sys.stdin.readline().strip().split()
(n, s) = numIN()
a = list(numIN())
b = list(numIN())
if not a[0] or (a[s - 1] == 0 and b[s - 1] == 0):
	print('NO')
	return
if a[s - 1]:
	print('YES')
	return
f = 0
for i in range(s, n):
	if a[i] and b[i]:
		f = 1
		break
if f:
	if b[s - 1]:
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, s) = list(map(int, input().split()))
n1 = list(map(int, input().split()))
n2 = list(map(int, input().split()))
a = [''] * n
for i in range(n):
	a[i] = n1[i] + n2[i]
if (a[0] and a[s - 1]) > 0 and n1[0] == 1:
	if a[s - 1] == 2 or n1[s - 1] == 1 or (n2[s - 1] == 1 and a[-1] == 2) or (max(a[s:]) == 2):
		print('YES')
	else:
		print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] != 1:
	print('no')
	exit()
if a[s - 1] == 1:
	print('yes')
	exit()
for i in range(s, n):
	if a[i] == b[i] == 1:
		break
else:
	print('no')
	exit()
if b[s - 1] == 1:
	print('yes')
else:
	print('no')


import sys
from collections import defaultdict
mod = 1000000007

def get_array():
	return list(map(int, sys.stdin.readline().split()))

def get_ints():
	return map(int, sys.stdin.readline().split())

def input():
	return sys.stdin.readline()

def print_array(a):
	print(' '.join(map(str, a)))

class Graph:

	def __init__(self):
		self.graph = defaultdict(list)

	def addEdge(self, u, v):
		self.graph[u].append(v)

	def traverse(self, n, fr, to):
		q = []
		visited = [False] * n
		visited[fr] = True
		q.append(self.graph[fr])
		while q:
			e = q.pop(0)
			if to in e:
				return True
			for x in e:
				if not visited[x]:
					visited[x] = True
					q.append(self.graph[x])
		return False

def main():
	(n, s) = get_ints()
	a = get_array()
	b = get_array()
	routes = Graph()
	for i in range(n - 1):
		if a[i] == 1:
			for j in range(i + 1, n):
				if a[j] == 1:
					routes.addEdge(i, j)
	for i in range(n - 1, 1, -1):
		if b[i] == 1:
			for j in range(i - 1, -1, -1):
				if b[j] == 1:
					routes.addEdge(i, j)
	print('YES' if routes.traverse(n, 0, s - 1) else 'NO')
main()


(n, s) = map(int, input().split())
line_forw = []
line_back = []
line_forw = input().split()
line_back = input().split()
cnt = 0
for i in range(n):
	line_forw[i] = int(line_forw[i])
	line_back[i] = int(line_back[i])
if line_forw[0] == 0 or line_forw[s - 1] + line_back[s - 1] == 0:
	print('NO')
elif line_forw[s - 1] == 1:
	print('YES')
else:
	for i in range(s - 1, n):
		if line_forw[i] == 1 and line_back[i] == 1:
			cnt = 1
	if cnt == 1:
		print('YES')
	else:
		print('NO')


(n, s) = map(int, input().split())
N1 = list(map(int, input().split()))
N2 = list(map(int, input().split()))
k = N1[s - 1]
if N1[0] == 1:
	if k == 1:
		print('Yes')
	elif N2[s - 1] == 1:
		for i in range(s, n):
			if N1[i] == 1 and N2[i] == 1:
				print('Yes')
				break
		else:
			print('No')
	else:
		print('No')
else:
	print('No')


answer = None
(n, s) = map(int, input().split())
toward = [bool(int(x)) for x in input().split()]
backward = [bool(int(x)) for x in input().split()]
if not toward[0]:
	answer = False
elif not toward[s - 1] and (not backward[s - 1]):
	answer = False
elif not toward[s - 1]:
	answer = False
	for i in range(s, n):
		if backward[i] and toward[i]:
			answer = True
else:
	answer = True
print('YES' if answer else 'NO')


def test_0():
	import math
	from collections import Counter
	(n, m) = list(map(int, input().split(' ')))
	data1 = list(map(int, input().split(' ')))
	data2 = list(map(int, input().split(' ')))
	if data1[0] == 0 or (data2[m - 1] == 0 and data1[m - 1] != 1):
		print('NO')
	elif data1[m - 1] == 1:
		print('YES')
	else:
		flag = 0
		for i in range(m - 1, n):
			if data1[i] == 1 and data2[i] == 1:
				flag = 1
		if flag:
			print('YES')
		else:
			print('NO')
test_0()


(n, s) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
s -= 1
f = False
for i in range(s, n):
	if a[i] == 1 and b[i] == 1:
		f = True
		break
if a[s] == 0 and b[s] == 0 or (a[s] == 0 and (not f)) or a[0] == 0:
	print('NO')
else:
	print('YES')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0 or sum(a) == 1:
	print('NO')
elif a[s - 1] or (any((x + y == 2 for (x, y) in zip(a[s:], b[s:]))) and b[s - 1]):
	print('YES')
else:
	print('NO')


import sys
(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
	sys.exit()
if a[s - 1] == 1:
	print('YES')
	sys.exit()
if b[s - 1] == 0:
	print('NO')
	sys.exit()
while s < n:
	if a[s] == 1 and b[s] == 1:
		print('YES')
		sys.exit()
	s += 1
print('NO')


def main():
	(n, s) = map(int, input().split())
	A = list(map(int, input().split()))
	B = list(map(int, input().split()))
	if A[0] and (A[s - 1] or (B[s - 1] and any([A[i] and B[i] for i in range(s, n)]))):
		return 'YES'
	else:
		return 'NO'
print(main())


(n, k) = map(int, input().split())
way1 = list(input().split())
way2 = list(input().split())
i = k - 1
if way1[0] != '0':
	ok = False
	while i < n:
		if way1[i] == '1' and i == k - 1 or (way1[i] == '1' and way2[i] == '1' and (way2[k - 1] == '1')):
			print('YES')
			ok = True
			break
		i += 1
	if not ok:
		print('NO')
else:
	print('NO')


a = list(map(int, input().split()))
n = a[0]
s = a[1]
tr1 = list(map(int, input().split()))
tr2 = list(map(int, input().split()))
if tr1[0] == 0:
	print('NO')
elif tr1[s - 1] == 1:
	print('YES')
elif tr2[s - 1] == 0:
	print('NO')
else:
	f = True
	for i in range(s, n):
		if tr1[i] == 1 and tr2[i] == 1:
			print('YES')
			f = False
			break
	if f:
		print('NO')


(a, b) = map(int, input().split())
listik1 = list(map(int, input().split()))
listik2 = list(map(int, input().split()))
if listik1[0] == 0:
	print('NO')
elif listik1[b - 1] == 0 and listik2[b - 1] == 0:
	print('NO')
elif listik1[b - 1] == 1:
	print('YES')
elif listik2[b - 1] == 1:
	for _ in range(b, a):
		if listik1[_] == 1 and listik2[_] == 1:
			print('YES')
			break
	else:
		print('NO')
else:
	print('NO')


def main():
	(n, s) = map(int, input().split())
	track_1 = [i == '1' for i in input().split()]
	track_2 = [i == '1' for i in input().split()]
	s -= 1
	if not track_1[0]:
		print('NO')
		return
	if track_1[s]:
		print('YES')
		return
	elif not track_2[s]:
		print('NO')
		return
	i = s + 1
	while i < n:
		if track_1[i] and track_2[i]:
			print('YES')
			return
		i += 1
	print('NO')
	return
main()


import sys
input = sys.stdin.readline
(n, s) = map(int, input().split())
fw = [0] + list(map(int, input().split()))
bw = [0] + list(map(int, input().split()))
if fw[1] == 0:
	print('NO')
elif fw[s] == 0 and bw[s] == 0:
	print('NO')
elif fw[s] == 1:
	print('YES')
else:
	valid = False
	for i in range(s + 1, len(fw)):
		if fw[i] and bw[i]:
			valid = True
	if valid:
		print('YES')
	else:
		print('NO')


i = input
(n, s) = map(int, i().split())
a = i().split()
b = i().split()
if a[0] == '0' or a[s - 1] + b[s - 1] == '00':
	print('NO')
elif a[0] + a[s - 1] == '11':
	print('YES')
else:
	for i in range(s, n):
		if a[i] == b[i] == '1':
			print('YES')
			exit()
	else:
		print('NO')


(a, b) = map(int, input().split())
c = list(map(int, input().split()))
d = list(map(int, input().split()))
if c[0] == 0:
	print('NO')
	exit()
if c[b - 1] == 1:
	print('YES')
	exit()
if d[b - 1] == 0:
	print('NO')
	exit()
for i in range(b, a):
	if c[i] == 1 and d[i] == 1:
		print('YES')
		exit()
print('NO')


(a, b) = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
if x[0] == 1 and x[b - 1] == 1:
	print('YES')
	exit()
elif x[0] == 1 and x[b - 1] == 0 and (y[b - 1] == 1):
	for j in range(b - 1, len(x)):
		if x[j] == 1 and y[j] == 1:
			print('YES')
			exit()
print('NO')


(n, alice) = [int(k) for k in input().split(' ')]
going = [int(k) for k in input().split(' ')]
coming = [int(k) for k in input().split(' ')]
mutual = False
alice -= 1
if going[0] == 0 or (going[alice] == 0 and coming[alice] == 0):
	print('NO')
elif going[0] == 1 and going[alice] == 1:
	print('YES')
else:
	bob_is_going = True
	i = alice
	while bob_is_going and i < len(going):
		if going[i] == 1 and coming[i] == 1:
			mutual = True
			bob_is_going = False
		else:
			i += 1
	if mutual and coming[alice] == 1:
		print('YES')
	else:
		print('NO')


[n, s] = [int(x) for x in input().strip().split(' ')]
a = [int(x) for x in input().split(' ')]
a = [0] + a
b = [int(x) for x in input().split(' ')]
b = [0] + b

def work():
	if a[1] == 0:
		return 'NO'
	if a[s] == 0 and b[s] == 0:
		return 'NO'
	if a[s] == 1:
		return 'YES'
	else:
		for j in range(s + 1, n + 1):
			if a[j] == b[j] and b[j] == 1:
				return 'YES'
	return 'NO'
print(work())


import sys
(n, s) = list(map(int, input().split()))
goR = list(map(int, input().split()))
goL = list(map(int, input().split()))
s = s - 1
if goR[0] == 0:
	print('NO')
	sys.exit()
if goR[s] == 0 and goL[s] == 0:
	print('NO')
	sys.exit()
if goR[s] == 1:
	print('YES')
	sys.exit()
for i in range(s + 1, n):
	if goR[i] == 1 and goL[i] == 1:
		print('YES')
		sys.exit()
print('NO')


import configparser
import sys
input = sys.stdin.readline

def ceil_div(x, y):
	return -(-x // y)

def main():
	(n, m) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	b = [int(x) for x in input().split(' ')]
	if a[0] == 0:
		if m != 1:
			print('NO')
		else:
			print('YES')
		return
	if a[m - 1] == 1:
		print('YES')
		return
	if b[m - 1] == 0:
		print('NO')
		return
	r = -12
	for i in range(n):
		if a[i] == 1 and b[i] == 1:
			r = i
	if r < 0:
		print('NO')
		return
	if m - 1 > r:
		print('NO')
		return
	print('YES')
main()


def main():
	(n, s) = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	if a[0] == 0 and s > 1 or (a[s - 1] == 0 and b[s - 1] == 0):
		return print('NO')
	if a[0] == 1 and a[s - 1] == 1:
		return print('YES')
	index_a = -1
	for i in range(n):
		if a[i] == 1:
			index_a = max(index_a, i + 1)
	if index_a < s:
		return print('NO')
	index_sum = -1
	for i in range(n):
		if a[i] == 1 and b[i] == 1:
			index_sum = max(index_sum, i + 1)
	if index_sum < s:
		return print('NO')
	if b[s - 1] == 0:
		return print('NO')
	return print('YES')
main()


(n, s) = [int(i) for i in input().split()]
a1 = [int(i) for i in input().split()]
a2 = [int(i) for i in input().split()]
s -= 1
if a1[0] == 1 and a1[s] == 1:
	print('YES')
	exit(0)
if a1[0] == 1 and (a1[s] == 1 or a2[s] == 1):
	for i in range(s, n):
		if a1[i] == 1 and a2[i] == 1:
			print('YES')
			exit(0)
	print('NO')
else:
	print('NO')


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
if a[0] == 0:
	print('NO')
elif a[s - 1] == 1:
	print('YES')
else:
	f = False
	i = s
	while i < n:
		if a[i] == 1 and b[i] == 1 and (b[s - 1] == 1):
			print('YES')
			f = True
			break
		i += 1
	if not f:
		print('NO')


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
if a[0] == 1:
	if a[k - 1] == 1:
		print('YES')
		exit()
	if b[k - 1] != 1:
		print('NO')
		exit()
	for i in range(k, n):
		if a[i] == 1 and b[i] == 1:
			print('YES')
			exit()
print('NO')


(n, k) = map(int, input().split())
ai = list(map(int, input().split()))
bi = list(map(int, input().split()))
res = 'NO'
if ai[0] == 1:
	if ai[k - 1] == 1:
		res = 'YES'
	elif [bi[k - 1] == 1]:
		for i in range(k, n):
			if ai[i] == 1 and bi[i] == 1 and (bi[k - 1] == 1):
				res = 'YES'
print(res)


(n, m) = map(int, input().split())
l1 = list(map(int, input().split()))
l2 = list(map(int, input().split()))
f = 0
if l1[0] == 0:
	print('NO')
elif l1[m - 1] == 1:
	print('YES')
elif l2[m - 1] == 0:
	print('NO')
else:
	for i in range(m - 1, n):
		f = 2
		if l1[i] == 1 and l2[i] == 1:
			print('YES')
			f = 1
			break
if f == 2:
	print('NO')


(n, s) = map(int, input().split())
way1 = list(map(int, input().split()))
way2 = list(map(int, input().split()))

def solve(n, s, way1, way2):
	if way1[0] == 0:
		return 'NO'
	elif way1[s - 1] == 1:
		return 'YES'
	else:
		for i in range(n):
			if i > s - 1 and way1[i] == 1 and (way2[i] == 1):
				if way2[s - 1] == 1:
					return 'YES'
	return 'NO'
print(solve(n, s, way1, way2))


I = lambda : map(int, input().split())
(n, s) = I()
a = (*I(),)
b = (*I(),)
print('NYOE S'[a[0] and (a[s - 1] or (b[s - 1] and any((x == 1 == y for (x, y) in zip(a[s:], b[s:])))))::2])


import sys
(n, s) = list(map(lambda x: int(x), sys.stdin.readline().split(' ')))
a = list(map(lambda x: int(x), sys.stdin.readline().strip().split(' ')))
b = list(map(lambda x: int(x), sys.stdin.readline().strip().split(' ')))
if a[0] == 1 and a[s - 1] == 1:
	print('YES')
elif a[0] == 1 and b[s - 1] == 1:
	i = s - 1
	while i < len(a) and (not (a[i] == 1 and b[i] == 1)):
		i += 1
	if i == len(a):
		print('NO')
	else:
		print('YES')
else:
	print('NO')