Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02891 (python)

Fixed submission:
import sys
S = input() 
K = int(input()) 
l = len(S)
ren = [0]*l
cnt = 0
 
for i in range(1,l):
  if S[i] == S[i-1]:
    cnt += 1
  elif S[i] != S[i-1]:
    ren[cnt] +=1
    cnt = 0
  if i == l-1:
    ren[cnt] +=1
    
ren = [K*i for i in ren]
   
if ren[l-1] or l ==1:
  print((l*K)//2)
  sys.exit()
  
if S[0]==S[-1]:
  start = 0
  while S[start]==S[start+1]:
    start += 1
  end = 0
  while S[-1-end]==S[-2-end]:
    end += 1
  ren[start+end+1] += K-1
  ren[start] -= K-1
  ren[end] -= K-1
 
 
ans = 0
 
for i in range(1,l):
  if i%2 ==0:
    ans += (i//2)*ren[i]
  else:
    ans += ((i+1)//2)*ren[i]
      
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
S = input() 
K = int(input()) 
l = len(S)
ren = [0]*l
cnt = 0

for i in range(1,l):
  if S[i] == S[i-1]:
    cnt += 1
  elif S[i] != S[i-1]:
    ren[cnt] +=1
    cnt = 0
  if i == l-1:
    ren[cnt] +=1
    
ren = [K*i for i in ren]
   
if ren[l-1]:
  print((l*K)//2)
  sys.exit()

if S[0]==S[-1]:
  start = 0
  while S[start]==S[start+1]:
    start += 1
  end = 0
  while S[-1-end]==S[-2-end]:
    end += 1
  ren[start+end+1] += K-1
  ren[start] -= K-1
  ren[end] -= K-1


ans = 0

for i in range(1,l):
  if i%2 ==0:
    ans += (i//2)*ren[i]
  else:
    ans += ((i+1)//2)*ren[i]
      
print(ans)
Problem p02897 (python)

Fixed submission:
n = int(input())


if n%2 == 0:
    ans = 0.5
else:
    ans = (n+1)/(2*n)

print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int, input().split()) 
h=list(map(int, input().split()))

ans = len([1 for x in h if x >= K])

print(ans)
Problem p03013 (python)

Fixed submission:
import sys
N, M =map(int, input().split())


if N == 1:
  print(1)
  sys.exit()

a =[1]*N
mod = 1000000007
for i in range(M):
  a[int(input())-1]=0

  
dp = [0]*N

dp[0] = a[0]*1
dp[1] = (dp[0] + 1)*a[1]

for i in range(2,N):
  dp[i] = (dp[i-1]+dp[i-2]) *a[i]
  
print(dp[-1]%mod)

Buggy submission (verdict: Runtime Error):
N, M =map(int, input().split())
a =[1]*N
mod = 1000000007
for i in range(M):
  a[int(input())-1]=0

dp = [0]*N

dp[0] = a[0]*1
dp[1] = (dp[0] + 1)*a[1]

for i in range(2,N):
  dp[i] = (dp[i-1]+dp[i-2]) *a[i]
  
print(dp[-1]%mod)
Problem p03045 (python)

Fixed submission:
import numpy as np
import sys
sys.setrecursionlimit(10**5+1)
input = sys.stdin.readline

def dfs(v,G,visit):
    visit[v-1]=1    
    for next in G[v-1]:        
        if visit[next-1]:
            continue
        _ = dfs(next,G,visit) 
 
N, M =map(int, input().split())
G  = [[] for _ in range(N)]
for i in range(M):
    a,b ,_= map(int, input().split())
    G[a-1].append(b)
    G[b-1].append(a)
 
count = 0

visit = np.array([0]*N)
for i in range(1,N+1):
  if visit[i-1]:
    continue
  if G[i-1]:  
    _ = dfs(i,G,visit)
  else:
    visit[i-1] = 1
  count += 1

print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline

def dfs(v,G,visit):
    visit[v-1]=1    
    for next in G[v-1]:        
        if visit[next-1]:
            continue
        if dfs(next,G,visit) == True:
            return True  
 
N, M =map(int, input().split())
G  = [[] for _ in range(N)]
for i in range(M):
    a,b ,_= map(int, input().split())
    G[a-1].append(b)
    G[b-1].append(a)
 
count = 0

visit = np.array([0]*N)
for i in range(1,N+1):
  if visit[i-1]:
    continue
  if G[i-1]:  
    _ = dfs(i,G,visit)
  else:
    visit[i-1] = 1
  count += 1

print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline

def dfs(v,G,visit):
    visit[v-1]=1    
    for next in G[v-1]:        
        if visit[next-1]:
            continue
        if dfs(next,G,visit) == True:
            return True  
 
N, M =map(int, input().split())
G  = [[] for _ in range(N)]
for i in range(M):
    a,b ,_= map(int, input().split())
    G[a-1].append(b)
    G[b-1].append(a)
 
count = 0

visit = np.array([0]*N)
for i in range(1,N+1):
  if visit[i-1]:
    continue
  if G[i-1]:  
    _ = dfs(i,G,visit)
  else:
    visit[i-1] = 1
  count += 1

print(count)
Problem p03775 (python)

Fixed submission:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
    return divisors
 
N=int(input()) 
div = make_divisors(N)

A = div[-1]
B = N//A
print(max(len(str(A)),len(str(B))))

Buggy submission (verdict: Runtime Error):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
    return divisors
 
N=int(input()) 
div = make_divisors(N)

A = div[-1]
B = N//A
print(max(len(str(A)),len(str(B))))
Problem p03295 (python)

Fixed submission:
N, M = map(int, input().split())
islands = [tuple(map(int, input().split())) for _ in range(M)]
islands.sort()

cnt = 0
l = 1
r = N
for left, right in islands:
    if r <= left:
        cnt += 1
        l = left
        r = right
    else:
        l = max(l, left)
        r = min(r, right)

print(cnt+1)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
islands = [map(int, input().split()) for _ in range(M)]
islands.sort()

cnt = 0
last = -float('inf')
for left, right in islands:
    if last <= left:
        cnt += 1
        last = right

print(cnt)
Problem p02860 (python)

Fixed submission:
def main():
    n = int(input())
    s = input()
    if n % 2 == 0:
        s1 = s[:(n//2)]
        s2 = s[n//2:]
        if s1 == s2:
            print("Yes")
        else:
            print("No")
    else:
        print("No")



if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n = int(input())
    s = input()s
    if n % 2 == 0:
        s1 = s[:(n//2)]
        s2 = s[n//2:]
        if s1 == s2:
            print("Yes")
        else:
            print("No")
    else:
        print("No")



if __name__ == "__main__":
    main()
Problem p02862 (python)

Fixed submission:
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (10**6+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)
    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
        return
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
INF = float("inf") #const
MOD = 10**9+7 #const
MAX = 510000 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (n+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)

    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
        return
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
MOD = 10**9+7 #const

def repeat(n,p):
    if p == 0:
        return 1
    if p%2==0:
        t = repeat(n,p//2)
        return t * t % MOD
    return n * repeat(n,p-1) % MOD


def com(n,r):
    if n < r or n < 0:
        return 0
    if n == 0 and r == 0:
        return 1
    fact = [0] * (n+1)
    fact[0] = 1
    for i in range(n):
        fact[i+1] = fact[i] * (i+1) % MOD #階乗計算
    f_inv = repeat(fact[r],MOD-2)
    f = repeat(fact[n-r],MOD-2)

    return fact[n] * f_inv * f % MOD


def main():
    x,y = map(int,input().split())
    if (x+y)%3 != 0:
        print(0)
    n = (2*y - x)//3
    m = (2*x - y)//3
    print(com(n+m,n))


if __name__ == "__main__":
    main()
Problem p03013 (python)

Fixed submission:
INF = float("inf") #const

def main():
    n,m = map(int,input().split())
    issafe = [True]*n
    for i in range(m):
        a = int(input())
        issafe[a] = False
    dp = [0]*(n+1)
    dp[0],dp[1] = 1,1

    for i in range(2,n+1):
        if issafe[i-1]:
            dp[i] += dp[i-1]
        if issafe[i-2]:
            dp[i] += dp[i-2]

    print(dp[n]%(10**9+7))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
INF = float("inf") #const

def main():
    n,m = map(int,input().split())
    issafe = [0]*m
    for i in range(m):
        a = int(input())
        issafe[a] = False
    dp = [0]*(n+1)
    dp[0],dp[1] = 1,1

    for i in range(2,n+1):
        if issafe[i-1]:
            dp[i] += dp[i-1]
        if issafe[i-2]:
            dp[i] += dp[i-2]

    print(dp[n]%(10**9+7))


if __name__ == "__main__":
    main()
Problem p03127 (python)

Fixed submission:
import fractions

def test():
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    for i in a:
        ans = fractions.gcd(ans,i)
    print(ans)


if __name__ == "__main__":
    test()

Buggy submission (verdict: Runtime Error):
import math

def test():
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    for i in a:
        ans = math.gcd(ans,i)
    print(ans)


if __name__ == "__main__":
    test()

Buggy submission (verdict: Runtime Error):
import numpy as np

def test():
    n = int(input())
    a = np.array(list(map(int,input().split())))
    if all(x%a.min() == 0 for x in a):
        print(a.min())
    else:
        a = sorted(list(set(a//a.min())))
        print(a[1]-a[0])


if __name__ == "__main__":
    test()

Buggy submission (verdict: Runtime Error):
import numpy as np

def test():
    n = int(input())
    a = np.array(list(map(int,input().split())))
    if all(x%a.min() == 0 for x in a):
        print(a.min())
    else:
        a = sorted(list(set(a//a.min())))
        print(a[1]-a[0])


if __name__ == "__main__":
    test()
Problem p03805 (python)

Fixed submission:
import itertools

n, m = [int(x) for x in input().split()]
edges = set(tuple(int(x) for x in input().split()) for _ in range(m))
print(sum(1 if all(p in edges or tuple(reversed(p)) in edges for p in [(1, path[0])] + list(zip(path, path[1:]))) else 0 for path in itertools.permutations(range(2, n + 1))))

Buggy submission (verdict: Runtime Error):
import itertools

n, m = [int(x) for x in input().split()]
edges = set(tuple(int(x) for x in input().split()) for _ in range(m))
print(sum(1 if all(p in edges or tuple(reversed(p)) in edges for p in [(1, path[0]), *zip(path, path[1:])]) else 0 for path in itertools.permutations(range(2, n + 1))))
Problem p03652 (python)

Fixed submission:
def dfs(people, sports, use_sports, answer):
    rank = [0 for n in range(sports)]
    for p in range(people):
        for s in (preference[p]):
            if s in use_sports:
                rank[s] += 1
                break
            will_delete = []
    max_p = max(rank)
    exclude = rank.index(max_p)
    if len(use_sports) > 1:
        answer = min(answer, dfs(people, sports, use_sports - {exclude}, answer))
    answer = min(answer, max_p)
    return answer

people, sports = (int(n) for n in input().split(" "))
preference = []
for _ in range(people):
    pre = [int(n) - 1 for n in input().split(" ")]
    preference.append(pre)
answer = float("inf")
use_sports = {n for n in range(sports)}
print(dfs(people, sports, use_sports, answer))

Buggy submission (verdict: Runtime Error):
def dfs(people, sports, use_sports, answer):
    rank = [0 for n in range(sports)]
    for p in range(people):
        for s in (preference[p]):
            if s in use_sports:
                rank[s] += 1
                break
            will_delete = []
    max_p = max(rank)
    exclude = rank.index(max_p)
    answer = min(answer, max_p, dfs(people, sports, use_sports - {exclude}, answer))
    return answer

people, sports = (int(n) for n in input().split(" "))
preference = []
for _ in range(people):
    pre = [int(n) for n in input().split(" ")]
    preference.append(pre)
answer = float("inf")
use_sports = {n for n in range(sports)}
print(dfs(people, sports, use_sports, answer))
Problem p03805 (python)

Fixed submission:
from collections import defaultdict
vertices, edges = map(int, input().split(" "))
connect = defaultdict(set)
for i in range(edges):
    a, b = map(int, input().split(" "))
    connect[a] |= {b}
    connect[b] |= {a}

answer = 0
queue = [[set(), 1]]
while queue:
    visited, now = queue.pop()
    visited |= {now}
    # print(visited, now, need_visit)
    if len(visited) == vertices:
        answer += 1
    else:
        for conn in connect[now]:
            if conn not in visited:
                queue.append([visited | {conn}, conn])
        # print(visited, now, need_visit)

print(answer)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
vertices, edges = map(int, input().split(" "))
connect = defaultdict(set)
for i in range(vertices):
    a, b = map(int, input().split(" "))
    connect[a] |= {b}
    connect[b] |= {a}

answer = 0
queue = [[set(), 1]]
while queue:
    visited, now = queue.pop()
    visited |= {now}
    # print(visited, now, need_visit)
    if len(visited) == vertices:
        answer += 1
    else:
        for conn in connect[now]:
            if conn not in visited:
                queue.append([visited | {conn}, conn])
        # print(visited, now, need_visit)

print(answer)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
vertices, edges = map(int, input().split(" "))
connect = defaultdict(set)
for i in range(vertices):
    a, b = map(int, input().split(" "))
    connect[a] |= {b}
    connect[b] |= {a}

comb_answers = defaultdict(int)

def bfs(start, connect, visited):
    queue = [start]
    while queue:
        here = queue.pop()
        visited |= {here}
        for conn in connect[here]:
            if conn not in visited:
                visited |= {conn}
                queue.append(conn)
    return visited
    
for e in connect[1]:
    need_visit = bfs(e, connect, {1})
    temp_answer = 0
    queue = [[{1}, e]]
    while queue:
        visited, now = queue.pop()
        visited |= {now}
        # print(visited, now, need_visit)
        for conn in connect[now]:
            if conn not in visited:
                queue.append([visited | {conn}, conn])
        if visited == need_visit:
            for c in comb_answers.keys():
                if c in visited:
                    comb_answers[c] += 1
                    break
            else:
                comb_answers[e] += 1
            # print(visited, now, need_visit)
answer = 1
for v in comb_answers.values():
    answer *= v

print(answer)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
vertices, edges = map(int, input().split(" "))
connect = defaultdict(set)
for i in range(vertices):
    a, b = map(int, input().split(" "))
    connect[a] |= {b}
    connect[b] |= {a}

answer = 0
queue = [[set(), 1]]
while queue:
    visited, now = queue.pop()
    visited |= {now}
    if len(visited) == vertices:
        answer += 1
        continue
    for conn in connect[now]:
        if conn not in visited:
            queue.append([visited | {conn}, conn])
print(answer)
Problem p02879 (python)

Fixed submission:
ab = list(map(int, input().split()))
if ab[0] < 10 and ab[1] < 10:
    print(ab[0] * ab[1])
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())

for i in range(int(math.sqrt(n)), 0, -1):
    if n % i == 0:
        num = i
        break
        
ans = int(num -1 + (n / num) -1)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
ans = n
yakusuu = make_divisors(n)
for i in range(0 ,len(yakusuu), 2):
    kari = yakusuu[i] -1 + yakusuu[i+1]-1
    if (ans > kari):
        ans = kari
print(ans)
Problem p02881 (python)

Fixed submission:
import math
n = int(input())
num = math.sqrt(n)

l = []
for i in range(1,int(num+1)):
    if n % i == 0:
        l.append(i)
ans = int(n/max(l)) -1 + int(max(l)) - 1
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
r = int(math.sqrt(n))
num = [i for i in range(1, r) if n % i == 0]
num = max(num)
ans = int(num -1 + (n / num) -1)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
num = 1
for i in range(1, int(np.sqrt(n))):
    if n % i == 0:
        num = i
ans = int(num -1 + (n / num) -1)
print(ans)
Problem p02935 (python)

Fixed submission:
n = int(input())
vn = list(map(int, input().split()))

vn.sort()
sumV = vn[0]

for v in vn[1:]:
    sumV = (sumV + v)/2
print(sumV)

Buggy submission (verdict: Runtime Error):
n = int(input())
vn = list(map(int, input().split())).sort()

sumV = vn[0]

for v in vn[1:]:
    sumV = (sumV + v)/2
print(sumV)
Problem p03012 (python)

Fixed submission:
import math
 
n = int(input())
wn = list(map(int, input().split()))
 
mini = 10000000000
for i in range(n-1):
    new_mini = abs(sum(wn[:i+1]) -sum(wn[i+1:]))
    if new_mini < mini:
        mini = new_mini
print(mini)

Buggy submission (verdict: Runtime Error):
import math

n = int(input())
wn = list(map(int, input().split()))
 
mini = math.inf
for i in range(n-1):
    new_mini = abs(sum(wn[:i+1]) -sum(wn[i+1:]))
    if new_mini < mini:
        mini = new_mini
print(mini)

Buggy submission (verdict: Runtime Error):
n = int(input())
wn = list(map(int, input().split()))


import math
mini = math.inf
for i in range(n-1):
    new_mini = abs(sum(wn[:i+1]) -sum(wn[i+1:]))
    if new_mini < mini:
        mini = new_mini
print(mini)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
wn = list(map(int, input().split()))
 
    
mini = math.inf
for i in range(n-1):
    new_mini = abs(sum(wn[:i]) -sum(wn[i:]))
    if new_mini < mini:
        mini = new_mini
print(mini)

Buggy submission (verdict: Runtime Error):
import math
n = int(input())
wn = list(map(int, input().split()))


mini = math.inf
for i in range(n-1):
    new_mini = abs(sum(wn[:i]) -sum(wn[i:]))
    if new_mini < mini:
        mini = new_mini
print(mini)
Problem p03208 (python)

Fixed submission:
NK = input()
NK = NK.split(" ")
N = int(NK[0])
K = int(NK[1])


h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

for i in range(N-K+1):
  ans = min(ans, h[i+K-1] - h[i])
print(ans)

Buggy submission (verdict: Runtime Error):
NK = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])

h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

for i in range(N-K+1):
  ans = min(ans, h[i+K-1] - h[i])
print(ans)

Buggy submission (verdict: Runtime Error):
NK = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])


h = []
for i in range(N):
  h.append(int(input()))
  
  
h.sort()
ans = h[-1] - h[0]

for i in range(N-K+1):
  ans = min(ans, h[i+K-1] - h[i])
print(ans)

Buggy submission (verdict: Runtime Error):
NK = input()
NK = N.split(" ")
N = int(NK[0])
K = int(NK[1])

h = []
for i in range(N):
  h.append(int(input()))
    
h.sort()
ans = h[-1] - h[0]

for i in range(N-K+1):
  ans = min(ans, h[i-K+1] - h[i])
print(ans)
Problem p02955 (python)

Fixed submission:
n, k = map(int, input().split())
arr = list(map(int, input().split()))

# n, k = 8, 7
# arr = list(map(int, "1 7 5 6 8 2 6 5".split()))

add = sum(arr)

def check(factor):
	mod_factor = [x%factor for x in arr]
	mod_factor.sort(reverse = True)
	p = sum(mod_factor)//factor
	# print('p: ', p, 'factor:',factor, 'sum: ', sum(mod_factor))
	# print('mod_factor: ', mod_factor)
	# print(mod_factor[:p])
	c = sum(factor - mod_factor[i] for i in range(p))
	return c <= k

ans = i = 1
while i*i <= add:
	if add % i == 0:
		if check(i):
			ans = max(ans, i)
		if check(add//i):
			ans = max(ans, add//i)
	i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
arr = list(map(int, input().split()))

# n, k = 4, 5
# arr = list(map(int, "10 1 2 22".split()))

add = sum(arr)

def check(factor):
	mod_factor = [x%factor for x in arr]
	left, right = 0, n-1
	reqd, rem = 0, 0
	mod_factor.sort()
	counter = 0
	while left <= right:
		reqd = factor - mod_factor[right]
		while mod_factor[right]% factor != 0:
			if reqd < mod_factor[left]:
				mod_factor[left] -= reqd
				mod_factor[right] = 0
				counter += reqd
			else:
				mod_factor[right] -= mod_factor[left]
				reqd -= mod_factor[left]
				counter += mod_factor[left]
				left += 1
		right -= 1
	return countera <= k

ans = i = 1
while i*i <= add:
	if add % i == 0:
		if check(i):
			ans = max(ans, i)
		if check(add//i):
			ans = max(ans, add//i)
	i += 1
print(ans)
Problem p02990 (python)

Fixed submission:
n, k = map(int, input().split())
reds = n-k
blues = k

mod = pow(10, 9) + 7

maxn = 2000
C = [[0]*(maxn+1) for i in range(maxn+1)]

def preprocess():
	global C
	for i in range(maxn+1):
		for j in range(i+1):
			if i == 0 or j== i :
				C[i][j] = 1
			else:
				C[i][j] = (C[i-1][j-1] + C[i-1][j])%mod
preprocess()


for i in range(k):
	slots = reds + 1
	res = (C[slots][i+1]*C[blues - 1][i])%mod
	print(res)

Buggy submission (verdict: Runtime Error):
mod = pow(10, 9)+7

n, k = map(int, input().split())
blues = k
reds = n-k

C = [[0]*2000 for i in range(2000)]

def preprocess():
	global C

	for i in range(2000):
		for j in range(i+1):
			if i==j or j==0:
				C[i][j] = 1
			else:
				C[i][j] = (C[i-1][j-1] + C[i-1][j])%mod
preprocess()

for i in range(k):
	slots = reds + 1
	res = (C[slots][i+1]*C[k-1][i])%mod
	print(res)
Problem p02851 (python)

Fixed submission:

from collections import deque
from collections import defaultdict


def p_e():
    n, k = map(int, input().split())
    a = [0] + list(map(int, input().split()))
    for i in range(n):
        a[i + 1] = (a[i + 1] + a[i] - 1) % k
    d = defaultdict(int)
    d[0] = 1
    q = deque()
    ans = 0
    for i in range(1, n + 1):
        if i - k >= 0:
            d[a[i - k]] -= 1
        ans += d[a[i]]
        d[a[i]] += 1
    print(ans)
    
p_e()

Buggy submission (verdict: Runtime Error):
from collections import deque


def p_e():
    n, k = map(int, input().split())
    *a, = map(int, input().split())
    s = [0] * (n + 1)
    for i in range(n):
        s[i + 1] = (s[i] + a[i] - 1) % k
    mp = [0] * k
    q = deque()
    ans = 0
    for i in range(n + 1):
        ans += mp[s[i]]
        mp[s[i]] += 1
        q.append(s[i])
        if len(q) == k:
            mp[q.popleft()] -= 1
    print(ans)
    
p_e()

Buggy submission (verdict: Runtime Error):
from collections import deque


def p_e():
    n, k = map(int, input().split())
    *a, = map(int, input().split())
    s = [0] * (n + 1)
    for i in range(n):
        s[i + 1] = (s[i] + a[i] - 1) % k
    mp = [0] * k
    q = deque()
    ans = 0
    for i in range(n + 1):
        ans += mp[s[i]]
        mp[s[i]] += 1
        q.append(s[i])
        if len(q) == k:
            mp[q.popleft()] -= 1
    print(ans)
    
p_e()