Link:
Solution:
$O(n^4)$……
Code:
#include <bits/stdc++.h> using namespace std; int n,pre[25],tot=0,res=0; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) { int x;scanf("%d",&x); pre[i]=pre[i-1]+x;tot+=x; } for(int a=1;a<=n-3;a++) for(int b=a+1;b<=n-2;b++) for(int c=b+1;c<=n-1;c++) for(int d=c+1;d<=n;d++) if(pre[b]-pre[a]==pre[d]-pre[c] && tot-(pre[d]-pre[a])==pre[c]-pre[b]) res++; printf("%d",res); return 0; }