#include<iostream>
#include<algorithm>
using namespace std;
int dp[101][101];
int r[100],c[100];
int solv(int a,int b){//a??????b-1?????§?????????????????????????????????????????°???????°???¨?????????????????????????????????
    if(dp[a][b]==-1){
        if(a == b-1){
            dp[a][b]=0;
        }else if(a==b-2){
            dp[a][b]=r[a]*c[a]*c[a+1];
        }else{
            int Pmin=999999999;
            for(int j=a+1;j<b;j++){
                int tmp=solv(a,j)+solv(j,b)+r[a]*r[j]*c[b-1];
                Pmin=min(Pmin,tmp);
            }
            dp[a][b]=Pmin;
        }
    }
    return dp[a][b];
}
int main(){
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            dp[i][j]=-1;
        }
    }
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>r[i]>>c[i];
    }
    int ans=solv(0,N);
    cout<<ans<<endl;
    return 0;
}
#include <bits/stdc++.h>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int mat[110][2], dp[110][110];
const int INF = 1<<29;

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  REP(i, N) REP(j, 2) cin >> mat[i][j];
  REP(i, N) REP(j, N) dp[i][j] = INF;
  REP(i, N) dp[i][i] = 0;
  for (int w = 1; w < N; w++) {
    for (int L = 0; L + w < N; L++) {
      int R = L + w;
      for (int i = L; i < R; i++)
	dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + mat[L][0] * mat[i][1] * mat[R][1]);
    }
  }
  cout << dp[0][N-1] << endl;
  return 0;
}