Go: package main

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

//util
var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func printList(list []int) {
	buf := bufio.NewWriter(os.Stdout)
	for _, v := range list {
		buf.Write([]byte(fmt.Sprintf(" %d", v)))
	}
	buf.Write([]byte("\n"))
	buf.Flush()
}

//solve
//単純な場合
func matrixChainMultiplication() {
	//行列が1つだけのとき
	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
			//kまでで区切る
			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])
			}
		}
	}
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

const MAX = 100

var n int
var p [MAX + 1]int

//m[i][j]: Mi * Mi+1 * ... * Mjを計算するときに必要なスカラー乗算の最小回数
var m [MAX + 1][MAX + 1]int

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()
	for i := 1; i <= n; i++ {

		p[i-1] = nextInt() //行数
		p[i] = nextInt()   //列数
	}

	matrixChainMultiplication()
	fmt.Println(m[1][n])
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

static const int N=100;

int main(){
int n,A[N+1],B[N+1][N+1];
cin>>n;
for(int i=1;i<=n;i++){
    cin>>A[i-1]>>A[i];
}
for(int i=1;i<=n;i++)B[i][i]=0;
for(int l=2;l<=n;l++){
    for(int i=1;i<=n-l+1;i++){
        int j=i+l-1;
        B[i][j]=(1<<21);
        for(int k=i;k<=j-1;k++){
            B[i][j]=min(B[i][j],B[i][k]+B[k+1][j]+A[i-1]*A[k]*A[j]);
        }
    }
}
cout<<B[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 = 0; i < N; i++) {
        cin >> p[i] >> p[i+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] = (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 <stdio.h>
#define N 101
#define INF 100000

int m[N][N];
int p[N];

int main(){
  int n, i, j, k, l, q;
  int trash;


  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%d%d", &p[i] ,&trash );
  }
  p[i] = trash;

  for( l = 2 ; l <= n ; l++ ){
    for( i = 1 ; i < (n+l-1) ; i++){
      j = i + l - 1;
      m[i][j] = INF;
      for( k = i ; k <= (j-1) ; k++ ){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	if( m[i][j] == -1 || m[i][j] > q){
	  m[i][j] = q;
	}
      }
    }
  }

  printf("%d\n" ,m[1][n]);

  return 0; // Don't forget 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 << 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;
}

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

int N ;
int a[101][101];
int m[101][2];

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

    for (int j = 1; j <= N; ++j) {
        a[j][j] = 0;
    }

    for (int k = 1; k < N; ++k) {
        for (int l = 1; l <= N- k ; ++l) {
            int j = l + k;
            int mn = INT_MAX;
            for (int p = l; p <= j-1 ; ++p) {
                mn = min(mn, a[l][p] + a[p+1][j] + m[l][0] * m[p][1] * m[j][1]);
            }
            a[l][j] = mn;
        }
    }
    cout << a[1][N] << endl;

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);
int m[101][101];
int p[101];
int l=0,n;
void matrixchainorder(){

  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]=INT_MAX;
      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 temp;
  cin>>n;
  rep(i,n+1)rep(j,n+1)m[i][j]=INT_MAX;
  for(int i=1;i<=n;i++)cin>>p[i-1]>>temp;
  p[n]=temp;
  matrixchainorder();
  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 ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

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