## 题目描述

Farmer John is considering buying more land for the farm and has his eye on N ($1 <= N <= 50,000$ additional rectangular plots, each with integer dimensions ($1 <= width_i <= 1,000,000$; $1 <= length_i <= 1,000,000$).

If FJ wants to buy a single piece of land, the cost is ￥1/square unit, but savings are available for large purchases. He can buy any number of plots of land for a price in dollars that is the width of the widest plot times the length of the longest plot. Of course, land plots cannot be rotated, i.e., if Farmer John buys a $3×5$ plot and a $5×3$ plot in a group, he will pay $5×5=25$

FJ wants to grow his farm as much as possible and desires all the plots of land. Being both clever and frugal, it dawns on him that he can purchase the land in successive groups, cleverly minimizing the total cost by grouping various plots that have advantageous width or length values.

Given the number of plots for sale and the dimensions of each, determine the minimum amount for which Farmer John can purchase all

## 输入输出格式

• Line 1: A single integer: $N$
• Lines 2.. $N+1$: Line $i+1$ describes plot i with two space-separated integers: $width_i$ and $length_i$

• Line 1: The minimum amount necessary to buy all the plots.

## 说明

There are four plots for sale with dimensions as shown.

The first group contains a 100×1 plot and costs 100. The next group contains a 1×100 plot and costs 100. The last group contains both the 20×5 plot and the 15×15 plot and costs 300. The total cost is 500, which is minimal.

## 题解

$O(n^2)$ 的方法很显然，按照 $x$ 从大到小排序，然后对于 $i,j$ , $X_i>X_j$ 且 $Y_i>Y_j$ ，j可以直接去掉（因为$i$的可以直接取掉。