local mmi = math.min
local n = io.read("*n")
local sum = {io.read("*n")}
for i = 2, n do
  sum[i] = sum[i - 1] + io.read("*n")
end
local dp = {}
dp[1] = {}
for i = 1, n do
  dp[1][i] = 0
end
for i = 2, n do
  dp[i] = {}
  local leftposlim = n - i + 1
  for j = 1, leftposlim do
    local v = dp[1][j] + dp[i - 1][j + 1]
    for k = 2, i - 1 do
      v = mmi(v, dp[k][j] + dp[i - k][j + k])
    end
    v = v + sum[j + i - 1]
    if 1 < j then v = v - sum[j - 1] end
    dp[i][j] = v
  end
end
print(dp[n][1])
