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

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

ans = int(n*(n-1)//2)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))

ans = 0
for i in range(n):
    ans += l[i] % l[i-n+1]

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))
i = -1
ans = 0
while i > -n:
  tmp = 0
  for j in range(n):
    tmp += l[j+i] % l[j]
  ans = max(ans, tmp)
  i -= 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(input())

l = list(range(1,n+1))
i = -1
ans = 0
while i > -n:
  ltmp = l[-i:] + l[:-i]
  tmp = sum(i%j for i,j in zip(l,ltmp))
  ans = max(ans, tmp)
  i -= 1
print(ans)
Problem p02972 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())
a = [0]
a += list(map(int, input().split()))

b = [0]*(n+1)

for i in range(n,0,-1):
    sum = 0
    for j in range(2*i, n+1, i):
        sum ^= b[j]
    b[i] = sum^a[i]
    
ans = []
for i in range(1,n+1):
    if b[i]: ans.append(i)

print(len(ans))
print(*ans)

Buggy submission (verdict: Runtime Error):
3
1 0 0
Problem p02983 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

l, r = map(int, input().split())

MOD = 2019

#n = 2019
#pf = {}
#
#for i in range(2,int(n**0.5)+1):
#    while n % i == 0:
#        pf[i] = pf.get(i,0) + 1
#        n //= i
#if n > 1: pf[n] = 1
#print(pf)
## 2019=3*673

import itertools

l_mod = l%MOD
r_mod = r%MOD

if r-l > 2019:
    ans = 0
else:
    if l_mod <= 3 <= r_mod and l_mod <= 673 <= r_mod:
        ans = 0
    elif l_mod < r_mod:
        li = [i for i in range(l_mod, r_mod+1)]
        ans = 2018
        for v in itertools.combinations(li, 2):
            ans = min(ans, v[0]*v[1]%MOD)        
    else:
        ans = 0

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

l, r = map(int, input().split())

MOD = 2019

#n = 2019
#pf = {}
#
#for i in range(2,int(n**0.5)+1):
#    while n % i == 0:
#        pf[i] = pf.get(i,0) + 1
#        n //= i
#if n > 1: pf[n] = 1
#print(pf)
## 2019=3*673

import itertools

l_mod = l%MOD
r_mod = r%MOD

if r-l > 2019:
    ans = 0
else:
    if l_mod < r_mod:
    	li = [i for i in range(l_mod, r_mod+1)]
    	ans = 2018
    	for v in itertools.combinations(li, 2):
      	ans = min(ans, v[0]*v[1]%MOD)        
    else:
        ans = 0

print(ans)
Problem p02996 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

n = int(input())

readline = sys.stdin.readline

d = {}

for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    d[b] = d.get(b, 0) + a

d_sorted = sorted(d.items(), key=lambda x:x[0])

s = 0
for t, w in d_sorted:
    s += w
    if s > t:
        print('No')
        break
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n = int(input())

readline = sys.stdin.readline

MAX_N = 10**9+5
w = [0]*MAX_N

for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    w[b] += a

s = 0
for i in range(MAX_N):
    if w[i]:
        s += w[i]
        if s > i:
            print('No')
            break
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n = int(input())
#b = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#
readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

MAX_N = 10**5*2+5
w = [0]*MAX_N

for _ in range(n):
    a,b = [int(i) for i in readline().split()]
    w[b] += a

s = 0
for i in range(MAX_N):
    if w[i]:
        s += w[i]
        if s > i:
            print('No')
            break
else:
    print('Yes')
Problem p03001 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

w, h, x, y = map(int, input().split())

ans1 = w*h/2
ans2 = 0

if x == w/2 and y == h/2:
    ans2 = 1

print(ans1, ans2)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

w, h, x, y = map(int, input().split())

area = max(min(w*y, w*(h-y)), min(x*h, (w-x)*h))
is_multi = 0

if x == w//2 and y == h//2
    is_multi = 1
    
print(area, is_multi)
Problem p03062 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)

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

flip_a = [0]*n
cnt_minus = 0

for i in range(n):
	if a[i] < 0:
		cnt_minus += 1
		flip_a[i] = -a[i]
	else:
		flip_a[i] = a[i]

flip_a.sort()

if cnt_minus%2 == 1:
	flip_a[0] = -flip_a[0]

print(sum(flip_a))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = list(map(int, input().split()))
INF = 10**9

dp = [[0]*2 for _ in range(n+1)]　# dp[i][0]がiを選んで反転させない場合の最大値, dp[i][1]がiを選んで反転させた場合の最大値

dp[0][0] = 0 
dp[0][1] = -INF

for i in range(1,n+1):
    dp[i][0] = max(dp[i-1][0]+A[i-1], dp[i-1][1]-A[i-1]) # iを選んで反転させない時、 i-1を選んで反転させていなかったらiはそのままで、i-1を反転させていたらiは反転する
    dp[i][1] = max(dp[i-1][0]-A[i-1], dp[i-1][1]+A[i-1]) # iを選んで反転させる時、i-1を選んで反転させていなかったらiは反転していて、i-1を反転させていたらiはそのまま

print(dp[n][0]) # nを選ぶことはできない（n+1が存在しない）ため、答えはdp[n][0]
Problem p03074 (python)

Fixed submission:
"""
keyword: 尺取法
"""

import sys
sys.setrecursionlimit(10**6)

n, k = map(int, input().split())
s = input()

nums = []
now = 1 # 今見ている数
cnt = 0 # nowがいくつ並んでいるか

for i in range(n):
    if s[i] == str(now):
        cnt += 1
    else:
        nums.append(cnt)
        now ^= 1 # 0と1を切り替える
        cnt = 1 # 新しいのをカウント
if cnt != 0:
    nums.append(cnt)

# 1-0-1-0-1-0-1って感じの配列が欲しい
# 1-0-1-0みたいに0で終わっていたら、適当に1つ足す
# 補足：1-0-1-0-1というのは、1が0個、0が2個、1が1個、、、などと並んでいるという意味。このとき1つ目の0をひっくり返すと1-1-1と連続する。1-...-1と連続している数が求める値なので、左端と右端は1にしたい
if len(nums)%2 == 0:
    nums.append(0)
    
add = 2*k+1

ans = 0
left = 0
right = 0
tmp = 0 # [left, right)のsum

# 1-0-1...の、1から始まり1で終わる範囲を見るので、偶数番目だけ見る
for i in range(0, len(nums), 2):
    
    nextleft = i
    nextright = min(i+add, len(nums))
    
    # 左端を移動
    while (nextleft > left):
        tmp -= nums[left]
        left += 1
    # 右端を移動
    while (nextright > right):
        tmp += nums[right]
        right += 1
        
    ans = max(tmp, ans)
    
print(ans)

Buggy submission (verdict: Runtime Error):
"""
keyword: 尺取法
"""

import sys
sys.setrecursionlimit(10**6)

n, k = map(int, input().split())
s = input()

nums = []
now = 1 # 今見ている数
cnt = 0 # nowがいくつ並んでいるか

for i in range(n):
    if s[i] == str(now):
        cnt += 1
    else:
        nums.append(cnt)
        now ^= 1 # 0と1を切り替える
        cnt = 1 # 新しいのをカウント
if cnt != 0:
    nums.append(cnt)

# 1-0-1-0-1-0-1って感じの配列が欲しい
# 1-0-1-0みたいに0で終わっていたら、適当に1つ足す
# 補足：1-0-1-0-1というのは、1が0個、0が2個、1が1個、、、などと並んでいるという意味。このとき1つ目の0をひっくり返すと1-1-1と連続する。1-...-1と連続している数が求める値なので、左端と右端は1にしたい
if len(nums)%2 == 0:
    nums.append(0)
    
add = 2*k+1

# 累積和を作る
tot = [0]*(len(nums)+1)
for i in range(len(tot)):
    tot[i+1] = tot[i]+nums[i]

ans = 0

# 1-0-1...の、1から始まり1で終わる範囲を見るので、偶数番目だけ見る
for i in range(0, len(nums), 2):
    
    # 次のleft, rightを計算する
    left = i
    right = min(i+add, len(nums))
    tmp = tot[right] - tot[left]
    
    ans = max(tmp, ans)
    
print(ans)
Problem p02609 (python)

Fixed submission:
n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
if m != 1:
    x_minus = x%(m-1)
else:
    x_minus = 1
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
x_minus = x%(m-1)
lis_plus = [0]*n
lis_minus = [0]*n
for i in range(n):
    if i == 0:
        lis_plus[i] = 1%(m+1)
        if m != 1:
            lis_minus[i] = 1%(m-1)
    else:
        lis_plus[i] = lis_plus[i-1]*2%(m+1)
        if m != 1:
            lis_minus[i] = lis_minus[i-1]*2%(m-1)
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = int(input(),2)

def popcount(l):
    return bin(l).count("1")
def count(l):
    res = 0
    while l != 0:
        p = popcount(l)
        l %= p
        res += 1
    return res
m = popcount(x)
x_plus = x%(m+1)
x_minus = x%(m-1)
lis_plus = []
lis_minus = []
for i in range(n):
    if i == 0:
        lis_plus.append(1%(m+1))
        if m != 1:
            lis_minus.append(1%(m-1))
    else:
        lis_plus.append(lis_plus[-1]*2%(m+1))
        if m != 1:
            lis_minus.append(lis_minus[-1]*2%(m-1))
for i in range(n):
    if (x >> (n-i-1)) & 1:
        if m == 1:
            print(0)
        else:
            print(count((x_minus - lis_minus[-i-1])%(m-1)) + 1)
    else:
        print(count((x_plus + lis_plus[-i-1])%(m+1)) + 1)
Problem p02936 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n, q = map(int, input().split())
lis = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    lis[a].append(b)
    lis[b].append(a)
c_plus = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    c_plus[p] += x
ans = [-1 for _ in range(n)]
def dfs(inp):
    now = inp[0]
    count = inp[1]
    count += c_plus[now]
    ans[now] = count
    for next in lis[now]:
        if ans[next] == -1:
            dfs([next, count])
dfs([0,0])
for i in range(n):
    ans[i] = str(ans[i])
print(" ".join(ans))

Buggy submission (verdict: Runtime Error):
n, q = map(int, input().split())
lis = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    lis[a].append(b)
    lis[b].append(a)
c_plus = [0 for _ in range(n)]
for _ in range(q):
    p, x = map(int, input().split())
    p -= 1
    c_plus[p] += x
ans = [-1 for _ in range(n)]
def dfs(inp):
    now = inp[0]
    count = inp[1]
    count += c_plus[now]
    ans[now] = count
    for next in lis[now]:
        if ans[next] == -1:
            dfs([next, count])
dfs([0,0])
for i in range(n):
    ans[i] = str(ans[i])
print(" ".join(ans))
Problem p03240 (python)

Fixed submission:
N = int(input())
xyz = []
for i in range(N):
    xyz.append(list(map(int, input().split())))
H = 0
h = 0
flag = False
maxz = xyz[0][2]
maxy = xyz[0][1]
maxx = xyz[0][0]
for k in range(N):
    if xyz[k][2] > maxz:
        maxz = xyz[k][2]
        maxx = xyz[k][0]
        maxy = xyz[k][1]
for i in range(101):
    for j in range(101):
        H = maxz + abs(maxx-i) + abs(maxy-j)
        for k in xyz:
            h = H -abs(k[0]-i)-abs(k[1]-j)
            if h < 0:
                h = 0
            if h == k[2]:
                continue
            else:
                break
        else:
            if H != 0:
                flag = True
                print("{} {} {}".format(i, j, H))
                break
    if flag:
        break

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
maxc = M//N
while True:
    if N == 1:
        print(1)
        break
    if M%maxc == 0:
        print(maxc)
        break
    maxc -=1
Problem p03262 (python)

Fixed submission:
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
N, X = map(int, input().split())
xlist =[X]
xlist.extend(list(map(int, input().split())))
dlist =[]
for i in range(N):
    dlist.append(abs(xlist[i+1]-xlist[i]))
g = max(dlist)
for d in dlist:
    g = gcd(g, d)
print(g)

Buggy submission (verdict: Runtime Error):
import math
N, X = map(int, input().split())
xlist =[X]
xlist.extend(list(map(int, input().split())))
dlist =[]
for i in range(N):
    dlist.append(abs(xlist[i+1]-xlist[i]))
g = max(dlist)
for d in dlist:
    g = math.gcd(g, d)
print(g)
Problem p03264 (python)

Fixed submission:
K = int(input())
if K % 2 == 0:
    print(int((K/2)**2))
else:
    print(int((K//2+1)*(K//2)))

Buggy submission (verdict: Runtime Error):
K = int(input())
if K % 2 == 0:
    print((K/2)**2)
else:
    print((k//2+1)*(k//2))
Problem p03274 (python)

Fixed submission:
N, K = map(int, input().split())
x = [i for i in map(int, input().split())]
i = 0
min_time =5e8
while i < N-K+1:
    if x[i]<0 and x[i+K-1]<0:
        time = -x[i]
    if x[i]<0 and x[i+K-1]>=0:
        time1 = -2*x[i] + x[i+K-1]
        time2 = -x[i] + 2*x[i+K-1]
        if time1< time2:
            time = time1
        else:
            time = time2
    if x[i] >= 0 and x[i+K-1] >=0:
        time = x[i+K-1]
    if time < min_time:
        min_time = time
    i += 1
print(min_time)

Buggy submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []
for i in range(H):
    a.append(input())
row = [False]*H
col = [False]*W
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            row[i] = True
            col[j] = True
for i in range(H):
    if row[i]:
        for j in range(W):
            if col[j]:
                print(a[i][j], end = "")
        print("", end = "\n")
Problem p03284 (python)

Fixed submission:
numbers = input()
number_list = numbers.split(" ")
N = int(number_list[0])
K = int(number_list[1])
if N%K == 0:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
numbers = input()
number_list = numbers.splist(" ")
N = int(number_list[0])
K = int(number_list[1])
if N%K == 0:
  print(0)
else:
  print(1)

Buggy submission (verdict: Runtime Error):
numbers = input()
number_list = numbers.splist(" ")
N = int(number_list[0])
K = int(number_list[1])
if N%K == 0:
  print 0
else:
  print 1
Problem p03285 (python)

Fixed submission:
N = int(input())
if N % 7 == 0:
  print('Yes')
else:
  while(N>0):
    if N%4 == 0:
      print('Yes')
      break
    else:
      N = N - 7
  else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
if N % 7 == 0:
	print('Yes')
else:
	while(N>0):
		if N%4 == 0:
			print('Yes')
			break
            else:
		N = N - 7
	else:
		print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
if N % 7 == 0:
  print('Yes')
else:
  while(N>0):
  	if N%4 == 0:
      print('Yes')
      break
  	else:
    	N = N - 7
  else:
  	print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
if N % 7 == 0:
  print('Yes')
else:
  while(N>0):
  	if N%4 == 0:
    	print('Yes')
    	break
  	else:
    	N = N - 7
  else:
  	print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
while(N>0):
  if N%4 == 0:
    print('Yes')
    return None
  else:
    N = N - 7
if N ==0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
while(N>0):
  if N%4 == 0:
    print("Yes")
    return
  else:
    N = N - 7
if N ==0:
  print("Yes")
else:
  print("No")
Problem p02678 (python)

Fixed submission:
from collections import deque
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)]

ans = [deque([]) for _ in range(m+10)]
ans2 = [[] for _ in range(m+10)]
for i in range(m):
    s = li[i][0]
    t = li[i][1]

    ans[s].append(t)
    ans[t].append(s)

stack = deque([1])
while stack:
    v = stack[0]

    if ans[v]:
        w = ans[v].popleft()
        if True:
            ans2[w].append(v)
        stack.append(w)
    else:
        stack.popleft()

print('Yes')
for i in range(2, n+1):
    print(ans2[i][0])

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)]

ans = [deque([]) for _ in range(m+10)]
ans2 = [[] for _ in range(m+10)]
for i in range(m):
    s = li[i][0]
    t = li[i][1]

    ans[s].append(t)
    ans[t].append(s)

stack = deque([1])
while stack:
    v = stack[0]

    if ans[v]:
        w = ans[v].popleft()
        if True:
            ans2[w].append(v)
        stack.append(w)
    else:
        stack.popleft()

print('Yes')
for i in range(2, m+1):
    print(ans2[i][0])

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)]

ans = [deque([]) for _ in range(m+10)]
ans2 = [[] for _ in range(m+10)]
for i in range(m):
    s = li[i][0]
    t = li[i][1]

    ans[s].append(t)
    ans[t].append(s)


stack = deque([1])
while stack:
    v = stack[0]

    if ans[v]:
        w = ans[v].popleft()
        if ans2[w] == []:
            ans2[w].append(v)
        stack.append(w)
    else:
        stack.popleft()

print('Yes')
for i in range(2, m+1):
    print(ans2[i][0])

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(m)]

ans = [deque([]) for _ in range(10)]
ans2 = [[] for _ in range(10)]
for i in range(m):
    s = li[i][0]
    t = li[i][1]

    ans[s].append(t)
    ans[t].append(s)
print(ans)

stack = deque([1])
while stack:
    v = stack[0]

    if ans[v]:
        w = ans[v].popleft()
        if ans2[w] == []:
            ans2[w].append(v)
        stack.append(w)
    else:
        stack.popleft()

print('Yes')
for i in range(2, m+1):
    print(ans2[i][0])
Problem p02797 (python)

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

if s >= 10**9:
    ans = [1]*n
else:
    ans = [10**9] * n

for i in range(k):
    ans[i] = s

print(*ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
li = [list(map(int,input().split())) for _ in range(n)]

ans = 0
cnt = 0
li.sort()
temp = []

while True:
    arr = []
    check = -10**10
    if len(temp) == 0:
        for i in range(n):
            s = li[i][0] - li[i][1]
            if check > s:
                arr.append(i-1)
                arr.append(i)
            check = li[i][0] + li[i][1]
    else:
        for i in temp:
            s = li[i][0] - li[i][1]
            if check > s:
                arr.append(i-1)
                arr.append(i)
            check = li[i][0] + li[i][1]
    if len(arr) == 0:
        break
    arr = list(set(arr))
    temp = arr
    t = -2
    for index,i in enumerate(arr):
        if t == -2:
            t = i
        elif t+1 == i:
            del temp[index]
            t = -2
            ans += 1
        else:
            t = i

print(n-ans)
Problem p02853 (python)

Fixed submission:
x,y = map(int,input().split())
ans = 0

if x == 1 and y == 1:
    ans += 400000
    
li = [0,300000, 200000, 100000]

if x <= 3:
    ans += li[x]
if y <= 3:
    ans += li[y]

print(ans)

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
ans = 0

if x == 1 and y == 1:
    ans += 400000
    
li = [0,300000, 200000, 100000]

if x <= 3:
    ans += li[x]
if y <= 3
    ans += li[y]

print(ans)

Buggy submission (verdict: Runtime Error):
x,y = map(int,input().split())
ans = 0

if x == 1 and y == 1:
    ans += 400000
    
li = [0,300000, 200000, 100000]

ans += li[x]
ans += li[y]

print(ans)
Problem p02947 (python)

Fixed submission:
from collections import defaultdict
from math import factorial

n = int(input())
s = []

for i in range(n):
    t = list(input())
    t.sort()
    s += [t]

for i in range(n):
    s[i] = ",".join(s[i])
    s[i] = s[i].replace(",","")
    
ans = 0

d = defaultdict(int)

for key in s:
    if key in d:
        ans += d[key]
    d[key] += 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from math import factorial

n = int(input())
s = []

for i in range(n):
    t = list(input())
    t.sort()
    s += [t]

for i in range(n):
    s[i] = ",".join(s[i])
    s[i] = s[i].replace(",","")
    
d = defaultdict(int)

for key in s:
    d[key] += 1
    
cnt = 0

for key, val in d.items():
    if val >= 2:
        cnt += factorial(val) / factorial(2) / factorial(val - 2)

print(int(cnt))
Problem p02963 (python)

Fixed submission:
S = int(input())

M = 10**9
t = (-S) % M  #M - S%M
x = (S + t) // M

answer = [0,0,1,M,x,t]

print(*answer)

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

x1 = 0
y1 = 0

def divisor(n):
    i = s//10 ** 9 + 1
    while i*i <= n:
        if n%i == 0:
            if n//i < 10 ** 9:
                a = i
                b = n//i
                break
        i += 1
    return a,b

if s == int(s ** 0.5) ** 2:
    a = int(s**0.5)
    b = int(s**0.5)

else:
    a,b = divisor(s)

x2 = a
y2 = 0
x3 = 0
y3 = b

print(x1,y1,x2,y2,x3,y3)
Problem p02995 (python)

Fixed submission:


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

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


v = c*d//gcd(c,d)

s = b//c - (a-1)//c
t = b//d - (a-1)//d
u = b//v - (a-1)//v

print((b-a+1) - (s+t-u))

Buggy submission (verdict: Runtime Error):
import math

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

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

v = lcm(c, d)

s = b//c - (a-1)//c
t = b//d - (a-1)//d
u = b//v - (a-1)//v

print((b-a+1) - (s+t-u))
Problem p03001 (python)

Fixed submission:
w,h,x,y = map(int,input().split())

a = min(x,w-x)
s = h*a

b = min(y, h-y)
t = w*b

result = 0

if x == w/2 and y == h/2:
    result = 1

print(h*w/2,result)

Buggy submission (verdict: Runtime Error):
w,h,x,y = map(int,input().split())

a = min(x,w-x)
s = h*a

b = min(y, h-y)
t = w*b

result = 0

if x == w/2 and y == h/2:
    result = 1

u = 0
if w == x and h == y:
    u = w*h/2
if x == 0 and y == h:
    u = w*h/2
if x == 0 and y == 0:
    u = w*h/2
if x == w and y == 0:
    u = w*h/2
 
v = 0
if x == 0 or x == w:
    temp = max(h-y,y)
    v = h*w/2

c = 0
if y/x == h/w:
    c = h*w/2

z = 0
try:
    if y == -h/w*x + h:
        z = h*w/2
except:
    pass

print(max(s,t,u,v,c,z),result)

Buggy submission (verdict: Runtime Error):
w,h,x,y = map(int,input().split())

a = min(x,w-x)
s = h*a

b = min(y, h-y)
t = w*b

result = 0

if x == w/2 and y == h/2:
    result = 1

u = 0
if x == 0 or x == w or y == 0 or y == h:
    u = h*w/2

v = 0
if y/x == h/w or y == -h/w + h:
    v = h*w/2

print(max(s,t,u,v),result)
Problem p03037 (python)

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

left_max = -1
right_min = n+1

for i in range(m):
    s,t = map(int,input().split())
    left_max = max(left_max,s)
    right_min = min(right_min, t)
    
print(max(0, right_min - left_max +1))

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

l = [""] * m

for i in range(m):
    l[i] = list(map(int,input().split()))
ans3 = set([0,n+1])

for i in range(m):
    ans2 = [j for j in range(min(ans3),max(ans3)+1) if l[i][0] <= j <= l[i][1]]
    if i == 0:
        ans3 = set(ans2)
    else:
        ans3 = ans3 & set(ans2)
    ans2.clear()
    
print(len(ans3))

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

l = [""] * m

for i in range(m):
    l[i] = list(map(int,input().split()))

ans3 = [i for i in range(1,n+1)]
ans3 = set(ans3)


for i in range(m):
    ans2 = [j for j in range(min(ans3),max(ans3)+1) if l[i][0] <= j <= l[i][1]]
    ans3 = ans3 & set(ans2)
    ans2.clear()
    
print(len(ans3))
Problem p03047 (python)

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

print(n - k + 1)

Buggy submission (verdict: Runtime Error):
R, G, B, N = map(int, input().split())

cnt = 0

for i in range(N//R + 1):
    for j in range(N//G + 1):
        sum = N - i * R - j * G
        if sum >= 0 and sum % B == 0:
            cnt += 1

print(cnt)