-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path015_Sub_Array_Division.py
More file actions
48 lines (33 loc) · 1.03 KB
/
Copy path015_Sub_Array_Division.py
File metadata and controls
48 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the birthday function below.
def birthday(s, d, m):
# liste1 = [] #[[1, 2], [2, 1], [1, 3], [3, 2]]
# liste2 = []
count = 0
for i in range(0, (len(s) + 1 - m)):
if sum(s[i:i + m]) == d:
count += 1
# liste1.append(s[i:(m+i)])
# for i in range(len(s)-m+1):
# if sum(liste1[i:i+m]) == d:
# count += 1
return count
# tp = (len(s)-m) + 1 #total number of pieces possible
# return len([1 for i in range(tp) if sum(s[i:i+m])==d])
#tek satır versiyon;
# return len([1 for i in range((len(s)-m) + 1) if sum(s[i:i+m])==d])
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input().strip())
s = list(map(int, input().rstrip().split()))
dm = input().rstrip().split()
d = int(dm[0])
m = int(dm[1])
result = birthday(s, d, m)
fptr.write(str(result) + '\n')
fptr.close()