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 <cstdio>
#include <algorithm>
#include <string>

using namespace std;

#define INFTY 2000000000

int p[100], c[105][105];

void solve( int n ){

    int i, j, k, l;

    for( i = 1; i <= n; i++ ) c[i][i] = 0;

    for( l = 2; l <= n; l++ ){

        for( i = 1; i <= n - l + 1 ; i++ ){

            j = i + l - 1;

            c[i][j] = INFTY;

            for( k = i; k <= j - 1; k++ ){

                c[i][j] = min( c[i][j], c[i][k] + c[k+1][j] + p[i-1] * p[k] * p[j] );

            }

        }

    }

}


int main(){

    int n, i, trash;

    scanf("%d", &n);

    for( i = 1; i <= n; i++ ){

        scanf("%d %d", &p[i-1], &p[i] );

    }

    solve(n);

    printf("%d\n", c[1][n]);

}

C++: #include <iostream>
#include <algorithm> // next_permutation
#include <iomanip>
#include <cmath>
#include <vector>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <list>
#include <numeric> //accumulate
//#include <unordered_map> //???????????\??¢??°
#include <fstream> //ifstream, ofstream

//#define NDEBUG //NDEBUG???#include <cassert>???????????????????????????????????´???assert?????????????????????????????????NDEBUG?????????????????????????????????????????????
#include <cassert> //assert


using namespace std;

//???????????°??????TEST????????????????????¬???????????????????????????????????¢????????????
#define TEST //*******************************************************************************************************************************************
//?????????????????¨??§?????\????????????????????????????????°?????????????¨???????????????????dout???????????????????????§???????????¬??????????????????????????????????????????
//??????????????????????????????????????????????????????????§?CPU???????£??????????????????§???TLE?????????????????????????????????????????§????????¨???                           ????????????????????????cerr????????£????????????????????????????????????
#ifdef TEST
#define dout cout
#define din cin
#else
stringstream dummy; //???????????°??????dout?????????????????????????????????
#define dout dummy.str(""); dummy.clear(stringstream::goodbit); dummy //dummy?????????????????????????????????????????¨?????¢?????¢???????????????
//???????????¨??????????????????goodbit?????????????????????????????¨???????????´????????????????????????????????¨?????°?????????????????§???????????????????????????????????? http://d.hatena.ne.jp/linden/20060427/p1
#endif

//?¨??????????????????????????????????????????????????????´??????OUTPUTFILE????????????????????¬???????????????????????????????????¢????????????
//#define OUTPUTFILE "output.txt" //*******************************************************************************************************************************************
#ifdef OUTPUTFILE
#define dout outputfile //??¨????????????TLE????????§?????????dout?????¨??¨??????????????¢????????????????????????????????????????????§????¨????????????´??????????????£??????????????????????¨?????????????????????????????????????????????§?????????????????????
ofstream outputfile(OUTPUTFILE);
#define OutputFilePath "/Users/Nag/Documents/Prgm/Test/DerivedData/Test/Build/Products/Debug/output.txt"
#endif

//?¨??????\???????????????????????????????????????????????´??????INPUTFROMTEXTFILE????????????????????¬???????????????????????????????????¢????????????
//#define INPUTFILE "input.txt" //*******************************************************************************************************************************************
#ifdef INPUTFILE
#define din inputfile
ifstream inputfile(INPUTFILE);
#endif


#define disp(A) dout << #A << " = " << (A) << endl
#define disP(A) dout << setw(3) << (A) << " " // << setw(3) ??????????????\????????????
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)

#define dispAll(A,n) dout << #A << " = "; rep(j, 0, (n)) {disP(A[j]);} dout << endl

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef unsigned long long ll;

const int INF = 1e9-1;

int N;
const int N_MAX = 100;
int m[N_MAX+2];
int dp[N_MAX][N_MAX]; //dp[i][j] = ??????M[i]??????M[j]?????§????????????????±?????????¨???????????????????????????????°??????°


int solve(int i, int j) {
//    dout<<"-------------\n";
//    disp(i); disp(j);
    
    if(i==j) return dp[i][j] = 0;
    if(dp[i][j]!=INF) return dp[i][j];
    
    int ans = INF;
    rep(k,i,j) {
        ans = min( ans, solve(i,k)+solve(k+1,j)+m[i]*m[k+1]*m[j+1] );
    }
    
    dp[i][j] = ans;
    
//    //test display
//    dout<<"        j = ";
//    rep(j,0,N) disP(j);
//    dout<<endl;
//    rep(i,0,N) {
//        disP(i);
//        dispAll(dp[i], N);
//    }
    
    return ans;
}

int main() {
    din >> N;
    int r, c;
    rep(i,0,N) {
        cin >> r >> c;
        if(i==0) m[i] = r, m[i+1] = c;
        else m[i+1] = c;
    }
    
    rep(i,0,N) {
        rep(j,0,N) {
            dp[i][j] = INF;
        }
    }

    dout<<solve(0,N-1)<<endl;
    
    
    
#ifdef INPUTFILE
    inputfile.close();
#endif
    
#ifdef OUTPUTFILE
    outputfile.close();
    cout << "\"" << OutputFilePath << "\"" << endl;
#endif
    
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <vector <ll>> dp(n, vector <ll> (n));
  vector <ll> v(n+1);
  rep(i, n) cin >> v.at(i) >> v.at(i+1);
  rep(i, n) dp.at(i).at(i) = 0;
  for (ll i = 2; i <= n; i++) {
    for (ll j =  0; i+j-1 < n; j++) {
      ll k = i+j-1;
      dp.at(j).at(k) = INF;
      for (ll l = j; l < k; l++) {
        dp.at(j).at(k) = min(dp.at(j).at(k), 
                             dp.at(j).at(l)+dp.at(l+1).at(k)+v.at(j)*v.at(l+1)*v.at(k+1));
      }
    }
  }
  cout << dp.at(0).at(n-1) << endl;
}