#include #if __has_include() #endif using namespace std; #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define RDVL(T,n,...) vec__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);lin(__VA_ARGS__) #define VL(n,...) RDVL(ll,n,__VA_ARGS__) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range(0,__VA_ARGS__);ivoid pp(const auto&...a){[[maybe_unused]]const char*c="";((o<(a...);} #define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{ namespace my{ void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} void lin(auto&...a){(cin>>...>>a);} constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;} templateconstexpr ll maxsize10(){return size10(numeric_limits::max());} bool amax(auto&a,const auto&b){return a>{a...});} templatestruct infinity{ templatestatic constexpr T ones(size_t n){return n?ones(n-1)*10+1:0;} templateconstexpr operator T()const{static constexpr T v=ones(maxsize10())*(1-is_negative*2);return v;} }; constexpr infinity oo; templateusing pack_back_t=tuple_element_t>; } namespace my{ template>struct multiset:std::multiset{ multiset()=default; ll size()const{return std::multiset::size();} void erase_unique(const T&x){if(auto p=this->find(x);p!=this->end())this->erase(p);} T front()const{assert(size());return*this->begin();} T back()const{assert(size());return*prev(this->end());} }; } namespace my{ templateistream&operator>>(istream&i,vector&v){fe(v,e)i>>e;return i;} templateconstexpr int depth=0; templatestruct core_t_helper{using type=T;}; templateusing core_t=core_t_helper::type; templatestruct vec; templatestruct hvec_helper{using type=vec::type>;}; templatestruct hvec_helper<0,T>{using type=T;}; templateusing hvec=hvec_helper::type; templatestruct vec:vector{ static constexpr int D=depth+1; using C=core_t; using vector::vector; void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else{ }} static auto make(ll n,const auto&...a){ if constexpr(sizeof...(a)==1)return vec(n,array{a...}[0]); else { } } template>auto sort(F f={})const{vec v=*this;ranges::sort(v,f);return v;} }; templaterequires(sizeof...(A)>=2)vec(const A&...a)->vec>>; auto pack_vec(const auto&...a){return vec>{a...};} } namespace my{ void sort(auto&...a){auto v=pack_vec(a...).sort();ll i=0;((a=v[i++]),...);} } namespace my{ struct shakutori{ static auto maximal_interval_enumerate(ll n,auto del_l,auto add_r,auto check_r){ vecres(n); for(ll l=0,r=0;lst; auto del_l=[&](ll l,ll r){st.erase_unique(a[l]);}; // 今見ている区間が[l,r)で,lを消す時の処理 auto add_r=[&](ll l,ll r){st.emplace(a[r]);}; // 今見ている区間が[l,r)で,rを加える時の処理 auto check=[&](ll l,ll r){ // 今見ている区間が[l,r)で,rを加えても真になるか判定 if(r-l==0)return true; ll M=st.back(),m0=st.front(),m1=(r-l>=2?*next(st.begin()):oo); ll t=a[r]; amax(M,t); sort(m0,m1,t); return M<=m0+m1; }; auto v=shakutori::maximal_interval_enumerate(N,del_l,add_r,check); ll ans=0; fo(l,N)ans+=max(v[l]-l-1,0); pp(ans); }}