Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for k := i; k <= j-1; k++ {
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

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

int solve(int *cr, int n) {
  int m[101][101];
  for (int i = 1; i <= n; i++) m[i][i] = 0;

  for (int length = 2; length <= n; length++) {
    for (int begin = 1; begin <= n - length + 1; begin++) {
      int end = begin + length - 1;
      m[begin][end] = numeric_limits<int>::max();
      for (int k = begin; k <= end - 1; k++) {
        m[begin][end] = min(m[begin][end], m[begin][k] + m[k + 1][end] + cr[begin - 1] * cr[k] * cr[end]);
      }
    }
  }
  return m[1][n];
}

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

  int n;
  cin >> n;

  int cr[101];

  for (int i = 1; i <= n; i++) {
    cin >> cr[i - 1] >> cr[i];
  }

  cout << solve(cr, n) << endl;

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

UL N;
ULL dp[101][101];
ULL R[100][2];

int main() {
 cin>>N;
 rep(i,N) rep(j,2) cin>>R[i][j];
 rep(i,N+1) rep(j,N+1) dp[i][j]=1000000000000;
 rep(i,N) dp[i][i+1]=0;
 for(UL j=2; j<=N; j++) for(UL i=j-2; i!=~0u; i--){
  for(UL k=i+1; k<=j-1; k++){
   dp[i][j]=min(dp[i][j],
    dp[i][k]+dp[k][j]+R[i][0]*R[j-1][1]*R[k][0]
   );
  }
 }
 cout<<dp[0][N]<<endl;
 return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, r[100], c[100], dp[100][101];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d%d", &r[i], &c[i]), dp[i][i] = 0;
	for(int i = 1; i < n; i++) {
		for(int j = 0; i + j <= n; j++) {
			dp[j][i + j] = min(dp[j][i + j - 1], dp[j + 1][i + j]) + c[j] * r[i + j - 1];
		}
	}
	printf("%d\n", dp[0][n]);
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dp[111][111];
int mat[111][2];

int solve(int l, int r){
    if(l + 1 >= r) return 0;
    if(dp[l][r]) return dp[l][r];

    int mi = INF;
    for(int i=l+1;i<r;++i){
        chmin(mi, solve(l, i) + solve(i, r) + mat[l][0] * mat[i][0] * mat[r-1][1]);
    }
    return dp[l][r] = mi;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    REP(i,n) cin >> mat[i][0] >> mat[i][1];
    cout << solve(0,n) << endl;
}

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

#define MAX_N 100
#define R(i) (m[2*(i)])
#define C(i) (m[2*(i)+1])

typedef int int32_t;

// ??????????¨????????????§DP???

int main(void) {
    int n;
    int m[2 * MAX_N] = {};

    int dp[MAX_N][MAX_N] = {};

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &R(i), &C(i));
    }

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

    printf("%d\n", dp[0][n-1]);
    return 0;
}

C++: #include <stdio.h>
#include <limits.h>
#define MAX 100

int main(){
	int n, m[MAX+1][MAX+1];
	int i, j, k, r, min;
	
	scanf("%d", &n);
	for(i=1;i<=n;++i) {
		scanf("%d %d", &m[i][i-1], &m[i+1][i]);
		m[i][i] = 0;
	}
	
	for(r=2;r<=n;++r){
		for(i=1;i<=n-r+1;++i){
			j=i+r-1;
			m[i][j] = INT_MAX;
			for(k=i;k<=j-1;++k){
				min = m[i][k]+m[k+1][j]+m[i][i-1]*m[k+1][k]*m[j+1][j];
				if(m[i][j] > min) m[i][j] = min;
			}
		}
	}
	printf("%d\n", m[1][n]);
	return 0;
}

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

using namespace std;

const int INFTY = (1<<30);

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

    vector< vector<int> > cost(N);
    cost[0].assign(N, 0);
    for (int l = 2; l < N + 1; l++)
    {
        cost[l - 1].assign(N - l + 1, INFTY);
        for (int num = 0; num < N - l + 1; num++)
        {
            for (int k = 1; k < l; k++)
            {
                cost[l-1][num] = min(
                    cost[l-1][num],
                    cost[k-1][num] + cost[l-1-k][num+k] + A[num]*A[num+k]*A[num+l]
                );
            }
        }
    }
    cout << cost[N-1][0] << endl;
}

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

static const int N = 100;

int main()
{
  int p,ppp[N+1],m[N+1][N+1];

  cin >> p;

  for( int i = 1; i <= p; i++)
    {
      cin >> ppp[i-1] >> ppp[i];
    }

  for (int i = 1; i <= p; i++) m[i][i] = 0;
  for (int k = 2; k <= p; k++)
    {
      for(int i = 1; i <= p-k+1 ; i++)
	{
	  int j = i + k - 1;
	  m[i][j] = (1 << 21);

	  for ( int q = i; q <= j-1 ; q++)
	    {
	      m[i][j] = min(m[i][j], m[i][q] + m[q+1][j] +
			      ppp[i-1] * ppp[q] * ppp[j]);
	    }
	}
    }

  cout << m[1][p] << endl;

  return 0;
}