Under construction

Still being built. Things may change

Ants

Time limit3sMemory limit128 MB

Summary
Find the minimum-cost perfect matching between n points and n points using squared Euclidean distance as edge weight.
Level

Medium7 of 10

Topics
Graph, Math, Dynamic programming
Solved
No attempts yet

Problem

Young naturalist Bill studies ants at school. His ants feed on plant lice (aphids) that live on apple trees, and each ant colony needs its own apple tree to feed from.

Bill has a map with the coordinates of nn ant colonies and nn apple trees. He wants to connect each ant colony to exactly one apple tree so that every colony is paired with a distinct tree.

The cost of connecting a colony located at (xc,yc)(x_c, y_c) to an apple tree located at (xt,yt)(x_t, y_t) is the squared Euclidean distance between them:

(xc−xt)2+(yc−yt)2.(x_c - x_t)^2 + (y_c - y_t)^2.

Among all ways to pair the nn colonies with the nn apple trees one-to-one, find the minimum possible total cost.

In the picture, ant colonies are drawn as empty circles and apple trees as filled circles; the lines show one possible pairing.

Input

The first line contains a single integer nn (1≤n≤1001 \le n \le 100) — the number of ant colonies and apple trees.

The next nn lines describe the ant colonies, and the following nn lines describe the apple trees. Each colony and each tree is given by a pair of integer coordinates xx and yy (−10 000≤x,y≤10 000-10\,000 \le x, y \le 10\,000) on the Cartesian plane. All 2n2n points are distinct.

Output

Print a single integer: the minimum total cost of pairing every ant colony with a distinct apple tree, where the cost of one connection is the squared Euclidean distance between the colony and the tree.

Examples3

  1. Example 1

    Input
    5
    -42 58
    44 86
    7 28
    99 34
    -13 -59
    -47 -44
    86 74
    68 -75
    -68 60
    99 -60
    
    Expected output
    26341
    
  2. Example 2

    Input
    1
    0 0
    3 4
    
    Expected output
    25
    
  3. Example 3

    Input
    2
    0 0
    6 6
    6 5
    1 1
    
    Expected output
    3