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 <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;
llint n;
vector<vector<llint>> dp;

vector<pair<llint, llint>> v;
llint recur(llint l,llint r){
    if(r-l==1){
        return dp[l][r]=0;
    }
    if(r-l==2){
        return dp[l][r] = v[l].first * v[l].second * v[r-1].second;
    }
    if(dp[l][r]!=-1){
        return dp[l][r];
    }
    llint result = linf;
    FOR(i,l+1,r){
        result = min(result, recur(l,i) +  recur(i,r) + v[l].first * v[i].first * v[r-1].second);
    }
    return dp[l][r]=result;
}
int main(){

    cin >> n;
    v.resize(n);
    dp.resize(n, vector<llint>(n + 1, -1));
    REP(i,n){
        cin >> v[i].first >> v[i].second;
    }
    cout << recur(0, n) << endl;
    return 0;
}

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

static const int INFTY = 2000000000;

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

	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] = INFTY;
			for (int k = i; k < j; 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 <vector>
#include <iostream>
#include <string>
#include <memory>
#include <climits>

class M{
  int left, right;
  int cnt;
public:
  M(int l = 0, int r = 0, int c = 0):left(l),right(r),cnt(c){}
  const bool is_init(){return left != 0;}
  int get_l(){return left;}
  int get_r(){return right;}
  int get_c(){return cnt;}
  void show(){std::cout << "[ " << left << "," << cnt << "," << right << " ]";}
  M operator+(M &other){
	  M res(left, other.get_r(), cnt + other.get_c() + left * right * other.get_r());
    return res;
  }
  bool operator>(M &other){
	  return cnt > other.get_c();
  }
};
void show_line(int line){
  std::cout << "start dp line " << line << std::endl;
}
void show_all(std::vector<M> &vec){
  for (auto i = vec.begin(); i != vec.end(); ++i){
    i->show();
    std::cout << "-";
  }
  std::cout << std::endl;
}
M Max(0, 0, INT_MAX);
int dp(std::vector<std::vector<M>> memo){
	std::vector<M> vec;
	const int n = memo[0].size() - memo.size();
	for (auto i = 0; i < n; ++i){
    M min = Max;
		for (auto j = 0; j < memo.size(); ++j){
			M temp = memo.at(j).at(i) + memo.at(memo.size() - j - 1).at(i + j + 1);
			if (min > temp){
				min = temp;
			}
		}
		vec.push_back(min);
	}
	if (vec.size() == 1){
		return vec.back().get_c();
	}else{
		memo.push_back(vec);
		return dp(memo);
	}
}
int main(){
  std::cout << "start" << std::endl;
  int n;
  std::vector<M> v;
  std::cin >> n;
  for (auto i = 0; i < n; ++i){
	  int a, b;
	  std::cin >> a >> b;
	  v.push_back(M(a, b));
  }
  std::vector<std::vector<M>> memo;
  memo.push_back(v);
  std::cout << dp(memo) << std::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];

	scanf("%d", &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]);
				}
			}
		}

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

		return 0;
	}

C++: #include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)


using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

int N;
vector<P> p(105);
ll dp[105][105];
queue<P> que;
ll rec(int l = 0, int r = N){
    if(r - l <= 1)return 0;
    if(r - l == 2){
        return p[l].first * p[l].second * p[r-1].second;
    }
    ll &ret = dp[l][r];
    if(ret != INF)return ret;
    for(int i = l + 1; i <= r - 1; i++){
        ll rr = rec(l, i) + rec(i, r) + (p[l].first * p[i].first * p[r-1].second);
      que.push(P(i, rr));
        chmin(ret, rr);
    }
    return ret;
}

int main(){
    cin >> N;
    rep(i, N){
        ll a, b;
        cin >> a >> b;
        p[i] = P(a, b);
    }
    rep(i, 105)rep(j, 105)dp[i][j] = INF;
    ll res = rec();

  //cout << p[1].first << " " << p[1].second << " " << p[2].second << endl;
    cout << res << endl;
}

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

int N ;
int a[101][101];
int m[101][2];

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

    for (int j = 1; j <= N; ++j) {
        a[j][j] = 0;
    }

    for (int k = 1; k < N; ++k) {
        for (int l = 1; l <= N- k ; ++l) {
            int j = l + k;
            int mn = INT_MAX;
            for (int p = l; p <= j-1 ; ++p) {
                mn = min(mn, a[l][p] + a[p+1][j] + m[l][0] * m[p][1] * m[j][1]);
            }
            a[l][j] = mn;
        }
    }
    cout << a[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] << endl;

   return 0;
}