import sys


def sol():
    sys.stdin = open("./11049/input.txt")
    input = sys.stdin.readline
    N = int(input())
    dims = [0] * (N + 1)
    for i in range(N):
        r, c = map(int, input().split())
        if i == 0:
            dims[i], dims[i + 1] = r, c
            continue
        dims[i + 1] = c
    print(matrix_chain_order(dims))


def matrix_chain_order(dims):
    n = len(dims) - 1
    dp = [[0] * n for _ in range(n)]
    for diagonal in range(1, n):
        for r in range(n - diagonal):
            c = r + diagonal
            size_rc = dims[r] * dims[c + 1]
            cost = min(
                dp_ik + dp_kj + dims_k * size_rc
                for dp_ik, dp_kj, dims_k in zip(
                    dp[r][r:c], dp[c][r + 1 : c + 1], dims[r + 1 : c + 1]
                )
            )
            dp[r][c] = dp[c][r] = cost
    return dp[0][n - 1]


if __name__ == "__main__":
    sol()

import sys


def sol():
    sys.stdin = open("./11049/input.txt")
    input = sys.stdin.readline
    N = int(input())
    dims = [0] * (N + 1)
    for i in range(N):
        r, c = map(int, input().split())
        if i == 0:
            dims[i], dims[i + 1] = r, c
            continue
        dims[i + 1] = c
    print(matrix_chain_order(dims))


def matrix_chain_order(dims):
    n = len(dims) - 1
    dp = [[0] * n for _ in range(n)]
    for diagonal in range(1, n):
        for r in range(n - diagonal):
            c = r + diagonal
            size_rc = dims[r] * dims[c + 1]
            cost = min(
                dp_ik + dp_kj + dims_k * size_rc
                for dp_ik, dp_kj, dims_k in zip(
                    dp[r][r:c], dp[c][r + 1 : c + 1], dims[r + 1 : c + 1]
                )
            )
            dp[r][c] = dp[c][r] = cost
    return dp[0][n - 1]


if __name__ == "__main__":
    sol()
