#include #include #include #include #include using namespace std; using i32 = int; using u32 = unsigned int; using i64 = long long; using u64 = unsigned long long; #define rep(i,n) for(int i=0; i<(int)(n); i++) const i64 INF = 1001001001001001001; using Modint = atcoder::static_modint<998244353>; struct LiCiaoTree { int N = 0; i64 off = 0; vector P; vector mid; vector> A; LiCiaoTree(int L, int R){ N = 1; while(N < R-L+1) N *= 2; P.resize(N, R); mid.resize(N*2); rep(i,R-L+1) P[i] = L+i; for(int d=0; (1<> d; rep(i,1<= 1){ ans = max(ans, A[pos].first * x + A[pos].second); pos /= 2; } return ans; } void update(i64 a, i64 b){ i64 i = 1; pair f = {a,b}; while(true){ if(A[i].first * mid[i] + A[i].second < f.first * mid[i] + f.second){ swap(A[i], f); } if(i >= N) break; bool rightup = f.first - A[i].first > 0; i = i * 2 + (rightup ? 1 : 0); } } }; int main(){ int N; cin >> N; vector Q(N); rep(i,N) cin >> Q[i]; auto ds = LiCiaoTree(-110000, 110000); i64 ans = -INF; rep(i,N){ i64 prevmax = ds.maxval(Q[i]); ans = max(ans, prevmax); if(prevmax < 0) prevmax = 0; ds.update(Q[i], prevmax); } cout << ans << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;