There is a robot staying at $X=0$ on the $Ox$ axis. He has to walk to $X=n$. You are controlling this robot and controlling how he goes. The robot has a battery and an accumulator with a solar panel.

The $i$-th segment of the path (from $X=i-1$ to $X=i$) can be exposed to sunlight or not. The array $s$ denotes which segments are exposed to sunlight: if segment $i$ is exposed, then $s_i = 1$, otherwise $s_i = 0$.

The robot has one battery of capacity $b$ and one accumulator of capacity $a$. For each segment, you should choose which type of energy storage robot will use to go to the next point (it can be either battery or accumulator). If the robot goes using the battery, the current charge of the battery is decreased by one (the robot can't use the battery if its charge is zero). And if the robot goes using the accumulator, the current charge of the accumulator is decreased by one (and the robot also can't use the accumulator if its charge is zero).

If the current segment is exposed to sunlight and the robot goes through it using the battery, the charge of the accumulator increases by one (of course, its charge can't become higher than it's maximum capacity).

If accumulator is used to pass some segment, its charge decreases by 1 no matter if the segment is exposed or not.

You understand that it is not always possible to walk to $X=n$. You want your robot to go as far as possible. Find the maximum number of segments of distance the robot can pass if you control him optimally.


-----Input-----

The first line of the input contains three integers $n, b, a$ ($1 \le n, b, a \le 2 \cdot 10^5$) — the robot's destination point, the battery capacity and the accumulator capacity, respectively.

The second line of the input contains $n$ integers $s_1, s_2, \dots, s_n$ ($0 \le s_i \le 1$), where $s_i$ is $1$ if the $i$-th segment of distance is exposed to sunlight, and $0$ otherwise.


-----Output-----

Print one integer — the maximum number of segments the robot can pass if you control him optimally.


-----Examples-----
Input
5 2 1
0 1 0 1 0

Output
5

Input
6 2 1
1 0 0 1 0 1

Output
3



-----Note-----

In the first example the robot can go through the first segment using the accumulator, and charge levels become $b=2$ and $a=0$. The second segment can be passed using the battery, and charge levels become $b=1$ and $a=1$. The third segment can be passed using the accumulator, and charge levels become $b=1$ and $a=0$. The fourth segment can be passed using the battery, and charge levels become $b=0$ and $a=1$. And the fifth segment can be passed using the accumulator.

In the second example the robot can go through the maximum number of segments using battery two times and accumulator one time in any order.

Difficulty: MEDIUM

Solutions:
(n, b, a) = (int(x) for x in input().strip().split(' '))
L = [int(x) for x in input().strip().split(' ')]
ans = 0
battery = b
acc = a
for x in L:
	if x == 1 and acc < a and (battery > 0):
		if battery == 0:
			break
		battery -= 1
		acc += 1
		ans += 1
	elif x == 1 and acc == a:
		acc -= 1
		ans += 1
	elif acc > 0:
		acc -= 1
		ans += 1
	elif battery > 0:
		battery -= 1
		ans += 1
	else:
		break
print(ans)


(n, b, a) = list(map(int, input().split()))
L = list(map(int, input().replace('0', '-1').split()))
csum = 0
A = []
b1 = b
c = 0
a1 = a
for n in L:
	c += 1
	if n == 1:
		if b1 > 0:
			if a1 == a:
				a1 -= 1
			else:
				a1 += 1
				b1 -= 1
		else:
			a1 -= 1
	elif a1 > 0:
		a1 -= 1
	else:
		b1 -= 1
	if b1 == 0 and a1 == 0:
		break
print(c)


from math import *
(n, b, a) = map(int, input().split())
ma = a
mb = b
l = list(map(int, input().split()))
for i in range(n):
	if l[i] == 1 and b != 0 and (a != ma):
		a = min(a + 1, ma)
		b -= 1
	elif l[i] == 1:
		a -= 1
	elif l[i] == 0 and a != 0:
		a -= 1
	else:
		b -= 1
	if a + b == 0:
		break
print(i + 1)


(n, b, a) = map(int, input().split())
arr = list(map(int, input().split()))
arr1 = [b]
val = b
for i in range(1, n):
	if arr[i] == 1:
		val -= 1
	arr1.append(val)
val = b
arr2 = [a - 1]
val2 = a - 1
ans = -1
for i in range(1, n):
	if arr[i] == 1:
		if val > 0:
			if val2 == a:
				val2 -= 1
			else:
				val -= 1
				val2 = min(val2 + 1, a)
		elif val2 == 0:
			ans = i
			break
		else:
			val2 -= 1
	elif val2 == 0:
		if val > 0:
			val -= 1
		else:
			ans = i
			break
	else:
		val2 -= 1
if ans == -1:
	print(n)
else:
	print(ans)


na = input().split()
n = int(na[0])
b = int(na[1])
c = int(na[2])
tc = c
tb = b
s = list(map(int, input().split()))
d = 0
i = 0
while b != 0 or c != 0:
	if s[i] == 1:
		if c == tc or (b == 0 and c != 0):
			c -= 1
		else:
			b -= 1
			c += 1
	elif c != 0:
		c -= 1
	else:
		b -= 1
	i += 1
	if i == n:
		break
print(i)


(n, tb, ta) = map(int, input().split())
s = list(map(int, input().split()))
(b, a) = (tb, ta)
s += [-1]
ans = -1
for i in range(n):
	if b == 0 and a == 0:
		ans = i
		break
	if s[i] == 0:
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif a == ta:
		a -= 1
	elif b > 0:
		b -= 1
		a = min(ta, a + 1)
	elif a > 0:
		a -= 1
if ans == -1:
	print(n)
else:
	print(ans)


(n, b, a) = tuple(map(int, input().split()))
ar = list(map(int, input().split()))
bat = b
acc = a
i = 0
while bat + acc > 0 and i < n:
	if ar[i] == 0:
		if acc > 0:
			acc -= 1
		else:
			bat -= 1
	elif acc >= a:
		acc -= 1
	elif bat > 0:
		bat -= 1
		acc += 1
	else:
		acc -= 1
	i += 1
print(i)


def main():
	(dest, battmax, accumax) = list(map(int, input().split()))
	batt = battmax
	accum = accumax
	light = list([bool(int(x)) for x in input().split()])
	path = 0
	for i in range(len(light)):
		if not batt and (not accum):
			break
		if accum == accumax:
			accum -= 1
			path += 1
		elif batt > 0 and light[i]:
			batt -= 1
			accum += 1
			path += 1
		elif accum > 0:
			accum -= 1
			path += 1
		else:
			batt -= 1
			path += 1
	print(path)

def __starting_point():
	main()
__starting_point()


(n, b, max_a) = [int(i) for i in input().split()]
light = [i for i in input().split()]
a = max_a
count = 0
for i in light:
	if a == max_a:
		a -= 1
	elif i == '0':
		if a > 0:
			a -= 1
		else:
			if b == 0:
				break
			b -= 1
	elif b > 0:
		a += 1
		b -= 1
	else:
		if a == 0:
			break
		a -= 1
	count += 1
print(count)


R = lambda : map(int, input().split())

def solve():
	(n, b, a) = R()
	xa = a
	sun = 0
	for i in [*R()]:
		if b == 0 and xa == 0:
			print(sun)
			exit()
		if i == 1 and b > 0 and (xa < a):
			b -= 1
			xa += 1
		elif xa:
			xa -= 1
		else:
			b -= 1
		sun += 1
	print(sun)
solve()


(n, b, a) = list(map(int, input().split()))
s = list(map(int, input().split()))
a_cpy = a
blocks = 0
for block in range(n):
	if a_cpy == a and a_cpy > 0:
		a_cpy -= 1
	elif s[block] != 1 and a_cpy > 0:
		a_cpy -= 1
	elif s[block] == 1 and a_cpy < a and (b > 0):
		b -= 1
		a_cpy += 1
	elif s[block] == 1 and a_cpy > 0 and (b == 0):
		a_cpy -= 1
	elif b > 0 and a_cpy == 0:
		b -= 1
	else:
		break
	blocks += 1
print(blocks)


(n, b, a) = map(int, input().split())
arr = list(map(int, input().split()))
(m, t) = (b, a)
c = 0
i = 0
while i < n:
	if arr[i] == 1:
		if m == 0 or t == a:
			t -= 1
			c += 1
		elif t == 0 or (t < a and m > 0):
			m -= 1
			t += 1
			c += 1
	elif arr[i] == 0:
		if t > 0:
			t -= 1
			c += 1
		elif t == 0:
			m -= 1
			c += 1
	if t == 0 and m == 0:
		break
	i += 1
print(c)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
ans = 0
maxa = a
for i in range(n):
	if a <= 0 and b <= 0:
		break
	ans += 1
	if s[i] == 1:
		if a < maxa and b > 0:
			b -= 1
			a += 1
			continue
		elif a > 0:
			a -= 1
		else:
			b -= 1
	if s[i] == 0 and a > 0:
		a -= 1
		continue
	if s[i] == 0 and a == 0:
		b -= 1
		continue
print(ans)


info = [int(x) for x in input().split()]
caminho = [int(x) for x in input().split()]
maxAcumulator = info[2]
contador = 0
for i in range(len(caminho)):
	if info[1] == 0 and info[2] == 0:
		print(i)
		quit()
	if caminho[i] == 1:
		if maxAcumulator == info[2]:
			info[2] -= 1
			continue
		elif info[1] != 0:
			info[2] += 1
			info[1] -= 1
			continue
		else:
			info[2] -= 1
			continue
	elif info[2] != 0:
		info[2] -= 1
		continue
	else:
		info[1] -= 1
else:
	print(i + 1)


(n, b, a) = list(map(int, input().split()))
line = list(map(int, input().split()))
(b1, a1) = (b, a)
dist = 0
for cell in line:
	if cell == 1:
		if a1 < a and b1 > 0:
			b1 -= 1
			a1 += 1
			dist += 1
		elif a1 > 0:
			a1 -= 1
			dist += 1
		else:
			break
	elif a1 > 0:
		a1 -= 1
		dist += 1
	elif b1 > 0:
		b1 -= 1
		dist += 1
	else:
		break
print(dist)


(n, a, b) = map(int, input().split())
mx = b
s = list(map(int, input().split()))
cnt = 0
for i in s:
	if i:
		if a and b < mx:
			a -= 1
			b += 1
		else:
			b -= 1
	elif b:
		b -= 1
	else:
		a -= 1
	cnt += 1
	if a + b == 0:
		break
print(cnt)


from math import sqrt, ceil, floor
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
import string
import bisect

def solve():
	(n, b, c) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	ans = 0
	cur_b = b
	cur_c = c
	for i in range(n):
		if cur_c == 0 and cur_b == 0:
			print(ans)
			return
		ans += 1
		if cur_b > 0 and cur_c < c and (a[i] == 1):
			cur_b -= 1
			cur_c += 1
		elif cur_c == 0:
			cur_b -= 1
			if a[i] == 1:
				cur_c = min(c, cur_c + 1)
		else:
			cur_c -= 1
	print(ans)
solve()


(n, b, a) = [int(num) for num in input().split(' ')]
path = [int(num) for num in input().split(' ')]
curA = a
step = 0
for val in path:
	if step == n:
		break
	if curA == a:
		step += 1
		curA -= 1
	elif val == 1 and curA < a and (b > 0):
		step += 1
		b -= 1
		curA += 1
	elif curA > 0:
		step += 1
		curA -= 1
	elif b > 0:
		step += 1
		b -= 1
	else:
		break
print(step)


(n, b, a) = map(int, input().strip().split())
exp = list(map(int, input().strip().split()))
acc = a
bat = b
res = 0
for i in exp:
	if i == 0:
		if acc != 0:
			acc -= 1
			res += 1
		elif bat != 0:
			bat -= 1
			res += 1
		else:
			break
	elif acc != a:
		if bat != 0:
			bat -= 1
			acc += 1
			res += 1
		elif acc != 0:
			acc -= 1
			res += 1
		else:
			break
	elif acc != 0:
		acc -= 1
		res += 1
	elif bat != 0:
		bat -= 1
		res += 1
	else:
		break
print(res)


R = lambda : map(int, input().split())
(n, b, a) = R()
s = tuple(R())
a0 = a
for i in range(n):
	if s[i]:
		if a == a0:
			a -= 1
		elif b:
			b -= 1
			a += 1
		elif a:
			a -= 1
		else:
			print(i)
			exit()
	elif a:
		a -= 1
	elif b:
		b -= 1
	else:
		print(i)
		exit()
print(n)


(n, b, a) = [int(x) for x in input().split()]
maxim = a
counter = 0
c = [int(x) for x in input().split()]
for item in c:
	if item == 0:
		if a != 0:
			a -= 1
		elif b != 0:
			b -= 1
		else:
			break
	elif a == maxim:
		a -= 1
	elif b != 0:
		b -= 1
		a += 1
	elif a != 0:
		a -= 1
	else:
		break
	counter += 1
print(counter)


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

def findMaxSeg(n, b, a, array):
	if n <= b + a:
		return n
	if b == 0:
		return a
	if a == 0:
		return b
	count = 0
	x = a
	y = b
	for i in array:
		if i == 0:
			if x > 0:
				x -= 1
			elif y > 0:
				y -= 1
			else:
				break
		elif i == 1:
			if x == a:
				x -= 1
			elif y > 0:
				y -= 1
				x += 1
				x = min(x, a)
			elif x > 0:
				x -= 1
			else:
				break
		count += 1
	return count
print(findMaxSeg(n, b, a, array))


(n, b, a) = list(map(int, input().split()))
s = list(map(int, input().split()))
y = b
z = a
x = 0
for i in range(n - 1):
	if s[i] == 1:
		if s[i + 1] == 1:
			if z == a:
				z -= 1
				x += 1
			elif z < a:
				if y > 0:
					y -= 1
					x += 1
					z += 1
				elif z > 0:
					z -= 1
					x += 1
				else:
					break
		elif s[i + 1] == 0:
			if z < a:
				if y > 0:
					y -= 1
					x += 1
					z += 1
				elif z > 0:
					z -= 1
					x += 1
				else:
					break
			elif z == a:
				z -= 1
				x += 1
	elif s[i] == 0:
		if z > 0:
			z -= 1
			x += 1
		elif y > 0:
			y -= 1
			x += 1
		else:
			break
if z > 0 or y > 0:
	x += 1
print(x)


(n, b, a) = map(int, input().split())
A = [int(i) for i in input().split()]
ans = 0
mx = a
for i in A:
	if b > 0:
		if i == 1 and a < mx:
			a += 1
			b -= 1
			ans += 1
		elif a > 0:
			a -= 1
			ans += 1
		else:
			b -= 1
			ans += 1
	elif a > 0:
		a -= 1
		ans += 1
	else:
		break
print(ans)


(n, b, a) = [int(item) for item in input().split()]
s = [int(item) for item in input().split()]
max_a = a
ans = 0
rem = [0] * n
rem[-1] = s[-1]
for i in range(n - 2, -1, -1):
	rem[i] = rem[i + 1] + s[i]
for (i, sun) in enumerate(s):
	if b == 0 and a == 0:
		break
	if b == 0:
		a -= 1
	elif a == 0:
		b -= 1
		if sun and a < max_a:
			a += 1
	elif a == max_a:
		a -= 1
	elif sun:
		a += 1
		b -= 1
	elif max_a - a < rem[i]:
		a -= 1
	else:
		b -= 1
	ans += 1
print(ans)


nba = input().split()
n = int(nba[0])
b = int(nba[1])
a = int(nba[2])
s = [int(i) for i in input().split()]
ans = 0
(bt, at) = (b, a)
for i in s:
	if a == 0 and b == 0:
		break
	ans += 1
	if i == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif a == at:
		a -= 1
	elif b > 0:
		b -= 1
		a = min(at, a + 1)
	elif a > 0:
		a -= 1
	else:
		break
print(ans)


(n, battery, accumulator) = list(map(int, input().split()))
s = list(map(int, input().split()))
b = battery
a = accumulator
ans = 0
for i in range(n):
	if a == 0 and b == 0:
		break
	elif s[i] == 0:
		if a > 0:
			a -= 1
			ans += 1
		else:
			b -= 1
			ans += 1
	elif a == accumulator:
		a -= 1
		ans += 1
	elif b > 0:
		b -= 1
		a += 1
		ans += 1
	else:
		a -= 1
		ans += 1
print(ans)


(n, b, a) = map(int, input().split())
sa = a
m = input().split()
for i in range(n):
	m[i] = int(m[i])
for i in range(n):
	if a == 0 and b == 0:
		print(i)
		exit(0)
	if m[i] == 1 and a != sa:
		if b > 0:
			a += 1
			b -= 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
else:
	print(n)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
ans = 0
bb = b
aa = a
for i in range(n):
	if b == 0 and a == 0:
		break
	if s[i] == 1:
		if b > 0 and a + 1 <= aa:
			ans = i
			a += 1
			b -= 1
		else:
			ans = i
			a -= 1
	else:
		if b == 0 and a == 0:
			break
		if a > 0:
			a -= 1
			ans = i
		else:
			b -= 1
			ans = i
print(ans + 1)


(n, b, a) = map(int, input().split())
lis = list(map(int, input().split()))
r = a
count = 0
for i in range(n):
	if lis[i] == 1:
		if a == r:
			a = a - 1
			count = count + 1
		elif b > 0:
			b = b - 1
			a = min(r, a + 1)
			count += 1
		elif a > 0:
			a = a - 1
			count = count + 1
		else:
			break
	elif a > 0:
		a = a - 1
		count = count + 1
	elif b > 0:
		b = b - 1
		count = count + 1
	else:
		break
print(count)


(n, b, a) = input().split()
(n, b, a) = (int(n), int(b), int(a))
a_max = a
s = [int(x) for x in input().split()]
p = 0
while p < len(s) and p != n:
	if b == 0 and a == 0:
		break
	if s[p] and a < a_max:
		if b > 0:
			b -= 1
			a += 1
		elif a > 0:
			a -= 1
	elif a > 0:
		a -= 1
	elif b > 0:
		b -= 1
	p += 1
print(p)


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n, b, a) = I()
l = I()
an = 0
cb = b
ca = a
for i in range(n):
	if ca == 0 and cb == 0:
		break
	if l[i]:
		if ca < a:
			if cb != 0:
				cb -= 1
				ca += 1
				an += 1
			else:
				ca -= 1
				an += 1
		else:
			ca -= 1
			an += 1
	elif ca != 0:
		ca -= 1
		an += 1
	else:
		cb -= 1
		an += 1
print(an)


(n, b, a) = map(int, input().split())
s = map(int, input().split())
cb = b
ca = a
c = 0
for x in s:
	if x == 1 and cb > 0 and (ca < a):
		c += 1
		ca += 1
		cb -= 1
	elif x == 0 and ca > 0:
		ca -= 1
		c += 1
	elif ca > 0:
		ca -= 1
		c += 1
	elif cb > 0:
		cb -= 1
		c += 1
	if ca == 0 and cb == 0:
		break
print(c)


import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
	(n, b, a) = map(int, input().split())
	a_max = a
	s = tuple(map(int, input().split()))
	r = 0
	while (b or a) and r < n:
		if b:
			if s[r] and a < a_max:
				b -= 1
				a += 1
			elif a:
				a -= 1
			else:
				b -= 1
		else:
			a -= 1
		r += 1
	print(r)
main()


(n, b, a) = map(int, input().split())
ar = list(map(int, input().split()))
(b1, a1) = (b, a)
s = 0
for i in ar:
	if a == 0 and b == 0:
		break
	s += 1
	if i == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif a == a1:
		a -= 1
	elif b > 0:
		b -= 1
		a = min(a1, a + 1)
	elif a > 0:
		a -= 1
	else:
		break
print(s)


(n, mb, ma) = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]
(a, b) = (ma, mb)
for i in range(n):
	if a + b == 0:
		print(i)
		return
	elif a != ma and b > 0 and (l[i] == 1):
		b -= 1
		a += 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
print(n)


import sys
(n, b, a) = map(int, input().split(' '))
ma = a
mb = b
suns = input('').split(' ')
ans = 0
for i in range(n):
	if b == 0 and a == 0:
		break
	if suns[i] == '0':
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif b > 0 and a < ma:
		b -= 1
		a += 1
	else:
		a -= 1
	ans += 1
print(ans)


s = [int(x) for x in input().split()]
n = s[0]
b = s[1]
a = s[2]
emka = a
s = [int(x) for x in input().split()]
ans = 0
while (a != 0 or b != 0) and ans != n:
	if s[ans] == 1:
		if b > 0 and a < emka:
			b -= 1
			a += 1
			ans += 1
		else:
			a -= 1
			ans += 1
	elif a > 0:
		a -= 1
		ans += 1
	else:
		b -= 1
		ans += 1
print(ans)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
(b1, a1) = (b, a)
k = 0
for c in s:
	if a1 == 0 and b1 == 0:
		break
	if c == 0:
		if a1 > 0:
			a1 -= 1
		elif b1 > 0:
			b1 -= 1
		else:
			break
	elif a1 != a:
		if b1 > 0:
			b1 -= 1
			a1 += 1
		elif a1 > 0:
			a1 -= 1
		else:
			break
	else:
		a1 -= 1
	k += 1
print(k)


(n, b, a) = [int(x) for x in str(input()).split(' ')]
s = [int(x) for x in str(input()).split(' ')]
counter = 0
amax = a
for i in s:
	if i == 1:
		if a == amax:
			a -= 1
		elif b > 0:
			b -= 1
			a += 1
		elif a > 0:
			a -= 1
		else:
			break
	elif a > 0:
		a -= 1
	elif b > 0:
		b -= 1
	else:
		break
	counter += 1
print(counter)


(n, b, a) = map(int, input().split())
bm = b
am = a
s = list(map(int, input().split()))
nb = 0
for i in s:
	if i == 0:
		if a > 0:
			a = a - 1
			nb = nb + 1
		elif b > 0:
			b = b - 1
			nb = nb + 1
		else:
			break
	elif a == am:
		a = a - 1
		nb = nb + 1
	elif b > 0:
		b = b - 1
		a = a + 1
		nb = nb + 1
	elif a > 0:
		a = a - 1
		nb = nb + 1
	else:
		break
print(nb)


(n, b, a) = map(int, input().split())
s = input().split()
ma = a
for (i, c) in enumerate(s):
	if b + a == 0:
		break
	if c == '0':
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif a == ma or b == 0:
		a -= 1
	else:
		b -= 1
		a += 1
else:
	i += 1
print(i)


(n, b, a) = (int(i) for i in input().split())
a_max = a
cnt = 0
for i in input().split():
	i = int(i)
	if i:
		if b:
			if a < a_max:
				b -= 1
				a += 1
				cnt += 1
			elif a:
				a -= 1
				cnt += 1
			else:
				b -= 1
				cnt += 1
		elif a:
			a -= 1
			cnt += 1
		else:
			break
	elif a:
		a -= 1
		cnt += 1
	elif b:
		b -= 1
		cnt += 1
	else:
		break
print(cnt)


(n, b, a) = map(int, input().split())
segment = list(map(int, input().split()))
aa = a
bb = b
i = 0
while i < n:
	if segment[i] == 0:
		if aa > 0:
			aa -= 1
		elif bb > 0:
			bb -= 1
		else:
			break
	elif bb > 0 and aa != a:
		bb -= 1
		aa += 1
	elif aa > 0:
		aa -= 1
	elif bb > 0:
		bb -= 1
	else:
		break
	i += 1
print(i)


import sys
import math
(n, b, a) = list(map(int, sys.stdin.readline().strip().split()))
s = list(map(int, sys.stdin.readline().strip().split()))
A = a
B = b
i = 0
while i < n:
	if s[i] == 1 and b > 0 and (a < A):
		b = b - 1
		a = a + 1
	elif s[i] == 1 and (b == 0 and a > 0):
		a = a - 1
	elif s[i] == 1 and a == A:
		a = a - 1
	elif s[i] == 0 and a > 0:
		a = a - 1
	elif s[i] == 0 and b > 0:
		b = b - 1
	else:
		print(i)
		i = n
	if i == n - 1:
		print(i + 1)
	i = i + 1


(n, b, ac) = map(int, input().split())
a = list(map(int, input().split()))
k = 0
x = ac
for i in range(len(a)):
	if a[i] == 1 and b > 0 and (x > 0):
		if x < ac:
			b -= 1
			x += 1
		else:
			x -= 1
		k += 1
	elif a[i] == 0 and b > 0 and (x > 0):
		x -= 1
		k += 1
	elif a[i] == 1 and b == 0 and (x > 0):
		x -= 1
		k += 1
	elif a[i] == 1 and b > 0 and (x == 0):
		b -= 1
		x += 1
		k += 1
	elif a[i] == 0 and b == 0 and (x > 0):
		x -= 1
		k += 1
	elif a[i] == 0 and b > 0 and (x == 0):
		b -= 1
		k += 1
	else:
		break
print(k)


(n, b, a) = list(map(int, input().split()))
arr = list(map(int, input().split()))
acc = a
steps = 0
for i in arr:
	if a == 0 and b == 0:
		break
	if i == 1:
		if b > 0:
			if a == acc:
				a -= 1
				steps += 1
			else:
				b -= 1
				a += 1
				steps += 1
				if a > acc:
					a -= 1
		else:
			steps += 1
			a -= 1
	if i == 0:
		if a > 0:
			a -= 1
			steps += 1
			continue
		elif b > 0:
			b -= 1
			steps += 1
print(steps)


(n, b, a) = list(map(int, input().strip().split()))
s = list(map(int, input().strip().split()))
max_a = a
for i in range(len(s)):
	if a == 0 and b == 0:
		print(i)
		break
	if s[i] == 1:
		if a == max_a:
			a -= 1
		elif a < max_a and b > 0:
			a += 1
			b -= 1
		elif b == 0 and a > 0:
			a -= 1
	elif a > 0:
		a -= 1
	elif b > 0:
		b -= 1
else:
	print(n)


(N, b, a) = map(int, input().split())
C = a
A = list(map(int, input().split()))
ind = 0
while ind < N:
	if A[ind] == 0:
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif a == C:
		a -= 1
	elif b > 0:
		b -= 1
		a += 1
	else:
		a -= 1
	ind += 1
	if a == 0 and b == 0:
		break
print(ind)


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 read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	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.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import Counter
import heapq
import heapq
(n, b, a) = map(int, input().split())
var1 = a
var2 = b
arr = list(map(int, input().split()))
d = 0
for i in range(n):
	if arr[i] == 0:
		if a > 0:
			a -= 1
			d += 1
		elif b > 0:
			b -= 1
			d += 1
	elif a < var1:
		if b > 0:
			b -= 1
			a += 1
			d += 1
		elif a >= 1:
			a -= 1
			d += 1
		else:
			break
	elif a > 0:
		a -= 1
		d += 1
	elif b > 0:
		b -= 1
		a += 1
		d += 1
	else:
		break
print(d)


from collections import Counter
(n, bb, aa) = map(int, input().split())
s = list(map(int, input().split()))
x = 0
a = aa
b = bb
for i in range(n):
	if s[i] == 1 and b > 0 and (a < aa):
		b -= 1
		a += 1
		x += 1
	elif s[i] == 1 and b > 0 and (a == aa):
		a -= 1
		x += 1
	elif a > 0:
		a -= 1
		x += 1
	elif b > 0:
		b -= 1
		x += 1
	else:
		break
print(x)


(n, b, a) = tuple(map(int, input().split()))
m = list(map(int, input().split()))
max_a = a
i = 0
while (b != 0 or a != 0) and i <= n - 1:
	if m[i] == 0:
		if a != 0:
			a -= 1
		else:
			b -= 1
	elif b != 0:
		if a == max_a:
			a -= 1
		else:
			b -= 1
			a = min(a + 1, max_a)
	else:
		a -= 1
	i += 1
print(i)


(n, b, a) = map(int, input().split())
max_a = a
ex = list(map(int, input().split()))
right = 0
left = 0
pos = 0
while pos < n:
	if not b and (not a):
		break
	right += 1
	if ex[pos]:
		if b:
			if a == max_a:
				a -= 1
			else:
				b -= 1
				a += 1
		else:
			a -= 1
	elif a:
		a -= 1
	else:
		b -= 1
	pos += 1
print(right)


(n, b, a) = map(int, input().split())
fa = a
l = list(map(int, input().split()))
mx = 0
for i in l:
	if i == 0 and fa > 0:
		fa -= 1
		mx += 1
	elif i == 0 and fa == 0:
		b -= 1
		mx += 1
	elif i == 1 and fa == a:
		fa -= 1
		mx += 1
	elif i == 1 and b > 0:
		mx += 1
		if fa + 1 > a:
			b -= 1
		else:
			b -= 1
			fa += 1
	elif i == 1 and b == 0:
		fa -= 1
		mx += 1
	if fa == 0 and b == 0:
		break
print(mx)


(n, b, a) = (int(x) for x in input().split())
s = [int(x) for x in input().split()]
charge = a
for (ans, t) in enumerate(s):
	if t:
		if charge < a and b:
			b -= 1
			charge += 1
		elif charge:
			charge -= 1
		elif b:
			b -= 1
		else:
			print(ans)
			raise SystemExit(0)
	elif charge:
		charge -= 1
	elif b:
		b -= 1
	else:
		print(ans)
		raise SystemExit(0)
print(ans + 1)


(n, b, a_max) = map(int, input().split())
s = list(map(int, input().split()))
a = a_max
for i in range(len(s)):
	if a == 0 and b == 0:
		i -= 1
		break
	if a == a_max:
		a -= 1
		continue
	if s[i] and b:
		b -= 1
		a += 1
		continue
	if not s[i] and a:
		a -= 1
		continue
	if b:
		b -= 1
		continue
	if a:
		a -= 1
		continue
	break
print(i + 1)


def robot(n, b, a, path):
	acc = a
	count = 0
	for i in path:
		if i == 1:
			if a == acc:
				a -= 1
			elif b > 0:
				b -= 1
				a += 1
			elif a > 0:
				a -= 1
			else:
				break
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
		count += 1
	return count
(n, b, a) = map(int, input().split())
path = [int(i) for i in input().split()]
print(robot(n, b, a, path))


def main():
	(n, b, a) = map(int, input().split())
	(cb, ca) = (b, a)
	p = 0
	for s in input().split():
		if ca == 0 and cb == 0:
			break
		if int(s):
			if ca < a and cb > 0:
				ca += 1
				cb -= 1
			else:
				ca -= 1
		elif ca > 0:
			ca -= 1
		else:
			cb -= 1
		p += 1
	print(p)
main()


(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
acap = a
bcap = b
cou = 0
for i in l:
	if a == 0 and b == 0:
		break
	cou += 1
	if i == 0:
		if a != 0:
			a -= 1
		elif b != 0:
			b -= 1
	elif b != 0 and a != acap:
		b -= 1
		a += 1
	elif b != 0 and a == acap:
		a -= 1
	elif b == 0 and a != 0:
		a -= 1
print(cou)


ln = [int(i) for i in input().split(' ')]
n = ln[0]
b = ln[1]
a = ln[2]
oa = a
ln = [int(i) for i in input().split(' ')]
t = 0
for i in range(0, len(ln)):
	if ln[i] == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif a >= oa:
		a -= 1
	elif b > 0:
		b -= 1
		a += 1
	elif a > 0:
		a -= 1
	else:
		break
	t += 1
print(t)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
i = 0
battery = b
accumulator = a
while i < n and (battery > 0 or accumulator > 0):
	if s[i] == 1 and accumulator == a:
		accumulator -= 1
	elif s[i] == 1 and battery > 0:
		battery -= 1
		accumulator += 1
	elif s[i] == 1:
		accumulator -= 1
	elif s[i] == 0 and accumulator > 0:
		accumulator -= 1
	else:
		battery -= 1
	i += 1
print(i)


(n, b, a) = (int(i) for i in input().split())
aa = a
L = [int(i) for i in input().split()]
s = 0
for i in L:
	if not i:
		if a:
			a -= 1
		elif b:
			b -= 1
		else:
			break
		s += 1
	else:
		if b and a < aa:
			b -= 1
			a += 1
		elif a:
			a -= 1
		else:
			break
		s += 1
print(s)


import sys
sys_input = sys.stdin.readline

def si():
	return sys_input().rstrip()

def ii():
	return int(si())

def sti():
	return si().split()

def iti():
	return map(int, sti())

def sli():
	return list(si())

def ili():
	return list(iti())

def main():
	a = A
	b = B
	for (i, s) in enumerate(S):
		if a == 0 and b == 0:
			print(i)
			return
		if s == 1:
			if b > 0:
				if a < A:
					b -= 1
					a += 1
				else:
					a -= 1
			else:
				a -= 1
		elif a > 0:
			a -= 1
		else:
			b -= 1
	print(N)
	return
(N, B, A) = iti()
S = ili()
main()


(n, b, a) = map(int, input().split())
s_list = list(map(int, input().split()))
ans = 0
now_a = a
now_b = b
for (i, s) in enumerate(s_list):
	if s == 0:
		if now_a > 0:
			now_a -= 1
		elif now_b > 0:
			now_b -= 1
		else:
			print(i)
			exit()
	if s == 1:
		if now_a < a:
			if now_b > 0:
				now_b -= 1
				now_a += 1
			elif now_a > 0:
				now_a -= 1
			else:
				print(i)
				exit()
		else:
			now_a -= 1
print(n)


(n, b, a) = map(int, input().split())
arr = [int(x) for x in input().split()]
point = 0
(battery, acc) = (b, a)
while point != n and (acc or battery):
	if arr[point]:
		if battery and acc != a:
			battery -= 1
			acc += 1
		else:
			acc -= 1
	elif acc:
		acc -= 1
	else:
		battery -= 1
	point += 1
print(point)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
import math
import random
import re
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 9

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(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
		if meh < 0:
			meh = 0
	return msf

def res(ans, t):
	print('Case #{}: {}'.format(t, ans))
(n, b, a) = numIN()
mxa = a
arr = list(numIN())
for i in range(n):
	if arr[i] == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			print(i)
			exit(0)
	elif b > 0:
		if a + 1 <= mxa:
			b -= 1
			a += 1
		elif a > 0:
			a -= 1
		else:
			b -= 1
	elif a > 0:
		a -= 1
	else:
		print(i)
		exit(0)
print(n)


import math
q = 1
for _ in range(q):
	(n, b, a) = map(int, input().split())
	maxa = a
	l = list(map(int, input().split()))
	ans = 0
	i = 0
	while (a > 0 or b > 0) and i < n:
		if a == maxa:
			ans += 1
			a -= 1
		elif l[i] == 0:
			if a > 0:
				ans += 1
				a -= 1
			elif b > 0:
				ans += 1
				b -= 1
			else:
				break
		elif b > 0:
			ans += 1
			b -= 1
			if a < maxa:
				a += 1
		elif a > 0:
			ans += 1
			a -= 1
		else:
			break
		i += 1
	print(ans)


from sys import stdin

def ria(sep=''):
	if sep == '':
		return list(map(int, input().split()))
	else:
		return list(map(int, input().split(sep)))

def rsa(sep=''):
	if sep == '':
		return input().split()
	else:
		return input().split(sep)

def ri():
	return int(input())

def rd():
	return float(input())

def rs():
	return input()
(N, B, A) = map(int, input().split())
S = ria()
a = A
b = B
now = 0
while now < N:
	if a == 0 and b == 0:
		break
	if S[now] == 1:
		if a == A or b == 0:
			a -= 1
		else:
			b -= 1
			a += 1
	elif a == 0:
		b -= 1
	else:
		a -= 1
	now += 1
print(now)


(n, b, a) = (int(x) for x in input().split())
path = (int(x) for x in input().split())
ans = 0
(bat, accu) = (b, a)
for type in path:
	if type:
		if accu < a:
			if bat:
				accu += 1
				bat -= 1
			elif accu:
				accu -= 1
			else:
				break
		elif accu:
			accu -= 1
		elif bat:
			bat -= 1
		else:
			break
	elif accu:
		accu -= 1
	elif bat:
		bat -= 1
	else:
		break
	ans += 1
print(ans)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
maxa = a
cnt = 0
for i in range(n):
	if s[i] == 0:
		if a > 0:
			a -= 1
			cnt += 1
		elif b > 0:
			b -= 1
			cnt += 1
	elif a < maxa and b > 0:
		b -= 1
		a += 1
		cnt += 1
	elif a > 0:
		a -= 1
		cnt += 1
	if b == 0 and a == 0:
		break
print(cnt)


(n, b, a) = map(int, input().split())
A = a
s = list(map(int, input().split()))
stop = 1
for i in range(n):
	if a == 0 and b == 0:
		stop = 0
		break
	elif a == 0:
		b -= 1
		a += s[i]
	elif b == 0:
		a -= 1
	elif a != A and s[i] == 1:
		b -= 1
		a += 1
	else:
		a -= 1
if stop == 1:
	i += 1
print(i)


(stop, batmax, capmax) = map(int, input().split())
bateria = batmax
cap = capmax
segs = input().split()
count = 0
for s in segs:
	if cap == 0 and bateria == 0:
		break
	elif cap == 0:
		if s == '1':
			cap = min(cap + 1, capmax)
		bateria -= 1
	elif bateria == 0:
		cap -= 1
	elif s == '1' and cap < capmax:
		cap = min(cap + 1, capmax)
		bateria -= 1
	else:
		cap -= 1
	count += 1
print(count)


line = input().split(' ')
n = int(line[0])
b = int(line[1])
a = int(line[2])
lim_b = b
lim_a = a
segs = input().split(' ')
step = 0
for seg in segs:
	if seg == '0':
		if a == 0:
			if b == 0:
				break
			b -= 1
		else:
			a -= 1
	elif b == 0:
		if a == 0:
			break
		a -= 1
	elif a == lim_a:
		a -= 1
	else:
		b -= 1
		a += 1
	step += 1
print(step)


import sys

def solve(n, bcap, acap, s):
	loc = 0
	b = bcap
	a = acap
	while loc < n and a + b > 0:
		if a == acap or (a > 0 and s[loc] == 0) or b == 0:
			a -= 1
		else:
			b -= 1
			if s[loc] == 1 and a < acap:
				a += 1
		loc += 1
	return loc
n = 0
b = 0
a = 0
s = None
for line in sys.stdin:
	if n == 0:
		(n, b, a) = tuple(map(int, line.split()))
	else:
		s = tuple(map(int, line.split()))
		break
print(solve(n, b, a, s))


(n, b, a) = input().split()
(n, b, a) = (int(n), int(b), int(a))
max_b = b
max_a = a
sun = [int(x) for x in input().split()]
i = 0
while a > 0 or b > 0:
	if i == n:
		break
	if sun[i] == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif sun[i] == 1:
		if b > 0:
			if a < max_a:
				b -= 1
				a += 1
			elif a == max_a:
				a -= 1
		elif a > 0:
			a -= 1
		else:
			break
	i += 1
print(i)


import sys
stdin = sys.stdin
[stepsCount, batteryCharge, accumChargeMax] = stdin.readline().split()
resultSteps = 0
stepsCount = int(stepsCount)
accumChargeMax = int(accumChargeMax)
accumCharge = accumChargeMax
batteryCharge = int(batteryCharge)
useAccum = True
i = 0
while i < stepsCount:
	if accumCharge == 0 and batteryCharge == 0:
		break
	shining = stdin.read(1) == '1'
	stdin.read(1)
	if shining == True:
		if accumCharge < accumChargeMax and batteryCharge > 0:
			accumCharge += 1
			batteryCharge -= 1
		else:
			accumCharge -= 1
	elif accumCharge > 0:
		accumCharge -= 1
	else:
		batteryCharge -= 1
	resultSteps += 1
	i += 1
print(resultSteps)


def line():
	return map(int, input().split())
(n, b, a0) = line()
a = a0
ss = line()
for (i, s) in enumerate(ss):
	if s and a < a0 and (b > 0):
		b -= 1
		a += 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	if a <= 0 and b <= 0:
		print(i + 1)
		break
else:
	print(n)


(n, b, a) = map(int, input().split())
arr = [int(k) for k in input().split()]
ans = 0
mx_a = a
mx_b = b
for i in range(n):
	if mx_a == a:
		mx_a -= 1
		ans += 1
	elif arr[i] == 1 and mx_b > 0:
		mx_b -= 1
		mx_a += 1
		ans += 1
	elif mx_a > 0:
		mx_a -= 1
		ans += 1
	else:
		mx_b -= 1
		ans += 1
	if mx_a == 0 and mx_b == 0:
		break
print(ans)


(n, b, a) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
ka = a
for (i, si) in enumerate(s):
	if si == 0:
		if ka > 0:
			ka -= 1
		else:
			b -= 1
	elif b > 0 and ka < a:
		b -= 1
		ka += 1
	elif ka > 0:
		ka -= 1
	else:
		b -= 1
	if b + ka == 0:
		print(i + 1)
		exit()
print(n)


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

def use_acc():
	global a
	a -= 1

def use_battery(s):
	global a, b, a_limit
	if s == 1:
		a = min(a + 1, a_limit)
		b -= 1
	else:
		b -= 1
ans = 0
for i in range(n):
	if a == 0 and b == 0:
		break
	ans += 1
	if a == 0 and b != 0:
		use_battery(s[i])
		continue
	elif a != 0 and b == 0:
		use_acc()
		continue
	if s[i] == 0:
		use_acc()
	elif a == a_limit:
		use_acc()
	else:
		use_battery(s[i])
print(ans)


(n, b, a) = map(int, input().split())
c = a
x = list(map(int, input().split()))
count = 0
while count < n and (b > 0 or a > 0):
	if x[count] == 0:
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif c - a > 0 and b > 0:
		b -= 1
		a += 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
		a = min(c, a + 1)
	count += 1
print(count)


from sys import stdin
(n, b, a) = map(int, stdin.readline().split())
arr = list(map(int, stdin.readline().split()))
i = 0
count = 0
(x, y) = (b, a)
while (x > 0 or y > 0) and i < n:
	if arr[i] == 1:
		if y == a:
			y -= 1
			count += 1
		elif y > 0:
			if x > 0:
				x -= 1
				y += 1
				y = min(y, a)
			else:
				y -= 1
			count += 1
		elif x > 0:
			x -= 1
			y += 1
			y = min(y, a)
			count += 1
		else:
			pass
	elif y > 0:
		y -= 1
		count += 1
	elif x > 0:
		x -= 1
		count += 1
	else:
		pass
	i += 1
print(count)


(n, b, a) = map(int, input().split())
S = list(map(int, input().split()))
max_a = a
c = 0
for i in range(n):
	if S[i] == 1:
		if b > 0:
			if a == max_a:
				a -= 1
			else:
				b -= 1
				a += 1
		elif a > 0:
			a -= 1
		else:
			print(i)
			exit()
	elif a > 0:
		a -= 1
	elif b > 0:
		b -= 1
	else:
		print(i)
		exit()
else:
	print(n)


(n, b, a) = [int(x) for x in input().split()]
sun = [int(x) for x in input().split()]
a_max = a
cur_len = 0
for element in sun:
	if b == 0 and a == 0:
		break
	elif b > 0 and a < a_max and (element == 1):
		b -= 1
		a += 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	cur_len += 1
print(cur_len)


(a, b, c) = map(int, input().split())
imax = c
lst = list(map(int, input().split()))
for i in range(len(lst)):
	if lst[i] == 1:
		if c > 0 and c == imax:
			c -= 1
		elif b > 0:
			b -= 1
			if c < imax:
				c += 1
		elif c > 0:
			c -= 1
		else:
			break
	elif c > 0:
		c -= 1
	elif b > 0:
		b -= 1
	else:
		break
else:
	i += 1
print(i)


(n, a, b) = map(int, input().split())
ar = list(map(int, input().split()))
bmax = b
i = 0
ans = 0
while i < n:
	if ar[i] == 1:
		if b < bmax and a > 0:
			b += 1
			a -= 1
			ans += 1
		elif b < bmax and a == 0:
			b -= 1
			ans += 1
		elif b >= bmax and a > 0:
			b -= 1
			ans += 1
		elif b >= bmax and a <= 0:
			b -= 1
			ans += 1
	elif b > 0:
		b -= 1
		ans += 1
	elif a > 0:
		a -= 1
		ans += 1
	if b == 0 and a == 0:
		flag = 0
		break
	else:
		i += 1
		flag = 1
if flag == 1:
	print(n)
else:
	print(i + 1)


(n, b, a) = map(int, input().split())
am = a
li = list(map(int, input().split()))
x = 0
for i in range(n):
	if li[i] == 0:
		if a == 0:
			b = b - 1
		else:
			a = a - 1
		x += 1
		if x == n:
			break
		if a == 0 and b == 0:
			break
	else:
		if b == 0:
			a = a - 1
		elif a == am:
			a = a - 1
		else:
			b = b - 1
			a = a + 1
		x += 1
		if x == n:
			break
		if a == 0 and b == 0:
			break
print(x)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		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 read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.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:
			self.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.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	(N, B, A) = getInts()
	A_cap = A
	path = getInts()
	i = 0
	while i < N:
		if path[i] == 1 and A < A_cap and (B > 0):
			B -= 1
			A += 1
			i += 1
		elif A > 0:
			A -= 1
			i += 1
		elif B > 0:
			B -= 1
			i += 1
		else:
			break
	return i
print(solve())


(n, b, a) = map(int, input().split())
lst = list(map(int, input().split()))
mx = a
for (i, x) in enumerate(lst):
	if b == 0 and a == 0:
		print(i)
		from sys import exit
		exit()
	if x == 0:
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif b > 0:
		if a + 1 <= mx:
			a += 1
			b -= 1
		else:
			a -= 1
	else:
		a -= 1
print(i + 1)


(n, b, a) = map(int, input().split())
A = [int(x) for x in input().split()]
charge = a
result = 0
for i in range(n):
	if A[i] == 1:
		if a == charge or (b == 0 and charge > 0):
			charge -= 1
		elif b > 0:
			b -= 1
			charge += 1
		else:
			break
	elif charge > 0:
		charge -= 1
	elif b > 0:
		b -= 1
	else:
		break
	result = max([result, i + 1])
print(result)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
c = 0
td = a
for i in range(n):
	if b == 0:
		if a == 0:
			continue
		elif a > 0:
			c += 1
			a -= 1
	if b > 0:
		if s[i] == 1:
			if a < td:
				b -= 1
				a += 1
				c += 1
			else:
				a -= 1
				c += 1
		elif a > 0:
			a -= 1
			c += 1
		elif a == 0:
			b -= 1
			c += 1
print(c)


import sys
(n, b, a) = tuple([int(i) for i in input().split()])
data = input().split()
dist = 0
bbs = b
aas = a
for i in range(n):
	if aas == a:
		aas -= 1
	elif data[i] == '0':
		if aas > 0:
			aas -= 1
		elif bbs > 0:
			bbs -= 1
		else:
			print(i)
			sys.exit()
	elif bbs > 0:
		bbs -= 1
		aas += 1
	elif aas > 0:
		aas -= 1
	else:
		print(i)
		sys.exit()
print(n)


(n, b, a) = map(int, input().split())
S = tuple(map(int, input().split()))
(now_a, now_b) = (a, b)
for i in range(n):
	if not (now_a or now_b):
		break
	if now_a == a:
		now_a -= 1
	elif S[i]:
		if now_b:
			now_b -= 1
			now_a += 1
		else:
			now_a -= 1
	elif now_a:
		now_a -= 1
	else:
		now_b -= 1
else:
	i += 1
print(i)


(n, b, a) = map(int, input().split())
a_max = a
arr = list(map(int, input().split()))
i = 0
while i < n:
	if arr[i] == 0:
		if a != 0:
			a -= 1
		elif b != 0:
			b -= 1
		else:
			break
	elif a == a_max:
		a -= 1
	elif b != 0:
		b -= 1
		a += 1
	elif a != 0:
		a -= 1
	else:
		break
	i += 1
print(i)


import sys
from sys import stdin
exit = sys.exit
input = stdin.readline
(n, b, a) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
limit = a
for i in range(n):
	if a == 0 and b == 0:
		print(i)
		exit()
	if s[i] == 1 and b and (a != limit):
		b -= 1
		a += 1
	elif a:
		a -= 1
	else:
		b -= 1
print(n)


(n, b, a) = list(map(int, input().split()))
i = 0
sp = list(map(int, input().split()))
na = a
nb = b
while i < n and (na != 0 or nb != 0):
	if sp[i] == 0:
		if na != 0:
			na -= 1
		else:
			nb -= 1
	elif na != a:
		if nb != 0:
			na += 1
			nb -= 1
		else:
			na -= 1
	else:
		na -= 1
	i += 1
print(i)


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


def main():
	(nb, b, a) = map(int, input().split())
	(cb, ca) = (b, a)
	tab = list(map(int, input().split()))
	score = 0
	for x in range(nb):
		if ca == 0 and cb == 0:
			break
		elif ca == 0 and cb > 0:
			cb -= 1
			if tab[x] == 1:
				ca += 1
		elif cb == 0 and ca > 0:
			ca -= 1
		elif tab[x] == 1 and ca < a:
			ca += 1
			cb -= 1
		else:
			ca -= 1
		score += 1
	print(score)
main()


(n, a, b) = map(int, input().split())
mab = b
l = list(map(int, input().split()))
ans = 0
for x in l:
	if x == 0:
		if b > 0:
			b -= 1
			ans += 1
		elif a > 0:
			a -= 1
			ans += 1
		else:
			break
	elif mab == b:
		b -= 1
		ans += 1
	elif a > 0:
		a -= 1
		b += 1
		ans += 1
	elif b > 0:
		ans += 1
		b -= 1
	else:
		break
print(ans)


import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
(n, a, b) = map(int, input().split())
s = list(map(int, input().split()))
x = a + 0
y = b + 0
for i in range(n):
	if x == 0 and y == 0:
		print(i)
		exit()
	if y == b:
		y -= 1
		continue
	if s[i] == 1 and x:
		x -= 1
		y += 1
		continue
	if y:
		y -= 1
		continue
	if x:
		x -= 1
		continue
print(n)


(n, b, a) = list(map(int, input().split()))
s = list(map(int, input().split()))
import sys
bat = b
acc = a
if a == 0:
	print(min(b, n))
	sys.exit()
for i in range(n):
	if acc == 0 and bat == 0:
		print(i)
		sys.exit()
	if s[i] == 1:
		if acc == a or bat == 0:
			acc -= 1
		else:
			acc += 1
			bat -= 1
	elif acc > 0:
		acc -= 1
	else:
		bat -= 1
print(n)


(n, b, a) = map(int, input().split())
x = list(map(int, input().split()))
cb = b
ca = a
r = 0
for i in x:
	if not ca and (not cb):
		break
	if i:
		if ca < a and cb:
			cb -= 1
			ca += 1
		else:
			ca -= 1
	elif ca:
		ca -= 1
	else:
		cb -= 1
	r += 1
print(r)


(n, b, a) = map(int, input().strip().split())
s = [int(i) for i in input().strip().split()]
ans = 0
to_mod = a
for i in range(n):
	if a <= 0 and b <= 0:
		break
	if s[i] == 0:
		if a > 0:
			a -= 1
			ans += 1
		elif b > 0:
			b -= 1
			ans += 1
	elif a == to_mod:
		a -= 1
		ans += 1
	elif b > 0:
		a += 1
		b -= 1
		ans += 1
	elif a > 0:
		a -= 1
		ans += 1
print(ans)


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		b = self.next_int()
		a = self.next_int()
		bb = b
		aa = a
		for _ in range(0, n):
			d = self.next_int()
			if aa == 0 and bb == 0:
				print(_)
				return
			elif aa == 0:
				bb -= 1
				if d == 1 and aa < a:
					aa += 1
			elif bb == 0:
				aa -= 1
			elif aa == a:
				aa -= 1
			elif d == 1:
				aa += 1
				bb -= 1
			else:
				aa -= 1
		print(n)
Main().solve()


(n, b, a) = map(int, input().split())
path = list(map(int, input().split()))
start = 0
bat = b
acc = a
res = 0
while (acc != 0 or bat != 0) and start < n:
	if path[start] == 1:
		if acc < a:
			if bat != 0:
				acc += 1
				bat -= 1
			else:
				acc -= 1
		elif acc != 0:
			acc -= 1
		else:
			bat -= 1
	elif acc != 0:
		acc -= 1
	else:
		bat -= 1
	res += 1
	start += 1
print(res)


import sys
input = sys.stdin.readline
(n, b, a) = list(map(int, input().split()))
S = list(map(int, input().split()))
bn = b
an = a
for i in range(n):
	if bn == 0 and an == 0:
		print(i)
		return
	if S[i] == 1 and bn > 0 and (an < a):
		bn -= 1
		an += 1
	elif an > 0:
		an -= 1
	else:
		bn -= 1
print(n)


(n, batery, accu) = map(int, input().split())
maxaccu = accu
maxbat = batery
arr = list(map(int, input().split()))
ans = 0
for i in range(n):
	if arr[i] == 1:
		if batery != 0:
			if accu == maxaccu:
				accu -= 1
			else:
				batery -= 1
				accu += 1
			ans += 1
		elif accu == 0:
			break
		else:
			accu -= 1
			ans += 1
	elif accu != 0:
		accu -= 1
		ans += 1
	elif batery == 0:
		break
	else:
		batery -= 1
		ans += 1
print(ans)


(n, b, a) = map(int, input().split())
c = a
s = [int(x) for x in input().split()]
r = 0
for i in s:
	if b == 0 and a == 0:
		break
	if i == 1:
		if b > 0 and a < c:
			a += 1
			b -= 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	r += 1
print(r)


list_ints = [int(x) for x in input().split()]
dest = list_ints[0] - 1
bat = list_ints[1]
acc = list_ints[2]
acc_max = acc
list_ints = [int(x) for x in input().split()]
steps = 1
acc -= 1
for i in range(1, len(list_ints)):
	if bat == 0 and acc == 0:
		break
	if list_ints[i] == 1 and bat != 0 and (acc < acc_max):
		bat -= 1
		acc += 1
	elif acc != 0:
		acc -= 1
	else:
		bat -= 1
	steps += 1
print(steps)


l = list(map(int, input().split()))
n = l[0]
battery = l[1]
accumulator = l[2]
max_a = accumulator
l2 = list(map(int, input().split()))
count = 0
for i in l2:
	if i == 0:
		if accumulator == 0:
			battery -= 1
		else:
			accumulator -= 1
	elif accumulator == max_a:
		if accumulator == 0:
			battery -= 1
		else:
			accumulator -= 1
	elif battery == 0:
		accumulator -= 1
	else:
		battery -= 1
		accumulator += 1
	count += 1
	if battery == 0 and accumulator == 0:
		break
print(count)


(n, b, a) = map(int, input().split(' '))
s = list(map(int, input().split(' ')))
res = 0
a1 = a
b1 = b
for i in range(n):
	if s[i] == 0:
		if a1 > 0:
			a1 -= 1
			res += 1
		elif b1 > 0:
			b1 -= 1
			res += 1
	elif s[i] == 1:
		if b1 > 0 and a1 < a:
			b1 -= 1
			a1 += 1
			res += 1
		elif a1 > 0:
			a1 -= 1
			res += 1
	if b1 == 0 and a1 == 0:
		break
print(res)


def input_ints():
	return [int(x) for x in input().split()]
(_, b, a) = input_ints()
xs = input_ints()
a_ = a
score = 0
for x in xs:
	if x == 0:
		if a_ > 0:
			a_ -= 1
			score += 1
		elif b > 0:
			b -= 1
			score += 1
		else:
			break
	elif a_ > 0 and (a_ == a or b == 0):
		a_ -= 1
		score += 1
	elif b > 0:
		b -= 1
		a_ = min(a, a_ + 1)
		score += 1
	else:
		break
print(score)


(n, b, a) = list(map(int, input().split()))
maxa = a
d = list(map(int, input().split()))
count = 0
for i in d:
	if i == 1 and a != maxa and (b != 0):
		b -= 1
		a += 1
		count += 1
	elif i == 1 and a != 0:
		a -= 1
		count += 1
	elif i == 0:
		if a != 0:
			a -= 1
			count += 1
		elif b != 0:
			b -= 1
			count += 1
		else:
			break
	else:
		break
print(count)


(n, b, a) = list(map(int, input().split()))
l = list(map(int, input().split()))
aa = a
for i in range(n):
	if a == 0 and b == 0:
		print(i)
		break
	if l[i] == 0:
		if a > 0:
			a -= 1
		else:
			b -= 1
	if l[i] == 1:
		if a == aa:
			a -= 1
		elif b > 0:
			b -= 1
			a = min(aa, a + 1)
		else:
			a -= 1
	if i == n - 1:
		print(n)


import sys
from collections import Counter
sys.setrecursionlimit(10 ** 7)
(n, b, a) = map(int, input().split())
ma = a
s = []
for i in input().split():
	s.append(int(i))
s.append(0)
for i in range(n + 1):
	st = ''
	if s[i] == 0:
		if a == 0:
			b -= 1
			st += '[nc,use b]'
			st += 'a,b=' + str(a) + ',' + str(b)
		else:
			a -= 1
			st += '[nc,use a]'
			st += 'a,b=' + str(a) + ',' + str(b)
	elif s[i] == 1:
		if a >= ma:
			a -= 1
			st += '[cc,use a]'
			st += 'a,b=' + str(a) + ',' + str(b)
		elif b > 0 and a < ma:
			b -= 1
			a += 1
			st += '[cc,chr a]'
			st += 'a,b=' + str(a) + ',' + str(b)
		elif b > 0 and a == ma:
			b -= 1
			st += '[cc,max a]'
			st += 'a,b=' + str(a) + ',' + str(b)
		elif b == 0:
			a -= 1
			st += '[cc,use a]'
			st += 'a,b=' + str(a) + ',' + str(b)
		else:
			b -= 1
	if b < 0 or a < 0:
		ans = i + 1
		break
print(i)


from sys import stdin, stdout
import math, queue, heapq
fastinput = stdin.readline
fastout = stdout.write

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

def computeLPSArray(pat, M, lps):
	len = 0
	lps[0]
	i = 1
	while i < M:
		if pat[i] == pat[len]:
			len += 1
			lps[i] = len
			i += 1
		elif len != 0:
			len = lps[len - 1]
		else:
			lps[i] = 0
			i += 1
m = 10 ** 9 + 7
t = 1
while t:
	t -= 1
	(n, b, a) = map(int, fastinput().split())
	u = list(map(int, fastinput().split()))
	(A, B) = (a, b)
	count = 0
	for i in u:
		if B == 0 and A == 0:
			break
		if i == 1 and B != 0 and (A != a):
			A += 1
			B -= 1
		elif i == 1 and (B == 0 or A == a):
			A -= 1
		elif i == 0 and A != 0:
			A -= 1
		elif i == 0 and B != 0:
			B -= 1
		count += 1
	print(count)


(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
x = b
y = a
for i in range(n):
	if x == 0 and y == 0:
		break
	if l[i] == 1:
		if x > 0 and y == a:
			y -= 1
		elif x > 0 and y < a:
			y += 1
			x -= 1
		else:
			y -= 1
	elif y > 0:
		y -= 1
	else:
		x -= 1
	ans += 1
print(ans)


import sys
(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
(batt, acc) = (b, a)
ans = 0
for i in range(n):
	if l[i]:
		if batt and acc < a:
			acc += 1
			batt -= 1
		elif acc:
			acc -= 1
		else:
			batt -= 1
	elif acc:
		acc -= 1
	else:
		batt -= 1
	ans = i
	if acc == 0 and batt == 0:
		break
print(ans + 1)


l = list(map(int, input().split()))
segs = list(map(int, input().split()))
n = l[0]
maxb = b = l[1]
maxa = a = l[2]

def walk(a, b, maxa, maxb, segs):
	count = 0
	for s in segs:
		if a == 0 and b == 0:
			break
		elif a == 0:
			if s == 1:
				a = min(a + 1, maxa)
			b -= 1
		elif b == 0:
			a -= 1
		elif s == 1 and a < maxa:
			a = min(a + 1, maxa)
			b -= 1
		else:
			a -= 1
		count += 1
	return count
count = walk(a, b, maxa, maxb, segs)
print(count)


def do_task_t(smallfact):
	x = 0
	x ^= 2 ** smallfact
GINT = 10 ** 4
modernise = 0
(X, Y) = (0, 0)
if modernise == 0:
	modernise += GINT - modernise

def ss():
	global X, Y
	(n, batt, acc) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	bat = batt
	ac = acc
	ind = n
	for i in range(len(a)):
		if X == 0:
			Y += 1
		if a[i] == 1 and ac == acc:
			ac -= 1
		elif a[i] == 1 and ac != acc and (bat > 0) and (bat > 0):
			bat -= 1
			ac += 1
			if X == 0:
				Y += 1
		elif a[i] == 1 and ac != acc and (bat == 0) and (bat == 0):
			if X == 0:
				Y += 1
			ac -= 1
			if X == 0:
				Y += 1
		elif a[i] == 0 and ac > 0:
			ac -= 1
			if X == 0:
				Y += 1
		elif a[i] == 0 and bat > 0:
			bat -= 1
		if bat == 0 and ac == 0:
			ind = i + 1
			break
	print(ind)
ss()
smallfact = 1
smallfact ^= 1
if X == 0:
	Y += 1
do_task_t(smallfact)
if X == 0:
	Y += 1
if X == 0:
	Y += 1
if X == 0:
	Y += 1


(n, a, b) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
(a, b) = (b, a)
ca = a
cb = b
for i in range(n):
	if l[i] == 0:
		if ca > 0:
			ca -= 1
		elif cb > 0:
			cb -= 1
		else:
			break
	elif ca < a and cb > 0:
		cb -= 1
		ca += 1
	elif ca > 0:
		ca -= 1
	elif cb > 0:
		cb -= 1
	else:
		break
	ans += 1
print(ans)


import sys
ilist = [int(i) for i in input().split()]
(n, b, a) = (ilist[0], ilist[1], ilist[2])
s = [int(i) for i in input().split()]
if n <= b + a:
	print(n)
	sys.exit()
result = 0
max_a = a
for i in s:
	if i == 0:
		if a > 0:
			a -= 1
			result += 1
		elif b > 0:
			b -= 1
			result += 1
		else:
			break
	elif a == max_a:
		a -= 1
		result += 1
	elif b > 0:
		b -= 1
		a += 1
		result += 1
	elif a > 0:
		a -= 1
		result += 1
	else:
		break
print(result)


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


(_, b, a) = list(map(int, input().strip().split()))
numbers = list(map(int, input().strip().split()))
max_a = a
for (i, n) in enumerate(numbers):
	if n:
		if b > 0 and a < max_a:
			b -= 1
			a += 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	if a == 0 and b == 0:
		break
print(i + 1)


(n, b, max_a) = map(int, input().split())
a = max_a
path = list(map(int, input().split()))
i = 0
for p in path:
	if a == 0 and b == 0:
		break
	if p == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
	elif b > 0 and a < max_a:
		b -= 1
		a += 1
	else:
		a -= 1
	i += 1
print(i)


(n, bt, kt) = map(int, input().split())
b = bt
k = kt
a = list(map(int, input().split()))
ans = 0
for i in range(n):
	if a[i] == 0:
		if k > 0:
			k -= 1
			ans += 1
		elif b > 0:
			b -= 1
			ans += 1
		else:
			print(ans)
			exit(0)
	elif k == kt:
		k -= 1
		ans += 1
	elif b > 0:
		b -= 1
		ans += 1
		k += 1
	elif k > 0:
		k -= 1
		ans += 1
	else:
		print(ans)
		exit(0)
print(ans)


(n, b, a) = map(int, input().split())
ib = b
ia = a
l = list(map(int, input().split()))
count = 0
i = 0
while (a != 0 or b != 0) and i < n:
	if a == ia:
		a -= 1
	elif a == 0:
		if l[i] == 1:
			a += 1
		b -= 1
	elif b == 0:
		a -= 1
	elif l[i] == 0:
		a -= 1
	elif l[i] == 1:
		b -= 1
		a += 1
	i += 1
print(i)


(n, b, a) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
amax = a
for i in arr:
	if b == 0 and a == 0:
		break
	elif b == 0:
		a -= 1
	elif a == 0:
		if i == 1:
			if a < amax:
				a += 1
		b -= 1
	elif i == 1 and a < amax:
		b -= 1
		a += 1
	else:
		a -= 1
	ans += 1
print(ans)


import collections

def solve():
	(n, b, a) = map(int, input().split())
	a_max = a
	S = list(map(int, input().split()))
	ans = 0
	for i in range(n):
		if S[i] == 1:
			if a < a_max and b > 0:
				b -= 1
				a += 1
			elif a > 0:
				a -= 1
			elif b > 0:
				b -= 1
			else:
				return i
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			return i
	return n
print(solve())


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
(ca, cb) = (a, b)
c = 0
for i in s:
	if i == 1:
		if a == ca:
			a = max(0, a - 1)
			c += 1
		elif b > 0:
			c += 1
			b = max(0, b - 1)
			a = min(a + 1, ca)
		elif a > 0 and a > b:
			c += 1
			a = max(0, a - 1)
		else:
			break
	elif a > 0:
		c += 1
		a = max(0, a - 1)
	elif b > 0:
		c += 1
		b = max(0, b - 1)
	else:
		break
print(c)


import sys, os
from io import BytesIO, IOBase
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
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 read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	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.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
(n, b, a) = mp()
mxa = a
arr = lmp()
i = 0
while i < n and (a or b):
	if arr[i] == 0:
		if a:
			a -= 1
		else:
			b -= 1
	elif a < mxa and b:
		b -= 1
		a = a + 1
	else:
		a -= 1
	i += 1
print(i)


(n, b, a) = tuple((int(_) for _ in input().split()))
s = tuple((int(_) for _ in input().split()))
(current_b, current_a) = (b, a)
for i in range(n):
	if s[i] == 1 and current_a == a:
		if current_a == a:
			current_a -= 1
	elif s[i] == 1 and current_b > 0:
		current_b -= 1
		current_a += 1
	elif current_a > 0:
		current_a -= 1
	elif current_b > 0:
		current_b -= 1
	if current_b == 0 and current_a == 0 and (i != n - 1):
		print(i + 1)
		break
	elif i == n - 1:
		print(n)


(nn, bb, aa) = map(int, input().split())
(n, b, a) = (nn, bb, aa)
S = list(map(int, input().split()))
for i in range(n):
	if a == 0 and b == 0:
		print(i)
		exit(0)
	if S[i] == 1:
		if b > 0 and a < aa:
			b -= 1
			a += 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
print(n)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
i = 0
aa = a
bb = b
while (bb > 0 or aa > 0) and i < n:
	if s[i] == 0:
		if aa > 0:
			aa -= 1
		else:
			bb -= 1
	elif aa == a or bb == 0:
		aa -= 1
	else:
		bb -= 1
		aa += 1
	i += 1
print(i)


(n, b, a) = map(int, input().split())
arr = list(map(int, input().split()))
maxa = a
p = 0
for i in range(n):
	if a == 0 and b == 0:
		break
	if arr[i] == 0:
		if a > 0:
			a -= 1
			p += 1
		elif b > 0:
			b -= 1
			p += 1
		continue
	if b == 0:
		a -= 1
	elif a < maxa:
		b -= 1
		a = a + 1
	else:
		a -= 1
	p = p + 1
print(p)


(n, b, a) = map(int, input().split())
list1 = list(map(int, input().split()))
bnow = b
anow = a
count = 0
for i in list1:
	if bnow == 0:
		anow -= 1
		count += 1
		if bnow == anow == 0:
			break
		continue
	elif anow == 0:
		bnow -= 1
		if i == 1:
			anow += 1
		count += 1
		if bnow == anow == 0:
			break
		continue
	elif anow == a:
		anow -= 1
		count += 1
		continue
	elif i == 0:
		anow -= 1
		count += 1
		continue
	else:
		bnow -= 1
		anow += 1
		count += 1
		continue
print(count)


__version__ = '0.1'
__date__ = '2019-04-16'
import sys

def count_distance(n, b, a, sunlights):
	if b + a >= n:
		return n
	A = a
	a -= 1
	steps = 1
	for s in sunlights[1:]:
		if a == 0 and b == 0:
			return steps
		if s == '1':
			if a < A:
				if b > 0:
					a += 1
					b -= 1
				else:
					a -= 1
			else:
				a -= 1
		elif a > 0:
			a -= 1
		elif b == 0:
			a -= 1
		else:
			b -= 1
		steps += 1
	return steps

def main(argv=None):
	(n, b, a) = map(int, input().split())
	sunlights = input().split()
	print(count_distance(n, b, a, sunlights))
	return 0
STATUS = main()
sys.exit(STATUS)


(n, b, a) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
dist = 0
mx = a
for i in l:
	if i == 0:
		if a != 0:
			a -= 1
		else:
			b -= 1
	if i == 1:
		if b != 0 and a < mx:
			b -= 1
			a += 1
		else:
			a -= 1
	dist += 1
	if a == 0 and b == 0:
		break
print(dist)


(n, shade, sun) = map(int, input().split())
lst = [int(x) for x in input().split()]
max_sun = sun
ans = 0
for i in lst:
	if i == 0:
		if sun > 0:
			sun -= 1
		else:
			shade -= 1
	elif shade > 0 and sun < max_sun:
		shade -= 1
		sun += 1
	elif sun > 0:
		sun -= 1
	else:
		shade -= 1
	if shade < 0 or sun < 0:
		break
	else:
		ans += 1
print(ans)


def main():
	(n, b, a) = map(int, input().split())
	arr = list(map(int, input().split()))
	B = b
	A = a
	for i in range(n + 1):
		if A == 0 and B == 0 or i == n:
			print(i)
			break
		if arr[i]:
			if A == a:
				A -= 1
			elif B:
				B -= 1
				A += 1
			else:
				A -= 1
		elif A:
			A -= 1
		else:
			B -= 1
	return 0
main()


(n, b, a) = map(int, input().split())
path = map(int, input().split())
max_a = a
current_a = a
count = 0
for segment in path:
	if segment == 0:
		if current_a > 0:
			current_a -= 1
		else:
			b -= 1
	elif current_a == max_a or b == 0:
		current_a -= 1
	else:
		b -= 1
		current_a += 1
	count += 1
	if current_a == 0 and b == 0:
		break
print(count)


(n, b, a) = map(int, input().split())
b1 = b
a1 = a
z = list(map(int, input().split()))
flag = 0
for i in range(len(z)):
	if z[i] == 1:
		if b and a < a1:
			b -= 1
			a += 1
			continue
		if a:
			a -= 1
			continue
		if a == 0 and b == 0:
			flag = 1
			break
	else:
		if a:
			a -= 1
			continue
		if b:
			b -= 1
			continue
		if a == 0 and b == 0:
			flag = 1
			break
if flag == 1:
	print(i)
else:
	print(n)


import sys
arr = [int(x) for x in input().strip().split(' ')]
route = [int(x) for x in input().strip().split(' ')]
cont = 0
temp2 = arr[2]
for i in route:
	if i == 0:
		if arr[2] >= 1:
			arr[2] -= 1
		elif arr[1] >= 1:
			arr[1] -= 1
		else:
			break
	elif arr[2] != temp2:
		if arr[1] >= 1:
			arr[1] -= 1
			if arr[2] < temp2:
				arr[2] += 1
		elif arr[2] >= 1:
			arr[2] -= 1
		else:
			break
	elif arr[2] >= 1:
		arr[2] -= 1
	elif arr[1] >= 1:
		arr[1] -= 1
	else:
		break
	cont += 1
	if arr[2] == arr[1] == 0:
		break
print(cont)


def main():
	(n, b, a) = map(int, input().split())
	array = list(map(int, input().split()))
	max_a = a
	for i in range(n - 1):
		if array[i] == 1:
			if b > 0:
				if a < max_a:
					b -= 1
					a += 1
				elif a > 0:
					a -= 1
				elif b > 0:
					b -= 1
				else:
					print(i)
					return
			elif a > 0:
				a -= 1
			else:
				print(i)
				return
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			print(i)
			return
	if a > 0 or b > 0:
		print(n)
		return
	print(n - 1)
main()


(n, b, a) = list(map(int, input().split()))
s = list(map(int, input().split()))
i = 0
(x, y) = (a, b)
while i != n:
	if s[i] == 0:
		if x > 0:
			x -= 1
		else:
			y -= 1
	elif s[i] == 1:
		if x == a:
			x -= 1
		elif y == 0:
			x -= 1
		else:
			y -= 1
			x += 1
	if x < 0 or y < 0:
		break
	i += 1
print(i)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
max_steps = 0
(curr_b, curr_a) = (b, a)
for (i, sun) in enumerate(s):
	if curr_a == a:
		curr_a -= 1
	elif sun:
		if curr_b > 0:
			curr_b -= 1
			curr_a += 1
		elif curr_a > 0:
			curr_a -= 1
		else:
			break
	elif curr_a > 0:
		curr_a -= 1
	elif curr_b > 0:
		curr_b -= 1
	else:
		break
	max_steps += 1
	if not (curr_a or curr_b):
		break
print(max_steps)


(n, b, a) = map(int, input().split())
power = b + a
am = a
path = list(map(int, input().split()))
num = 0
for i in range(n):
	if am == b == 0:
		break
	else:
		if path[i] == 0:
			if am > 0:
				am -= 1
			else:
				b -= 1
		elif am == a:
			am -= 1
		elif b > 0:
			b -= 1
			if am < a:
				am += 1
		else:
			am -= 1
		num += 1
print(num)


(n, battery, acc) = map(int, input().split(' '))
accumulator = acc
ans = 0
Arr = list(map(int, input().split(' ')))
for i in range(n):
	if battery == 0 and accumulator == 0:
		break
	if Arr[i] == 0:
		if accumulator > 0:
			accumulator -= 1
		elif battery > 0:
			battery -= 1
	elif accumulator != acc and battery > 0:
		accumulator += 1
		battery -= 1
	else:
		accumulator -= 1
	ans += 1
print(ans)


(n, maxb, maxa) = map(int, input().split())
b = maxb
a = maxa
segs = list(map(int, input().split()))
steps = 0
for seg in segs:
	steps = steps + 1 if b > 0 or a > 0 else steps
	if b > 0 and seg == 1 and (a < maxa):
		b -= 1
		a += 1
		a = min(maxa, a)
	elif a > 0:
		a -= 1
	else:
		b -= 1
	if b <= 0 and a <= 0:
		break
print(steps)


(n, b, a) = [int(x) for x in input().split()]
ma = a
v = [int(x) for x in input().split()]
at = 0
while (b > 0 or a > 0) and at < len(v):
	if a > 0 and v[at] == 0:
		a = a - 1
	elif b > 0 and v[at] == 1 and (a < ma):
		b = b - 1
		a = a + 1
	elif a > 0:
		a = a - 1
	else:
		b = b - 1
	at = at + 1
print(at)


(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
maxB = b
maxA = a
for (i, x) in enumerate(l):
	if x == 1:
		if b != 0 and a != maxA:
			b -= 1
			a = min(a + 1, maxA)
		elif a != 0:
			a -= 1
	elif a != 0:
		a -= 1
	elif b != 0:
		b -= 1
	if a == 0 and b == 0:
		break
print(i + 1)


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *

def main():
	(n, b, a) = [int(x) for x in stdin.readline().split()]
	s = [int(x) for x in stdin.readline().split()]
	maxa = a
	res = 0
	for ex in s:
		if a == 0 and b == 0:
			break
		if a > 0:
			if a == maxa or ex == 0 or b == 0:
				a -= 1
				res += 1
				continue
		res += 1
		b -= 1
		if ex == 1:
			if a < maxa:
				a += 1
	stdout.write(str(res))
	return 0
main()


n = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
max_battery = n[1]
max_accum = n[2]
flag = False
res = n[0]
for j in range(n[0]):
	if s[j] == 1:
		if n[1] > 0 and n[2] != max_accum:
			n[1] -= 1
			if n[2] != max_accum:
				n[2] += 1
		elif n[2] != 0:
			n[2] -= 1
		flag = False
	elif n[2] != 0:
		n[2] -= 1
	elif n[1] != 0:
		n[1] -= 1
	if n[1] == 0 and n[2] == 0:
		res = j + 1
		break
print(res)


R = lambda : map(int, input().split())
(n, b, a) = R()
s = list(R())
x = 0
(v, u) = (b, a)
for y in s:
	if v or u:
		if (not y or u == a) and u:
			u -= 1
		elif v:
			v -= 1
			if y:
				u = min(u + 1, a)
		else:
			u -= 1
		x += 1
print(x)


import sys
import copy
line = sys.stdin.readline().strip('\n')
(a, b, c) = list(map(int, line.split()))
line = sys.stdin.readline().strip('\n')
num = list(map(int, line.split()))
(bb, cc) = copy.deepcopy((b, c))
cnt = 0
for i in range(a):
	cnt += 1
	if num[i] == 0:
		if c > 0:
			c -= 1
		elif b > 0:
			b -= 1
		else:
			cnt -= 1
			break
	elif c == cc:
		c -= 1
	elif b > 0:
		b -= 1
		c += 1
	elif c > 0:
		c -= 1
	else:
		cnt -= 1
		break
print(cnt)


(n, b, a) = map(int, input().split())
m_a = a
m_b = b
X = list(map(int, input().split()))
for i in range(n):
	if X[i] == 1 and b != 0 and (m_a != a):
		b -= 1
		a += 1
	elif X[i] == 1 and (b == 0 or m_a == a):
		a -= 1
	elif X[i] == 0 and a != 0:
		a -= 1
	elif X[i] == 0 and a == 0:
		b -= 1
	if a == 0 and b == 0:
		break
print(i + 1)


def f(bat, ac, lst):
	charge = ac
	ans = 0
	for i in lst:
		if i == 0:
			if charge:
				charge -= 1
				ans += 1
			elif bat:
				bat -= 1
				ans += 1
			else:
				break
		if i == 1:
			if charge != ac:
				if bat:
					bat -= 1
					charge += 1
					ans += 1
				elif charge:
					charge -= 1
					ans += 1
			elif charge == ac:
				charge -= 1
				ans += 1
			elif charge == 0 and bat == 0:
				break
	return ans
(n, bat, ac) = map(int, input().strip().split())
lst = list(map(int, input().strip().split()))
print(f(bat, ac, lst))


n = input()
n = n.split(' ')
m = input()
m = m.split(' ')
n[0] = int(n[0])
n[1] = int(n[1])
n[2] = int(n[2])
c = n[2]
t = 0
for i in m:
	if i == '0':
		if n[2] > 0:
			n[2] = n[2] - 1
			t = t + 1
		elif n[1] > 0:
			n[1] = n[1] - 1
			t = t + 1
	elif i == '1':
		if n[2] == c:
			n[2] = n[2] - 1
			t = t + 1
		elif n[1] > 0:
			n[1] = n[1] - 1
			t = t + 1
			if n[2] < c:
				n[2] = n[2] + 1
		elif n[2] > 0:
			n[2] = n[2] - 1
			t = t + 1
print(t)


(n, b, a_capacity) = map(int, input().split())
s = list(map(int, input().split()))
a = a_capacity
for i in range(n):
	if b == 0 and a == 0:
		print(i)
		exit()
	if s[i] == 1:
		if b > 0 and a < a_capacity:
			b -= 1
			a += 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
print(n)


def solve(nums, b, a):
	maxA = a
	count = 0
	for i in nums:
		if i == '1' and b > 0 and (a < maxA):
			b -= 1
			a += 1
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
		count += 1
	return count
(n, b, a) = map(int, input().split())
nums = input().split()
print(solve(nums, b, a))


(n, max_b, max_a) = list(map(int, input().split()))
a = max_a
b = max_b
s = list(map(int, input().split()))
i = 0
while a != 0 or b != 0:
	if i == n:
		print(i)
		break
	elif b == 0:
		if a != 0:
			a -= 1
			i += 1
		else:
			print(i)
			break
	elif a == 0:
		if b != 0:
			a += s[i]
			b -= 1
			i += 1
		else:
			print(i)
			break
	elif a == max_a:
		a -= 1
		i += 1
	elif s[i] == 1:
		b -= 1
		a += 1
		i += 1
	else:
		a -= 1
		i += 1
if a == 0 and b == 0:
	print(i)


import sys
input = sys.stdin.readline
(n, b, a) = map(int, input().split())
max_b = b
max_a = a
s = input().rstrip().split()
count = 0
for c in s:
	if a == b == 0:
		break
	elif c == '1':
		if b > 0 and a < max_a:
			b -= 1
			a += 1
		elif a > 0:
			a -= 1
		else:
			b -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	count += 1
print(count)


import os

def _f(n, b, a, arr):
	max_a = a
	for i in range(n):
		if a == 0 and b == 0:
			return i
		elif arr[i] == 1:
			if a == max_a:
				a -= 1
			elif b > 0:
				b -= 1
				a += 1
			else:
				a -= 1
		elif a > 0:
			a -= 1
		else:
			b -= 1
	return n

def f(n, b, a, arr):
	return _f(n, b, a, arr)
if os.environ.get('DEBUG', False):
	print(f'{f(5, 2, 1, [0, 1, 0, 1, 0])} = 5')
	print(f'{f(6, 2, 1, [1, 0, 0, 1, 0, 1])} = 3')
else:
	(n, b, a) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	print(f(n, b, a, arr))


gi = lambda : list(map(int, input().strip().split()))
(n, b, a) = gi()
l = gi()
(bb, aa) = (n, a)
for k in range(n):
	if b == aa == 0:
		print(k)
		exit()
	if l[k]:
		if aa == a or b == 0:
			aa -= 1
		else:
			b -= 1
			aa += 1
	elif aa:
		aa -= 1
	else:
		b -= 1
print(n)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
(cb, ca) = (b, a)
i = 0
while (cb or ca) and i < len(s):
	if s[i] == 1:
		if ca < a:
			if cb:
				cb -= 1
				ca += 1
			else:
				ca -= 1
		else:
			ca -= 1
	elif ca:
		ca -= 1
	else:
		cb -= 1
	i += 1
print(i)


import sys, math, queue
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
amax = a
for i in range(n):
	if b == 0 and a == 0:
		print(i)
		exit()
	if s[i] == 0:
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif a < amax and b > 0:
		a += 1
		b -= 1
	else:
		a -= 1
print(n)


import math
(n, b, a) = map(int, input().split())
arr = [int(p) for p in input().split()]
batt = b
acc = a
pos = 0
for i in range(n):
	pos = i + 1
	if acc == a:
		acc -= 1
	elif acc < a:
		if arr[i] == 1:
			if batt > 0:
				batt -= 1
				acc += 1
			elif batt == 0:
				if acc > 0:
					acc -= 1
				elif acc == 0:
					pos -= 1
					break
		elif arr[i] == 0:
			if acc > 0:
				acc -= 1
			elif acc == 0:
				if batt > 0:
					batt -= 1
				elif batt == 0:
					pos -= 1
					break
print(pos)


(n, a, b) = list(map(int, input().split()))
cur = b
l = list(map(int, input().split()))
for i in range(n):
	if i == n - 1:
		if b or a:
			print(n)
		else:
			print(i)
		exit()
	if b == 0 and a == 0:
		print(i)
		exit()
	if l[i] == 0:
		if b == 0:
			a -= 1
		else:
			b -= 1
	elif b != cur and a != 0:
		a -= 1
		b += 1
	else:
		b -= 1


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 read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	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.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

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

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	(n, b, a) = map(int, input().split())
	s = list(map(int, input().split()))
	i = 0
	am = a
	while i < n:
		if not a + b:
			break
		if s[i] == 1:
			if b and a != am:
				b -= 1
				a = min(a + 1, am)
			elif a:
				a -= 1
			else:
				b -= 1
		elif a:
			a -= 1
		else:
			b -= 1
		i += 1
	print(i)


import sys
from itertools import accumulate

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
(N, bt, ac) = MAP()
A = LIST()
mxac = ac
cnt = 0
for a in A:
	if a == 1:
		if bt > 0 and ac < mxac:
			bt -= 1
			ac += 1
		elif ac > 0:
			ac -= 1
		elif bt > 0:
			bt -= 1
		else:
			break
	elif ac > 0:
		ac -= 1
	elif bt > 0:
		bt -= 1
	else:
		break
	cnt += 1
print(cnt)


(n, b, a_max) = map(int, input().split())
seq = map(int, input().split())
a = a_max
pos = 0
for (i, sunlight) in enumerate(seq):
	if a == b == 0:
		break
	elif a == 0:
		if sunlight:
			a = min(a + 1, a_max)
		b -= 1
	elif b == 0:
		a -= 1
	elif sunlight and a < a_max:
		a = min(a + 1, a_max)
		b -= 1
	else:
		a -= 1
	pos += 1
print(pos)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
sys.setrecursionlimit(111111)
INF = 99999999999999999999999999999999

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		(n, b, a) = ria()
		s = ria()
		i = 0
		ha = a
		while (a > 0 or b > 0) and i < n:
			if s[i] == 1:
				if b > 0 and ha != a:
					b -= 1
					a += 1
				else:
					a -= 1
			elif a > 0:
				a -= 1
			else:
				b -= 1
			i += 1
		wi(i)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


(n, a, b) = map(int, input().split())
bin_ = list(map(int, input().split()))
counter = 0
(a_cur, b_cur) = (a, b)
for i in bin_:
	if i == 1:
		if b_cur == b or a_cur == 0:
			b_cur -= 1
		else:
			b_cur += 1
			a_cur -= 1
	if i == 0:
		if b_cur > 0:
			b_cur -= 1
		else:
			a_cur -= 1
	counter += 1
	if a_cur == 0 and b_cur == 0:
		break
print(counter)


(n, b, a) = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
an = 0
bb = b
aa = a
for i in range(n):
	if arr[i] == 0:
		if aa > 0:
			an += 1
			aa -= 1
		elif bb > 0:
			an += 1
			bb -= 1
		else:
			break
	elif bb > 0 and aa < a:
		bb -= 1
		aa = min(aa + 1, a)
		an += 1
	elif aa > 0:
		aa -= 1
		an += 1
	else:
		break
print(an)


(n, b, a) = list(map(int, input().split()))
maxi_a = a
path = list(map(int, input().split()))
c = 0
while (b > 0 or a > 0) and c < len(path):
	if path[c] == 1 and b > 0 and (a != maxi_a):
		a += 1
		b -= 1
	elif a > 0:
		a -= 1
	elif b > 0:
		b -= 1
	c += 1
print(c)


import sys
fin = sys.stdin.readline
(n, b, max_a) = [int(elem) for elem in fin().split()]
s_list = [int(elem) for elem in fin().split()]
assert len(s_list) == n
cur_pos = 0
a = max_a
while cur_pos < n and (a > 0 or b > 0):
	is_sunlight_available = s_list[cur_pos] == 1
	if not is_sunlight_available:
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif b > 0 and a < max_a:
		b -= 1
		a += 1
	else:
		a -= 1
	cur_pos += 1
print(cur_pos)


inp = lambda cast=int: list(map(cast, input().split()))
(n, batt, acc) = inp()
max_acc = acc
S = inp()
d = 0
for s in S:
	if batt == 0 and acc == 0:
		break
	if s == 1:
		if batt > 0 and acc < max_acc:
			batt -= 1
			acc += 1
		else:
			acc -= 1
	elif acc > 0:
		acc -= 1
	else:
		batt -= 1
	d += 1
print(d)


(n, b, a) = [int(x) for x in input().split()]
path = input().split()

def f(path, n, b, a):
	originala = a
	for i in range(n):
		if path[i] == '0':
			if a == 0:
				if b == 0:
					return i
				else:
					b -= 1
			else:
				a -= 1
		elif b > 0 and a < originala:
			b -= 1
			a += 1
		elif a == 0:
			if b > 0:
				b -= 1
			else:
				return i
		else:
			a -= 1
	return n
print(f(path, n, b, a))


xbn = [int(elem) for elem in input().split()]
s = [int(ggg) for ggg in input().split()]
bat = xbn[1]
akk = xbn[2]
BAT = xbn[1]
AKK = xbn[2]
road = 0
fin = 0
for i in range(xbn[0]):
	if s[i] == 1:
		if akk < AKK and bat > 0:
			bat -= 1
			akk += 1
			road += 1
		elif akk > 0:
			akk -= 1
			road += 1
		else:
			fin = road
			break
	elif akk > 0:
		akk -= 1
		road += 1
	elif bat > 0:
		road += 1
		bat -= 1
	else:
		break
print(road)


(n, b, a) = map(int, input().split())
(aa, bb) = (a, b)
w = False
c = list(map(int, input().split()))
for i in range(n):
	if c[i] == 1 and b > 0 and (a < aa):
		a += 1
		b -= 1
		continue
	if a > 0:
		a -= 1
		continue
	if b > 0:
		b -= 1
		continue
	print(i)
	w = True
	break
if not w:
	print(n)


nba = list(map(int, input().split()))
n = nba[0]
b = nba[1]
a = nba[2]
arr = input().split()
a_cap = a
result = 0
for i in range(len(arr)):
	if a == a_cap and a != 0:
		a -= 1
	elif arr[i] == '0':
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif b > 0:
		a += 1
		b -= 1
	else:
		a -= 1
	result += 1
	if a == 0 and b == 0:
		break
print(result)


(n, q, p) = map(int, input().split())
l = list(map(int, input().split()))
count = 0
i = 0
b = q
a = p
if p == 0:
	print(q)
	exit()
elif q == 0:
	print(p)
	exit()
while i < n:
	if l[i] == 1:
		if a < p and b > 0:
			b -= 1
			count += 1
			a += 1
		elif a == p and b > 0:
			a -= 1
			count += 1
		elif a > 0:
			a -= 1
			count += 1
		else:
			print(count)
			exit()
	elif a > 0:
		a -= 1
		count += 1
	elif b > 0:
		b -= 1
		count += 1
	else:
		print(count)
		exit()
	i += 1
print(min(count, n))


(n, b, a) = map(int, input().split())
maxa = a
Way = list(map(int, input().split()))
Way.reverse()
calc = 0
while Way and (b or a):
	if Way[-1] == 1 and b and (a != maxa):
		calc += 1
		Way.pop()
		b -= 1
		a += 1
	elif a:
		a -= 1
		calc += 1
		Way.pop()
	else:
		b -= 1
		calc += 1
		Way.pop()
print(calc)


(a, b, max_c) = map(int, input().strip().split())
s_ = map(int, input().strip().split())
c = max_c
passed = 0
for s in s_:
	if s == 0:
		if c > 0:
			c -= 1
			passed += 1
		elif b > 0:
			b -= 1
			passed += 1
		else:
			print(passed)
			exit(0)
	if s == 1:
		if c == max_c:
			if c > 0:
				c -= 1
				passed += 1
			elif b > 0:
				b -= 1
				passed += 1
			else:
				print(passed)
				exit(0)
		elif b > 0:
			b -= 1
			c += 1
			passed += 1
		elif c > 0:
			c -= 1
			passed += 1
		else:
			print(passed)
			exit(0)
print(passed)


from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from heapq import heappush, heappop
import math
import io
import os
import math
import bisect

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def digits(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def ceil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def mapin():
	return map(int, input().split())
(n, b, a) = mapin()
l = [int(x) for x in input().split()]
tt = a
for i in range(n):
	if l[i] == 0:
		if a == 0 and b == 0:
			print(i)
			exit()
		elif a == 0:
			b -= 1
		else:
			a -= 1
	elif a == 0 and b == 0:
		print(i)
		exit()
	elif b == 0 or a == tt:
		a -= 1
	else:
		b -= 1
		a += 1
		a = min(a, tt)
print(n)


(n, b, a) = map(int, input().split())
v = list(map(int, input().split()))
(battery, acc) = (b, a)
dist = 0
for i in v:
	if i == 1:
		if acc == a:
			acc -= 1
			dist += 1
		elif battery > 0:
			battery -= 1
			acc = min(acc + 1, a)
			dist += 1
		elif acc > 0:
			acc -= 1
			dist += 1
		else:
			break
	elif acc > 0:
		acc -= 1
		dist += 1
	elif battery > 0:
		battery -= 1
		dist += 1
	else:
		break
print(dist)


(n, b, a) = map(int, input().split())
lst = list(map(int, input().split()))
a1 = a
b1 = b
cnt = 0
for i in range(n):
	if lst[i] == 1:
		if b1 == 0:
			if a1 > 0:
				a1 -= 1
		elif a1 == a:
			a1 -= 1
		else:
			b1 -= 1
			a1 += 1
	elif a1 > 0:
		a1 -= 1
	else:
		b1 -= 1
	cnt += 1
	if b1 == 0 and a1 == 0:
		break
print(cnt)


(n, b, a) = (int(x) for x in input().split(' '))
s = [int(x) for x in input().split(' ')]
a_max = a
path_len = 0
for i in range(n):
	if b == 0:
		path_len += min(n - i, max(a, b))
		break
	if s[i] == 1:
		if a < a_max:
			a += 1
			b -= 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	path_len += 1
print(path_len)


(N, B, A) = list(map(int, input().split()))
maxA = A
S = [int(a) for a in input().split()]
for i in range(N):
	s = S[i]
	if A + B == 0:
		print(i)
		break
	elif s > 0 and A < maxA and (B > 0):
		B -= 1
		A += 1
	elif A > 0:
		A -= 1
	else:
		B -= 1
else:
	print(N)


(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
maxa = a
c = 0
ans = 0
for i in range(n):
	if a == 0 and b == 0:
		break
	elif a == 0:
		if l[i] == 1:
			a = min(a + 1, maxa)
		b -= 1
	elif b == 0:
		a = a - 1
	elif l[i] == 1 and a < maxa:
		a = min(a + 1, maxa)
		b -= 1
	else:
		a = a - 1
	ans += 1
print(ans)


(n, a, b) = map(int, input().split())
rd = list(map(int, input().split()))
na = a
nb = b
ans = 0
for i in range(n):
	if na == 0 and nb == 0:
		break
	if rd[i] == 1:
		if nb == b:
			nb -= 1
			ans += 1
		elif nb < b:
			if na > 0:
				na -= 1
				nb += 1
				ans += 1
			else:
				nb -= 1
				ans += 1
	elif rd[i] == 0:
		if nb > 0:
			nb -= 1
			ans += 1
		else:
			na -= 1
			ans += 1
print(ans)


(n, b, a) = map(int, input().split())
lt = [int(x) for x in input().split()]
c = a
i = 0
while i < n:
	if b == 0 and c == 0:
		break
	elif c == 0:
		b -= 1
		if lt[i] == 1:
			c = min(a, c + 1)
	elif b == 0:
		c -= 1
	elif lt[i] == 1 and c < a:
		b -= 1
		c = min(a, c + 1)
	else:
		c -= 1
	i += 1
print(i)


(n, b, a) = map(int, input().split())
s = [int(i) for i in input().split()]
m = a
cur = 0
while a + b and cur < n:
	if a:
		if not s[cur]:
			a -= 1
		elif a != m:
			if b:
				b -= 1
				a += 1
			else:
				a -= 1
		else:
			a -= 1
	else:
		b -= 1
		if s[cur]:
			a += 1
			a = min(a, m)
	cur += 1
print(cur)


(l, b, a) = list(map(int, input().split()))
hours = [i for i in input().split()]
distance = 0
c = 0
c = a
for i in range(l):
	if hours[i] == '0':
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	if hours[i] == '1':
		if b > 0 and a < c:
			a += 1
			b -= 1
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	distance += 1
print(distance)


nl = '\n'
import sys
input = sys.stdin.readline
print = sys.stdout.write
(n, b, a) = [int(x) for x in input().split()]
a0 = a
arr = [int(x) for x in input().split()]
c = 0
for i in range(n):
	if a == 0 == b:
		print(str(c))
		exit()
	if a == a0:
		a -= 1
		c += 1
		continue
	if arr[i] == 1 and b:
		a += 1
		b -= 1
	elif a:
		a -= 1
	else:
		b -= 1
	c += 1
print(str(c))


import math as mt
import collections as cc
import sys
I = lambda : list(map(int, input().split()))
(n, b, a) = I()
ab = b
aa = a
l = I()
st = 0
for i in range(n):
	if not aa and (not ab):
		break
	if l[i] == 1:
		if aa < a and ab:
			ab -= 1
			aa += 1
		else:
			aa -= 1
	elif aa:
		aa -= 1
	else:
		ab -= 1
	st += 1
print(st)


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	(n, mb, ma) = map(int, input().split())
	b = mb
	a = ma
	s = list(map(int, input().split()))
	i = 0
	while (a != 0 or b != 0) and i < n:
		if s[i] == 1:
			if a == ma:
				a -= 1
			elif b > 0:
				b -= 1
				a = min(a + 1, ma)
			elif a > 0:
				a -= 1
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		i += 1
	print(i)
main()


[d, b, a] = list(map(int, input().split(' ')))
s = input().split(' ')
m = a
cnt = 0
j = 0
while (b > 0 or a > 0) and cnt < int(d):
	if s[j] == '1' and b > 0 and (a < m):
		b -= 1
		a += 1
		cnt += 1
	elif a:
		a -= 1
		cnt += 1
	else:
		b -= 1
		cnt += 1
	j += 1
print(cnt)


(destination, battery, accumulatorCap) = map(int, input().split())
numbers = list(map(int, input().split()))
currentPoint = 0
accumulator = accumulatorCap
while True:
	if currentPoint == destination:
		break
	if numbers[currentPoint] == 0:
		if accumulator > 0:
			currentPoint += 1
			accumulator -= 1
		elif battery > 0:
			currentPoint += 1
			battery -= 1
		else:
			break
	elif accumulator < accumulatorCap and battery > 0:
		currentPoint += 1
		battery -= 1
		accumulator += 1
	elif accumulator > 0 and battery == 0:
		currentPoint += 1
		accumulator -= 1
	elif accumulator == accumulatorCap:
		currentPoint += 1
		accumulator -= 1
	elif battery == 0 and accumulator == 0:
		break
	else:
		print('WOW')
		break
print(currentPoint)


(n, b, a) = [int(i) for i in input().split(' ')]
steps = [int(i) for i in input().split(' ')]
maxA = a
counter = 0
for i in steps:
	if i == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif a != maxA and b > 0:
		b -= 1
		a += 1
	elif a == 0 and b > 0:
		b -= 1
	elif a == maxA:
		a -= 1
	elif b == 0 and a > 0:
		a -= 1
	else:
		break
	counter += 1
print(counter)


(length, maxbat, maxacc) = map(int, input().split())
l = list(map(int, input().split()))
acc = maxacc
bat = maxbat
res = 0
for i in range(0, len(l)):
	if acc != 0 or bat != 0:
		if acc == maxacc:
			acc -= 1
		else:
			if l[i] == 0 and acc != 0:
				acc -= 1
			elif l[i] == 0:
				bat -= 1
			if l[i] == 1 and bat != 0:
				bat -= 1
				acc += 1
				if acc > maxacc:
					acc = maxacc
			elif l[i] == 1:
				acc -= 1
		res += 1
	else:
		break
print(res)


(n, b, a) = map(int, input().split())
it = list(map(int, input().split()))
aa = a
st = False
for i in range(len(it)):
	if b == 0 and a == 0:
		st = True
		break
	if it[i] == 0 or a == aa:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			st = True
			break
		continue
	elif b > 0:
		b -= 1
		if a < aa:
			a += 1
		continue
	elif a > 0:
		a -= 1
		continue
	else:
		st = True
		break
if st:
	print(i)
else:
	print(n)


(n, b, a) = map(int, input().split())
max_a = a
dist = 0

def acc():
	global a
	global b
	global dist
	if a > 0:
		a -= 1
		dist += 1
	elif b > 0:
		b -= 1
		dist += 1
	else:
		print(dist)
		exit()

def bat():
	global a
	global b
	global dist
	global max_a
	if a == max_a:
		a -= 1
		dist += 1
	elif b > 0:
		b -= 1
		dist += 1
		a += 1
	elif a > 0:
		a -= 1
		dist += 1
	else:
		print(dist)
		exit()
s = list(map(int, input().split()))
acc()
for i in s[1:]:
	if i == 0:
		acc()
	else:
		bat()
print(n)


(n, b, a) = map(int, input().split())
mb = b
ma = a
m = list(map(int, input().split()))
k = 0
for i in range(n):
	if m[i] == 0:
		if a != 0:
			a -= 1
			k += 1
		elif b != 0:
			b -= 1
			k += 1
		else:
			break
	elif a == ma:
		a -= 1
		k += 1
	elif b != 0 and a != ma:
		b -= 1
		a += 1
		k += 1
	elif b == 0 and a != 0:
		a -= 1
		k += 1
	else:
		break
if k + a + b > n:
	print(n)
else:
	print(k + a + b)


(n, b, a) = list(map(int, input().split()))
segments = list(map(int, input().split()))
maxBat = b
maxAccum = a
answer = 0
currPtr = 0
while (b > 0 or a > 0) and currPtr < len(segments):
	if segments[currPtr] == 1:
		if b > 0 and a + 1 <= maxAccum:
			a += 1
			b -= 1
			currPtr += 1
			answer += 1
		else:
			a -= 1
			currPtr += 1
			answer += 1
	elif a > 0:
		a -= 1
		currPtr += 1
		answer += 1
	else:
		b -= 1
		currPtr += 1
		answer += 1
print(answer)


l = list(map(int, input().split()))
l1 = list(map(int, input().split()))
n = l[0]
b = l[1]
a = l[2]
a1 = a
count = 0
r = 0
for i in range(n):
	if l1[i] == 0 and a > 0:
		a -= 1
		count += 1
	elif (l1[i] == 0 and a == 0) and b > 0:
		b -= 1
		count += 1
	elif (l1[i] == 0 and a == 0) and b == 0:
		print(count)
		r += 1
		break
	elif (l1[i] == 1 and b > 0) and a != a1:
		b -= 1
		if a < a1:
			a += 1
		count += 1
	elif (l1[i] == 1 and b > 0) and a == a1:
		a -= 1
		count += 1
	elif (l1[i] == 1 and a > 0) and b == 0:
		a -= 1
		count += 1
	elif (l1[i] == 1 and a == 0) and b == 0:
		print(count)
		r += 1
		break
if r == 0:
	print(count)


(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
c = 0
i = 0
c1 = a
while i < n:
	if l[i] == 1:
		if b != 0:
			if c1 + 1 <= a:
				c1 += 1
				i += 1
				b -= 1
				c += 1
			else:
				c1 -= 1
				i += 1
				c += 1
		else:
			if c1 == 0:
				break
			if c + c1 <= n:
				c += c1
				break
			else:
				c = n
				break
	elif b == 0:
		if c1 == 0:
			break
		if c + c1 <= n:
			c += c1
			break
		else:
			c = n
			break
	elif c1 == 0:
		b -= 1
		i += 1
		c += 1
	else:
		c1 -= 1
		i += 1
		c += 1
print(c)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
rs = 0
tmp_a = a
nap = True
for i in s:
	nap = True
	if i == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
		rs += 1
	else:
		if b == 0 and a > 0 or a == tmp_a:
			a -= 1
			nap = False
		elif b > 0:
			b -= 1
		else:
			break
		if nap:
			a += 1
			a = min(tmp_a, a)
		rs += 1
print(rs)


List = list(map(int, input().split()))
List2 = list(map(int, input().split()))
bat = int(List[1])
acc = int(List[2])
ma = int(List[2])
days = 0
spot = 0
while spot < len(List2):
	if List2[spot] == 0:
		if acc > 0:
			acc -= 1
		elif bat > 0:
			bat -= 1
		else:
			break
	elif bat > 0 and acc != ma:
		acc = min(acc + 1, ma)
		bat -= 1
	elif acc == 0 and bat > 0:
		bat -= 1
	elif acc > 0:
		acc -= 1
	else:
		break
	days += 1
	spot += 1
print(days)


(n, b, a) = map(int, input().split())
s = input().split()
(ma, mb) = (a, b)
for i in range(n):
	if s[i] == '1':
		if ma == a:
			ma -= 1
		elif ma > 0 and mb == 0:
			ma -= 1
		else:
			mb -= 1
			ma += 1
	elif s[i] == '0':
		if ma != 0:
			ma -= 1
		elif mb != 0:
			mb -= 1
	if ma == mb == 0:
		print(i + 1)
		exit()
print(n)


(n, b, a) = map(int, input().split())
m = a
l = [*map(int, input().split())]
res = 0
for i in range(n):
	t = a and (l[i] == 0 or (l[i] and (a == m or b == 0)))
	if t:
		if a == 0:
			break
		a -= 1
	else:
		if b == 0:
			break
		b -= 1
		if l[i]:
			a = min(m, a + 1)
	res += 1
print(res)


def func(n, b, a, params):
	max_a = a
	res = 0
	for i in range(n):
		if a == 0 and b == 0:
			break
		s = params[i]
		if s == 1:
			if a == max_a:
				a -= 1
			elif a == max_a or b == 0:
				a -= 1
			else:
				b -= 1
				a = min(max_a, a + 1)
		elif a > 0:
			a -= 1
		else:
			b -= 1
		res += 1
	print(res)
(n, b, a) = list(map(int, input().split()))
params = list(map(int, input().split()))
func(n, b, a, params)


x = [int(a) for a in input().split()]
N = x[0]
B = x[1]
A = x[2]
Amax = A
s = [int(a) for a in input().split()]
maxi = 0
for i in range(N):
	if s[i] == 0:
		if A > 0:
			A -= 1
			maxi += 1
		elif B > 0:
			B -= 1
			maxi += 1
		else:
			break
	elif A == Amax or (B == 0 and 0 < A < Amax):
		A -= 1
		maxi += 1
	elif B > 0:
		B -= 1
		maxi += 1
		if 0 <= A < Amax:
			A += 1
	else:
		break
print(maxi)


from sys import stdin

def arr_inp(n):
	if n == 1:
		return [int(x) for x in stdin.readline().split()]
	elif n == 2:
		return [float(x) for x in stdin.readline().split()]
	else:
		return list(stdin.readline()[:-1])
(n, b, a) = arr_inp(1)
(arr, ans, a1) = (arr_inp(1), 0, a)
for i in range(n):
	if arr[i]:
		if b and a < a1:
			b -= 1
			ans += 1
			a += 1
		elif a:
			a -= 1
			ans += 1
		else:
			break
	elif a:
		a -= 1
		ans += 1
	elif b:
		ans += 1
		b -= 1
	else:
		break
print(ans)


from sys import stdin
(n, a, b) = map(int, stdin.readline().strip().split())
s = list(map(int, stdin.readline().strip().split()))
a1 = a
b1 = b
ans = 0
for i in range(n):
	if b1 == b:
		b1 -= 1
		ans += 1
	elif s[i] == 1 and a1 > 0:
		a1 -= 1
		b1 += 1
		ans += 1
	elif b1 > 0:
		b1 -= 1
		ans += 1
	else:
		a1 -= 1
		ans += 1
	if a1 == 0 and b1 == 0:
		break
print(ans)


import sys
import copy
sys.setrecursionlimit(1000000)
(n, b, a) = map(int, input().split())
s = [int(x) for x in input().split()]
A = a
for i in range(n):
	if s[i] == 0:
		if a > 0:
			a -= 1
			continue
		elif b > 0:
			b -= 1
			continue
		else:
			print(i)
			exit()
	if s[i] == 1:
		if a == A:
			a -= 1
			continue
		if b > 0:
			b -= 1
			a += 1
			continue
		elif a > 0:
			a -= 1
			continue
		else:
			print(i)
			exit()
print(n)


n = list(map(int, input().split()))
grid = n[0]
bat = n[1]
acc = n[2]
max_acc = acc + 0
g = list(map(int, input().split()))
ans = 0
for i in g:
	if i == 0:
		if acc >= 1:
			acc -= 1
			ans += 1
		elif bat >= 1:
			bat -= 1
			ans += 1
		else:
			break
	elif bat >= 1 and acc < max_acc:
		bat -= 1
		acc = min(max_acc, acc + 1)
		ans += 1
	elif acc >= 1:
		acc -= 1
		ans += 1
	else:
		break
print(ans)


def main():
	(n, b, a) = map(int, input().split())
	sunlight = list(map(int, input().split()))
	a_max = a
	dist = 0
	while (b > 0 or a > 0) and dist < n:
		sun = sunlight[dist]
		dist += 1
		if sun == 0:
			if a > 0:
				a -= 1
			else:
				b -= 1
		elif a == a_max:
			a -= 1
		elif b > 0:
			b -= 1
			a += 1
		else:
			a -= 1
	print(dist)
main()


(n, b, a) = input().split()
s = input().split()
s = [int(i) for i in s]
(n, b, a) = (int(n), int(b), int(a))
(minb, mina, ans) = (b, a, 0)
for i in s:
	if i == 1:
		if a == mina:
			a -= 1
		elif b != 0:
			b -= 1
			if a < mina:
				a += 1
		else:
			a -= 1
	elif a != 0:
		a -= 1
	else:
		b -= 1
	ans += 1
	if a == 0 and b == 0:
		break
print(ans)


(n, b, a) = map(int, input().split())
u = list(map(int, input().split()))
ans = 0
am = a
for i in range(n):
	if u[i] == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif a < am:
		if b > 0:
			b -= 1
			a += 1
		elif a > 0:
			a -= 1
		else:
			break
	elif a > 0:
		a -= 1
	elif b > 0:
		b -= 1
	else:
		break
	ans += 1
print(ans)


(n, b_max, a_max) = map(int, input().split(' '))
seg_max = 0
s = list(map(int, input().split(' ')))
battery = b_max
acc = a_max
for i in range(n):
	if s[i] == 1:
		if battery > 0 and acc < a_max:
			battery -= 1
			acc += 1
			seg_max += 1
		elif acc > 0:
			acc -= 1
			seg_max += 1
		else:
			break
	elif acc > 0:
		acc -= 1
		seg_max += 1
	elif battery > 0:
		battery -= 1
		seg_max += 1
	else:
		break
print(int(seg_max))


(n, b, a) = map(int, input().split())
akk = a
s = [int(i) for i in input().split()]
i = 0
while i < n:
	if s[i] == 0:
		if b == 0:
			if akk > 0:
				akk -= 1
			else:
				break
		elif akk > 0:
			akk -= 1
		else:
			b -= 1
	elif b == 0:
		if akk > 0:
			akk -= 1
		else:
			break
	elif akk == a:
		akk -= 1
	else:
		b -= 1
		akk += 1
	i += 1
print(i)


(n, b, a) = map(int, input().split())
arr = list(map(int, input().split()))
res = 0
a_ = a
for i in arr:
	if a == 0 and b == 0:
		break
	if i == 1 and b > 0 and (a < a_):
		b -= 1
		a = min(a_, a + 1)
		res += 1
	else:
		if a > 0:
			a -= 1
		else:
			b -= 1
		res += 1
print(res)


import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque, Counter
from math import gcd, sqrt, factorial, ceil, log10, log2
from itertools import permutations
from heapq import heappush, heappop, heapify
inf = float('inf')
mod = 1000000007

def factorial_p(n, p):
	ans = 1
	if n <= p // 2:
		for i in range(1, n + 1):
			ans = ans * i % p
	else:
		for i in range(1, p - n):
			ans = ans * i % p
		ans = pow(ans, p - 2, p)
		if n % 2 == 0:
			ans = p - ans
	return ans

def nCr_p(n, r, p):
	ans = 1
	while n != 0 or r != 0:
		(a, b) = (n % p, r % p)
		if a < b:
			return 0
		ans = ans * factorial_p(a, p) * pow(factorial_p(b, p), p - 2, p) * pow(factorial_p(a - b, p), p - 2, p) % p
		n //= p
		r //= p
	return ans

def prime_sieve(n):
	flag = n % 6 == 2
	sieve = bytearray((n // 3 + flag >> 3) + 1)
	for i in range(1, int(n ** 0.5) // 3 + 1):
		if not sieve[i >> 3] >> (i & 7) & 1:
			k = 3 * i + 1 | 1
			for j in range(k * k // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
			for j in range(k * (k - 2 * (i & 1) + 4) // 3, n // 3 + flag, 2 * k):
				sieve[j >> 3] |= 1 << (j & 7)
	return sieve

def prime_list(n):
	res = []
	if n > 1:
		res.append(2)
	if n > 2:
		res.append(3)
	if n > 4:
		sieve = prime_sieve(n + 1)
		res.extend((3 * i + 1 | 1 for i in range(1, (n + 1) // 3 + (n % 6 == 1)) if not sieve[i >> 3] >> (i & 7) & 1))
	return res

def binary(number):
	result = 0
	while number:
		result = result + 1
		number = number & number - 1
	return result

def is_prime(n):
	if n < 5 or n & 1 == 0 or n % 3 == 0:
		return 2 <= n <= 3
	s = (n - 1 & 1 - n).bit_length() - 1
	d = n >> s
	for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
		p = pow(a, d, n)
		if p == 1 or p == n - 1 or a % n == 0:
			continue
		for _ in range(s):
			p = p * p % n
			if p == n - 1:
				break
		else:
			return False
	return True

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

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

def input():
	return sys.stdin.readline().strip()
(n, b, a) = get_ints()
Arr = get_array()
maxi = a
total = 0
for i in range(n):
	if Arr[i] == 0:
		if a != 0:
			a -= 1
			total += 1
		elif b != 0:
			b -= 1
			total += 1
		else:
			break
	elif a == maxi:
		a -= 1
		total += 1
	elif b != 0:
		b -= 1
		if a < maxi:
			a += 1
		total += 1
	elif a != 0:
		a -= 1
		total += 1
	else:
		break
print(total)


(n, b, a) = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
flag = 0
ans = 0
(mb, ma) = (b, a)
for i in range(n):
	if arr[i] == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			ans = i
			flag = 1
			break
	elif a == ma and a > 0:
		a -= 1
	elif b > 0:
		b -= 1
		a = min(ma, a + 1)
	elif a > 0:
		a -= 1
	else:
		ans = i
		flag = 1
		break
if flag == 0:
	print(n)
else:
	print(ans)


(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
bt = b
ac = a
count = 0
for i in l:
	if i == 0 and ac > 0:
		ac -= 1
		count += 1
	elif i == 1 and ac == a:
		ac -= 1
		count += 1
	elif i == 1 and bt > 0:
		bt -= 1
		count += 1
		if ac < a:
			ac += 1
	elif ac == 0 and bt == 0:
		break
	elif i == 0 and ac == 0:
		bt -= 1
		count += 1
	elif i == 1 and bt == 0:
		ac -= 1
		count += 1
print(count)


import sys
import math

def main(args):
	(n, b, a) = map(int, input().split())
	ar = list(map(int, input().split()))
	res = 0
	max_a = a
	for x in ar:
		if x == 0:
			if a:
				(a, res) = (a - 1, res + 1)
			elif b:
				(b, res) = (b - 1, res + 1)
			else:
				break
		elif a and a == max_a:
			(a, res) = (a - 1, res + 1)
		elif b:
			(a, b, res) = (min(a + 1, max_a), b - 1, res + 1)
		elif a:
			(a, res) = (a - 1, res + 1)
		else:
			break
	print(res)
sys.exit(main(sys.argv))


(n, B, A) = map(int, input().split())
s = input().split()
(b, a) = (B, A)
complete = True
for (i, si) in enumerate(s):
	if b == 0 and a == 0:
		print(i)
		complete = False
	if si == '0':
		if a > 0:
			a -= 1
		else:
			b -= 1
	if si == '1':
		if a == A and a > 0 or b == 0:
			a -= 1
		elif b > 0:
			a += 1
			b -= 1
if complete:
	print(n)


(n, b, a) = map(int, input().split())
x = a
s = list(map(int, input().split()))
t = 0
for i in range(n):
	if s[i] == 1:
		if a < x and b > 0:
			b -= 1
			a += 1
			t += 1
		else:
			a -= 1
			t += 1
	elif a > 0:
		a -= 1
		t += 1
	elif b > 0:
		b -= 1
		t += 1
	if a == 0 and b == 0:
		break
print(t)


(n, b, a) = map(int, input().split())
A = list(map(int, input().split()))
m = a
ans = 0
for i in range(n):
	if A[i] == 1:
		if b > 0 and a < m:
			b -= 1
			a += 1
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif a > 0:
		a -= 1
	elif b > 0:
		b -= 1
	else:
		break
	ans = i + 1
print(ans)


(n, b, a) = map(int, input().split())
tempA = a + 1
ans = 0
sun = list(map(int, input().split()))[:n]
for i in range(n):
	if sun[i] == 1:
		if a == tempA - 1:
			a -= 1
			ans += 1
		elif b > 0:
			b -= 1
			a = (a + 1) % tempA
			ans += 1
		elif a > 0:
			a -= 1
			ans += 1
		else:
			break
	elif a > 0:
		ans += 1
		a -= 1
	elif b > 0:
		ans += 1
		b -= 1
	else:
		break
print(ans)


(n, b, a) = map(int, input().split())
a_init = a
s = list(map(int, input().split()))
for i in range(n):
	if b == 0 and a == 0:
		print(i)
		break
	elif a > 0 and s[i] == 0:
		a -= 1
	elif a == a_init:
		a -= 1
	elif b > 0 and s[i] == 1:
		a = min(a_init, a + 1)
		b -= 1
	elif b > 0:
		b -= 1
	else:
		a -= 1
else:
	print(n)


(n, b, a) = list(map(int, input().split()))
s = list(map(int, input().split()))
(cb, ca) = (b, a)
for (i, t) in enumerate(s):
	if t == 0:
		if ca > 0:
			ca -= 1
		elif cb > 0:
			cb -= 1
		else:
			print(i)
			import sys
			sys.exit(0)
	elif cb > 0 and ca < a:
		cb -= 1
		ca += 1
	elif ca > 0:
		ca -= 1
	elif cb > 0:
		cb -= 1
	else:
		print(i)
		import sys
		sys.exit(0)
print(len(s))


(n, b, a) = map(int, input().split())
l1 = list(map(int, input().split()))
maxa = a
dist = 0
x = 0
while (b != 0 or a != 0) and dist < n:
	if a == maxa:
		a -= 1
		x += 1
		dist += 1
	elif l1[x] == 0:
		if a > 0:
			dist += 1
			a -= 1
			x += 1
		else:
			x += 1
			dist += 1
			b -= 1
	elif b > 0:
		dist += 1
		b -= 1
		a += 1
		x += 1
	else:
		dist += 1
		a -= 1
		x += 1
print(dist)


(n, b, a) = list(map(int, input().split()))
arr = list(map(int, input().split()))
i = 0
a_now = a
flag = True
while flag and i < len(arr):
	while i < len(arr) and arr[i] == 0:
		if a_now > 0:
			a_now -= 1
		elif b > 0:
			b -= 1
		else:
			flag = False
			break
		i += 1
	while i < len(arr) and arr[i] == 1:
		if a_now < a and b > 0:
			b -= 1
			a_now += 1
		elif a_now > 0:
			a_now -= 1
		else:
			flag = False
			break
		i += 1
print(i)


MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, b, a) = f()
x = a
l = il()
for i in range(n):
	if a == 0 and b == 0:
		print(i)
		exit()
	if a == x:
		a -= 1
	elif l[i] == 1 and b > 0:
		b -= 1
		a += 1
	elif a > 0:
		a -= 1
	elif b > 0:
		b -= 1
print(n)


(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
a_max = a
i = 0
while not (b == 0 and a == 0 or i == n):
	if a == 0:
		b -= 1
		if l[i]:
			a = min(a_max, a + 1)
	elif b == 0:
		a -= 1
	elif a == a_max or not l[i]:
		a -= 1
	else:
		b -= 1
		if l[i]:
			a = min(a_max, a + 1)
	i += 1
print(i)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

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

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mm = 1000000007

def solve():
	t = 1
	for tt in range(t):
		(n, b, a) = num()
		x = li()
		xp = a
		cc = 0
		for i in range(n):
			if a == 0 and b == 0:
				break
			if x[i] == 1:
				if a == xp:
					a -= 1
					cc += 1
				else:
					if b > 0:
						b -= 1
						a += 1
					else:
						a -= 1
					cc += 1
			else:
				if a > 0:
					a -= 1
				else:
					b -= 1
				cc += 1
		print(cc)
solve()


(n, b, a) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
maxb = b
maxa = a
ans = 0
for i in range(n):
	if s[i] == 0:
		if a > 0:
			a -= 1
			ans += 1
		elif b > 0:
			b -= 1
			ans += 1
		else:
			break
	elif b > 0 and a != maxa:
		a += 1
		a = min(a, maxa)
		b -= 1
		ans += 1
	elif a > 0:
		a -= 1
		ans += 1
	else:
		break
print(ans)


array = [int(i) for i in input().split(' ')]
n = array[0]
b = array[1]
a = array[2]
capasity = a
array = [int(i) for i in input().split(' ')]
distanse = 0
for i in array:
	if i == 1:
		if b > 0:
			if a != capasity:
				b -= 1
				a += 1
				distanse += 1
			else:
				a -= 1
				distanse += 1
		elif a > 0:
			a -= 1
			distanse += 1
		else:
			break
	elif a > 0:
		a -= 1
		distanse += 1
	elif b > 0:
		b -= 1
		distanse += 1
	else:
		break
print(distanse)


import sys
(dest, battery, acc) = [int(x) for x in input().split()]
sun = [int(x) for x in input().split()]
c_acc = acc
for (i, s) in enumerate(sun):
	if s == 1:
		if battery > 0 and c_acc < acc:
			c_acc += 1
			battery -= 1
			continue
	if c_acc > 0:
		c_acc -= 1
	elif battery > 0:
		battery -= 1
	else:
		print(i)
		sys.exit()
print(dest)


def robot():
	(n, b, a) = map(int, input().split(' '))
	amax = a
	L = list(map(int, input().split(' ')))
	for i in range(n):
		if L[i]:
			if a == amax:
				a -= 1
			elif b > 0:
				b -= 1
				a += 1
			elif a > 0:
				a -= 1
			else:
				return i
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			return i
	return n
print(robot())


[n, b, a] = list(map(int, input().rstrip().split()))
s = list(map(int, input().rstrip().split()))
ina = a
i = 0
flag = True
while flag == True and i < n:
	if s[i] == 0:
		if a > 0:
			a -= 1
		else:
			b -= 1
	elif a < ina and b > 0:
		a += 1
		b -= 1
	else:
		a -= 1
	i += 1
	if a == 0 and b == 0:
		flag = False
print(i)


def mp():
	return map(int, input().split())
(n, bb, aa) = mp()
s = list(mp())
a = aa
b = bb
i = 0
while i < n and (not (a < 0 or b < 0 or (a == 0 and b == 0))):
	if a == aa:
		a -= 1
	elif s[i] == 1 and b != 0:
		b -= 1
		a += 1
	elif s[i] == 1:
		a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	i += 1
print(i)


(n, b, a) = map(int, input().split())
z = a
li = list(map(int, input().split()))
ans = 0
for i in range(0, len(li)):
	if li[i] == 0:
		if a > 0:
			a = a - 1
			ans += 1
		elif b > 0:
			b = b - 1
			ans += 1
		else:
			break
	elif a == z:
		a = a - 1
		ans += 1
	elif b > 0:
		b = b - 1
		a += 1
		ans += 1
	elif b == 0 and a > 0:
		ans += 1
		a -= 1
	else:
		break
print(ans)


from collections import defaultdict
from sys import stdin
from bisect import bisect_left as bl, bisect_right as br, insort
import heapq
from collections import deque
import math
(n, b, a) = list(map(int, input().split()))
s = list(map(int, input().rstrip().split()))
count = 0
if a + b >= n:
	print(n)
	exit()
i = 1
initial = a
a -= 1
while i < n:
	if s[i] == 1:
		if b > 0 and a < initial:
			b -= 1
			a += 1
			i += 1
		elif a > 0:
			a -= 1
			i += 1
		else:
			break
	elif s[i] == 0:
		if a > 0:
			a -= 1
			i += 1
		elif b > 0:
			b -= 1
			i += 1
		else:
			break
print(i)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
ta = max(a, 1)
for i in range(len(s)):
	if s[i] == 1 and b > 0:
		if ta < a:
			b -= 1
			ta += 1
			continue
		if ta == a:
			ta -= 1
	elif ta > 0:
		ta -= 1
	elif b > 0:
		b -= 1
	if ta == 0 and b == 0:
		print(i + 1)
		exit(0)
print(n)


nba = input().split()
nba = list(map(int, nba))
n = nba[0]
b = nba[1]
a = nba[2]
arr = input().split()
arr = list(map(int, arr))
i = 0
for x in arr:
	if a == 0 and b == 0:
		break
	elif x == 1:
		if b != 0 and a != 0 or (b != 0 and a == 0):
			if a == nba[2]:
				a -= 1
				i += 1
			else:
				a += 1
				b -= 1
				i += 1
		else:
			a -= 1
			i += 1
	elif b != 0 and a != 0 or (b == 0 and a != 0):
		a -= 1
		i += 1
	else:
		b -= 1
		i += 1
print(i)


(s, b, a) = [int(i) for i in input().split()]
path = [int(i) for i in input().split()]
b1 = b
a1 = a
count = 0
for i in range(s):
	if path[i] == 1:
		if a1 != a and b1 != 0:
			b1 -= 1
			a1 += 1
			count += 1
		elif a1 != 0:
			a1 -= 1
			count += 1
		else:
			print(count)
			quit()
	elif path[i] == 0:
		if a1 != 0:
			a1 -= 1
			count += 1
		elif b1 != 0:
			b1 -= 1
			count += 1
		else:
			print(count)
			quit()
print(count)


(n, b, a) = map(int, input().split())
cap = a
s = list(map(int, input().split()))
res = 0
for x in s:
	if b == 0 and a == 0:
		break
	if x == 1:
		if b > 0 and a < cap:
			a += 1
			b -= 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	res += 1
print(res)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
from math import gcd
(n, b, ac) = ll()
s = list(ll())
t = ac
final = 0
for i in range(n):
	if s[i] == 1 and b:
		if ac != t:
			ac += 1
			b -= 1
		else:
			ac -= 1
	elif s[i] == 0 and ac:
		ac -= 1
	elif ac and (not b):
		final = min(ac + final, n)
		break
	elif b and (not ac):
		b -= 1
	else:
		break
	final += 1
print(final)


(N, B, A) = map(int, input().split())
S = [True if x == '1' else False for x in input().split()]
(b, a) = (B, A)
result = 0
for i in range(N):
	if a == 0 and b == 0:
		break
	elif a == 0:
		b -= 1
		if S[i]:
			a = min(a + 1, A)
	elif b == 0:
		a -= 1
	elif S[i] and a < A:
		b -= 1
		a += 1
	else:
		a -= 1
	result += 1
print(result)


(n, b, a) = map(int, input().split())
aa = [int(x) for x in input().split()]
a1 = a
ans = 0
for i in aa:
	if a + b == 0:
		break
	if i == 0:
		if a > 0:
			a -= 1
			ans += 1
		else:
			b -= 1
			ans += 1
	elif a == a1:
		a -= 1
		ans += 1
	elif b > 0:
		b -= 1
		a += 1
		ans += 1
	else:
		a -= 1
		ans += 1
print(ans)


(N, b, a) = map(int, input().split())
List = [int(x) for x in input().split()]
bat = b
acc = a
flag = 0
for i in range(N):
	if bat == 0 and acc == 0:
		flag = 1
		print(i)
		break
	if List[i]:
		if bat:
			if acc != a:
				bat -= 1
				acc += 1
			else:
				acc -= 1
		else:
			acc -= 1
	elif acc:
		acc -= 1
	else:
		bat -= 1
if not flag:
	print(N)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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 read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	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.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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

def solve():
	(n, b, a) = sep()
	(maxb, maxa) = (b, a)
	s = lis()
	curr = -1
	for i in range(n):
		if b == 0 and a == 0:
			break
		if s[i] == 1:
			if a == 0 or (b > 0 and a < maxa):
				b -= 1
				a += 1
			else:
				a -= 1
		elif a > 0:
			a -= 1
		else:
			b -= 1
		curr = i
	print(curr + 1)
testcase(1)


emon = input().split()
n = int(emon[0])
b = int(emon[1])
c = int(emon[2])
a = c
m = 0
emon1 = input().split()
for i in emon1:
	t = int(i)
	if t == 0:
		if c > 0:
			c -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif a == c:
		c -= 1
	elif b > 0:
		b -= 1
		c += 1
	elif c > 0:
		c -= 1
	else:
		break
	m += 1
print(m)


(n, b, a) = [int(i) for i in input().split()]
m = [int(i) for i in input().split()]
d = 0
max_a = a
for i in range(len(m)):
	if (m[i] == 1 and a < max_a) and b > 0:
		a += 1
		b -= 1
		d += 1
	elif a > 0:
		a -= 1
		d += 1
	elif b > 0:
		b -= 1
		d += 1
print(d)


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
mod = 10 ** 9 + 7
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

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

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)

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

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

def string_list():
	return list(input())

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

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

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	max_so_far = -sys.maxsize - 1
	max_ending_here = 0
	start = 0
	end = 0
	s = 0
	for i in range(0, size):
		max_ending_here += a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
			start = s
			end = i
		if max_ending_here < 0:
			max_ending_here = 0
			s = i + 1
	return (max_so_far, start, end)

def lis(arr):
	n = len(arr)
	lis = [1] * n
	for i in range(1, n):
		for j in range(0, i):
			if arr[i] >= arr[j] and lis[i] < lis[j] + 1:
				lis[i] = lis[j] + 1
	maximum = 0
	for i in range(n):
		maximum = max(maximum, lis[i])
	return maximum

def solve():
	(n, battery, s) = num_input()
	solar = s
	arr = list_input()
	ans = 0
	for i in arr:
		if i == 1:
			if solar < s:
				if battery > 0:
					ans += 1
					battery -= 1
					solar += 1
				elif solar > 0:
					ans += 1
					solar -= 1
				else:
					break
			else:
				ans += 1
				solar -= 1
		elif solar > 0:
			ans += 1
			solar -= 1
		elif battery > 0:
			ans += 1
			battery -= 1
		else:
			break
	print(ans)
t = 1
for _ in range(t):
	solve()


(n, b, a) = map(int, input().split())
ao = a
array = list(map(int, input().split()))
for i in range(n):
	if b == 0 and ao == 0:
		print(i)
		break
	if array[i] == 1 and b > 0 and (a > ao):
		ao += 1
		b -= 1
	elif ao:
		ao -= 1
	else:
		b -= 1
else:
	print(n)


(n, mb, ma) = map(int, input().split())
b = mb
a = ma
cl = list(map(int, input().split()))
for i in range(n):
	if cl[i] == 0:
		if a == 0 and b == 0:
			print(i)
			exit()
		elif a == 0:
			b -= 1
		elif b == 0:
			a -= 1
		else:
			a -= 1
	elif a == 0 and b == 0:
		print(i)
		exit()
	elif b == 0:
		a -= 1
	elif a == ma:
		a -= 1
	else:
		b -= 1
		a = min(ma, a + 1)
print(n)


def solve():
	(n, b, a) = map(int, input().split())
	S = [int(k) for k in input().split()]
	ans = 0
	curr_a = a
	curr_b = b
	for i in range(n):
		if curr_a == 0 and curr_b == 0:
			break
		if S[i] == 1:
			if curr_a < a and curr_b > 0:
				ans += 1
				curr_b -= 1
				curr_a += 1
				continue
			if curr_a > 0:
				curr_a -= 1
				ans += 1
				continue
			if curr_b > 0:
				curr_b -= 1
				ans += 1
		else:
			if curr_a > 0:
				ans += 1
				curr_a -= 1
				continue
			if curr_b > 0:
				ans += 1
				curr_b -= 1
	print(ans)
solve()


(n, b, a) = map(int, input().split())
A = list(map(int, input().split()))
a0 = a
ans = 0
for elem in A:
	if a + b == 0:
		break
	if elem == 0:
		if a > 0:
			a -= 1
			ans += 1
		else:
			b -= 1
			ans += 1
	elif a == a0:
		a -= 1
		ans += 1
	elif b > 0:
		b -= 1
		a += 1
		ans += 1
	else:
		a -= 1
		ans += 1
print(ans)


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

def robot(a, b, L):

	def use_acc(a):
		a -= 1
		return a

	def use_bat(a, b, light):
		b -= 1
		if light:
			a += 1
		return (a, b)
	amax = a
	step = 0
	for i in range(n):
		if a == 0 and b == 0:
			break
		elif a == 0:
			(a, b) = use_bat(a, b, L[i])
		elif b == 0:
			a = use_acc(a)
		elif L[i] == 1 and a < amax:
			(a, b) = use_bat(a, b, L[i])
		else:
			a = use_acc(a)
		step = i
	return step + 1
print(robot(a, b, L))


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
import re
pattern = '0+'
(n, b, a) = list(map(int, input().split()))
(cb, ca) = (int(b), int(a))
segs = list(map(int, input().split()))
pos = 0
while pos < len(segs):
	if segs[pos] == 0:
		if cb == 0 and ca == 0:
			break
		if cb == 0:
			ca -= 1
			pos += 1
		elif ca == 0:
			cb -= 1
			pos += 1
		else:
			ca -= 1
			pos += 1
	else:
		if cb == 0 and ca == 0:
			break
		if ca == 0:
			cb -= 1
			ca += 1
			pos += 1
		elif cb == 0:
			ca -= 1
			pos += 1
		elif ca != a:
			cb -= 1
			ca += 1
			pos += 1
		else:
			ca -= 1
			pos += 1
print(pos)


def main():
	(n, battery, accumulator) = map(int, input().split())
	accumulator_max = accumulator
	s = list(map(int, input().split()))
	result = 0
	for is_lit in s:
		if is_lit:
			if battery > 0 and accumulator < accumulator_max:
				battery -= 1
				accumulator += 1
			elif accumulator > 0:
				accumulator -= 1
			elif battery > 0:
				battery -= 1
			else:
				print(result)
				return
		elif accumulator > 0:
			accumulator -= 1
		elif battery > 0:
			battery -= 1
		else:
			print(result)
			return
		result += 1
	print(result)
main()


def main():
	(n, a, b) = (int(i) for i in input().split())
	ma = a
	mb = b
	S = [int(i) for i in input().split()]
	ans = 0
	for s in S:
		if s == 0 and b > 0:
			b -= 1
		elif s == 0 and b == 0 and (a > 0):
			a -= 1
		elif s == 1 and a > 0 and (b < mb):
			a -= 1
			b += 1
		elif s == 1 and b > 0:
			b -= 1
		elif s == 1 and b == 0 and (a > 0):
			a -= 1
		elif a == 0 and b == 0:
			break
		ans += 1
	print(ans)
main()


(n, b_, a_) = (int(i) for i in input().split())
s = [int(i) for i in input().split()]

def solve():
	(a, b) = (a_, b_)
	for i in range(n):
		if s[i] > 0:
			if b > 0:
				if a < a_:
					a += 1
					b -= 1
				else:
					a -= 1
			elif a > 0:
				a -= 1
			else:
				return i
		elif a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			return i
	return n
print(solve())


def compute(n, b, a, st):
	X = -1
	ma = a
	while b >= 0 and a >= 0 and (X < n):
		X = X + 1
		if X == n:
			break
		if st[X] == '1':
			if b > 0 and a + 1 <= ma:
				b = b - 1
				a = a + 1
			else:
				a = a - 1
		elif a > 0:
			a = a - 1
		else:
			b = b - 1
	return X

def main():
	(n, b, a) = input().split(' ')
	n = int(n)
	b = int(b)
	a = int(a)
	st = input().split(' ')
	print(compute(n, b, a, st))
main()


arr = input()
(N, B, A) = [int(x) for x in arr.split(' ')]
arr = input()
arr = [int(x) for x in arr.split(' ')]
cur_A = A
steps = 0
for i in range(len(arr)):
	num = arr[i]
	if cur_A == 0 and B == 0:
		break
	else:
		steps += 1
	if num == 0:
		if cur_A != 0:
			cur_A -= 1
		else:
			B -= 1
	elif cur_A == A or B == 0:
		cur_A -= 1
	else:
		B -= 1
		cur_A += 1
print(steps)


(dest, batterie, solaire) = map(int, input().split())
expo = list(map(int, input().split()))
maxCap = solaire
index = 0
for i in range(dest):
	if not batterie and (not solaire):
		break
	if solaire == maxCap:
		solaire -= 1
	elif expo[i] and batterie:
		batterie -= 1
		solaire = min(solaire + 1, maxCap)
	elif solaire:
		solaire -= 1
	else:
		batterie -= 1
	index += 1
print(index)


def find(l, b, a):
	x = a
	count = 0
	for i in range(len(l)):
		if l[i] == 0 and x != 0:
			x -= 1
			count += 1
		elif l[i] == 0 and x == 0 and (b != 0):
			b -= 1
			count += 1
		elif l[i] == 1 and b != 0:
			if x != a:
				x += 1
				b -= 1
				count += 1
			else:
				x -= 1
				count += 1
		elif l[i] == 1 and b == 0 and (x != 0):
			count += 1
			x -= 1
	return count
m = list(map(int, input().strip().split()))
l = list(map(int, input().strip().split()))
print(find(l, m[1], m[2]))


(n, b, a) = map(int, input().split())
s = input().split()
(c, maxa) = (0, a)
for x in s:
	if x == '0':
		if a > 0:
			a -= 1
			c += 1
		elif b > 0:
			b -= 1
			c += 1
		else:
			break
	elif a < maxa:
		if b > 0:
			b -= 1
			a += 1
			c += 1
		elif a > 0:
			a -= 1
			c += 1
		else:
			break
	elif a > 0:
		a -= 1
		c += 1
	elif b > 0:
		b -= 1
		c += 1
	else:
		break
print(c)


(target, battery, accum) = map(int, input().split())
a = list(map(int, input().split()))
lim = accum
for i in range(target):
	if battery + accum == 0:
		print(i)
		break
	if a[i] == 1:
		if battery > 0 and accum < lim:
			battery -= 1
			accum += 1
		else:
			accum -= 1
	elif accum > 0:
		accum -= 1
	else:
		battery -= 1
else:
	print(target)


import sys
import math
import collections
import bisect
import string

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

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

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	(n, battery, acc) = get_ints()
	arr = get_list()
	count = 0
	i = 0
	maxim_acc = acc
	while i < n:
		if arr[i] == 0:
			if acc > 0:
				acc -= 1
			else:
				battery -= 1
		elif maxim_acc == acc:
			acc -= 1
		elif battery > 0:
			battery -= 1
			acc += 1
		else:
			acc -= 1
		i += 1
		count += 1
		if acc == 0 and battery == 0:
			break
	print(count)


(n, baa, acc) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
bat = baa
ac = acc
ind = n
for i in range(len(a)):
	if a[i] == 1 and ac == acc:
		ac -= 1
	elif a[i] == 1 and ac != acc and (bat > 0):
		bat -= 1
		ac += 1
	elif a[i] == 1 and ac != acc and (bat == 0):
		ac -= 1
	elif a[i] == 0 and ac > 0:
		ac -= 1
	elif a[i] == 0 and bat > 0:
		bat -= 1
	if bat == 0 and ac == 0:
		ind = i + 1
		break
print(ind)


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
(n, b, a) = viread()
path = viread()
max_a = a
ans = 0
while a > 0 or b > 0:
	if n == ans:
		break
	if path[ans] == 1:
		if a == max_a:
			a -= 1
		elif b > 0:
			b -= 1
			if a < max_a:
				a += 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	ans += 1
print(ans)


(n, b, a) = map(int, input().split())
l = list(map(int, input().split()))
bat = b
acc = a
for i in range(n):
	if l[i] == 1:
		if acc == a:
			acc -= 1
		elif bat == 0:
			acc -= 1
		else:
			bat -= 1
			acc += 1
	elif acc == 0:
		bat -= 1
	else:
		acc -= 1
	if acc == 0 and bat == 0:
		break
print(i + 1)


(n, b, a) = map(int, input().split())
maxa = a
maxb = b
l = list(map(int, input().split()))
seg = 0
for i in range(n):
	if l[i] == 0:
		if a > 0:
			a -= 1
			seg += 1
		elif b > 0:
			b -= 1
			seg += 1
		else:
			break
	elif b > 0:
		if a == maxa:
			a -= 1
		else:
			b -= 1
			a += 1
		seg += 1
	elif a > 0:
		a -= 1
		seg += 1
	else:
		break
print(seg)


(n, B, A) = map(int, input().split())
b = B
a = A
path = map(int, input().split())
ans = 0
for (i, s) in enumerate(path):
	if s == 0:
		if a > 0:
			a -= 1
		elif b > 0:
			b -= 1
		else:
			break
	elif a == A:
		a -= 1
	elif b > 0:
		b -= 1
		a += 1
	elif a > 0:
		a -= 1
	else:
		break
	ans += 1
print(ans)


(N, bat, ac) = [int(x) for x in input().split()]
sk = [int(x) for x in input().split()]
prad = ac
for i in range(N):
	if sk[i]:
		if ac == prad:
			ac -= 1
		elif bat:
			bat -= 1
			ac = min(prad, ac + 1)
		else:
			ac -= 1
	elif ac:
		ac -= 1
	else:
		bat -= 1
	if not bat and (not ac):
		print(i + 1)
		exit()
print(N)


def input_one(f=int):
	return f(input().strip())

def input_row(f=int):
	return list(map(f, input_one(str).split()))
(n, b, a) = input_row()
MAX_A = a
x = input_row()
for i in range(n):
	if x[i] == 1 and a != MAX_A:
		if b == 0:
			a -= 1
		else:
			b -= 1
			a = min(a + 1, MAX_A)
	elif a == 0:
		b -= 1
	else:
		a -= 1
	if a < 0 or b < 0:
		break
else:
	i += 1
print(i)


(n, b, a) = map(int, input().split())
amax = a
s = [int(s) for s in input().split()]
pos = 0
while pos < n:
	if a == 0 and b == 0:
		break
	if s[pos] == 0:
		if a > 0:
			a -= 1
			pos += 1
		elif b > 0:
			b -= 1
			pos += 1
	elif s[pos] == 1:
		if a == amax:
			a -= 1
			pos += 1
		elif b > 0:
			b -= 1
			if a < amax:
				a += 1
			pos += 1
		elif a > 0:
			a -= 1
			pos += 1
print(pos)


def main(argc, argv) -> {}:
	sync_with_stdio(false)
	cin.tie(0)
	cout.tie(0)
	n = B = A = 0
	n <<= cin
	B <<= cin
	A <<= cin
	S = vector << int >> n
	S <<= cin
	a = A
	b = B
	i = 0
	while i < len(S) and (b > 0 or a > 0) or {}:
		if S[i] == 1 and b > 0 and (a < A) or {}:
			b -= 1
			a += 1
			{}
		elif a > 0 or {}:
			a -= 1
			{}
		else:
			b -= 1
			{}
		i += 1
		{}
	cout << i << endl
	{}
import base64
exec(base64.decodebytes('cHkyID0gcm91bmQoMC41KQoKaWYgcHkyOgogICAgZnJvbSBmdXR1cmVfYnVpbHRpbnMgaW1wb3J0IGFzY2lpLCBmaWx0ZXIsIGhleCwgbWFwLCBvY3QsIHppcAogICAgcmFuZ2UgPSB4cmFuZ2UKCmRlZiBzeW5jX3dpdGhfc3RkaW8oYik6CiAgICBpZiBiOiByZXR1cm4KICAgIGltcG9ydCBvcywgc3lzCiAgICBmcm9tIGlvIGltcG9ydCBCeXRlc0lPLCBJT0Jhc2UKICAgIAogICAgIyBGYXN0SU8gZm9yIFB5UHkyIGFuZCBQeVB5MyAod29ya3Mgd2l0aCBpbnRlcmFjdGl2ZSkgYnkgUGFqZW5lZ29kCiAgICBjbGFzcyBGYXN0SShvYmplY3QpOgogICAgICAgIGRlZiBfX2luaXRfXyhzZWxmLCBmZD0wLCBidWZmZXJzaXplPTIqKjE0KToKICAgICAgICAgICAgc2VsZi5zdHJlYW0gPSBzdHJlYW0gPSBCeXRlc0lPKCk7IHNlbGYuYnVmZW5kbCA9IDAKICAgICAgICAgICAgZGVmIHJlYWQyYnVmZmVyKCk6CiAgICAgICAgICAgICAgICBzID0gb3MucmVhZChmZCwgYnVmZmVyc2l6ZSArIG9zLmZzdGF0KGZkKS5zdF9zaXplKTsgcG9zID0gc3RyZWFtLnRlbGwoKQogICAgICAgICAgICAgICAgc3RyZWFtLnNlZWsoMCwyKTsgc3RyZWFtLndyaXRlKHMpOyBzdHJlYW0uc2Vlayhwb3MpOyByZXR1cm4gcwogICAgICAgICAgICBzZWxmLnJlYWQyYnVmZmVyID0gcmVhZDJidWZmZXIKICAgICAgICAjIFJlYWQgZW50aXJlIGlucHV0CiAgICAgICAgZGVmIHJlYWQoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYucmVhZDJidWZmZXIoKTogcGFzcwogICAgICAgICAgICByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZCgpIGlmIHNlbGYuc3RyZWFtLnRlbGwoKSBlbHNlIHNlbGYuc3RyZWFtLmdldHZhbHVlKCkKICAgICAgICBkZWYgcmVhZGxpbmUoc2VsZik6CiAgICAgICAgICAgIHdoaWxlIHNlbGYuYnVmZW5kbCA9PSAwOiBzID0gc2VsZi5yZWFkMmJ1ZmZlcigpOyBzZWxmLmJ1ZmVuZGwgKz0gcy5jb3VudChiIlxuIikgKyAobm90IHMpCiAgICAgICAgICAgIHNlbGYuYnVmZW5kbCAtPSAxOyByZXR1cm4gc2VsZi5zdHJlYW0ucmVhZGxpbmUoKQogICAgICAgIGRlZiBpbnB1dChzZWxmKTogcmV0dXJuIHNlbGYucmVhZGxpbmUoKS5yc3RyaXAoYidcclxuJykKICAgICAgICAKICAgICAgICAjIFJlYWQgYWxsIHJlbWFpbmluZyBpbnRlZ2VycywgdHlwZSBpcyBnaXZlbiBieSBvcHRpb25hbCBhcmd1bWVudAogICAgICAgIGRlZiByZWFkbnVtYmVycyhzZWxmLCB6ZXJvPTApOgogICAgICAgICAgICBjb252ID0gb3JkIGlmIHB5MiBlbHNlIGxhbWJkYSB4OngKICAgICAgICAgICAgQSA9IFtdOyBudW1iID0gemVybzsgc2lnbiA9IDE7IGMgPSBiIi0iWzBdCiAgICAgICAgICAgIGZvciBjIGluIHNlbGYucmVhZCgpOgogICAgICAgICAgICAgICAgaWYgYyA+PSBiIjAiWzBdOiBudW1iID0gMTAgKiBudW1iICsgY29udihjKSAtIDQ4CiAgICAgICAgICAgICAgICBlbGlmIGMgPT0gYiItIlswXTogc2lnbiA9IC0xCiAgICAgICAgICAgICAgICBlbGlmIGMgIT0gYiJcciJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYik7IG51bWIgPSB6ZXJvOyBzaWduID0gMQogICAgICAgICAgICBpZiBjID49IGIiMCJbMF06IEEuYXBwZW5kKHNpZ24qbnVtYikKICAgICAgICAgICAgcmV0dXJuIEEKICAgIAogICAgY2xhc3MgRmFzdE8oSU9CYXNlKToKICAgICAgICBkZWYgX19pbml0X18oc2VsZiwgZmQ9MSk6CiAgICAgICAgICAgIHN0cmVhbSA9IEJ5dGVzSU8oKQogICAgICAgICAgICBzZWxmLmZsdXNoID0gbGFtYmRhOiBvcy53cml0ZSgxLCBzdHJlYW0uZ2V0dmFsdWUoKSkgYW5kIG5vdCBzdHJlYW0udHJ1bmNhdGUoMCkgYW5kIHN0cmVhbS5zZWVrKDApCiAgICAgICAgICAgIHNlbGYud3JpdGUgPSBzdHJlYW0ud3JpdGUgaWYgcHkyIGVsc2UgbGFtYmRhIHM6IHN0cmVhbS53cml0ZShzLmVuY29kZSgpKQogICAgCiAgICBzeXMuc3RkaW4sIHN5cy5zdGRvdXQgPSBGYXN0SSgpLCBGYXN0TygpCiAgICBnbG9iYWwgaW5wdXQKICAgIGlucHV0ID0gc3lzLnN0ZGluLmlucHV0CgoKaW1wb3J0IHN5cwoKY2xhc3Mgb3N0cmVhbToKICAgIGRlZiBfX2xzaGlmdF9fKHNlbGYsYSk6CiAgICAgICAgaWYgYSA9PSBlbmRsOgogICAgICAgICAgICBzeXMuc3Rkb3V0LndyaXRlKCJcbiIpCiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHN5cy5zdGRvdXQud3JpdGUoc3RyKGEpKQogICAgICAgIHJldHVybiBzZWxmCiAgICBkZWYgdGllKHNlbGYsIHZhbCk6cGFzcwpjb3V0ID0gb3N0cmVhbSgpCmVuZGwgPSBvYmplY3QoKQoKY2xhc3MgaXN0cmVhbToKICAgIHRpZWR0byA9IGNvdXQKICAgIGlucCA9IE5vbmUKICAgIGRlZiBfX3Jsc2hpZnRfXyhhLGIpOgogICAgICAgIGlmIGEudGllZHRvID09IGNvdXQ6CiAgICAgICAgICAgIHN5cy5zdGRvdXQuZmx1c2goKQogICAgICAgIGlmIHR5cGUoYik9PXR1cGxlIG9yIHR5cGUoYik9PWxpc3Q6CiAgICAgICAgICAgIHJldHVybiB0eXBlKGIpKHR5cGUoYykoYS5nZXQoKSkgZm9yIGMgaW4gYikKICAgICAgICByZXR1cm4gdHlwZShiKShhLmdldCgpKQogICAgZGVmIHRpZShzZWxmLCB2YWwpOgogICAgICAgIHNlbGYudGllZHRvID0gdmFsCiAgICBkZWYgZ2V0KGEpOgogICAgICAgIHdoaWxlIG5vdCBhLmlucDoKICAgICAgICAgICAgYS5pbnAgPSBzeXMuc3RkaW4ucmVhZGxpbmUoKS5zcGxpdCgpWzo6LTFdCiAgICAgICAgcmV0dXJuIGEuaW5wLnBvcCgpCmNpbiA9IGlzdHJlYW0oKQoKY2xhc3MgVmVjdG9yOgogICAgZGVmIF9fbHNoaWZ0X18oc2VsZiwgb3RoZXIpOgogICAgICAgIHNlbGYudHlwZSA9IG90aGVyCiAgICAgICAgcmV0dXJuIHNlbGYKICAgIGRlZiBfX3JzaGlmdF9fKHNlbGYsIG90aGVyKToKICAgICAgICBpZiB0eXBlKG90aGVyKSA9PSB0dXBsZToKICAgICAgICAgICAgcmV0dXJuIFtzZWxmLnR5cGUob3RoZXJbMV0pXSpvdGhlclswXQogICAgICAgIGVsc2U6CiAgICAgICAgICAgIHJldHVybiBbc2VsZi50eXBlKCldKm90aGVyCnZlY3RvciA9IFZlY3RvcigpCg=='.encode()))
true = True
false = False
main(len(sys.argv), sys.argv)


import sys

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

def print(*x, sep=' ', end='\n'):
	return sys.stdout.write(sep.join(map(str, x)) + end)

def read():
	return sys.stdin.read()

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

def out(*arg):
	if type(arg[0]) == list:
		for i in arg[0]:
			print(i)
	else:
		print(arg)

def main():
	(n, b, a) = get()
	start = a
	path = [int(i) for i in input().split()]
	flag = False
	for i in range(n):
		if path[i] == 1 and a == start:
			a -= 1
		elif path[i] == 1 and b != 0:
			b -= 1
			a = min(a + 1, start)
		elif path[i] == 1 and b == 0:
			a -= 1
		elif path[i] == 0 and a != 0:
			a -= 1
		elif path[i] == 0 and a == 0:
			b -= 1
		if b == 0 and a == 0:
			print(i + 1)
			flag = True
			break
	if not flag:
		print(n)
main()


(n, b, acapacity) = map(int, input().split())
a = acapacity
sunlights = [0 for i in range(n)]
sunlights[0:n] = map(int, input().split())
seg = 0
for sunlight in sunlights:
	if b == 0 and a == 0:
		break
	elif sunlight == 0:
		if b == 0:
			a -= 1
			seg += 1
		elif a == 0:
			b -= 1
			seg += 1
		else:
			a -= 1
			seg += 1
	elif b == 0:
		a -= 1
		seg += 1
	elif a == acapacity:
		a -= 1
		seg += 1
	else:
		b -= 1
		a += 1
		seg += 1
print(seg)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
ma = a
x = 0
while (b > 0 or a > 0) and x < len(s):
	if s[x]:
		if b > 0 and (a == 0 or a != ma):
			a += 1
			a = min(ma, a)
			b -= 1
		else:
			a -= 1
	elif a > 0:
		a -= 1
	else:
		b -= 1
	x += 1
print(x)


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

def rdi():
	return int(input())
(n, b, a) = rlist()
max_a = a
line = rlist()
sun = [[line[0], 1]]
for i in range(1, len(line)):
	if line[i] == sun[-1][0]:
		sun[-1][1] += 1
	else:
		sun.append([line[i], 1])
otr = 0
dist = 0
for ss in sun:
	(s, d) = ss
	if s == 0:
		g = min(a, d)
		dist += g
		d -= g
		a -= g
		g = min(b, d)
		dist += g
		d -= g
		b -= g
	else:
		g = min(b, max_a - a, d)
		dist += g
		d -= g
		b -= g
		a += g
		g = min(d // 2, b)
		dist += g * 2
		d -= g * 2
		b -= g
		g = min(d, a)
		dist += g
		d -= g
		a -= g
	if a == 0 and b == 0:
		break
print(dist)


(n, b, a) = (int(i) for i in input().split())
track = [int(i) for i in input().split()]
max_charge = a
for (i, v) in enumerate(track):
	if v == 0:
		if a > 0:
			a -= 1
			continue
		elif b > 0:
			b -= 1
			continue
		else:
			break
	elif v == 1:
		if a == max_charge:
			a -= 1
			continue
		elif b > 0:
			b -= 1
			a += 1 if a < max_charge else 0
			continue
		elif a > 0:
			a -= 1
			continue
		else:
			break
else:
	print(n)
	quit()
print(i)


(n, b, a) = map(int, input().split())
m = a
for (i, s) in enumerate(input().split()):
	if s == '1':
		if a == m:
			a -= 1
		elif b:
			b -= 1
			a += 1
		elif a:
			a -= 1
		else:
			print(i)
			break
	elif a:
		a -= 1
	elif b:
		b -= 1
	else:
		print(i)
		break
else:
	print(n)


(n, b, a) = list(map(int, input().split()))
expo = list(map(int, input().split()))
initial_a = a
for i in range(n):
	if a == 0 and b == 0:
		print(i)
		exit()
	elif b == 0:
		a -= 1
	elif a == initial_a:
		a -= 1
	elif expo[i] == 0 and a:
		a -= 1
	elif expo[i] == 1 and b:
		a += 1
		b -= 1
	else:
		b -= 1
print(n)


(n, b, a) = map(int, input().split())
s = list(map(int, input().split()))
max_a = a
res = 0
for i in range(n):
	if a == 0 and b == 0:
		break
	if not (b > 0 and s[i] and (a < max_a)) and a != 0:
		a -= 1
	else:
		b -= 1
		if s[i] and a < max_a:
			a += 1
	res += 1
print(res)


(n, b, a) = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
ln = 0
max_a = a
for i in arr:
	if a == 0 and b == 0:
		break
	elif a == 0:
		if i == 1:
			a = min(a + 1, max_a)
		b -= 1
	elif b == 0:
		a -= 1
	elif i == 1 and a < max_a:
		a += 1
		b -= 1
	else:
		a -= 1
	ln += 1
print(ln)