output_description: Print an integer representing the minimum amount of money needed before
  cutting the bar into two parts with the same length.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 A_3 ... A_N
attempt: # 2019/11/23
  # DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選 - B
  
  
  # Binary Search
  def binSearch(tlis, tval):
      lf = 0
      rg = len(tlis)
      while lf <= rg:
          ct = int((lf + rg) / 2)
          if tlis[ct] < tval:
              lf = ct + 1
          elif tlis[ct] > tval:
              rg = ct - 1
          else:
              return ct
      return ct
  
  
  # Input
  n = int(input())
  a = list(map(int, input().split()))
  acm_a = list()
  acm_a.append(0)
  
  # Sum
  for i in range(len(a)):
      acm_a.append(a[i] + acm_a[i])
  
  acm_a.append(acm_a[len(a)])
  # Calc Center
  center = acm_a[len(a)] / 2
  ctidx = binSearch(acm_a, center)
  
  ans = min(
      abs((acm_a[len(a)] - acm_a[ctidx - 1]) - acm_a[ctidx - 1]),
      abs((acm_a[len(a)] - acm_a[ctidx]) - acm_a[ctidx]),
      abs((acm_a[len(a)] - acm_a[ctidx + 1]) - acm_a[ctidx + 1]),
  )
  
  # Output
  print(ans)
  
problem_description: Statement
  
  Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1
  notches, which divide the bar into N sections. The i-th section from the left
  has a length of A_i millimeters.
  
  Takahashi wanted to choose a notch and cut the bar at that point into two
  parts with the same length. However, this may not be possible as is, so he
  will do the following operations some number of times **before** he does the
  cut:
  
    * Choose one section and expand it, increasing its length by 1 millimeter. Doing this operation once costs 1 yen (the currency of Japan).
    * Choose one section of length at least 2 millimeters and shrink it, decreasing its length by 1 millimeter. Doing this operation once costs 1 yen.
  
  Find the minimum amount of money needed before cutting the bar into two parts
  with the same length.
samples: [{"input": "3\n    2 4 3", "output": "3\n    \n\nThe initial lengths of the sections are [2, 4, 3] (in millimeters). Takahashi\ncan cut the bar equally after doing the following operations for 3 yen:\n\n  * Shrink the second section from the left. The lengths of the sections are now [2, 3, 3].\n  * Shrink the first section from the left. The lengths of the sections are now [1, 3, 3].\n  * Shrink the second section from the left. The lengths of the sections are now [1, 2, 3], and we can cut the bar at the second notch from the left into two parts of length 3 each.\n\n* * *"}, {"input": "12\n    100 104 102 105 103 103 101 105 104 102 104 101", "output": "0"}]