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 <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1501001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> R(N), C(N);
    for(int i = 0; i < N; ++i)  cin >> R[i] >> C[i];

    vector<vector<int>> dp(N + 1, vector<int>(N + 1, -1));
    auto MemoRec = [&](auto&& self, int l, int r) -> int {
        if(dp[l][r] != -1)  return dp[l][r];
        if(r - l <= 1)  return dp[l][r] = 0;
        int res = INF;
        for(int m = l + 1; m < r; ++m){
            int S = self(self, l, m) + self(self, m, r) + R[l] * R[m] * C[r - 1];
            chmin(res, S);
        }
        return dp[l][r] = res;
    };

    cout << MemoRec(MemoRec, 0, N) << endl;
}

C++: #include <iostream>

using namespace std;

const int N = 102;
int dp[N][N], r[N], c[N];

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d", &r[i], &c[i]);
    }
    for (int k = 2; k <= n; k++)
    {
        for (int i = 0; i <= n - k; i++)
        {
            int mn = 2e9;
            for (int j = i; j < i + k - 1; j++)
            {
                mn = min(mn, dp[i][j] + dp[j+1][i+k-1] + r[i]*c[j]*c[i+k-1]);
            }
            dp[i][i+k-1] = mn;
        }
    }
    printf("%d\n", dp[0][n-1]);
    return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.txt"
 
int memo[100][100];
vector<pair<int, int>>ps;
int getans(const int l, const int r) {
	if (memo[l][r] != -1)return memo[l][r];
	if (l + 1 == r) {
		return memo[l][r] = ps[l].first*ps[l].second*ps[r].second;
	}
	else if (l == r) {
		return memo[l][r] = 0;
	}
	else {
		int ans = 1e9;
		for (int t = l; t < r; ++t) {
			int len = getans(l, t) + ps[l].first*ps[t].second*ps[r].second + getans(t + 1, r);
			ans = min(ans, len);
		}
		return memo[l][r] = ans;
	}
}
int main() {
	for (int i = 0; i < 100; ++i) {
		for (int j = 0; j < 100; ++j) {
			memo[i][j] = -1;
		}
	}
	int N; cin >> N;
	ps.resize(N);
	for (int i = 0; i < N; ++i) {
		int a, b; cin >> a >> b;
		ps[i] = make_pair(a, b);
	}
	int ans=getans(0, N - 1);
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

int mat[110][2], dp[110][110];
const int INF = 1<<29;

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  REP(i, N) REP(j, 2) cin >> mat[i][j];
  REP(i, N) REP(j, N) dp[i][j] = INF;
  REP(i, N) dp[i][i] = 0;
  for (int w = 1; w < N; w++) {
    for (int L = 0; L + w < N; L++) {
      int R = L + w;
      for (int i = L; i < R; i++)
	dp[L][R] = min(dp[L][R], dp[L][i] + dp[i+1][R] + mat[L][0] * mat[i][1] * mat[R][1]);
    }
  }
  cout << dp[0][N-1] << endl;
  return 0;
}

C++: #include <iostream>

using namespace std;

typedef struct matrix{
  int row;
  int column;
  struct matrix *next;
  struct matrix *back; 
}Matrix;

Matrix *push_back(Matrix *begin, int row, int column) {
  Matrix *p = (Matrix*)malloc(sizeof(Matrix));
  p->row = row;
  p->column = column;
  p->next = NULL;
  p->back = NULL;
  if(begin == NULL) return p;
  Matrix *p2 = begin;
  while(p2->next != NULL) p2 = p2->next;
  p2->next = p;
  p->back = p2;
  return begin;
}

Matrix *product_count(Matrix *x, int type, long *count) {
  Matrix *a,*b;
  if(type == 0) {
    a = x->back;
    b = x;
  }
  else {
    a = x;
    b = a->next;
  }
  *count = 0;
  if(a == NULL || b == NULL) return x;
  *count += a->row * a->column * b->column;
  Matrix *c = (Matrix*)malloc(sizeof(Matrix));
  c->row = a->row;
  c->column = b->column;
  c->next = b->next;
  c->back = a->back;
  if(a->back != NULL) a->back->next = c;
  if(b->next != NULL) b->next->back = c;
  free(a);
  free(b);
  return c;
}

int main()
{
  int i,n,r,c;
  Matrix *begin = NULL;
  scanf("%d",&n);
  for (i = 0; i < n; i++) {
    scanf("%d %d",&r,&c);
    begin = push_back(begin,r,c);
  }
  Matrix *min = begin, *p = begin;
  while (p->next != NULL) {
    if(min->column > p->column) min = p;
    p = p->next;
  }
  long sum = 0,count;
  if(min->column <= begin->row) {
    begin = NULL;
    while(1) {
      min = product_count(min,0,&count);
      if(count != 0) sum += count;
      else break;
    }
    if(min->next != NULL) {
      min = min->next;
      while(1) {
	min = product_count(min,1,&count);
	if(count != 0) sum += count;
	else break;
      }
      min = product_count(min,0,&count);
      sum += count;
    }
  }
  else{
    min = begin;
    begin = NULL;
    while(1) {
      min = product_count(min,1,&count);
      if(count != 0) sum += count;
      else break;
    }
  }
  cout << sum << endl;
  
  return 0;
}

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

int main()
{
	int n,i;
	int a[25];
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
}

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

	if (n > 1) {
		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;
}