Under construction

Still being built. Things may change

Dynamic Array

Interview

Time limit1sMemory limit1024 MB

Summary
Simulate store and delete commands on a dynamic array that doubles when full, then print its final maximum size.
Level

Easy2 of 10

Topics
Implementation, Simulation, Array
Solved
No attempts yet

Problem

Do you know about dynamic arrays? If not, you have probably declared arrays with a fixed size. You may have run into a case where the array was too small and the judge returned an unwanted result. A dynamic array grows automatically when its declared size is not enough. The following explains how this works.

A dynamic array operates as follows.

  1. Create a dynamic array with any initial size you want. The dynamic array starts empty.
  2. When you need to store an element but the dynamic array is full, declare a new dynamic array whose size is 22 times the current size.
  3. Copy all elements of the existing dynamic array to the front of the new 22-times-size array. Then delete the existing array and replace it with the new one. Store the element from step 2 after the copied elements.

To do this, a dynamic array manages two variables. SS is the current maximum size, and UU is the number of slots currently in use.

Given the initial size of a dynamic array and a series of store or delete commands, print the maximum size of the array after all commands are processed.

Input

The first line contains three integers S_0S\_0, NN, and MM, separated by spaces. S_0S\_0 is the initial maximum size, NN is the number of store commands, and MM is the number of delete commands. (1≤S_0≤10,  1≤N≤100 000,  0≤M≤N)(1 \le S\_0 \le 10, \; 1 \le N \le 100\,000, \; 0 \le M \le N)

From the second line through line N+M+1N + M + 1, each line contains either 1 or 0. 1 stores an element in the array. 0 deletes an element from the end of the array.

A delete command is never given when the dynamic array has no elements.

Output

Print the maximum size of the dynamic array after all commands are processed.

Hint

A well-known example of a dynamic array is the vector in C++.

Examples1

  1. Example 1

    Input
    1 5 1
    1
    1
    1
    1
    0
    1
    
    Expected output
    4