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 <cstdio>
#include <algorithm>

using namespace std;

const int INF = 1e9;
const int MAX = 100;

int main(){
  int n,r[MAX],c[MAX];
  int dp[MAX][MAX];

  scanf("%d" ,&n);
  for(int i = 0 ; i < n ; i++){
    scanf("%d %d" ,&r[i] , &c[i]);
  }

  for(int i = 0 ; i < n ; i++){
    for(int j = 0 ; j < n ; j++){
      dp[i][j] = INF;
    }
  }

  for(int i = 0 ; i < n ; i++){
    dp[i][i] = 0;
  }
 
  for(int i = 1 ; i < n ; i++){
    for(int j = 0 ; j < n-i ; j++){
      for(int k = j ; k < i + j ; k++){
	int M = r[j] * c[k] * r[k+1] * c[i+j];
	dp[j][i+j] = min(dp[j][i+j],dp[j][k] + dp[k+1][i+j] + M);
      }
    }
  }

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

  return 0;
}

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{ int a, b; };


int main()
{
    int n;
	cin >> n;
	
	vector<M> v(n);
	vector<vint> dp(n, vint(n, 1 << 20));
	
	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 <cstdio>
#include <algorithm>
#include <cmath>

#define INF (1 << 30)

using namespace std;

int DP[200][200]; // DP[i][j] : i????????????????????????j???????±±????????¨????????¨??????????°????

int main(){
	
	int n;
	
	int a[200], b[200];
	
	for(int i = 0; i < 200; i++){
		for(int j = 0; j < 200; j++){
			DP[i][j] = INF;
		}
	}
	
	cin >> n;
	
	for(int i = 0; i < n; i++){
		cin >> a[i] >> b[i];
		DP[i][1] = 0;
	}
	
	for(int loop = 2; loop <= n; loop++){
		for(int i = 0; i < n - loop + 1; i++){
			for(int j = 1; j < loop; j++){
				DP[i][loop] = min(DP[i][loop], DP[i][j] + DP[i + j][loop - j] + a[i] * b[i + j - 1] * a[i + j] * b[i + loop - 1]);
			}
			//cout << DP[i][loop] << " ";
		}
		//cout << endl;
	}
	
	cout << DP[0][n] << endl;
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define INF (1<<29)

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


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

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
const int INF = 1<<28;

int ans = INF;

void dfs(int cost, vector< pair<int, int> > v) {
	if(cost > ans) return;
	if(v.size() == 1)
		ans = min(ans, cost);
	REP(i, v.size()-1) {
		vector< pair<int, int> > v2(v);
		int cost2 = cost + v2[i].first * v2[i].second * v2[i+1].first * v2[i+1].second;
		v2[i].second = v2[i+1].second;
		v2.erase(v2.begin()+ i + 1);
		dfs(cost2, v2);
	}
	return;
}

int main() {
	int n; cin >> n;
	vector< pair<int, int> > cards(n);
	REP(i, n)
		cin >> cards[i].first >> cards[i].second;
	dfs(0, cards);
	cout << ans << endl;
	return 0;
}

C++: #include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int cost[100][100]={0},t[100],b[100];
		rep(i,n)cin>>t[i]>>b[i];
		rep(j,n)if(j)rep(i,n-j){
			int mn=1<<30,c;
			rep(k,j)if(mn>(c=cost[k][i]+cost[j-k-1][i+k+1]+t[i]*b[i+k]*t[i+k+1]*b[i+j]))mn=c;
			cost[j][i]=mn;
		}
		cout<<cost[n-1][0]<<endl;
	}
	return 0;
}