Go: package main

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

const N = 100

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

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var p [N]int
	var m [N + 1][N + 1]int
	for i := 1; i <= n; i++ {
		sc.Scan()
		p[i-1], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		p[i], _ = strconv.Atoi(sc.Text())
	}

	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])
			}
		}
	}

	return fmt.Sprintf("%d", m[1][n])
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
	int INFTY = 1000000000;

	int n;
	scanf("%d", &n);

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

	int m[n + 1][n + 1];

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			m[i][j] = 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 << i << ":" << j << "," << m[i][j] << endl;
			}
		}
	}
	cout << m[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 = 0;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>
#define eol '\n'
using namespace std;

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

  int n;
  cin >> n;

  vector< vector<int> > mat(n, vector<int>(n, (1 << 21)));
  vector<int> r(n), c(n);
  
  for (int i = 0; i < n; i++) {
    mat[i][i] = 0;
    cin >> r[i] >> c[i];
  }
  
  for (int l = 1; l < n; l++) {
    for (int i = 0; i < n - l; i++) {
      int j = i + l;
      for (int k = i; k < j; k++) {
        mat[i][j] = min(mat[i][j], mat[i][k] + mat[k+1][j] + r[i] * c[k] * c[j]);
      }
    }
  }

  cout << mat[0][n-1] << eol;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
#define MAX 100
int main() {

    int n;
    cin >> n;
    int p[MAX+1], m[MAX+1][MAX+1];
    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] = INT_MAX;     //INFいれる
            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 <bits/stdc++.h>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int n;
int m[110][2], dp[110][110];

int rec(int l, int r) {
    if (dp[l][r] != -1) {
        return dp[l][r];
    }

    if (abs(l - r) <= 1) {
        return dp[l][r] = 0;
    }

    int res = iINF;

    if (abs(l - r) == 2) {
        return dp[l][r] = m[l][0] * m[l][1] * m[r - 1][1];
    }

    for (int mid = l + 1; mid < r; mid++) {
        res = min(
            res, rec(l, mid) + rec(mid, r) + m[l][0] * m[mid - 1][1] * m[r - 1][1]);
    }

    return dp[l][r] = res;
}

int main() {
    cin >> n;
    REP(i, n) {
        int r, c;
        cin >> r >> c;
        m[i][0] = r;
        m[i][1] = c;
    }

    memset(dp, -1, sizeof(dp));

    cout << rec(0, n) << endl;
    return 0;
}

C++: #include <iostream> 
#include <math.h> 
 
using namespace std; 
 
int r[45] = {0}; 
int a[100][100] = {0}; 
 
int f(int n, int m); 
int f(int n, int k, int m); 
 
 
int f(int n, int k, int m) 
{ 
    return f(n,k) * f(k+1,m) + (r[n] * r[k+1] * r[m+1]); 
} 
 
int f(int n, int m) 
{ 
    if (n==m) return 1; 
    int & ra = a[n][m]; 
    if (ra) return ra; 
    ra = INT_MAX; 
    for (int k=n;k<m;k++) 
    { 
        int ans = f(n,k,m); 
        if (ans < ra) ra = ans; 
    } 
    return ra; 
} 
 
int main() 
{ 
    int rr = 0; 
    int cc = 0; 
    int n = 0; 
    cin >> n; 
    for (int i=0;i<n;i++) 
    { 
        cin >> rr >> cc; 
        r[i]=rr; 
        r[i+1]=cc; 
    } 
    for (int i=0;i<n-1;i++) 
    { 
        a[i][i+1] = r[i] * r[i+1] * r[i+2]; 
    } 
    int ans = f(0,n-1); 
    cout << ans << endl; 
}

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

#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

static const int N = 100;



int main(int argc, char const *argv[]) {
  cin.tie(0); ios::sync_with_stdio(false);
  int n;
  int p[N+1]; //M_i が p[i-1]行 p[i]列 となる
  int m[N+1][N+1]; //M_i ~ M_jまでをかけあわせたときの最小の掛け算の数
  std::cin >> n;
  REP1(i,n) std::cin >> p[i-1] >> p[i];
  REP1(i,n) m[i][i]=0;

  FOR(l, 2, n){
    REP1(i, n-l+1){
      int j = i+l-1;
      m[i][j] = INTINF;
      FOR(k, i, j-1){
        m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
      }
    }
  }

  std::cout << m[1][n] << '\n';

  return 0;
}

C++: #include <iostream>
#include <limits>

constexpr int MAXN = 100;
int C[MAXN + 1][MAXN + 1];
int M[MAXN][2];

int main() {
    int n;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> M[i][0] >> M[i][1];
    }

    for (int i = 0; i < n; i++) {
        C[i][i] = 0;
    }

    for (int j = 1; j < n; j++) {
        for (int i = j - 1; i >= 0; i--) {
            C[i][j] = std::numeric_limits<int>::max();
            for (int k = i; k < j; k++) {
                C[i][j] = std::min(C[i][j], C[i][k] + C[k+1][j] + M[i][0] * M[j][1] * M[k][1]);
            }
        }
    }
    std::cout << C[0][n-1] << std::endl;
}