W = int(input()) d = [(0, 0)] #points, money w = [(0, 0)] s = [] def merge(school, work, date, a, b, c): #date res_d = [(x + b, y - c) for x, y in school] res_s, res_w = [], [] work.reverse(); date.reverse() while work and date: if work[-1][0] < date[-1][0]: score, money = work.pop() else: score, money = date.pop() while res_s and res_s[-1][1] <= money: res_s.pop() res_w.pop() res_s.append((score, money)) res_w.append((score, money + a)) while work: score, money = work.pop() while res_s and res_s[-1][1] <= money: res_s.pop() res_w.pop() res_s.append((score, money)) res_w.append((score, money + a)) while date: score, money = date.pop() while res_s and res_s[-1][1] <= money: res_s.pop() res_w.pop() res_s.append((score, money)) res_w.append((score, money + a)) return res_s, res_w, res_d for _ in range(W): a, b, c = map(int, input().split()) s, w, d = merge(s, w, d, a, b, c) ans = 0 for score, money in s: if money >= 0: ans = max(ans, score) for score, money in w: if money >= 0: ans = max(ans, score) for score, money in d: if money >= 0: ans = max(ans, score) print(ans)