import sys

INF = float("inf")

n = int(eval(input()))

A = [0]

for i, a in enumerate(sys.stdin):

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

    if i == 0:

        A.extend(a)

    else:

        A.append(a[1])

C = [[INF] * (n + 1) for _ in range(n + 1)]

for i in range(n + 1):

    C[i][i] = 0

for j in range(1, n):

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

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

            cost = C[i][k - 1] + C[k][i + j] + A[i] * A[k] * A[i + j + 1]

            if cost < C[i][i + j]:

                C[i][i + j] = cost

print((C[1][n]))



INF = float("inf")

MAX = 101

n = int(eval(input()))

z = []

m = [[0] * MAX for _ in range(MAX)]

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

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

    z.append(a)

z.append(b)

for l in range(2, n + 1):

    for i in range(1, n - l + 2):

        j = i + l - 1

        m[i][j] = INF

        for k in range(i, j):

            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])

print((m[1][n]))



import sys

INF = float("inf")
n = int(eval(input()))
A = [0]
for i, a in enumerate(sys.stdin):
    a = list(map(int, a.split()))
    if i == 0:
        A.extend(a)
    else:
        A.append(a[1])
C = [[INF] * (n + 1) for _ in range(n + 1)]
for i in range(n + 1):
    C[i][i] = 0
for j in range(1, n):
    for i in range(1, n - j + 1):
        for k in range(i + 1, i + j + 1):
            cost = C[i][k - 1] + C[k][i + j] + A[i] * A[k] * A[i + j + 1]
            if cost < C[i][i + j]:
                C[i][i + j] = cost
print((C[1][n]))

INF = float("inf")
MAX = 101
n = int(eval(input()))
z = []
m = [[0] * MAX for _ in range(MAX)]
for i in range(1, n + 1):
    a, b = list(map(int, input().split()))
    z.append(a)
z.append(b)
for l in range(2, n + 1):
    for i in range(1, n - l + 2):
        j = i + l - 1
        m[i][j] = INF
        for k in range(i, j):
            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j])
print((m[1][n]))

-import sys - +MAX = 101 -A = [0] -for i, a in enumerate(sys.stdin): -    a = list(map(int, a.split())) -    if i == 0: -        A.extend(a) -    else: -        A.append(a[1]) -C = [[INF] * (n + 1) for _ in range(n + 1)] -for i in range(n + 1): -    C[i][i] = 0 -for j in range(1, n): -    for i in range(1, n - j + 1): -        for k in range(i + 1, i + j + 1): -            cost = C[i][k - 1] + C[k][i + j] + A[i] * A[k] * A[i + j + 1] -            if cost < C[i][i + j]: -                C[i][i + j] = cost -print((C[1][n])) +z = [] +m = [[0] * MAX for _ in range(MAX)] +for i in range(1, n + 1): +    a, b = list(map(int, input().split())) +    z.append(a) +z.append(b) +for l in range(2, n + 1): +    for i in range(1, n - l + 2): +        j = i + l - 1 +        m[i][j] = INF +        for k in range(i, j): +            m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + z[i - 1] * z[k] * z[j]) +print((m[1][n]))