Go: package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N := sc.nextInt()
	p := make([]int, N+1)
	dp := make([][]int, N+1)
	for i, _ := range dp {
		dp[i] = make([]int, N+1)
	}
	for i := 0; i < N; i++ {
		p[i] = sc.nextInt()
		p[i+1] = sc.nextInt()
	}
	for i := 1; i <= N; i++ {
		dp[i][i] = 0
	}
	for l := 2; l <= N; l++ {
		for i := 1; i <= N-l+1; i++ {
			j := i + l - 1
			dp[i][j] = 1 << 60
			for k := i; k <= j-1; k++ {
				dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
			}
		}
	}

	fmt.Fprintln(wtr, dp[1][N])
	wtr.Flush()
}

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

const int MAX = 103;
const int INF = 1 << 21;
int dp[MAX][MAX];
int p[MAX];

void solve(int n) {
  for (int i=1; i<=n; i++) {
    dp[i][i] = 0;
  }

  for (int l=2; l<=n; l++) {
    for (int i=1; i<=(n-l+1); i++) {
      int j = i + l - 1;
      dp[i][j] = INF;
      for (int k=i; k<=(j-1); k++) {
	dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + p[i-1] * p[k] * p[j]);
      }
    }
  }
}

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

  solve(n);
  cout << dp[1][n] << endl;
  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <limits.h>
using namespace std;

int m[101][101]; // m[i][j]: i ?????????j ????????§
int p[101]; // 
int main(){
	int n; scanf("%d", &n);
	for (int i = 0; i < n; ++i){
		int r, c; scanf("%d %d", &r, &c);
		p[i] = r; p[i + 1] = c;
	}
	// initialize m[][]
	for (int i = 0; i <= 100; ++i){
		for (int j = 0; j <= 100; ++j) m[i][j] = INT_MAX;
	}
	for (int i = 0; i <= 100; ++i) m[i][i] = 0;
	//
	for (int l = 2; l <= n; ++l){
		for (int i = 1; i <= n; ++i){
			int j = i + l - 1;
			for (int k = i; k < j; ++k){
				if (m[i][k] == INT_MAX || m[k + 1][j] == INT_MAX) continue;
				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';
}

C++: #include<iostream>
#include<string>
#include<algorithm>

int lcs(std::string x, std::string y) {
	int c[101][101];
	int m = x.size();
	int n = y.size();
	int maxl = 0;
	x = ' ' + x;
	y = ' ' + y;
	for (int i = 1; i <= m; i++) {
		c[i][0] = 0;
	}
	for (int i = 1; i <= n; i++) {
		c[0][i] = 0;
	}

	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (x[i] == y[j]) {
				c[i][j] = c[i - 1][j - 1] + 1;
			} else {
				c[i][j] = std::max(c[i - 1][j], c[i][j - 1]);
			}
			maxl = std::max(maxl, c[i][j]);
		}
	}
	return maxl;
}


int main() {
	int n, p[101], m[101][101];
	std::cin >> n;
	for (int i = 1; i <= n; i++) {
		std::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 - 1; i++) {
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for (int k = i; k <= j; k++) {
				m[i][j] = std::min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	std::cout << m[1][n] << std::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(min[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 long N = 100;

int main(){
	long n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (long i = 1; i <= n; i++){
		cin >> p[i - 1] >> p[i];
	}

	for (long i = 1; i <= n; i++) m[i][i] = 0;
	for (long l = 2; l <= n; l++){
		for (long i = 1; i <= n - l + 1; i++){
			long j = i + l - 1;
			m[i][j] = (1 << 21);
			for (long 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]);
			}
		}
	}

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

	return 0;
}

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)

#define int long long

signed main(){
	int n;
	cin>>n;
	int p[101],m[101][101];
	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]=INF;
			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 <stdlib.h>
#include <stdio.h>

int MCM(int n){


int main(){

int i,n,m[100];

scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d %d",&m[i],&m[i+1]);
   }
printf("%d\n",MCM(n));
return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int limN = 105;

int xs[limN], ys[limN];
ll dp[limN][limN];
bool usd[limN][limN];

ll memo(int l, int r) {
    if(l>=r)
        return 0;
    if(usd[l][r])
        return dp[l][r];
    usd[l][r] = true;
    ll &ans = dp[l][r];
    ans = (1LL<<62);
    for(int i=l; i<r; i++) {
        // printf("%d %d %d\n", xs[l], ys[i], ys[i+1]);
        // printf("considerando %d %d %d => %d %lld %lld\n", l, i, r, xs[l]*ys[i]*ys[r], memo(l, i), memo(i+1, r));
        ans = min(ans, xs[l]*ys[i]*ys[r] + memo(l, i) + memo(i+1, r));
    }
    return ans;
}

int main() {
    int N ;
    scanf("%d", &N);
    for(int i=0; i<N; i++) {
        scanf("%d%d", &xs[i], &ys[i]);
    }
    printf("%lld\n", memo(0, N-1));
}

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

static const int N=100;

int main(){
  int i,l,j,k,n,p[N+1],m[N+1][N+1];
  cin >> n;
  for(i=1;i<=n;i++) cin >> 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-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;
}