Skip to main content
LIVE CONTEST: ALGOR Contest: Round #4 (Special Challenge) is live now!

~/algor $ cat problems/bit-shaharlarni-aylanish

Visiting all cities

Hard 2000 ms 128 MB 67%
Share

There are $n$ cities, travelling from city $i$ to city $j$ costs $d_{i,j}$ (the cost may depend on the direction, $d_{i,i} = 0$). A traveller leaves city $1$, must visit every other city exactly once and return to city $1$. Find the smallest total cost. If $n = 1$, the answer is $0$.

Four cities and directed roads between them; the cheapest round trip is highlighted

Input

The first line contains a positive integer $n$. Each of the next $n$ lines contains $n$ integers — $d_{i,j}$.

Output

One integer — the smallest cost.

Note

$1 \le n \le 12$
$0 \le d_{i,j} \le 10^{6}$, $d_{i,i} = 0$

Examples

Input #1
4
0 10 15 20
5 0 9 10
6 13 0 12
8 8 9 0
Output #1
35
Input #2
1
0
Output #2
0

Sign in to submit a solution

Signing up is free and takes a minute.