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;

const int N=110;

int a[N],dp[N][N];

int main()
{
    int n;

    scanf("%d",&n);

    for(int i=1;i<=n;i++) scanf("%d %d",&a[i],&a[i+1]);

    memset(dp,0x3f3f,sizeof(dp));

    for(int i=1;i<=n;i++) dp[i][i]=0;

    for(int l=2;l<=n;l++)
    {
        for(int i=1;i+l<=n+1;i++)
        {
            int j=i+l-1;
            for(int k=i;k<j;k++)
            {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+a[i]*a[j+1]*a[k+1]);
            }
        }
    }

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

    return 0;
}

C++: #include <iostream>
#include <utility>
#include <vector>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using P = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl
#define MOD 1000000007
#define INF 1000000000

vector<P> M;
VVI dp;
int solve(int start, int end) {
  if (dp[start][end] != INF)
    return dp[start][end];
  if (start + 2 == end)
    return dp[start][end] = dp[start][start+1] + dp[start+1][end] + M[start].first * M[start].second * M[start+1].second;
  int res = INF;
  for(int i = start; i + 1 != end; ++i) {
    res = min(res, solve(start, i + 1) + solve(i + 1, end) + M[start].first * M[i].second * M[end-1].second);
  }
  return dp[start][end] = res;
}
int main() {
  IN(N);
  dp.resize(N+1, VI(N+1, INF));

  REP(i, N) {
    IN(row);
    IN(column);
    M.push_back(make_pair(row, column));
    dp[i][i] = 0;
    dp[i][i+1] = 0;
  }
  OUT(solve(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[1][n] << endl;

   return 0;
}

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

int n, a[100], v[101];
long sum, m = 1000000000;
bool f[100], g[100];

void permsum(int p) {
	if (p == n - 1) {
		sum = 0;
		memset(g, 0, 100);
		for (int i = 0; i < n - 1; i++) {
			g[a[i]] = 1;
			int u = 1, w = 1;
			while (g[a[i] - u])
				u++;
			while (g[a[i] + w])
				w++;
			sum += v[a[i] - u] * v[a[i]] * v[a[i] + w];			
		}
		if (m > sum)
			m = sum;
	}
	else {
		for (int j = 0; j < n - 1; j++) {
			if (!f[j]) {
				a[p] = j + 1;
				f[j] = 1;
				permsum(p + 1);
				f[j] = 0;
			}
		}
	}
}

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> v[i] >> v[i + 1];

	permsum(0);

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

	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#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;    
    
    return 0;
}

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

int main(){

    int n;
    scanf("%d", &n);

    int m[101][101], p[101];

    for(int i=1; i<=n; i++){
        int r, c;
        scanf("%d %d", &r, &c);
        p[i-1] = r; //これはなかなか思いつかない
        p[i] = c;
    }

    //行列の積になっていない
    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]);
            }
        }
    }

    printf("%d\n", m[1][n]);
    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 - 1]);
			}
		}
	}
	cout << dp[0][n] << endl;
}

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;

  return 0;
}

C++: #include<stdio.h>
#define  N 100
 
int main() {
  int n,p[N+1], m[N+1][N+1];
  scanf("%d",&n);
  for (int i = 1;i <=n; i++) {
    scanf("%d %d",&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-1; i++){
    int j = i + l -1;
    m[i][j] = 10000000;
    for (int k = i;k <= j -1;k++) {
      if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j])
      m[i][j] = m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
      }
    }
  }
 
  printf("%d\n",m[1][n]);
  return 0;
}