Go: package main

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

const N = 100

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var p [N]int
	var m [N + 1][N + 1]int
	for i := 1; i <= n; i++ {
		sc.Scan()
		p[i-1], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		p[i], _ = strconv.Atoi(sc.Text())
	}

	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])
			}
		}
	}

	return fmt.Sprintf("%d", m[1][n])
}

func main() {
	fmt.Println(answer(os.Stdin))
}

C++: #include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i,n) for(UL i=0; i<(n); i++)

UL N;
ULL dp[101][101];
ULL R[100][2];

int main() {
 cin>>N;
 rep(i,N) rep(j,2) cin>>R[i][j];
 rep(i,N+1) rep(j,N+1) dp[i][j]=1000000000000;
 rep(i,N) dp[i][i+1]=0;
 for(UL j=2; j<=N; j++) for(UL i=j-2; i!=~0u; i--){
  for(UL k=i+1; k<=j-1; k++){
   dp[i][j]=min(dp[i][j],
    dp[i][k]+dp[k][j]+R[i][0]*R[j-1][1]*R[k][0]
   );
  }
 }
 cout<<dp[0][N]<<endl;
 return 0;
}

C++: #include <stdio.h>
#include <algorithm>
using namespace std;
int n, r[100], c[100], dp[100][101];
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d%d", &r[i], &c[i]), dp[i][i] = 0;
	for(int i = 1; i < n; i++) {
		for(int j = 0; i + j <= n; j++) {
			dp[j][i + j] = min(dp[j][i + j - 1], dp[j + 1][i + j]) + c[j] * r[i + j - 1];
		}
	}
	printf("%d\n", dp[0][n]);
	return 0;
}

C++: #include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int dp[111][111];
int mat[111][2];

int solve(int l, int r){
    if(l + 1 >= r) return 0;
    if(dp[l][r]) return dp[l][r];

    int mi = INF;
    for(int i=l+1;i<r;++i){
        chmin(mi, solve(l, i) + solve(i, r) + mat[l][0] * mat[i][0] * mat[r-1][1]);
    }
    return dp[l][r] = mi;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    REP(i,n) cin >> mat[i][0] >> mat[i][1];
    cout << solve(0,n) << endl;
}

C++: #include <cstdio>
#include <cstdint>
#include <algorithm>
using namespace std;

#define MAX_N 100
#define R(i) (m[2*(i)])
#define C(i) (m[2*(i)+1])

typedef int int32_t;

// ??????????¨????????????§DP???

int main(void) {
    int n;
    int m[2 * MAX_N] = {};

    int dp[MAX_N][MAX_N] = {};

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &R(i), &C(i));
    }

    for (int i = 0; i < n-1; i++) {
        dp[i][i + 1] = R(i) * C(i) * C(i+1);
    }
    for (int i = 2; i < n; i++) {
        for (int j = 0; j <= n - i; j++) {
            dp[j][i + j] = INT32_MAX;
            for (int k = 0; k < i; k++) {
                 dp[j][i + j] = min(dp[j][i + j], dp[j][j+k] + dp[j+k+1][i+j] + R(j) * R(j+k+1) * C(i+j));
            }
        }
    }

    printf("%d\n", dp[0][n-1]);
    return 0;
}

C++: #include <stdio.h>
#include <limits.h>
#define MAX 100

int main(){
	int n, m[MAX+1][MAX+1];
	int i, j, k, r, min;
	
	scanf("%d", &n);
	for(i=1;i<=n;++i) {
		scanf("%d %d", &m[i][i-1], &m[i+1][i]);
		m[i][i] = 0;
	}
	
	for(r=2;r<=n;++r){
		for(i=1;i<=n-r+1;++i){
			j=i+r-1;
			m[i][j] = INT_MAX;
			for(k=i;k<=j-1;++k){
				min = m[i][k]+m[k+1][j]+m[i][i-1]*m[k+1][k]*m[j+1][j];
				if(m[i][j] > min) m[i][j] = min;
			}
		}
	}
	printf("%d\n", m[1][n]);
	return 0;
}

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

using namespace std;

const int INFTY = (1<<30);

int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 1);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i] >> A[i + 1];
    }

    vector< vector<int> > cost(N);
    cost[0].assign(N, 0);
    for (int l = 2; l < N + 1; l++)
    {
        cost[l - 1].assign(N - l + 1, INFTY);
        for (int num = 0; num < N - l + 1; num++)
        {
            for (int k = 1; k < l; k++)
            {
                cost[l-1][num] = min(
                    cost[l-1][num],
                    cost[k-1][num] + cost[l-1-k][num+k] + A[num]*A[num+k]*A[num+l]
                );
            }
        }
    }
    cout << cost[N-1][0] << endl;
}

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

static const int N = 100;

int main()
{
  int p,ppp[N+1],m[N+1][N+1];

  cin >> p;

  for( int i = 1; i <= p; i++)
    {
      cin >> ppp[i-1] >> ppp[i];
    }

  for (int i = 1; i <= p; i++) m[i][i] = 0;
  for (int k = 2; k <= p; k++)
    {
      for(int i = 1; i <= p-k+1 ; i++)
	{
	  int j = i + k - 1;
	  m[i][j] = (1 << 21);

	  for ( int q = i; q <= j-1 ; q++)
	    {
	      m[i][j] = min(m[i][j], m[i][q] + m[q+1][j] +
			      ppp[i-1] * ppp[q] * ppp[j]);
	    }
	}
    }

  cout << m[1][p] << 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;
??
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] << "\n";
????????return 0;
}

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

long int M[101][101];
long int a[100];
int n;
void solve(){
  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]=INT_MAX;
       	  for(int k=i;k<j;k++){
	        long int tmp = M[i][k]+M[k+1][j]+a[i-1]*a[k]*a[j];
		if(M[i][j]>tmp){
		    M[i][j] = tmp;	
		}
	    }
	}
    }
}

int main(){ 
   cin>>n;
   for(int i=0;i<n;i+=2){
	cin>>a[i]>>a[i+1];
   }
   solve();
   for(int i=0;i<=n;i++){
	for(int j=0;j<=n;j++){
//	    cout<<"("<<i<<","<<j<<")"<<M[i][j]<<" ";
	}
//	cout<<endl;
   }
   cout<<M[1][n-1]<<endl;
   return 0;
}