#include #define rep(i,n) for (int i = 0; i < (n); i++) #define per(i,n) for (int i = (n)-1; i>=0; i--) using namespace std; using ll = long long; using P = pair; vector jp; int getjp(int i){ if(jp[i]==i) return i; else return jp[i]=getjp(jp[i]); } int main(){ int n; cin>>n; vector a(n); rep(i, n) cin>>a[i]; jp = vector(n+2); ll tot=0; per(l, n){ for(int i=1; i<=n+1; i++) jp[i]=i; for(int r=l; r