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<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
#define P pair<int, int>
#define MAX_N 101
#define INF 1 << 21

int n, dp[MAX_N][MAX_N];
vector<P> cards, cardsCpy;
bool useFlag[MAX_N];

void setDp();
void loop(int left, int right);
void disp();
void dispCards();
void resetUseFlag();

int main(){
    resetUseFlag();
    cards.clear();
    cin >>n;
    for(int i = 0; i < n; i++){
        int x, y;
        cin >>x >>y;
        cards.push_back( make_pair(x, y) );
    }
    cardsCpy = cards;
    setDp();
    loop(0, n - 1);
    cout <<dp[0][n - 1] <<endl;
    return 0;
}

void setDp(){
    for(int i = 0; i < MAX_N; i++){
        for(int j = 0; j < MAX_N; j++){
            if(i == j) dp[i][j] = 0;
            else dp[i][j] = INF;
        }
    }
}

void loop(int left, int right){
    for(int i = left; i < right; i++){
        cards[i + 1].first = cardsCpy[i + 1].first;
        //cout <<"! " <<i + 1 <<endl;
        if(left != i) loop(left, i);
        if(i + 1 != right) loop(i + 1, right);
        int tmp = cards[left].first * cards[left].second * cards[right].first * cards[right].second + dp[left][i] + dp[i + 1][right];
        //cout <<cards[left].first <<" * " <<cards[left].second <<" * " <<cards[right].first <<" * " <<cards[right].second <<" + " <<dp[left][i] <<" + " <<dp[i + 1][right] <<" = " <<tmp <<endl;
        if(dp[left][right] > tmp) dp[left][right] = tmp;
        cards[i + 1].first = cards[i].first;
    }
    //cout <<left <<", " <<right <<", " <<dp[left][right] <<endl;
    //dispCards();
    //disp();
    //cout <<endl;
}

void disp(){
    for(int i= 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cout <<dp[i][j] <<" ";
        }
        cout <<endl;
    }
}

void dispCards(){
    for(int i = 0; i < cards.size(); i++){
        cout <<"(" <<cards[i].first <<", " <<cards[i].second <<") ";
    }
    cout <<endl;
}

void resetUseFlag(){
    for(int i = 0; i < MAX_N; i++) useFlag[i] = false;
}

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

using namespace std;

//dp[i][j] = [i,j]をすべてまとめるときの最小コスト
int dp[128][100];

int solve(const vector<pair<int,int> > &v, int left, int right) {
    int &res = dp[left][right];
    if(res < INT_MAX) return res;
    for(int split = left; split < right; ++split) {
        const int lcost = solve(v, left, split);
        const int rcost = solve(v, split+1, right);
        const int cost = v[left].first*v[split].second * v[split+1].first*v[right].second;
        res = min(res, lcost+rcost+cost);
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    vector<pair<int,int> > v(N);
    for(int i = 0; i < N; ++i) {
        cin >> v[i].first >> v[i].second;
    }
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j < N; ++j) {
            if(i == j) dp[i][j] = 0;
            else dp[i][j] = INT_MAX;
        }
    }
    cout << solve(v, 0, N-1) << endl;
    return 0;
}

C++: #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;

int main(){
	int n,minimum,tmp;
	scanf("%d",&n);
	int table[n][n];
	int data[n][2];

	for(int i=0;i<n;i++){
		for(int k=0;k<n;k++)table[i][k] = 0;
		scanf("%d %d",&data[i][0],&data[i][1]);
	}

	for(int col = 0; col <= n-2; col++){
		table[1][col] = data[col][0]*data[col][1]*data[col+1][0]*data[col+1][1];
	}

	for(int row = 2; row <= n-1; row++){
		for(int col = 0; col <= n-(row+1); col++){
			minimum = 2147483647;

			for(int div = 0; div <= row-1;div++){
				tmp = (table[div][col+div]+table[row-div-1][col+div+1])+(data[col][0]*data[col+div][1]*data[col+div+1][0]*data[col+row][1]);
				minimum = min(minimum,tmp);
			}
			table[row][col] = minimum;
		}
	}

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

    return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 28;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
int dp[200][200];
int ct[200];
int cb[200];

int main(){
	int n;
	cin >> n;
	fill(&dp[0][0], &dp[199][199] + 1, INF);
	rep(i, n){
		cin >> ct[i] >> cb[i];
		dp[i][i] = 0;
	}
	rep2(w, 2, n + 1){
		rep(i, n){
			rep2(j, 1, w){
				dp[i][i+w-1] = min(dp[i][i+w-1],
					dp[i][i+j-1] + dp[i+j][i+w-1] + ct[i] * cb[i+j-1] * ct[i+j] * cb[i+w-1]);

			}
		}
	}
	cout << dp[0][n-1] << endl;
	return 0;
}

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

using namespace std;

typedef pair<int, int> P;
vector<P> D;

int n, a, b;
int DP[101][101];

void solve()
{
	for(int i=0; i<n; i++)
	{
		for(int j=0; j<n; j++)
		{
			if(i!=j) DP[i][j] = INT_MAX;
			else DP[i][j] = 0;
		}
	}	

	for(int i=1; i<n; i++)
	{
		for(int j=0; j<n-i; j++)
		{
			for(int k=j; k<j+i; k++)
			{
				int cost = D[j].first * D[k].second * D[k+1].first * D[j+i].second;
				DP[j][j+i] = min(DP[j][j+i], cost + DP[j][k] + DP[k+1][j+i]);
			}
		}
	}

	cout << DP[0][n-1] << endl;
}

int main(int argc, char** argv)
{
	cin >> n;
	for(int i=0; i<n; i++)
	{
		cin >> a >> b;
		P p(a, b);
		D.push_back(p);
	}

	solve();
}