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

Fixed submission:
*D, = open(0)
n = int(D[0])

edge = [[] for _ in range(n+1)]
v_val = [0 for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a)
c = list(map(int, D[n].split()))
c = sorted(c, reverse=True)

from collections import deque
visited = [False for _ in range(len(edge))]
start = 1
que = deque()
que.append(start)
order = []
order.append(start)
visited[start] = True

while que:
    node = que.popleft()
    for it in edge[node]:
        if not visited[it]:
            order.append(it)
            visited[it] = True
            que.append(it)
# calculate cost
v_val = [0 for _ in range(len(c)+1)]
for i, it in enumerate(order):
    v_val[it] = c[i]

print(sum(c[1:]))
print(' '.join(map(str, v_val[1:])))

Buggy submission (verdict: Runtime Error):
*D, = open(0)
n = int(D[0])

edge = [[] for _ in range(n+1)]
v_val = [0 for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a)
c = list(map(int, D[n].split()))
c = sorted(c, reverse=True)

from collections import deque
visited = [False for _ in range(len(edge))]
start = 1
que = deque()
que.append(start)
order.append(start)
visited[start] = True
order = []

while que:
    node = que.popleft()
    for it in edge[node]:
        if not visited[it]:
            order.append(it)
            visited[it] = True
            que.append(it)
# calculate cost
v_val = [0 for _ in range(len(c)+1)]
for i in order:
    v_val[i] = c[i-1]

print(sum(c[1:]))
print(' '.join(map(str, v_val[1:])))

Buggy submission (verdict: Runtime Error):
*D, = open(0)
n = int(D[0])

edge = [[] for _ in range(n+1)]
v_val = [0 for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b = map(int, D[i].split())
    edge[a].append(b)
    edge[b].append(a)
c = list(map(int, D[n].split()))
c = sorted(c, reverse=True)

from collections import deque
visited = [False for _ in range(len(edge))]
start = 1
que = deque()
que.append(start)
order.append(node)
visited[node] = True
order = []

while que:
    node = que.popleft()
    for it in edge[node]:
        if not visited[it]:
            order.append(it)
            visited[it] = True
            que.append(it)
# calculate cost
v_val = [0 for _ in range(len(c)+1)]
for i in order:
    v_val[i] = c[i-1]

print(sum(c[1:]))
print(' '.join(map(str, v_val[1:])))
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)
 
*D, = open(0)
n = int(D[0])
 
v = [[] for _ in range(n+1)]
 
dist = {}
 
for i in range(1, n):
    a, b, d = map(int, D[i].split())
    v[a].append(b)
    v[b].append(a)
    dist[(a,b)]=d
    dist[(b,a)]=d
 
def visit(current, v, dist, color):
   
    for it in v[current]:
        if color[it] != None:
            continue
        if dist[(it, current)]%2 == 0:
            color[it] = color[current]
        else:
            color[it] = not color[current]
        visit(it, v, dist, color)
        
color = [None for _ in range(n+1)]
color[1]=True
visit(1, v, dist, color)
 
for i in range(1, n+1):
    if color[i]:
        print('0')
    else:
        print('1')

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(15000)

*D, = open(0)
n = int(D[0])
 
v = [[] for _ in range(n+1)]
 
dist = {}
 
for i in range(1, n):
    a, b, d = map(int, D[i].split())
    v[a].append(b)
    v[b].append(a)
    dist[(a,b)]=d
    dist[(b,a)]=d
 
def visit(current, v, dist, color):
   
    for it in v[current]:
        if color[it] != None:
            continue
        if dist[(it, current)]%2 == 0:
            color[it] = color[current]
        else:
            color[it] = not color[current]
        visit(it, v, dist, color)
        
color = [None for _ in range(n+1)]
color[1]=True
visit(1, v, dist, color)
 
for i in range(1, n+1):
    if color[i]:
        print('0')
    else:
        print('1')

Buggy submission (verdict: Runtime Error):
*D, = open(0)
n = int(D[0])

v = [[] for _ in range(n+1)]

dist = {}

for i in range(1, n):
    a, b, d = map(int, D[i].split())
    v[a].append(b)
    v[b].append(a)
    dist[(a,b)]=d
    dist[(b,a)]=d

def visit(current, v, dist, color):
   
    for it in v[current]:
        if color[it] != None:
            continue
        if dist[(it, current)]%2 == 0:
            color[it] = color[current]
        else:
            color[it] = not color[current]
        visit(it, v, dist, color)
        
color = [None for _ in range(n+1)]
color[1]=True
visit(1, v, dist, color)

for i in range(1, n+1):
    if color[i]:
        print('0')
    else:
        print('1')
Problem p03050 (python)

Fixed submission:
N = int(input())
val = []
max_len = [2,4]
def comb(val, max_len, depth=0):
    if depth==len(max_len):
        yield val
        return 

    for i in range(max_len[depth]+1):
        yield from comb(val+[i], max_len, depth+1)
# for it in comb(val, max_len):
# #     print('a')
#     print(it)


import math
def primeFactor(num):
    prime = {}
    x = 2
    MAX =  math.sqrt(num)+1
    while x <MAX:
        if num%x==0:
            if x in prime:
                prime[x] += 1
            else:
                prime[x]=1
            num //= x
        else:
            x += 1
    if num != 1:
        prime[num]=1
    return prime

divisor = primeFactor(N)


ans = 0
val = []
for it in comb(val, list(divisor.values())):
    total = 1
    for i, j in zip(list(divisor.keys()), it):
    #     print(i, j)
        total *= i**j
#     print(total)
    
    m = total - 1
    if m < 1:
        continue
    if N%m==N//m:
#         print('{0} mod {1} = {2}, {0}/{1} = {3}'.format(N, m, N%m, N//m))
        ans += m
        
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())

import math
i=0
prime = []
while 2**i<math.sqrt(N):
    j = 0
    while 2**i*5**j < math.sqrt(N):
        prime.append(2**i*5**j)
        j += 1
    i += 1
prime = sorted(prime)

cnt = 0
ret = []
m = N//(prime[cnt])
while m>0:
    if N//m==N%m:
        ret.append(m)
#         print(m,N//m, N%m)
        cnt += 1
        if len(prime) > cnt:
            while N//(prime[cnt]) > m:
                cnt += 1
            m = N//(prime[cnt])-1
#             print(m)
        else:
            m = 0
    else:
        m-=1
        
sum(ret)
Problem p03062 (python)

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

cnt = 0
min_val = abs(a[0])
for it in a:
    if abs(it) < min_val:
        min_val = abs(it)
    
    if it < 0:
        cnt+=1
        
abs_list = list(map(abs, a))
if cnt%2 == 0:
    print(sum(abs_list))
else:
    print(sum(abs_list) - 2*min_val)

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

ret = 0
for i in range(len(a)-1):
    if a[i] < 0:
        a[i] *= -1
        a[i+1] *= -1
    ret += a[i]
    print(a[i], ret)
ret += a[-1]

abs_list = list(map(abs, a))
test = sorted(enumerate(abs_list), key=lambda x:x[1])
print(max(solve(a), solve(a[::-1]), solve(a[::-1], test[0][0]), solve(a[::-1], test[1][0])))
Problem p03074 (python)

Fixed submission:
n, k = list(map(int, input().split()))
s = input()
 
data = []
cnt = 0
curr = '1'
for i in range(len(s)):
    if s[i] != curr:
        data.append(cnt)
        curr = s[i]
        cnt = 1
    else:
        cnt += 1
data.append(cnt)
data.append(0)
data.append(0)
 
current_sum = sum(data[0:0 + 2*k+1])
ret = current_sum
for start in range(2, len(data)-k-2, 2):
    if start + 2*k >= len(data):
        break
    diff = -data[start-2]-data[start-1]+data[start + 2*k]+data[start + 2*k-1]
    current_sum += diff
 
#     print(start, val)
    if current_sum > ret:
        ret = current_sum
print(ret)

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

data = []
cnt = 0
curr = '1'
for i in range(len(s)):
    if s[i] != curr:
        data.append(cnt)
        curr = s[i]
        cnt = 1
    else:
        cnt += 1
data.append(cnt)
data.append(0)

current_sum = sum(data[0:0 + 2*k+1])
ret = current_sum
for start in range(2, len(data), 2):
    if (start + 2*k-1) < len(data): 
        diff = -data[start-2]-data[start-1]+data[start + 2*k]+data[start + 2*k-1]
        current_sum += diff

        if current_sum > ret:
            ret = current_sum
    else:
        break
print(ret)

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

data = []
cnt = 0
curr = '1'
for i in range(len(s)):
    if s[i] != curr:
        data.append(cnt)
        curr = s[i]
        cnt = 1
    else:
        cnt += 1
data.append(cnt)
data.append(0)

current_sum = sum(data[0:0 + 2*k+1])
ret = current_sum
for start in range(2, len(data), 2):
    if (start + 2*k-1) < len(data): 
        diff = -data[start-2]-data[start-1]+data[start + 2*k]+data[start + 2*k-1]
        current_sum += diff

    #     print(start, val)
        if current_sum > ret:
            ret = current_sum
    else:
        break
print(ret)

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

data = []
cnt = 0
curr = '1'
for i in range(len(s)):
    if s[i] != curr:
        data.append(cnt)
        curr = s[i]
        cnt = 1
    else:
        cnt += 1
data.append(cnt)
data.append(0)
data.append(0)

current_sum = sum(data[0:0 + 2*k+1])
ret = current_sum
for start in range(2, len(data)-k-2, 2):
    diff = -data[start-2]-data[start-1]+data[start + 2*k]+data[start + 2*k-1]
    current_sum += diff

#     print(start, val)
    if current_sum > ret:
        ret = current_sum
print(ret)

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

data = []
cnt = 0
curr = '1'
for i in range(len(s)):
    if s[i] != curr:
        data.append(cnt)
        curr = s[i]
        cnt = 1
    else:
        cnt += 1
data.append(cnt)
data.append(0)
data.append(0)

current_sum = sum(data[0:0 + 2*k+1])
ret = current_sum
for start in range(2, len(data)-k-2, 2):
    diff = -data[start-2]-data[start-1]+data[start + 2*k]+data[start + 2*k-1]
    current_sum += diff

#     print(start, val)
    if current_sum > ret:
        ret = current_sum
print(ret)
Problem p03089 (python)

Fixed submission:
N = int(input())
b = list(map(int, input().split()))

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret.append(-1)
        break

for it in ret[::-1]:
    print(it)

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

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret = -1
        break

for it in ret[::-1]:
    print(it)

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

def matchIndex(b):
    N = len(b)
    for i in range(N-1, -1, -1):
        val = b[i]
        if val == i+1:
            return i
    return -1

ret = []
while len(b) > 0:
    index = matchIndex(b)
    if index >= 0:
        ret.append(b.pop(index))
#         print(ret[-1])
    else:
        ret = []
        ret = -1
        break

for it in ret[::-1]:
    print(it)
Problem p03163 (python)

Fixed submission:
N, W = map(int, input().split())
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    
dp = [[0 for i in range(W+1)] for j in range(N+1)]
i = 0
for w, v in p:
    i += 1
    for w_limit in range(1, W+1):
        if w_limit < w:
            dp[i][w_limit]=dp[i-1][w_limit]
            continue
        if (dp[i-1][w_limit-w] + v) > dp[i-1][w_limit]:
            dp[i][w_limit] = dp[i-1][w_limit-w] + v
        else:
            dp[i][w_limit]=dp[i-1][w_limit]
print(max(max(dp)))

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    
import numpy as np
dp = np.zeros((N+1,W+1), dtype=np.int64)

i = 0
for w, v in p:
    i += 1
    for w_limit in range(1, W+1):
        if w_limit < w:
            dp[i,w_limit]=dp[i-1,w_limit]
            continue
        if (dp[i-1, w_limit-w] + v) > dp[i-1, w_limit]:
            dp[i, w_limit] = dp[i-1, w_limit-w] + v
        else:
            dp[i,w_limit]=dp[i-1,w_limit]
print(dp.max())

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
p = []
for it in test[1:]:
    p.append(list(map(int,input().split())))
    
import numpy as np
dp = np.zeros((N+1,W+1), dtype=np.int64)

i = 0
for w, v in p:
    i += 1
    for w_limit in range(1, W+1):
        if w_limit < w:
            dp[i,w_limit]=dp[i-1,w_limit]
            continue
        if (dp[i-1, w_limit-w] + v) > dp[i-1, w_limit]:
            dp[i, w_limit] = dp[i-1, w_limit-w] + v
        else:
            dp[i,w_limit]=dp[i-1,w_limit]
print(dp.max())
Problem p03164 (python)

Fixed submission:
N, W = map(int, input().split())

max_total = 0
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    max_total += p[-1][1]
    
    
MAX_WEIGHT = 1000000009
dp = [[MAX_WEIGHT for i in range(max_total+1)] for j in range(N+1)]
dp[0][0]=0
i = 0
for w, v in p:
    i += 1
    for target_val in range(0, max_total+1):
        
        if target_val-v >=0 and dp[i-1][target_val] > (dp[i-1][target_val-v]+w):
            dp[i][target_val] = dp[i-1][target_val-v]+w
        else:
            dp[i][target_val] = dp[i-1][target_val]
            
ret = 0
for v, w in enumerate(dp[N]):
    if w<=W and v>ret:
        ret = v
print(ret)

Buggy submission (verdict: Runtime Error):
N, W = map(int, input().split())
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    
MAX_WEIGHT = 1000000009
dp = [[MAX_WEIGHT for i in range(max_total+1)] for j in range(N+1)]
dp[0][0]=0
i = 0
for w, v in p:
    i += 1
    for target_val in range(0, max_total+1):
        
        if target_val-v >=0 and dp[i-1][target_val] > (dp[i-1][target_val-v]+w):
            dp[i][target_val] = dp[i-1][target_val-v]+w
        else:
            dp[i][target_val] = dp[i-1][target_val]
            
ret = 0
for v, w in enumerate(dp[N]):
    if w<=W and v>ret:
        ret = v
print(ret)
Problem p02994 (python)

Fixed submission:
n, l = map(int, input().split())
aji = []

for i in range(1, n+1):
    aji.append(l + i - 1)

aji.sort(key=abs)
print(sum(aji[1:]))

Buggy submission (verdict: Runtime Error):
n, l = map(int, input().split())
pie = 0
min_aji = 100
for i in range(1, n+1):
    aji = l + i - 1
    pie += aji
    if abs(aji) < min_aji:
        min_aji = abs(aji)
        apple = i
        
pie -= l + apple -1

print(pie)

Buggy submission (verdict: Runtime Error):
n, l = map(int, input().split())
pie = 0
min_aji = 100
for i in range(1, n+1):
    pie += l + i - 1
    if abs(l + i - 1) < min_aji:
        min_aji = abs(l + i - 1)
        apple = i
        
pie -= l + apple -1

print(pie)

Buggy submission (verdict: Runtime Error):
n, l = map(int, input().split())
pie = 0
min_aji = 100
for i in range(1, n+1):
    if abs(l + i - 1) < min_aji:
        min_aji = abs(l + i - 1)
        apple = i
        
for i in range(1, n+1):
    if apple == i:
        continue
    pie += l + i - 1

print(pie)
Problem p02995 (python)

Fixed submission:
import fractions

a, b, c, d = map(int, input().split())

# cとdの最大公約数
g = fractions.gcd(c, d)

# cとdの最小公倍数
l = c * d // g

# cとdで割り切れないb以下の数の個数
# (全体) - (cの倍数の個数) - (dの倍数の個数) + (cの倍数かつdの倍数の個数)
x = b - b // c - b // d + b // l

# cとdで割り切れない(a-1)以下の数の個数
y = (a - 1) - (a - 1) // c - (a - 1) // d + (a - 1) // l
    
print(x - y)

Buggy submission (verdict: Runtime Error):
import math

a, b, c, d = map(int, input().split())

# cとdの最大公約数
g = math.gcd(c, d)

# cとdの最小公倍数
l = c * d // g

# cとdで割り切れないb以下の数の個数
# (全体) - (cの倍数の個数) - (dの倍数の個数) + (cの倍数かつdの倍数の個数)
x = b - b // c - b // d + b // l

# cとdで割り切れない(a-1)以下の数の個数
y = (a - 1) - (a - 1) // c - (a - 1) // d + (a - 1) // l
    
print(x - y)
Problem p03000 (python)

Fixed submission:
N, X = map(int, input().split())
L = [int(i) for i in input().split()]

count = 1
d = 0
for l in L:
    d += l
    if d > X:
        break
    count += 1
    
print(count)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = [int(i) for i in input().split()]

i = 1
d = 0
c = 1
while True:
    d += l[i-1]
    if d > x or i == n + 1:
        break
    c += 1
    i += 1
    
print(c)

Buggy submission (verdict: Runtime Error):
n, x = map(int, input().split())
l = [int(i) for i in input().split()]

i = 0
d = 0
c = 0
while d <= x:
    c += 1
    d += l[i-1]
    i += 1
    
print(c)
Problem p02861 (python)

Fixed submission:
import numpy as np
import math
N = int(input())
a = list()
for i in range(N):
    a.append(list(map(int, input().split())))
a = np.array(a)    
dis = 0
for i in range(N):
    for j in range(N):
        dis = dis + math.sqrt((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)
dis = dis/2
print(dis*2/N)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
N = int(input())
a = list()
for i in range(N):
    a.append(list(map(int, input().split())))
a = np.array(a)    
dis = 0
for i in range(N):
    for j in range(N):
        dis = dis + numpy.linalg.norm(a[i]-a[j])
dis = dis/2
print(dis*2/N)
Problem p02996 (python)

Fixed submission:
import numpy as np

N = int(input())

hyo = np.zeros((N,2))

for NN in range(N):
    hyo[NN] = input().split(' ')

hyo_sorted = hyo[np.argsort(hyo[:,1])]

tooktime = hyo_sorted[:,0].cumsum()

timeup = hyo_sorted[:,1]

if any(tooktime > timeup) ==True:
    print("No")
else:
    print("Yes")

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

N = 3

hyo = np.zeros((N,2))

for NN in range(N):
    hyo[NN] = input().split(' ')

hyo_sorted = hyo[np.argsort(hyo[:,1])]

tooktime = hyo_sorted[:,0].cumsum()

timeup = hyo_sorted[:,1]

if any(tooktime > timeup) ==True:
    print("No")
else:
    print("Yes")
Problem p02913 (python)

Fixed submission:
n = int(input())
s = input()

dp = [[0 for i in range(5005)] for j in range(5005)]

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

res = 0
for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        curr = min(dp[i][j], j - i)
        res = max(res, curr)

print(res)

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

tmp = n // 2
if s[0:tmp + 1] == s[tmp + 1:]:
    return tmp

res = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        tt = res
        mx = min(j - i, n - j)
        if tt >= mx:
            continue
        while tt <= mx:
            tt += 1
            if s[i:i + tt] != s[j:j + tt]:
                break
        _res = tt - 1
        res = max(res, _res)

print(res)
Problem p02929 (python)

Fixed submission:
import math
n = int(input())
s = [0 if i == "W" else 1 for i in list(input())]
cnt = 0
c = 1
for i in range(n * 2):
    if (s[i] + cnt) % 2 != 0:
        cnt += 1
    else:
        c = (c * (cnt if cnt != 0 else 1)) % (10 ** 9 + 7)
        cnt -= 1
    if cnt < 0:
        print(0)
        exit()
if cnt != 0:
    print(0)
else:
    print((c * math.factorial(n)) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
n = int(input())
s_list = list(input())
mod = 10 ** 9 + 7

if s_list[0] == "W" or s_list[-1] == "W":
    print(0)
    return

from math import factorial

l_counter = 0
res = 1

for i in range(2 * n):
    s = s_list[i]
    if i % 2 == 0:
        s = "W" if s == "B" else "B"

    if s == "W":
        l_counter += 1
    else:
        res *= l_counter
        l_counter -= 1
        if l_counter < 0:
            print(0)
            return

if l_counter != 0:
    print(0)
else:
    print(res * factorial(n) % mod)
Problem p02939 (python)

Fixed submission:
s = str(input())
l = len(s)

counter = 0
prev = None
pivot = 0

while pivot < l:
    n = 1
    if prev == s[pivot]:
        if pivot + 1 < l:
            if pivot + 2 < l:
                prev = s[pivot + 2]
                counter += 2
                pivot += 3
            else:
                counter += 1
                break
        else:
            break
    else:
        counter += 1
        prev = s[pivot]
        pivot += n

print(int(counter))

Buggy submission (verdict: Runtime Error):
s = str(input())
l = len(s)

counter = 0
prev = None
pivot = 0

while pivot < l:
    n = 1
    if prev == s[pivot]:
        if pivot + 1 < l:
            prev = s[pivot + 2]
            counter += 2
            pivot += 3

        else:
            break
    else:
        counter += 1
        prev = s[pivot]
        pivot += n

print(int(counter))
Problem p02947 (python)

Fixed submission:
N = int(input())

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

m = {}

def sort_str(s):
    return "".join(sorted(list(s)))

for i in range(N):
    s = str(input())
    ss = sort_str(s)

    if ss in m:
        m[ss] += 1
    else:
        m[ss] = 1


count = 0

for c in m.values():
    if c > 1:
        count += cmb(c, 2)

print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

m = {}

def sort_str(s):
    return "".join(sorted(list(s)))

for i in range(N):
    s = str(input())
    ss = sort_str(s)

    if ss in m:
        m[ss] += 1
    else:
        m[ss] = 1


count = 0

for c in m.values():
  	if c > 1:
    	count += cmb(c, 2)

print(count)
Problem p02958 (python)

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

counter = 0
for i in range(n):
    if arr[i] != sorted_arr[i]:
        counter += 1
    if counter > 2:
        break

if counter == 2 or counter == 0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
5
2 4 3 5 15
2 4 3 5 1
Problem p02983 (python)

Fixed submission:
import sys

def main():
    input = sys.stdin.readline
    L, R = map(int, input().split())
    R = min(R, L + 2019)

    ans = 2019
    for i in range(L, R):
        for j in range(i+1, R+1):
            ans = min(ans, (i*j)%2019)

    return ans


if __name__ == '__main__':
    print(main())

Buggy submission (verdict: Runtime Error):
import sys

def main():
    input = sys.stdin.readline
    L, R = map(int, input().split())

    if L == 0:
        return 0

    if (R // 2019) > ((L-1) // 2019):
        return 0

    if (R // 673) > ((L-1) // 673):
        if R - L >= 2:
            return 0
        if (R % 3) == 0 or (L % 3) == 0:
            return 0

    left = L % 2019
    return (left * (left + 1)) % MOD


if __name__ == '__main__':
    print(main())