Floyd - existence#672

Floyd - existence

1 second
128 megabytes
Medium (≈1350)

The directed weighted graph is given. Using its weighted matrix, determine for each pair of vertices whether there exists a shortest path between them or not.

The shortest path may not exist for two reasons:

Input

The first line contains the number of vertices n~(1 \le n \le 100). The next lines contains numbers that describe the weighted matrix (-th of the -th row corresponds to the weight of the edge from vertex to vertex ). The number in this matrix represents no edge, and any other number — the existence of an edge of corresponding weight. All the numbers do not exceed by absolute value.

Output

Print rows with numbers: the -th number in the -th row must be if the path from to does not exist, if there is a shortest path, and if there is a path of arbitrarily small weight.

Examples

Example 1

Loading
Loading