output_description: Print the amount you have left after shopping.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      X
      A
      B
attempt: n = int(input())
  
  
  def c(x, y):
      if 0 <= x < n and 0 <= y < 2:
          if cache[y][x] != " ":
              return cache[y][x]
  
          if x == 0 and y == 0:
              total = matrice[0][0]
          else:
              if x > 0:
                  tt1 = c(x - 1, y)
              else:
                  tt1 = 0
              if y > 0:
                  tt2 = c(x, y - 1)
              else:
                  tt2 = 0
              total = max(tt1, tt2) + matrice[y][x]
          cache[y][x] = total
          return total
  
  
  matrice = []
  cache = [[" " for i in range(n)] for a in range(2)]
  for i in range(2):
      matrice.append([int(i) for i in input().split()])
  
  print(c(n - 1, 1))
  
problem_description: Statement
  
  You went shopping to buy cakes and donuts with X yen (the currency of Japan).
  
  First, you bought one cake for A yen at a cake shop. Then, you bought as many
  donuts as possible for B yen each, at a donut shop.
  
  How much do you have left after shopping?
samples: [{"input": "1234\n    150\n    100", "output": "84\n    \n\nYou have 1234 - 150 = 1084 yen left after buying a cake. With this amount, you\ncan buy 10 donuts, after which you have 84 yen left.\n\n* * *"}, {"input": "1000\n    108\n    108", "output": "28\n    \n\n* * *"}, {"input": "579\n    123\n    456", "output": "0\n    \n\n* * *"}, {"input": "7477\n    549\n    593", "output": "405"}]