Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for k := i; k <= j-1; k++ {
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

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;
}