output_description: Print the maximum total number of monsters the heroes can defeat.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_{N+1}
      B_1 B_2 ... B_N
attempt: # -*- coding: utf-8 -*-
  N = int(input())
  A = list(map(int, input().split()))
  B = list(map(int, input().split()))
  reverse_A = list(reversed(A))
  reverse_B = list(reversed(B))
  sum = 0
  
  if (B[N - 1] - A[N]) >= (B[0] - A[0]):
      for n in range(len(reverse_A)):
          if n == 0:
              if (reverse_B[n] - reverse_A[n]) >= 0:
                  sum += reverse_A[n]
                  temp = reverse_B[n] - reverse_A[n]
              else:
                  sum += reverse_B[n]
                  temp = 0
          elif n >= 1 and n <= (N - 1):
              if (temp + reverse_B[n] - reverse_A[n]) >= 0:
                  sum += reverse_A[n]
                  if (temp - reverse_A[n]) >= 0:
                      temp = reverse_B[n]
                  else:
                      temp = temp + reverse_B[n] - reverse_A[n]
              else:
                  sum += reverse_B[n]
                  temp = 0
          elif n == N:
              if (temp - reverse_A[n]) >= 0:
                  sum += reverse_A[n]
              else:
                  sum += temp
  else:
      for n in range(len(A)):
          if n == 0:
              if (B[n] - A[n]) >= 0:
                  sum += A[n]
                  temp = B[n] - A[n]
              else:
                  sum += B[n]
                  temp = 0
          elif n >= 1 and n <= (N - 1):
              if (temp + B[n] - A[n]) >= 0:
                  sum += A[n]
                  if (temp - A[n]) >= 0:
                      temp = B[n]
                  else:
                      temp = temp + B[n] - A[n]
              else:
                  sum += B[n]
                  temp = 0
          elif n == N:
              if (temp - A[n]) >= 0:
                  sum += A[n]
              else:
                  sum += temp
  print(sum)
  
problem_description: Statement
  
  There are N+1 towns. The i-th town is being attacked by A_i monsters.
  
  We have N heroes. The i-th hero can defeat monsters attacking the i-th or
  (i+1)-th town, for a total of at most B_i monsters.
  
  What is the maximum total number of monsters the heroes can cooperate to
  defeat?
samples: [{"input": "2\n    3 5 2\n    4 5", "output": "9\n    \n\nIf the heroes choose the monsters to defeat as follows, they can defeat nine\nmonsters in total, which is the maximum result.\n\n  * The first hero defeats two monsters attacking the first town and two monsters attacking the second town.\n  * The second hero defeats three monsters attacking the second town and two monsters attacking the third town.\n\n* * *"}, {"input": "3\n    5 6 3 8\n    5 100 8", "output": "22\n    \n\n* * *"}, {"input": "2\n    100 1 1\n    1 100", "output": "3"}]