#C4264. Dynamic Array Capacity Adjustment

    ID: 47783 Type: Default 1000ms 256MiB

Dynamic Array Capacity Adjustment

Dynamic Array Capacity Adjustment

You are given a sequence of operations performed on a dynamic array. The dynamic array starts with a capacity of 1 and no elements. Each operation is represented by an integer: (1) for an insertion and (-1) for a deletion. When an insertion is executed and the array is full, its capacity is doubled (i.e., (current_size \to 2 \times current_size) when (num_elements = current_size)). Conversely, after a deletion, if the number of elements becomes less than or equal to (\frac{current_size}{4}) and the current size is greater than 1, the capacity is halved (but never below 1), expressed as (current_size \to \max\left(\frac{current_size}{2},1\right)). Your task is to simulate this process and determine the final capacity of the dynamic array.

inputFormat

The input is read from stdin. The first line contains an integer (q), the number of operations. The second line contains (q) space-separated integers representing the operations, each of which is either (1) (insertion) or (-1) (deletion).

outputFormat

Print a single integer representing the final capacity of the dynamic array to stdout after processing all operations.## sample

5
1 1 1 -1 -1
2

</p>