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>
using namespace std;

const long N = 100;

int main(){
	long n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (long i = 1; i <= n; i++){
		cin >> p[i - 1] >> p[i];
	}

	for (long i = 1; i <= n; i++) m[i][i] = 0;
	for (long l = 2; l <= n; l++){
		for (long i = 1; i <= n - l + 1; i++){
			long j = i + l - 1;
			m[i][j] = (1 << 21);
			for (long k = 0; 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 <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

const ll mod = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vvll dp(n, vll(n, INF));

  vll p(n + 1);
  rep(i, n) {
    cin >> p[i] >> p[i + 1];
    dp[i][i] = 0;
  }

  for (ll h = 1; h <= n - 1; h++) {
    for (ll i = 0; i <= n - 1 - h; i++) {
      ll j = i + h;
      for (ll k = i; k <= j - 1; k++) {
        chmin(dp[i][j], dp[i][k] + dp[k+1][j] + p[i] * p[k + 1] * p[j + 1]);
      }  // k
    }    // i
  }      // h

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

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;cin>>n;
	vector<int> v(n + 1);
	for(int i = 0; i < n; i++) {
		int a,b;cin>>a>>b;
		v[i] = a;
		if (i == n - 1){
			v[i + 1] = b;
		}
	}
	vector<vector<int>> dp(n,vector<int>(n,INF));
	for(int i = 0; i < n; i++) {
		dp[i][i] = 0;
	}

	for(int l = 1; l < n; l++) {//連鎖の大きさ(iとｊの幅)(j - i)
		for(int i = 0; i < n - l; i++) {
			int j = i + l;
			for(int k = i; k < j; k++) {
				dp[i][j] = min(dp[i][j],dp[i][k] + dp[k + 1][j] + v[i] * v[k + 1] * v[j + 1]);
			}
		}
	}
	cout << dp[0][n - 1] << endl;
	// for(int i = 0; i < n; i++) {
	// 	for(int j = 0; j < n; j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	return 0;
}

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=1;i<=n;i++) m[i][j]=0;
  for(int l=2;i<=n;i++){
    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 <bits/stdc++.h>
#define index indexxx
using namespace std;
int n;
int p[10000],m[1000][1000];
int index;
int fun(int left,int right)
{
	if(m[left][right]!=0)
		return m[left][right]; 
	if(left==right){
		return 0;
	}
	int i=left,j=right;
	int u=fun(left,left)+fun(left+1,right)+p[i-1]*p[i]*p[j];
	for(int k=i+1;k<j;k++){//遍历
		int t=fun(i,k)+fun(k+1,right)+p[i-1]*p[k]*p[j]; 
		if(t<u)
		{
			u=t;
		}
	}
	m[left][right]=u;
	return u;
}

int main(void)
{
	cin>>n;
	scanf("%d",p+(index++));
	scanf("%d",p+(index++));
	int tmp,x;
	for(int i=1;i<n;i++){
		scanf("%d",&x);
		scanf("%d",p+(index++));
	}
	printf("%d\n",fun(1,n));
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N;
int r[105],c[105];
ll dp[105][105]={0};

void dbg()
{
	for(int i=0;i<N;i++,puts(""))
		for(int j=0;j<N;j++)
			printf("%7d ",dp[i][j]);
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
		scanf("%d%d",&r[i],&c[i]);
	for(int i=0;i<N;i++)dp[i][i]=0;
	for(int l=1;l<N;l++)
		for(int i=0;i<N-l;i++)
		{
			int j=i+l;
			dp[i][j]=1e20;
			for(int k=0;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
		}
	printf("%lld\n",dp[0][N-1]);
	return 0;
}

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

using namespace std;
int p[100], m[100 + 1][100 + 1];

void matrixChainMultiplication(int n) {
	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]);
			}
		}
	}
}

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

	matrixChainMultiplication(N);
	cout << m[1][N] << endl;
	return 0;
}