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>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1001001001001001;

int n;
ll r[111], c[111];
ll dp[111][111]; // dp[le][ri] = [le, ri) の最小回数

ll rec(int le, int ri) {
    if (dp[le][ri] != INF) return dp[le][ri];
    if (ri - le - 2 == 0) {
        return dp[le][ri] = min(dp[le][ri], r[le] * c[le] * c[ri - 1]);
    }
    if (le + 1 < ri - 1) dp[le][ri] = min(dp[le][ri], rec(le + 1, ri) + r[le] * c[le] * c[ri - 1]);
    if (le < ri - 2) dp[le][ri] = min(dp[le][ri], rec(le, ri - 1) + r[le] * c[ri - 2] * c[ri - 1]);
    for (int md = le + 1; md < ri - 1; md++) {
        dp[le][ri] = min(dp[le][ri], rec(le, md) + rec(md, ri) + r[le] * c[md - 1] * c[ri - 1]);
    }
    return dp[le][ri];
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> r[i] >> c[i];
    for (int i = 0; i < 111; i++) {
        for (int j = 0; j < 111; j++) {
            dp[i][j] = INF;
        }
    }
    if (n == 1) {
        cout << 0 << endl;
        return 0;
    }
    rec(0, n);
    cout << dp[0][n] << endl;
}

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

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

static 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[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}

	cout << m[1][n] << endl;

	return 0;
}

C++: #include <cstdio>
#include <climits>

typedef struct{
    int r;
    int c;
}matrix;

int table[100][100];

int calc(matrix* m, int l, int r){
    if(r<=l+1)return 0;
    if(table[l][r]>0)return table[l][r];
    int i, tmp;
    int ans = INT_MAX;
    for(i=l+1;i<r;i++){
        tmp = m[l].r*m[i].r*m[r-1].c + calc(m,l,i) + calc(m,i,r);
        if(tmp<ans)ans = tmp;
    }
    table[l][r] = ans;
    return ans;
}

int main(){
    int i, j, n;
    matrix m[100];
    scanf("%d",&n);
    for(i=0;i<100;i++){
        for(j=0;j<100;j++){
            table[i][j] = 0;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&(m[i].r),&(m[i].c));
    }
    printf("%d\n",calc(m,0,n));
    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[i][n] << endl;
	
	return 0;
}

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

struct mat{
  int row, col;
};

int m[101][101];
mat p[101];

int main(){
  int n;
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> p[i].row >> p[i].col;
  for(int l = 2; l <= n; l++){
    for(int i = 1; i <= n - l + 1; i++){
      int j = i + l - 1;
      if(i == j) m[i][j] = 0;
      else{
	int minc = 1e9;
	for(int k = i; k < j; k++){
	  int x = m[i][k] + m[k+1][j] + p[i].row * p[k].col * p[j].col;
	  minc = minc < x ? minc : x;
	}
	m[i][j] = minc;
      }
    }
  }
  cout << m[1][n] << endl;
  return 0;
}