P9417 [POI 2021/2022 R1] Printing

Background

Translated from [XXIX Olimpiada Informatyczna – Stage I](https://sio2.mimuw.edu.pl/c/oi29-1/dashboard/) [Druk](https://sio2.mimuw.edu.pl/c/oi29-1/p/dru/)。

Description

You are given an $n \times m$ rectangle of characters containing only lowercase English letters. You need to make two stencils (templates). One is horizontal (one row and $l$ columns), and the other is vertical ($l$ rows and one column). The value $l$ is called the stencil length. Both stencils contain exactly the same string (from left to right, from top to bottom, and they cannot be flipped). You must ensure that you can use these two stencils to print the whole rectangle without overlap and without leaving any cell unprinted. There may be many ways to make the stencils. You only need to output all feasible stencil lengths.

Input Format

The first line contains two positive integers $n, m$, representing the size of the rectangle. The next part is an $n$-row, $m$-column rectangle of characters, containing only lowercase English letters.

Output Format

The first line contains an integer, the number of feasible lengths you found. The second line contains several integers: all feasible lengths you found.

Explanation/Hint

Explanation for sample 1: ![image missing](https://cdn.luogu.com.cn/upload/image_hosting/2zs08vop.png) Explanation for sample 4: ![image missing](https://cdn.luogu.com.cn/upload/image_hosting/p1zo7v6x.png) For all testdata, $1 \leq n, m \leq 1000$. ## Constraints | Subtask ID | Additional Constraints | Score | | :----------: | :----------: | :----------: | | 1 | $n = 1, m \leq 1000$ | 10 | | 2 | $n \leq 3, m \leq 1000$ | 25 | | 3 | $n, m \leq 20$ | 20 | | 4 | | 45 | Translated by ChatGPT 5