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>
using namespace std;
int dp[101][101];
class point {
public: int x, y;
};
point p[101];
int n;
int solve(int left, int right) {
	if (left == right) return dp[left][right] = 0;
	if (dp[left][right]) return dp[left][right];
	else
	{
		int min = 1<<29;
		for (int i = left; i < right; i++) {
			int k = dp[left][i] + dp[i + 1][right] + p[left].x * p[i + 1].x * p[right].y;
			if (k < min) min = k;
		}
		 dp[left][right] = min;
		 return min;
	}
}
int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i].x>>p[i].y;
	}
	for(int l=1;l<n; l++)
	for (int i = 0; i < n; i++) {
		if (i + l < n)
		{
			solve(i, i + l);
		}
	}
	cout << dp[0][n - 1]<<endl;
}

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

#define int long long
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)



void solve(){
    int N;
    cin >> N;
    vector<int> p(N+1,0);
    for(int i=0; i<N; i++)
        cin >> p[i] >> p[i+1];
    
    vector<vector<int>> dp(N+1, vector<int>(N+1,0));
    
    for(int w=2; w<=N; w++){
        for(int i=1; i<=N-w+1; i++){
            int j=i+w-1;
            dp[i][j] = INF;
            for(int 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]);
            }
        }
    }
    cout << dp[1][N] << endl;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}

C++: #include <cstdio>
#include <cstdlib>
#include <cassert>
#include <memory.h>
#include <iostream>
#include <vector>
#include <string>
#include <ctime>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <cassert>
typedef unsigned long long ull;
typedef unsigned long ul;
#define rep(i,n) for(unsigned long long i = 0;i<n;i++)
#define clear(c) memset(c,0,sizeof(c))
#define clearm(c) memset(c,-1,sizeof(c))
using namespace std;

int main(){
	int n;

	cin >> n;
	ull dp[10+1][10+1];
	clearm(dp);
	ull r[n],c[n];
	rep(i,n){
		int rr,cc;
		cin >> rr >> cc;
		r[i] = rr;
		c[i] = cc;
	}
	rep(i,n-1){
		dp[i][i+1] = r[i] * c[i+1] * r[i+1];
	}
	rep(i,n){
		dp[i][i] = 0;
	}
	for(int dif = 2;dif<n;dif++){
		for(int i = 0;i + dif<n;i++){
			for(int j = i + 1;j <= i +dif - 1;j++){
				dp[i][i+dif] = min(dp[i][i+dif],dp[i][j] + dp[j+1][i+dif] + r[i] * c[j] * c[i+dif]);
			}
		}
	}
	cout << dp[0][n-1] << endl;
	return 0;
}

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

#define N 100

int M[101][101], p[101], n;

int solve()
{
	int l, i, j, k;
	for (l = 2; l <= n; l++) {
		for (i = 1; i <= n - l + 1; i++) {
			j = i + l - 1;
			M[i][j] = 1 << 30;
			for (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]);
		}
	}
	return M[1][n];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	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;

	cout << solve() << endl;
	return 0;
}

C++: #include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


#define repi(i,a,b) for(ll i = (a); i < (b); i++)
#define rep(i, n) for(ll i = 0; i < (n); ++i)


ll MOD = 1000000007;
ll inf = 1e18;
int main() {
	int N;
	cin >> N;
	vector<ll> R(N + 1);
	vector<ll> C(N + 1);
	repi(i, 1, N + 1) cin >> R[i] >> C[i];
	vector<vector<ll>> dp(N + 1);
	rep(i, N + 1) {
		dp[i].resize(N + 2);
		rep(j, N + 2)dp[i][j] = (i == j || i +1 == j) ? 0 : inf;
	}
	repi(x, 2, N+1) {
		repi(r, 1, N + 1) {
			int l = r + x;
			if (l > N + 1) break;
			ll m = inf;
			repi(j, r + 1, l) {
				m = min(m, dp[r][j] + dp[j][l] + (R[r] * R[j] * C[l - 1]));
			}
			dp[r][l] = m;
		}
	}
	cout << dp[1][N + 1] << endl;
	return 0;
}

C++: #include <iostream>
using namespace std;
int n, a[111], b[111], dp[111][111];
int main() {
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
	for(int i = 2; i <= n; i++) {
		for(int j = 0; j <= n - i; j++) {
			int l = j, r = j + i; // [l, r)
			dp[l][r] = 999999999;
			for(int k = l + 1; k < r; k++) {
				dp[l][r] = min(dp[l][r], dp[l][k] + dp[k][r] + a[l] * a[k] * b[r]);
			}
		}
	}
	cout << dp[0][n] << endl;
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 105;
vector<pp> rc(n);
vector<vector<int>> dp(n+1,vector<int>(n+1,-1));

int f(int l,int r){
        if(dp.at(l).at(r) >= 0) return dp.at(l).at(r);
        if( l+1 == r) return dp.at(l).at(r) = 0;
        int res = INF;
        for(int i = l+1;i<r;i++){
                res = min(res,f(l,i)+f(i,r)+rc.at(l).first*rc.at(i).first*rc.at(r-1).second);
        }
        return dp.at(l).at(r) = res;
}

int main() {
        cin >> n;
        rep(i,n){
                 int r,c;
                cin >> r >> c;
                rc.at(i) = make_pair(r,c);
        }
        
        cout << f(0,n) << endl;
        
        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]=10000000;
			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;
}