import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.Scanner;
/
Floyd 弗洛伊德算法
graph 图的邻阶矩阵
更新后的graph i点到j点的最短路径
/
public class Main {
public static StreamTokenizer st = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
public static Scanner scanner = new Scanner(System.in);
public static int n;
public static int[][] graph;
public static void main(String[] args) throws IOException {
n = nextInt();
graph = new int[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
graph[i][j] = nextInt();
}
}
for (int k = 0; k < n; k++) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
graph[i][j] = Math.min(graph[i][j], graph[i][k] + graph[k][j]);
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
System.out.print(graph[i][j] + " ");
}
System.out.println();
}
}
private static long nextLong() throws IOException {
st.nextToken();
return (long) st.nval;
}
private static int nextInt() throws IOException {
st.nextToken();
return (int) st.nval;
}
}