#D8529. Dangerous Tower
Dangerous Tower
Dangerous Tower
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well.
Today's training is to gain dexterity that never mistypes by carefully stacking blocks. Since there are many building blocks, let's build a tall tower.
There are N blocks, and the i-th (1 ≤ i ≤ N) building blocks are in the shape of a rectangular parallelepiped of 1 x Ai x Bi. The side of length 1 is used in the depth direction, and the sides of lengths Ai and Bi are assigned one by one in the horizontal direction and one in the height direction. When building blocks, the upper building blocks must be exactly shorter in width than the lower building blocks. The blocks can be used in any order, and some blocks may not be used. Under these restrictions, I want to make the tallest tower that can be built.
Input
N A1 B1 ... AN BN
Satisfy 1 ≤ N ≤ 1,000, 1 ≤ Ai, Bi ≤ 1,000,000. All input values are integers.
Output
Output the maximum height of the tower on one line.
Examples
Input
3 10 40 10 40 20 30
Output
80
Input
4 1 2 2 3 3 4 4 1
Output
11
inputFormat
Input
N A1 B1 ... AN BN
Satisfy 1 ≤ N ≤ 1,000, 1 ≤ Ai, Bi ≤ 1,000,000. All input values are integers.
outputFormat
Output
Output the maximum height of the tower on one line.
Examples
Input
3 10 40 10 40 20 30
Output
80
Input
4 1 2 2 3 3 4 4 1
Output
11
样例
3
10 40
10 40
20 30
80