fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n; cin >> n;
  6. vector<int> arr(n);
  7. int tot_sum = 0;
  8. for(int i = 0; i < n; i++){
  9. int temp;
  10. cin >> temp;
  11. tot_sum += temp;
  12. arr[i] = temp;
  13. }
  14. if(tot_sum % 4 != 0)
  15. return 0;
  16.  
  17. int y = tot_sum/4;
  18. int county = 0;
  19. int count2y = 0;
  20. int ans = 0;
  21.  
  22. int pre_sum = 0;
  23. for(int i = 0; i < n-1; i++){
  24. pre_sum += arr[i];
  25. if(pre_sum == 3*y)
  26. ans += count2y;
  27. if(pre_sum == 2*y)
  28. count2y += county;
  29. if(pre_sum == y)
  30. county++;
  31. }
  32. cout << ans;
  33. return 0;
  34. }
Success #stdin #stdout 0s 5316KB
stdin
5
0 0 0 0 0
stdout
4