QOJ.ac

QOJ

Limite de temps : 4 s Limite de mémoire : 256 MB Points totaux : 100

#2106. Print

Statistiques

Printer Bajtazar has received an order to print a text-based tablet. The letters on the tablet are arranged uniformly on an $n \times m$ grid. Bajtazar will perform the printing using a printing template, which is a strip with a width equal to the width of one row of letters. The printing is done by (potentially multiple) applications of the template and spraying paint exactly over the template, with the constraint that at the moment of printing, the template cannot extend beyond the tablet.

The template will be prepared in a horizontal and a vertical version, and both versions must contain the same text. Bajtazar must print each position on the tablet exactly once using the template. Note that neither version of the template can be rotated, so that the letters are not printed in an inverted manner.

Help Bajtazar and provide all template lengths with which Bajtazar can print the entire tablet.

Input

The first line of input contains two positive integers $n$ and $m$, representing the number of rows of letters on the tablet and the number of letters in each row of the tablet, respectively. The $i$-th of the following $n$ lines contains an $m$-letter string consisting of lowercase English letters (a–z), representing the target content of the $i$-th row of the tablet from the top.

Output

The first line of output should contain a single integer representing the number of template lengths with which Bajtazar can print the tablet. The second line should contain all these lengths, ordered strictly increasingly, separated by single spaces. If the first line of output contains the number 0, the second line should remain empty.

Examples

Input 1

5 8
aabaaaaa
babaabbb
aabaaaaa
aabaaaaa
abaaabaa

Output 1

1
4

Subtasks

The test suite is divided into the following subtasks. Tests for each subtask consist of one or more separate test groups.

Subtask Constraints Points
1 $n = 1, m \le 1000$ 10
2 $n \le 3, m \le 1000$ 25
3 $n, m \le 20$ 20
4 $n, m \le 1000$ 45

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.