#P9224. 「PEOI Rd1」k 叉堆(heap)
「PEOI Rd1」k 叉堆(heap)
Background
Constraints are stronger than during the contest.
- 2023.04.25: The 1.50 s time limit was too tight due to constant factors, so it was increased to 2.00 s.
Problem Description
Given a sequence of positions , each position has parameters . It is known that this sequence is obtained by taking the BFS order of a max-heap.
The BFS order is the order of the red numbered nodes in the figure below:

A max-heap satisfies the condition if and only if, for every child node, all of its values are less than or equal to those of its parent, i.e., $\forall u \in [1,n], \forall v \in son(u), \forall j \in [1,k], a_{v,j} \leq a_{u,j}$.
Assume this max-heap is a complete -ary tree. Find all such that this -ary heap satisfies the condition.
Input Format
The first line contains two integers .
Then follow lines, each containing integers, describing the given sequence. Specifically, the value in row and column is .
You can understand this as: all parameters for all positions are given, split into lines.
Output Format
The first line contains an integer , the number of possible values of .
The next line contains integers, the possible values of .
3 2
1 1 1
1 1 1
2
1 2
6 1
2 1 2 1 1 2
2
2 5
Hint
Sample Explanation
In Sample , both -ary and -ary heaps obviously satisfy the condition.
Constraints
| Subtask ID | Score | |
|---|---|---|
For of the testdata, it is guaranteed that , , and .
Translated by ChatGPT 5