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++: #include<iostream>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

int minana(int a,int b){
  if(a<b){
    return a;
  }
  else if(a>b){
    return b;
  }
  else return a;
}


int main(){
  int n;
  cin>>n;
  int r[100];
  int m[101][101];
  int j;
  int q=0;
  //int c[n];
  for(int i=1;i<=n;i++){
    cin>>r[i-1]>>r[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++){
      j=i+l-1;
      m[i][j]=(1<<21);
      for(int k=i;k<j;k++){
	q=m[i][k]+m[k+1][j]+r[i-1]*r[k]*r[j];
	m[i][j]=minana(m[i][j],q);
      }
    }
  }
  
  cout<<m[1][n]<<endl;
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int solve(vector<vll> &c, vector<pii> &m, int s, int e1) {
  int e = e1 - 1;
  if (c[s][e1] != 0) return c[s][e1];
  
  if (e1 - s == 2) {
    c[s][e1] = m[s].first * m[s].second * m[e].second;
    return c[s][e1];
  }

  ll n_calc = LLONG_MAX;
  for (int i = s + 1; i < e1; i++) {
    ll total = 0;
    
    if (i - s > 1) {
      c[s][i] = solve(c, m, s, i);
      total += c[s][i];
    }
    
    if (e1 - i > 1) {
      c[i][e1] = solve(c, m, i, e1);
      total += c[i][e1];
    }

    total += m[s].first * m[i].first * m[e].second;
    
    n_calc = min(n_calc, total);
  }

  c[s][e1] = n_calc;
  return c[s][e1];
}

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

  vector<pii> m(n);
  rep(i, n) cin >> m[i].first >> m[i].second;

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<vll> c(n + 1, vll(n + 1, 0));
  cout << solve(c, m, 0, n) << endl;
}

C++: #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[101][101],p[101];

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

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

using namespace std;
static const int N = 100;

#define INT_MIN     (-2147483647 - 1) /* minimum (signed) int value */
#define INT_MAX       2147483647    /* maximum (signed) int value */

void solve(vector<int> &data)
{
	vector<vector<int> > dp(N + 1, vector<int>(N + 1, 0));

	int nums = data.size() - 1;
	for (int len = 2; len <= nums; ++len)
	{
		for (int l = 1; l <= nums - len + 1; ++l)
		{
			int r = l + len - 1;
			dp[l][r] = INT_MAX;
			for (int m = l; m <= r - 1; ++m)
			{
				dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + data[l - 1] * data[m] * data[r]);
			}
		}
	}

	cout << dp[1][nums] << endl;
}

int main()
{
	int num; cin >> num;
	vector<int> data(num + 1);
	for (int i = 1; i <= num; ++i)
		cin >> data[i-1] >> data[i];

	solve(data);
}

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];

	scanf("%d", &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]);
				}
			}
		}

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

		return 0;
	}

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

int main() {
  int n;
  cin >> n;
  vector<int> p(n + 1);
  for (int i = 1; i <= n; ++i)
    cin >> p[i - 1] >> p[i];

  vector< vector<int> > dp(n + 1, vector<int>(n + 1));
  for (int l = 2; l <= n; ++l) {
    for (int i = 1; i <= n - l + 1; ++i) {
      int j = i + l - 1;
      dp[i][j] = 1000000000;
      for (int k = i; k < j; ++k)
        dp[i][j] =
            min(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
    }
  }

  cout << dp[1][n] << endl;
}

C++: #include <iostream>
#include <string>
#define MAX 100001
#define SENTINEL 2000000000
using namespace std;

int m[101][101];
int p[101];

void mcm()
{
}

int main()
{
    int n;
    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] = MAX;
            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>
#include <climits>
#define INF INT_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    int m[n+1][n+1], p[n+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] = INF;
            for(int k = i; k < j; k++){
                int q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
                m[i][j] = min(m[i][j], q);
            }
        }
    }

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

    return 0;
}