Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/ochkoz-ikki-shahar

Sending to two cities

Medium 1000 ms 128 MB 58%
Share

A company sends $2n$ employees on a business trip: exactly $n$ of them go to city $A$, and the other $n$ go to city $B$. Sending the $i$-th employee to $A$ costs $a_{i}$ soums, and to $B$ costs $b_{i}$ soums. What is the smallest total cost?

Employees with two prices; split evenly between cities A and B, the cheapest assignment

Input

The first line contains a positive integer $n$. Each of the next $2n$ lines contains two positive integers: $a_{i}$ and $b_{i}$.

Output

One integer — the smallest total cost.

Note

$1 \le n \le 5 * 10^{4}$
$1 \le a_{i}, b_{i} \le 10^{9}$

Examples

Input #1
2
10 20
30 200
400 50
30 20
Output #1
110
Input #2
1
5 5
7 3
Output #2
8

Sign in to submit a solution

Signing up is free and takes a minute.