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++: 
// #define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

ll INF = 1LL << 31;
int main()
{
    int n;
    cin >> n;
    vector<P> m(n);
    rep(i, n) cin >> m[i].first >> m[i].second;

    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, INF));
    rep(i, n + 1) dp[i][i] = 0;

    // start by doing a 1 matrix times 1 matrix multiplication
    // AB = A.x * A.y * B.y
    for (int w = 1; w <= n; w++)
    {
        // for each possible left most matrix for each width
        // i.e. until your "right" matrix defined by the width is m[n-1]
        for (int l = 0; l <= n - w; l++)
        {
            // as seen here.
            int r = l + w - 1;

            // for every matrix inbetween:
            for (int k = l; k < r; k++)
            {
                // multiplying (AB)(CDE) gives you an (A.x * B.y) x (C.x=B.y * E.y) mult.
                // Thus, this is a A.x * B.y * E.y + dp[A][B] + dp[C][E].

                // Do this for all possible combinations
                // e.g. A(BCD), (AB)(CD), (ABC)D where ABC-> A(BC) or (AB)C , etc.
                chmin(dp[l][r], m[l].first * m[k].second * m[r].second + dp[l][k] + dp[k + 1][r]);
            }
        }
    }

    cout << dp[0][n - 1] << endl;

    return 0;
}

C++: /*
 * Problem Description: Matrix Chain Multiplication
 * Category: Dynamic Programming
 * Author: Khan
 * Date: 20th October, 2017
 */

#include <iostream>
#include <algorithm>

using namespace std;

#define N 100

int main(int argc, char const *argv[])
{
    //freopen("sample.txt", "r", stdin);
    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<bits/stdc++.h>
#define N 105
using namespace std;
int n,u,k,v,e[N][N],cnt;
int ans1[N],ans2[N];
bool used[N];
 
void dfs(int x){
  if(used[x])return;
  used[x]=true;
  ans1[x]=cnt++;
  for(int i=0;i<n;i++)
    if(e[x][i])dfs(i);
  ans2[x]=cnt++;
}
 
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>u>>k;
    for(int j=0;j<k;j++)
      cin>>v,e[u-1][v-1]=1;
  }
  cnt=1;
  for(int i=0;i<n;i++){
    if(!used[i])dfs(i);
  }
  for(int i=0;i<n;i++){
    cout<<i+1<<' '<<ans1[i]<<' '<<ans2[i]<<endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define INF (int) 2e9
#define MOD (int) 1e9 + 7

#define MAX_N 100

int memo[MAX_N][MAX_N];
int row[MAX_N], col[MAX_N];

int f(int l, int r, int pos){
    if(pos != -1){
        if(pos == r){
            return INF;
        }
        return min(f(l, pos, -1) + f(pos + 1, r, -1) + row[l] * col[pos] * col[r], f(l, r, pos + 1));
    }
    if(memo[l][r]>0) return memo[l][r];
    if(r-l==0){
        return 0;
    }
    return memo[l][r] = f(l, r, l);
}

int main(){
    int n;
    cin >> n;
    
    rep(i, n){
        cin >> row[i] >> col[i];
    }
    cout << f(0, n-1, -1) << 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<algorithm>
using namespace std;
#define MAX 100
#define infinit 1e+8
int main() {
	int n,p[MAX],m[MAX+1][MAX+1];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i-1] >> p[i];
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (i == j || i==0 || j==0) m[i][j] = 0;
			else m[i][j] = infinit;
		}
    }
	for (int l = 2; l <= n; l++) {
		for (int i = 0; i <= n - l + 1;i++) {
			int j = i + l - 1;
			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;
	

}

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

using namespace std;

static const int N = 1000;
static int c[N + 1][N + 1] = {};

static int lcs(string& X, string& Y) {
  const size_t m(X.size());
  const size_t n(Y.size());

  int lcs = 0;
  
  for (size_t i = 1; i <= m; i++) {
    for (size_t j = 1; j <= n; j++) {
      if (X[i] == Y[j]) {
        c[i][j] = c[i - 1][j - 1] + 1;
      }
      else {
        c[i][j] = max(c[i - 1][j], c[i][j - 1]);
      }
      lcs = max(lcs, c[i][j]);
    }
  }
  return lcs;
}

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

  string X, Y;
  for (int i = 0; i < n; i++) {
    cin >> X;
    cin >> Y;
    cout << lcs(X, Y) << endl;
  }
 
  return 0;
}

C++: #include <bits/stdc++.h>
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;
}