PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000004. Hệ thống truyền tin MPI (MPI Maelstrom)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hệ thống truyền tin MPI (MPI Maelstrom)

MPI Maelstrom

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

An undirected network of nn processors is described by a lower-triangular matrix of direct transmission delays; x denotes no connection. Find the largest shortest-path delay from processor 11.

Input

nn, followed by row ii (2≤i≤n2\le i\le n) containing i−1i-1 weights or x.

Output

Print the largest shortest distance from processor 11.

Subtasks

  • Subtask 1 (40 points): n≤12n\le 12; 1≤n≤1001\le n\le 100; 1≤w≤10000001\le w\le 1000000.
  • Subtask 2 (60 points): 1≤n≤1001\le n\le 100; 1≤w≤10000001\le w\le 1000000.

Examples

Input

3
3
x 4

Output

7

Explanation

Processor 11 reaches processor 22 in 33 time units, then processor 33 in 3+4=73+4=7; there is no direct edge 1−31-3.