public static void main(String... args) throws IOException {
        MyScanner sc = new MyScanner();
        int n = sc.nextInt();
        int[] t = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
        }

        long sum = 0;
        Pair[] sortedSums = new Pair[n];
        long[] sums = new long[n];
        for (int i = 0; i < n; i++) {
            sum += t[i];
            sortedSums[i] = new Pair(sum, i);
            sums[i] = sum;
        }

        Arrays.sort(sortedSums, (p1, p2)
                -> ((p1.sum == p2.sum) ? p1.indx - p2.indx : ((p1.sum < p2.sum) ? -1 : 1)));

        long sol = 0;
        for (int i = n - 1; i >= 1; i--) {
            long thidSum = sums[n - 1] - sums[i - 1];
            if (sums[i - 1] - thidSum == thidSum) {
                int firstInd = findFirstSum(sortedSums, thidSum, i);
                if (firstInd != -1) {
                    int findLasInd = findLastSum(sortedSums, thidSum, i);
                    sol += findLasInd - firstInd + 1;
                }
            }
        }

        System.out.println(sol);
    }