output_description: If we have x hours until New Year at M o'clock on 30th, December, print x.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      M
attempt: n = int(input())
  cc = []
  ss = []
  ff = []
  for i in range(n - 1):
      c, s, f = list(map(int, input().split()))
      cc.append(c)
      ss.append(s)
      ff.append(f)
  for l in range(n - 1):
      ans = ss[l] + cc[l]
      for k in range(l + 1, n - 1):
          temp = ss[k]
          while temp < ans:
              temp += ff[k]
          ans = temp + cc[k]
      print(ans)
  print(0)
  
problem_description: Statement
  
  How many hours do we have until New Year at M o'clock (24-hour notation) on
  30th, December?
samples: [{"input": "21", "output": "27\n    \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]