//GIVE ME AC!!!!!!!!!!!!!!!!! #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #define ll long long #define floatset() fixed<; void insert(set> &st, int v) { auto t = st.lower_bound({v-1,2}); if (t != st.end() && t->first == v-1) t = st.erase(t); else st.insert({v,1}); if (t != st.end() && t->first == v+1) st.erase(t); else st.insert({v,2}); } // mexを計算 int mex(set> &st) { auto t = st.lower_bound({0,-1}); if (t->first != 0) return 0; else { t++; return t->first + 1; } } int main(){ ll n; cin>>n; ll a[n]; rep(i,0,n){ cin>>a[i]; } ll ans=0; rep(i,0,n){ set>s; rep(j,i,n){ insert(s,a[j]); ans+=mex(s); } } cout<