package com;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int d, i, j, k;
int trash = 0;
long temp;
int R[] = new int[1010];
long M[][] = new long[10100][10100];
for (int h = 0; h < N; h++) {
if(h != N - 1) {
R[h] = sc.nextInt();
trash = sc.nextInt();
}
else {
R[h] = sc.nextInt();
R[h + 1] = sc.nextInt();
}
}
for (d = 1; d <= N - 1; d++) {
long min = 10000000;
for (i = 1; i <= N - d; i++) {
j = d + i;
for (k = i; k < j; k++) {
temp = M[i][k] + M[k+1][j] + R[i-1]*R[k]*R[j];
if (min > temp) {
min = temp;
}
M[i][j] = min;
int a = i;
int b = j;
if (a != i || b != j) min = 10000000;
}
}
}
System.out.println(M[1][N]);
}
}