Problem: A scientist Arthur C. McDonell is conducting a very complex chemical experiment. This experiment requires a large number of very simple operations to pour water into every column of the vessel at the predetermined ratio. Tired of boring manual work, he was trying to automate the operation.

One day, he came upon the idea to use three-pronged tubes to divide the water flow. For example, when you want to pour water into two columns at the ratio of 1 : 1, you can use one three-pronged tube to split one source into two.

<image>

He wanted to apply this idea to split water from only one faucet to the experiment vessel at an arbitrary ratio, but it has gradually turned out to be impossible to set the configuration in general, due to the limitations coming from the following conditions:

1. The vessel he is using has several columns aligned horizontally, and each column has its specific capacity. He cannot rearrange the order of the columns.
2. There are enough number of glass tubes, rubber tubes and three-pronged tubes. A three-pronged tube always divides the water flow at the ratio of 1 : 1.
3. Also there are enough number of fater faucets in his laboratory, but they are in the same height.
4. A three-pronged tube cannot be used to combine two water flows. Moreover, each flow of water going out of the tubes must be poured into exactly one of the columns; he cannot discard water to the sewage, nor pour water into one column from two or more tubes.
<image>
5. The water flows only downward. So he cannot place the tubes over the faucets, nor under the exit of another tubes. Moreover, the tubes cannot be crossed.

<image>

Still, Arthur did not want to give up. Although one-to-many division at an arbitrary ratio is impossible, he decided to minimize the number of faucets used. He asked you for a help to write a program to calculate the minimum number of faucets required to pour water into the vessel, for the number of columns and the ratio at which each column is going to be filled.



Input

The input consists of an integer sequence.

The first integer indicates N, the number of columns in the vessel. Then the following N integers describe the capacity by which each column should be filled. The i-th integer in this part specifies the ratio at which he is going to pour water into the i-th column.

You may assume that N ≤ 100, and for all i, vi ≤ 1000000.

Output

Output the number of the minimum faucet required to complete the operation.

Example

Input




Output

Solution (in CPP):

Solution:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <sstream>
#include <bitset>
using namespace std;
#define MP(a, b) make_pair(a, b)
#define VT vector
#define FI first
#define SE second
#define FOR(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 1; i <= n; ++i)
typedef long long ll;
typedef unsigned long long ull;

bool can[110][110];

int a[110];
int dp[110];
int sum[110][110];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]), can[i][i] = 1, sum[i][i] = a[i];

    for (int l = 2; l <= n; l++) {
        for (int i = 1; i + l - 1 <= n; i++) {
            for (int j = i; j < i + l; j++) {
                sum[i][i+l-1] = sum[i][j] + sum[j+1][i+l-1];
                if (sum[i][j] == sum[j+1][i+l-1])
                    can[i][i+l-1] = can[i][j] & can[j+1][i+l-1];
                // printf("can[%d][%d] = %d\n", i, i + l - 1, can[i][i+l-1]);
            }
        }
    }

    dp[0] = 0;
    for (int i = 1; i <= n; i++) {
        dp[i] = 1000;
        for (int j = 0; j < i; j++) {
            if (can[j+1][i]) {
                dp[i] = min(dp[i], dp[j] + 1);
            }
        }
    }
    printf("%d\n", dp[n]);



    return 0;
}