Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it. 

Lily decides to share a contiguous segment of the bar selected such that: 

The length of the segment matches Ron's birth month, and,
The sum of the integers on the squares is equal to his birth day.

Determine how many ways she can divide the chocolate.

Example 

$s=[2,2,1,3,2]$ 

$\boldsymbol{d}=4$ 

$m=2$   

Lily wants to find segments summing to Ron's birth day, $\boldsymbol{d}=4$ with a length equalling his birth month, $m=2$.  In this case, there are two segments meeting her criteria: $[2,2]$ and $[1,3]$.

Function Description

Complete the birthday function in the editor below.    

birthday has the following parameter(s):  

int s[n]: the numbers on each of the squares of chocolate  
int d: Ron's birth day  
int m: Ron's birth month  

Returns   

int: the number of ways the bar can be divided  

Input Format

The first line contains an integer $n$, the number of squares in the chocolate bar. 

The second line contains $n$ space-separated integers $s[i]$, the numbers on the chocolate squares where $0\leq i<n$. 

The third line contains two space-separated integers, $\boldsymbol{d}$ and $m$, Ron's birth day and his birth month.

Constraints

$1\leq n\leq100$  
$1\leq s[i]\leq5$, where ($0\leq i<n$)     
$1\leq d\leq31$  
$1\leq m\leq12$

Sample Input 0
5
1 2 1 3 2
3 2

Sample Output 0
2

Explanation 0

Lily wants to give Ron $m=2$ squares summing to $\boldsymbol{d}=3$.  The following two segments meet the criteria:

Sample Input 1
6
1 1 1 1 1 1
3 2

Sample Output 1
0

Explanation 1

Lily only wants to give Ron $m=2$ consecutive squares of chocolate whose integers sum to $\boldsymbol{d}=3$. There are no possible pieces satisfying these constraints:

Thus, we print $\mbox{o}$ as our answer.

Sample Input 2
1
4
4 1

Sample Output 2
1

Explanation 2

Lily only wants to give Ron $m=1$ square of chocolate with an integer value of $\boldsymbol{d}=4$. Because the only square of chocolate in the bar satisfies this constraint, we print $\mbox{1}$ as our answer.

Source: hackerrank | Difficulty: EASY
Tags: Implementation


Solutions:
n = int(input())
s = list(map(int, input().split()))
(d, m) = map(int, input().split())
ans = 0
for i in range(n - m + 1):
	if sum(s[i:i + m]) == d:
		ans += 1
print(ans)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(m, n + 1):
	if sum(squares[i - m:i]) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
c = 0
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		c = c + 1
print(c)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
answer = 0
for i in range(n - m + 1):
	t = 0
	for j in range(i, i + m):
		t += squares[j]
	if t == d:
		answer += 1
print(answer)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
y = [sum(squares[i:i + m]) for i in range(len(squares))]
print(y.count(d))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
c = 0
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		c += 1
print(c)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
ways = 0
for i in range(n):
	sum = 0
	for j in range(m):
		if i + j >= n:
			break
		sum += squares[i + j]
	if sum == d:
		ways += 1
print(ways)


import sys
count = 0
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
for i in range(len(squares) - m + 1):
	suma = 0
	for j in range(i, i + m):
		suma = suma + squares[j]
	if suma == d:
		count = count + 1
else:
	print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
ways = 0
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		ways += 1
print(ways)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = map(int, input().strip().split(' '))
count = 0
for i in range(len(squares)):
	if sum(squares[i:i + m]) == d:
		count += 1
print(count)


n = int(input().strip())
l = [int(x) for x in input().strip().split(' ')]
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
a = 0
for j in range(n - m + 1):
	if sum(l[j:j + m]) == d:
		a = a + 1
print(a)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(len(squares)):
	if i + m <= len(squares) and sum(squares[i:i + m]) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
c = 0
from functools import reduce
for i in range(n):
	a = reduce(lambda x, y: x + y, squares[i:i + m])
	if a == d:
		c = c + 1
print(c)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
if n == 1:
	if squares[0] == d:
		print(1)
	else:
		print(0)
else:
	for i in range(n - m + 1):
		total = 0
		for j in range(i, i + m):
			total += squares[j]
		if total == d:
			count += 1
	print(count)


import sys
c = 0
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		c += 1
print(c)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
ans = 0
if m <= n:
	t = sum(squares[:m])
	if t == d:
		ans += 1
	for i in range(m, n):
		t = t - squares[i - m] + squares[i]
		if t == d:
			ans += 1
print(ans)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
num_ways = 0
for i in range(0, n - m + 1):
	if sum(squares[i:i + m]) == d:
		num_ways += 1
print(num_ways)


n = int(input())
ar = list(map(int, input().split()))
(d, m) = map(int, input().split())
res = 0
for i in range(0, len(ar) - m + 1):
	s = 0
	for j in range(i, i + m):
		s += ar[j]
	if s == d:
		res += 1
print(res)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		count += 1
print(count)


def main():
	l = input()
	my_list = list(map(int, input().split()))
	(d, m) = map(int, input().split())
	answer = 0
	for i in range(len(my_list)):
		for j in range(i, i + m + 1):
			if sum(my_list[i:j]) == d and len(my_list[i:j]) == m:
				answer += 1
	print(answer)
main()


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
mycount = 0
for start in range(0, n - m + 1):
	sum = 0
	for i in range(start, start + m):
		sum += squares[i]
	if sum == d:
		mycount += 1
print(mycount)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
cpt = 0
for i in range(0, n - m + 1):
	test = 0
	for j in range(0, m):
		test += squares[i + j]
	if test == d:
		cpt += 1
print(cpt)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
num_conc = 0
for i in range(len(squares)):
	sum_conc = 0
	for j in range(i, i + m):
		if j >= len(squares):
			break
		sum_conc += squares[j]
	if sum_conc == d:
		num_conc += 1
print(num_conc)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if m > n:
	print(0)
else:
	answer = 0
	s = sum(squares[0:m])
	i = m - 1
	while i <= n:
		if s == d:
			answer += 1
		i += 1
		if i == len(squares):
			break
		s -= squares[i - m]
		s += squares[i]
	print(answer)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
num_solutions = 0
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		num_solutions += 1
print(num_solutions)


n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
sum1 = 0
for n in range(0, n - (m - 1)):
	val = sum(squares[n:n + m])
	if val == d:
		sum1 = sum1 + 1
print(sum1)


n = int(input())
squares = [int(i) for i in input().split()]
(d, m) = (int(i) for i in input().split())
s = sum((sum(squares[i:i + m]) == d for i in range(len(squares) - m + 1)))
print(s)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if m > len(squares):
	print(0)
	quit()
temp = 0
ans = 0
for i in range(0, m):
	temp = temp + squares[i]
if temp == d:
	ans = ans + 1
for i in range(m, len(squares)):
	temp = temp + squares[i] - squares[i - m]
	if temp == d:
		ans = ans + 1
print(ans)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]

def get_variants_number(squares, n, d, m):
	result = 0
	for i in range(0, n - m + 1):
		current_sum = sum(squares[i:i + m])
		if current_sum == d:
			result += 1
	return result
print(get_variants_number(squares, n, d, m))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
output = 0
for index in range(n - m + 1):
	i = index
	count = 0
	sum = 0
	while sum <= d and count <= m and (i < n):
		sum = sum + squares[i]
		count = count + 1
		i = i + 1
		if sum == d and count == m:
			output += 1
print(output)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if m > n:
	print('0')
else:
	result = 0
	for i in range(n - m + 1):
		if sum(squares[i:i + m]) == d:
			result += 1
	print(result)


n = int(input())
a = list(map(int, input().split(' ')))
(d, m) = map(int, input().split(' '))
count = 0
for i in range(n - m + 1):
	sum1 = 0
	for j in range(i, i + m):
		sum1 += a[j]
	if sum1 == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(0, n):
	test = squares[i:i + m]
	if sum(test) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
i = 0
while i < n:
	sum = 0
	for j in range(m):
		if i + j == n:
			i = n
			break
		sum += squares[i + j]
	if sum == d:
		count += 1
	i += 1
print(str(count))


import sys
n = int(input().strip())
sums = 0
count = 0
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
for i in range(0, n):
	q = squares[i:m + i]
	sums = sum(q)
	if sums == d:
		count = count + 1
	i = i + m
print(count)


def parse_line():
	return list(map(int, input().split(' ')))
n = int(input())
a = parse_line()
(d, m) = parse_line()
print([sum(a[i:i + m]) for i in range(n - m + 1)].count(d))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(len(squares) - m + 1):
	t = 0
	for j in range(i, i + m):
		t = t + squares[j]
	if d == t:
		count = count + 1
print(count)


import sys

def birthday(s, d, m):
	if len(s) < m:
		return 0
	p = s[:m]
	if sum(p) == d:
		ans = 1
	else:
		ans = 0
	for i in s[m:]:
		p = p[1:] + [i]
		if sum(p) == d:
			ans += 1
	return ans
n = int(input().strip())
s = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
print(birthday(s, d, m))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
forms = 0
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		forms += 1
print(forms)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
l = len(squares)
for i in range(0, l - m + 1):
	if sum(squares[i:i + m]) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
tot = 0
count = 0
pos = 0
if m <= len(squares):
	for i in squares:
		if pos == len(squares) - (m - 1) and len(squares) != 1:
			break
		for j in range(m):
			tot += squares[j + pos]
		if tot == d:
			count += 1
		tot = 0
		pos += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(0, n - m + 1):
	s = 0
	for j in range(i, i + m):
		s += squares[j]
	if s == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(n - m + 1):
	s = 0
	for j in range(i, m + i):
		s = s + squares[j]
	if s == d:
		count = count + 1
print(count)


import sys

def total_comb(s, d, m):
	total = 0
	if len(s) == m and sum(s) == d:
		return 1
	for i in range(len(s) - m + 1):
		tmp = 0
		tmp = sum(s[i:i + m])
		if tmp == d:
			total += 1
	return total
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
print(total_comb(squares, d, m))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if m > n:
	cpt = 0
else:
	sum = 0
	for i in range(0, m):
		sum = sum + squares[i]
	if sum == d:
		cpt = 1
	else:
		cpt = 0
	i = m
	while i < n:
		sum = sum - squares[i - m] + squares[i]
		if sum == d:
			cpt = cpt + 1
		i = i + 1
print(cpt)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
total = 0
for i in range(len(squares) - m + 1):
	s = sum(squares[i:i + m])
	if s == d:
		total += 1
print(total)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]

def x(n, squares, d, m):
	i = 0
	result = 0
	while i + m <= n:
		if sum(squares[i:i + m]) == d:
			result = result + 1
		i = i + 1
	print(result)
x(n, squares, d, m)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
cnt = 0
if n > 1:
	for i in range(0, n - 1):
		sq_sub = squares[i:m + i]
		if d == sum(sq_sub):
			cnt += 1
elif d == sum(squares):
	cnt += 1
print(cnt)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
result = 0
pos = m
j = 0
pairs = [0] * (n - m + 1)
for i in range(0, n - m + 1):
	pairs[i] = squares[j:pos]
	j = j + 1
	pos = pos + 1
sums = [0] * (n - m + 2)
for i in range(0, n - m + 1):
	sums[i] = 0
	for j in pairs[i]:
		sums[i] = sums[i] + j
	if sums[i] == d:
		result += 1
print(result)


import sys
f = 0
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
for i in range(1, n):
	squares[i] += squares[i - 1]
for i in range(m - 1, n):
	if i - m == -1 and squares[i] == d or squares[i] - squares[i - m] == d:
		f += 1
print(f)


import sys
n = int(input().strip())
s = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
i = 0
t = 0
while i <= n - m:
	t1 = s[i]
	k = i + 1
	while k <= i + m - 1:
		t1 += s[k]
		k += 1
	if t1 == d:
		t += 1
	i += 1
if len(s) == 1 and sum(s) == d:
	print(1)
else:
	print(t)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
output = 0
for x in range(0, n - m + 1):
	count = 0
	for y in range(x, x + m):
		count = count + squares[y]
	if count == d:
		output = output + 1
print(output)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(n):
	sum1 = 0
	if i <= n - m:
		for j in range(m):
			sum1 = sum1 + squares[i + j]
		if sum1 == d:
			count = count + 1
print(count)


import sys

def main():
	n = int(input().strip())
	squares = list(map(int, input().strip().split(' ')))
	assert n == len(squares)
	(d, m) = input().strip().split(' ')
	(d, m) = [int(d), int(m)]
	assert n >= m
	ways = 0
	for i in range(0, n - m + 1):
		temp_sum = 0
		for j in range(0, m):
			temp_sum += squares[i + j]
			if temp_sum > d:
				break
		if temp_sum == d:
			ways += 1
	print(ways)
main()


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(0, n - m + 1):
	if sum(squares[i:i + m]) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
way = 0
for i in range(len(squares) - m + 1):
	sum = 0
	for auxx in range(i, m + i):
		sum = sum + squares[auxx]
	if sum == d:
		way = way + 1
print(way)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
(ptr1, ptr2) = (0, 0)
curr_sum = 0
for _ in range(m - 1):
	if ptr2 < n:
		curr_sum += squares[ptr2]
		ptr2 += 1
	else:
		print('error: there are less squares than the m provided')
n_of_ways = 0
while ptr2 < n:
	curr_sum += squares[ptr2]
	if curr_sum == d:
		n_of_ways += 1
	curr_sum -= squares[ptr1]
	ptr1 += 1
	ptr2 += 1
print(n_of_ways)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if n < 1 or n > 100 or d > 31 or (d < 1) or (m > 12) or (m < 1):
	exit
for i in squares:
	if i > 5 or i < 1:
		exit
final = []
(j, sums, count) = (0, 0, 0)
for i in range(n):
	j = i
	sums = 0
	s = m
	t = j + s - 1
	while s > 0 and t < n:
		t = j + s - 1
		sums = sums + squares[t]
		s = s - 1
	final.append(sums)
for i in final:
	if i == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
ans = 0
s = 0
for i in range(0, m):
	s += squares[i]
if s == d:
	ans += 1
for i in range(1, n - m + 1):
	s += squares[i + m - 1] - squares[i - 1]
	if s == d:
		ans += 1
print(ans)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(len(squares) - m + 1):
	if sum(squares[i:i + m]) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
numways = 0
for index in range(n - m + 1):
	sum = 0
	for offset in range(m):
		sum += squares[index + offset]
	if sum == d:
		numways += 1
print(numways)


import sys
n = int(input().strip())
s = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
cnt = 0
for i in range(0, len(s) - m + 1):
	if sum(s[i:i + m]) == d:
		cnt += 1
print(cnt)


def works(arr, d, m, start):
	if sum(arr[start:start + m]) == d:
		return True
	else:
		return False

def solution(arr, d, m):
	count = 0
	for i in range(len(arr) - (m - 1)):
		if works(arr, d, m, i):
			count += 1
	return count
size = input().strip()
arr = [int(_) for _ in input().strip().split()]
(d, m) = [int(_) for _ in input().strip().split()]
ans = solution(arr, d, m)
print(str(ans))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
check = 0
for i in range(len(squares) - m + 1):
	sum = 0
	for x in range(i, m + i):
		sum = sum + squares[x]
	if sum == d:
		check = check + 1
print(check)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]

def check(value, variable):
	if variable == 'n':
		tf = list(map(lambda x: x > 100, value))
		if sum(tf) > 0:
			raise KeyError('n is greater than 100')
res = 0
if not n < m:
	for i in range(n - m + 1):
		if sum(squares[i:i + m]) == d:
			res += 1
print(res)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
day = d
month = m

def num_squares(bar, day, month):
	num_of_squares = 0
	for i in range(len(bar)):
		res = 0
		for num in range(month):
			if len(bar) - 1 >= i + num:
				res += bar[i + num]
		if res == day:
			num_of_squares += 1
	return num_of_squares
print(num_squares(squares, day, month))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
consum = sum(squares[:m])
if consum == d:
	ways = 1
else:
	ways = 0
for i in range(m, n):
	consum = consum + squares[i] - squares[i - m]
	if consum == d:
		ways = ways + 1
print(ways)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
c = 0
for i in range(n - m + 2):
	sumo = sum(list(map(int, squares[i:m + i])))
	if sumo == d:
		c = c + 1
print(c)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if m > n:
	print('0')
p1 = 0
p2 = m - 1
count = 0
while p2 < n:
	sum1 = sum(squares[p1:p2 + 1])
	if sum1 == d:
		count += 1
	p1 += 1
	p2 += 1
print(count)


import sys
n = int(input())
a = list(map(int, input().split()))
(d, m) = map(int, input().split())
count = 0
if n >= m:
	dsum = sum(a[:m])
	if dsum == d:
		count += 1
	for i in range(n - m):
		j = i + m
		dsum += a[j] - a[i]
		if dsum == d:
			count += 1
print(count)


def main():
	n = int(input().strip())
	bar = [int(sqr) for sqr in input().strip().split(' ')]
	data = [int(i) for i in input().strip().split(' ')]
	day = data[0]
	month = data[1]
	counter = 0
	for i in range(n):
		accum = 0
		for j in range(month):
			if i + j < n:
				accum += bar[i + j]
		if accum == day:
			counter += 1
	print(counter)
main()


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
sq = []
count = 0
for i in range(n):
	sq = squares[i:m]
	m += 1
	sum1 = sum(sq)
	if sum1 == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
number_of_possibilities = 0
i = 0
while i <= len(squares) - m:
	if sum(squares[i:i + m]) == d:
		number_of_possibilities += 1
	i += 1
print(number_of_possibilities)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]

def main(arr, d, m):
	num_squares = len(arr)
	if num_squares < m:
		return 0
	start = 0
	end = m - 1
	total = sum(arr[start:end + 1])
	counter = 0
	if total == d:
		counter += 1
	while end < num_squares - 1:
		total -= arr[start]
		start += 1
		end += 1
		total += arr[end]
		if total == d:
			counter += 1
	return counter
print(main(squares, d, m))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
window = sum(squares[0:m])
if window == d:
	count += 1
j = 0
for i in range(m, n):
	window -= squares[j]
	j += 1
	window += squares[i]
	if window == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
shared = 0
for i in range(n):
	if sum(squares[i:i + m]) == d:
		shared += 1
print(shared)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = map(int, input().strip().split(' '))
if m > n:
	print(0)
else:
	ans = 0
	s = 0
	for i in range(0, m):
		s += squares[i]
	if s == d:
		ans += 1
	for i in range(m, n):
		s += squares[i]
		s -= squares[i - m]
		if s == d:
			ans += 1
	print(ans)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
(i, sumIs, ctr) = (0, 0, 0)
while i <= len(squares) - m:
	sumIs = sum(squares[i:i + m])
	if sumIs == d:
		ctr = ctr + 1
	i = i + 1
print(ctr)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
s = 0
count = 0
rg1 = min(n, m)
for i in range(rg1):
	s = s + squares[i]
if s == d:
	count += 1
for i in range(1, n - m + 1):
	s = s - squares[i - 1] + squares[i + m - 1]
	if s == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
possibles = []
ind = 0
while ind <= n - m:
	possibles.append(squares[ind:ind + m])
	ind += 1
count = 0
for each in possibles:
	if sum(each) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if m > len(squares):
	print(0)
else:
	ways = 0
	for i in range(m - 1, len(squares) + 1):
		if sum(squares[i - m + 1:i + 1]) == d:
			ways += 1
	print(ways)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
ways = 0
for i in range(len(squares) - m + 1):
	if sum(squares[i:i + m]) == d:
		ways += 1
print(ways)


import sys

def sumCount(m, d, seq):
	n = list(seq[:m])
	s = sum(n)
	c = 1 if s == d else 0
	for v in seq[m:]:
		p = n.pop(0)
		s -= p
		s += v
		n.append(v)
		if s == d:
			c += 1
	return c
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
print(sumCount(m, d, squares))


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if n <= 1 and n >= 100:
	print('input n again')
	n = int(input().strip())
l = len(squares)
for i in range(0, l):
	if squares[i] <= 1 and squares[i] >= 5:
		print('input si again')
		squares = list(map(int, input().strip().split(' ')))
if d <= 1 and d >= 12 and (m <= 1) and (m >= 12):
	print('input d and m again')
	(d, m) = input().strip().split(' ')
	(d, m) = [int(d), int(m)]
number = 0
k = l - m + 1
p = 0
num = 0
for j in range(0, k):
	sum = 0
	for i in range(j, j + m):
		sum = sum + squares[i]
	if sum == d:
		number = number + 1
print(number)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
s = sum(squares[:m])
ways = 0
for i in range(m, n):
	if s == d:
		ways += 1
	s -= squares[i - m]
	s += squares[i]
if s == d:
	ways += 1
print(ways)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(len(squares) - m + 1):
	k = i
	a = 0
	j = 0
	while j < m:
		a += squares[k]
		k += 1
		j += 1
	if a == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
ways = 0
for i in range(n - m + 1):
	if sum(squares[i:i + m]) == d:
		ways += 1
print(ways)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
j = 0
r = 0
if (n >= 1 and n <= 100) and (d >= 1 and d <= 31) and (m >= 1 and m <= 12) and all((i >= 1 and i <= 5 for i in squares)):
	while j <= n:
		sm = 0
		k = j
		while k <= j + m - 1 and k <= n - 1:
			sm += squares[k]
			k += 1
		if sm == d:
			r += 1
		j += 1
	print(r)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]

def bdChoc():
	count = 0
	square = 0
	while square <= len(squares) - m:
		index = square
		res = sum(squares[square:square + m])
		if res == d:
			count += 1
		square += 1
	print(count)
bdChoc()


import sys
n = int(input().strip())
A = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
ans = 0
for i in range(n - m + 1):
	if sum(A[i:i + m]) == d:
		ans += 1
print(ans)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(n):
	if sum(squares[i:i + m]) == d:
		count += 1
print(count)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
i = 0
validChunks = 0
while i + m <= len(squares):
	summe = sum(squares[i:i + m])
	if summe == d:
		validChunks = validChunks + 1
	i = i + 1
print(validChunks)


import sys
import math
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
countit = 0
for j in range(n - m + 1):
	x = sum(squares[j:j + m])
	if x == d:
		countit += 1
if n == 1 and m == 1 and (squares[0] == d):
	print(1)
else:
	print(countit)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
if m > n:
	print(0)
elif m == d:
	print(1)
elif m > d:
	print(0)
if m < d and n > 1:
	i = 0
	count = 0
	while i < n - 1:
		total = 0
		for j in squares[i:i + m]:
			total = total + j
		if total == d:
			count = count + 1
		i = i + 1
	print(count)
elif m < d and n == 1:
	if squares[0] == d:
		print(1)
	else:
		print(0)


import sys
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
k = 0
i = 0
sum = 0
cont = 0
while i <= n - m:
	sum = squares[i]
	while k < m - 1:
		sum += squares[k + i + 1]
		k += 1
	if sum == d:
		cont += 1
	i += 1
	k = 0
	sum = 0
print(cont)


n = int(input().strip())
sq = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
count = 0
for i in range(0, n - m + 1):
	if sum(sq[i:i + m]) == d:
		count += 1
print(count)


import sys

def find_piece(start_index, arr, sum, how_many):
	f_sum = 0
	arr = arr[start_index:start_index + how_many]
	for i in arr:
		f_sum += i
	if f_sum == sum:
		return 1
	else:
		return 0
n = int(input().strip())
squares = list(map(int, input().strip().split(' ')))
(d, m) = input().strip().split(' ')
(d, m) = [int(d), int(m)]
ways_for_the_chocolate = 0
for i in range(0, len(squares)):
	c = find_piece(i, squares, d, m)
	ways_for_the_chocolate += c
print(ways_for_the_chocolate)


n = int(input())
s = list(map(int, input().split()))
(d, m) = map(int, input().split())
options = 0
for i in range(len(s)):
	j = i + 1
	sum_of_s = s[i]
	sum_len = 1
	while j < len(s) and sum_len < m and (sum_of_s < d):
		sum_of_s += s[j]
		sum_len += 1
		j += 1
	if sum_len == m and sum_of_s == d:
		options += 1
print(options)