Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	mm := make([]int, n+1)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, n+1)
	}
	for i := 0; i < n; i++ {
		mm[i] = getNextInt(scanner)
		mm[i+1] = getNextInt(scanner)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			for k := i; k <= j-1; k++ {
				d := dp[i][k] + dp[k+1][j] + mm[i-1]*mm[k]*mm[j]
				if dp[i][j] == 0 || dp[i][j] > d {
					dp[i][j] = d
				}
			}
		}
	}

	fmt.Fprintln(writer, dp[1][n])

	writer.Flush()
}

C++: #include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    int p[n+1], m[n+1][n+1];
    for(int i = 1; i <= n; i++) cin >> p[i-1] >> p[i];
    for(int i = 1; i <= n; i++) m[i][i] = 0;
    for(int i = 2; i <= n; i++) for(int j = 1; j <= n - i + 1; j++){
        int k = j + i - 1;
        m[j][k] = (1 << 21);
        for(int l = j; l <= k - 1; l++) m[j][k] = min(m[j][k], m[j][l] + m[l + 1][k] + p[j - 1] * p[l] * p[k]);
    }
    cout << m[1][n] << endl;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

static const int N=100;

int main() {
    int n, p[N+1], m[N+1][N+1];
    cin >> n;
    for (int i=1; i<=n; i++) {
        cin >> p[i-1] >> p[i];
    }
    
    for (int i=0; i<=n; i++) m[i][i] = 0;
    for (int l=2; l<=n; l++) {
        for(int i=1; i<=n-l+1; i++) {
            int j = i+l-1;
            m[i][j] = (1 << 21);
            for (int k=i; k<=j-1; k++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
            }
        }
    }
    
    cout << m[1][n] << endl;
    
    return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int N = 100;
int main() {
	int n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (int i = 1; i <= n; i++)cin >> p[i - 1] >> p[i];
	for (int i = 1; i <= n; i++)m[i][i] = 0;
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for (int k = i; k <= j - 1; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 200000001;
int m[101][101];
int p[101];

int main(void)
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i] >> p[i + 1];
	for (int i = 1; i <= n; i++)
		m[i][i] = 0;
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = MAX;
			for (int k = i; k <= j - 1; k++)
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;

static const int N=100;

//求解矩阵链乘法的最优解
//p 用于存储矩阵的行和列的
//dp[i][j] 表示从矩阵i乘到矩阵j的最小乘法次数

int main(){
    int n;
    int p[N+1],dp[N+1][N+1];

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>p[i-1]>>p[i];
    }

    for(int i=1;i<n;i++){
        dp[i][i]=0;
    }
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            dp[i][j]=(1<<21);//取一个很大的值
            for(int k=i;k<=j;k++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    
    cout<<dp[1][n]<<endl;

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> p(n+1);
  rep(i, n){
    int a, b;
    cin >> a >> b;
    if(i != 0) p.at(i+1) = b;
    else{
      p.at(0) = a;
      p.at(1) = b;
    }
  }
  vector<vector<ll>> dp(n, vector<ll>(n, 0));
  rep2(l, 1, n){
    rep(i, n - l){
      int j = i + l;
      dp.at(i).at(j) = LLONG_MAX;
      rep2(k, i, j){
        ll add = dp.at(i).at(k) + dp.at(k+1).at(j) + p.at(i) * p.at(k+1) * p.at(j+1);
        dp.at(i).at(j) = min(dp.at(i).at(j), add);
      }
    }
  }
  // rep(i, n){
  //   rep(j, n){
  //     printf("%9d ", (int)dp.at(i).at(j));
  //   }
  //   cout << endl;
  // }
  cout << dp.at(0).at(n-1) << endl;
  return 0;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
static const int N=100;

int main(){
  int n,i,l,k,p[N+1],m[N+1][N+1];
  cin>>n;
  for(i=1;i<=n;i++){
    cin>>p[i-1]>>p[i];
  }
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      int j=i+l-1;
      m[i][j]=(1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  cout<<m[1][n]<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = 1e9;

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<ll> rows(n + 5), cols(n + 5);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%lld %lld", &rows[i + 1], &cols[i + 1]);
  }
  vector<vector<ll> > dp(n + 5, vector<ll>(n + 5, 0));
  for (int l = 2; l <= n; ++l) {
    for (int i = 1; i <= n - l + 1; ++i) {
      int j = l + i - 1;
      dp[i][j] = std::numeric_limits<ll>::max();
      for (int k = i; k <= j - 1; ++k) {
        dp[i][j] = min(dp[i][j],
                       dp[i][k] + dp[k + 1][j] + rows[i] * cols[k] * cols[j]);
      }
    }
  }
  fprintf(stdout, "%lld\n", dp[1][n]);
  return 0;
}

C++: #include <stdlib.h>
#include <stdio.h>

int MCM(int n){
int i,j,k,l,m[101][101],p[101],x;

for(i=1;i<=n;i++)m[i][i]=0;
for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
        j=i+l-1;
     m[i][j]=10000000;
        for(k=i;k<=j;k++){
            x=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
            if(m[i][j]>x)m[i][j]=x;
            }
        }
    }
return m[i][j];
}

int main(){

int i,n,m[101];

scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d %d",&m[i],&m[i+1]);
   }
printf("%d\n",MCM(n));
return 0;
}