There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself.

Vasya has an account in each bank. Its balance may be negative, meaning Vasya owes some money to this bank.

There is only one type of operations available: transfer some amount of money from any bank to account in any neighbouring bank. There are no restrictions on the size of the sum being transferred or balance requirements to perform this operation.

Vasya doesn't like to deal with large numbers, so he asks you to determine the minimum number of operations required to change the balance of each bank account to zero. It's guaranteed, that this is possible to achieve, that is, the total balance of Vasya in all banks is equal to zero.

Input

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of banks.

The second line contains n integers ai ( - 109 ≤ ai ≤ 109), the i-th of them is equal to the initial balance of the account in the i-th bank. It's guaranteed that the sum of all ai is equal to 0.

Output

Print the minimum number of operations required to change balance in each bank to zero.

Examples

Input

3
5 0 -5


Output

1


Input

4
-1 0 1 0


Output

2


Input

4
1 2 3 -6


Output

3

Note

In the first sample, Vasya may transfer 5 from the first bank to the third.

In the second sample, Vasya may first transfer 1 from the third bank to the second, and then 1 from the second to the first.

In the third sample, the following sequence provides the optimal answer: 

  1. transfer 1 from the first bank to the second bank; 
  2. transfer 3 from the second bank to the third; 
  3. transfer 6 from the third bank to the fourth. 
/*-
 * Codeforces problem :
 * http://codeforces.com/problemset/problem/675/C
 *
 * Find the minimum number of money transfer between neighboring 
 * banks required to bring all account balances to 0.
 */

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author Karthik Venkataraman
 * @email kafy83@gmail.com
 */
public class MoneyTransfers {

    class InputReader {

        private static final int inputkb = 4 * 1024;
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), inputkb);
        }

        private String readNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    throw new IllegalStateException(ex);
                }
            }
            return tokenizer.nextToken();
        }

        private int nextInt() {
            return Integer.parseInt(readNext());
        }

        private long nextLong() {
            return Long.parseLong(readNext());
        }
    }

    class RbTree {

        private static final boolean RED = true;
        private static final boolean BLACK = false;
        private Node root;

        class Node {

            private Long key;
            private Integer value;
            private Node left, right;
            private boolean color;

            Node(Long key, Integer value, boolean color) {
                this.key = key;
                this.value = value;
                this.color = color;
            }
        }

        private Integer get(Long key) {
            Node x = get(root, key);
            if (x == null) {
                return null;
            }
            return x.value;
        }

        private Node get(Node x, Long key) {
            if (x == null) {
                return null;
            }
            int cmp = (key > x.key) ? 1 : key < x.key ? -1 : 0;
            if (cmp < 0) {
                return get(x.left, key);
            } else if (cmp > 0) {
                return get(x.right, key);
            } else {
                return x;
            }
        }

        private void put(Long key) {
            root = put(root, key);
            root.color = BLACK;
        }

        private boolean isRed(Node x) {
            if (x == null) {
                return false;
            }
            return x.color;
        }

        private Node rotateLeft(Node h) {
            Node x = h.right;
            h.right = x.left;
            x.left = h;
            x.color = h.color;
            h.color = RED;
            return x;
        }

        private Node rotateRight(Node h) {
            Node x = h.left;
            h.left = x.right;
            x.right = h;
            x.color = h.color;
            h.color = RED;
            return x;
        }

        private void flipColors(Node h) {
            h.color = !h.color;
            h.left.color = !h.left.color;
            h.right.color = !h.right.color;
        }

        private Node put(Node x, Long key) {
            if (x == null) {
                return new Node(key, 1, RED);
            }
            int cmp = (key > x.key) ? 1 : key < x.key ? -1 : 0;
            if (cmp < 0) {
                x.left = put(x.left, key);
            } else if (cmp > 0) {
                x.right = put(x.right, key);
            } else {
                x.value++;
            }

            if (isRed(x.right) && !isRed(x.left)) {
                x = rotateLeft(x);
            }
            if (isRed(x.left) && isRed(x.left.left)) {
                x = rotateRight(x);
            }
            if (isRed(x.left) && isRed(x.right)) {
                flipColors(x);
            }
            return x;
        }
    }

    private int n;
    private int output;

    private void compute() {
        InputReader sc = new InputReader(System.in);
        RbTree rb = new RbTree();
        n = sc.nextInt();
        output = n - 1;
        long cum = 0;
        for (int i = 0; i < n; i++) {
            cum += sc.nextInt();
            rb.put(cum);
            output = Math.min(output, n - rb.get(cum));
        }
        System.out.println(output);
    }

    public static void main(String[] args) {
        MoneyTransfers m = new MoneyTransfers();
        m.compute();
    }
}
