inf = float('inf')



n = int(eval(input()))

a = tuple(int(x) for x in input().split())



d = [[inf] * n for _ in range(n)]

for i in range(n):

    d[i][i] = 0



c = [0]

for aa in a:

    c.append(c[-1] + aa)



for i in range(n - 1, -1, -1):

    for j in range(i + 1, n):

        for k in range(i, j):

            # [i, k], (k, j]

            d[i][j] = min(d[i][j], d[i][k] + d[k + 1][j])

        d[i][j] += c[j + 1] - c[i]

# print(d)

# print(c)

print((d[0][n - 1]))

inf = 10 ** 16



n = int(eval(input()))

a = tuple(int(x) for x in input().split())



d = [[inf] * n for _ in range(n)]

for i in range(n):

    d[i][i] = 0



c = [0]

for aa in a:

    c.append(c[-1] + aa)



for i in range(n - 1, -1, -1):

    for j in range(i + 1, n):

        for k in range(i, j):

            # [i, k], (k, j]

            d[i][j] = min(d[i][j], d[i][k] + d[k + 1][j])

        d[i][j] += c[j + 1] - c[i]

# print(d)

# print(c)

print((d[0][n - 1]))

inf = float("inf")
n = int(eval(input()))
a = tuple(int(x) for x in input().split())
d = [[inf] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
c = [0]
for aa in a:
    c.append(c[-1] + aa)
for i in range(n - 1, -1, -1):
    for j in range(i + 1, n):
        for k in range(i, j):
            # [i, k], (k, j]
            d[i][j] = min(d[i][j], d[i][k] + d[k + 1][j])
        d[i][j] += c[j + 1] - c[i]
# print(d)
# print(c)
print((d[0][n - 1]))

inf = 10**16
n = int(eval(input()))
a = tuple(int(x) for x in input().split())
d = [[inf] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
c = [0]
for aa in a:
    c.append(c[-1] + aa)
for i in range(n - 1, -1, -1):
    for j in range(i + 1, n):
        for k in range(i, j):
            # [i, k], (k, j]
            d[i][j] = min(d[i][j], d[i][k] + d[k + 1][j])
        d[i][j] += c[j + 1] - c[i]
# print(d)
# print(c)
print((d[0][n - 1]))

-inf = float("inf") +inf = 10**16