Buggy python submission (verdict: Time Limit Exceeded):
from numpy import*
n,a=open(0)
n=int(n)
a=cumsum(int64([0]+a.split()))
dp=zeros((n,n+1),'i8')
for k in range(1,n):
  l=arange(n-k)
  r=arange(k+1,n+1)
  m=array([arange(i+1,j)for i,j in zip(l,r)]).T
  dp[l,r]=amin(dp[l,m]+dp[m,r],0)+a[r]-a[l]
print(dp[0,n])

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Buggy python submission (verdict: Time Limit Exceeded):
from numpy import*
n,a=open(0)
n=int(n)
a=cumsum(int64([0]+a.split()))
dp=zeros((n,n+1),'i8')
for k in range(1,n):
  l=arange(n-k)
  r=arange(k+1,n+1)
  dp[l,r]=amin([dp[l,m]+dp[m,r]for m in array([arange(i+1,j)for i,j in zip(l,r)]).T],0)+a[r]-a[l]
print(dp[0,n])

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    if(l,r)in d:return d[(l,r)]
    if r-l<2:return 0
    d[(l,r)]=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return d[(l,r)]
  d={}
  n,*a=map(int,open(0).read().split())
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from functools import*
sys.setrecursionlimit(10**7)
@lru_cache(None)
def s(l,r):
  if r-l<2:return 0
  return min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
n,*a=map(int,open(0).read().split())
for i in range(n-1):a[i+1]+=a[i]
a+=[0]
print(s(0,n))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Buggy python submission (verdict: Runtime Error):
from functools import*
@lru_cache(None)
def s(l,r):
  if r-l<2:return 0
  return min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
n,*a=map(int,open(0).read().split())
for i in range(n-1):a[i+1]+=a[i]
a+=[0]
print(s(0,n))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Buggy python submission (verdict: Runtime Error):
from functools import*
@lru_cache(None)
def s(a,d):
  n=len(a)
  if n==1:return a[0]*d
  return min(s(a[:i],d+1)+s(a[i:],d+1)for i in range(1,n))
n,*a=map(int,open(0).read().split())
print(s(tuple(a),0))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()

Buggy python submission (verdict: Time Limit Exceeded):
def s(a,d):
  n=len(a)
  if n==1:return a[0]*d
  return min(s(a[:i],d+1)+s(a[i:],d+1)for i in range(1,n))
n,*a=map(int,open(0).read().split())
print(s(a,0))

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
def main():
  def s(l,r):
    k=l*n+r
    if d[k]:return d[k]
    if r-l<2:return 0
    d[k]=t=min(s(l,i)+s(i,r)for i in range(l+1,r))+a[r-1]-a[l-1]
    return t
  n,*a=map(int,open(0).read().split())
  d=[None]*(n*n+1)
  for i in range(n-1):a[i+1]+=a[i]
  a+=[0]
  print(s(0,n))
main()