Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for k := i; k <= j-1; k++ {
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

Python: n = int(input())
M = []
dp = [[None for i in range(100)] for i in range(100)]

def calcMatrix(i,j):
    #print(i,j)
    if i == j:
        dp[i][j] = 0
    elif i == j-1:
        dp[i][j] = M[i]*M[i+1]*M[i+2]
    else:
        for k in range(j-i):
            #print(i,j,k)
            #print(dp[i][i+k])
            #print(dp[i+k+1][j])
            #print(M[i]*M[k+1]*M[j])
            current = dp[i][i+k] + dp[i+k+1][j] + M[i]*M[i+k+1]*M[j+1]
            if k==0:
                dp[i][j] = current
            if current < dp[i][j]:
                dp[i][j] = current 

for i in range(n-1):
    Q = list(map(int,input().split()))
    M.append(Q[0])
Q = list(map(int,input().split()))
M.append(Q[0])
M.append(Q[1])
#print(M)

for i in range(n):
    for j in range(n-i):
        calcMatrix(j,i+j)
        #for k in range(10):
        # print(dp[k])
        # print()
print(dp[0][n-1])

Python: n = int(input())
r = [0] * n
c = [0] * n
for i in range(n):
    r[i], c[i] = map(int, input().split())

dp = [[0 for i in range(n+1)] for j in range(n+1)]

for i in range(2, n+1): #幅
    for j in range(0, n+1-i): #左端
        dp[j][j+i] = min([dp[j][k]+(r[j]*c[k-1]*c[j+i-1])+dp[k][j+i] for k in range(j+1,j+i)])

print(dp[0][n])

Python: N = int(input())
matrices = [tuple(map(int, input().split())) for _ in range(N)]
R, C = zip(*matrices)
dp = [[float('inf')] * N for _ in range(N)]
for i in range(N): dp[i][i] = 0
for l in range(1, N):
    for i in range(N-l):
        r, c = R[i], C[i+l]
        dp[i][i+l] = min(r * C[j] * c + dp[i][j] + dp[j+1][i+l] for j in range(i, i+l))
print(dp[0][N-1])

Python: def s():
 n=int(input())+1
 e=[input().split()for _  in[0]*~-n]
 p=[int(e[0][0])]+list(int(x[1])for x in e)
 m=[[0]*n for _ in[0]*n]
 for i in range(n):
  for r in range(n-i-1):
   c=r+i+1
   for j in range(r+1,c):
    x=m[r][j]+m[j][c]+p[r]*p[j]*p[c]
    if 1>m[r][c]or m[r][c]>x:m[r][c]=x
 print(m[r][c])
if'__main__'==__name__:s()

Python: n=int(input())
m={}
p=[]

for i in range(n+1):
    m[i]=[0 for j in range(n+1)]
for i in range(n):
    tmp=list(map(int,input().split()))
    if i==0:
        p.append(tmp[0])
        p.append(tmp[1])
    else:
        p.append(tmp[1])

for l in range(2,n+1):
    for i in range(1,n-l+2):
        j=i+l-1
        m[i][j]=10000000
        for k in range(i,j):
            m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+(p[i-1]*p[k]*p[j]))
            
print(m[1][n])

Python: def s():
 n=int(input())+1
 e=[input().split()for _  in[0]*~-n]
 p=[int(e[0][0])]+list(int(x[1])for x in e)
 m=[[0]*n for _ in[0]*n]
 for i in range(n):
  for r in range(n-i-1):
   c=r+i+1
   for j in range(r+1,c):
    x=m[r][j]+m[j][c]+p[r]*p[j]*p[c]
    if not 0<m[r][c]<=x:m[r][c]=x
 print(m[r][c])
if'__main__'==__name__:s()

Python: N = int(input())
for i in range(N):
    if i == 0:
        P = list(map(int, input().split()))
        continue
    P.append(int(input().split()[1]))

# dpテーブルの用意 minを取るときはinf埋めしておくと処理が楽になるしバグが見つかりやすい
INF = 2**32-1
dp = [[INF]*N for _ in range(N)]

# dpテーブルの初期化
# 対角成分0
for ij in range(N):
    dp[ij][ij] = 0
    
for l in range(1, N):
    for i in range(N-l):
        j = i+l
        for k in range(i,j):
            dp[i][j] = min(dp[i][k] + dp[k+1][j] + P[i]* P[j+1]*P[k+1], dp[i][j])
print(dp[0][-1])

Python: import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

N = ii()
l = li2(N)


'''
# メモ化再帰
dp = dp2(-1, N, N)
def rec(i, j):
    if dp[i][j] != -1:
        return dp[i][j]
    if i == j:
        dp[i][j] = 0
        return 0
    if j-i == 1:
        dp[i][j] = l[i][0] * l[i][1] * l[j][1]
        return dp[i][j]
    res = float('inf')
    for k in range(i, j):
        res = min(res, rec(i, k) + rec(k+1, j) + l[i][0] * l[k+1][0] * l[j][1])
    dp[i][j] = res
    return res

print(rec(0, N-1))
'''

# 2次元DP

dp = dp2(float('inf'), N, N)

for i in range(N):
    dp[i][i] = 0

for h in range(1, N):
    for i in range(N):
        if i+h < N:
            if h == 1:
                dp[i][i+h] = l[i][0] * l[i][1] * l[i+h][1]
            else:
                #dp[i][i+h] = dp[i][i+h-1] + l[i][0] * l[i+h][0] * l[i+h][1]
                for r in range(i, i+h):
                    dp[i][i+h] = min(dp[i][i+h], dp[i][r]+dp[r+1][i+h]+l[i][0]*l[r+1][0]*l[i+h][1])
#print(dp)
print(dp[0][N-1])

Python: n = int(input())
m = []


def memoize(f):
    memo = [[None] * n for _ in range(n)]
    for i in range(n):
        memo[i][i] = 0

    def main(b, e):
        if memo[b][e] is not None:
            return memo[b][e]
        result = memo[b][e] = f(b, e)
        return result

    return main


@memoize
def contract(b, e):
    return min(contract(b, i) + contract(i + 1, e) + m[b] * m[i + 1] * m[e + 1] for i in range(b, e))


r, c = map(int, input().split())
m.append(r)
m.append(c)
nc = n - 1
while nc:
    r, c = map(int, input().split())
    m.append(c)
    nc -= 1

print(contract(0, n - 1))