#include<bits/stdc++.h>
#define reg register
#define ll long long
#define maxn 500010
#define getchar() (_S==_T&&(_T=(_S=_B)+fread(_B,1,1<<15,stdin),_S==_T)?EOF:*_S++)
char _B[1<<15],*_S=_B,*_T=_B;
int read() {
reg int s=0,f=1; reg char ch;
for(;(ch=getchar())<'0'||ch>'9';ch=='-'?f=-f:0);
for(;ch>='0'&&ch<='9';s=s*10+ch-'0',ch=getchar());
return s*f;
}
int n,m,tt,v[maxn],x[maxn*2],s[maxn*2];
ll ans=-1e18,y[maxn*2];
bool cmax(reg ll&a,reg ll b) {return a<b?a=b,1:0;}
struct P{
int v,id;
bool operator<(reg const P&a)const{return v<a.v;}
}p[maxn*2];
int main() {
n=read();
for(reg int i=1;i<=n;++i) p[i*2-1]=(P){read(),i},p[i*2]=(P){read(),i},v[i]=read()*2;
reg ll tot=0; std::sort(p+1,p+n*2+1),p[1].v>1?x[m=1]=1:0;
for(reg int i=1,j;i<=n*2;x[++m]=p[j].v,y[m]=tot)
for(j=i;i<=n*2&&p[i].v==p[j].v;tot+=v[p[i++].id]);
for(reg int i=1;i<=m;s[++tt]=i++)
for(;tt>1&&1.0*(x[s[tt]]-x[s[tt-1]])/(x[i]-x[s[tt]])>=1.0*(y[s[tt]]-y[s[tt-1]])/(y[i]-y[s[tt]]);--tt);
for(reg int i=1;i<=m;cmax(ans,y[i]+y[s[tt]]-4ll*x[i]*x[s[tt]]),++i)
for(;tt>1&&y[s[tt-1]]-4ll*x[i]*x[s[tt-1]]>=y[s[tt]]-4ll*x[i]*x[s[tt]];--tt);
for(reg int i=1;i<=n;++i) ans-=2ll*v[i];
printf("%lld\n",ans);
return 0;
}