#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 int main(){ int N; cin>>N; vector a(N); rep(i,N)cin>>a[i]; vector dp(N,0); dp.back() = N-1; for(int i=N-2;i>=0;i--){ if(a[i+1]!=a[i]){ dp[i] = dp[i+1]; } else{ dp[i] = i+1; } } long long ans= 0; rep(i,N){ if(a[i]==0)continue; ans += dp[i] - i; } cout<