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>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dp[111][111];
int mat[111][2];

int solve(int l, int r){
    if(l + 1 >= r) return 0;
    if(dp[l][r]) return dp[l][r];

    int mi = INF;
    for(int i=l+1;i<r;++i){
        chmin(mi, solve(l, i) + solve(i, r) + mat[l][0] * mat[i][0] * mat[r-1][1]);
    }
    return dp[l][r] = mi;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    REP(i,n) cin >> mat[i][0] >> mat[i][1];
    cout << solve(0,n) << endl;
}

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

#define MAX_N 100
#define R(i) (m[2*(i)])
#define C(i) (m[2*(i)+1])

typedef int int32_t;

// ??????????¨????????????§DP???

int main(void) {
    int n;
    int m[2 * MAX_N] = {};

    int dp[MAX_N][MAX_N] = {};

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &R(i), &C(i));
    }

    for (int i = 0; i < n-1; i++) {
        dp[i][i + 1] = R(i) * C(i) * C(i+1);
    }
    for (int i = 2; i < n; i++) {
        for (int j = 0; j <= n - i; j++) {
            dp[j][i + j] = INT32_MAX;
            for (int k = 0; k < i; k++) {
                 dp[j][i + j] = min(dp[j][i + j], dp[j][j+k] + dp[j+k+1][i+j] + R(j) * R(j+k+1) * C(i+j));
            }
        }
    }

    printf("%d\n", dp[0][n-1]);
    return 0;
}

C++: #include <stdio.h>
#include <limits.h>
#define MAX 100

int main(){
	int n, m[MAX+1][MAX+1];
	int i, j, k, r, min;
	
	scanf("%d", &n);
	for(i=1;i<=n;++i) {
		scanf("%d %d", &m[i][i-1], &m[i+1][i]);
		m[i][i] = 0;
	}
	
	for(r=2;r<=n;++r){
		for(i=1;i<=n-r+1;++i){
			j=i+r-1;
			m[i][j] = INT_MAX;
			for(k=i;k<=j-1;++k){
				min = m[i][k]+m[k+1][j]+m[i][i-1]*m[k+1][k]*m[j+1][j];
				if(m[i][j] > min) m[i][j] = min;
			}
		}
	}
	printf("%d\n", m[1][n]);
	return 0;
}

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

using namespace std;

const int INFTY = (1<<30);

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

    vector< vector<int> > cost(N);
    cost[0].assign(N, 0);
    for (int l = 2; l < N + 1; l++)
    {
        cost[l - 1].assign(N - l + 1, INFTY);
        for (int num = 0; num < N - l + 1; num++)
        {
            for (int k = 1; k < l; k++)
            {
                cost[l-1][num] = min(
                    cost[l-1][num],
                    cost[k-1][num] + cost[l-1-k][num+k] + A[num]*A[num+k]*A[num+l]
                );
            }
        }
    }
    cout << cost[N-1][0] << endl;
}

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

static const int N = 100;

int main()
{
  int p,ppp[N+1],m[N+1][N+1];

  cin >> p;

  for( int i = 1; i <= p; i++)
    {
      cin >> ppp[i-1] >> ppp[i];
    }

  for (int i = 1; i <= p; i++) m[i][i] = 0;
  for (int k = 2; k <= p; k++)
    {
      for(int i = 1; i <= p-k+1 ; i++)
	{
	  int j = i + k - 1;
	  m[i][j] = (1 << 21);

	  for ( int q = i; q <= j-1 ; q++)
	    {
	      m[i][j] = min(m[i][j], m[i][q] + m[q+1][j] +
			      ppp[i-1] * ppp[q] * ppp[j]);
	    }
	}
    }

  cout << m[1][p] << 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][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 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] << "\n";
????????return 0;
}

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

long int M[101][101];
long int a[100];
int n;
void solve(){
  for(int i=0;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;k++){
	        long int tmp = M[i][k]+M[k+1][j]+a[i-1]*a[k]*a[j];
		if(M[i][j]>tmp){
		    M[i][j] = tmp;	
		}
	    }
	}
    }
}

int main(){ 
   cin>>n;
   for(int i=0;i<n;i+=2){
	cin>>a[i]>>a[i+1];
   }
   solve();
   for(int i=0;i<=n;i++){
	for(int j=0;j<=n;j++){
//	    cout<<"("<<i<<","<<j<<")"<<M[i][j]<<" ";
	}
//	cout<<endl;
   }
   cout<<M[1][n-1]<<endl;
   return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
    int n,a;
    cin>>n;
    int p[n+1];
    for(int i=0;i<=n;i++){
        cin>>p[i]>>p[i+1];
    }
    int m[n+1][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]=100000000;
            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;
                }
            }
        }
    }
    cout<<m[1][n]<<endl;
    return 0;
}