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, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll n;
        cin >> n;
        vll a(n+1);

        rep(i, 1, n+1) cin >> a[i-1] >> a[i];

        //print1d(a);

        vllvll dp(110, vll(110, inf));
        rep(i, 0, 110) dp[i][i] = 0;
        
        rep(width, 2, n+1) {
            rep(left, 1, n-width+2) {
                ll right = left + width - 1;
                rep(div, left, right) {
                    chmin(dp[left][right], dp[left][div] + dp[div+1][right] + a[left-1] * a[div] * a[right]);
                }
            }
        }

        cout << dp[1][n] << endl;
}

C++: #include<bits/stdc++.h>
using namespace std;

long long n;
long long r[110], c[110];
vector<vector<long long>> dp(110, vector<long long>(110, -1));
long long rec(long long l, long long m){
    if(dp[l][m] != -1) return dp[l][m];
    if(l + 1 == m) return dp[l][m] = r[l] * c[l] * c[m];
    else if(l == m) return dp[l][m] = 0;
    else{
        long long ans = 1e9;
        for (long long i = l; i < m; i++)
        {
            long long len = rec(l, i) + r[l] * c[i] * c[m] + rec(i + 1, m);
            ans = min(ans , len);
        }
        return dp[l][m] = ans;
    }
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> r[i] >> c[i];
    }

    int ans = rec(0, n-1);
    cout << ans << endl;
}

C++: #include<iostream>
#include<algorithm>
using namespace std;
int dp[101][101];
int r[100],c[100];
int solv(int a,int b){//a??????b-1?????§?????????????????????????????????????????°???????°???¨?????????????????????????????????
    if(dp[a][b]==-1){
        if(a == b-1){
            dp[a][b]=0;
        }else if(a==b-2){
            dp[a][b]=r[a]*c[a]*c[a+1];
        }else{
            int Pmin=999999999;
            for(int j=a+1;j<b;j++){
                int tmp=solv(a,j)+solv(j,b)+r[a]*r[j]*c[b-1];
                Pmin=min(Pmin,tmp);
            }
            dp[a][b]=Pmin;
        }
    }
    return dp[a][b];
}
int main(){
    for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            dp[i][j]=-1;
        }
    }
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>r[i]>>c[i];
    }
    int ans=solv(0,N);
    cout<<ans<<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=0;i<n;i++) cin >> p[i] >> p[i+1];
    for(int l=1;l<=n;l++) {
        for(int i=0;i<=n-l;i++) {
            int j = i + l;
            if(l==1) m[i][j] = 0;
            else if(l==2) m[i][j] = p[i]*p[i+1]*p[j];
            else {
                m[i][j] = 1000000000;
                for(int k=1;k<l;k++) {
                    m[i][j] = min(m[i][j], m[i][i+k] + m[i+k][j] + p[i]*p[i+k]*p[j]);
                }
            }
        }
    }
    //cout << m[4][6] << endl;
    cout << m[0][n] << endl;
    
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

#define N 100
#define INF 1000000
int main(){
	int n, tmp, p[N + 1], dp[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++){
		dp[i][i] = 0;
	}
	
	for(int l = 2 ; l <= n ; l++){    //l = ???????????????????????????????????????
		for(int i = 1 ; i <= n - l + 1 ; i++){
			int j = i + l - 1; 
			dp[i][j] = INF;
			for(int k = i ; k <= j - 1 ; k++){
				tmp = dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j];
			if(dp[i][j] > tmp) dp[i][j] = tmp;
			else dp[i][j] = dp[i][j];
				}
		}
	}
	
	cout << dp[1][n] << endl;
	
	return 0;
}

C++: #include<cstdio>
#include<algorithm>
static const int 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+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>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int n;

int m[101][101];

int p[101];


void matrix(){
  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] = 1000000;
      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]);
      }
    }
  }
}

int main(){

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

  matrix();



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