N=int(eval(input()))

A=list(map(int,input().split()))



DPLIST=[[None]*N for i in range(N)]



for i in range(N):

    DPLIST[i][i]=[0,A[i]]



for i in range(1,N):

    for j in range(i,N):

        #print(i,j)

        ANS=float("inf")

        slime=float("inf")



        for k in range(j-i,j):

            sc1,sl1=DPLIST[j-i][k]

            sc2,sl2=DPLIST[k+1][j]



            if ANS>sc1+sc2+sl1+sl2:

                ANS=sc1+sc2+sl1+sl2

                slime=sl1+sl2

        

        DPLIST[j-i][j]=[ANS,slime]



    #print(DPLIST)

    #print()

            



print((DPLIST[0][N-1][0]))
N=int(eval(input()))

A=list(map(int,input().split()))



DPLIST=[[None]*N for i in range(N)]



for i in range(N):

    DPLIST[i][i]=0



SUM=[0]

for i in range(N):

    SUM.append(SUM[-1]+A[i])



for i in range(1,N):

    for j in range(i,N):



        ANS=float("inf")



        for k in range(j-i,j):



            if ANS>DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]:

                ANS=DPLIST[j-i][k]+DPLIST[k+1][j]+SUM[j+1]-SUM[j-i]

        

        DPLIST[j-i][j]=ANS



print((DPLIST[0][N-1]))
N = int(eval(input()))
A = list(map(int, input().split()))
DPLIST = [[None] * N for i in range(N)]
for i in range(N):
    DPLIST[i][i] = [0, A[i]]
for i in range(1, N):
    for j in range(i, N):
        # print(i,j)
        ANS = float("inf")
        slime = float("inf")
        for k in range(j - i, j):
            sc1, sl1 = DPLIST[j - i][k]
            sc2, sl2 = DPLIST[k + 1][j]
            if ANS > sc1 + sc2 + sl1 + sl2:
                ANS = sc1 + sc2 + sl1 + sl2
                slime = sl1 + sl2
        DPLIST[j - i][j] = [ANS, slime]
    # print(DPLIST)
    # print()
print((DPLIST[0][N - 1][0]))

N = int(eval(input()))
A = list(map(int, input().split()))
DPLIST = [[None] * N for i in range(N)]
for i in range(N):
    DPLIST[i][i] = 0
SUM = [0]
for i in range(N):
    SUM.append(SUM[-1] + A[i])
for i in range(1, N):
    for j in range(i, N):
        ANS = float("inf")
        for k in range(j - i, j):
            if ANS > DPLIST[j - i][k] + DPLIST[k + 1][j] + SUM[j + 1] - SUM[j - i]:
                ANS = DPLIST[j - i][k] + DPLIST[k + 1][j] + SUM[j + 1] - SUM[j - i]
        DPLIST[j - i][j] = ANS
print((DPLIST[0][N - 1]))

-    DPLIST[i][i] = [0, A[i]] +    DPLIST[i][i] = 0 +SUM = [0] +for i in range(N): +    SUM.append(SUM[-1] + A[i]) -        # print(i,j) -        slime = float("inf") -            sc1, sl1 = DPLIST[j - i][k] -            sc2, sl2 = DPLIST[k + 1][j] -            if ANS > sc1 + sc2 + sl1 + sl2: -                ANS = sc1 + sc2 + sl1 + sl2 -                slime = sl1 + sl2 -        DPLIST[j - i][j] = [ANS, slime] -    # print(DPLIST) -    # print() -print((DPLIST[0][N - 1][0])) +            if ANS > DPLIST[j - i][k] + DPLIST[k + 1][j] + SUM[j + 1] - SUM[j - i]: +                ANS = DPLIST[j - i][k] + DPLIST[k + 1][j] + SUM[j + 1] - SUM[j - i] +        DPLIST[j - i][j] = ANS +print((DPLIST[0][N - 1]))