Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#Union Find
import sys
input = sys.stdin.readline
 
n,m = map(int,input().split())

#根なら-size,子なら親の頂点
par = [-1]*n

#xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x != y:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

def size(x):
    return -par[find(x)]


edge = [tuple(map(int,input().split())) for i in range(m)]
edge = edge[::-1]
for i in range(m):
    edge[i] = (edge[i][0]-1,edge[i][1]-1)

res = []
for i in range(m):
    fi = find(edge[i][0])
    se = find(edge[i][1])
    if fi == se:
        res.append(0)
    else:
        res.append(size(fi)*size)
        unite(fi,se)
ass = 0
for i in range(m):
    ass += res[m-1-i]
    print(ass)

Fixed submission:
import sys
input = sys.stdin.readline

#木の根を求める
def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x != y:
        #xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
            size[y] += size[x]
        else:
            par[y] = x
            size[x] += size[y]
            if rank[x]==rank[y]:
                rank[x] += 1

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

########################################
#初期化
n,m = map(int,input().split())

par = [0]*n #親
for i in range(n):
    par[i] = i
rank = [1]*n #深さ
size = [1]*n #size[i]:iを根とするグループのサイズ
edge2 = [[0] for i in range(m)]
for i in range(m):
    edge2[i] = list(map(int,input().split()))

edge = [[0] for i in range(m)]
for i in range(m):
    edge[i] = [edge2[m-1-i][0]-1,edge2[m-1-i][1]-1]
res = []
for i in range(m):
    fi = find(edge[i][0])
    se = find(edge[i][1])
    if fi == se:
        res.append(0)
    else:
        res.append(size[fi]*size[se])
        unite(fi,se)
ass = 0
for i in range(m):
    ass += res[m-1-i]
    print(ass)
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
s = [None]*h
for i in range(h):
    s[i]=list(input())

res = 0
ans = [[0]*w for i in range(h)]


def f(x,y):
    c = 0
    if x+1 < h and s[x+1][y] =="#" and ans[x+1][y] == 0:
        ans[x+1][y] = 1
        c += 1
        if x+2 < h and s[x+2][y] == ".":
            c += f(x+2,y)
        if y+1 < w and s[x+1][y+1] == ".":
            c += f(x+1,y+1)
    if y+1 < w and s[x][y+1] == "#" and ans[x][y+1] == 0:
        ans[x][y+1] = 1
        c += 1
        if x+1 <h and s[x+1][y+1] == ".":
            c += f(x+1,y+1)
        if y+2 < w and s[x][y+2] == ".":
            c += f(x,y+2)
    return c

def g(x,y):
    c = 0
    if x+1 < h and s[x+1][y] =="." and ans[x+1][y] == 0:
        ans[x+1][y] = 1
        c += 1
        if x+2 < h and s[x+2][y] == "#":
            c += g(x+2,y)
        if y+1 < w and s[x+1][y+1] == "#":
            c += g(x+2,y)
    if y+1 < w and s[x][y+1] == "." and ans[x][y+1] == 0:
        ans[x][y+1] = 1
        c += 1
        if x+1 <h and s[x+1][y+1] == "#":
            c += g(x+1,y+1)
        if y+2 < w and s[x][y+2] == "#":
            c += g(x,y+2)
    return c
res = 0
for i in range(h):
    for j in range(w):
        ans = [[0]*w for i in range(h)]
        if s[i][j] == ".":
            #print(f(i,j))
            res += f(i,j)
        else:
            #print(g(i,j))
            res += g(i,j)
            

print(res)

Fixed submission:
h,w = map(int,input().split())
s = [None]*h
for i in range(h):
    s[i]=list(input())
    
###########
#Union Find
par = [] #親
rank = [] #木の深さ

#初期化
for i in range(h*w):
    #par[i]:i rank[i]:0
    par.append(i)
    rank.append(0)

#木の根を求める
def find(x,par):
    if par[x] == x:
        return x
    else:
        return find(par[x],par)

#xとyの属する集合の併合
def unite(x,y,par,rank):
    x = find(x,par)
    y = find(y,par)
    
    if x != y:
        #xとyの属している集合が異なる時
        if rank[x] < rank[y]:
            par[x] = y
        else:
            par[y] = x
            if rank[x]==rank[y]:
                rank[x] += 1

#xとyが同じ集合に属するかの判定
def same(x,y,par):
    return find(x,par) == find(y,par)
###############
for i in range(h*w):
    if i//w + 1 < h and s[i//w][i%w] != s[i//w+1][i%w]:
        unite(i,i+w,par,rank)
    if i%w +1 < w and s[i//w][i%w] != s[i//w][i%w+1]:
        unite(i,i+1,par,rank)

res = [[0,0] for i in range(w*h)] #[".","#"]
for i in range(h*w):
    r = find(i,par)
    if s[i//w][i%w] ==".":
        res[r][0]+=1
    else:
        res[r][1]+=1

ans = 0
for i in range(h*w):
    ans += res[i][0]*res[i][1]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0]*(w+1)
for i in range(n):
    for j in range(w,wv[i][0]-1,-1):
        dp[j] = max(dp[j],dp[j-wv[i][0]]+wv[i][1])

print(max(dp))

Fixed submission:
import sys
input = sys.stdin.readline
n,w = map(int,input().split())
wv = [tuple(map(int,input().split())) for i in range(n)]

dp = [0]*(w+1)
for i in range(n):
    for j in range(w,wv[i][0]-1,-1):
        dp[j] = max(dp[j],dp[j-wv[i][0]]+wv[i][1])

print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
s = tuple(input())
t = tuple(input())
n = len(s)
m = len(t)

dp = [['']*m for i in range(n)]
if s[0] == t[0]:
    dp[0][0] = s[0]

for i in range(1,m):
    if s[0] == t[i]:
        dp[0][i] = s[0]
    else:
        dp[0][i] = dp[0][i-1]
for i in range(1,n):
    if t[0] == s[i]:
        dp[i][0] = t[0]
    else:
        dp[i][0] = dp[i-1][0]

for i in range(1,n):
    for j in range(1,m):
        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1] + s[i]
        else:
            if len(dp[i-1][j]) > len(dp[i][j-1]):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = dp[i][j-1]
print(dp[-1][-1])

Fixed submission:
s = tuple(input())
t = tuple(input())
n = len(s)
m = len(t)

dp = [[0]*(m+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1]  + 1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

res = ''
while n != 0 and m != 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        n -= 1
        m -= 1
        res = s[n] + res
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
t = list(input())
n = len(s)
m = len(t)

dp = [['']*m for i in range(n)]
if s[0] == t[0]:
    dp[0][0] = s[0]

for i in range(1,m):
    if s[0] == t[i]:
        dp[0][i] = s[0]
    else:
        dp[0][i] = dp[0][i-1]
for i in range(1,n):
    if t[0] == s[i]:
        dp[i][0] = t[0]
    else:
        dp[i][0] = dp[i-1][0]

for i in range(1,n):
    for j in range(1,m):
        if s[i] == t[j]:
            dp[i][j] = dp[i-1][j-1] + s[i]
        else:
            if len(dp[i-1][j]) > len(dp[i][j-1]):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = dp[i][j-1]
print(dp[-1][-1])

Fixed submission:
s = tuple(input())
t = tuple(input())
n = len(s)
m = len(t)

dp = [[0]*(m+1) for i in range(n+1)]

for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1]  + 1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

res = ''
while n != 0 and m != 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        n -= 1
        m -= 1
        res = s[n] + res
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys,bisect
input = sys.stdin.readline
n = int(input())
p = tuple(map(float,input().split()))

dp = [[0.0]*(n+1) for i in range(n+1)]
dp[0][0] = 1.0
for i in range(1,n+1):
    for j in range(i+1):
        dp[i][j] = dp[i-1][j]*(1-p[i-1])
        if j > 0:
            dp[i][j] += dp[i-1][j-1]*p[i-1]

res = 0.0
for i in range((n+1)//2,n+1):
    res += dp[-1][i]
print(res)

Fixed submission:
import sys,bisect
input = sys.stdin.readline
n = int(input())
p = tuple(map(float,input().split()))

dp = [[0.0]*(n+1) for i in range(n+1)]
dp[0][0] = 1.0
for i in range(1,n+1):
    for j in range(i+1):
        dp[i][j] = dp[i-1][j]*(1-p[i-1])
        if j > 0:
            dp[i][j] += dp[i-1][j-1]*p[i-1]

res = 0.0
for i in range((n+1)//2,n+1):
    res += dp[-1][i]
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = tuple(map(int,input().split()))
mod =10**9+7

#dp[i][j]:0~iまでの子がj個分け合う場合の数
dp = [[0]*(k+1) for i in range(n)]
#b[q+1]-b[p] = dp[x][p]+...+dp[x][q]
b = [0]*(k+2)

for i in range(k+1):
    if i <= a[0]:
        dp[0][i] = 1
    b[i+1] = b[i]+dp[0][i] 

for i in range(1,n):
    for j in range(k+1):
        dp[i][j] = b[j+1]-b[max(0,j-a[i])]
    #bの更新
    b[0] = 0
    for j in range(k+1):
        b[j+1] = b[j]+dp[i][j]
        dp[i][j] = dp[i][j]%mod
print(dp[-1][-1])

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = tuple(map(int,input().split()))
mod =10**9+7

#dp[i][j]:0~iまでの子がj個分け合う場合の数
dp = [[0]*(k+1) for i in range(n)]
#b[q+1]-b[p] = dp[x][p]+...+dp[x][q]
b = [0]*(k+2)

for i in range(k+1):
    if i <= a[0]:
        dp[0][i] = 1
    b[i+1] = b[i]+dp[0][i] 

for i in range(1,n):
    for j in range(k+1):
        dp[i][j] = (b[j+1]-b[max(0,j-a[i])])%mod
    #bの更新
    b[0] = 0
    for j in range(k+1):
        b[j+1] = (b[j]+dp[i][j])%mod
        dp[i][j] = dp[i][j]%mod
print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(i,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(31):
    p = res + 2**(30-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

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

b = sum(a)/n
for i in range(n):
    a[i] = abs(a[i]-b)

k = a.index(min(a))
print(k)

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

b = []
for i in range(n):
    r = 0
    for j in range(n-i):
        r += a[i+j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

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

b = sum(a)/n
for i in range(n):
    a[i] = abs(a[i]-b)

k = a.index(min(a))
print(k)
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    import sys
    input = sys.stdin.readline

    n = int(input())
    s = input()
    _q = int(input())
    
    for k in map(int,input().split()):
        res = 0
        p = 0
        cnt = 0
        q = 0
        for i in range(n):
            if i >= k:
                if s[i-k] == 'D':
                    cnt -= 1
                    p -= q
                elif s[i-k] == 'M':
                    q -= 1

            if s[i] == 'D':
                cnt += 1
            elif s[i] == 'M':
                p += cnt
                q += 1
            elif s[i] == 'C':
                res += p
        print(res)

if __name__ == '__main__':
    main()

Fixed submission:
def main():
    import sys,bisect
    input = sys.stdin.readline

    n = int(input())
    s = input()
    q = int(input())
    k_list = tuple(map(int,input().split()))
    
    for k in k_list:
        res = 0
        p = 0
        cnt = 0
        q = 0
        for i in range(n):
            if i >= k:
                if s[i-k] == 'D':
                    cnt -= 1
                    p -= q
                elif s[i-k] == 'M':
                    q -= 1

            if s[i] == 'D':
                cnt += 1
            elif s[i] == 'M':
                p += cnt
                q += 1
            elif s[i] == 'C':
                res += p
        print(res)



if __name__ == '__main__':
    main()
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,m = map(int,input().split())	
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

r = primes(m+1)
if m in r:
    print(1)
else:
    while n <= m:
        if m % n == 0:
            break
        n += 1

    print(m//n)

Fixed submission:
import math
n,m = map(int,input().split())	
r = m
k = 0
a = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
for i in range(len(a)):
    if m%a[i] == 0 and m >= a[i]:
        r = m//a[i]
        break
if r == m and m >= 199:
    r = m//199
if n > r:
    k = 1

while n <= r :
    if m % n == 0:
        break
    n += 1
if n == r + 1 or k == 1:
    print(1)
else:
    print(m//n)

Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())	

while n <= m:
    if m % n == 0:
        break
    n += 1

print(m//n)

Fixed submission:
import math
n,m = map(int,input().split())	
r = m
k = 0
a = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
for i in range(len(a)):
    if m%a[i] == 0 and m >= a[i]:
        r = m//a[i]
        break
if r == m and m >= 199:
    r = m//199
if n > r:
    k = 1

while n <= r :
    if m % n == 0:
        break
    n += 1
if n == r + 1 or k == 1:
    print(1)
else:
    print(m//n)
Buggy python submission (verdict: Runtime Error):
import functools
import math
import fraction
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
gcd = functools.reduce(fraction.gcd, values)
print(gcd)

Fixed submission:

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
ass = values[0]
for i in range(n):
    ass = gcd(ass,values[i])
print(ass)

Buggy python submission (verdict: Runtime Error):
import functools
import math
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
gcd = functools.reduce(math.gcd, values)
print(gcd)

Fixed submission:

def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a
n,x = map(int,input().split())
values = list(map(int,input().split()))
for i in range(n):
    values[i] = abs(values[i]-x)
ass = values[0]
for i in range(n):
    ass = gcd(ass,values[i])
print(ass)
Buggy python submission (verdict: Runtime Error):
# cook your dish here
import bisect 
n,k = map(int,input().split())
x = list(map(int,input().split()))

w  = x.count(0)
for i in range(w):
    x.remove(0)

if k <= w:
    print(0)
else:
    k = k -w
    #print(x)

    r = bisect.bisect_left(x,0)
    
    if x[-1]<0:
        print(abs(x[len(x)-k]))
    elif x[0] > 0:
        print(x[k-1])    
    else:
        ass = 10 ** 10
        for i in range(r,min(len(x),r + k )):
            if i-r+1 >= k:
                ans = abs(x[i])
            
            else:
                if i - k + 1 >= 0:
                    ans = x[i] + abs(x[i-k+1]) + min(x[i],abs(x[i-k+1]))
            ass = min(ass,ans)
        if r-k >= 0:
            ans = abs(x[r-k])
        ass = min(ass,ans)
        print(ass)

Fixed submission:
# cook your dish here
import bisect 
n,k = map(int,input().split())
x = list(map(int,input().split()))

w  = x.count(0)
for i in range(w):
    x.remove(0)

if k <= w:
    print(0)
else:
    k = k -w
    #print(x)

    r = bisect.bisect_left(x,0)
    
    if x[-1]<0:
        print(abs(x[len(x)-k]))
    elif x[0] > 0:
        print(x[k-1])    
    else:
        ass = 10 ** 10
        ans = 10**10
        for i in range(r,min(len(x),r + k )):
            if i-r+1 >= k:
                ans = abs(x[i])
            
            else:
                if i - k + 1 >= 0:
                    ans = x[i] + abs(x[i-k+1]) + min(x[i],abs(x[i-k+1]))
            ass = min(ass,ans)
        if r-k >= 0:
            ans = abs(x[r-k])
        ass = min(ass,ans)
        print(ass)
Buggy python submission (verdict: Runtime Error):
a=int(input())
b=int(input())

print((a-1)*(b-1))

Fixed submission:
x,y = map(int,input().split())
print((x-1)*(y-1))
Buggy python submission (verdict: Runtime Error):
s=list(input())
k=int(input())

a = 0
while s[a] == '1':
    a += 1

if k <= a:
    print('1')
else:
    print(s[a])

Fixed submission:
s=list(input())
k=int(input())

a = 0
while s[a] == '1':
    a += 1
    if a >= len(s):
        break

if k <= a:
    print('1')
else:
    if a >= len(s):
        print('1')
    else:
        print(s[a])
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
n,m,q = map(int,input().split())
lr = []
for i in range(m):
    l = list(map(int,input().split()))	
    lr.append(l)
 
ass = np.zeros((n,n))
ans = np.zeros((n,n))   
        
for i in range(m):
    ass[lr[i][0]-1][lr[i][1]-1] += 1
        
#print(ass)

for i in range(n):
    for j in range(n):
        if i == 0:
            ans[n-1][j] = sum(ass[n-1][:j+1:])
        else:
            ans[n-1-i][j] = sum(ass[n-1-i][:j+1:]) + ans[n-i][j]
#print(ass)
#print(ans)

for i in range(q):
    p,qa = map(int,input().split())
   
    print(int(ans[p-1][qa-1]))

Fixed submission:
import sys
input = sys.stdin.readline
n,m,q = map(int,input().split())

res = [[0]*n for i in range(n)]
for i in range(m):
    L,r = map(int,input().split())
    L -= 1
    r -= 1
    res[r][0] += 1
    if L != n-1:
        res[r][L+1] -= 1

for i in range(n):
    for j in range(1,n):
        res[i][j] += res[i][j-1]
for i in range(n):
    for j in range(1,n):
        res[j][i] += res[j-1][i]
for i in range(q):
    p,q = map(int,input().split())
    print(res[q-1][p-1])

Buggy python submission (verdict: Time Limit Exceeded):
# cook your dish here
import numpy as np
n,m,q = map(int,input().split())
lr = []
for i in range(m):
    l = list(map(int,input().split()))	
    lr.append(l)
 
ass = np.zeros((n,n))
        
        
for i in range(m):
    ass[lr[i][0]-1][lr[i][1]-1] += 1
        
#print(ass)
 
for i in range(q):
    p,qa = map(int,input().split())
    ans = 0
    for i in range(p-1,qa):
        ans += sum(ass[i][:qa:])
    print(int(ans))

Fixed submission:
import sys
input = sys.stdin.readline
n,m,q = map(int,input().split())

res = [[0]*n for i in range(n)]
for i in range(m):
    L,r = map(int,input().split())
    L -= 1
    r -= 1
    res[r][0] += 1
    if L != n-1:
        res[r][L+1] -= 1

for i in range(n):
    for j in range(1,n):
        res[i][j] += res[i][j-1]
for i in range(n):
    for j in range(1,n):
        res[j][i] += res[j-1][i]
for i in range(q):
    p,q = map(int,input().split())
    print(res[q-1][p-1])

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import bisect
n,m,q = map(int,input().split())
lr = []
s = []
for i in range(m):
    l = list(map(int,input().split()))	
    lr.append(l)
    s.append(l[0])
lr.sort()
s.sort()

ass = np.zeros((n,n))
#print(ass)
#print(lr)

for i in range(n):
    k = bisect.bisect_left(s,i+1)
    
    for j in range(k,m):
        ass[i][lr[j][1]-1]+=1
        
#print(ass)

for i in range(q):
    p,qa = map(int,input().split())
    ans = sum(ass[p-1][:qa:])
    print(int(ans))

Fixed submission:
import sys
input = sys.stdin.readline
n,m,q = map(int,input().split())

res = [[0]*n for i in range(n)]
for i in range(m):
    L,r = map(int,input().split())
    L -= 1
    r -= 1
    res[r][0] += 1
    if L != n-1:
        res[r][L+1] -= 1

for i in range(n):
    for j in range(1,n):
        res[i][j] += res[i][j-1]
for i in range(n):
    for j in range(1,n):
        res[j][i] += res[j-1][i]
for i in range(q):
    p,q = map(int,input().split())
    print(res[q-1][p-1])
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,m = map(int,input().split())
a = list(map(int,input().split()))

s = []
k = 0
for i in range(0,n):
    k += a[i]
    s.append(k)

for i in range(0,n):
    s[i] = s[i]%m

d = [0]
ass = 0
w = s.count(0)
ass += w*(w+1)//2

for i in range(0,n):
    if s[i] not in d:
        d.append(s[i])
        w = s.count(s[i])
        if w != 1:
            ass += w*(w-1)//2

print(ass)

Fixed submission:
import bisect
n,m = map(int,input().split())
a = list(map(int,input().split()))

s = []
k = 0
for i in range(0,n):
    k += a[i]
    s.append(k%m)

ass = 0
w = s.count(0)
ass += w*(w+1)//2
s.sort()

hj = w
while hj <= n-1:
    jkl = bisect.bisect_right(s,s[hj])
    w = jkl - hj
    if w != 1:
        ass += w*(w-1)//2
    hj = jkl
print(ass)
Buggy python submission (verdict: Runtime Error):
s=list(input())
c = 0
if s[0] == 'A':
    c += 1
if s[2:len(s)-1:].count('C') == 1:
    c += 1
    s.remove('A')
    s.remove('C')
a = 'a'
for i in range(len(s)):
    a += s[i]
if a.islower():
    c += 1

if c == 3:
    print('AC')
else:
    print('WA')

Fixed submission:
# cook your dish here
s=list(input())
c = 0
if s[0] == 'A':
    c += 1
if s[2:len(s)-1:].count('C') == 1:
    c += 1

    s.remove('C')
if 'A' in s:
    s.remove('A')
a = 'a'
for i in range(len(s)):
    a += s[i]
if a.islower():
    c += 1
 
if c == 3:
    print('AC')
else:
    print('WA')