Flat Earth
Time limit2sMemory limit1024 MB
Choose nonzero row and column multipliers that make every cell of an N x N grid equal, minimizing the number of distinct multiplier values.
Problem
Chanwoo supports the flat Earth theory. To prove it, he will flatten POSTECH! The ground height distribution of POSTECH is represented by an matrix. For every , Chanwoo performs both of the following operations to make all the uneven ground heights of POSTECH equal.
- Multiply every number in row by a nonzero number of your choice.
- Multiply every number in column by a nonzero number of your choice.
Note that each does not need to be an integer.
Chanwoo is lazy and does not want more kinds of multipliers to handle. He wants to choose so that the number of distinct values among them is as small as possible. Help Chanwoo minimize the number of distinct values in the sequence !
Input
The first line contains ().
From the second line on, lines follow, each containing integers separated by spaces. is the ground height at row , column of POSTECH. (; )
Output
Print the minimum number of distinct values among that satisfy the conditions. If no sequence can flatten POSTECH, print -1.
Hint
⚠️ This differs from the actual POSTECH environment. ⚠️