output_description: Find the minimum possible absolute difference of the maximum and the minimum
  among P,Q,R,S.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
attempt: N = int(input())
  A = list(map(int, input().split()))
  
  
  # 累積
  acc = [0]
  for i in range(N):
      acc.append(acc[i] + A[i])
  
  
  def dev_sec(start, end, previous_best):
      # check left
      dif_min = 10**10
      best_p = -1
      best_q = -1
      best_sep = previous_best
  
      for p_end in range(previous_best, end):
          sum_of_p = acc[p_end + 1] - acc[start]
          sum_of_q = acc[end + 1] - acc[p_end + 1]
          # sumの最小
          dif = abs(sum_of_p - sum_of_q)
          if dif_min > dif:
              dif_min = dif
              best_p = sum_of_p
              best_q = sum_of_q
              best_sep = p_end
          else:
              break
      return best_p, best_q, best_sep
  
  
  dif_min = 10**10
  previous_best_left = 0
  previous_best_right = 2
  for left_end in range(1, N - 2):
  
      p, q, previous_best_left = dev_sec(0, left_end, previous_best_left)
      r, s, previous_best_right = dev_sec(left_end + 1, N - 1, previous_best_right)
  
      dif = max(p, q, r, s) - min(p, q, r, s)
      if dif_min > dif:
          dif_min = dif
  print(dif_min)
  
problem_description: Statement
  
  Snuke has an integer sequence A of length N.
  
  He will make three cuts in A and divide it into four (non-empty) contiguous
  subsequences B, C, D and E. The positions of the cuts can be freely chosen.
  
  Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively. Snuke is
  happier when the absolute difference of the maximum and the minimum among
  P,Q,R,S is smaller. Find the minimum possible absolute difference of the
  maximum and the minimum among P,Q,R,S.
samples: [{"input": "5\n    3 2 4 1 2", "output": "2\n    \n\nIf we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3. Here,\nthe maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute\ndifference of 2. We cannot make the absolute difference of the maximum and the\nminimum less than 2, so the answer is 2.\n\n* * *"}, {"input": "10\n    10 71 84 33 6 47 23 25 52 64", "output": "36\n    \n\n* * *"}, {"input": "7\n    1 2 3 1000000000 4 5 6", "output": "999999994"}]