#!/usr/bin/env python

# -*- coding: utf-8 -*-



import sys





def mat_mul_opt(_mat_info):

    r, c = list(map(int, _mat_info[0]))

    rc_info.extend([r, c])

    for each in _mat_info[1:]:

        rc_info.append(int(each[1]))



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

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

            j = i + l - 1

            ans[i][j] = 1e7

            for k in range(i, j):

                ans[i][j] = min(ans[i][j], ans[i][k] + ans[k + 1][j] +

                                rc_info[i - 1] * rc_info[k] * rc_info[j])



    return ans[1][mat_num]





if __name__ == '__main__':

    _input = sys.stdin.readlines()

    mat_num = int(_input[0])

    mat_info = tuple([x.split() for x in _input[1:]])



    rc_info = []

    ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]

    print((mat_mul_opt(mat_info)))
#!/usr/bin/env python

# -*- coding: utf-8 -*-



import sys





def mat_mul_opt(_mat_info):

    rc_info.extend(list(map(int, _mat_info[0])))

    rc_info.extend(list([int(x[1]) for x in _mat_info[1:]]))



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

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

            j = i + l - 1

            ans[i][j] = 1e7

            for k in range(i, j):

                ans[i][j] = min(ans[i][j], ans[i][k] + ans[k + 1][j] +

                                rc_info[i - 1] * rc_info[k] * rc_info[j])



    return ans[1][mat_num]





if __name__ == '__main__':

    _input = sys.stdin.readlines()

    mat_num = int(_input[0])

    mat_info = tuple([x.split() for x in _input[1:]])



    rc_info = []

    ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]

    print((mat_mul_opt(mat_info)))
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys


def mat_mul_opt(_mat_info):
    r, c = list(map(int, _mat_info[0]))
    rc_info.extend([r, c])
    for each in _mat_info[1:]:
        rc_info.append(int(each[1]))
    for l in range(2, mat_num + 1):
        for i in range(1, mat_num - l + 2):
            j = i + l - 1
            ans[i][j] = 1e7
            for k in range(i, j):
                ans[i][j] = min(
                    ans[i][j],
                    ans[i][k]
                    + ans[k + 1][j]
                    + rc_info[i - 1] * rc_info[k] * rc_info[j],
                )
    return ans[1][mat_num]


if __name__ == "__main__":
    _input = sys.stdin.readlines()
    mat_num = int(_input[0])
    mat_info = tuple([x.split() for x in _input[1:]])
    rc_info = []
    ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]
    print((mat_mul_opt(mat_info)))

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys


def mat_mul_opt(_mat_info):
    rc_info.extend(list(map(int, _mat_info[0])))
    rc_info.extend(list([int(x[1]) for x in _mat_info[1:]]))
    for l in range(2, mat_num + 1):
        for i in range(1, mat_num - l + 2):
            j = i + l - 1
            ans[i][j] = 1e7
            for k in range(i, j):
                ans[i][j] = min(
                    ans[i][j],
                    ans[i][k]
                    + ans[k + 1][j]
                    + rc_info[i - 1] * rc_info[k] * rc_info[j],
                )
    return ans[1][mat_num]


if __name__ == "__main__":
    _input = sys.stdin.readlines()
    mat_num = int(_input[0])
    mat_info = tuple([x.split() for x in _input[1:]])
    rc_info = []
    ans = [[0] * (mat_num + 1) for _ in range(mat_num + 1)]
    print((mat_mul_opt(mat_info)))

-    r, c = list(map(int, _mat_info[0])) -    rc_info.extend([r, c]) -    for each in _mat_info[1:]: -        rc_info.append(int(each[1])) +    rc_info.extend(list(map(int, _mat_info[0]))) +    rc_info.extend(list([int(x[1]) for x in _mat_info[1:]]))