Under construction

Still being built. Things may change

Computing MDSST

Time limit1sMemory limit512 MB

Summary
Given a complete weighted graph on at most 15 vertices, find the spanning tree whose sum of all pairwise shortest-path distances is smallest, and print that sum.
Level

Hard8 of 10

Topics
Graph, Minimum spanning tree, Brute force, Bit manipulation
Solved
No attempts yet

Problem

In this problem we consider weighted undirected graphs where every edge has positive weight.

Let D(G,i,j)D(G,i,j) be the length of the shortest path in graph GG between vertex ii and vertex jj.

We are given a complete weighted undirected graph GG with nn vertices numbered from 11 to nn. Among the spanning trees of GG, the MDSST (Minimum Distance Sum Spanning Tree) is the tree TT that minimizes S(T)=∑_1≤i<j≤nD(T,i,j)S(T) = \sum\_{1 \leq i < j \leq n} D(T,i,j). Find the MDSST of GG and print S(T)S(T).

Input

The first line contains an integer nn, the number of vertices in the graph (2≤n≤152 \le n \le 15). The ii-th of the following n−1n-1 lines contains n−in-i integers separated by spaces. The jj-th integer on this line is the length of the edge between vertex ii and vertex i+ji+j.

All lengths are between 11 and 10910^9, inclusive.

Output

On the first line, print one integer: the value S(T)S(T) for the MDSST you found.

Examples1

  1. Example 1

    Input
    4
    3 2 1
    5 6
    7
    
    Expected output
    18