#include<iostream>
#include<climits>
using namespace std;
int main(){
  int n,data[101]; cin>>n;
  for(int i=0;i<n;++i) cin>>data[i]>>data[i+1];
  int dp[100][100]={};
  for(int num=2;num<=n;++num){
    for(int first=0;first<=n-num;++first){
      int end=first+num-1;
      dp[first][end]=INT_MAX/2;
      for(int i=first;i<=end;++i){
	if(dp[first][end]>dp[first][i]+dp[i+1][end]+data[first]*data[i+1]*data[end+1])
	  dp[first][end]=dp[first][i]+dp[i+1][end]+data[first]*data[i+1]*data[end+1];
      }
    }
  }
  cout<<dp[0][n-1]<<endl;
  return 0;
}

