PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000132. Robot chạy bằng năng lượng mặt trời (Walking Robot)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Robot chạy bằng năng lượng mặt trời (Walking Robot)

Walking Robot

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A robot starts at position 00 and wants to traverse nn unit segments. Its battery initially holds bb units and its solar accumulator initially holds aa units (both full). Every segment consumes one unit from exactly one source. When using the battery on a sunny segment si=1s_i=1, the accumulator recharges by one up to its capacity. Find the maximum number of traversable segments.

Input

The first line contains n,b,an,b,a. The next line contains nn binary values sis_i.

Output

Print the maximum number of segments traversed.

Subtasks

  • Subtask 1 (20 points): 1≤n,b,a≤201\le n,b,a\le 20; si∈{0,1}s_i\in\{0,1\} for all ii.
  • Subtask 2 (30 points): 1≤n,b,a≤12001\le n,b,a\le 1200; si∈{0,1}s_i\in\{0,1\} for all ii.
  • Subtask 3 (50 points): 1≤n,b,a≤2000001\le n,b,a\le 200000; si∈{0,1}s_i\in\{0,1\} for all ii.

Examples

Input

5 2 1
0 1 0 1 0

Output

5

Explanation

Use accumulator on segment 11, battery on sunny segment 22 to recharge it, accumulator on 33, battery on sunny 44 to recharge, and accumulator on 55. All five segments are traversed.