#Lutece0738. floyd

floyd

Migrated from Lutece 738 floyd

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

已知nn个点两两之间的最短路,求nn个点之间最少需要连接多少条有向边才能使得两两之间的最短路满足所给方阵

Input

包含多组数据。对于每组数据,第一行包含一个数nnn100n\le 100),表示点的个数,接下来的nn行每行包含nn个非负整数,其中第ii行第jj个数表示第ii个点到第jj个点的最短路长度(109\le 10^9

Output

每组数据包含一行,即最少路径条数,若不存在输出1-1

Samples

输入数据 1

3
0 1 1
1 0 1
1 1 0
3
0 1 1
1 0 2
1 2 0

输出数据 1

6
4

Resources

2013 UESTC ACM Training for Graph Theory