#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
int a[5][5];
int n=4,i,j,k;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
a[i][j] = i==j ? 0 : 9;
a[1][3]=a[3][4]=a[4][2]=1;
a[3][1]=a[4][3]=a[2][4]=1;
for(j=1;j<=n;j++)
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
a[i][j] = min(a[i][j], a[i][k] + a[k][j]);
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
printf("%d%c",a[i][j],j<n?' ':'\n');
return 0;
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IGFbNV1bNV07CglpbnQgbj00LGksaixrOwoJZm9yKGk9MTtpPD1uO2krKykKCQlmb3Ioaj0xO2o8PW47aisrKQoJCQlhW2ldW2pdID0gaT09aiA/IDAgOiA5OwogICAgYVsxXVszXT1hWzNdWzRdPWFbNF1bMl09MTsKICAgIGFbM11bMV09YVs0XVszXT1hWzJdWzRdPTE7CiAgICBmb3Ioaj0xO2o8PW47aisrKQogICAgICAgIGZvcihrPTE7azw9bjtrKyspCiAgICAgICAgICAgIGZvcihpPTE7aTw9bjtpKyspCiAgICAgICAgICAgICAgICBhW2ldW2pdID0gbWluKGFbaV1bal0sIGFbaV1ba10gKyBhW2tdW2pdKTsKCWZvcihpPTE7aTw9bjtpKyspCgkJZm9yKGo9MTtqPD1uO2orKykKCQkJcHJpbnRmKCIlZCVjIixhW2ldW2pdLGo8bj8nICc6J1xuJyk7CiAgICByZXR1cm4gMDsKfQ==