Codeforces Round 208 (Div. 2)
E
Dima and Kicks
Codeforces
2300
原题
← D→
翻译中…

Dima is a good person. In fact, he's great. But all good things come to an end...

翻译中…

Seryozha is going to kick Dima just few times.. For this reason he divides the room into unit squares. Now the room is a rectangle $*n* × *m*$ consisting of unit squares.

翻译中…

For the beginning, Seryozha put Dima in a center of some square. Then he started to kick Dima (it is known, that he kicks Dima at least once). Each time when Dima is kicked he flyes up and moves into one of four directions (up, left, right, down). On each move Dima passes $*k*$ $(*k* > 1)$ unit of the length in the corresponding direction. Seryozha is really kind, so he kicks Dima in such way that Dima never meets the walls (in other words, Dima never leave the room's space). Seryozha is also dynamic character so Dima never flies above the same segment, connecting a pair of adjacent squares, twice.

翻译中…

Seryozha kicks Dima for a long time, but Dima is not vindictive — Dima writes. Dima marked all squares in which he was staying or above which he was flying. Thanks to kicks, Dima does not remember the $*k*$ value, so he asks you to find all possible values which matches to the Dima's records.

翻译中…

Input

翻译中…

The first line contains $*n*$ and $*m*$ $(1 ≤ *n*, *m* ≤ 10^{3})$ — size of the room.

翻译中…

Next $*n*$ lines goes, each contains $*m*$ numbers $*a*_{*ij*}$ — Dima's notes: $*a*_{*ij*} = 1$, if Dima was staying in the square $(*i*, *j*)$ or was flying above it. Otherwise $*a*_{*ij*} = 0$.

翻译中…

At least one $*a*_{*ij*}$ equals $1$.

翻译中…

Output

翻译中…

In a single line in accending order print all $*k*$ $(*k* > 1)$, which matches the Dima's notes. If there are no such $*k*$ and Dima invented this story with kicks, print -$1$.

翻译中…

样例

Input #1
5 5
1 1 1 1 1
1 0 0 0 1
1 0 0 0 1
1 0 0 0 1
1 1 1 1 1
Output #1
2 4
InputCopy OutputCopy
Input #2
7 7
0 0 1 1 1 0 0
0 0 1 0 1 0 0
1 1 1 1 1 1 1
1 0 1 0 1 0 1
1 1 1 1 1 1 1
0 0 1 0 1 0 0
0 0 1 1 1 0 0
Output #2
2
InputCopy OutputCopy
Input #3
3 3
1 1 1
1 1 1
1 1 1
Output #3
-1
InputCopy OutputCopy
Input #4
4 4
1 1 1 1
0 0 0 0
0 0 0 0
0 0 0 0
Output #4
3
InputCopy OutputCopy
Input #5
5 5
0 0 1 0 0
0 0 1 0 0
1 1 1 1 1
0 0 1 0 0
0 0 1 0 0
Output #5
-1
InputCopy OutputCopy
题目信息
题号
358E
时间限制
2 s
内存限制
256 MB
标签
暴力
并查集
图论
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。