#include <bits/stdc++.h>   using namespace std;   int a[1000010];   int solution[1000010] = {0};   int main() {     ios::sync_with_stdio(0);     int n;     long long int sum = 0;     long long int part;     long long partSum = 0;     long long int result = 0;     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> a[i];       sum += a[i];     }     if (sum % 3)       cout <<  0 ;     else {       part = sum / 3;       for (int i = 0; i < n; ++i) {         partSum += a[i];         if (partSum == part) solution[i] = 1;       }       for (int i = 0; i < n - 2; i++) solution[i + 1] += solution[i];       partSum = 0;       for (int i = n - 1; i - 2 >= 0; --i) {         partSum += a[i];         if (partSum == part) result += solution[i - 2];       }       cout << result;     }     return 0;   }   