#54471: 不是最佳解,但AC,可以參考看看。


tcr980328@gmail.com (蔡承融)


import itertools

all = []
n = int(input())
for i in range(n):
  s,d,t = map(int, input().split())
  all.append([s,d,t])

ans = 0
for order in itertools.permutations(all):
  low = 0
  high = 1000
  best = 0
  while low <= high:
    mid = (low + high) // 2
    times = 0
    p = True
    for i in range(n):
      s, d, t = order[i]
      if i > 0:
        times += mid
      if times < s:
        times = s
      if times + t > d:
        p = False
        break

      times += t
    if p:
      best = mid
      low = mid + 1
    else:
      high = mid - 1
  if best > ans:
    ans = best
print(ans)