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>
#include <algorithm>
using namespace std;

const long N = 100;

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

     for ( long i = 1; i <= n; i++ )   m[i][i] = 0;
     for ( long l = 2; l <= n; l++ ) {
          for ( i = 1; i <= n - l + 1; i++ ) {
               long j = i + l - 1;
               m[i][j] = (1 << 21);
               for ( long 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;

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