Go: package main

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

const N = 100

func min(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, N+1)
	m := make([][]int, N+1)
	for i := range m {
		m[i] = make([]int, N+1)
	}
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 1; i <= n; i++ {
		scanner.Scan()
		p[i-1], _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		p[i], _ = strconv.Atoi(scanner.Text())
	}
	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
			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])
			}
		}
	}
	fmt.Println(m[1][n])
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;

int n = 105;
vector<pp> rc(n);
vector<vector<int>> dp(n+1,vector<int>(n+1,-1));

int f(int l,int r){
        if(dp.at(l).at(r) >= 0) return dp.at(l).at(r);
        if( l+1 == r) return dp.at(l).at(r) = 0;
        int res = INF;
        for(int i = l+1;i<r;i++){
                res = min(res,f(l,i)+f(i,r)+rc.at(l).first*rc.at(i).first*rc.at(r-1).second);
        }
        return dp.at(l).at(r) = res;
}

int main() {
        cin >> n;
        rep(i,n){
                 int r,c;
                cin >> r >> c;
                rc.at(i) = make_pair(r,c);
        }
        
        cout << f(0,n) << endl;
        
        return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int N;
int r[105],c[105];
ll dp[105][105]={0};

void dbg()
{
	for(int i=0;i<N;i++,puts(""))
		for(int j=0;j<N;j++)
			printf("%7d ",dp[i][j]);
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
		scanf("%d%d",&r[i],&c[i]);
	for(int i=0;i<N;i++)dp[i][i]=0;
	for(int l=1;l<N;l++)
		for(int i=0;i<N-l;i++)
		{
			int j=i+l;
			dp[i][j]=10000000;
			for(int k=0;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
		}
	printf("%lld\n",dp[0][N-1]);
	return 0;
}

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

#define INF 1000000000

struct matrix {
	int row;
	int column;

};

using namespace std;

//leftはindexの添え字
int partprob_matchain(vector<vector<int>>& table, matrix* mat, int left, int right) {
	if (left == right) return 0;
	if (table.at(left).at(right) != 0) return table.at(left).at(right);
	int temp, min = INF;
	for (int i = left, j = left + 1; j <= right; i++, j++) {
		temp = partprob_matchain(table, mat, left, i);
		temp += partprob_matchain(table, mat, j, right);
		temp += mat[left].row * mat[i].column * mat[right].column;
		if (temp < min) min = temp;
	}
	table.at(left).at(right) = min;
	return min;
}


int matrix_chain(vector<vector<int>>& table, matrix* mat) {
	return partprob_matchain(table, mat, 0, table.at(0).size() - 1);
}


int main(void) {
	int size;
	cin >> size;
	matrix* mat = new matrix[size];
	vector<vector<int>> table(size, vector<int>(size));

	for (int i = 0; i < size; i++) cin >> mat[i].row >> mat[i].column;

	cout << matrix_chain(table, mat) << endl;
	delete[] mat;
	return 0;

}

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

inline int MIN(int a,int b){
	return ((a)<(b)?(a):(b));
}

int minimumProduct(int left, int right, vector<pair<int,int> >& mat, vector<vector<int> >& product) {
	if(left==right) return 0;
	if(product[left][right]!=-1) {
		return product[left][right];
	}
	int i,min=INT_MAX;
	for(i=left; i<right; ++i) {
		min=MIN(min,minimumProduct(left,i,mat,product)
				+minimumProduct(i+1,right,mat,product)
				+mat[left].first*mat[right].second*((i==right-1)?mat[right].first:mat[i].second));
	}
	return product[left][right]=min;
}

int main() {
	int n;
	int i,j;
	vector<pair<int,int> > mat;
	vector<vector<int> > product;

	scanf("%d",&n);
	mat.resize(n);
	product.resize(n);
	for(i=0; i<n; ++i) {
		product[i].resize(n);
		scanf("%d%d",&mat[i].first,&mat[i].second);
		for(j=0; j<n; ++j) {
			product[i][j]=-1;
		}
	}
	printf("%d\n",minimumProduct(0,n-1,mat,product));
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const int MAXN = 100+7;

int p[MAXN];
int dp[MAXN][MAXN];
int n;
void generate_dp(){
    for(int i = 1; i <= n; i++){
        dp[i][i] = 0;
    }
    for(int b = 1; b < n; b++){
        for(int i = 1; i <= n-b; i++){
            int j = i+b;
            int k; k = i;
            int min_x = dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j];
            for(k = i+1; k < j; k++){
                if(dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j] < min_x){
                    min_x = dp[i][k] + dp[k+1][j] + p[i-1]*p[k]*p[j];
                }
            }
            dp[i][j] = min_x;
        }
    }
}
int main(){

    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%d %d", &p[i], &p[i+1]);
    }
    generate_dp();
    printf("%d\n", dp[1][n]);

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	ll a, b;
	vector<pair<ll, ll>> v;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		v.push_back({a, b});
	}

	vector<vector<ll>> dp(n, vector<ll>(n, -1));
	function<ll(int, int)> f = [&](int i, int j)
	{
		if (i == j)
			return 0LL;

		if (dp[i][j] != -1)
			return dp[i][j];

		ll r = 1LL<<62;
		for (int k = i; k < j; ++k)
			r = min(r, f(i, k)+f(k+1, j)+v[i].first*v[j].second*v[k].second);

		return dp[i][j]=r;
	};

	cout << f(0, n-1) << "\n";

	return 0;
}

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;
}