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: # -*- coding: utf-8 -*-
  from sys import stdin
  import numpy as np
  
  d_in = lambda: int(stdin.readline())  # N = d_in()
  ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()
  
  
  def left_diff(array):
      """
      array: ordered ndarray, len(array) >= 2
      """
      x = (array[-1] + 1) >> 1
      mid = np.searchsorted(array, x)
      if abs(array[-1] - array[mid] * 2) < abs(array[-1] - array[mid - 1] * 2):
          return array[mid], array[-1] - array[mid]
      else:
          return array[mid - 1], array[-1] - array[mid - 1]
  
  
  def right_diff(array, offset):
      """
      array: ordered ndarray, len(array) >= 2
          target array or list
  
      offset: int
          offset value for right array
      """
      x = (array[-1] - offset + 1) >> 1
      mid = np.searchsorted(array, x + offset)
      if abs(array[-1] - array[mid] * 2 + offset) < abs(
          array[-1] - array[mid - 1] * 2 + offset
      ):
          return array[mid] - offset, array[-1] - array[mid]
      else:
          return array[mid - 1] - offset, array[-1] - array[mid - 1]
  
  
  def calc_max_diff(p, q, r, s):
      return max(p, q, r, s) - min(p, q, r, s)
  
  
  if __name__ == "__main__":
      N = d_in()
      a_array = np.array(ds_in())
  
      cum_a = np.cumsum(a_array)
      left_cut_points = (cum_a[1:-2] + 1) // 2
      left_mid_points = np.searchsorted(cum_a, left_cut_points)
      right_cut_points = (cum_a[-1] + cum_a[1:-2] + 1) // 2
      right_mid_points = np.searchsorted(cum_a, right_cut_points)
  
      ans = float("inf")
      for i in range(2):
          for j in range(2):
              P = cum_a[left_mid_points - i]
              Q = cum_a[1:-2] - P
              R = cum_a[right_mid_points - j] - cum_a[1:-2]
              S = cum_a[-1] - cum_a[right_mid_points - j]
              MAX = np.maximum(np.maximum(P, Q), np.maximum(R, S))
              MIN = np.minimum(np.minimum(P, Q), np.minimum(R, S))
              ans = min(ans, (MAX - MIN).min())
  
      print(ans)
  
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"}]