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 <iostream>
using namespace std;
#define INF 200000000

int n,m[101],cm[101][101];

void calc(){
  int i,j,l,p,k;
  for (i=0;i<n;i++)cm[i][i]=0;
  for (l=1;l<n;l++){
    for(i=0;i<n-l;i++){
      j=i+l;
      cm[i][j]=INF;
      //cout << i << " "<< j << endl;
      for (k=i;k<j;k++){
	//cout << i << " "<< j <<" "<< k<<" "<<cm[i][k]<<" "<<cm[k+1][j] <<  endl;
	p=cm[i][k]+cm[k+1][j]+m[i]*m[k+1]*m[j+1];
	cm[i][j]=min(cm[i][j],p);
      }
    }
  }
}

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

  calc();

  cout << cm[0][n-1]<<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[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

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

int64_t calculateMultiply(std::vector<std::pair<int, int>>& v) {
  int n = v.size();
  std::vector<std::vector<int64_t>> m(n, std::vector<int64_t>(n, 0));
  for (int l = 1; l < n; ++l) {
    for (int i = 0; i < n-l; ++i) {
      int j = i+l;
      m[i][j] = INT64_MAX;
      for (int k = i; k < j; ++k) {
        int q = m[i][k] + m[k+1][j] + (v[i].first)*(v[k].second)*(v[j].second);
        if (q < m[i][j]) {
          m[i][j] = q;
        }
      }
    }
  }
  return m[0][n-1];
}


int main() {
  int n;
  std::cin >> n;
  std::vector<std::pair<int, int>> v;
  for (int i = 0; i < n; ++i) {
    int a, b;
    std::cin >> a >> b;
    v.push_back({a, b});
   }
  std::cout << calculateMultiply(v) << std::endl;
}

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

static const int N = 100;

int main(int argc, char const *argv[])
{
    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 "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<vector<int> > vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<string, int> psi;
typedef pair<int, int> pii;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define loop(i) for(int i = 0;true; i++)
#define all(x) (x).begin(), (x).end()
#define mn 1000000007
int main() {
	int N;
	cin >> N;
	vi A(N+1);
	vvi cost(N, vi(N,0));
	for (int i = 0; i < N; i++)
	{
		cin >> A[i] >> A[i + 1];
	}
	for (int i = 2; i <= N; i++)
	{
		for (int left = 0; left <= N-i; left++)
		{
			int right = left + i - 1;
			cost[left][right] =1e9;
			for (int k = left; k < right; k++)
			{
				cost[left][right] = min(cost[left][right], cost[left][k] +cost[k+1][right]+ A[left] * A[k+1] * A[right+1]);
			}
		}
	}
	cout << cost[0][N - 1] << endl;
};

C++: #include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;

const int NIL = -1;
const int MAX = 200000001;
int m[101][101];
int p[101];

int main(void)
{
	int n;
	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] = 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]);
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

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

static const int N=100;

//求解矩阵链乘法的最优解
//p 用于存储矩阵的行和列的
//dp[i][j] 表示从矩阵i乘到矩阵j的最小乘法次数

int main(){
    int n;
    int p[N+1],dp[N+1][N+1];

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

    for(int i=1;i<n;i++){
        dp[i][i]=0;
    }
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            dp[i][j]=(1<<21);//取一个很大的值
            for(int k=i;k<=j;k++){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    
    cout<<dp[1][n]<<endl;

    return 0;
}