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

Fixed submission:
class BIT:
  def __init__(self, n):
    self.N = n+1
    self.bit = [0]*self.N
  
  def bit_sum(self, i):
    s = 0
    i += 1
    while i>0:
      s += self.bit[i]
      i -= i & -i
    return s

  def bit_add(self, i, n):
    i += 1
    while i<self.N:
      self.bit[i] += n
      i += i & -i

N, *A = map(int, open(0).read().split())
inf = [(a,i) for i, a in enumerate(A)]
n = A[0]
ls = [0]
for i in range(1,N):
  if A[i]>n:
    n = A[i]
    ls.append(i)
B = BIT(N)
C = BIT(N)
inf.sort(reverse=True)
cnt = [0]*N
ccnt = [0]*N
for a,i in inf:
  B.bit_add(i,a)
  cnt[i] = B.bit_sum(N-1)-B.bit_sum(i)
for a, i in inf:
  C.bit_add(i,1)
  ccnt[i] = C.bit_sum(N-1)-C.bit_sum(i)

ans = [0]*N
s = sum(A)
p = 0
x = 0
for i in range(len(ls)-1,0,-1):
  a = ls[i]
  b = ls[i-1]
  m = cnt[b]-A[b]*ccnt[b]
  n = m-x
  ans[a] = n
  s -= n
  x += ans[a]
ans[0] = s
print('\n'.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
class BIT:
  def __init__(self, n):
    self.N = n+1
    self.bit = [0]*self.N
  
  def bit_sum(self, i):
    s = 0
    i += 1
    while i>0:
      s += self.bit[i]
      i -= i & -i
    return s

  def bit_add(self, i, n):
    i += 1
    while i<self.N:
      self.bit[i] += n
      i += i & -i

N, *A = map(int, open(0).read().split())
inf = [(a,i) for i, a in enumerate(A)]
n = A[0]
ls = [0]
for i in range(1,N):
  if A[i]>n:
    n = A[i]
    ls.append(i)
B = BIT(N)
inf.sort(reverse=True)
cnt = [0]*N
for a,i in inf:
  B.bit_add(i,1)
  cnt[i] = B.bit_sum(N-1)-B.bit_sum(i-1)

s = sum(A)
ans = [0]*N
n = A[ls[-2]]
for i in range(ls[-1],N):
  if A[i]>n:
    ans[ls[-1]] += A[i]-n
    s -= A[i]-n
for i in range(len(ls)-2,0,-1):
  a = ls[i]
  b = ls[i-1]
  m = A[a]-A[b]
  ans[a] = m*cnt[a]
  s -= m*cnt[a]
ans[0] = s
print('\n'.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
class BIT:
  def __init__(self, n):
    self.N = n+1
    self.bit = [0]*self.N
  
  def bit_sum(self, i):
    s = 0
    i += 1
    while i>0:
      s += self.bit[i]
      i -= i & -i
    return s

  def bit_add(self, i, n):
    i += 1
    while i<=self.N:
      self.bit[i] += n
      i += i & -i

N, *A = map(int, open(0).read().split())
inf = [(a,i) for i, a in enumerate(A)]
n = A[0]
ls = [0]
for i in range(1,N):
  if A[i]>n:
    n = A[i]
    ls.append(i)
B = BIT(N)
inf.sort(reverse=True)
cnt = [0]*N
for a,i in inf:
  B.bit_add(i,1)
  cnt[i] = B.bit_sum(N-1)-B.bit_sum(i-1)

s = sum(A)
ans = [0]*N
for i in range(len(ls)-1,0,-1):
  a = ls[i]
  b = ls[i-1]
  m = A[a]-A[b]
  ans[a] = m*cnt[a]
  s -= m*cnt[a]
ans[0] = s
print('\n'.join(map(str,ans)))
Problem p03816 (python)

Fixed submission:
N, *A = map(int, open(0).read().split())
cnt = 0
log = [0]*(max(A)+1)
for i in range(N):
  c = A[i]
  if log[c]!=0:
    cnt += 1
  else:
    log[c] = 1
if cnt%2==0:
  print(N-cnt)
else:
  print(N-cnt-1)

Buggy submission (verdict: Runtime Error):
N, *A = map(int, open('0').read().split())
cnt = 0
log = [0]*(max(A)+1)
for i in range(N):
  c = A[i]
  if log[c]!=0:
    cnt += 1
  else:
    log[c] = 1
if cnt%2==0:
  print(N-cnt)
else:
  print(N-cnt-1)
Problem p03837 (python)

Fixed submission:
from collections import defaultdict
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = defaultdict(list)
Els = []
for i in range(M):
  a, b, c = map(int, input().split())
  dic[a-1] += [(b-1,c)]
  dic[b-1] += [(a-1, c)]
  Els += [(a-1,b-1,c)]

def dijkstra(s,e):
  dist = [float('inf')]*N
  dist[s] = 0
  q = [(0,s)]
  z = -1
  while q:
    c, v = heappop(q)
    if dist[v]<c:
      continue
    dist[v] = c
    for u, m in dic[v]:
      if dist[u]>dist[v]+m:
        dist[u] = dist[v]+m
        heappush(q,(dist[u],u))
        if u==e:
          z = v
  return z

ans = 0
for a, b, c in Els:
  if dijkstra(a,b)!=a:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
from heapq import heappush, heappop
N, M = map(int, input().split())
dic = defaultdict(list)
Els = []
for i in range(M):
  a, b, c = map(int, input().split())
  dic[a-1] += [(b-1,c)]
  dic[b-1] += [(a-1, c)]
  Els += [(a,b,c)]

def dijkstra(s,e):
  dist = [float('inf')]*N
  dist[s] = 0
  q = [(0,s)]
  z = -1
  while q:
    c, v = heappop(q)
    if dist[v]<c:
      continue
    dist[v] = c
    for u, m in dic[v]:
      if dist[u]>dist[v]+m:
        dist[u] = dist[v]+m
        heappush(q,(dist[v],v))
        if u==e:
          z = v
  return z

ans = 0
for a, b, c in Els:
  if dijkstra(a,b)==a:
    ans += 1
print(ans)
Problem p03938 (python)

Fixed submission:
N, *P = map(int, open(0).read().split())
b = list(range(N*N, N-1, -N))
a = [0]*N
for i,p in enumerate(P):
  a[p-1] = N*p+i
print(*a)
print(*b)

Buggy submission (verdict: Runtime Error):
N, *P = map(int, open('0').read().split())
b = list(range(N*N, N-1, -N))
a = [0]*N
for i,p in enumerate(P):
  a[p-1] = N*p+i
print(*a)
print(*b)
Problem p03946 (python)

Fixed submission:
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1,-1):
  if st-A[i]>0:
    ls += [st-A[i]]
  else:
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
p = A[0]
flag = True
ls = []
st = A[-1]
for i in range(N-2,-1-1):
  if st-A[i]>0:
    ls += [st-A[i]]
  else:
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)

Buggy submission (verdict: Runtime Error):
N, T = map(int, input().split())
A = [int(c) for c in input().split()]
p = A[0]
flag = True
ls = []
st = A[0]
for i in range(1,N):
  if A[i]>=A[i-1]:
    flag = True
  else:
    if flag:
      ls += [A[i-1]-st]
    flag = False
    st = A[i]
ls.sort()
ans = ls.count(ls[-1])
print(ans)
Problem p03987 (python)

Fixed submission:
N = int(input())
p = [None]+[int(c) for c in input().split()]
p_to_i = [None]*(N+1)
for i, x in enumerate(p[1:],1):
  p_to_i[x] = i

tree = [0]*(N+1)

def BIT_add(i):
  while i<=N:
    tree[i] += 1
    i += i&(-i)
    
def BIT_sum(i):
  s = 0
  while 0<i:
    s += tree[i]
    i -= i&(-i)
  return s

def BIT_search(c):
  s = 0
  step = 1<<(N.bit_length()-1)
  i = 0
  while step:
    if i+step<=N and s+tree[i+step]<c:
      i += step
      s += tree[i]
    step >>= 1
  return i+1

ans = 0
for i in range(1,N+1):
  c = p_to_i[i]
  L = BIT_sum(c)
  R = i-1-L
  BIT_add(c)
  a = BIT_search(L) if L>0 else 0
  b = BIT_search(L+2) if R>0 else N+1
  m = (c-a)*(b-c)
  ans += m*i
#  print(i, ans, a, b, c, L, R)
print(ans)

Buggy submission (verdict: Runtime Error):
class BIT:
  def __init__(self,n):
    self.N = n
    self.data = [0]*(N+1)
  def bit_add(self,i,a):
    j = i+1
    while j<=N:
      self.data[j] += a
      j += j&-j
  def bit_sum(self,i):
    m = 0
    j = i+1
    while j>0:
      m += self.data[j]
      j -= j&-j
    return m
  def bit_search(self,x):
    i = 0
    m = 0
    j = 1<<(self.N.bit_length()-1)
    while j:
      if i+j<=N and self.data[i+j]+m<=x:
        i += j
        m += self.data[i]
      j >>= 1
    return i
N, *A = map(int, open('0').read().split())
bit = BIT(N)
ntoi = [0]*(N+1)
ans = 0
for i, a in enumerate(A):
  ntoi[a] = i
for i in range(1,N+1):
  j = ntoi[i]
  L = bit.bit_sum(j)
  R = N-L-1
  if L!=0:
    a = bit.bit_search(L-1)
  else:
    a = -1
  if R!=0:
    b = bit.bit_search(L)
  else:
    b = N
  ans += (j-a)*(b-j)*i
  bit.bit_add(j,1)
print(ans)

Buggy submission (verdict: Runtime Error):
class BIT:
  def __init__(self,n):
    self.N = n
    self.data = [0]*(N+1)
  def bit_add(self,i,a):
    j = i+1
    while j<=N:
      self.data[j] += a
      j += j&-j
  def bit_sum(self,i):
    m = 0
    j = i+1
    while j>0:
      m += self.data[j]
      j -= j&-j
    return m
  def bit_search(self,x):
    i = 0
    m = 0
    j = 1<<(self.N.bit_length()-1)
    while j:
      if i+j<=N and self.data[i+j]+m<=x:
        i += j
        m += self.data[i]
      j >>= 1
    return i
N, *A = map(int, open('0').read().split())
bit = BIT(N)
ntoi = [0]*(N+1)
ans = 0
for i, a in enumerate(A):
  ntoi[a] = i
for i in range(1,N+1):
  j = ntoi[i]
  L = bit.bit_sum(j)
  R = N-L-1
  if L!=0:
    a = bit.bit_search(L-1)
  else:
    a = -1
  if R!=0:
    b = bit.bit_search(L)
  else:
    b = N
  ans += (j-a)*(b-j)*i
  bit.bit_add(j,1)
print(ans)
Problem p04000 (python)

Fixed submission:
from collections import defaultdict
H, W, N, *L = map(int, open(0).read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print(*ans,sep='\n')

Buggy submission (verdict: Runtime Error):
H, W, N, *L = map(int, open('0').read().split())
dic = {}
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[i*W+j] = dic.get(i*W+j,0)+1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print('\n'.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
H, W, N, *L = map(int, open('0').read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
  for i in range(a-2,a+1):
    for j in range(b-2,b+1):
      if 0<i and i+2<=H and 0<j and j+2<=W:
        dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
  ans[dic[k]] += 1
  ans[0] -= 1
print(*ans,sep='\n')
Problem p04006 (python)

Fixed submission:
from itertools import accumulate as acc
N, x, *A = map(int, open(0).read().split())
dp = []
for i in range(N):
  dp.append(list(acc((A[(i-j)%N] for j in range(N)),min)))

ans = 10**60
for i,a in enumerate(zip(*dp)):
  ans = min(ans,i*x+sum(a))
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate as acc
N, x, *A = map(int, open(0).read().split())
dp = []
for i in range(N):
  dp.append(list(acc((A[(i-j)%N] for j in range(N)),min)))

ans = 10**10
for i,a in enumerate(zip(*dp)):
  ans = min(ans,i*x+sum(a))
print(ans)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate as acc
N, x, *A = map(int, open('0').read().split())
dp = []
for i in range(N):
  dp.append(list(acc((A[(i-j)%N] for j in range(N)),min)))

ans = 10**10
for i,a in enumerate(zip(*dp)):
  ans = min(ans,i*x+sum(a))
print(ans)
Problem p04020 (python)

Fixed submission:
N, *A = map(int, open(0).read().split())
ls = []
s = 0
ans = 0
for c in A:
  if c==0:
    ans += s//2
    s = 0
  else:
    s += c
ans += s//2
print(ans)

Buggy submission (verdict: Runtime Error):
N, *A = map(int, open('0').read().split())
ans = sum(c//2 for c in A)
A = [c%2 for c in A]
for i in range(N-2):
  if A[i]==A[i+1]==1:
    A[i+1] = 0
    ans += 1
print(ans)
Problem p02660 (python)

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

    divisors.sort()
    return divisors
def is_prime(n):
    if n == 1:
        return False
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False
    return True

def insu(num):
    from collections import defaultdict
    div_prime = [d for d in make_divisors(num) if is_prime(d)]
    res = defaultdict(int)
    for d in div_prime:
        while num % d == 0:
            num //= d
            res[d] += 1
    return res
ins = insu(N)
ans = 0
for v in ins.values():
    counter = 1
    while v >= counter:
        v -= counter
        counter += 1
        ans += 1
print(ans)

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

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]



def insu(num):
    from collections import defaultdict
    primes = get_sieve_of_eratosthenes(int(num**(1 / 2)) + 1)
    res = defaultdict(int)
    for p in primes:
        while num % p == 0:
            res[p] += 1
            num //= p
    return res
ins = insu(N)
ans = 0
for v in ins.values():
    counter = 1
    while v >= counter:
        v -= counter
        counter += 1
        ans += 1
print(ans)

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

def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]



def insu(num):
    from collections import defaultdict
    primes = get_sieve_of_eratosthenes(int(num**(1 / 2)) + 1)
    res = defaultdict(int)
    for p in primes:
        while num % p == 0:
            res.append(p)
            num //= p
    return res
ins = insu(N)
ans = 0
for v in ins.values():
    counter = 1
    while v >= counter:
        v -= counter
        counter += 1
        ans += 1
print(ans)
Problem p02690 (python)

Fixed submission:
num = [i**5 for i in range(-121, 121)]
X = int(input())
for i in range(len(num)):
    a = num[i]
    for j in range(i+1):
        if a - num[j] == X:
            print(i-121, j-121)
            exit()

Buggy submission (verdict: Runtime Error):
from math import sqrt, log, pow
num = [i**5 for i in range(-1, 150)]
c = 0
def solve(X):
    try:
        for i in range(len(num)):
            a = num[i]
            for j in range(i+1):
                if a - num[j] == X:
                    x, y = i-1, j-1
                    # print(i-1, j-1)
                    assert x**5-y**5 == X
                    return x, y
    except IndexError:
        print(0)
print(*solve(int(input())))

Buggy submission (verdict: Runtime Error):
from math import sqrt, log, pow
num = [i**5 for i in range(-1, 150)]
c = 0
def solve(X):
    try:
        for i in range(len(num)):
            a = num[i]
            for j in range(i+1):
                if a - num[j] == X:
                    x, y = i-1, j-1
                    # print(i-1, j-1)
                    assert x**5-y**5 == X
                    return x, y
    except AssertionError:
        print(0)
print(*solve(int(input())))

Buggy submission (verdict: Runtime Error):
from math import sqrt, log, pow
num = [i**5 for i in range(-1, 150)]
c = 0
def solve(X):
    for i in range(len(num)):
        a = num[i]
        for j in range(i+1):
            if a - num[j] == X:
                x, y = i-1, j-1
                # print(i-1, j-1)
                assert x**5-y**5 == X
                return x, y
print(*solve(int(input())))
Problem p02720 (python)

Fixed submission:
from collections import deque
counter = 0
todo = deque(range(1, 10))
ans = []
while counter < 10**5 + 500:
    seed = str(todo.popleft())
    ans.append(int(seed))
    counter += 1
    seed_last = seed[-1]
    for i in range(max(0, int(seed_last)-1), min(10, int(seed_last)+2)):
        todo.append(seed + str(i))

K = int(input())
print(ans[K-1])

Buggy submission (verdict: Runtime Error):
from collections import deque
K = int(input()) - 1
todo = deque(range(1, 10))
ans = []
counter = 0
while counter <= K:
    seed = todo.pop(0)
    ans.append(seed)
    counter += 1
    last_dig = int(str(seed)[-1])
    for i in range(max(0, last_dig-1), min(10, last_dig+2)):
        todo.append(int(str(seed) + str(i)))
print(ans[-1])
Problem p02742 (python)

Fixed submission:
from math import ceil

H, W = map(int, input().split())
if H == 1 or W == 1:
    print(1)
    exit()
even = ceil(H/2)
odd = H-even
ans = H*(W//2) + even*(W%2)

print(max(ans, 1))

Buggy submission (verdict: Runtime Error):
from math import sqrt
a, b, c = map(int, input().split())
if a + 2*sqrt(a)*sqrt(b) + b < c:
    print("Yes")
else:
    print("No")
Problem p02744 (python)

Fixed submission:
N = int(input())
seed = "a"
alpha = "abcdefghij"


def dfs(string, mx_ind):
    if len(string) == N:
        print(string)
    else:
        for i in range(mx_ind + 1):
            dfs(string + alpha[i], mx_ind + 1 if i == mx_ind else mx_ind)


dfs("", 0)

Buggy submission (verdict: Runtime Error):
from decimal import Decimal, getcontext
a, b, c = map(int, input().split())
getcontext().prec = 20
if Decimal(a).sqrt() + Decimal(b).sqrt() < Decimal(c).sqrt():
    print("Yes")
else:
    print("No")
Problem p02761 (python)

Fixed submission:
N, M = map(int, input().split())
ans = {}
flg = False
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        if N == 1:
            flg = True
            ans[s] = c
        else:
            print(-1)
            exit()
    else:
        if s in ans.keys():
            if c != ans[s]:
                print(-1)
                exit()
        else:
            ans[s] = c
if flg:
    print(0)
else:
    if N >= 2:
        num = ["1"] + ["0"]*(N-1)
        for k, v in ans.items():
            num[k-1] = str(v)
        print("".join(num))
    else:
        if ans.keys():
            print(ans[1])
        else:
            print(0)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
ans = {}
flg = False
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        if N == 1:
            flg = True
            ans[s] = c
        else:
            print(-1)
            exit()
    else:
        if s in ans.keys():
            if c != ans[s]:
                print(-1)
                exit()
        else:
            ans[s] = c
if flg:
    print(0)
else:
    if N >= 2:
        num = ["1"] + ["0"]*(N-1)
        for k, v in ans.items():
            num[k-1] = str(v)
        print("".join(num))
    else:
        print(ans[1])
Problem p02845 (python)

Fixed submission:
N = int(input())
Alist = list(map(int, input().split()))
nums = [0, 0, 0]
ans = 1
for i in range(N):
    try:
        A = Alist[i]
        ans = (ans * nums.count(A)) % (10**9 + 7)
        nums[nums.index(A)] += 1
    except:
        print(0)
        break
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
Alist = list(map(int, input().split()))
abc = [0, 0, 0]
ans = 1
for i in range(N):
    A = Alist[i]
    ans = (ans * abc.count(A)) % (10**9 + 7)
    abc[abc.index(A)] += 1

print(ans)
Problem p02866 (python)

Fixed submission:
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    for i in range(1, max(Dlist) + 1):
        num *= DCounter[i - 1] ** DCounter[i]

    print(num % 998244353)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    mae = 1
    for key, value in sorted(DCounter.items()[1:]):
        num *= (mae ** value)
        mae = value
        num %= 998244353
    print(num % 998244353)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
Dlist = list(map(int, input().split()))
DCounter = Counter(Dlist)
if DCounter[0] == 1 and Dlist[0] == 0:
    num = 1
    mae = 1
    for key, value in sorted(Dlist.items()):
        num *= (mae ** value)
        mae = value
        num %= 998244353
    print(num % 998244353)
else:
    print(0)
Problem p02886 (python)

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

all = 0
for i1, d1 in enumerate(dlist):
  for d2 in dlist[i1+1:]:
    all += d1*d2

print(all)

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

all = 0
for i1, d1 in enumrate(dlist):
  for i2, d2 in enumrate(dlist):
    if i1 != i2:
      all += d1*d2

print(all)
Problem p02889 (python)

Fixed submission:
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
inf = float("inf")
N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="D")
graph = np.full((N, N), inf)
for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1

Q = int(input())
def int_(num_str):
    return int(num_str) - 1

costs = shortest_path(csr_matrix(graph), directed=False, method="D")
for _ in range(Q):
    s, t = map(int_, input().split())
    print(int(costs[s][t])-1 if costs[s][t] != inf else -1)

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
inf = float("inf")
N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="WF")
graph = np.full((N, N), inf)
for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1

Q = int(input())
def int_(num_str):
    return int(num_str) - 1

costs = shortest_path(csr_matrix(graph), directed=False, method="WF")
for _ in range(Q):
    s, t = map(int_, input().split())
    print(int(costs[s][t])-1 if costs[s][t] != inf else -1)

Buggy submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
inf = float("inf")
N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
shortest_paths = shortest_path(csr_matrix(graph), directed=False, method="D")
graph = np.full((N, N), inf)
for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1

Q = int(input())
def int_(num_str):
    return int(num_str) - 1

costs = shortest_path(csr_matrix(graph), directed=False, method="D")
for _ in range(Q):
    s, t = map(int_, input().split())
    print(int(costs[s][t])-1 if costs[s][t] != inf else -1)
Problem p02947 (python)

Fixed submission:
from collections import Counter
N = int(input())
slist = ["".join(sorted(list(input()))) for _ in range(N)]
c = Counter(slist)
ans = 0
for v in c.values():
    ans += sum(range(v))
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
c = Counter([sorted(input()) for _ in range(N)])
print(sum([(v*(v+1))//2 for v in c.values()]))
Problem p02972 (python)

Fixed submission:
N = int(input())
alist = list(map(int, input().split()))
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors

balls_multiple = [0] * N
ans = []
for num in range(N-1, -1, -1):
    if balls_multiple[num] % 2 != alist[num]:
        ans.append(num+1)
        for div in make_divisors(num+1):
            balls_multiple[div-1] += 1
if ans:
    print(len(ans))
    print(*sorted(ans))
else:
    print(0)

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

    divisors.sort()
    return divisors

balls_multiple = [0] * N
ans = []
for num in range(N-1, -1, -1):
    if balls_multiple[num] % 2 != alist[num]:
        ans.append(num+1)
        for div in make_divisors(num+1):
            balls_multiple[div-1] += 1
if ans:
    print(len(ans))
    print(*sorted(ans))
else:
    print(0)