Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	m := make([][]int, n)
	sizes := make([][]int, n)
	for i := 0; i < n; i++ {
		sizes[i] = []int{nextInt(), nextInt()}
		m[i] = make([]int, n)
	}
	// fmt.Println(sizes)

	for w := 1; w < n; w++ {
		for i := 0; i < n-w; i++ {
			j := i + w
			minBetweenIandJ := 10000000
			for k := i; k < j; k++ {
				// fmt.Println(i, j, k, m[i][k], m[k+1][j], sizes[i][0]*sizes[k][1]*sizes[j][1])
				minBetweenIandJ = min(minBetweenIandJ, m[i][k]+m[k+1][j]+sizes[i][0]*sizes[k][1]*sizes[j][1])
			}
			m[i][j] = minBetweenIandJ
		}
	}
	// for i := 0; i < len(m); i++ {
	// 	fmt.Println(stringifyArray(m[i]))
	// }
	fmt.Println(m[0][n-1])
}

C++: #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
 
int main()
{
    int n;
    cin >> n;
    vector<int> p(n + 1);
    for(int i = 0; i <= n; i++){
        int a,b;
        cin >> a >> b;
        if(!i) {
         p[i] = a;
         i++;
        }
        p[i] = b;
    }
    
    vector<vector<int>> m(n + 1, vector<int>(n + 1, 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] << endl;
    return 0;
}

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

int main() {
  
 int n;
 cin >> n;

 vector<long long> p(n+1);
 for(int i = 1;i <= n;i++) {
   cin >> p.at(i-1) >> p.at(i);
 }

 vector<vector<long long> > dp(n+1,vector<long long>(n+1,0));

 for(int l = 2;l <= n;l++) {
   for(int i = 1;i <= n-l+1;i++) {
     int j = i + l - 1;
     dp[i][j] = (1<<21);
     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;
 
 
  
}

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

void fnInput(vector<int>& rvnMtrx)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMtrx.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; ++i)
    cin >> rvnMtrx[i] >> rvnMtrx[i + 1];
}

int fnMtrxChainMultpl(vector<vector<int>>& rvvnDetDP, const vector<int>& cnrvnMtrx)
{
  const int nMAXSIZ = cnrvnMtrx.size() - 1;
  for (int i = 1; i <= nMAXSIZ; ++i)  rvvnDetDP[i][i] = 0;

  for (int nDif = 1; nDif <= nMAXSIZ - 1; ++nDif)
    for (int nBgn = 1; nBgn <= nMAXSIZ - nDif; ++nBgn)
    {
      int nEnd = nBgn + nDif;
      for (int nx = nBgn; nx <= nEnd - 1; ++nx)
        rvvnDetDP[nBgn][nEnd] =
          min(rvvnDetDP[nBgn][nEnd],
              rvvnDetDP[nBgn][nx] + rvvnDetDP[nx + 1][nEnd] 
                                  + cnrvnMtrx[nBgn - 1] * cnrvnMtrx[nx] * cnrvnMtrx[nEnd]);
    }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnDetDP; 
  vector<int> vnMtrx;

  fnInput(vnMtrx);
  vvnDetDP.resize(vnMtrx.size(), vector<int>(vnMtrx.size(), INT_MAX));

  fnMtrxChainMultpl(vvnDetDP, vnMtrx);
  cout << vvnDetDP[1][vnMtrx.size() - 1] << endl;
  return 0;
}

C++: #include<iostream>

using namespace std;

void MATRIX_CHAIN_ORDER(int n, int p[]){
    int m[n+1][n+1];
    int s[n][n+1];

    for(int i = 1; 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] = 2000000000;
            for(int k = i; k <= j-1; k++){
                int q = m[i][k] + m[k+1][j] + (p[i-1] * p[k] * p[j]);
                if(q < m[i][j]){
                    m[i][j] = q;
                    s[i][j] = k;
                }
            }
        }
    }
    cout << m[1][n] << endl;
}

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

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll dp[105][105]; // 区間[i,j)の連鎖行列積の最小回数

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll v(n+1);
  rep(i,n){
    cin>>v[i]>>v[i+1];
  }
  
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  
  for(ll l=2; l<=n; l++){
    for(ll i=0; i<n-l+1; i++){
      ll j=i+l;
      // [j,j+i)を更新する
      dp[i][j]=LINF;
      for(ll k=i+1; k<j; k++){
        chmin(dp[i][j],dp[i][k]+dp[k][j]+v[i]*v[k]*v[j]);
      }
    }
  }
  
  cout<<dp[0][n]<<endl;
}

C++: #include <bits/stdc++.h>
#define lp(n) for(int i = 0; i < n; i++)
using namespace std;
int main(){
  int n, t;
  int dp[101][101];
  int A[101];
  cin >> n;
  cin >> A[0] >> A[1];
  for(int i = 1; i < n; i++) {
    cin >> t >> A[i+1];
  }
  for(int i = 1; i <= n; i++) dp[i][i] = 0;
  for(int l = 2; l <= n; l++) {
    for(int i = 1; i <= n-l+1; i++) {
      int j = i + l - 1;
      dp[i][j] = 1e9;
      for(int k = i; k <= j-1; k++) {
	int q = dp[i][k] + dp[k + 1][j] + A[i - 1]*A[k]*A[j];
	dp[i][j] = min(dp[i][j], q);
      }
    }
  }
  /*
    for(int i = 1; i <= n; i++) {
    for(int j = n; j >= 1; j--)cout << dp[i][j] << " ";	
    cout << endl;
    }
  */
  cout << dp[1][n] << 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][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 << 22);
            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;
}