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: introductory

Starter code:

Solutions:
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
	else:
		if a == a0:
			a -= 1
			ans += 1
		elif b > 0:
			b -= 1
			a += 1
			ans += 1
		else:
			a -= 1
			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
        else:
            if A:
                A -= 1
            else:
                B -= 1
    return 0

main()

IN = input
rint = lambda: int(IN())
rmint = lambda: list(map(int, IN().split()))
rlist = lambda: list(rmint())

n, b, a = rmint()
y = a
x = b
d = 0


def ex():
    print(d)
    return


for s in rlist():
    if s:
        if x and y < a:
            y += 1
            x -= 1
        else:
            if y:
                y -= 1
            else:
                if x:
                    x -= 1
                else:
                    ex()
    else:
        if y:
            y -= 1
        else:
            if x:
                x -= 1
            else:
                ex()
    d += 1

print(d)





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:
            # if accum is full
            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, A = list(map(int, input().split()))
maxA = A
S = [int(a) for a in input().split()]

for i in range(N):
    # print(B, A)
    s = S[i]
    if A + B == 0:
        print(i)
        break
    else:
        if s > 0 and A < maxA and B > 0:
            B -= 1
            A += 1
        elif A > 0:
            A -= 1
        else:
            B -= 1
else:
    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)
        return
    if S[i] == 1:
        if b > 0 and a < aa:
            b -= 1
            a += 1
        else:
            a -= 1
    else:
        if a > 0:
            a -= 1
        else:
            b -= 1
print(n)

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

	else:
		if 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, 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)


n,a,b=list(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
        else :
            if a>0 :
                a-=1
                ans+=1
            else :
                break
    else :
        if mab==b :
            b-=1
            ans+=1
        else :
            if a>0 :
                a-=1
                b+=1
                ans+=1
            else :
                if b>0 :
                    ans+=1
                    b-=1
                else :
                    break
print(ans)


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):
    #print(bn,an)
    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,b,a = list(map(int,input().split()))
si = list(map(int,input().split()))
a2 = a
ans = n
for i in range(n):
    if b != 0:
        if a2 == a:
            a2 -= 1
        else:
            if a2 != 0:
                if si[i] == 1:
                    b -= 1
                    a2 += 1
                else:
                    a2 -= 1
            else:
                b -= 1
                if si[i] == 1:
                    a2 += 1
    else:
        if a2 == 0:
            ans = i
            break
        a2 -= 1
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
    else:
        if 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 = list(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
	else:
		
		if 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 = 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
		else:
			if b > 0:
				b -= 1
				a = min(aa, a + 1)
			else:
				a -= 1
	if i == n - 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

	else:

		if ca:

			ca -= 1

		else:

			cb -= 1

	i += 1

print(i)

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
    else :
        if b>0:
            dist+=1
            b-=1
            a+=1
            x+=1
        else :
            dist+=1
            a-=1
            x+=1
print(dist)

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):
    # print(b, a, sun)
    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
    else:
        if a == max_a:
            a -= 1
        else:
            if sun:
                a += 1
                b -= 1
            else:
                if max_a - a < rem[i]:
                    a -= 1
                else:
                    b -= 1

    ans += 1

print(ans)


''' CODED WITH LOVE BY SATYAM KUMAR '''

from sys import stdin, stdout
import cProfile, math
from collections import Counter,defaultdict
from bisect import bisect_left,bisect,bisect_right
import itertools
from copy import deepcopy
from fractions import Fraction
import sys, threading
import operator as op
from functools import reduce
sys.setrecursionlimit(10**6) # max depth of recursion
threading.stack_size(2**27)  # new thread will get stack of such size
fac_warmup = False
printHeap = str()
memory_constrained = False
P = 10**9+7
import sys

class merge_find:
    def __init__(self,n):
        self.parent = list(range(n))
        self.size = [1]*n
        self.num_sets = n
        self.lista = [[_] for _ in range(n)]
    def find(self,a):
        to_update = []
        while a != self.parent[a]:
            to_update.append(a)
            a = self.parent[a]
        for b in to_update:
            self.parent[b] = a
        return self.parent[a]
    def merge(self,a,b):
        a = self.find(a)
        b = self.find(b)
        if a==b:
            return
        if self.size[a]<self.size[b]:
            a,b = b,a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self.size[b]
        self.lista[a] += self.lista[b]
    def set_size(self, a):
        return self.size[self.find(a)]
    def __len__(self):
        return self.num_sets

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

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

def fibonacci_modP(n,MOD):
    if n<2: return 1
    #print (n,MOD)
    return (cached_fn(fibonacci_modP, (n+1)//2, MOD)*cached_fn(fibonacci_modP, n//2, MOD) + cached_fn(fibonacci_modP, (n-1) // 2, MOD)*cached_fn(fibonacci_modP, (n-2) // 2, MOD)) % MOD

def factorial_modP_Wilson(n , p): 
    if (p <= n): 
        return 0
    res = (p - 1) 
    for i in range (n + 1, p): 
        res = (res * cached_fn(InverseEuler,i, p)) % p 
    return res 

def binary(n,digits = 20):
    b = bin(n)[2:]
    b = '0'*(20-len(b))+b
    return b

def isprime(n):
    """Returns True if n is prime."""
    if n < 4:
        return True
    if n % 2 == 0:
        return False
    if n % 3 == 0:
        return False
    i = 5
    w = 2
    while i * i <= n:
        if n % i == 0:
            return False
        i += w
        w = 6 - w
    return True
factorial_modP = []
def warm_up_fac(MOD):
    nonlocal factorial_modP,fac_warmup
    if fac_warmup: return
    factorial_modP= [1 for _ in range(fac_warmup_size+1)]
    for i in range(2,fac_warmup_size):
        factorial_modP[i]= (factorial_modP[i-1]*i) % MOD
    fac_warmup = True

def InverseEuler(n,MOD):
    return pow(n,MOD-2,MOD)

def nCr(n, r, MOD):
    nonlocal fac_warmup,factorial_modP
    if not fac_warmup:
        warm_up_fac(MOD)
        fac_warmup = True
    return (factorial_modP[n]*((pow(factorial_modP[r], MOD-2, MOD) * pow(factorial_modP[n-r], MOD-2, MOD)) % MOD)) % MOD

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

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

def display_2D_list(li):
    for i in li:
        print(i)
def prefix_sum(li):
    sm = 0
    res = []
    for i in li:
        sm+=i
        res.append(sm)
    return res

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

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

def get_list():
    return list(map(int, stdin.readline().split()))
import heapq,itertools
pq = []                         # list of entries arranged in a heap
entry_finder = {}               # mapping of tasks to entries
REMOVED = '<removed-task>' 
def add_task(task, priority=0):
    'Add a new task or update the priority of an existing task'
    if task in entry_finder:
        remove_task(task)
    count = next(counter)
    entry = [priority, count, task]
    entry_finder[task] = entry
    heapq.heappush(pq, entry)

def remove_task(task):
    'Mark an existing task as REMOVED.  Raise KeyError if not found.'
    entry = entry_finder.pop(task)
    entry[-1] = REMOVED

def pop_task():
    'Remove and return the lowest priority task. Raise KeyError if empty.'
    while pq:
        priority, count, task = heapq.heappop(pq)
        if task is not REMOVED:
            del entry_finder[task]
            return task
    raise KeyError('pop from an empty priority queue')
memory = dict()
def clear_cache():
    nonlocal memory
    memory = dict()
def cached_fn(fn, *args):
    nonlocal memory
    if args in memory:
        return memory[args]
    else:
        result = fn(*args)
        memory[args] = result
        return result

def ncr (n,r):
    return math.factorial(n)/(math.factorial(n-r)*math.factorial(r))
def binary_serach(i,li):
    #print("Search for ",i)
    fn = lambda x: li[x]-x//i
    x = -1
    b = len(li)
    while b>=1:
        #print(b,x)
        while b+x<len(li) and fn(b+x)>0: #Change this condition 2 to whatever you like
            x+=b
        b=b//2
    return x

# -------------------------------------------------------------- MAIN PROGRAM
TestCases = False
testingMode = False
fac_warmup_size = 10**5+100
optimiseForReccursion = True #Can not be used clubbed with TestCases # WHen using recursive functions, use Python 3
from math import factorial


def main():
    n,b,a = get_tuple()
    b_fuel, a_fuel = b,a
    li = get_list()
    for i,ele in enumerate(li):
        if a_fuel==0 and b_fuel==0:
            print(i)
            return
        if (ele==1):
            if b_fuel>0 and a_fuel<a:
                b_fuel-=1
                a_fuel+=1
            elif (b_fuel>0 and a_fuel==a) or b_fuel==0:
                a_fuel-=1
            else:
                b_fuel-=1
        else:
            if a_fuel>0:
                a_fuel-=1
            else: b_fuel-=1

    print(n)


    


# --------------------------------------------------------------------- END=


if TestCases: 
    for i in range(get_int()): 
        cProfile.run('main()') if testingMode else main(i) 
else: (cProfile.run('main()') if testingMode else main()) if not optimiseForReccursion else threading.Thread(target=main).start()

n,b,a=list(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)
		else:
			if(val2==0):
				ans=i
				break
			else:
				val2-=1
		
	else:
		if(val2==0):
			if(val>0):
				val-=1
			else:
				ans=i
				break
		else:
			val2-=1
if(ans==-1):
	print(n)
else:
	print(ans)











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)
    else:
        if charge:
            charge -= 1
        elif b:
            b -= 1
        else:
            print(ans)
            raise SystemExit(0)
print(ans + 1)


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
        else:
            if ca > 0:
                ca -= 1
            else:
                cb -= 1
        p += 1
    
    print(p)

main()

import collections

def solve():
    n,b,a=list(map(int,input().split()))
    a_max=a
    S=list(map(int,input().split()))
    ans=0
    for i in range(n):
        #print(i,b,a)
        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
        else:
            if a>0:
                a-=1
            elif b>0:
                b-=1
            else:
                return i
    return n

print(solve())


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
    else:
        if(b>0 and a<a_max and element==1):
            b-=1
            a+=1
        else:
            if(a>0):
                a-=1
            else:
                b-=1
    cur_len+=1
print(cur_len)

    


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
    else:
        if a1 > 0:
            a1 -= 1
            dist += 1
        elif b1 > 0:
            b1 -= 1
            dist += 1
        else:
            break
print(dist)


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