include[HTML_REMOVED]
using namespace std;
define int long long
int n;
struct per{
int p,w,d;
}P[200005];
int check(int x) {
int res = 0;
for(int i = 0 ; i < n ; i ++) {
int p = P[i].p,w = P[i].w,d = P[i].d;
if(p + d >= x &&p - d <= x)continue;
if(p + d < x)res += (x - p - d) * w;
if(p - d > x)res += (p - d - x) * w;
}
return res;
}
signed main() {
cin >> n;
for(int i = 0 ;i < n ;i ++) {
cin>> P[i].p >> P[i].w >> P[i].d;
}
int l = 0,r = 1e9;
while(l < r) {
int midl = l + (r - l)/3;
int midr = r - (r - l) / 3;
if(check(midl) >= check(midr))l = midl + 1;
else r = midr - 1;
}
cout << min(check(l),check(r)) << endl;
return 0;
}