logo AlgoBeat OnlineJudge
登录 注册

#217811. [JAG 2026 Summer Camp #3] Noise Cancelling

内存限制:2048 MiB 时间限制:3000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

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.

输入格式

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.

输出格式

Print a single integer representing the number of pairs such that is noise-cancelling.

样例

样例输入 1

9
1 -3 2 -2 -1 3 -2 2 -2

样例输出 1

4

样例输入 2

20
-1 -1 -1 1 1 1 -1 -1 1 1 -1 -1 -1 1 1 -1 1 -1 -1 1

样例输出 2

26