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>
#define INF 1000000
using namespace std;

int n;
int matrix[110][2];
int _dp[110][110];

int dp(int begin,int end){
	if(_dp[begin][end]) return _dp[begin][end];
	if(begin + 1 == end){
		_dp[begin][end] == 0;
		return 0;
	}
	if(begin + 2 == end){
		int temp = matrix[begin][0] * matrix[begin][1] * matrix[end-1][1];
		_dp[begin][end] = temp;
		return temp;
	}
	int min = INF;
	for(int i = begin+1; i<end; i++){
		int temp = dp(begin, i) + dp(i, end)
			+ matrix[begin][0] * matrix[i][0] * matrix[end-1][1];
		if(temp < min) min = temp;
	}
	_dp[begin][end] = min;
	return min;
}

int main(void){
	int n;
	cin >> n;
	
	for(int i=0; i<n; i++) cin >> matrix[i][0] >> matrix[i][1];
	
	cout << dp(0,n) << endl;
	
	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAX 100

int main(){
  int n,dammy;
  cin>>n;
  int p[MAX+1];
  cin>>p[0];
  for(int i=0;i<n-1;i++){
    cin>>p[i+1];
    cin>>dammy;
  }
  cin>>p[n];
  int C[MAX+1][MAX+1];
  for(int i=1;i<=n;i++) C[i][i]=0;
  for(int h=2;h<=n;h++){
    for(int s=1;s<=n-h+1;s++){
      int e=s+h-1;
      C[s][e]=C[s][s]+C[s+1][e]+p[s-1]*p[s]*p[e];
      for(int j=s+1;j<e;j++){
        C[s][e]=min(C[s][e],C[s][j]+C[j+1][e]+p[s-1]*p[j]*p[e]);
      }
    }
  }
  cout<<C[1][n]<<endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {

    int n;
    cin >> n;
    vector<int> R(n);
    vector<int> C(n);
    REP(i,n) cin >> R[i] >> C[i];
    vector<vector<int>> dp(n,vector<int>(n,INF));

    REP(i,n) dp[i][i] = 0;

    FOR(w,1,n){
        FOR(l,0,n-w){
            int r = l+w; 
            FOR(m,l,r){
                dp[l][r] = min(dp[l][r], dp[l][m] + dp[m+1][r] + R[l]*C[m]*C[r]);
            }
        }

    }

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


    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<climits>
using namespace std;
  int n;

int m[101][101];
  int p[101];
void chain(){
  int n1;
  int j;
  int q;
  n1=n;
  //ok
  // cout <<"n1 "<<n1<<endl;
  for(int i=1;i<=n1;i++){
    m[i][i]=0;
  }
  for(int l=2;l<=n1;l++){
    for(int i=1;i<=n1-l+1;i++){
      j=i+l-1;
      m[i][j] = INT_MAX;
      for(int k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
	//	cout<<"q "<<q<<endl;
	if(q<m[i][j]){
	  m[i][j]=q;
	  //	  cout<<s[i][j]<<endl;
	}
      }
    }
  }
}

int main(){

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

  //ok
  /*
 for(int i=0;i<=n;i++){
   cout<<"p "<<p[i]<<endl;
 }
  */
  chain();
  /*  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cout<<m[i][j]<<endl;
    }
   }
*/
  cout<<m[1][n]<<endl;

  return 0;
}

C++: //#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>

using namespace std;
int N = 100;

int main(){
  int i,j,k,l;
  int n,p[N+1],m[N+1][N+1];
  cin >> n;
  for(i = 1; i <= n; i++){
    cin >> p[i-1];
    cin >> 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<iostream>
#include<algorithm>
using namespace std;
static const int N = 100;


int main() {
	int n;
	cin >> n;
	int p[N],m[N+1][N+1];
	for (int i = 1;i <= n;i++) {
		cin >> p[i - 1] >> p[i];
	}
	for (int i = 0;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;
static const int N=100;
int main(){
  int j,i,k,n,l,p[N+1],m[N+1][N+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&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[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
        }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}

C++: #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
static const int MAX = 100;
#define INF (1 << 30);

int store[MAX][MAX] = {{}};

struct matrix {
  int row;
  int col;
};

int nMul(matrix x, matrix y) { return x.row * x.col * y.col; }

matrix mult(matrix x, matrix y) {
  matrix mat;
  mat.row = x.row;
  mat.col = y.col;
  return mat;
}

int main() {
  matrix mat[MAX];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> mat[i].row;
    cin >> mat[i].col;
  }

  int mcm[MAX][MAX] = {0};
  i         k         j
  for (int j = 1; j < n; j++) {
    for (int i = j-1; i >= 0; i--) {
      int minimum = INF;
      for (int k = i; k < j; k++) {
        int joint = nMul(mult(mat[i], mat[k]), mult(mat[k+1], mat[j]));
        int tmp = mcm[i][k] + mcm[k+1][j] + joint;
        minimum = min(minimum, tmp);
      }
      mcm[i][j] = minimum;
    }
  }

  cout << mcm[0][n-1] << endl;
}

C++: #include<stdio.h>
#include<algorithm>

#define MAX 1000
#define INFINITY 2000000000

int A[MAX];
int m[MAX][MAX];
int n;

void minimumCount() {
    for (int i = 0; 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] = INFINITY;
            for (int k = i; k < j; ++k) {
                m[i][j] = std::min(m[i][j], m[i][k] + m[k+1][j] + A[i-1] * A[k] * A[j]);
            }
        }
    }
}

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d %d", &A[i - 1], &A[i]);
    }
    minimumCount();
    printf("%d\n", m[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] = (l<<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;
}