Go: package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		fmt.Scan(&a[i+1])
	}

	m := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		m[i] = make([]int, n+1)
	}

	for d := 2; d <= n; d++ {
		for s := 0; s+d <= n; s++ {
			min := 1 << 30
			for j := s+1; j < s+d; j++ {
				val := m[s][j] + m[j][s+d] + a[s]*a[j]*a[s+d]
				if val < min {
					min = val
				}
			}
			m[s][s+d] = min
		}
	}
	fmt.Println(m[0][n])
}

C++: #include<iostream>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<string>
//#define MAX 101
#define INFTY (1<<21)

using namespace std;

static const int N = 100;


/*int min(int a, int r[], int c[]) {



	for(int i=1; i<=a; i++){
		if(r[i] == c[i+1]){
			int s = r[i]*c[i]*r[i+1];
		}
}*/

int main() {
	int n;
	

	int M[N+1][N+1];
	int p[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 j = 2; j <= n; j++) {
		for (int i = 1; i <= n - j + 1; i++) {
			int k = i + j - 1;

			M[i][k] = INFTY;

			for (int a = i; a <= k - 1; a++) {
				int b = M[i][a] + M[a + 1][k] + p[i - 1] * p[a] * p[k];
				M[i][k] = min(M[i][k], b);

			}
		}
	}

	cout << M[1][n] << endl;
	/*int R[MAX];
	int C[MAX];

	int r, c;
	for(int i = 1; i<=n; i++){
		cin >> r >> c;
		R[i] = r;
		C[i] = c;

	}*/

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

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 = 0;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>
using namespace std;

constexpr int INF = (1 << 30) - 1;

int memo[105][105];
int n; 
int r[105], c[105];

int dfs(int left, int right)
{
    int ret = INF;
    if ( left == right ) return ( 0 );
    if ( memo[left][right] != -1 ) return ( memo[left][right] );
    for ( int i = left; i < right; i++ ) { 
        ret = min(ret, dfs(left, i) + dfs(i + 1, right) + r[left] * c[right] * c[i]);
    }
    return ( memo[left][right] = ret );
}

int main()
{
    fill_n(*memo, 105 * 105, -1);

    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> r[i] >> c[i];
    }

    cout << dfs(0, n - 1) << endl;

    return ( 0 );
}

C++: #include<cstdio>
using namespace std;
const char N_MAX = 105;
int INF = 1<<30;
int dp[N_MAX][N_MAX];
char matrix[N_MAX];
int n;
int solve() {
    for(char offset = 1; offset < n; offset++) {
        for(char c = 1, r = c + offset; r <= n; c++, r++) {
            dp[c][r] = INF;
            for(char divid = 1; divid <= offset; divid ++) {
                int newValue = dp[c][c - 1 + divid] + dp[c + divid][r] + matrix[c - 1] * matrix[r] * matrix[c + divid - 1];
                if(newValue < dp[c][r])
                    dp[c][r] = newValue;
            }
        }
    }
    return dp[1][n];
}
int main(){
    scanf("%d", &n);
    for(char i=0;i<n;i++) scanf("%d %d", &matrix[i], &matrix[i+1]);
    printf("%d\n", solve());
    return 0;
}

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

int calcDpTable(int i, int j, const int ** dpTable, const int *p) {
	int minValue = INT_MAX; 
	for (int k = i; k < j; ++k) {
		minValue = min(dpTable[i][k - i] + dpTable[k + 1][j - k - 1] + p[i] * p[k + 1] * p[j + 1], minValue);
	}
	return minValue;
}

int minNumOfMultiplications(const int *p, int n) {
	int **dpTable = new int*[n];
	for (int i = 0; i < n; ++i) {
		dpTable[i] = new int[n - i];
		dpTable[i][0] = 0;
	}

	int d = 1;
	for (int to = n - 2; to >= 0; --to) {
		for (int i = 0; i <= to; ++i) {
			int j = i + d;
			dpTable[i][j - i] = calcDpTable(i, j, const_cast<const int**>(dpTable), p);
		}
		++d;
	}
	int ret = dpTable[0][n - 1];
	
	for (int i = 0; i < n; ++i) {
		delete[] dpTable[i];
	}
	delete[] dpTable;

	return ret;
}

int main() {
	int n;
	cin >> n;
	int *p = new int[n + 1];
	for (int i = 0; i < n; ++i) {
		cin >> p[i] >> p[i + 1];
	}
	cout << minNumOfMultiplications(p, n) << endl;
}

C++: #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i,n)   for (int i = 0; i < (n); ++i)
#define SORT(a)    sort((a).begin(), (a).end());
#define UNIQ(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define FIND(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define REVERSE(a) reverse((a).begin(), (a).end());
#define OUT(d) cout << (d);
#define OUT_L(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define CEIL(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

const int MAX_N = 100;
ll N;
ll dp[MAX_N][MAX_N];
vector<ll> p(MAX_N + 1);

ll solve(int l, int r) {
  if (dp[l][r] != 0) return dp[l][r];
  if (l == r) return 0;

  ll ret = __INT_MAX__;
  REP(i, r - l) {
    ret = min(ret, solve(l, l + i) + solve(l + i + 1, r) + p[l] * p[l + i + 1] * p[r + 1]);
  }
  return dp[l][r] = ret;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));

  cin >> N;

  cin >> p[0];
  for(int i = 1; i <= N - 1; i++) {
    cin >> p[i];
    cin >> p[i];
  }
  cin >> p[N];
  memset(dp, 0, sizeof(dp));

  OUT_L(solve(0, N - 1))
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <climits>


using namespace std;


using ll = long long;


const ll MAX = 100;


int main()
{
    ll n;

    cin >> n;
    vector<vector<ll>> m(n + 1);
    for (ll i = 0; i <= n; i++)
        m[i].resize(n + 1);
    vector<pair<ll, ll>> M;
    for (ll i = 0; i < n; i++) {
        ll r, c;
        cin >> r >> c;
        M.push_back(make_pair(r, c));
    }

    for (ll i = 0; i < n; i++) {
        m[i][i] += 0;
    }

    for (ll i = 0; i < n - 1; i++) {
        m[i][i + 1] += M[i].first * M[i].second * M[i + 1].second;
    }

    for (ll len = 2; len < n; len++) {
        for (ll l = 0; l < n - len; l++) {
            ll r = l + len;
            m[l][r] = LONG_LONG_MAX;
            for (ll mid = l; mid < r; mid++) {
                ll tmp = M[l].first * M[mid].second * M[r].second;
                // cout << tmp << endl;
                m[l][r] = min(m[l][r], tmp + m[l][mid] + m[mid + 1][r]);
            }
        }
    }
    cout << m[0][n - 1] << endl;
}