Buggy python submission (verdict: Time Limit Exceeded):
import numpy
from bisect import bisect_left, bisect_right

N = int(input())
A = list(map(int, input().split()))
A_sum = numpy.cumsum(A)

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  i=bisect_left(A_sum,sum_left/2)
  sum1=A_sum[i]
  if i!=0:
    if A_sum[i]+A_sum[i-1]>sum_left:
      sum1=A_sum[i-1]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  i=bisect_left(A_sum,sum_left+sum_right/2)
  sum3=A_sum[i]-sum_left
  if i!=m:
    if A_sum[i]+A_sum[i-1]-2*sum_left>sum_right:
      sum3=A_sum[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A_sum = list(accumulate(A))

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  i=bisect_left(A_sum,sum_left/2)
  sum1=A_sum[i]
  if i!=0:
    if A_sum[i]+A_sum[i-1]>sum_left:
      sum1=A_sum[i-1]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  i=bisect_left(A_sum,sum_left+sum_right/2)
  sum3=A_sum[i]-sum_left
  if i!=m:
    if A_sum[i]+A_sum[i-1]-2*sum_left>sum_right:
      sum3=A_sum[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy

N = int(input())
A = list(map(int, input().split()))
A_sum = numpy.cumsum(A)

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  for i in range(1,m):
    if A_sum[i-1]>=sum_left/2:
      break
  sum1=A_sum[i-1]
  if i!=1:
    if A_sum[i-1]+A_sum[i-2]>sum_left:
      sum1=A_sum[i-2]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  for i in range(m+1,N):
    if A_sum[i-1]-sum_left>=sum_right/2:
      break
  sum3=A_sum[i-1]-sum_left
  if i!=m+1:
    if A_sum[i-1]+A_sum[i-2]-2*sum_left>sum_right:
      sum3=A_sum[i-2]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A_sum = list(accumulate(A))

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  i=bisect_left(A_sum,sum_left/2)
  sum1=A_sum[i]
  if i!=0:
    if A_sum[i]+A_sum[i-1]>sum_left:
      sum1=A_sum[i-1]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  i=bisect_left(A_sum,sum_left+sum_right/2)
  sum3=A_sum[i]-sum_left
  if i!=m:
    if A_sum[i]+A_sum[i-1]-2*sum_left>sum_right:
      sum3=A_sum[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy

N = int(input())
A = list(map(int, input().split()))
A_sum = numpy.cumsum(A)

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  for i in range(1,m):
    sum1=A_sum[i-1]
    sum2=sum_left-sum1
    if sum2<sum1:
      break
  if i!=1:
    if sum1-sum2>sum_left-2*A_sum[i-2]:
      sum1=A_sum[i-2]
      sum2=sum_left-sum1
  
  sum_right=A_sum[N-1]-sum_left
  for i in range(m+1,N):
    sum3=A_sum[i-1]-sum_left
    sum4=sum_right-sum3
    if sum4<sum3:
      break
  if i!=m+1:
    if sum3-sum4>sum_right-2*(A_sum[i-2]-sum_left):
      sum3=A_sum[i-2]-sum_left
      sum4=sum_left-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A_sum = list(accumulate(A))

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  i=bisect_left(A_sum,sum_left/2)
  sum1=A_sum[i]
  if i!=0:
    if A_sum[i]+A_sum[i-1]>sum_left:
      sum1=A_sum[i-1]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  i=bisect_left(A_sum,sum_left+sum_right/2)
  sum3=A_sum[i]-sum_left
  if i!=m:
    if A_sum[i]+A_sum[i-1]-2*sum_left>sum_right:
      sum3=A_sum[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans=sum(A)
for a in range(3,N):
  for b in range(2,a):
    for c in range(1,b):
      sum1=sum(A[:c])
      sum2=sum(A[c:b])
      sum3=sum(A[b:a])
      sum4=sum(A[a:])
      dif=max(sum1,sum2,sum3,sum4)-min(sum1,sum2,sum3,sum4)
      if dif<ans:
        ans=dif
      if sum2<=sum1:
        break
    if min(sum1,sum2,sum3)==sum3:
      break
  if min(sum1,sum2,sum3,sum4)==sum4:
    break

print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A_sum = list(accumulate(A))

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  i=bisect_left(A_sum,sum_left/2)
  sum1=A_sum[i]
  if i!=0:
    if A_sum[i]+A_sum[i-1]>sum_left:
      sum1=A_sum[i-1]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  i=bisect_left(A_sum,sum_left+sum_right/2)
  sum3=A_sum[i]-sum_left
  if i!=m:
    if A_sum[i]+A_sum[i-1]-2*sum_left>sum_right:
      sum3=A_sum[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans=sum(A)
for a in range(3,N):
  for b in range(2,a):
    for c in range(1,b):
      sum1=sum(A[:c])
      sum2=sum(A[c:b])
      sum3=sum(A[b:a])
      sum4=sum(A[a:])
      dif=max(sum1,sum2,sum3,sum4)-min(sum1,sum2,sum3,sum4)
      if dif<ans:
        ans=dif

print(ans)

Fixed submission:
from bisect import bisect_left, bisect_right
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
A_sum = list(accumulate(A))

ans=A_sum[N-1]
for m in range(2,N-1):
  sum_left=A_sum[m-1]
  i=bisect_left(A_sum,sum_left/2)
  sum1=A_sum[i]
  if i!=0:
    if A_sum[i]+A_sum[i-1]>sum_left:
      sum1=A_sum[i-1]
  sum2=sum_left-sum1

  sum_right=A_sum[N-1]-sum_left
  i=bisect_left(A_sum,sum_left+sum_right/2)
  sum3=A_sum[i]-sum_left
  if i!=m:
    if A_sum[i]+A_sum[i-1]-2*sum_left>sum_right:
      sum3=A_sum[i-1]-sum_left
  sum4=sum_right-sum3
  max_sum=max(sum1,sum2,sum3,sum4)
  min_sum=min(sum1,sum2,sum3,sum4)
  dif=max_sum-min_sum
  if dif<ans:
    ans=dif

print(ans)