struct A{ __int128_t d; ll x; }; vector s[3]; s[0].push_back({0,0}); s[1].push_back({0,0}); ll@n; rrep(h,n){ ll@a[3]; vector t[3]; rep(i,3){ vector u; __int128_t w=0; rep(j,3){ if(i!=j){ for(auto b:s[j]){ ll x=b.x+a[i]; __int128_t d=b.d+x; u.push_back({d,x=x==0?0:x-1}); w=max(w,d+__int128_t(x+x-h+1)*h/2); } } } for(auto b:u){ long y=min(b.x,h); if(b.d+__int128_t(b.x*2-y+1)*y/2>=w){ t[i].push_back(b); } } } rep(i,3){ s[i]=t[i]; } } __int128_t z=0; rep(i,3){ for(auto b:s[i]){ z=max(z,b.d); } } if(z>=10d18){ printf("%lld%018lld",(ll)(z/1d18),(ll)(z%1d18)); }else{ printf("%lld",(ll)z); }