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<cstdio>
#include<climits>
#include<algorithm>
using namespace std;
int AskMCM(int *p,int n){
    int cost[n+1][n+1];
    for(int i = 1;i <= n;++i) cost[i][i] =0;
    for(int l = 2;l <= n; l++){
        for(int i = 1;i <= n - l + 1;i++){
            int j = i+l -1;
            int min_cost = INT_MAX;
            for(int k = i;k < j;++k) min_cost = min(min_cost,cost[i][k] + cost[k+1][j] + p[i-1] * p[k] * p[j]);
            cost[i][j] = min_cost;
        }
    }
    return cost[1][n];
}

int main(){
    int n,r,tmp;
    scanf("%d",&n);
    int p[n+1];
    for(int i = 1;i <= n;++i) scanf("%d %d",&p[i-1],&p[i]);
    printf("%d\n",AskMCM(p,n));
}

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

int main(void){
    int n,i,k,a[110],min,x;
    
    int dp[110][110];
    int length,left,mid,right;
    
    cin>>n;
    
    cin>>a[0]>>a[1];
    for(i=2;i<n+1;i++){
        cin>>x>>a[i];
    }
    
    for(i=0;i<n;i++){
        dp[i][i]=0;
    }

    for(length=1;length<n;length++){
        for(left=0;left<n-length;left++){
            min=1000000000;
            right=left+length;
            for(mid=left;mid<right;mid++){
                x=dp[left][mid]+dp[mid+1][right]+a[left]*a[mid+1]*a[right+1];
                if(x<min)min=x;
            }
            dp[left][right]=min;
        }
    
    }

    cout<<dp[0][n-1]<<endl;
    return 0;
}

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

int calc(const vector<pair<int, int> >& M, int idx_b, int idx_e) {
    if (idx_b == idx_e) return 0;
    int min = 2e9;
    for (int i = idx_b; i < idx_e; i++) {
        int val = 0;
        val = calc(M, idx_b, i);
        val += calc(M, i + 1, idx_e);
        val += M[idx_b].first * M[i].second * M[idx_e].second;
        if (val < min) min = val;
    }
    return min;
}

int main(){
    int n;
    cin >> n;
    vector<pair<int, int> > M;

    for (int i = 0; i < n; i++) {
        pair<int, int> input;
        cin >> input.first >> input.second;
        M.push_back(input);
    }
    cout << calc(M, 0, M.size() - 1) << endl;

    return 0;
}

C++: #include <iostream>
using namespace std;
#define MAX_SIZE (101)

int main() {
	int n;
	cin >> n;
	// p[i-1], p[i] correspond to M[i]'s row and column size
	int p[MAX_SIZE];
	for (int i=1;i<=n;++i) {
		cin >> p[i-1] >> p[i];
	}
	// [i][j] is a cost for multiplying matrices between M[i] and M[j].
	int dp[MAX_SIZE][MAX_SIZE];
	// [i][i] = 0, i=1,...,n
	for (int i=1;i<=n;++i) {
		dp[i][i] = 0;
	}
	// [i][j], i<j, i=1,...,n
	// j - i = l-1 = 1,2,...,n-1
	// このindexの指定の仕方: なんとなくnまでに合わせたい, l=2,...,nで(l-1)=1,...,n-1になる
	// j = i + (l-1)で, i+1, ..., n まで動く.
	for (int l=2;l<=n;++l) {
		for (int i=1;i<=n-l+1;++i) {
			int j = i + l - 1;// i+1, i+2, ..., n
			dp[i][j] = (1 << 30); 
			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>
using namespace std;

int dp[101][101];
int INF = 1000100100;


int main(){
    int n,r[101],c[101];
    cin >> n;
    for(int i=1; i<n+1; i++){
        cin >>r[i] >> c[i];
    }

    //dp[][]を初期化
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            dp[i][j]=INF;
        }
    }

    //dp[i][i]=0にする。
    for(int i=1;i<n+1;i++){
        dp[i][i]=0;
    }
    //区間幅をずらしていく。2からスタート
    for(int k=2; k < n+1; k++){
        //対象区間の始点を一つずつ見ていく
        for(int i=1; i+k -1 < n+1; i++){
            //対象区間を2つの小区間にわける
            for(int j =i; j < i+k; j++){
                dp[i][i+k-1]=min(dp[i][i+k-1], dp[i][j]+dp[j+1][i+k-1] + r[i]*c[j]*c[i+k-1]);
            }
        }//添え字が間違ってないか不安。。
    }
    //全区間の答えを出力
    cout << dp[1][n] << endl;
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

static const int N = 100;

signed main() {
	ios::sync_with_stdio(false);
	int n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	int i;
	FOR(i, 1, n + 1) {
		cin >> p[i - 1] >> p[i];
	}
	FOR(i, 1, n + 1) 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] << '\n';
	return 0;
}

C++: #include <stdio.h>

int main() {	
	int rankN;
	int colRowL[101];
	int min[100][100];
	int left, right;
	int temp;
	int i, j, k;

	scanf("%d", &rankN);
	for (i = 0; i < rankN; i++) {
		scanf("%d %d", &colRowL[i], &colRowL[i + 1]);
	}

	for (i = 0; i < rankN; i++) {
		min[i][i] = 0;
	}
	for (i = 1; i < rankN; i++) {
		for (j = 0; j < rankN - i; j++) {
			left = j;
			right = j + i;
			min[left][right] = 1000000000;

			for (k = left; k < right ; k++) {
				temp = min[left][k] + min[k + 1][right] 
		                    +colRowL[left] * colRowL[k + 1] * colRowL[right + 1];
				if (temp < min[left][right]) {
					min[left][right] = temp;
				}
			}
		}
	}

	printf("%d\n", min[0][rankN - 1]);

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#define INT_MAX 100000000
using namespace std;
int index;
int mm[1000][1000];
int mine = INT_MAX;

void solve(int p[]){
  int n = index-1,j,q;
  for(int i=1;i<=n;i++)mm[i][i]=0;
  for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
      j = i+l-1;
      mm[i][j] = INT_MAX;
      for(int k=i;k<=j-1;k++){
	q = mm[i][k] + mm[k+1][j] + p[i-1]*p[k]*p[j];
	if(q<mm[i][j]){
	  mm[i][j] = q;
       
	}

      }
    }
  }




}

int main(){
  int p[1000],a,b;
  scanf("%d",&index);
  //for(int i=0;i<=index;i++)for(int j=0;j<=n;j++)mm[i][j] = INT_MAX;
  for(int i=0;i<index;i++){
    scanf("%d %d",&a,&b);
    p[i] = a;
    if(i == index-1)p[i+1] = b;
  }

  index = index+1;
  solve(p);
 
  printf("%d\n",mm[1][index]);
  return 0;
}