Go: package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	mm := make([]int, n+1)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, n+1)
	}
	for i := 0; i < n; i++ {
		mm[i] = getNextInt(scanner)
		mm[i+1] = getNextInt(scanner)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			for k := i; k <= j-1; k++ {
				d := dp[i][k] + dp[k+1][j] + mm[i-1]*mm[k]*mm[j]
				if dp[i][j] == 0 || dp[i][j] > d {
					dp[i][j] = d
				}
			}
		}
	}

	fmt.Fprintln(writer, dp[1][n])

	writer.Flush()
}

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