n = int(eval(input()))

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

z = [0] * (n + 1)

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

    z[i - 1], z[i] = list(map(int, input().split()))

j = 0

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

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

        j = i + l - 1

        m[i][j] = int(1e8)

        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]))
n = int(eval(input()))

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

z = [0] * (n + 1)

for i in range(n):

    z[i], z[i + 1] = list(map(int, input().split()))

j = 0

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

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

        j = i + l - 1

        m[i][j] = float("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]))
n = int(eval(input()))
m = [[0 for j in range(n + 1)] for i in range(n + 1)]
z = [0] * (n + 1)
for i in range(1, n + 1):
    z[i - 1], z[i] = list(map(int, input().split()))
j = 0
for l in range(2, n + 1):
    for i in range(1, n - l + 2):
        j = i + l - 1
        m[i][j] = int(1e8)
        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]))

n = int(eval(input()))
m = [[0] * (n + 1) for _ in range(n + 1)]
z = [0] * (n + 1)
for i in range(n):
    z[i], z[i + 1] = list(map(int, input().split()))
j = 0
for l in range(2, n + 1):
    for i in range(1, n - l + 2):
        j = i + l - 1
        m[i][j] = float("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]))

-m = [[0 for j in range(n + 1)] for i in range(n + 1)] +m = [[0] * (n + 1) for _ in range(n + 1)] -for i in range(1, n + 1): -    z[i - 1], z[i] = list(map(int, input().split())) +for i in range(n): +    z[i], z[i + 1] = list(map(int, input().split())) -        m[i][j] = int(1e8) +        m[i][j] = float("inf")