Go: package main

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

const N = 100

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

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var p [N]int
	var m [N + 1][N + 1]int
	for i := 1; i <= n; i++ {
		sc.Scan()
		p[i-1], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		p[i], _ = strconv.Atoi(sc.Text())
	}

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

	return fmt.Sprintf("%d", m[1][n])
}

func main() {
	fmt.Println(answer(os.Stdin))
}

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

const int INF = 1 << 28;

int main()
{
    int n;
    int dp[101][101];
    int r[102];
    
    cin >> n;
    
    fill((int*)dp, (int*)(dp + n), INF);
    
    for(int i = 0; i < n; ++i){
        cin >> r[i] >> r[i + 1];
        dp[i][i] = 0;
    }
    
    for(int w = 1; w < n; ++w){
        for(int i = 0, j ; j = i + w, j < n; ++i){
            for(int k = i; k < j; ++k){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + r[i] * r[k + 1] * r[j + 1]);
            }
        }
    }
    
    cout << dp[0][n-1] << endl;
    
}

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

void MatrixChainMultiplication(int n,int p[],int m[101][101]) {
	int i, j, k,l;
	for (i = 1; i <= n; i++) m[i][i] = 0;
	for (l = 2; l <= n; l++) {
		for (i = 1; i <= n - l +1; i++) {
			j = i + l - 1;
			m[i][j] = (1<<21);
			for (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, p[101], m[101][101];
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	MatrixChainMultiplication(n, p, m);
	cout << m[1][n] << endl;

	
}

C++: #include <bits/stdc++.h>
#define INF 1e7

using namespace std;
typedef long long int ll;

int main()
{
    int n;
    cin >> n;
    vector<int>l(n),r(n);
    for(int i = 0; i < n; i++) cin >> l[i] >> r[i];
    vector<vector<int>>dp(n,vector<int>(n,INF));
    for(int i = 0; i < n; i++) dp[i][i] = 0;
    for(int p = 2; p <= n; p++)
    {
        for(int i = 0; i+p-1 <= n-1; i++)
        {
            int j = i+p-1;
            int S = INF;
            for(int k = i; k < j; k++) S = min(S,dp[i][k]+dp[k+1][j]+l[i]*r[k]*r[j]);
            dp[i][j] = S;
        }
    }
    cout << dp[0][n-1] << endl;
}

C++: #include <bits/stdc++.h>
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]m[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] << endl;

  return 0;
}

C++: #include <cassert>
// #include <algorithm>
#include <iostream>
#include <vector>
#include <climits>

struct TSize
{
    int r;
    int c;
    TSize() : r(0), c(0) {}
    TSize(int Ar, int Ac)
     : r(Ar), c(Ac)
    {}
};

class TMcmSolver
{
    typedef std::vector<std::vector<int> > TMatrix;
    TMatrix FMemo;
    const std::vector<TSize>& FChain;

    static int Count(const TSize& Left, const TSize& Right)
    {
        return Left.r * Right.c * Left.c;
    }
    int Solve(int s, int l)
    {
        assert(s <= l);
        if(s == l) return 0;
        if(FMemo[s][l] != 0) return FMemo[s][l];
        if(s + 1 == l){
            FMemo[s][l] = Count(FChain[s], FChain[l]);
        }else{
            int min = INT_MAX;
            for(int i = s+1; i < l; ++i){
                int c = Solve(s, i) + Count(TSize(FChain[s].r, FChain[i].c), TSize(FChain[i+1].r, FChain[l].c)) + Solve(i+1, l);
                min = std::min(min, c);
            }
            FMemo[s][l] = min;
        }
        return FMemo[s][l];
    }
public:
    TMcmSolver(const std::vector<TSize>& Chain)
     : FChain(Chain)
    {
        FMemo.resize(Chain.size());
        for(std::size_t i = 0; i < FMemo.size(); ++i){
            FMemo[i].resize(Chain.size(), 0);
        }
    }
    int Answer()
    {
        return Solve(0, FMemo.size()-1);
    }
    void Print()const
    {
        for(std::size_t s = 0; s < FMemo.size(); ++s){
            for(std::size_t l = 0; l < FMemo[0].size(); ++l){
                std::cout << FMemo[s][l] << '\t';
            }
            std::cout << '\n';
        }
    }
};

int main()
{
    int n;
    std::cin >> n;
    if(n == 1){
        std::cout << 0 << std::endl;
        return 0;
    }
    std::vector<TSize> Chain(n);
    for(int i = 0; i < n; ++i){
        std::cin >> Chain[i].r >> Chain[i].c;
    }
    TMcmSolver Solver(Chain);
    
    std::cout << Solver.Answer() << std::endl;
    // Solver.Print();
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll dp[105][105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<pll> A(N);
    REP(i, N) {
        cin >> A[i].first >> A[i].second;
    }

    REP(i, N + 1) {
        REP(j, N + 1) {
            dp[i][j] = INF;
        }
        dp[i][i] = 0;
    }

    FOR(len, N, 1) {
        REP(left, N) {
            if (left + len >= N)
                break;
            REP(i, len) {
                ll mul = dp[left][left + i] + dp[left + i + 1][left + len];
                mul += A[left].first * A[left + i].second * A[left + len].second;
                dp[left][left + len] = std::min(dp[left][left + len], mul);
            }
        }
    }

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

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

int calc(const vector<pair<int, int> >& M, int idx_b, int idx_e,
         vector<vector<int> >& Memo) {
    if (idx_b == idx_e) return 0;
    if (Memo[idx_b][idx_e]) return Memo[idx_b][idx_e];
    int min = 2e9;
    for (int i = idx_b; i < idx_e; i++) {
        int val  = calc(M, idx_b, i, Memo) + calc(M, i + 1, idx_e, Memo)
                   + M[idx_b].first * M[i].second * M[idx_e].second;
        if (val < min) min = val;
    }
    return Memo[idx_b][idx_e] = 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);
    }
    vector<int> tmp(n, 0);
    vector<vector<int> > Memo(n, tmp);
    cout << calc(M, 0, M.size() - 1, Memo) << endl;

    return 0;
}

C++: #include <stdio.h>
#include <limits.h>
int main(){
  int n,p[101],i,j,k,l,x,m[101][101];
  scanf("%d",&n);
  for(i=1;i<=n;i++)scanf("%d %d",&p[i-1],&p[i]);
  for(i=1;i<=n;i++)m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INT_MAX;
      for(k=i;k<j;k++){
	x=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	if(m[i][j]>x)m[i][j]=x;
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}