RoAlgo Contest #6 | sliniare

This was the problem page during the contest. Access the current page here.
Time limit: 0.13s Memory limit: 64MB Input: Output:

Given an array VV of NN elements from the set {0,1}\{0, 1\}, a subarray is called linear if the equality aUZ=baU - Z = b is true, where UU and ZZ represent the number of elements equal to 11 in the subarray and the number of elements equal to 00 in the subarray, respectively, and aa and bb are given natural numbers.

Task

Determine the number of linear subarrays in the array VV.

Input data

The first line contains NN, aa, and bb separated by a space. The next line contains NN natural numbers, separated by a space, representing the elements of the array VV.

Output data

The first line will contain a natural number, representing the number of linear subarrays in the array VV.

Constraints and clarifications

  • 1N100 0001 \leq N \leq 100 \ 000
  • 1a10 0001 \leq a \leq 10 \ 000
  • 1b1 000 000 0001 \leq b \leq 1 \ 000 \ 000 \ 000
# Points Constraints
0 0 Examples
1 11 N100N \leq 100
2 13 N2 000N \leq 2 \ 000
3 17 All values in the array VV are equal to 11
4 59 No additional constraints

Example 1

stdin

9 1 3
1 0 1 1 1 0 0 1 1

stdout

4

Explanation

The linear subarrays are [1,0,1,1,1][1, 0, 1, 1, 1], [1,1,1][1, 1, 1], [1,1,1,0,0,1,1][1, 1, 1, 0, 0, 1, 1], and [1,0,1,1,1,0,0,1,1][1, 0, 1, 1, 1, 0, 0, 1, 1].

Example 2

stdin

9 3 8
1 1 1 0 1 0 0 0 1

stdout

4

Explanation

The linear subarrays are [1,1,1,0][1, 1, 1, 0], [1,1,0,1][1, 1, 0, 1], [1,1,1,0,1,0,0,0][1, 1, 1, 0, 1, 0, 0, 0], and [1,1,0,1,0,0,0,1][1, 1, 0, 1, 0, 0, 0, 1].

Example 3

stdin

5 2 5
1 0 0 1 1

stdout

0

Explanation

There are no linear subarrays.

Log in or sign up to be able to send submissions!