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

Fixed submission:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
F = []
for _ in range(N):
    Fi = l_inpl()
    F.append(Fi)

P = []
for _ in range(N):
    Pi = l_inpl()
    P.append(Pi)


# bit全探索
ans = -1 * INF
for i in range(1, 2**10):
    tmp = 0
    for j in range(N):
        c = 0
        # NOTE: iとF[j]のAND演算
        for k in range(10):
            if ((i>>k) & 1) & F[j][k]:
                c += 1
        tmp += P[j][c]
    ans = max(ans, tmp)

print(ans)

Buggy submission (verdict: Runtime Error):
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = s_inpl()   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import copy
from collections import defaultdict, Counter
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
import numpy as np

def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
F = []
for _ in range(N):
    Fi = l_inpl()
    F.append(Fi)

P = []
for _ in range(N):
    Pi = l_inpl()
    P.append(Pi)


# bit全探索
ans = -1 * INF
for i in range(1, 2<<10):
    tmp = 0
    for j in range(N):
        c = 0
        # NOTE: iとF[j]のAND演算
        for k in range(10):
            if ((i>>k) & 1) & F[j][k]:
                c += 1
        tmp += P[j][c]
    ans = max(ans, tmp)

print(ans)
Problem p03612 (python)

Fixed submission:
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
 
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
p = l_inpl()

ans = 0
for i in range(N-1):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1

if p[-1] == N:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
import math
import copy
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
from bisect import bisect_left, bisect_right
# import numpy as np
 
def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W
 
# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def s_inpl(): return map(int,input().split())
def l_inpl(): return list(map(int, input().split()))
INF = float("inf")

N = i_inpl()
p = l_inpl()

ans = 0
for i in range(N):
    if p[i] == i+1:
        p[i], p[i+1] = p[i+1], p[i]
        ans += 1

if p[-1] == N:
    ans += 1

print(ans)
Problem p03659 (python)

Fixed submission:

from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

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

ans = 10**100
res = np.cumsum(a)

print(min([abs(res[-1]-res[i]-res[i]) for i in range(len(res)-1)]))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

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

ans = 10**100
for i in range(1, n):
    if ans>abs(sum(a[:i])-sum(a[i:])):
        ans = abs(sum(a[:i])-sum(a[i:]))

print(ans)
Problem p02995 (python)

Fixed submission:
import fractions 
A, B, C, D = map(int, input().split())

lcm_cd = C * D // fractions.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd

ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd


ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)

print(ans)

Buggy submission (verdict: Runtime Error):
import math
A, B, C, D = map(int, input().split())

lcm_cd = C * D // math.gcd(C, D)
divBbyC = B // C
divBbyD = B // D
divBbyCD = B // lcm_cd
divAmbyC = (A - 1) // C
divAmbyD = (A - 1) // D
divAmbyCD = (A - 1) // lcm_cd


ans = (B - divBbyC - divBbyD + divBbyCD) - ((A - 1) - divAmbyC - divAmbyD + divAmbyCD)

print(ans)
Problem p03557 (python)

Fixed submission:
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
counter = 0
for b in B:
    counter += bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b))

print(counter)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
M = np.array([[0 for _ in range(0, max(C)+1)] for _ in range(2)])
for i in range(N):
    M[0][A[i]] += 1
    M[1][C[i]] += 1
cum_M = np.cumsum(M, axis=1)
counter = 0
min_a = A[0]
max_c = C[-1]
for b in B:
    if min_a < b < max_c:
        counter += cum_M[0][b-1]*(cum_M[1][-1]-cum_M[1][b])
        
print(int(counter))

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
M = np.array([[0 for _ in range(0, max(C)+1)] for _ in range(3)])
for i in range(N):
    M[0][A[i]] += 1
    M[1][B[i]] += 1
    M[2][C[i]] += 1
cum_M = np.cumsum(M, axis=1)
counter = 0
min_a = A[0]
max_c = C[-1]
for b in B:
    if min_a < b < max_c:
        counter += cum_M[0][b-1]*(cum_M[2][-1]-cum_M[2][b])
        
print(counter)

Buggy submission (verdict: Runtime Error):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
M = np.array([[0 for _ in range(0, max(C)+1)] for _ in range(3)])
for i in range(N):
    M[0][A[i]] += 1
    M[1][B[i]] += 1
    M[2][C[i]] += 1
cum_M = np.cumsum(M, axis=1)
counter = 0
min_a = A[0]
max_c = C[-1]
for b in B:
    if min_a < b < max_c:
        counter += cum_M[0][b-1]*(cum_M[2][-1]-cum_M[2][b])
        
print(counter)
Problem p03844 (python)

Fixed submission:
print(eval(input()))

Buggy submission (verdict: Runtime Error):
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = True
if n % 2 == 1:
    if a[0] != 0:
        print(0)
    else:
        ans = [i for i in range(2, n, 2) for j in range(2)]
        ans.insert(0, 0)
        if ans != a:
            print(0)
            flag = False
    if flag:
        print((2**((n - 1) // 2)) % (1e9 + 7))

else:
    ans = [i for i in range(1, n, 2) for j in range(2)]
    if ans != a:
        print(0)
        flag = False
    if flag:
        print((2**(n // 2)) % (1e9 + 7))
Problem p03846 (python)

Fixed submission:
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = True
if n % 2 == 1:
    if a[0] != 0:
        print(0)
    else:
        ans = [i for i in range(2, n, 2) for j in range(2)]
        ans.insert(0, 0)
        if ans != a:
            print(0)
            flag = False
    if flag:
        print((2**((n - 1) // 2)) % (10**9 + 7))

else:
    ans = [i for i in range(1, n, 2) for j in range(2)]
    if ans != a:
        print(0)
        flag = False
    if flag:
        print((2**(n // 2)) % (10**9 + 7))

Buggy submission (verdict: Runtime Error):
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = True
if n % 2 == 1:
    if a[0] != 0:
        print(0)
    else:
        ans = [i for i in range(2, n, 2) for j in range(2)]
        ans.insert(0, 0)
        if ans != a:
            print(0)
            flag = False
    if flag:
        print((2**((n - 1) // 2)) % (1e9 + 7))

else:
    ans = [i for i in range(1, n, 2) for j in range(2)]
    if ans != a:
        print(0)
        flag = False
    if flag:
        print((2**(n // 2)) % (1e9 + 7))

Buggy submission (verdict: Runtime Error):
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = True
if n % 2 == 1:
    if a[0] != 0:
        print(0)
    else:
        ans = [i for i in range(2, n, 2) for j in range(2)]
        ans.insert(0, 0)
        if ans != a:
            print(0)
            flag = False
    if flag:
        print(int((2**((n - 1) // 2)) % (1e9 + 7)))

else:
    ans = [i for i in range(1, n, 2) for j in range(2)]
    if ans != a:
        print(0)
        flag = False
    if flag:
        print(int((2**(n // 2)) % (1e9 + 7)))

Buggy submission (verdict: Runtime Error):
import copy
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = True
if n % 2 == 1:
    if a[0] != 0:
        print(0)
    else:
        for i in range(2, n, 2):
            if not(a[i - 1] == i and a[i] == i):
                print(0)
                flag = False
                break
    if flag:
        print(int((2**((n-1)//2))%(1e9+7)))

else:
    for i in range(1, n, 2):
        if not(a[i - 1] == i and a[i] == i):
            print(0)
            flag = False
            break
    if flag:
        print(int((2**(n//2))%(1e9+7)))
Problem p02885 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    ans = max(0, A - (2 * B))
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def solve(A: int, B: int):
    ans = max(0, A - (2 * B))
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()
Problem p02900 (python)

Fixed submission:
#!/usr/bin/env python3
import sys


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


def solve(A: int, B: int):
    while A % B:
        tmp = B
        B = A % B
        A = tmp
    if B == 1:
        print(1)
    else:
        ans = factorization(B)
        print(len(ans)+1)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys


def era(N: int):
    N1 = N+1
    prim = [0]*N1
    i = 2
    while i**2 < N1:
        if prim[i] == 0:
            for j in range(i**2, N1, i):
                if prim[j] == 0:
                    prim[j] = i
        i += 1
    ans = []
    p = N
    n = prim[p]
    while n != 0:
        ans.append(n)
        p = p // n
        n = prim[p]
    ans.append(n)
    return ans


def solve(A: int, B: int):

    while A % B:
        tmp = B
        B = A % B
        A = tmp
    ans = set(era(B))
    print(len(ans)+1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()
Problem p03455 (python)

Fixed submission:
s=input().split()
if (int(s[0])*int(s[-1]))%2 == 1:
  print("Odd")
else:
  print("Even")

Buggy submission (verdict: Runtime Error):
s=input()
if (int(s[0])*int(s[-1]))%2 == 1:
  print("Odd")
 else:
  print("Even")
Problem p03457 (python)

Fixed submission:
num_list=int(input())
a=[0,0,0]
for i in range(num_list):
  b=[int(x) for x in input().split()]
  dt=(b[0]-a[0])
  d=(abs(b[1]-a[1])+abs(b[2]-a[2]))
  if d<=dt and dt%2==d%2:
    if i == num_list-1:
      print("Yes")
      break
    a=b
  else:
    print("No")
    break

Buggy submission (verdict: Runtime Error):
num_list=int(input())
a=[int(x) for x in input().split()]
for i in range(num_list):
  b=[int(x) for x in input().split()]
  if (abs(b[1]-a[1])+abs(b[2]-a[2]))<=(b[0]-a[0]) and (abs(b[1]-a[1])+abs(b[2]-a[2])) != 0:
    if i+2 == num_list:
      print("Yes")
      break
    a=b
    continue
  else:
    print("No")
    break

Buggy submission (verdict: Runtime Error):
num_list=int(input())
a=[int(x) for x in input().split()]
for i in range(num_list):
  b=[int(x) for x in input().split()]
  if (abs(b[1]-a[1])+abs(b[2]-a[2]))<=(b[0]-a[0]):
    if i+2 == num_list:
      print("Yes")
      break
    a=b
    continue
  else:
    print("No")
    break

Buggy submission (verdict: Runtime Error):
num_list=int(input())
a=[int(x) for x in input().split()]
print(a)
for i in range(num_list):
  b=[int(x) for x in input().split()]
  print(b)
  if (abs(b[1]-a[1])+abs(b[2]-a[2]))<=(b[0]-a[0]):
    if i+2 == num_list:
      print("Yes")
      break
    a=b
    continue
  else:
    print("No")
    break
Problem p02911 (python)

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

lst = [0] * N

for i in range(Q):
    lst[int(input())-1] += 1

x = Q - K 

for i in range(len(lst)):
    if lst[i] - x > 0 :
        print('Yes')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
import collections

N,K,Q = map(int,input().split())
lst =[int(input()) for i in range (Q)]

if K > Q :
    for i in range(N):
        print('Yes')
    exit(0)
else:
    x = Q - K

#s = set(lst)
c = collections.Counter(lst)

values, counts = zip(*c.most_common(x))

if len(values) == 0 :
    for i in range(N):
        print('No')
    exit(0)
    

#print(values)
#print(type(values))
newlist = sorted(values)
j = 0
l = len(values)
for i in range(N):
    if l-1 >= j :
        if i +1 == values[j] :
            print('Yes')
            j += 1
        else:
            print('No')
    else:
        print('No')

Buggy submission (verdict: Runtime Error):
import collections

N,K,Q = map(int,input().split())
lst =[int(input()) for i in range (Q)]

if K > Q :
    for i in range(N):
        print('Yes')
    exit(0)
else:
    x = Q - K

#s = set(lst)
c = collections.Counter(lst)

values, counts = zip(*c.most_common(x))

if len(values) == 0 :
    for i in range(N):
        print('No')
        exit(0)

#print(values)
#print(type(values))
#values.sort()
j = 0
l = len(values)
for i in range(N):
    if l-1 >= j :
        if i +1 == values[j] :
            print('Yes')
            j += 1
        else:
            print('No')
    else:
        print('No')
Problem p03206 (python)

Fixed submission:
D = int(input())
 
if ( D == 25 ):
	print('Christmas')
elif (D == 24):
	print('Christmas Eve')
elif (D == 23):
	print('Christmas Eve Eve')
elif (D == 22):
	print('Christmas Eve Eve Eve')

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

if ( D == 25 )
	print('Christmas')
elif (D == 24)
	print('Christmas Eve')
elif (D == 23)
	print('Christmas Eve Eve')
elif (D == 22)
	print('Christmas Eve Eve Eve')
Problem p03238 (python)

Fixed submission:
n = int(input())
if n == 1:
  print('Hello World')
else:
  a = int(input())
  b = int(input())
  print( a + b )

Buggy submission (verdict: Runtime Error):
n = int(input())
if n == 1:
  print('Hello World')
else:
  a,b = map(int,input().split())
  print( a + b )
Problem p03701 (python)

Fixed submission:
N = int(input())

lst = []
# listにN個の数値を格納
for i in range(N):
    lst.append(int(input()))

lst.sort()
lstsum = sum(lst)
p_list = [ i / 10 for i in lst if i % 10 != 0 ]

if len(p_list) == 0:
    print(0)
elif lstsum % 10 != 0:
    print(lstsum)
else:
    for i in range(N):
        ans = lstsum - lst[i]
        if ans % 10 != 0:
            print(ans)
            exit(0)

Buggy submission (verdict: Runtime Error):
import itertools

N = int(input())

lst = []
# listにN個の数値を格納
for i in range(N):
    lst.append(int(input()))

l_sum = sum(lst)

p_list = []

if l_sum % 10 == 0:
    
    # enumerate()関数を使うと、forループの中でリスト（配列）インデックス番号（カウント、順番）を取得できる
    # i にインデックス番号が入る

    for i, _ in enumerate(lst, 1):
        # permutations()を使うと 第2引数分の全パターンを取得できる
        for j in itertools.permutations(lst, r=i):  # rには1、2、3と渡される
            p_list.append(j)
    
    q_list = sorted(set(list(map(sum, p_list))),reverse=True)
    
    x = 0
    for i, item in enumerate(q_list, 1):
        if item % 10 != 0 :
            print(item)
            x = 1
            break
    
    if x = 0:
        print(0)

else:
    print (l_sum)
Problem p02882 (python)

Fixed submission:
import math

a, b, x = map(int, input().split())

if a*a*b/2 > x:
    theta = math.atan((2*x)/(b*b*a))
    print(90 - math.degrees(theta))
else:
    theta = math.atan((2*(a*a*b-x))/(a*a*a))
    print(math.degrees(theta))

Buggy submission (verdict: Runtime Error):
import math

a, b, x = map(int, input().split())

if b >= a:
    theta = 0.5 * math.asin((4*x)/(b*b*a))
    print(90 - math.degrees(theta))
else:
    theta = math.atan((2*(a*a*b-x))/(a*a*a))
    print(math.degrees(theta))

Buggy submission (verdict: Runtime Error):
import math

a, b, x = map(int, input().split())

if b >= a:
    theta = 0.5 * math.asin((4*x)/(b*b*a))
    print(90 - math.degrees(theta))
else:
    theta = math.atan((2*(a*a*b-x))/(a*a*a))
    print(math.degrees(theta))
Problem p02889 (python)

Fixed submission:
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
edges = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    edges[a - 1][b - 1] = c
    edges[b - 1][a - 1] = c

Q = int(input())
st = []
for _ in range(Q):
    st.append([int(j) - 1 for j in input().split()])

edges = floyd_warshall(edges)

for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

edges = floyd_warshall(edges)

for i, j in st:
    if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1)

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall

N, M, L = map(int, input().split())
edges = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    edges[a - 1][b - 1] = c
    edges[b - 1][a - 1] = c

Q = int(input())
st = []
for _ in range(Q):
    st.append([int(j) - 1 for j in input().split()])

edges = floyd_warshall(edges)

for i in range(N):
    for j in range(N):
        if edges[i][j] <= L:
            edges[i][j] = 1
        else:
            edges[i][j] = 0

edges = floyd_warshall(edges)

for i, j in st:
    if edges[i][j] == float("inf"):
        print(-1)
    else:
        print(int(edges[i][j]) - 1)
Problem p02947 (python)

Fixed submission:
N = int(input())
words_dict = {}
count = 0
for i in range(N):
  ss = input()
  ss = "".join(sorted(ss))
  words_dict.setdefault(ss, 0)
  count += words_dict[ss]
  words_dict[ss] += 1
print(count)

Buggy submission (verdict: Runtime Error):
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += cmb(v, 2)
      # count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)

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

N = int(input())
words_dict = {}
for i in range(N):
  ss = input()
  ss_dict = {}
  for s in ss:
    ss_dict.setdefault(s, 0)
    ss_dict[s] += 1
  ss_dict = sorted(ss_dict.items())
  ss = [str(k)+str(v) for (k, v) in ss_dict]
  word = ''.join(ss)
  words_dict.setdefault(word, 0)
  words_dict[word] += 1
count = 0
for k, v in words_dict.items():
  if v > 1:
      count += int(factorial(v) / factorial(2) / factorial(v-2))
print(count)