#include <bits/stdc++.h>

using namespace std;

const int INF = 1e9;

int n, m;
vector<int> d;
vector<vector<int>> g;

void bfs(int s) {
	d = vector<int>(n, INF);
	d[s] = 0;

	queue<int> q;
	q.push(s);

	while (!q.empty()) {
		int v = q.front();
		q.pop();

		for (auto to : g[v]) {
			if (d[to] == INF) {
				d[to] = d[v] + 1;
				q.push(to);
			}
		}
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;

	for (int tc = 0; tc < t; ++tc){
		cin >> n >> m;
		g = vector<vector<int>>(n);
		for (int i = 0; i < m; ++i) {
			int x, y;
			cin >> x >> y;
			--x, --y;
			g[x].push_back(y);
			g[y].push_back(x);
		}

		bfs(0);
		vector<int> even, odd;
		for (int i = 0; i < n; ++i) {
			if (d[i] & 1) odd.push_back(i);
			else even.push_back(i);
		}

		if (even.size() < odd.size()) {
			cout << even.size() << endl;
			for (auto v : even) cout << v + 1 << " ";
		} else {
			cout << odd.size() << endl;
			for (auto v : odd) cout << v + 1 << " ";
		}
		cout << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    bool B[n+1];
    ll i,j,k,l;
    for(i=0;i<=n;i++)
        B[i]=false;
    ll a[n+1]={0};
    vector<ll>v[n+1],d;
    ll ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui].push_back(vi);
        v[vi].push_back(ui);
    }

    for(i=1;i<n+1;i++)
    {
        l=0;
        for(j=0;j<v[i].size();j++)
        {
            if(B[v[i][j]]==false)
            {
                B[v[i][j]]=true;
                l=1;
            }
        }
        if(l==1)
            d.push_back(i);

    }
    cout<<d.size()<<endl;
    j=d.size();
    j=max(n/2,j);
    //cout<<j<<endl;
    for(i=0;i<j;i++)
        cout<<d[i]<<" ";
    cout<<endl;

    //cout<<n/2<<endl;

   }

    return 0;
}


/*
....................
....................
*/
#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

void breadthFirstSearch(vector< list< int > > adjacencyList, int parent[], int level[])
{
    list<int>::iterator itr;
    int i, par, lev;
    bool flag = true;

    lev = 0;
    level[1] = lev;

    while (flag) {
        flag = false;
        for (i = 1; i < adjacencyList.size(); ++i) {
            if (level[i] == lev) {
                flag = true;
                itr = adjacencyList[i].begin();
                par = i;

                while (itr != adjacencyList[i].end()) {
                    if (level[*itr] != -1) {
                        ++itr;
                        continue;
                    }

                    level[*itr] = lev + 1;
                    parent[*itr] = par;
                    ++itr;
                }
            }
        }

        ++lev;
    }
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // here;

     ll t;
     cin>>t;
     while(t--)
     {
        ll vertices, edges, v1, v2, weight;

        cin>>vertices>>edges;
        //cout<<vertices<<" "<<edges<<endl;

        vector< list<int> > adjacencyList(vertices + 1);

        for (int i = 1; i <= edges; ++i)
        {
            cin>>v1>>v2;

        // Adding Edges
            adjacencyList[v1].push_back(v2);
            adjacencyList[v2].push_back(v1);
        }

        int parent[vertices + 1];
        int level[vertices + 1];

        for (int i = 0; i <= vertices; ++i) {
            parent[i] = 0;
            level[i] = -1;
        }

        breadthFirstSearch(adjacencyList, parent, level);

        vector<ll>od,ev;
        for (int i = 1; i <= vertices; ++i)
        {
            if(level[i]%2==0)
            {
                ev.pb(i);
            }
            else
                od.pb(i);
        }

        if(od.size()<ev.size())
        {
            cout<<od.size()<<endl;
            for(ll i=0;i<od.size();i++)
            {
                cout<<od[i]<<" ";
            }
            cout<<endl;
        }
        else
        {
            cout<<ev.size()<<endl;
            for(ll i=0;i<ev.size();i++)
            {
                cout<<ev[i]<<" ";
            }
            cout<<endl;
        }

    continue;
     }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    //cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<(n%2==0?n/2:n/2+1)<<endl;
    j=n%2==0?n/2:n/2+1;
    for(i=0;i<j;i++)
        cout<<a[i].second<<" ";
    cout<<endl;
   }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    //cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<(n%2==0?n/2:n/2+1)<<endl;
    j=n%2==0?n/2:n/2+1;
    for(i=0;i<j;i++)
       {
        if(i%2==0)
        {
             cout<<a[i].second<<" ";
        }
        else
             cout<<a[a.size()-1-i].second<<" ";
       }
    cout<<endl;
   }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    //cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<n/2<<endl;
    j=n/2;
    for(i=0;i<j;i++)
       {
        cout<<a[a.size()-1-i].second<<" ";
       }
    cout<<endl;
   }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    //cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<(n%2==0?n/2:n/2+1)<<endl;
    j=n%2==0?n/2:n/2+1;
    for(i=0;i<j;i++)
       {
        if(i%2==0)
        {
             cout<<a[i].second<<" ";
        }
        else
             cout<<a[j+i].second<<" ";
       }
    cout<<endl;
   }

    return 0;
}


#include<bits/stdc++.h>
#define ll long long int
#define here cout<<"here\n"
#define pb push_back
#define mp make_pair
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pf printf
#define pfi(x) printf("%d\n",x)
#define pfl(x) printf("%lld\n",x)
using namespace std;

const ll mod = 1e9+7;

const int MAX = 100005;

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

   ll t;
   cin>>t;
   //cout<<t<<endl;
   while(t--)
   {
     ll n,m;
    cin>>n>>m;
    ll v[n+1]={0};
    ll i,j,k,ui,vi;
    for(i=0;i<m;i++)
    {
        cin>>ui>>vi;
        v[ui]++;
        v[vi]++;
    }
    vector<pair<ll,ll > >a;
    //cout<<n/2<<endl;
    for(i=1;i<n+1;i++)
    {
         a.push_back(make_pair(v[i],i));
    }
    sort(a.begin(),a.end());

    cout<<n/2<<endl;
    j=n/2;
    for(i=0;i<j;i++)
       {
        if(i%2==0)
        {
             cout<<a[i].second<<" ";
        }
        else
             cout<<a[a.size()-1-i].second<<" ";
       }
    cout<<endl;
   }

    return 0;
}


/*
 * 	Roses are red
 * 		Violets are blue
 * 			I cried
 * 				And so did you
*/
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
//typedef double f80;
#define double long double
#define pii pair<int,int>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
#define deb cout<<"Line: "<<__LINE__<<" plz "
typedef long long ll;
const ll inf=1e18;
const ll mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powm(ll a, ll b, ll m);

vector<pair<pii,int>> rects;
int consta[1000001];
bool removed[1000001];
deque<pair<pii,double>> yi;
void solve()
{
	int n;
	cin>>n;
	int x,y,c;
	for(int i=1; i<=n; i++)
	{
		cin>>x>>y>>c;
		rects.pb({{x,y},c});
	}
	sort(all(rects));
	int ans=0;
	yi.pb({{0,0},0});
	//yi first - answer,
	//second - xi value;
	// third - activation enthalpy yi
	for(int i=0; i<n; i++)
	{
		auto lol=yi.front();
		ans=max(ans,lol.fi.fi-lol.fi.se*rects[i].fi.se+rects[i].fi.se*rects[i].fi.fi-rects[i].se);
		auto pop=yi.back();
		yi.pop_back();
		if(!yi.empty())
		{
		auto top=yi.back();
		while((!yi.empty())&&top.fi.fi-top.fi.se*top.se<ans-rects[i].fi.fi*top.se)
		{
			pop=yi.back();
			yi.pop_back();
			if(!yi.empty())
				top=yi.back();
		}
		}
		double optiheight=(ans-pop.fi.fi)/(rects[i].fi.fi-pop.fi.se+0.0);
		yi.push_back({pop.fi,optiheight});
		yi.push_back({{ans,rects[i].fi.fi},0});
//		cout<<ans<<endl;
	}
	cout<<ans<<endl;
}
signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
	auto clk=clock();
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	clk=clock()-clk;
	cout<<endl<<endl<< "Time Elapsed: " << ((double)clk)/CLOCKS_PER_SEC <<endl;
#endif
	return 0;
}
ll powm(ll a,ll b, ll m) {
	ll te=1;
	while(b) {
		if(b&1) te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


/*
 * 	Roses are red
 * 		Violets are blue
 * 			I cried
 * 				And so did you
*/
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifndef rd
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
//typedef double f80;
#define double long double
#define pii pair<int,int>
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define all(con) con.begin(),con.end()
#define deb cout<<"Line: "<<__LINE__<<" plz "
typedef long long ll;
const ll inf=1e18;
const ll mod=1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll powm(ll a, ll b, ll m);

vector<pair<pii,int>> rects;
int consta[1000001];
bool removed[1000001];
deque<pair<pii,double>> yi;
void solve()
{
	int n;
	cin>>n;
	int x,y,c;
	for(int i=1; i<=n; i++)
	{
		cin>>x>>y>>c;
		rects.pb({{x,y},c});
	}
	sort(all(rects));
	int ans=0;
	yi.pb({{0,0},0});
	//yi first - answer,
	//second - xi value;
	// third - activation enthalpy yi
	for(int i=0; i<n; i++)
	{
		auto lol=yi.front();
		while(lol.second>rects[i].fi.se)
		{
			yi.pop_front();
			lol=yi.front();
		}
//		cout<<lol.fi.fi<<" "<<lol.fi.se<<" "<<lol.se<<endl;
		ans=max(ans,lol.fi.fi-lol.fi.se*rects[i].fi.se+rects[i].fi.se*rects[i].fi.fi-rects[i].se);
		auto pop=yi.back();
		yi.pop_back();
		if(!yi.empty())
		{
		auto top=yi.back();
		}
		double optiheight=(ans-pop.fi.fi)/(rects[i].fi.fi-pop.fi.se+0.0);
		yi.push_back({pop.fi,optiheight});
		yi.push_back({{ans,rects[i].fi.fi},0});
//		cout<<ans<<endl;
	}
	cout<<ans<<endl;
}
signed main()
{
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::steady_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
	auto clk=clock();
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	clk=clock()-clk;
	cout<<endl<<endl<< "Time Elapsed: " << ((double)clk)/CLOCKS_PER_SEC <<endl;
#endif
	return 0;
}
ll powm(ll a,ll b, ll m) {
	ll te=1;
	while(b) {
		if(b&1) te=(te*a)%m;
		a=(a*a)%m;
		b>>=1;
	}
	return te;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define _CRT_SECURE_NO_WARNINGS
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>

//#ifdef LOCAL
//# include <opencv2/core/core.hpp>
//# include <opencv2/highgui/highgui.hpp>
//# include <opencv2/imgproc/imgproc.hpp>
//#endif

using namespace std;

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 6,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,_6,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cerr<<#a<<"=["; printarray(a,n); cerr<<"]\n"
#define DAR(a,n,s) cerr<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cerr<<"]\n"

#ifdef _MSC_VER
#define PREFETCH(ptr, rw, level) ((void)0)
#else
#define PREFETCH(ptr, rw, level) __builtin_prefetch(ptr, rw, level)
#endif

#if defined _MSC_VER
#define ASSUME(condition) ((void)0)
#define __restrict
#elif defined __clang__
#define ASSUME(condition)       __builtin_assume(condition)
#elif defined __GNUC__
[[noreturn]] __attribute__((always_inline)) inline void undefinedBehaviour() {}
#define ASSUME(condition)       ((condition) ? true : (undefinedBehaviour(), false))
#endif

#ifdef LOCAL
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#else
#define CURTIME()
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef int itn;

template<class T1, class T2, class T3>
struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
template<class T1, class T2, class T3>
bool operator<(const triple<T1,T2,T3>&t1,const triple<T1,T2,T3>&t2){if(t1.a!=t2.a)return t1.a<t2.a;else if(t1.b!=t2.b)return t1.b<t2.b;else return t1.c<t2.c;}
template<class T1, class T2, class T3>
bool operator>(const triple<T1,T2,T3>&t1,const triple<T1,T2,T3>&t2){if(t1.a!=t2.a)return t1.a>t2.a;else if(t1.b!=t2.b)return t1.b>t2.b;else return t1.c>t2.c;}
#define tri triple<int,int,int>
#define trll triple<ll,ll,ll>

#define FI(n) for(int i=0;i<(n);++i)
#define FJ(n) for(int j=0;j<(n);++j)
#define FK(n) for(int k=0;k<(n);++k)
#define FL(n) for(int l=0;l<(n);++l)
#define FQ(n) for(int q=0;q<(n);++q)
#define FOR(i,a,b) for(int i = (a), __e = (int) (b); i < __e; ++i)
#define all(a) std::begin(a), std::end(a)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())

#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(1.0 * (x))
#define pow(x, n) pow(1.0 * (x), n)

#define COMPARE(obj) [&](const std::decay_t<decltype(obj)>& a, const std::decay_t<decltype(obj)>& b)
#define COMPARE_BY(obj, field) [&](const std::decay_t<decltype(obj)>& a, const std::decay_t<decltype(obj)>& b) { return a.field < b.field; }

#define checkbit(n, b) (((n) >> (b)) & 1)
#define setbit(n, b) ((n) | (static_cast<std::decay<decltype(n)>::type>(1) << (b)))
#define removebit(n, b) ((n) & ~(static_cast<std::decay<decltype(n)>::type>(1) << (b)))
#define flipbit(n, b) ((n) ^ (static_cast<std::decay<decltype(n)>::type>(1) << (b)))
inline int countBits(uint v){v=v-((v>>1)&0x55555555);v=(v&0x33333333)+((v>>2)&0x33333333);return((v+(v>>4)&0xF0F0F0F)*0x1010101)>>24;}
inline int countBits(ull v){uint t=v>>32;uint p=(v & ((1ULL << 32) - 1)); return countBits(t) + countBits(p); }
inline int countBits(ll v){return countBits((ull)v); }
inline int countBits(int v){return countBits((uint)v); }
unsigned int reverseBits(uint x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
template<class T> inline int sign(T x){ return x > 0 ? 1 : x < 0 ? -1 : 0; }
inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); }
constexpr ll power(ll x, int p) { return p == 0 ? 1 : (x * power(x, p - 1)); }
template<class T>
inline bool inRange(const T& val, const T& min, const T& max) { return min <= val && val <= max; }
//template<class T1, class T2, class T3> T1 inline clamp(T1 x, const T2& a, const T3& b) { if (x < a) return a; else if (x > b) return b; else return x; }
unsigned long long rdtsc() { unsigned long long ret = 0;
#ifdef __clang__
    return __builtin_readcyclecounter();
#endif
#ifndef _MSC_VER
    asm volatile("rdtsc" : "=A" (ret) : :);
#endif
    return ret; }
// Fast IO ********************************************************************************************************
const int __BS = 4096;
static char __bur[__BS + 16], *__er = __bur + __BS, *__ir = __er;
template<class T = int> T readInt() {
    auto c = [&]() { if (__ir == __er) std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur; };
    c(); while (*__ir && (*__ir < '0' || *__ir > '9') && *__ir != '-') ++__ir; c();
    bool m = false; if (*__ir == '-') ++__ir, c(), m = true;
    T r = 0; while (*__ir >= '0' && *__ir <= '9') r = r * 10 + *__ir - '0', ++__ir, c();
    ++__ir; return m ? -r : r;
}
string readString() {
    auto c = [&]() { if (__ir == __er) std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur; };
    string r; c(); while (*__ir && isspace(*__ir)) ++__ir, c();
    while (!isspace(*__ir)) r.push_back(*__ir), ++__ir, c();
    ++__ir; return r;
}
char readChar() {
    auto c = [&]() { if (__ir == __er) std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur; };
    c(); while (*__ir && isspace(*__ir)) ++__ir, c(); return *__ir++;
}
static char __buw[__BS + 20], *__iw = __buw, *__ew = __buw + __BS;
template<class T>
void writeInt(T x, char endc = '\n') {
    if (x < 0) *__iw++ = '-', x = -x; if (x == 0) *__iw++ = '0';
    char* s = __iw;
    while (x) { T t = x / 10; char c = x - 10 * t + '0'; *__iw++ = c; x = t; }
    char* f = __iw - 1; while (s < f) swap(*s, *f), ++s, --f;
    if (__iw > __ew) cout.write(__buw, __iw - __buw), __iw = __buw;
    if (endc) { *__iw++ = endc; }
}
template<class T>
void writeStr(const T& str) {
    int i = 0; while (str[i]) { *__iw++ = str[i++]; if (__iw > __ew) cout.write(__buw, __iw - __buw), __iw = __buw; }
}
struct __FL__ { ~__FL__() { if (__iw != __buw) cout.write(__buw, __iw - __buw); } };
static __FL__ __flushVar__;

//STL output *****************************************************************************************************
#define TT1 template<class T>
#define TT1T2 template<class T1, class T2>
#define TT1T2T3 template<class T1, class T2, class T3>
TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p);
TT1 ostream& operator << (ostream& os, const vector<T>& v);
TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v);
TT1T2 ostream& operator << (ostream& os, const multiset<T1, T2>&v);
TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v);
TT1T2T3 ostream& operator << (ostream& os, const map<T1, T2, T3>& v);
TT1T2T3 ostream& operator << (ostream& os, const multimap<T1, T2, T3>& v);
TT1T2T3 ostream& operator << (ostream& os, const triple<T1, T2, T3>& t);
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v);
TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p){ return os <<"("<<p.first<<", "<< p.second<<")"; }
TT1 ostream& operator << (ostream& os, const vector<T>& v){       bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v) {     bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v){    bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multiset<T1,T2>&v){bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2T3 ostream& operator << (ostream& os, const map<T1,T2,T3>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multimap<T1, T2>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v) { bool f = 1; os << "["; while (!v.empty()) { auto x = v.top(); v.pop(); if (!f) os << ", "; f = 0; os << x; } return os << "]"; }
TT1T2T3 ostream& operator << (ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }
TT1T2 void printarray(const T1& a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }

//STL input *****************************************************************************************************
TT1T2T3 inline istream& operator >> (istream& os, triple<T1, T2, T3>& t);
TT1T2 inline istream& operator >> (istream& os, pair<T1, T2>& p) { return os >> p.first >> p.second; }
TT1 inline istream& operator >> (istream& os, vector<T>& v) {
    if (v.size()) for (T& t : v) os >> t; else {
        string s; T obj; while (s.empty()) {getline(os, s); if (!os) return os;}
        stringstream ss(s); while (ss >> obj) v.push_back(obj);
    }
    return os;
}
TT1T2T3 inline istream& operator >> (istream& os, triple<T1, T2, T3>& t) { return os >> t.a >> t.b >> t.c; }

//Pair magic *****************************************************************************************************
#define PT1T2 pair<T1, T2>
TT1T2 inline PT1T2 operator+(const PT1T2 &p1 , const PT1T2 &p2) { return PT1T2(p1.first + p2.first, p1.second + p2.second); }
TT1T2 inline PT1T2& operator+=(PT1T2 &p1 , const PT1T2 &p2) { p1.first += p2.first, p1.second += p2.second; return p1; }
TT1T2 inline PT1T2 operator-(const PT1T2 &p1 , const PT1T2 &p2) { return PT1T2(p1.first - p2.first, p1.second - p2.second); }
TT1T2 inline PT1T2& operator-=(PT1T2 &p1 , const PT1T2 &p2) { p1.first -= p2.first, p1.second -= p2.second; return p1; }

#undef TT1
#undef TT1T2
#undef TT1T2T3

#define FREIN(FILE) freopen(FILE, "rt", stdin)
#define FREOUT(FILE) freopen(FILE, "wt", stdout)
#ifdef LOCAL
#define BEGIN_PROFILE(idx, name) int profileIdx = idx; profileName[profileIdx] = name; totalTime[profileIdx] -= rdtsc() / 1e3;
#define END_PROFILE totalTime[profileIdx] += rdtsc() / 1e3; totalCount[profileIdx]++;
#else
#define BEGIN_PROFILE(idx, name)
#define END_PROFILE
#endif

const int USUAL_MOD = 1000000007;
template<class T> inline void normmod(T &x, T m = USUAL_MOD) { x %= m; if (x < 0) x += m; }
template<class T1, class T2> inline T2 summodfast(T1 x, T1 y, T2 m = USUAL_MOD) { T2 res = x + y; if (res >= m) res -= m; return res; }
template<class T1, class T2, class T3 = int> inline void addmodfast(T1 &x, T2 y, T3 m = USUAL_MOD) { x += y; if (x >= m) x -= m; }
template<class T1, class T2, class T3 = int> inline void submodfast(T1 &x, T2 y, T3 m = USUAL_MOD) { x -= y; if (x < 0) x += m; }
inline ll mulmod(ll x, ll n, ll m){ x %= m; n %= m; ll r = x * n - ll(ld(x)*ld(n) / ld(m)) * m; while (r < 0) r += m; while (r >= m) r -= m; return r; }
inline ll powmod(ll x, ll n, ll m){ ll r = 1; normmod(x, m); while (n){ if (n & 1) r *= x; x *= x; r %= m; x %= m; n /= 2; }return r; }
inline ll powmulmod(ll x, ll n, ll m) { ll res = 1; normmod(x, m); while (n){ if (n & 1)res = mulmod(res, x, m); x = mulmod(x, x, m); n /= 2; } return res; }
template<class T> inline T gcd(T a, T b) { while (b) { T t = a % b; a = b; b = t; } return a; }
template<class T>
T fast_gcd(T u, T v) {
    int shl = 0; while ( u && v && u != v) { T eu = u & 1; u >>= eu ^ 1; T ev = v & 1; v >>= ev ^ 1;
        shl += (~(eu | ev) & 1); T d = u & v & 1 ? (u + v) >> 1 : 0; T dif = (u - v) >> (sizeof(T) * 8 - 1); u -= d & ~dif; v -= d & dif;
    } return std::max(u, v) << shl;
}

inline ll lcm(ll a, ll b){ return a / gcd(a, b) * b; }
template<class T> inline T gcd(T a, T b, T c){ return gcd(gcd(a, b), c); }
ll gcdex(ll a, ll b, ll& x, ll& y) {
    if (!a) { x = 0; y = 1; return b; }
    ll y1; ll d = gcdex(b % a, a, y, y1); x = y1 - (b / a) * y;
    return d;
}

bool isPrime(long long n) {
    if (n <= (1 << 14)) { int x = (int) n; if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
        for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }
    long long s = n - 1; int t = 0; while (s % 2 == 0) { s /= 2; ++t; }
    for (int a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { if (!(a %= n)) return true;
        long long f = powmulmod(a, s, n); if (f == 1 || f == n - 1) continue;
        for (int i = 1; i < t; ++i) if ((f = mulmod(f, f, n)) == n - 1) goto nextp;
        return false; nextp:;
    } return true;
}

// Useful constants

//int some_primes[7] = {24443, 100271, 1000003, 1000333, 5000321, 98765431,
#define T9          1000000000
#define T18         1000000000000000000LL
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define mod         1000000007
#define fftmod      998244353
#define EPS         1e-10
#define PI          3.14159265358979323846264
#define link        himomisubmitted
#define rank        thatsnoteasytask
//*************************************************************************************

int32_t solve();
int32_t main(int argc, char** argv) {
    ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef LOCAL
    FREIN("input.txt");
//    FREOUT("out.txt");
#endif

    return solve();
}

trll p[1010101];
int allY[1010101];
struct Line {
    ll k, b;
    ll eval(int pos) {
        return k * allY[pos] + b;
    }
};
Line tr[3010101];
void update(int cur, int l, int r, Line line) {
    int m = (l + r) / 2;
    if (tr[cur].eval(m) < line.eval(m)) {
        swap(tr[cur], line);
    }
    if (l == r) return;
    int dcur = cur + cur;
    if (tr[cur].eval(l) < line.eval(l)) {
        update(dcur, l, m, line);
    }
    if (tr[cur].eval(r) < line.eval(r)) {
        update(dcur + 1, m + 1, r, line);
    }
}
ll get(int cur, int l, int r, int x) {
    ll res = tr[cur].eval(x);
    if (l != r) {
        int m = (l + r) / 2;
        int dcur = cur + cur;
        if (x <= m) {
            res = max(res, get(dcur, l, m, x));
        } else {
            res = max(res, get(dcur + 1, m + 1, r, x));
        }
    }
    return res;
}
int solve() {
    int n;
    cin >> n;
    FI(n) {
        cin >> p[i + 1];
    }
    sort(p + 1, p + n + 1);
    p[0].a = 0;
    p[0].b = INF;
    p[n + 1].a = INF;
    p[n + 1].b = 0;
    for (int i = 0; i < n + 2; ++i) {
        allY[i] = p[i].b;
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ll x = p[i].a;
        ll y = p[i].b;
        ll res = get(1, 0, n, i) - p[i].c + x * y;
        ans = max(ans, res);
        Line line = {-x, res};
        update(1, 0, n, line);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e6 + 10;
const ll inf = 1e18;

struct Line
{
    ll a, b;
    Line() {}
    Line(ll a, ll b) : a(a), b(b) {}
    ll valueAt(ll x)
    {
        return a * x + b;
    }
    ld intersectX(Line l)
    {
        return -(ld)(b - l.b) / (a - l.a);
    }
};

int n;
struct rec
{
    ll x, y, a;
    rec() {}
} h[maxN];
ll dp[maxN], res = -inf;
int head = 1e6, tail = 1e6;
Line d[maxN * 2];

void addLine(Line l)
{
    while (tail - head >= 2 && l.intersectX(d[head]) >= d[head].intersectX(d[head + 1]))
    {
        ++head;
    }
    d[--head] = l;
}

ll maxAt(ll x)
{
    while (tail - head >= 2 && d[tail - 1].valueAt(x) <= d[tail - 2].valueAt(x))
    {
        --tail;
    }
    return d[tail - 1].valueAt(x);
}

inline ll Read()
{
    ll x = 0;
    char c = getchar_unlocked();
    while (c < 48) c = getchar_unlocked();
    while (c > 47) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar_unlocked();
    return x;
}

void solve()
{
    n = Read();
    for1(i, n)
    {
        h[i].x = Read();
        h[i].y = Read();
        h[i].a = Read();
    }
    sort(h + 1, h + n + 1, [](const rec &l, const rec &r)
    {
        return l.x < r.x;
    });
    addLine(Line(0, 0));
    for1(i, n)
    {
        dp[i] = maxAt(h[i].y) + h[i].x * h[i].y - h[i].a;
        uax(res, dp[i]);
        addLine(Line(-h[i].x, dp[i]));
    }
    printf("%I64d", res);
}

int main()
{
    int T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define _CRT_SECURE_NO_WARNINGS
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_map>
# include <unordered_set>

//#ifdef LOCAL
//# include <opencv2/core/core.hpp>
//# include <opencv2/highgui/highgui.hpp>
//# include <opencv2/imgproc/imgproc.hpp>
//#endif

using namespace std;

#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL_((0,__VA_ARGS__, 6,5,4,3,2,1))
#define VA_NUM_ARGS_IMPL_(tuple) VA_NUM_ARGS_IMPL tuple
#define VA_NUM_ARGS_IMPL(_0,_1,_2,_3,_4,_5,_6,N,...) N
#define macro_dispatcher(macro, ...) macro_dispatcher_(macro, VA_NUM_ARGS(__VA_ARGS__))
#define macro_dispatcher_(macro, nargs) macro_dispatcher__(macro, nargs)
#define macro_dispatcher__(macro, nargs) macro_dispatcher___(macro, nargs)
#define macro_dispatcher___(macro, nargs) macro ## nargs
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define DBN(...) macro_dispatcher(DBN, __VA_ARGS__)(__VA_ARGS__)
#define DA(a,n) cerr<<#a<<"=["; printarray(a,n); cerr<<"]\n"
#define DAR(a,n,s) cerr<<#a<<"["<<s<<"-"<<n-1<<"]=["; printarray(a,n,s); cerr<<"]\n"

#ifdef _MSC_VER
#define PREFETCH(ptr, rw, level) ((void)0)
#else
#define PREFETCH(ptr, rw, level) __builtin_prefetch(ptr, rw, level)
#endif

#if defined _MSC_VER
#define ASSUME(condition) ((void)0)
#define __restrict
#elif defined __clang__
#define ASSUME(condition)       __builtin_assume(condition)
#elif defined __GNUC__
[[noreturn]] __attribute__((always_inline)) inline void undefinedBehaviour() {}
#define ASSUME(condition)       ((condition) ? true : (undefinedBehaviour(), false))
#endif

#ifdef LOCAL
#define CURTIME() cerr << clock() * 1.0 / CLOCKS_PER_SEC << endl
#else
#define CURTIME()
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef int itn;

template<class T1, class T2, class T3>
struct triple{ T1 a; T2 b; T3 c; triple() : a(T1()), b(T2()), c(T3()) {}; triple(T1 _a, T2 _b, T3 _c) :a(_a), b(_b), c(_c){} };
template<class T1, class T2, class T3>
bool operator<(const triple<T1,T2,T3>&t1,const triple<T1,T2,T3>&t2){if(t1.a!=t2.a)return t1.a<t2.a;else if(t1.b!=t2.b)return t1.b<t2.b;else return t1.c<t2.c;}
template<class T1, class T2, class T3>
bool operator>(const triple<T1,T2,T3>&t1,const triple<T1,T2,T3>&t2){if(t1.a!=t2.a)return t1.a>t2.a;else if(t1.b!=t2.b)return t1.b>t2.b;else return t1.c>t2.c;}
#define tri triple<int,int,int>
#define trll triple<ll,ll,ll>

#define FI(n) for(int i=0;i<(n);++i)
#define FJ(n) for(int j=0;j<(n);++j)
#define FK(n) for(int k=0;k<(n);++k)
#define FL(n) for(int l=0;l<(n);++l)
#define FQ(n) for(int q=0;q<(n);++q)
#define FOR(i,a,b) for(int i = (a), __e = (int) (b); i < __e; ++i)
#define all(a) std::begin(a), std::end(a)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())

#define sqr(x) ((x) * (x))
#define sqrt(x) sqrt(1.0 * (x))
#define pow(x, n) pow(1.0 * (x), n)

#define COMPARE(obj) [&](const std::decay_t<decltype(obj)>& a, const std::decay_t<decltype(obj)>& b)
#define COMPARE_BY(obj, field) [&](const std::decay_t<decltype(obj)>& a, const std::decay_t<decltype(obj)>& b) { return a.field < b.field; }

#define checkbit(n, b) (((n) >> (b)) & 1)
#define setbit(n, b) ((n) | (static_cast<std::decay<decltype(n)>::type>(1) << (b)))
#define removebit(n, b) ((n) & ~(static_cast<std::decay<decltype(n)>::type>(1) << (b)))
#define flipbit(n, b) ((n) ^ (static_cast<std::decay<decltype(n)>::type>(1) << (b)))
inline int countBits(uint v){v=v-((v>>1)&0x55555555);v=(v&0x33333333)+((v>>2)&0x33333333);return((v+(v>>4)&0xF0F0F0F)*0x1010101)>>24;}
inline int countBits(ull v){uint t=v>>32;uint p=(v & ((1ULL << 32) - 1)); return countBits(t) + countBits(p); }
inline int countBits(ll v){return countBits((ull)v); }
inline int countBits(int v){return countBits((uint)v); }
unsigned int reverseBits(uint x){ x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1)); x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2)); x = (((x & 0xf0f0f0f0) >> 4) | ((x & 0x0f0f0f0f) << 4)); x = (((x & 0xff00ff00) >> 8) | ((x & 0x00ff00ff) << 8)); return((x >> 16) | (x << 16)); }
template<class T> inline int sign(T x){ return x > 0 ? 1 : x < 0 ? -1 : 0; }
inline bool isPowerOfTwo(int x){ return (x != 0 && (x&(x - 1)) == 0); }
constexpr ll power(ll x, int p) { return p == 0 ? 1 : (x * power(x, p - 1)); }
template<class T>
inline bool inRange(const T& val, const T& min, const T& max) { return min <= val && val <= max; }
//template<class T1, class T2, class T3> T1 inline clamp(T1 x, const T2& a, const T3& b) { if (x < a) return a; else if (x > b) return b; else return x; }
unsigned long long rdtsc() { unsigned long long ret = 0;
#ifdef __clang__
    return __builtin_readcyclecounter();
#endif
#ifndef _MSC_VER
    asm volatile("rdtsc" : "=A" (ret) : :);
#endif
    return ret; }
// Fast IO ********************************************************************************************************
const int __BS = 4096;
static char __bur[__BS + 16], *__er = __bur + __BS, *__ir = __er;
template<class T = int> T readInt() {
    auto c = [&]() { if (__ir == __er) std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur; };
    c(); while (*__ir && (*__ir < '0' || *__ir > '9') && *__ir != '-') ++__ir; c();
    bool m = false; if (*__ir == '-') ++__ir, c(), m = true;
    T r = 0; while (*__ir >= '0' && *__ir <= '9') r = r * 10 + *__ir - '0', ++__ir, c();
    ++__ir; return m ? -r : r;
}
string readString() {
    auto c = [&]() { if (__ir == __er) std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur; };
    string r; c(); while (*__ir && isspace(*__ir)) ++__ir, c();
    while (!isspace(*__ir)) r.push_back(*__ir), ++__ir, c();
    ++__ir; return r;
}
char readChar() {
    auto c = [&]() { if (__ir == __er) std::fill(__bur, __bur + __BS, 0), cin.read(__bur, __BS), __ir = __bur; };
    c(); while (*__ir && isspace(*__ir)) ++__ir, c(); return *__ir++;
}
static char __buw[__BS + 20], *__iw = __buw, *__ew = __buw + __BS;
template<class T>
void writeInt(T x, char endc = '\n') {
    if (x < 0) *__iw++ = '-', x = -x; if (x == 0) *__iw++ = '0';
    char* s = __iw;
    while (x) { T t = x / 10; char c = x - 10 * t + '0'; *__iw++ = c; x = t; }
    char* f = __iw - 1; while (s < f) swap(*s, *f), ++s, --f;
    if (__iw > __ew) cout.write(__buw, __iw - __buw), __iw = __buw;
    if (endc) { *__iw++ = endc; }
}
template<class T>
void writeStr(const T& str) {
    int i = 0; while (str[i]) { *__iw++ = str[i++]; if (__iw > __ew) cout.write(__buw, __iw - __buw), __iw = __buw; }
}
struct __FL__ { ~__FL__() { if (__iw != __buw) cout.write(__buw, __iw - __buw); } };
static __FL__ __flushVar__;

//STL output *****************************************************************************************************
#define TT1 template<class T>
#define TT1T2 template<class T1, class T2>
#define TT1T2T3 template<class T1, class T2, class T3>
TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p);
TT1 ostream& operator << (ostream& os, const vector<T>& v);
TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v);
TT1T2 ostream& operator << (ostream& os, const multiset<T1, T2>&v);
TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v);
TT1T2T3 ostream& operator << (ostream& os, const map<T1, T2, T3>& v);
TT1T2T3 ostream& operator << (ostream& os, const multimap<T1, T2, T3>& v);
TT1T2T3 ostream& operator << (ostream& os, const triple<T1, T2, T3>& t);
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v);
TT1T2 ostream& operator << (ostream& os, const pair<T1, T2>& p){ return os <<"("<<p.first<<", "<< p.second<<")"; }
TT1 ostream& operator << (ostream& os, const vector<T>& v){       bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
template<class T, size_t N> ostream& operator << (ostream& os, const array<T, N>& v) {     bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const set<T1, T2>&v){    bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multiset<T1,T2>&v){bool f=1;os<<"[";for(auto& i : v) { if (!f)os << ", ";os<<i;f=0;}return os << "]"; }
TT1T2T3 ostream& operator << (ostream& os, const map<T1,T2,T3>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, const multimap<T1, T2>& v){ bool f = 1; os << "["; for (auto& ii : v) { if (!f)os << ", "; os << "(" << ii.first << " -> " << ii.second << ") "; f = 0; }return os << "]"; }
TT1T2 ostream& operator << (ostream& os, priority_queue<T1, T2> v) { bool f = 1; os << "["; while (!v.empty()) { auto x = v.top(); v.pop(); if (!f) os << ", "; f = 0; os << x; } return os << "]"; }
TT1T2T3 ostream& operator << (ostream& os, const triple<T1, T2, T3>& t){ return os << "(" << t.a << ", " << t.b << ", " << t.c << ")"; }
TT1T2 void printarray(const T1& a, T2 sz, T2 beg = 0){ for (T2 i = beg; i<sz; i++) cout << a[i] << " "; cout << endl; }

//STL input *****************************************************************************************************
TT1T2T3 inline istream& operator >> (istream& os, triple<T1, T2, T3>& t);
TT1T2 inline istream& operator >> (istream& os, pair<T1, T2>& p) { return os >> p.first >> p.second; }
TT1 inline istream& operator >> (istream& os, vector<T>& v) {
    if (v.size()) for (T& t : v) os >> t; else {
        string s; T obj; while (s.empty()) {getline(os, s); if (!os) return os;}
        stringstream ss(s); while (ss >> obj) v.push_back(obj);
    }
    return os;
}
TT1T2T3 inline istream& operator >> (istream& os, triple<T1, T2, T3>& t) { return os >> t.a >> t.b >> t.c; }

//Pair magic *****************************************************************************************************
#define PT1T2 pair<T1, T2>
TT1T2 inline PT1T2 operator+(const PT1T2 &p1 , const PT1T2 &p2) { return PT1T2(p1.first + p2.first, p1.second + p2.second); }
TT1T2 inline PT1T2& operator+=(PT1T2 &p1 , const PT1T2 &p2) { p1.first += p2.first, p1.second += p2.second; return p1; }
TT1T2 inline PT1T2 operator-(const PT1T2 &p1 , const PT1T2 &p2) { return PT1T2(p1.first - p2.first, p1.second - p2.second); }
TT1T2 inline PT1T2& operator-=(PT1T2 &p1 , const PT1T2 &p2) { p1.first -= p2.first, p1.second -= p2.second; return p1; }

#undef TT1
#undef TT1T2
#undef TT1T2T3

#define FREIN(FILE) freopen(FILE, "rt", stdin)
#define FREOUT(FILE) freopen(FILE, "wt", stdout)
#ifdef LOCAL
#define BEGIN_PROFILE(idx, name) int profileIdx = idx; profileName[profileIdx] = name; totalTime[profileIdx] -= rdtsc() / 1e3;
#define END_PROFILE totalTime[profileIdx] += rdtsc() / 1e3; totalCount[profileIdx]++;
#else
#define BEGIN_PROFILE(idx, name)
#define END_PROFILE
#endif

const int USUAL_MOD = 1000000007;
template<class T> inline void normmod(T &x, T m = USUAL_MOD) { x %= m; if (x < 0) x += m; }
template<class T1, class T2> inline T2 summodfast(T1 x, T1 y, T2 m = USUAL_MOD) { T2 res = x + y; if (res >= m) res -= m; return res; }
template<class T1, class T2, class T3 = int> inline void addmodfast(T1 &x, T2 y, T3 m = USUAL_MOD) { x += y; if (x >= m) x -= m; }
template<class T1, class T2, class T3 = int> inline void submodfast(T1 &x, T2 y, T3 m = USUAL_MOD) { x -= y; if (x < 0) x += m; }
inline ll mulmod(ll x, ll n, ll m){ x %= m; n %= m; ll r = x * n - ll(ld(x)*ld(n) / ld(m)) * m; while (r < 0) r += m; while (r >= m) r -= m; return r; }
inline ll powmod(ll x, ll n, ll m){ ll r = 1; normmod(x, m); while (n){ if (n & 1) r *= x; x *= x; r %= m; x %= m; n /= 2; }return r; }
inline ll powmulmod(ll x, ll n, ll m) { ll res = 1; normmod(x, m); while (n){ if (n & 1)res = mulmod(res, x, m); x = mulmod(x, x, m); n /= 2; } return res; }
template<class T> inline T gcd(T a, T b) { while (b) { T t = a % b; a = b; b = t; } return a; }
template<class T>
T fast_gcd(T u, T v) {
    int shl = 0; while ( u && v && u != v) { T eu = u & 1; u >>= eu ^ 1; T ev = v & 1; v >>= ev ^ 1;
        shl += (~(eu | ev) & 1); T d = u & v & 1 ? (u + v) >> 1 : 0; T dif = (u - v) >> (sizeof(T) * 8 - 1); u -= d & ~dif; v -= d & dif;
    } return std::max(u, v) << shl;
}

inline ll lcm(ll a, ll b){ return a / gcd(a, b) * b; }
template<class T> inline T gcd(T a, T b, T c){ return gcd(gcd(a, b), c); }
ll gcdex(ll a, ll b, ll& x, ll& y) {
    if (!a) { x = 0; y = 1; return b; }
    ll y1; ll d = gcdex(b % a, a, y, y1); x = y1 - (b / a) * y;
    return d;
}

bool isPrime(long long n) {
    if (n <= (1 << 14)) { int x = (int) n; if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
        for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1; }
    long long s = n - 1; int t = 0; while (s % 2 == 0) { s /= 2; ++t; }
    for (int a : {2, 325, 9375, 28178, 450775, 9780504, 1795265022}) { if (!(a %= n)) return true;
        long long f = powmulmod(a, s, n); if (f == 1 || f == n - 1) continue;
        for (int i = 1; i < t; ++i) if ((f = mulmod(f, f, n)) == n - 1) goto nextp;
        return false; nextp:;
    } return true;
}

// Useful constants

//int some_primes[7] = {24443, 100271, 1000003, 1000333, 5000321, 98765431,
#define T9          1000000000
#define T18         1000000000000000000LL
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define mod         1000000007
#define fftmod      998244353
#define EPS         1e-10
#define PI          3.14159265358979323846264
#define link        himomisubmitted
#define rank        thatsnoteasytask
//*************************************************************************************

int32_t solve();
int32_t main(int argc, char** argv) {
    ios_base::sync_with_stdio(0);cin.tie(0);
#ifdef LOCAL
//    FREIN("input.txt");
//    FREOUT("out.txt");
#endif

    return solve();
}

tri p[1010101];
int allY[1010101];
struct Line {
    ll k, b;
    ll eval(int pos) {
        return k * allY[pos] + b;
    }
};
Line tr[2010101];
void update(int cur, int l, int r, Line line) {
    int m = (l + r) / 2;
    if (tr[cur].eval(m) < line.eval(m)) {
        swap(tr[cur], line);
    }
    if (l == r) return;
    int dcur = cur + cur;
    if (tr[cur].eval(l) < line.eval(l)) {
        update(dcur, l, m, line);
    }
    if (tr[cur].eval(r) < line.eval(r)) {
        update(dcur + 1, m + 1, r, line);
    }
}
ll get(int cur, int l, int r, int x) {
    ll res = tr[cur].eval(x);
    if (l != r) {
        int m = (l + r) / 2;
        int dcur = cur + cur;
        if (x <= m) {
            res = max(res, get(dcur, l, m, x));
        } else {
            res = max(res, get(dcur + 1, m + 1, r, x));
        }
    }
    return res;
}
int solve() {
    int n;
    cin >> n;
    FI(n) {
        cin >> p[i + 1];
    }
    sort(p + 1, p + n + 1);
    p[0].a = 0;
    p[0].b = INF;
    p[n + 1].a = INF;
    p[n + 1].b = 0;
    for (int i = 0; i < n + 2; ++i) {
        allY[i] = p[i].b;
    }
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        int x = p[i].a;
        int y = p[i].b;
        ll res = get(1, 0, n + 1, i) - p[i].c + x * 1LL * y;
        ans = max(ans, res);
        Line line = {-x, res};
        update(1, 0, n + 1, line);
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x <= p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

ll pass(point p, point q) {
    ll a = p.cost - q.cost;
    ll b = q.y - p.y;
    return (a + b - 1) / b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        while (l + 1 < r && pass(have[r - 1], have[r - 2]) > pass(p, have[r - 2]))
            --r;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x < p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

ll pass(point p, point q) {
    ll a = p.cost - q.cost;
    ll b = q.y - p.y;
    return (a + b - 1) / b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        while (l + 1 < r && pass(cur, have[r - 1]) <= pass(have[r - 1], have[r - 2]))
            --r;
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x < p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

long double pass(point p, point q) {
    ll a = p.cost - q.cost;
    ll b = q.y - p.y;
    return a / (long double) b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        while (l + 1 < r && pass(cur, have[r - 1]) <= pass(have[r - 1], have[r - 2]))
            --r;
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x <= p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

ll pass(point p, point q) {
    ll a = p.cost - q.cost;
    ll b = q.y - p.y;
    return (a + b - 1) / b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        while (l + 1 < r && pass(p, have[r - 1]) < pass(p, have[r - 2]))
            --r;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

struct line {
    ll m, c;
    ll value(int x) { return m * x + c; }
    ll pass(line l) {
        ll a = c - l.c;
        ll b = l.m - m;
        return (a + b - 1) / a;
    }
};

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<line> have(N);
    for (point p : P) {
        while (l + 1 < r && have[l].value(p.x) <= have[l + 1].value(p.x))
            ++l;
        ll bestCost = 1ll * p.x * p.y - p.cost;
        if (l < r)
            bestCost += max(0ll, have[l].value(p.x));
        ans = max(ans, bestCost);
        line cur = line{-p.y, bestCost};
        while (l + 1 < r && have[r - 1].pass(have[r - 2]) >= cur.pass(have[r - 1]))
            --r;
        have[r++] = cur;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x <= p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

struct line {
    ll m, c;
    ll value(int x) { return m * x + c; }
    ll pass(line l) {
        ll a = c - l.c;
        ll b = l.m - m;
        return (a + b - 1) / b;
    }
};

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<line> have(N);
    for (point p : P) {
        while (l + 1 < r && have[l].value(p.x) <= have[l + 1].value(p.x))
            ++l;
        ll bestCost = 1ll * p.x * p.y - p.cost;
        if (l < r)
            bestCost += max(0ll, have[l].value(p.x));
        ans = max(ans, bestCost);
        line cur = line{-p.y, bestCost};
        while (l + 1 < r && have[r - 1].pass(have[r - 2]) <= cur.pass(have[r - 1]))
            --r;
        have[r++] = cur;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

struct line {
    ll m, c;
    ll value(int x) { return m * x + c; }
    ll pass(line l) {
        ll a = c - l.c;
        ll b = l.m - m;
        return (a + b - 1) / b;
    }
};

int n;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<line> have(N);
    for (point p : P) {
        while (l + 1 < r && have[l].value(p.x) <= have[l + 1].value(p.x))
            ++l;
        ll bestCost = 1ll * p.x * p.y - p.cost;
        if (l < r)
            bestCost += max(0ll, have[l].value(p.x));
        ans = max(ans, bestCost);
        line cur = line{-p.y, bestCost};
        while (l + 1 < r && have[r - 1].pass(have[r - 2]) >= cur.pass(have[r - 1]))
            --r;
        have[r++] = cur;
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x < p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

long double pass(point p, point q) {
    ll a = p.cost - q.cost;
    ll b = q.y - p.y;
    return a / (long double) b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        while (l + 1 < r && pass(cur, have[r - 1]) >= pass(have[r - 1], have[r - 2]))
            --r;
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x < p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

ll pass(point p, point q) {
    ll a = p.cost - q.cost;
    ll b = q.y - p.y;
    return (a + b - 1) / b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        while (l + 1 < r && pass(cur, have[r - 1]) >= pass(have[r - 1], have[r - 2]))
            --r;
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x <= p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        while (l < r && value(have[r - 1], p.x) <= value(cur, p.x))
            --r;
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x <= p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) < value(have[l + 1], p.x))
            ++l;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        while (l < r && value(have[r - 1], p.x) < value(cur, p.x))
            --r;
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }

    cout << ans << endl;

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e6 + 5;

struct point {
    int x, y;
    ll cost;
    bool operator<(const point& other) const {
        return y < other.y;
    }
};

int n;

ll value(point p, int x) {
    assert(x <= p.x);
    return 1ll * p.y * (p.x - x) + p.cost;
}

ll pass(point p, point q) {
    ll a = p.cost - q.cost;
    ll b = q.y - p.y;
    return (a + b - 1) / b;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);

    cin >> n;
    vector<point> P(n);
    for (point& p : P)
        cin >> p.x >> p.y >> p.cost;

    sort(P.begin(), P.end());

    ll ans = 0;
    int l = 0, r = 0;
    vector<point> have(N);
    for (point p : P) {
        while (l + 1 < r && value(have[l], p.x) <= value(have[l + 1], p.x))
            ++l;
        ll bestCost = -p.cost;
        if (l < r)
            bestCost += max(0ll, value(have[l], p.x));
        point cur = point{p.x, p.y, bestCost};
        while (l + 1 < r && pass(cur, have[r - 1]) <= pass(cur, have[r - 2]))
            --r;
        have[r++] = cur;
        ans = max(ans, 1ll * p.x * p.y + bestCost);
    }
    cout << ans << endl;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define inf 1e18
#define sz(x) int(x.size())

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <pair <ld, ld> > cxt, otr;
ll ans = 0, dp[N * 10];

ld cross(pair <ld, ld> a, pair <ld, ld> b) {return (a.S - b.S) / (a.F - b.F);}
void add(pair <ld, ld> nxt)
{
    while (sz(cxt) > 1 && otr.back().S <= cross(cxt.back(), nxt)) {cxt.pop_back(); otr.pop_back();}
    cxt.pb(nxt);
    otr.back().F = cross(cxt.back(), nxt);
    otr.pb({-inf, cross(cxt.back(), nxt)});
}
void upd(int x)
{
    dp[x] = vr[x].F.F * vr[x].F.S - vr[x].S;
    int l = 0, r = sz(otr) - 1;
    while (l < r)
    {
        int md = (l + r) >> 1;
        if (otr[md].F >= vr[x].F.S) l = md + 1; else r = md;
    }
    if (dp[l] - vr[l].F.F * vr[x].F.S > 0) dp[x] += dp[l] - vr[l].F.F * vr[x].F.S;
    ans = max(ans, dp[x]);
    add({vr[x].F.F, dp[x]});
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0] = vr[0].F.F * vr[0].F.S - vr[0].S;
    cxt.pb({vr[0].F.F, dp[0]});
    otr.pb({-inf, inf});
    ans = dp[0];
    for (int i = 1; i < n; i++) upd(i);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define sz(x) int(x.size())

typedef long long ll;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <int> cxt;
pair <ll, ll>  dp[N * 10];

void upd(int x)
{
    dp[x].F = vr[x].F.F * vr[x].F.S - vr[x].S;
    bool f = 1;
    int nm = cxt.back();
    ll lst = dp[nm].F - dp[nm].S * vr[x].F.S;
    cxt.pop_back();
    while (f && sz(cxt) > 0)
    {
       f = 0;
       int v = cxt.back();
       ll val = dp[v].F - dp[v].S * vr[x].F.S;
       if (val >= lst)
       {
           nm = v;
           f = 1;
           cxt.pop_back();
           lst = val;
       }
    }
    cxt.pb(nm);
    if (lst > 0) dp[x].F += lst;
    dp[x].S = vr[x].F.F;
}
void add(int x) {cxt.pb(x);}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0].F = vr[0].F.F * vr[0].F.S - vr[0].S; dp[0].S = vr[0].F.F; add(0);
    dp[1].F = vr[1].F.F * vr[1].F.S - vr[1].S + dp[0].F - dp[0].S * vr[1].F.S; dp[1].S = vr[1].F.F; add(1);
    for (int i = 2; i < n; i++) {upd(i); add(i);}
    ll ans = 0;
    for (int i = 0; i < n; i++) ans = max(ans, dp[i].F);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define inf 1e18
#define sz(x) int(x.size())

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <pair <ld, ld> > cxt, otr;
ll ans = 0, dp[N * 10];

ld cross(pair <ld, ld> a, pair <ld, ld> b) {return (a.S - b.S) / (a.F - b.F);}
void add(pair <ld, ld> nxt)
{
    while (sz(cxt) > 1 && otr.back().S <= cross(cxt.back(), nxt)) {cxt.pop_back(); otr.pop_back();}
    cxt.pb(nxt);
    otr.back().F = cross(cxt.back(), nxt);
    otr.pb({-inf, cross(cxt.back(), nxt)});
}
void upd(int x)
{
    dp[x] = vr[x].F.F * vr[x].F.S - vr[x].S;
    int l = 0, r = sz(otr) - 1;
    while (l < r)
    {
        int md = (l + r) >> 1;
        if (otr[md].F >= ld(vr[x].F.S)) l = md + 1; else r = md;
    }
    if (dp[l] - vr[l].F.F * vr[x].F.S > 0) dp[x] += dp[l] - vr[l].F.F * vr[x].F.S;
    ans = max(ans, dp[x]);
    add({ld(vr[x].F.F), ld(dp[x])});
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0] = vr[0].F.F * vr[0].F.S - vr[0].S;
    cxt.pb({ld(vr[0].F.F), ld(dp[0])});
    otr.pb({-inf, inf});
    ans = dp[0];
    for (int i = 1; i < n; i++) upd(i);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define inf 1e18
#define sz(x) int(x.size())

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <pair <ld, ld> > cxt, otr;
ll ans = 0, dp[N * 10];

ld cross(pair <ld, ld> a, pair <ld, ld> b) {return ld(b.S - a.S) / ld(a.F - b.F);}
void add(pair <ld, ld> nxt)
{
    while (sz(cxt) > 1 && otr.back().S <= cross(cxt.back(), nxt)) {cxt.pop_back(); otr.pop_back();}
    otr.back().F = cross(cxt.back(), nxt);
    otr.pb({-inf, otr.back().F});
    cxt.pb(nxt);
}
void upd(int x)
{
    dp[x] = vr[x].F.F * vr[x].F.S - vr[x].S;
    int l = 0, r = sz(otr) - 1;
    while (l < r)
    {
        int md = (l + r) >> 1;
        if (otr[md].F >= ld(vr[x].F.S)) l = md + 1; else r = md;
    }
    if (cxt[l].S - cxt[l].F * vr[x].F.S > 0) dp[x] += cxt[l].S - cxt[l].F * vr[x].F.S;
    ans = max(ans, dp[x]);
    add({ld(-vr[x].F.F), ld(dp[x])});
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0] = vr[0].F.F * vr[0].F.S - vr[0].S;
    cxt.pb({ld(-vr[0].F.F), ld(dp[0])});
    otr.pb({-inf, inf});
    ans = dp[0];
    for (int i = 1; i < n; i++) upd(i);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define inf 1e18
#define sz(x) int(x.size())

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <pair <ld, ld> > cxt, otr;
ll ans = 0, dp[N * 10];

ld cross(pair <ld, ld> a, pair <ld, ld> b) {return ld(b.S - a.S) / ld(a.F - b.F);}
void add(pair <ld, ld> nxt)
{
    while (sz(cxt) > 1 && otr.back().S <= cross(cxt.back(), nxt)) {cxt.pop_back(); otr.pop_back();}
    otr.back().F = cross(cxt.back(), nxt);
    otr.pb({-inf, otr.back().F});
    cxt.pb(nxt);
}
void upd(int x)
{
    dp[x] = vr[x].F.F * vr[x].F.S - vr[x].S;
    int l = 0, r = sz(otr) - 1;
    while (l < r)
    {
        int md = (l + r) >> 1;
        if (otr[md].F >= ld(vr[x].F.S)) l = md + 1; else r = md;
    }
    if (cxt[l].S - cxt[l].F * vr[x].F.S > 0) dp[x] += cxt[l].S - cxt[l].F * vr[x].F.S;
    ans = max(ans, dp[x]);
    add({ld(vr[x].F.F), ld(dp[x])});
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0] = vr[0].F.F * vr[0].F.S - vr[0].S;
    cxt.pb({ld(vr[0].F.F), ld(dp[0])});
    otr.pb({-inf, inf});
    ans = dp[0];
    for (int i = 1; i < n; i++) upd(i);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define inf 1e18
#define sz(x) int(x.size())

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <pair <ld, ld> > cxt, otr;
ll ans = 0, dp[N * 10];

ld cross(pair <ld, ld> a, pair <ld, ld> b) {return ld(b.S - a.S) / ld(a.F - b.F);}
void add(pair <ld, ld> nxt)
{
    while (sz(cxt) > 1 && otr.back().S <= cross(cxt.back(), nxt)) {cxt.pop_back(); otr.pop_back();}
    otr.back().F = cross(cxt.back(), nxt);
    otr.pb({-inf, otr.back().F});
    cxt.pb(nxt);
}
void upd(int x)
{
    dp[x] = vr[x].F.F * vr[x].F.S - vr[x].S;
    int l = 0, r = sz(otr) - 1;
    while (l < r)
    {
        int md = (l + r) >> 1;
        if (otr[md].F >= ld(vr[x].F.S)) l = md + 1; else r = md;
    }
    if (cxt[l].S + cxt[l].F * vr[x].F.S > 0) dp[x] += cxt[l].S + cxt[l].F * vr[x].F.S;
    ans = max(ans, dp[x]);
    add({ld(-vr[x].F.F), ld(dp[x])});
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0] = vr[0].F.F * vr[0].F.S - vr[0].S;
    cxt.pb({ld(-vr[0].F.F), ld(dp[0])});
    otr.pb({-inf, inf});
    ans = dp[0];
    for (int i = 1; i < n; i++) upd(i);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define sz(x) int(x.size())

typedef long long ll;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <int> cxt;
pair <ll, ll>  dp[N * 10];
ll ans = 0;
int j = 0;

void add(int x) {cxt.pb(x);}
void upd(int x)
{
    dp[x].F = vr[x].F.F * vr[x].F.S - vr[x].S;

    while (j + 1 < sz(cxt) && dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S <= dp[cxt[j + 1]].F - dp[cxt[j + 1]].S * vr[x].F.S) j++;

    if (dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S > 0) dp[x].F += dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S;

    dp[x].S = vr[x].F.F;
    ans = max(ans, dp[x].F);
    add(x);
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0].F = vr[0].F.F * vr[0].F.S - vr[0].S; dp[0].S = vr[0].F.F; add(0);
    dp[1].F = vr[1].F.F * vr[1].F.S - vr[1].S + dp[0].F - dp[0].S * vr[1].F.S; dp[1].S = vr[1].F.F; add(1);
    ans = max(dp[0].F, dp[1].F);
    for (int i = 2; i < n; i++) upd(i);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define sz(x) int(x.size())

typedef long long ll;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <int> cxt;
pair <ll, ll>  dp[N * 10];

void upd(int x)
{
    dp[x].F = vr[x].F.F * vr[x].F.S - vr[x].S;
    bool f = 1;
    int nm = cxt.back();
    ll lst = dp[nm].F -dp[nm].S * vr[x].F.S;
    cxt.pop_back();
    while (f && sz(cxt) > 0)
    {
       f = 0;
       int v = cxt.back();
       ll val = dp[v].F + dp[v].S * vr[x].F.S;
       if (val <= lst)
       {
           nm = v;
           f = 1;
           cxt.pop_back();
           lst = val;
       }
    }
    cxt.pb(nm);
    if (lst > 0) dp[x].F += lst;
    dp[x].S = vr[x].F.F;
}
void add(int x) {cxt.pb(x);}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0].F = vr[0].F.F * vr[0].F.S - vr[0].S; dp[0].S = vr[0].F.F; add(0);
    dp[1].F = vr[1].F.F * vr[1].F.S - vr[1].S + dp[0].F - dp[0].S * vr[1].F.S; dp[1].S = vr[1].F.F; add(1);
    for (int i = 2; i < n; i++) {upd(i); add(i);}
    ll ans = 0;
    for (int i = 0; i < n; i++) ans = max(ans, dp[i].F);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define inf 1e18
#define sz(x) int(x.size())

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <pair <ld, ld> > cxt, otr;
ll ans = 0, dp[N * 10];

ld cross(pair <ld, ld> a, pair <ld, ld> b) {return (b.S - a.S) / (a.F - b.F);}
void add(pair <ld, ld> nxt)
{
    while (sz(cxt) > 1 && otr.back().S <= cross(cxt.back(), nxt)) {cxt.pop_back(); otr.pop_back();}
    cxt.pb(nxt);
    otr.back().F = cross(cxt.back(), nxt);
    otr.pb({-inf, cross(cxt.back(), nxt)});
}
void upd(int x)
{
    dp[x] = vr[x].F.F * vr[x].F.S - vr[x].S;
    int l = 0, r = sz(otr) - 1;
    while (l < r)
    {
        int md = (l + r) >> 1;
        if (otr[md].F >= ld(vr[x].F.S)) l = md + 1; else r = md;
    }
    if (dp[l] - vr[l].F.F * vr[x].F.S > 0) dp[x] += dp[l] - vr[l].F.F * vr[x].F.S;
    ans = max(ans, dp[x]);
    add({ld(vr[x].F.F), ld(dp[x])});
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0] = vr[0].F.F * vr[0].F.S - vr[0].S;
    cxt.pb({ld(vr[0].F.F), ld(dp[0])});
    otr.pb({-inf, inf});
    ans = dp[0];
    for (int i = 1; i < n; i++) upd(i);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define inf 1e18
#define sz(x) int(x.size())

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <pair <ld, ld> > cxt, otr;
ll ans = 0, dp[N * 10];

ld cross(pair <ld, ld> a, pair <ld, ld> b) {return (b.S - a.S) / (a.F - b.F);}
void add(pair <ld, ld> nxt)
{
    while (sz(cxt) > 1 && otr.back().S <= cross(cxt.back(), nxt)) {cxt.pop_back(); otr.pop_back();}
    otr.back().F = cross(cxt.back(), nxt);
    otr.pb({-inf, cross(cxt.back(), nxt)});
    cxt.pb(nxt);
}
void upd(int x)
{
    dp[x] = vr[x].F.F * vr[x].F.S - vr[x].S;
    int l = 0, r = sz(otr) - 1;
    while (l < r)
    {
        int md = (l + r) >> 1;
        if (otr[md].F >= ld(vr[x].F.S)) l = md + 1; else r = md;
    }
    if (dp[l] - vr[l].F.F * vr[x].F.S > 0) dp[x] += dp[l] - vr[l].F.F * vr[x].F.S;
    ans = max(ans, dp[x]);
    add({ld(vr[x].F.F), ld(dp[x])});
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0] = vr[0].F.F * vr[0].F.S - vr[0].S;
    cxt.pb({ld(vr[0].F.F), ld(dp[0])});
    otr.pb({-inf, inf});
    ans = dp[0];
    for (int i = 1; i < n; i++) upd(i);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define sz(x) int(x.size())

typedef long long ll;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <int> cxt;
pair <ll, ll>  dp[N * 10];
int j = 0;

void add(int x) {cxt.pb(x);}
void upd(int x)
{
    dp[x].F = vr[x].F.F * vr[x].F.S - vr[x].S;
    while (j + 1 < sz(cxt) && dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S <= dp[cxt[j + 1]].F - dp[cxt[j + 1]].S * vr[x].F.S) j++;
    if (dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S > 0) dp[x].F += dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S;
    dp[x].S = vr[x].F.F;
    add(x);
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0].F = vr[0].F.F * vr[0].F.S - vr[0].S; dp[0].S = vr[0].F.F; add(0);
    dp[1].F = vr[1].F.F * vr[1].F.S - vr[1].S + dp[0].F - dp[0].S * vr[1].F.S; dp[1].S = vr[1].F.F; add(1);
    for (int i = 2; i < n; i++) upd(i);
    ll ans = 0;
    for (int i = 0; i < n; i++) ans = max(ans, dp[i].F);
    cout << ans;
}


//#NDEBUG
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")

using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define S second
#define F first
#define N 100015
#define M ll(1e9 + 7)
#define sz(x) int(x.size())

typedef long long ll;
typedef pair <ll, ll> pt;

vector <pair <pair <ll, ll>, ll> > vr;
vector <int> cxt;
pair <ll, ll>  dp[N * 10];
int j = 0;

void add(int x) {cxt.pb(x);}
void upd(int x)
{
    dp[x].F = vr[x].F.F * vr[x].F.S - vr[x].S;
    while (j + 1 < sz(cxt) && dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S < dp[cxt[j + 1]].F - dp[cxt[j + 1]].S * vr[x].F.S) j++;
    if (dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S > 0) dp[x].F += dp[cxt[j]].F - dp[cxt[j]].S * vr[x].F.S;
    dp[x].S = vr[x].F.F;
    add(x);
}

int main()
{
    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n; vr.resize(n);
    for (int i = 0; i < n; i++) cin >> vr[i].F.F >> vr[i].F.S >> vr[i].S;
    sort(vr.begin(), vr.end());
    dp[0].F = vr[0].F.F * vr[0].F.S - vr[0].S; dp[0].S = vr[0].F.F; add(0);
    dp[1].F = vr[1].F.F * vr[1].F.S - vr[1].S + dp[0].F - dp[0].S * vr[1].F.S; dp[1].S = vr[1].F.F; add(1);
    for (int i = 2; i < n; i++) upd(i);
    ll ans = 0;
    for (int i = 0; i < n; i++) ans = max(ans, dp[i].F);
    cout << ans;
}


#include <bits/stdc++.h>

using namespace std;

typedef pair <int , int> pii;
typedef long long ll;

const int N = 1e6+10;

//CHT it's a copied code
class CHT{
    typedef long long coef_t, coord_t, val_t;
//Line 'y=a*x+b' represented by 2 coefficients 'a' and 'b'
private:
    struct Line{
        coef_t a, b;
        double xLeft;
        enum Type {line, maxQuery, minQuery} type;
        coord_t val;
        explicit Line(coef_t aa=0, coef_t bb=0) : a(aa), b(bb), xLeft(-INFINITY), type(Type::line), val(0) {}
        val_t valueAt(coord_t x) const { return a*x+b; }
        friend bool areParallel(const Line& l1, const Line& l2) { return l1.a==l2.a; }
        friend double intersectX(const Line& l1, const Line& l2) { return areParallel(l1,l2)?INFINITY:1.0*(l2.b-l1.b)/(l1.a-l2.a); }
        bool operator<(const Line& l2) const{
            if (l2.type == line) return this->a < l2.a;
            if (l2.type == maxQuery) return this->xLeft < l2.val;
            if (l2.type == minQuery) return this->xLeft > l2.val;
            assert(0);
            return false;
        }
    };
private:
    bool            isMax; //whether or not saved envelope is top(search of max value)
    std::set<Line>  hull;  //envelope itself
private:
    bool hasPrev(std::set<Line>::iterator it) { return it!=hull.begin(); }
    bool hasNext(std::set<Line>::iterator it) { return it!=hull.end() && std::next(it)!=hull.end(); }
    bool irrelevant(const Line& l1, const Line& l2, const Line& l3) { return intersectX(l1,l3) <= intersectX(l1,l2); }
    bool irrelevant(std::set<Line>::iterator it){
        return hasPrev(it) && hasNext(it) && ((isMax && irrelevant(*std::prev(it), *it, *std::next(it)))
                                              || (!isMax && irrelevant(*std::next(it), *it, *std::prev(it))));
    }
    std::set<Line>::iterator updateLeftBorder(std::set<Line>::iterator it){
        if ((isMax && !hasPrev(it)) || (!isMax && !hasNext(it))) return it;
        double val = intersectX(*it, isMax?*std::prev(it):*std::next(it));
        Line buf(*it);
        it = hull.erase(it), buf.xLeft = val, it = hull.insert(it, buf);
        return it;
    }
public:
    explicit CHT(): isMax(true) {} // true is for max and false is for min
    void addLine(coef_t a, coef_t b){
        Line l3 = Line(a, b);
        auto it = hull.lower_bound(l3);
        if (it!=hull.end() && areParallel(*it, l3)){
            if ((isMax && it->b < b) || (!isMax && it->b > b)) it = hull.erase(it);
            else return;
        }
        it = hull.insert(it, l3);
        if (irrelevant(it)) { hull.erase(it); return; }
        while (hasPrev(it) && irrelevant(std::prev(it))) hull.erase(std::prev(it));
        while (hasNext(it) && irrelevant(std::next(it))) hull.erase(std::next(it));
        it = updateLeftBorder(it);
        if (hasPrev(it)) updateLeftBorder(std::prev(it));
        if (hasNext(it)) updateLeftBorder(std::next(it));
    }
    val_t getBest(coord_t x) const{
        Line q;
        q.val = x, q.type = isMax ? Line::Type::maxQuery : Line::Type::minQuery;
        auto bestLine = hull.lower_bound(q);
        if (isMax) --bestLine;
        return bestLine->valueAt(x);
    }
};
//CHT

ll x[N] , y[N] , a[N];

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector <pii> v;
    for(int i = 0 ; i < n ; i++){
        cin >> x[i] >> y[i] >> a[i];
        v.push_back({y[i] , i});
    }
    sort(v.rbegin() , v.rend());
    ll ans = 0;
    CHT cht;
    cht.addLine(0 , 0);
    for(int i = 0 ; i < n ; i++){
        int id = v[i].second;
        ll val = 1ll * x[id] * y[id] - a[id] + cht.getBest(y[id]);
        ans = max(ans , val);
        cht.addLine(-x[id] , val);
    }
    cout << ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e6+10 , mod = 1e9+7;

double intersect(pair <int , ll> x , pair <int , ll> y){
   return (double)(y.second - x.second) / (x.first / y.first);
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   vector < pair <pii , ll> > v;
   for(int i = 0 ; i < n ; i++){
      int x , y;
      ll a;
      cin >> x >> y >> a;
      v.push_back({{x , y} , a});
   }
   ll ans = 0;
   sort(v.begin() , v.end());
   set < pair <int , ll> > s;
   for(int i = 0 ; i < n ; i++){
      int x = v[i].first.first , y = v[i].first.second;
      ll a = v[i].second;
      ll dp = 1ll * x * y - a;
      if(s.size()){
         auto xx = *s.begin();
         dp = max(dp , xx.second - 1ll * xx.first * y + 1ll * x * y - a);
      }
      while(s.size() > 1){
         auto it = s.end();
         it--;
         auto xx = *it;
         it--;
         auto yy = *it;
         xx.first = -xx.first;
         yy.first = -yy.first;
         if(intersect({-x , dp} , yy) >= intersect(xx , yy)){
            it++;
            s.erase(it);
         }
         else
            break;
      }
      if(s.empty() || (*s.rbegin()).second < dp)
         s.insert({x , dp});
      //cout << dp << endl;
      ans = max(ans , dp);
   }
   cout << ans;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e6+10 , mod = 1e9+7;

 double intersect(pair <int , ll> x , pair <int , ll> y){
   return (double)(y.second - x.second) / (x.first - y.first);
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   vector < pair <pii , ll> > v;
   for(int i = 0 ; i < n ; i++){
      int x , y;
      ll a;
      cin >> x >> y >> a;
      v.push_back({{x , y} , a});
   }
   ll ans = 0;
   sort(v.begin() , v.end());
   set < pair <int , ll> > s;
   for(int i = 0 ; i < n ; i++){
      int x = v[i].first.first , y = v[i].first.second;
      ll a = v[i].second;
      while(s.size() > 1){
         auto it = s.begin();
         auto xx = *it;
         it++;
         auto yy = *it;
         xx.first = -xx.first;
         yy.first = -yy.first;
         if(intersect(xx , yy) >= y){
            s.erase(s.begin());
         }
         else
            break;
      }
      ll dp = 1ll * x * y - a;
      if(s.size()){
         auto xx = *s.begin();
         dp = max(dp , xx.second - 1ll * xx.first * y + 1ll * x * y - a);
      }
      while(s.size() > 1){
         auto it = s.end();
         it--;
         auto xx = *it;
         it--;
         auto yy = *it;
         xx.first = -xx.first;
         yy.first = -yy.first;
         if(intersect({-x , dp} , yy) >= intersect(xx , yy)){
            it++;
            s.erase(it);
         }
         else
            break;
      }

      s.insert({x , dp});
      /*cout << i << ":" << endl;
      for(auto xxx : s)
         cout << xxx.first << " " << xxx.second << endl;*/
      ans = max(ans , dp);
   }
   cout << ans;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e6+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   vector < pair <pii , int> > v;
   for(int i = 0 ; i < n ; i++){
      int x , y , a;
      cin >> x >> y >> a;
      v.push_back({{x , y} , a});
   }
   ll ans = 0;
   sort(v.begin() , v.end());
   set < pair <int , ll> > s;
   for(int i = 0 ; i < n ; i++){
      int x = v[i].first.first , y = v[i].first.second , a = v[i].second;
      while(s.size() > 1){
         auto it = s.begin();
         auto xx = *it;
         it++;
         auto yy = *it;
         if(yy.second - 1ll * yy.first * y >= xx.second + 1ll * xx.first * y)
            s.erase(s.begin());
         else
            break;
      }
      ll dp = x * y - a;
      if(s.size()){
         auto xx = *s.begin();
         dp = max(dp , xx.second - 1ll * xx.first * y + 1ll * x * y - a);
      }
      if(s.empty() || (*s.rbegin()).second < dp)
         s.insert({x , dp});
      //cout << dp << endl;
      ans = max(ans , dp);
   }
   cout << ans;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e6+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   vector < pair <pii , ll> > v;
   for(int i = 0 ; i < n ; i++){
      int x , y;
      ll a;
      cin >> x >> y >> a;
      v.push_back({{x , y} , a});
   }
   ll ans = 0;
   sort(v.begin() , v.end());
   set < pair <int , ll> > s;
   for(int i = 0 ; i < n ; i++){
      int x = v[i].first.first , y = v[i].first.second;
      ll a = v[i].second;
      while(s.size() > 1){
         auto it = s.end();
         it--;
         auto xx = *it;
         it--;
         auto yy = *it;
         if(yy.second - 1ll * yy.first * y >= xx.second + 1ll * xx.first * y){
            it++;
            s.erase(it);
         }
         else
            break;
      }
      ll dp = 1ll * x * y - a;
      if(s.size()){
         auto xx = *s.begin();
         dp = max(dp , xx.second - 1ll * xx.first * y + 1ll * x * y - a);
      }
      if(s.empty() || (*s.rbegin()).second < dp)
         s.insert({x , dp});
      //cout << dp << endl;
      ans = max(ans , dp);
   }
   cout << ans;
   return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int , int> pii;

const int N = 1e6+10 , mod = 1e9+7;

double intersect(pair <int , ll> x , pair <int , ll> y){
   return (double)(y.second - x.second) / (x.first / y.first);
}

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   vector < pair <pii , ll> > v;
   for(int i = 0 ; i < n ; i++){
      int x , y;
      ll a;
      cin >> x >> y >> a;
      v.push_back({{x , y} , a});
   }
   ll ans = 0;
   sort(v.begin() , v.end());
   set < pair <int , ll> > s;
   for(int i = 0 ; i < n ; i++){
      int x = v[i].first.first , y = v[i].first.second;
      ll a = v[i].second;
      ll dp = 1ll * x * y - a;
      if(s.size()){
         auto xx = *s.begin();
         dp = max(dp , xx.second - 1ll * xx.first * y + 1ll * x * y - a);
      }
      while(s.size() > 1){
         auto it = s.end();
         it--;
         auto xx = *it;
         it--;
         auto yy = *it;
         xx.first = -xx.first;
         yy.first = -yy.first;
         if(intersect({-x , dp} , yy) >= intersect(xx , yy)){
            it++;
            s.erase(it);
         }
         else
            break;
      }
      s.insert({x , dp});
      //cout << dp << endl;
      ans = max(ans , dp);
   }
   cout << ans;
   return 0;
}