Go: package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)

	P := make([]int, n+1)
	for i := 1; i <= n; i++ {
		l := nextInt(sc)
		P[i-1] = l
		m := nextInt(sc)
		P[i] = m
	}

	matrix := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		matrix[i] = make([]int, n+1)
	}

	for l := 2; l <= n; l++ {
		for i := 1; i <= n - l + 1; i++ {
			j := i + l - 1
			matrix[i][j] = (1 << 21)
			for k := i; k <= j-1; k++ {
				matrix[i][j] = min(matrix[i][j], matrix[i][k] + matrix[k+1][j] + P[i-1] * P[k] * P[j])
			}
		}
	}
	fmt.Println(matrix[1][n])
}

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[i][n] << endl;
	
	return 0;
}

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

int main() {
    int n;
    cin >> n;

    int R[101];
    int C[101];
    int A[101][101];
    for (int i = 1; i <= n; i++) {
        cin >> R[i] >> C[i];
        A[i][i] = 0;
    }

    for (int k = 2; k <= n; k++) {
        for (int i = 1; i <= (n - k + 1); i++) {
            int j = i + k - 1;
            A[i][j] = 10000001;
            for (int l = i; l < j; l++) {
                A[i][j] = min(A[i][j], A[i][l] + A[l+1][j] + (R[i] * C[l] * C[j]));
            }
        }
    }

    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];
  int i,j,k,l;
  cin >>n;
  for(i=1;i<=n;i++){
  cin >>p[i-1]>>p[i];
  }
  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]);
      }
    }
  }
  cout <<m[1][n]<<endl;
  
  return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int n;
	cin >> n;
	vector<int> c(n + 1);
	REP(i, n) {
		int r;
		cin >> r >> c[i + 1];
		if (i == 0) {
			c[0] = r;
		}
	}
	static int dp[101][101];
	FOR(i, 2, n + 1) {
		REP(j, n - i + 1) {
			int res = INT_MAX;
			FOR(k, 1, i) {
				int l = i - k;
				res = min(res, dp[k][j] + dp[l][j + k] + c[j] * c[j + k] * c[j + i]);
			}
			dp[i][j] = res;
		}
	}
	cout << dp[n][0] << 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;
}

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

void fnInput(vector<int>& rvnMtrx)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMtrx.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; ++i)
    cin >> rvnMtrx[i] >> rvnMtrx[i + 1];
}

int fnMtrxChainMultpl(vector<vector<int>>& rvvnDetDP, const vector<int>& cnrvnMtrx)
{
  const int nMAXSIZ = cnrvnMtrx.size() - 1;
  for (int i = 1; i < cnrvnMtrx.size(); ++i)  rvvnDetDP[i][i] = 0;

  for (int nDif = 1; nDif <= nMAXSIZ - 1; ++nDif)
    for (int nRow = 1; nRow <= nMAXSIZ - nDif; ++nRow)
    {
      int nCol = nRow + nDif;
      for (int nx = nRow; nx <= nCol - 1; ++nx)
        rvvnDetDP[nRow][nCol] =
          min(rvvnDetDP[nRow][nCol],
              rvvnDetDP[nRow][nx] + rvvnDetDP[nx + 1][nCol] 
                                  + cnrvnMtrx[nRow - 1] * cnrvnMtrx[nx] * cnrvnMtrx[nCol]);
    }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnDetDP; 
  vector<int> vnMtrx;

  fnInput(vnMtrx);
  vvnDetDP.resize(vnMtrx.size(), vector<int>(vnMtrx.size(), INT_MAX));

  fnMtrxChainMultpl(vvnDetDP, vnMtrx);
  cout << vvnDetDP[1][vnMtrx.size() - 1] << endl;
  return 0;
}