Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}
func main() {
	sc.Split(bufio.ScanWords)
	var n int
	var M [101][101]int

	n = nextInt()

	P := make([]int, n*2)

	for i := 1; i <= n; i++ {
		P[i-1] = nextInt()
		P[i] = nextInt()
	}
	for l := 2; l <= n; l++ {
		for i := 1; i <= n-l+1; i++ {
			j := i + l - 1
			M[i][j] = 1000000
			for k := i; k <= j-1; k++ {
				M[i][j] = int(math.Min(float64(M[i][j]), float64(M[i][k]+M[k+1][j]+P[i-1]*P[k]*P[j])))
			}
		}
	}
	fmt.Println(M[1][n])
}

C++: #include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
int dp[101][101];
signed main() {
  int n;
  cin>>n;
  rep(i,101){
    rep(j,101){
      dp[i][j]=0;
    }
  }
  vector<int>gyou(n+1);
  vector<int>retu(n+1);
  rep(i,n){
    cin>>gyou[1+i]>>retu[1+i];
  }
  for(int len=2;len<=n;len++){
    for(int l=1;l<=n-len+1;l++){
      int r=l+len-1;
      dp[l][r]=min(dp[l+1][r]+gyou[l]*retu[l]*retu[r],dp[l][r-1]+gyou[l]*gyou[r]*retu[r]);
      if(len>=4)for(int k=l+1;k<r-1;k++){dp[l][r]=min(dp[l][r],dp[l][k]+dp[k+1][r]+gyou[l]*retu[k]*retu[r]);}
    }
  }
  cout<<dp[1][n]<<endl;
}

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;

const int N = 1000;

int main() {
    int n;
    int m[N + 1][N + 1];
    int p[N+ 1];
    for (int i = 1; i <= N; i++)
        m[i][i] = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i] >> p[i + 1];
    }
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= n - i + 1; j++) {
            int k = j + i - 1;
            m[j][k] = (1<<21);
            for (int l = j; l < k; l++) {
                m[j][k] = min(m[j][k], m[j][l] + m[l + 1][k] + p[j - 1] * p[l] * p[k]);
            }
        }
    }
    cout << m[1][n] << endl;
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	vector<ll> p(n+1);
	FOR(i,1,n+1){
		cin>>p[i-1]>>p[i];
	}
	ll dp[n+1][n+1];
	FOR(i,0,n+1)FOR(j,0,n+1)dp[i][j]=0;
	FOR(l,2,n+1){
		FOR(i,1,n+2-l){
			int j = i + l - 1;
			dp[i][j] = (1 << 21);
			FOR(k,i,j){
				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 <cstdio>
#include <cstdlib>
#include <cassert>
#include <string>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>

using namespace std;

// ---------------------
// repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

// debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

// ---------------------
#define INF 922337203685477580
typedef long long ll;

ll dp[110][110];
ll matrix[110][2];

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

  REP(i, N) {
    cin >> matrix[i][0] >> matrix[i][1];
  }

  // for (int i = 0; i < N - 1; i++) {
  //   dp[i][i + 1] = matrix[i][0] * matrix[i][1] * matrix[i + 1][1];
  // }
  for (int i = 0; i < N; i++) {
    dp[i][i] = 0;
  }

  // cout << dp[0][1] << endl;

  for (int l = 2; l <= N; l++) {
    for (int i = 0; i < N - l + 1; i++) {
      int j = i + l - 1;

      dp[i][j] = INF;

      for (int k = i; k < j; k++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + matrix[i][0] * matrix[k][1] * matrix[j][1]);
      }
    }
  }




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

  return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string>
#include <cmath>

#define MAX_LENGTH 1000
#define NIL -1
using namespace std;
//think easy make easy

int q;//num of datasets
string X;
string Y;
char map[MAX_LENGTH+1][MAX_LENGTH+1];

int findMaxLength(int x,int y){//x:Xの終端.y:Yの終端(0オリジン)
	if(x < 0 || y < 0) return 0;
	if(map[x][y] == NIL){
		if(X.at(x) == Y.at(y)){
			return findMaxLength(x-1,y-1) +1;
		}else{
			return max(findMaxLength(x-1,y),findMaxLength(x,y-1));
		}
	}else return map[x][y];
}

int main(){
	
	scanf("%d",&q);

	for(int i=0;i<q;i++){
		cin >>X; cin >> Y;
		for(int i=0;i<X.size();i++){
			for(int j=0;j<Y.size();j++){
				map[i][j] = NIL;
			}
		}
	
		cout <<findMaxLength(X.size()-1,Y.size()-1) <<endl;
	}

	return 0;
}

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

void Print( const std::vector<std::vector<int>>& m ){
    int n = m.size();
    for( int j = n; j > 0; --j ){
        for( int i = 1; i < j; ++i ){
            std::cout << m[i][j] << "\t";
        }
        std::cout << "\n";
    }
}

void MatrixChainOrder( const std::vector<int>& p, std::vector<std::vector<int>>& m ){
    int n = p.size() - 1;
    for( int i = 1; i <= n; ++i ){
        m[i][i] = 0;
    }

    constexpr int INF = 1 << 25;
    int j;
    int q;
    for( int l = 2; l <= n; ++l ){
        for( int i = 1; i <= n-l+1; ++i ){
            j = i + l - 1;  
            m[i][j] = INF;
            for( int k = i; k <= j-1; ++k ){
                q = m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
                m[i][j] = ( m[i][j] < q )? m[i][j] : q;
            }
        }
    }
}

int main(){
    int n;
    std::cin.tie( 0 );
    std::cin >> n;

    std::vector<int> p( n+1 );
    std::vector<std::vector<int>> m( n+1 );
    for( auto& elem : m ){
        elem = std::vector<int>( n+1 );
    }

    int dump;
    for( int i = 0; i < n; ++i ){
        std::cin >> p[i] >> dump;
    }
    p[n] = dump;

    MatrixChainOrder( p, m );

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

    //Print( m );

}

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

int main()
{
	int n, p = 0, m = 101, mini;
	int v[101];

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> v[i] >> v[i + 1];
		if (m > v[i]) {
			m = v[i];
			mini = i;
		}
	}

	for (int j = 0; j < n; j++)
		p += v[j] * v[j + 1];
	p += v[0] * v[n];

	if (mini == 0)
		p -= v[0] * v[1];
	else if (mini == n)
		p -= v[n - 1] * v[n];
	else
		p -= v[mini] * (v[mini + 1] + v[mini - 1]);

	p *= v[mini];

	cout << p << endl;

	return 0;
}

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

static const int N = 100;

int main(void){
    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;
}