1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 #include<queue>
7 #include<cmath>
8 using namespace std;
9 #define Maxn 1000010
10 #define LL long long
11
12 // LL x[Maxn],p[Maxn],c[Maxn];
13 LL s1[Maxn],s2[Maxn],f[Maxn];
14
15 struct hp
16 {
17 LL x,p,c;
18 }d[Maxn];
19
20 struct node
21 {
22 LL x,y;
23 }t[Maxn];LL cnt;
24 LL n;
25
26 bool cmp(hp x,hp y) {return x.x<y.x;}
27 LL mymin(LL x,LL y) {return x<y?x:y;}
28
29 void init()
30 {
31 scanf("%lld",&n);
32 for(LL i=1;i<=n;i++)
33 {
34 scanf("%lld%lld%lld",&d[i].x,&d[i].p,&d[i].c);
35 }
36 // sort(d+1,d+1+n,cmp);
37 s2[0]=0;s1[0]=0;
38 for(LL i=1;i<=n;i++)
39 {
40 s1[i]=s1[i-1]+d[i].p;
41 s2[i]=s2[i-1]-d[i].p*d[i].x;
42 }
43 }
44
45 bool check(LL x,LL y,LL k)
46 {
47 return (t[y].y-t[x].y)<=k*(t[y].x-t[x].x);
48 }
49
50 bool check2(LL x,LL y,LL z)
51 {
52 return (t[x].y-t[z].y)*(t[x].x-t[y].x)<=(t[x].x-t[z].x)*(t[x].y-t[y].y);
53 }
54
55 void ffind()
56 {
57 LL cnt=0,st;
58 f[n]=d[n].c;
59 t[++cnt].x=d[n].x;t[cnt].y=s1[n]*d[n].x+s2[n]+f[n];st=1;
60 LL ans=t[1].y;
61 for(LL i=n-1;i>=1;i--)
62 {
63 while(st<cnt&&check(st,st+1,s1[i])) st++;
64 f[i]=-s1[i]*t[st].x+t[st].y-s2[i]+d[i].c;
65 //-s1[i]*x[j]+ s1[j]*x[j]+s2[j] - s2[i]
66 t[0].x=d[i].x;t[0].y=s1[i]*d[i].x+s2[i]+f[i];
67 while(st<cnt&&check2(cnt,cnt-1,0)) cnt--;
68 t[++cnt]=t[0];
69 ans=mymin(ans,t[cnt].y);
70 }
71 printf("%lld\n",ans);
72 }
73
74 int main()
75 {
76 init();
77 ffind();
78 return 0;
79 }