#include <bits/stdc++.h>
using namespace std;
const int maxn = 510;
int n;
long long lx[maxn], ly[maxn], slack_y[maxn], g[maxn][maxn];
int mx[maxn];
bool vx[maxn], vy[maxn];
bool dfs(int x, bool extend) {
  if (vx[x]) return false;
  vx[x] = true;
  for (int y = 1; y <= n; y++) {
    if (vy[y]) continue;
    long long d = lx[x] + ly[y] - g[x][y];
    if (d == 0) {
      vy[y] = true;
      if (mx[y] == -1 || dfs(mx[y], extend)) {
        if (extend) mx[y] = x;
        return true;
      }
    } else if (d < slack_y[y])
      slack_y[y] = d;
  }
  return false;
}
long long solve() {
  for (int i = 1; i <= n; i++) {
    lx[i] = -(1ll << 62);
    ly[i] = 0;
    mx[i] = -1;
    for (int j = 1; j <= n; j++) lx[i] = max(lx[i], g[i][j]);
  }
  for (int x = 1; x <= n; x++) {
    for (int y = 1; y <= n; y++) slack_y[y] = 1ll << 62;
    memset(vx, 0, sizeof vx);
    memset(vy, 0, sizeof vy);
    if (dfs(x, true)) continue;
    bool fin = false;
    while (!fin) {
      long long delta = 1ll << 62;
      for (int y = 1; y <= n; y++)
        if (!vy[y] && delta > slack_y[y]) delta = slack_y[y];
      for (int i = 1; i <= n; i++) {
        if (vx[i]) lx[i] -= delta;
        if (vy[i])
          ly[i] += delta;
        else
          slack_y[i] -= delta;
      }
      for (int y = 1; y <= n; y++) {
        if (!vy[y] && slack_y[y] == 0) {
          vy[y] = true;
          if (mx[y] == -1 || dfs(mx[y], false)) {
            fin = true;
            break;
          }
        }
      }
    }
    memset(vx, 0, sizeof vx);
    memset(vy, 0, sizeof vy);
    dfs(x, true);
  }
  long long ret = 0;
  for (int i = 1; i <= n; i++) ret += lx[i] + ly[i];
  return ret;
}
int main() {
  int a, b, k;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d", &a, &b, &k);
    for (int j = 1; j <= n; j++) {
      g[i][j] = max(0ll, a - (long long)b * min(k, n - j));
    }
  }
  printf("%lld\n", solve());
  return 0;
}
