Under construction

Still being built. Things may change

Interval Addition

Time limit4sMemory limit2048 MB

Summary
Given an array of up to 23 values, find the fewest operations that add a real number to a contiguous interval to make every element zero.
Level

Medium7 of 10

Topics
Bit manipulation, Dynamic programming, Prefix sum
Solved
No attempts yet

Problem

You are given an array aa of nn integers. You can perform operations on this array. In a single operation, you can add any real number xx to some consecutive interval of aa.

Determine the minimum number of operations that have to be performed to make all elements of aa equal to 00.

Input

The first line contains an integer nn (1≤n≤231 \leq n \leq 23).

The second line contains the array a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9).

Output

Print a line with a single integer: the minimum number of operations needed.

Examples2

  1. Example 1

    Input
    5
    1 2 3 2 1
    
    Expected output
    3
    
  2. Example 2

    Input
    6
    1 1 4 5 1 4
    
    Expected output
    4