Let . One strength- particle adds in total, so only strengths satisfying are candidates.
Let be the particle count at orbital , with indices cycling through . Compute . Then . Split the indices into cycles of length . Integrate once, determine the initial slope from the cyclic condition, and integrate again. Every cycle permits adding an arbitrary integer constant to its base solution.
Let be the sum of the base solutions and let be the sum of their negated minima. The required particle count is . The candidate is valid exactly when and .
With candidate strengths, the time complexity is and the space complexity is .
Proof
The second difference of the triangular kernel leaves at its center and at both positions steps away. On a cycle, writing gives . The slopes close exactly when , and uniquely fixes the initial slope. A nonintegral initial slope is impossible.
In subtask 1, a nonzero particle has peak , leaving only three strengths.
For subtask 2, let be the common difference. If , check . If , we must have . Let , . The base-solution sum is and the minimum nonnegative total is . Thus check and , taking per candidate.
After the second integration, all integer solutions differ by a constant on each cycle. This constant is at least the negated minimum and changes the particle count by a multiple of . The stated divisibility and lower-bound conditions are therefore necessary and sufficient. The constructed intensity sequence and have equal second differences and equal sums. A circular sequence with zero second difference is constant, so the two sequences agree.
For an arithmetic progression with , only and are nonzero. They must belong to the same cycle, since each cycle has curvature sum zero, so . Starting at position and repeatedly adding , position occurs after steps. The base solution consists of two linear pieces with height , total , and minimum . Its minimum nonnegative total is therefore , and constants change its total by multiples of . When , every cycle has zero base solution; the condition is , equivalently .
Solution written by GPT6