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 <bits/stdc++.h>
using namespace std;

#define N_MAX 105
#define INF (1 << 21)

long P[N_MAX];
long dp[N_MAX][N_MAX];

int main() {
    long n;
    cin >> n;
    for (long i = 0; i < n; i++) {
        cin >> P[i] >> P[i + 1];
    }

    for (long i = 1; i <= n; i++) {
        dp[i][i] = 0;
    }

    for (long l = 1; l <= n - 1; l++) {
        for (long i = 1; i + l <= n; i++) {
            long j = i + l;
            dp[i][j] = INF;
            for (long k = i; k <= j; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + P[i - 1] * P[j] * P[k]);
            }
        }
    }

    cout << dp[1][n] << endl;

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
struct RC {
    int r, c;
};

int dp[101][101];
int main()
{
    int N;
    cin >> N;
    vector<RC> rc(N);
    rep(i, N) {
        int r, c;
        cin >> r >> c;
        rc[i] = {r, c};
    }

    vector<vector<int>> dp(N, vector<int>(N, 1e9));
    rep(i, N) dp[i][i] = 0;

    repd(w, 1, N) {
        rep(i, N - w) {
            int j = i + w;
            repd(k, i, j) {
                chmin(dp[i][j], dp[i][k] + dp[k + 1][j] + rc[i].r * rc[k].c * rc[j].c);
            }
        }
    }

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

C++: #include <bits/stdc++.h>
using namespace std;

#define N 101

vector<vector<int> > dp(N, vector<int>(N));
int p[N+1];

// dp[i][j] := [Mi, Mj]におけるminimum number of scalar multiplications 

int main(){
    
    int n;
    cin >> n;
    
    for (int i = 1; i < n+1; i++) cin >> p[i-1] >> p[i];
    
    
    // l はchain lengthを表す変数である.
    // l == 1のとき計算回数は0である.
    for (int l = 2; l <= n; l++){
        
        // 変数iは区間の左端を表す
        // 左端が動ける範囲の上限は, n - l + 1である
        // 具体例を考えてみよ
        for (int i = 1; i <= n-l+1; i++){
            
            // jは右端の上限値を表す
            int j = i + l - 1;
            
            dp[i][j] = (1<<20);
            
            // 今回調べる区間は, [i, j-1]
            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;
}

C++: #include <stdio.h>

int N;
int R[200];
int dp[200][200];

int min(int x, int y) { return x < y ? x : y; }

int main(void) {
	scanf("%d", &N);
	for (int i = 0; i < N; i ++) {
		scanf("%d %d", &R[i], &R[i+1]);
	}
	for (int i = 0; i < N; i ++) {
		for (int j = 0; j < N; j ++) {
			dp[i][j] = 1 << 20;
		}
	}
	for (int i = 0; i < N; i ++) {
		dp[i][0] = 0;
	}
	for (int j = 0; j < N; j ++) {
		for (int i = 0; i + j < N; i ++) {
			// M_j ... M_{j+i}のi+1個の積について考える
			for (int k = 0; k < j; k ++) {
				// (M_j ... M_{j+k}) (M_{j+k+1} ... M_{j+i})
				//   (k+1個の積)            (i-k個の積)
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[i+k+1][j-k-1] + R[i] * R[i+k+1] * R[i+j+1]);
			}
		}
	}
	printf("%d\n", dp[0][N-1]);
	return 0;
}

C++: #include <iostream>
#include <limits.h>

using namespace std;

int dp[100][100];
int p[101];
int n;

void solve() {
	for (int m = n; m > 0; m--) {
		for (int t = 0, i = 0, j = n - m + 1; t < n && j < n; t++) {
			dp[i][j] = INT_MAX;
			for (int k = i; k < j; k++) {
				int temp = dp[i][k] + dp[k + 1][j] + p[i] * p[k + 1] * p[j + 1];
				if (temp < dp[i][j]) {
					dp[i][j] = temp;
				}
			}
			i++;
			j++;
		}
	}
}

int main() {
	int a, b;
	cin >> n >> a;

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

	solve();
	cout << dp[0][n - 1] << endl;

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
static const int MAX = 101;
int M[MAX][MAX], P[MAX];

int main()
{
    int n, r, c;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> r >> c;
        P[i-1] = r;
        P[i] = c;
    }
    for (int i = 0; i <= MAX; ++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 << 20);
            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 main(){
	int n, p[101],m[101][101];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>p[i-1]>>p[i];
		}
		
	for(int i=1 ; i<=101 ; 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;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;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384626433832795

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	int n, in;
	vector<ll> v;
	cin >> n;
	rep(i, n) {
		cin >> in;
		v.push_back(in);
		cin >> in;
		if (i == n - 1)v.push_back(in);
	}
	vector<vector<ll>> vv(n, vector<ll>(n));
	for (int i = 1; i < n; i++) {
		vv[i - 1][i] = v[i - 1] * v[i] * v[i + 1];
	}
	for (int i = 2; i < n; i++) {
		for (int j = 0; i+j < n; j++) {
			ll ans;
			for (int k = 0; k <= i - 1; k++) {
				if (k == 0) {
					ans = vv[j][j + k] + vv[j + k+1][j + i] + v[j] * v[j + k + 1] * v[i + j + 1];
				}
				else {
					ll tmp = vv[j][j + k] + vv[j + k+1][j + i] + v[j] * v[j + k + 1] * v[i + j + 1];
					if (ans > tmp)ans = tmp;
				}
			}
			vv[j][i + j] = ans;
		}
	}
	cout << vv[0][n - 1] << endl;
}