#include <bits/stdc++.h>
using namespace std;
struct aaa {
  long long val, w, len;
} a[500010];
long long n, i, j, ans, f[5100][5010];
bool cmp(aaa a, aaa b) { return a.w > b.w; }
int main() {
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) scanf("%lld%lld%lld", &a[i].val, &a[i].w, &a[i].len);
  sort(a + 1, a + n + 1, cmp);
  for (i = 1; i <= n; i++) {
    for (j = 0; j < i; j++) {
      f[i][j] = max(f[i][j], f[i - 1][j]);
      f[i][j] = max(f[i][j], f[i - 1][j] + a[i].val - a[i].w * a[i].len);
      f[i][j + 1] = max(f[i][j + 1], f[i - 1][j] + a[i].val - a[i].w * j);
    }
  }
  for (i = 0; i <= n; i++) ans = max(ans, f[n][i]);
  printf("%lld", ans);
}
