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

~/algor $ cat problems/dp-ishchilar-va-ishlar

Workers and jobs

Hard 2000 ms 128 MB 86%
Share

There are $n$ workers and $n$ jobs. The $i$-th worker does the $j$-th job for $c_{i,j}$ soums. Each worker must be assigned exactly one job, and each job exactly one worker. What is the smallest total cost?

A price table: one cell chosen in every row and every column, with the smallest total

Input

The first line contains a positive integer $n$. The $i$-th of the next $n$ lines contains $n$ integers: $c_{i,1}, \ldots, c_{i,n}$.

Output

One integer — the smallest total cost.

Note

$1 \le n \le 15$
$0 \le c_{i,j} \le 10^{6}$

Examples

Input #1
3
4 1 3
2 0 5
3 2 2
Output #1
5
Input #2
1
9
Output #2
9

Sign in to submit a solution

Signing up is free and takes a minute.