Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)
const INF = 0x7fffffff
func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	top := make([]int, 0)
	bottom := make([]int, 0)
	for i := 0; i < n; i++ {
		scanner.Scan()
		buf := strings.Split(scanner.Text(), " ")
		a, _ := strconv.Atoi(buf[0])
		b, _ := strconv.Atoi(buf[1])
		top = append(top, a)
		bottom = append(bottom, b)
	}
	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			dp[i][j] = INF
		}
	}
	for j := 0; j < n; j++ {
		dp[0][j] = 0
	}
	for i := 1; i < n; i++ {
		for j := 0; j < n-i; j++ {
			tmp := make([]int, 0)
			for k := 0; k < i; k++ {
				tmp = append(tmp, dp[k][j] + dp[i - k - 1][j + k + 1] +top[j] * bottom[j + k] * top[j + k + 1] * bottom[j + i])
			}
			sort.Ints(tmp)
			dp[i][j] = tmp[0]
		}
	}
	fmt.Println(dp[n-1][0])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

C++: #include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

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

    pair<int, int> p[105];
    rep(i,n) cin >> p[i].first >> p[i].second;

    vector<vector<vector<long long>>> dp(105,vector<vector<long long>>(205,vector<long long>(205,INF)));
    rep(l,n){
        dp[1][p[l].first][p[l].second] = 0;
        for(int i = n; i > 1; i--){
            range(j,1,201){
                range(k,1,201){
                    dp[i][j][p[l].second] = min(dp[i][j][p[l].second], dp[i - 1][j][k] + j * k * p[l].first * p[l].second);
                    dp[i][p[l].first][k] = min(dp[i][p[l].first][k], dp[i - 1][j][k] + j * k * p[l].first * p[l].second);
                }
            }
        }
    }

    long long mini = INF;
    rep(i,201) rep(j,201)  mini = min(mini, dp[n][i][j]);
    cout << mini << endl;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

struct M{ ll a, b; };


int main()
{
    int n;
	cin >> n;
	
	vector<M> v(n);
	vector<vector<ll> > dp(n, vector<ll>(n, 1 << 30LL));
	
	rep(i, n) cin >> v[i].a >> v[i].b;
	rep(i, n) dp[i][i] = 0;
	
	REP(i, 1, n) rep(j, n - i) rep(k, i + j) 
	{
		chmin(dp[j][i + j], dp[j][k] + dp[k + 1][i + j] + v[j].a * v[k].b * v[k + 1].a * v[i + j].b);
	}
	
	cout << dp[0][n - 1] << endl;
}

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

using namespace std;

typedef pair<int,int> P;

int dp[101][101];
vector<P> v;

const int INF=(1<<31)-1;

int dfs(int d,int u){
	if(u==d)
		return 0;
	if(dp[d][u]!=INF)
		return dp[d][u];
	int minCost=INF;
	for(int i = d; i < u; i++){
		minCost=min(minCost,v[d].second*v[u].first*v[i].first*v[i+1].second+dfs(d,i)+dfs(i+1,u));
	}
	dp[d][u]=minCost;
	return dp[d][u];
}

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		int over,down;
		cin>>over>>down;
		v.push_back(P(over,down));
	}
	for(int i = 0; i < 101; i++)
		fill(dp[i],dp[i]+101,INF);
	cout<<dfs(0,n-1)<<endl;

	return 0;
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <climits>
#include <string>
using namespace std;

int a[100],b[100];
int dp[100][100];
 
int main(){
    int n,i,j,k;
    cin >> n;
    for(i=0;i<n;i++) cin >> a[i] >> b[i];
    for(i=0;i<n;i++) for(j=0;j<n;j++) dp[i][j] = INT_MAX;
    for(i=0;i<n;i++) dp[i][i] = 0;
    for(i=2;i<=n;i++){
        for(j=0;j<=n-i;j++){
            for(k=j+1;k<j+i;k++){
                dp[j][j+i-1] = min(dp[j][j+i-1] , dp[j][k-1] + dp[k][j+i-1] + a[j] * b[k-1] * a[k] * b[j+i-1]);
            }
        }
    }
    cout << dp[0][n-1] << endl;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll a[111],b[111],dp[111][111];

ll rec(int l,int r){
    if(dp[l][r]!=0)return dp[l][r];
    if(l==r)return 0;
    if(l+1==r)return dp[l][r]=a[l]*b[l]*a[r]*b[r];
    ll ret=longinf;
    REP(i,l,r){
        ret=min(rec(l,i)+rec(i+1,r)+a[l]*b[i]*a[i+1]*b[r],ret);
    }
    return dp[l][r]=ret;
}

int main(){
    int n;cin>>n;
    rep(i,n)cin>>a[i]>>b[i];
    cout<<rec(0,n-1)<<endl;
    return 0;
}

C++: #include <stdio.h>

#define INF 0x100000000

int n;
int u[100];
int d[100];
long long int dp[100][100]; // dp[l][r]

int main() {
    int i,j,k;

    scanf("%d", &n);
    for (i=0; i<n; i++) {
        for (j=0; j<n; j++) {
	    dp[i][j] = INF;
	}
    }

    for (i=0; i<n; i++) {
        int a, b;
	scanf("%d %d", &a, &b);
        u[i] = a;
	d[i] = b;
	dp[i][i] = 0;
    }

    for (k=1; k<n; k++) {
        for (i=0; i<n-k; i++) {
	    for (j=0; j<k; j++) {
	        int l1 = i;
		int r1 = i+j;
		int l2 = i+j+1;
		int r2 = i+k;
	        long long int val = dp[l1][r1] + dp[l2][r2] + u[l1] * d[r1] * u[l2] * d[r2];
		if (val < dp[l1][r2]) dp[l1][r2] = val;
	    }
	}
    }

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

C++: #include <iostream>
#include <climits>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n, dp[100][100] = {}, c[100][2];
	cin >> n;
	rep(i,n) {
		cin >> c[i][0] >> c[i][1];
	}
	rep(i,100) {
		rep(j,100) {
			if(i==j) continue;
			dp[i][j] = INT_MAX;
		}
	}
	rep2(i,1,n) {
		rep(j,n-i) {
			rep2(k,j,j+i) {
				dp[j][j+i] = min(dp[j][j+i], dp[j][k]+dp[k+1][j+i]+c[j][0]*c[k][1]*c[k+1][0]*c[j+i][1]);
			}
		}
	}
	cout << dp[0][n-1] << endl;
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int dp[100][100], n, a[100], b[100];

int dfs(int l, int r){
  //  printf("%d %d\n", l, r);
  if(l == r) return 0;
  if(dp[l][r] >= 0) return dp[l][r];

  int res = INF;
  REP(i, l, r){
    res = min(res, dfs(l, i) + dfs(i+1, r) + a[l]*b[i]*a[i+1]*b[r]);
  }
  return dp[l][r] = res;
}

int main(){
  memset(dp, -1, sizeof(dp));
  scanf("%d", &n);
  rep(i, n) scanf("%d%d", a+i, b+i);
  printf("%d\n", dfs(0, n-1));
  return 0;
}