Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def h(i,j):
  ci,cj = C[i],C[j]
  k = bisect(C, (ci+cj)//2, lo=i+1,hi=j)
  _,a,b = min((abs(ci+cj-2*c),cj-c,c-ci) for c in (C[k-1],C[k]))
  return a,b

def solve(x):
  L = h(0,x)+h(x,N)
  return max(L)-min(L)

print(min(solve(i) for i in range(2,N-2)))

Fixed submission:
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def h(i,j):
  ci,cj = C[i],C[j]
  k = bisect(C, (ci+cj)//2, lo=i+1,hi=j)
  _,a,b = min((abs(ci+cj-2*c),cj-c,c-ci) for c in (C[k-1],C[k]))
  return a,b

def solve(x):
  L = h(0,x)+h(x,N)
  return max(L)-min(L)

print(min(solve(i) for i in range(2,N-1)))

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def solve(x):
  def h(i,j):
    m = (C[j]+C[i])//2
    k = bisect(C, m, lo=i+1,hi=j)

    _,a,b = min((abs(m-C[x]),C[x]-C[i],C[j]-C[x]) for x in (k-1,k))
    return a,b

  L = h(0,x)+h(x,N)
  return max(L)-min(L)

print(min(solve(i) for i in range(2,N-2)))

Fixed submission:
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def h(i,j):
  ci,cj = C[i],C[j]
  k = bisect(C, (ci+cj)//2, lo=i+1,hi=j)
  _,a,b = min((abs(ci+cj-2*c),cj-c,c-ci) for c in (C[k-1],C[k]))
  return a,b

def solve(x):
  L = h(0,x)+h(x,N)
  return max(L)-min(L)

print(min(solve(i) for i in range(2,N-1)))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
from bisect import bisect_left

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def helper(i,j):
  m = (C[j]+C[i])/2
  k = bisect_left(C, m, lo=i+1,hi=j-1)

  if k > i+1:
    _,a,b = min((abs(m-C[x]),C[x]-C[i],C[j]-C[x]) for x in (k-1,k))
  else:
    a,b = C[k]-C[i],C[j]-C[k]
  return a,b


m = bisect_left(C,C[N]/2)
if m < 2:
  m = 2
elif m > N-2:
  m = N-2

L = helper(0,m)+helper(m,N)
best = max(L)-min(L)

i = m+1
while i < N-1 and abs(abs(C[N]-C[i])-abs(C[i])) < best*2:
  L = helper(0,i)+helper(i,N)
  best = min(best, max(L)-min(L))
  i += 1

i = m-1
while i > 1 and abs(abs(C[N]-C[i])-abs(C[i])) < best*2:
  L = helper(0,i)+helper(i,N)
  best = min(best, max(L)-min(L))
  i -= 1


print(best)

Fixed submission:
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def h(i,j):
  ci,cj = C[i],C[j]
  k = bisect(C, (ci+cj)//2, lo=i+1,hi=j)
  _,a,b = min((abs(ci+cj-2*c),cj-c,c-ci) for c in (C[k-1],C[k]))
  return a,b

def solve(x):
  L = h(0,x)+h(x,N)
  return max(L)-min(L)

print(min(solve(i) for i in range(2,N-1)))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
from bisect import bisect
N = int(input())
A = list(map(int,input().split()))
C = [0]+list(accumulate(A))

def helper(i,j):
  m = (C[j]+C[i])/2
  k = bisect(C, m, lo=i,hi=j)
  if k == i:
    k += 1
  elif k == j:
    k -= 1

  if k > 0:
    _,a,b = min((abs(m-C[x]),C[x]-C[i],C[j]-C[x]) for x in (k-1,k))
  else:
    a,b = C[k]-C[i],C[j]-C[k]

  return a,b

m = bisect(C,C[N]/2)
if m < 2:
  m = 2
elif m > N-2:
  m = N-2

L = helper(0,m)+helper(m,N)
best = max(L)-min(L)
i = m+1
while i < N-1 and (2*C[i]-C[N]) < best*2:
  L = helper(0,i)+helper(i,N)
  best = min(best, max(L)-min(L))
  i += 1
i = m-1
while i > 1 and (C[N]-2*C[i]) < best*2:
  L = helper(0,i)+helper(i,N)
  best = min(best, max(L)-min(L))
  i -= 1


print(best)

Fixed submission:
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def h(i,j):
  ci,cj = C[i],C[j]
  k = bisect(C, (ci+cj)//2, lo=i+1,hi=j)
  _,a,b = min((abs(ci+cj-2*c),cj-c,c-ci) for c in (C[k-1],C[k]))
  return a,b

def solve(x):
  L = h(0,x)+h(x,N)
  return max(L)-min(L)

print(min(solve(i) for i in range(2,N-1)))

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
from bisect import bisect
N = int(input())
A = list(map(int,input().split()))
C = [0]+list(accumulate(A))

def helper(i,j):
  m = (C[j]+C[i])/2
  k = bisect(C, m, lo=i,hi=j)
  if k == i:
    k += 1
  elif k == j:
    k -= 1

  if k > 0:
    _,a,b = min((abs(m-C[x]),C[x]-C[i],C[j]-C[x]) for x in (k-1,k))
  else:
    a,b = C[k]-C[i],C[j]-C[k]

  return a,b

best = float('inf')

for i in range(2,N-1):
  L = helper(0,i)+helper(i,N)
  best = min(best,max(L)-min(L))

print(best)

Fixed submission:
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def h(i,j):
  ci,cj = C[i],C[j]
  k = bisect(C, (ci+cj)//2, lo=i+1,hi=j)
  _,a,b = min((abs(ci+cj-2*c),cj-c,c-ci) for c in (C[k-1],C[k]))
  return a,b

def solve(x):
  L = h(0,x)+h(x,N)
  return max(L)-min(L)

print(min(solve(i) for i in range(2,N-1)))

Buggy python submission (verdict: Runtime Error):
from itertools import accumulate
from bisect import bisect
N = int(input())
A = list(map(int,input().split()))
C = [0]+list(accumulate(A))

def helper(i,j):
  m = (C[j]+C[i])/2
  k = bisect(C, m, lo=i,hi=j)
  if k == i:
    k += 1
  elif k == j:
    k -= 1

  if k > 0:
    _,a,b = min((abs(m-C[x]),C[x]-C[i],C[j]-C[x]) for x in (k-1,k))
  else:
    a,b = C[k]-C[i],C[j]-C[k]

  return a,b

best = float('inf')

for i in range(2,N-1):
  L = (*helper(0,i),*helper(i,N))
  best = min(best,max(L)-min(L))

print(best)

Fixed submission:
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))

def h(i,j):
  ci,cj = C[i],C[j]
  k = bisect(C, (ci+cj)//2, lo=i+1,hi=j)
  _,a,b = min((abs(ci+cj-2*c),cj-c,c-ci) for c in (C[k-1],C[k]))
  return a,b

def solve(x):
  L = h(0,x)+h(x,N)
  return max(L)-min(L)

print(min(solve(i) for i in range(2,N-1)))