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

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

H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

direction = True
here = 0
answer = []
for i in range(H):
    if direction:
        while here < W:
            if here == W - 1:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = False
                break
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here + 1] += 1
                answer.append([i, here, i, here + 1])
                here += 1
            else:
                here += 1
    else:
        while -1 < here:
            if here == 0:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = True
                break
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here - 1] += 1
                answer.append([i, here, i, here - 1])
                here -= 1
            else:
                here -= 1

print(len(answer))
for i in answer:
    print(' '.join(map(str, [j + 1 for j in i])))

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(H)]

direction = True
here = 0
answer = []
for i in range(H):
    if direction:
        while here < W:
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here + 1] += 1
                answer.append([i, here, i, here + 1])
                here += 1
            else:
                here += 1
            if here == W - 1:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = False
                break
    else:
        while 0 < here:
            if a[i][here] % 2 == 1:
                a[i][here] -= 1
                a[i][here - 1] += 1
                answer.append([i, here, i, here - 1])
                here -= 1
            else:
                here -= 1
            if here == 0:
                if i == H - 1:
                    break
                if a[i][here] % 2 == 1:
                    a[i][here] -= 1
                    a[i + 1][here] += 1
                    answer.append([i, here, i + 1, here])
                direction = True
                break

print(len(answer))
for i in answer:
    print(' '.join(map(str, [j + 1 for j in i])))
Problem p03283 (python)

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

N, M, Q = map(int, input().split())
# city[L][R]
city = [[0] * (N + 1) for _ in range(N + 2)]

for _ in range(M):
    L, R = map(int, input().split())
    city[L][R] += 1

city = np.array(city).reshape(N + 2, N + 1)
np.cumsum(city, axis=0, out=city)
np.cumsum(city, axis=1, out=city)

for _ in range(Q):
    p, q = map(int, input().split())
    print(city[q][q] - city[q][p - 1] - city[p - 1][q] + city[p - 1][p - 1])

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
buf = sys.stdin.buffer

N, M, Q = map(int, buf.readline().split())
city = np.zeros((N + 1, N + 1), dtype='int32')
L, R = np.array(buf.read((N + 2) * M).split(), dtype='int32').reshape(M, 2).T
p, q = np.array(buf.read((N + 2) * Q).split(), dtype='int32').reshape(Q, 2).T

np.add.at(city, (L, R), 1)
np.cumsum(city, axis=0, out=city)
np.cumsum(city, axis=1, out=city)

p -= 1
answer = city[q, q] - city[p, q] - city[q, p] + city[p, p]
print('\n'.join(answer.astype(str)))
Problem p03289 (python)

Fixed submission:
S = list(input())

if S[0] == 'A' and S[2:- 1].count('C') == 1:
    S.remove('A')
    S.remove('C')
    if ''.join(S).islower():
        print('AC')
    else:
        print('WA')
else:
    print('WA')

Buggy submission (verdict: Runtime Error):
S = list(input())

if S[0] == 'A' and S[2:- 1].count('C') == 1:
    S.remove('A').remove('C')
    if ''.join(S).islower:
        print('AC')
    else:
        print('WA')
else:
    print('WA')
Problem p03324 (python)

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

if N != 100:
    print(N * 100 ** D)
else:
    print((N + 1) * 100 ** D)

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

print(N * 100 ** D)D, N = map(int, input().split())

if N != 100:
    print(N * 100 ** D)
else:
    print((N + 1) * 100 ** D)
Problem p03450 (python)

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

N, M = map(int, readline().split())

if M == 0:
    print('Yes')
    exit()

LRD = map(int, read().split())
graph = [[] for _ in range(N + 1)]

# 根からの距離、根は複数の可能性あり
distance = [-1] * (N + 1)
child = [0] * (N + 1)

for L, R, D in zip(LRD, LRD, LRD):
    graph[L].append((R, D))
    child[R] = 1

for i in range(1, N + 1):
    if child[i]:
        continue

    # 以下iは根
    distance[i] = 0
    stack = [i]
    while stack:
        V = stack.pop()
        for v, d in graph[V]:
            if distance[v] == -1:
                distance[v] = distance[V] + d
                stack.append(v)
            else:
                if distance[v] != distance[V] + d:
                    print('No')
                    exit()

# 例4のような循環タイプは上のfor内で処理されない
if -1 in set(distance[1:]):
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline
read = sys.stdin.read


    def main():
    N, M = map(int, readline().split())

    if M == 0:
        print('Yes')
        exit()

    *LRD, = map(int, read().split())
    graph = [[] for _ in range(N + 1)]

    # 根からの距離、根は複数の可能性あり
    distance = [-1] * (N + 1)
    child = [False] * (N + 1)

    for L, R, D in zip(*[iter(LRD)] * 3):
        graph[L].append((R, D))
        child[R] = True

    for i in range(1, N + 1):
        if child[i]:
            continue

        # 以下iは根
        distance[i] = 0
        stack = [i]
        while stack:
            V = stack.pop()
            for v, d in graph[V]:
                if distance[v] == -1:
                    distance[v] = distance[V] + d
                else:
                    if distance[v] != distance[V] + d:
                        print('No')
                        exit()

                stack.append(v)

    # 例4のような循環タイプは上のfor内で処理されない
    if -1 in distance[1:]:
        print('No')
    else:
        print('Yes')


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

Fixed submission:
import sys
import numpy as np
from collections import Counter

read = sys.stdin

N, K = map(int, read.readline().split())
k = 2 * K
xyc = np.array(read.read().split(), np.str).reshape(-1, 3)
x = xyc[:, 0].astype(int)
y = xyc[:, 1].astype(int)
c = xyc[:, 2]

x = np.where(c == 'B', x - K, x)
x %= k
y %= k

'''
# grid[[1,2],[1,2]]+=1 としてもgrid[1,2]=1であり重複は考慮されない。
# uniqueを使って(x,y)の重複をカウントする
# return_countはver1.9からだった・・・ ダメじゃん
xy, cnt = np.unique(x + y * 10000, return_counts=True)
x = xy % 10000
y = xy // 10000
'''
xy = Counter(list(zip(x, y)))
cnt = np.array(list(xy.values()), np.int64)
xy = np.array(list(xy.keys()), np.int64)
x = xy[:, 0]
y = xy[:, 1]

grid = np.zeros((3 * K, 3 * K), np.int64)
grid[x, y] += cnt
grid[x + K, y + K] += cnt
grid[x + K, y] -= cnt
grid[x, y + K] -= cnt
np.cumsum(grid, axis=0, out=grid)
np.cumsum(grid, axis=1, out=grid)

p1 = grid[:K, :K] + grid[k:, k:] + grid[K:k, K:k] + grid[k:, :K] + grid[:K, k:]
p2 = grid[K:k, :K] + grid[K:k, k:] + grid[:K, K:k] + grid[k:, K:k]
print(max(p1.max(), p2.max()))

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

read = sys.stdin

N, K = map(int, read.readline().split())
k = 2 * K
xyc = np.array(read.read().split(), np.str).reshape(-1, 3)
x = xyc[:, 0].astype(int)
y = xyc[:, 1].astype(int)
c = xyc[:, 2]

x = np.where(c == 'B', x - K, x)
x %= k
y %= k

# grid[[1,2],[1,2]]+=1 としてもgrid[1,2]=1であり重複は考慮されない。
# uniqueを使って(x,y)の重複をカウントする
xy, cnt = np.unique(x + y * 10000, return_counts=True)
x = xy % 10000
y = xy // 10000

grid = np.zeros((3 * K, 3 * K), np.int64)
grid[x, y] += cnt
grid[x + K, y + K] += cnt
grid[x + K, y] -= cnt
grid[x, y + K] -= cnt
np.cumsum(grid, axis=0, out=grid)
np.cumsum(grid, axis=1, out=grid)

p1 = grid[:K, :K] + grid[k:, k:] + grid[K:k, K:k] + grid[k:, :K] + grid[:K, k:]
p2 = grid[K:k, :K] + grid[K:k, k:] + grid[:K, K:k] + grid[k:, K:k]
print(max(p1.max(), p2.max()))
Problem p03503 (python)

Fixed submission:
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
l = [format(i, 'b').zfill(10) for i in range(1, 2 ** 10)]
ans = []

for i in l:
    c = [0] * N
    for j in range(10):
        if i[j] == '1':
            for k in range(N):
                if F[k][j] == 1:
                    c[k] += 1
                else:
                    continue
        else:
            continue
    temp = 0
    for j in range(N):
        temp += P[j][c[j]]
    ans.append(temp)

print(max(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
F = [list(map(int, input().split())) for i in range(N)]
P = [list(map(int, input().split())) for i in range(N)]
l = [format(i, 'b').zfill(10) for i in range(1, 2 ** 10)]
ans = []

for i in l:
    c = [0] * 
    for j in range(10):
        if i[j] == '1':
            for k in range(N):
                if F[k][j] == 1:
                    c[k] += 1
                else:
                    continue
        else:
            continue
    temp = 0
    for j in range(N):
        temp += P[j][c[j]]
    ans.append(temp)

print(max(ans))
Problem p03569 (python)

Fixed submission:
s = input()

l = 0
r = len(s) - 1
answer = 0

while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        l += 1
        answer += 1
    elif s[r] == 'x':
        r -= 1
        answer += 1
    else:
        print(-1)
        exit()

print(answer)

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

l = 0
r = len(s) - 1
answer = 0

while l != r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    elif s[l] == 'x':
        l += 1
        answer += 1
    elif s[r] == 'x':
        r -= 1
        answer += 1
    else:
        print(-1)
        exit()

print(answer)

Buggy submission (verdict: Runtime Error):
from collections import deque

s = deque(input())
answer = 0

if len(s) == 1:
    print(0)
    exit()

l = ''
r = ''

while l == '' or r == '':
    if s:
        if l == '':
            l = s.popleft()
        if r == '':
            r = s.pop()

    if l == r:
        l = ''
        r = ''
    elif l == 'x':
        answer += 1
        l = ''
    elif r == 'x':
        answer += 1
        r = ''
    elif r == '' or l == '':
        break
    else:
        print(-1)
        exit()

print(answer)
Problem p03578 (python)

Fixed submission:
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

d = Counter(D)
t = Counter(T)
for key, value in t.items():
    if d.get(key, 0) < value:
        print('NO')
        exit()
else:
    print('YES')

Buggy submission (verdict: Runtime Error):
from collections import Counter

N = int(input())
D = int, input().split()
M = int(input())
T = input().split()

d = Counter(D)
t = Counter(T)
for key, value in t.items():
    if d.get(key, 0) < value:
        print('NO')
        exit()
else:
    print('YES')
Problem p03608 (python)

Fixed submission:
import sys
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline

N, M, R = map(int, readline().split())
r = list(map(int, readline().split()))

INF = float('inf')
graph = [[INF] * (N + 1) for _ in range(N + 1)]
ABC = map(int, read().split())

for i in range(N + 1):
    graph[i][i] = 0

for A, B, C in zip(*[iter(ABC)] * 3):
    graph[A][B] = C
    graph[B][A] = C

distance = floyd_warshall(graph, directed=False)
answer = 10 ** 9
for tour in permutations(r):
    tmp = 0
    for i in range(R - 1):
        tmp += distance[tour[i]][tour[i + 1]]

    if tmp < answer:
        answer = tmp

print(int(answer))

Buggy submission (verdict: Runtime Error):
import sys
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline

N, M, R = map(int, readline().split())
r = list(map(int, readline().split()))
ABC = map(int, read().split())
A, B, C = map(list, zip(*zip(ABC, ABC, ABC)))

for i in range(N + 1):
    A.append(i)
    B.append(i)
    C.append(0)

csr = csr_matrix((C, (A, B)), (N + 1, N + 1))
distance = shortest_path(csr, directed=False)

answer = 10 ** 9
for tour in permutations(r):
    tmp = 0
    for i, j in zip(tour, tour[1:]):
        tmp += distance[i][j]

    if tmp < answer:
        answer = tmp

print(int(answer))

Buggy submission (verdict: Runtime Error):
import sys
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline

N, M, R = map(int, readline().split())
r = list(map(int, readline().split()))
ABC = map(int, read().split())
A, B, C = map(list, zip(*zip(ABC, ABC, ABC)))
A.append(0)
B.append(0)
C.append(0)

csr = csr_matrix((C, (A, B)), (N + 1, N + 1))
distance = shortest_path(csr, directed=False)

answer = 10 ** 9
for tour in permutations(r):
    tmp = 0
    for i, j in zip(tour, tour[1:]):
        tmp += distance[i][j]

    if tmp < answer:
        answer = tmp

print(int(answer))

Buggy submission (verdict: Runtime Error):
import sys
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import coo_matrix
from itertools import permutations
read = sys.stdin.read
readline = sys.stdin.readline

N, M, R = map(int, readline().split())
r = list(map(int, readline().split()))
ABC = map(int, read().split())

INF = float('inf')

ABC = zip(ABC, ABC, ABC)
A, B, C = zip(*ABC)

csr = coo_matrix((C, (A, B)), (N + 1, N + 1))
distance = shortest_path(csr, directed=False)

answer = 10 ** 9
for tour in permutations(r):
    tmp = 0
    for i, j in zip(tour, tour[1:]):
        tmp += distance[i][j]

    if tmp < answer:
        answer = tmp

print(int(answer))
Problem p03660 (python)

Fixed submission:
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
read = sys.stdin.read

N, *ab = map(int, read().split())
a, b = zip(*zip(*[iter(ab)] * 2))

graph = csr_matrix(([1] * (N - 1), (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False, indices=[1, N])
d1 = distance[0]
dn = distance[1]

Fennec = -1
for i, j in zip(d1, dn):
    if i <= j:
        Fennec += 1

if Fennec > N - Fennec:
    print('Fennec')
else:
    print('Snuke')

Buggy submission (verdict: Runtime Error):
import sys
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import shortest_path
read = sys.stdin.read

N, *ab = map(int, read().split())

graph = csr_matrix(([1] * (N - 1), (ab[::2], ab[1::2])), shape=(N + 1, N + 1))
distance = shortest_path(graph, directed=False, indices=[1, N])
d1 = distance[0]
dn = distance[1]

Fennec = -1
for i, j in zip(d1, dn):
    if i <= j:
        Fennec += 1

if Fennec > N - Fennec:
    print('Fennec')
else:
    print('Sunuke')
Problem p03682 (python)

Fixed submission:
import sys
import numpy as np
read = sys.stdin.read


class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if self.root[x] < 0:
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]

    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if x == y:
            return
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif self.rnk[x] > self.rnk[y]:
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if self.rnk[x] == self.rnk[y]:
                self.rnk[y] += 1

    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]


N, *xy = map(int, read().split())
xy = np.array(xy, np.int64).reshape(N, 2)

town = np.arange(N)
arg_x = np.argsort(xy[:, 0])
arg_y = np.argsort(xy[:, 1])

edges_x = xy[arg_x[1:], 0] - xy[arg_x[:-1], 0]
town_x = zip(town[arg_x[1:]], town[arg_x[:-1]])
edges_y = xy[arg_y[1:], 1] - xy[arg_y[:-1], 1]
town_y = zip(town[arg_y[1:]], town[arg_y[:-1]])

edges = list(zip(edges_x, town_x)) + list(zip(edges_y, town_y))
edges.sort()

tree = UnionFind(N)
answer = 0

for d, (t1, t2) in edges:
    if tree.isSameGroup(t1, t2):
        continue

    tree.Unite(t1, t2)
    answer += d

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import minimum_spanning_tree
read = sys.stdin.read

N, *xy = map(int, read().split())
xy = np.array(xy, np.int64).reshape(N, 2)
x = xy[:, 0]
y = xy[:, 1]

town = np.arange(N)
arg_x = np.argsort(x)
arg_y = np.argsort(y)

edges_x = x[arg_x[1:]] - x[arg_x[:-1]]
town_x = town[arg_x]

edges_y = y[arg_y[1:]] - y[arg_y[:-1]]
town_y = town[arg_y]

edges = np.concatenate([edges_x, edges_y])
towns_1 = np.concatenate([town_x[1:], town_y[1:]])
towns_2 = np.concatenate([town_x[:-1], town_y[:-1]])

graph = csr_matrix((edges, (towns_1, towns_2)), shape=(N, N))
tree = minimum_spanning_tree(graph, overwrite=True).astype(dtype='int')
answer = tree.sum()

print(answer)
Problem p03729 (python)

Fixed submission:
A, B, C = input().split()

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

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

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')

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

if A[-1] == B[0] and B[-1] == C[0]:
    print('YES')
else:
    print('NO')
Problem p03732 (python)

Fixed submission:
import sys
from itertools import accumulate, product
from operator import itemgetter
read = sys.stdin.read

N, W, *wv = map(int, read().split())
w1 = wv[0]
V = [[0] for _ in range(4)]

for w, v in sorted(zip(*[iter(wv)] * 2), key=itemgetter(1), reverse=True):
    V[w - w1].append(v)


V = list(map(list, map(accumulate, V)))
n = [len(V[i]) for i in range(4)]
answer = 0
for a, b, c, d in product(range(n[0]), range(n[1]), range(n[2]), range(n[3])):
    if b + c * 2 + d * 3 + (a + b + c + d) * w1 > W:
        continue

    v = V[0][a] + V[1][b] + V[2][c] + V[3][d]
    if v > answer:
        answer = v

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.read

N, W, *wv = map(int, read().split())
dp = np.zeros((W + 1, N + 1), np.int64)
idx = 1

for w, v in zip(*[iter(wv)] * 2):
    dp[:, idx] = dp[:, idx - 1]
    if w <= W:
        dp[w:, idx] = np.maximum(dp[w:, idx], dp[:-w, idx] + v)
    idx += 1

print(dp[-1, -1])

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.read

N, W, *wv = map(int, read().split())
dp = np.zeros((W + 1, N + 1), np.int64)
idx = 1

for w, v in zip(*[iter(wv)] * 2):
    if w > W:
        continue

    dp[:, idx] = dp[:, idx - 1]
    dp[w:, idx] = np.maximum(dp[w:, idx], dp[:-w, idx] + v)
    idx += 1

print(dp[-1, -1])

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.read

N, W, *wv = map(int, read().split())
dp = np.zeros((W + 1, N + 1), np.int64)
idx = 1

for w, v in zip(*[iter(wv)] * 2):
    if w > W:
        continue

    dp[:, idx] = dp[:, idx - 1]
    dp[w:, idx] = np.maximum(dp[w:, idx], dp[:W - w + 1, idx] + v)
    idx += 1

print(dp[-1, -1])

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
read = sys.stdin.read

N, W, *wv = map(int, read().split())
dp = np.zeros((W + 1, N + 1), np.int64)
idx = 1

for w, v in zip(*[iter(wv)] * 2):
    dp[:, idx] = dp[:, idx - 1]
    dp[w:, idx] = np.maximum(dp[w:, idx], dp[:W - w + 1, idx] + v)
    idx += 1

print(dp[-1, -1])
Problem p03759 (python)

Fixed submission:
a, b, c = map(int, input().split())

if b - a == c - b:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
a, b, c = input().split()

if b - a == c - b:
    print('YES')
else:
    print('NO')
Problem p03777 (python)

Fixed submission:
a, b = map(str, input().split())

if a == b:
    print('H')
else:
    print('D')

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

if a == b:
    print('H')
else:
    print('D')
Problem p03837 (python)

Fixed submission:
import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
read = sys.stdin.read

N, M, *abc = map(int, read().split())
a, b, c = zip(*zip(*[iter(abc)] * 3))

graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False)

answer = 0

for i, j, k in zip(a, b, c):
    k = float(k)
    if k == distance[i][j]:
        continue

    for s in range(1, N + 1):
        if i == s or j == s:
            continue

        if k + distance[j][s] == distance[i][s]:
            break

        if k + distance[i][s] == distance[j][s]:
            break

    else:
        answer += 1

print(answer)

Buggy submission (verdict: Runtime Error):
import sys
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix
from itertools import combinations
read = sys.stdin.read

N, M, *abc = map(int, read().split())
a, b, c = zip(*zip(*[iter(abc)] * 3))

graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = shortest_path(graph, directed=False)

answer = 0

for i, j in zip(a, b):
    for s in range(1, N + 1):
        if distance[i][j] + distance[j][s] == distance[i][s]:
            continue

        if distance[j][i] + distance[i][s] == distance[j][s]:
            continue

        answer += 1

print(answer)
Problem p03910 (python)

Fixed submission:
from itertools import accumulate
from math import sqrt
from bisect import bisect_left

N = int(input())
n = list(accumulate(range(int(sqrt(2 * N)) + 2)))

r = bisect_left(n, N)

if n[r] == N:
    print('\n'.join(map(str, range(1, r + 1))))
    exit()

d = n[r] - N
for i in range(1, r + 1):
    if i != d:
        print(i)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from math import sqrt, floor
from bisect import bisect_left

N = int(input())
n = list(accumulate(range(floor(sqrt(2 * N)) + 1)))

r = bisect_left(n, N)

if n[r] == N:
    print('\n'.join(map(str, range(1, r + 1))))
    exit()

d = n[r] - N
for i in range(1, r + 1):
    if i != d:
        print(i)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from math import sqrt
from bisect import bisect_left

N = int(input())
n = list(accumulate(range(int(sqrt(N)) + 5)))

r = bisect_left(n, N)

if n[r] == N:
    print('\n'.join(map(str, range(1, r + 1))))
    exit()

d = n[r] - N
for i in range(1, r + 1):
    if i != d:
        print(i)

Buggy submission (verdict: Runtime Error):
from itertools import accumulate
from math import sqrt
from bisect import bisect_left

N = int(input())
n = list(accumulate(range(int(sqrt(N)) + 3)))

r = bisect_left(n, N)

if n[r] == N:
    print('\n'.join(map(str, range(1, r + 1))))
    exit()

d = n[r] - N
for i in range(1, r + 1):
    if i != d:
        print(i)