#P17579. [JAG 2026 Summer Camp #3] Noise Cancelling
[JAG 2026 Summer Camp #3] Noise Cancelling
Problem Description
A sequence consisting of nonzero integers is called noise-cancelling if there exists a positive integer such that its length is and
holds for every (), where denotes the -th element of . In other words, the second half of a noise-cancelling sequence is the elementwise negation of its first half, so the corresponding elements cancel each other out. In particular, no sequence of odd length is noise-cancelling.
For example, is noise-cancelling.
You are given a sequence of nonzero integers . Find the number of pairs of integers () such that the contiguous subsequence is noise-cancelling.
Input Format
The input consists of a single test case of the following format.
N
a_1 a_2 ... a_N
The first line contains an integer (), representing the length of the sequence.
The second line contains nonzero integers (), representing the elements of the sequence.
Output Format
Print a single integer representing the number of pairs such that is noise-cancelling.
9
1 -3 2 -2 -1 3 -2 2 -2
4
20
-1 -1 -1 1 1 1 -1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 1
26