from functools import reduce
n = int(input())

Card = [[] for _ in [0]*n]

Cost = {}

for i in range(n):

  Card[i] = list(map(int, input().split()))

  Cost[(i, i)] = 0

for i in range(1, n):

  for j in range(0, n-i):

    a = j+i

    Cost[(j, a)] = min([reduce(lambda a,b: a*b, [Card[j][0],Card[k][1],Card[k+1][0],Card[a][1]]) + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])

print(Cost[0, n-1])
n = int(input())

Card = [[] for _ in [0]*n]

Cost = {}

for i in range(n):

  Card[i] = list(map(int, input().split()))

  Cost[(i, i)] = 0

for i in range(1, n):

  for j in range(0, n-i):

    a = j+i

    Cost[(j, a)] = min([Card[j][0] * Card[k][1] * Card[k+1][0] * Card[a][1] + Cost[(j, k)] + Cost[(k+1, a)] for k in range(j, j+i)])

print(Cost[0, n-1])
from functools import reduce

n = int(input())
Card = [[] for _ in [0] * n]
Cost = {}
for i in range(n):
    Card[i] = list(map(int, input().split()))
    Cost[(i, i)] = 0
for i in range(1, n):
    for j in range(0, n - i):
        a = j + i
        Cost[(j, a)] = min(
            [
                reduce(
                    lambda a, b: a * b,
                    [Card[j][0], Card[k][1], Card[k + 1][0], Card[a][1]],
                )
                + Cost[(j, k)]
                + Cost[(k + 1, a)]
                for k in range(j, j + i)
            ]
        )
print(Cost[0, n - 1])

n = int(input())
Card = [[] for _ in [0] * n]
Cost = {}
for i in range(n):
    Card[i] = list(map(int, input().split()))
    Cost[(i, i)] = 0
for i in range(1, n):
    for j in range(0, n - i):
        a = j + i
        Cost[(j, a)] = min(
            [
                Card[j][0] * Card[k][1] * Card[k + 1][0] * Card[a][1]
                + Cost[(j, k)]
                + Cost[(k + 1, a)]
                for k in range(j, j + i)
            ]
        )
print(Cost[0, n - 1])

-from functools import reduce - -                reduce( -                    lambda a, b: a * b, -                    [Card[j][0], Card[k][1], Card[k + 1][0], Card[a][1]], -                ) +                Card[j][0] * Card[k][1] * Card[k + 1][0] * Card[a][1]