14341 - 2024_IDS_Spring_Quiz3_Hamburger Transport   

Description

In a universe beyond our own, known as the Hamburger Universe, there are N hamburger shop. The coordinates of the i-th hamburger shop are (xi, yi). 

The residents of the Hamburger Universe have a fondness for hamburgers. To facilitate a hamburgers exchange conference, they have decided to set up hamburger teleportation gates between the hamburger shops. Specifically, there is a cost of |x- xj| * |y- yj| to set up a gate between the i-th and j-th hamburger shops (Note that |a| means the absolute value of a). Once a gate is set up between two shops, the i-th shop can instantly teleport hamburger to the j-th shop, and vice versa. Once a teleportation gate is built, it can be used any number of times.

Due to financial constraints in the Hamburger Universe, please help them calculate the minimum total cost required to ensure that all N breakfast shop can transport hamburgers to any other shop through a series of teleportation gates.

Input

The first line contains a positive integer N.

Following that, there are N lines, each containing two integers xi and yi.

  • 1 ≤ N ≤ 1000
  • 0 ≤ xi, yi ≤ 5000

There could be different shops located at same coordinates.

Output

Output the answer in one line.

Sample Input  Download

Sample Output  Download

Tags




Discuss