CitadelOA #12
Count Stable Segments
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesHashing
In a contiguous segment of length at least 3, the left and right endpoint capacities must be equal and must equal the sum of all interior capacities. Find the number of such segments. The original capacity[i] is restored to the left endpoint capacity[l] based on the following sentence and the examples.
Input
The first line contains n, followed by n capacity values; complete original bounds 1≤n≤100000, 1≤capacity[i]≤100000.
Output
Output a single integer, the answer.
Example 1
Input:
5
9 3 3 3 9
Output:
2
Example 2
Input:
7
9 3 1 2 3 9 10
Output:
2
Example 3
Input:
2
1 1
Output:
0
Example notes
The outputs of the three public examples are, in order: 2; 2; 0. These answers were verified by independent enumeration or direct simulation.
Editorial
Loading solution…