import sys



def get_min_cost(n, p):

	m = [[0 for x in range(n+1)] for x in range(n+1)]

	for s in range(n):

		i = 1

		for j in range(s+2, n+1):

			m[i][j] = sys.maxsize

			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])

			i+=1	

	return m[1][n]



n = int(eval(input()))

p = [0] * (n+1)

j = 0

for i in range(n):

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

	if i == 0:

		p[j] = a[0]

		j += 1

	p[j] = a[1]

	j += 1

print((get_min_cost(n, p)))

		

		



def mcm(p,n):

	m=[[0 for x in range(n+1)] for x in range(n+1)]

	for s in range(n):

		for i,j in zip(list(range(1,n+1)),list(range(s+2,n+1))):

			m[i][j] = 1 << 30

			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])

	return m[1][n]



n=int(eval(input()))

p=[0]*(n+1)

for i in range(n-1):

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

	p[i]=t[0];

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

p[n-1]=t[0]

p[n]=t[1]



ans=mcm(p,n)

print(ans)



import sys


def get_min_cost(n, p):
    m = [[0 for x in range(n + 1)] for x in range(n + 1)]
    for s in range(n):
        i = 1
        for j in range(s + 2, n + 1):
            m[i][j] = sys.maxsize
            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])
            i += 1
    return m[1][n]


n = int(eval(input()))
p = [0] * (n + 1)
j = 0
for i in range(n):
    a = list(map(int, input().split()))
    if i == 0:
        p[j] = a[0]
        j += 1
    p[j] = a[1]
    j += 1
print((get_min_cost(n, p)))

def mcm(p, n):
    m = [[0 for x in range(n + 1)] for x in range(n + 1)]
    for s in range(n):
        for i, j in zip(list(range(1, n + 1)), list(range(s + 2, n + 1))):
            m[i][j] = 1 << 30
            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])
    return m[1][n]


n = int(eval(input()))
p = [0] * (n + 1)
for i in range(n - 1):
    t = list(map(int, input().split()))
    p[i] = t[0]
t = list(map(int, input().split()))
p[n - 1] = t[0]
p[n] = t[1]
ans = mcm(p, n)
print(ans)

-import sys - - -def get_min_cost(n, p): +def mcm(p, n): -        i = 1 -        for j in range(s + 2, n + 1): -            m[i][j] = sys.maxsize +        for i, j in zip(list(range(1, n + 1)), list(range(s + 2, n + 1))): +            m[i][j] = 1 << 30 -            i += 1 -j = 0 -for i in range(n): -    a = list(map(int, input().split())) -    if i == 0: -        p[j] = a[0] -        j += 1 -    p[j] = a[1] -    j += 1 -print((get_min_cost(n, p))) +for i in range(n - 1): +    t = list(map(int, input().split())) +    p[i] = t[0] +t = list(map(int, input().split())) +p[n - 1] = t[0] +p[n] = t[1] +ans = mcm(p, n) +print(ans)