'''
区间DP
'''
N = int(input())
arr = list(map(int, input().split()))
from functools import lru_cache
# 序号i到j的节点序列的所有划分方案里面权值乘积之和的最小数值
@lru_cache(typed=False, maxsize=128000000)
def dp(i, j):
if j == i + 2:
return arr[i] * arr[i + 1] * arr[i + 2]
else:
# i-j连起来的这条边不动,枚举根这条边配对的点的位置,枚举切割位置
ans = 0x7ffffffffffffffffffffffffffff
for k in range(i + 1, j):
if k == i + 1:
ans = min(ans, arr[i] * arr[k] * arr[j] + dp(k, j))
elif k == j - 1:
ans = min(ans, arr[i] * arr[k] * arr[j] + dp(i, k))
else:
ans = min(ans, arr[i] * arr[k] * arr[j] + dp(i, k) + dp(k, j))
return ans
print(dp(0, N - 1))