#P8166. [eJOI 2021] Kpart

[eJOI 2021] Kpart

Problem Description

An array AA containing only positive integers is called a KK array if every consecutive subsequence of length KK can be split into two parts whose element sums are equal. For example, {1,2,1,3}\{1,2,1,3\} is a 33 array, because {1,2,1}\{1,2,1\} can be split into {1,1}\{1,1\} and {2}\{2\} with both sums equal to 22, and {2,1,3}\{2,1,3\} can be split into {1,2}\{1,2\} and {3}\{3\} with both sums equal to 33. However, this array is not a 22 array, because {1,2}\{1,2\} cannot be split into two parts with equal element sums.

Given TT arrays containing only positive integers, for each array, find all possible values of KK such that the array is a KK array.

Input Format

The first line contains an integer TT.

Then TT arrays are described. For each array, the first line contains an integer NN, and the second line contains NN integers representing the elements of the array.

Output Format

Output TT lines. For each line, first output the number of valid KK values, then output all valid KK values in increasing order.

2
7
7 3 5 1 3 3 5
6
1 2 3 5 8 3
2 4 6
2 3 6

Hint

Constraints

This problem uses bundled testdata.

  • Subtask 1 (10 pts): 1N301 \le N \le 30.
  • Subtask 2 (20 pts): 31N12031 \le N \le 120.
  • Subtask 3 (70 pts): 121N1000121 \le N \le 1000.

For 100%100\% of the testdata, 1T201 \le T \le 20, and for each array, the sum of its elements does not exceed 10510^5.

Notes

This problem is translated from eJOI2021 Day 1 B Kpart.

Translated by ChatGPT 5