1 %:pragma GCC optimize(2)
2 #include<bits/stdc++.h>
3 #define sqr(x) ((x)*(x))
4 #define LL long long
5 using namespace std;
6 const int N=1000005;
7 const double inf=1e18;
8 int n,k,l,r; LL X[N],P[N],C[N],s1[N],s2[N],f[N];
9 struct point {
10 LL x,y;
11 point() {}
12 point(LL _x,LL _y):x(_x),y(_y) {}
13 }st[N];
14 int read() {
15 int x=0,f=1; char ch=getchar();
16 while (ch<‘0‘||ch>‘9‘) f=(ch==‘-‘)?-1:1,ch=getchar();
17 while (ch>=‘0‘&&ch<=‘9‘) x=x*10+ch-‘0‘,ch=getchar();
18 return x*f;
19 }
20 double slope(point u,point v) {
21 return u.x==v.x?(u.y<v.y?inf:-inf):1.0*(v.y-u.y)/(v.x-u.x);
22 }
23 LL get(LL k) {
24 while (l<r&&slope(st[l],st[l+1])<1.0*k) l++;
25 return st[l].y-k*st[l].x;
26 }
27 void insert(point cur) {
28 while (l<r&&slope(st[r-1],st[r])>slope(st[r-1],cur)) r--;
29 st[++r]=cur;
30 }
31 int main() {
32 n=read(),s1[0]=s2[0]=0;
33 for (int i=1; i<=n; i++) X[i]=read(),P[i]=read(),C[i]=read();
34 for (int i=1; i<=n; i++) s1[i]=s1[i-1]+P[i],C[i]+=s1[i]*X[i];
35 for (int i=1; i<=n; i++) s2[i]=s2[i-1]+P[i]*X[i],C[i]-=s2[i];
36 l=1,r=0,st[++r]=point(0,0);
37 for (int i=1; i<=n; i++) {
38 f[i]=get(X[i])+C[i];
39 insert(point(s1[i],f[i]+s2[i]));
40 }
41 printf("%lld\n",f[n]);
42 return 0;
43 }