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

Fixed submission:
n = int(input())
ans=0
if n == 1:
  print(0)
  quit()

#test = 0
#for i in range(1, n):
#  if n//i == n%i:
#    test+=i
#print(test)
  
for i in range(1, n):
  #余り、商がi
  temp=n-i
  syou=temp/i
  #print(syou)
  if syou>i:
    if syou.is_integer():
      ans+=int(syou)
  else:
    break
print(ans)

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

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab = list(map(lambda x: [x[0], x[1], x[0]+x[1]], ab))
ab.sort(key=lambda x:x[2], reverse=True)
ab=deque(ab)
count = 0
ans=0
while len(ab)>0:
  a, b, dif = ab.popleft()
  if count%2==0:
    ans+=a
  else:
    ans-=b
  count+=1
print(ans)

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

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab = list(map(lambda x: [x[0], x[1], x[0]+x[1]], ab))
ab.sort(key=lambda x:x[2], reverse=True)
ab=deque(ab)
count = 0
ans=0
while len(ab)>0:
  a, b, dif = ab.popleft()
  if count%2==0:
    ans+=a
  else:
    ans-=b
  count+=1
print(ans)
Problem p03262 (python)

Fixed submission:
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 make_codivisors(n):
    divisors = []
    n0divisors = make_divisors(n[0])
    n0len = len(n0divisors)
    for i in n0divisors:
        for j in range(1, len(n)):
            if n[j] % i != 0:
                break
            if j == len(n)-1:
                divisors.append(i)
            
    # divisors.sort()
    return max(divisors)


n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(x)
a.sort()
b = [a[i]-a[i-1] for i in range(1, n+1)]

#print(b)
#print(a)
if len(b) >= 2:
  print(make_codivisors(b))
else:
  print(b[0])

Buggy submission (verdict: Runtime Error):
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 make_codivisors(n):
    divisors = []
    n0divisors = make_divisors(n[0])
    n0len = len(n0divisors)
    for i in n0divisors:
        for j in range(1, len(n)):
            if n[j] % i != 0:
                break
            if j == len(n)-1:
                divisors.append(i)
            
    # divisors.sort()
    return max(divisors)


n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(x)
a.sort()
b = [a[i]-a[i-1] for i in range(1, n+1)]

#print(b)
#print(a)

print(make_codivisors(b))

Buggy submission (verdict: Runtime Error):
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 make_codivisors(n):
    divisors = []
    n0divisors = make_divisors(n[0])
    n0len = len(n0divisors)
    for i in n0divisors:
        for j in range(1, len(n)):
            if n[j] % i != 0:
                break
            if j == len(n)-1:
                divisors.append(i)
            
    # divisors.sort()
    return max(divisors)


n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
a.append(x)
a.sort()
b = [a[i]-a[i-1] for i in range(1, n+1)]

print(b)
print(a)

print(make_codivisors(b))
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()
b.sort()
c.sort()

bc = [0]*n
bc[n-1]=n-bisect.bisect_right(c, b[n-1])

for i in range(0,n-1):
  bc[n-2-i]=bc[n-1-i] + n-bisect.bisect_right(c, b[n-2-i])

ans = 0
for i in range(n):
  temp = bisect.bisect_right(b, a[i])
  if temp != n:  
    ans += bc[temp]
  
print(ans)

Buggy submission (verdict: Runtime Error):
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()
b.sort()
c.sort()

bc = [0]*n
bc[n-1]=n-bisect.bisect_right(c, b[n-1])

for i in range(0,n-1):
  bc[n-2-i]=bc[n-1-i] + n-bisect.bisect_right(c, b[n-2-i])

ans = 0
for i in range(n):
  ans += bc[bisect.bisect_right(b, a[i])]
  
print(ans)
Problem p03575 (python)

Fixed submission:

def solve(pos):
  for i in range(n):
    if line[pos][i] == 1 and reach[i] == 0:
      reach[i] = 1
      solve(i)
  return

n, m = list(map(int, input().split()))
line = [[0]*n for i in range(n)]
ms = []

for i in range(m):
  a, b = list(map(int, input().split()))
  line[a-1][b-1]=1
  line[b-1][a-1]=1
  ms.append([a, b])
  
ans = 0
for i in range(m):
  line[ms[i][0]-1][ms[i][1]-1]=0
  line[ms[i][1]-1][ms[i][0]-1]=0
  reach=[0]*n
  reach[0]=1
  solve(0)
  if 0 in reach:
    ans += 1
  line[ms[i][0]-1][ms[i][1]-1]=1
  line[ms[i][1]-1][ms[i][0]-1]=1
print(ans)

Buggy submission (verdict: Runtime Error):

def solve(pos):
  for i in range(m):
    if line[pos][i] == 1 and reach[i] == 0:
      reach[i] = 1
      solve(i)
  return

n, m = list(map(int, input().split()))
line = [[0]*n for i in range(n)]
ms = []
for i in range(m):
  a, b = list(map(int, input().split()))
  line[a-1][b-1]=1
  line[b-1][a-1]=1
  ms.append([a, b])
  
ans = 0
for i in range(m):
  line[ms[i][0]-1][ms[i][1]-1]=0
  line[ms[i][1]-1][ms[i][0]-1]=0
  reach=[0]*n
  reach[0]=1
  solve(0)
  if 0 in reach:
    ans += 1
  line[ms[i][0]-1][ms[i][1]-1]=1
  line[ms[i][1]-1][ms[i][0]-1]=1
print(ans)
Problem p04026 (python)

Fixed submission:
s = input()
l = len(s)
for i in range(l-2):
  temp = s[i]
  if s[i+1]==temp:
    print(str(i+1)+" "+str(i+2))
    quit()
  if s[i+2]==temp:
    print(str(i+1)+" "+str(i+3))
    quit()
    
if s[-1]==s[-2]:
  print(str(l-1)+ " "+str(l))
  quit()
print("-1 -1")

Buggy submission (verdict: Runtime Error):
s = input()
l = len(s)
for i in range(l-2):
  temp = s[i]
  if s[i+1]==temp:
    print(str(i+1)+" "+str(i+2))
    quit()
  if s[i+2]==temp:
    print(str(i+1)+" "+str(i+3))
    quit()
if s[i+1]==s[i+2]:
  print(str(i+2)+ " "+str(i+3))
  quit()
print("-1 -1")
Problem p02684 (python)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
graph = [set() for i in range(N)]
for i, a in enumerate(A):
    graph[i].add(a - 1)

queue = [0]
seen = {0}
path = []
while queue:
    new = []
    for cur in queue:
        path.append(cur)
        for nei in graph[cur]:
            if nei not in seen:
                new.append(nei)
                seen.add(nei)
    queue = new

if 0 in graph[path[-1]]:
    rest = K % len(path)
    print(path[rest] + 1)
else:
    if K < len(path):
        print(path[K] + 1)
    else:
        start = graph[path[-1]].pop()
        index = path.index(start)
        rest = (K - len(path[:index])) % len(path[index:])
        print(path[index:][rest] + 1)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
graph = [set() for i in range(N)]
for i, a in enumerate(A):
    graph[i].add(a - 1)

stack = [0]
seen = {0}
path = []
dist = [-1] * N
while stack:
    cur = stack.pop()
    if dist[cur] != -1:
        break
    dist[cur] = len(path)
    path.append(cur)
    for nei in graph[cur]:
        if nei not in seen:
            stack.append(nei)
            seen.add(nei)

not_loop = graph[cur].pop()
loop = len(path) - not_loop
if K < not_loop:
    print(path[K] + 1)
else:
    K -= not_loop
    K %= loop
    print(path[not_loop + K - 1] + 1)
Problem p02696 (python)

Fixed submission:
def target(x):
    return (A * x) // B - A * (x // B)


A, B, N = map(int, input().split())
print(target(min(B - 1, N)))

Buggy submission (verdict: Runtime Error):
from decimal import *


def target(x):
    x = Decimal(x)
    return (A * x).divmod(B) - A * (x.divmod(B))


A, B, N = map(int, input().split())
A = Decimal(A)
B = Decimal(B)

left = 1
right = N

while right - left > 1:
    mid = left + (right - left) // 2
    y = target(mid)
    prv = target(mid - 1)
    nxt = target(mid + 1)
    if prv <= y <= nxt:
        left = mid
    else:
        right = mid


print(target(right))

Buggy submission (verdict: Runtime Error):
from decimal import *


def target(x):
    x = Decimal(x)
    return (A * x).divmod(B) - A * (x.divmod(B))


A, B, N = map(int, input().split())
A = Decimal(A)
B = Decimal(B)

left = 1
right = N

while right - left > 1:
    mid = left + (right - left) // 2
    y = target(mid)
    prv = target(mid - 1)
    nxt = target(mid + 1)
    if prv <= y <= nxt:
        left = mid
    else:
        right = mid


print(target(right))
Problem p02702 (python)

Fixed submission:
S = list(input())
n = len(S)
cur = 0
count = [0] * 2020
count[0] = 1
for i, c in enumerate(map(int, S[::-1])):
    cur = (cur + c * pow(10, i, 2019)) % 2019
    count[cur] += 1
    
print(sum(c * (c - 1) // 2 for c in count))

Buggy submission (verdict: Runtime Error):
S = input()
n = len(S)
prefix = [''] * (n + 1)
for i, c in enumerate(S, start=1):
    prefix[i] = prefix[i - 1] + c
res = 0
count = [0] * 2020
for i in range(1, n + 1):
    num = int(prefix[i])
    if num % 2019 == 0:
        res += 1
    temp = (num * 10 ** (n - i)) % 2019
    res += count[temp]
    count[temp] += 1
print(res)
Problem p02743 (python)

Fixed submission:
from decimal import Decimal, getcontext

getcontext().prec = 100

a, b, c = map(Decimal, input().split())
if a + b + Decimal(2) * (a * b).sqrt() < c:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import math


a, b, c = map(int, input().split())
if math.log2(a + b + 2 * ((a * b) ** .5)) < math.log2(c):
    print('Yes')
else:
    print('No')
Problem p02783 (python)

Fixed submission:
import math

H, A = map(int, input().split())
print(math.ceil(H / A))

Buggy submission (verdict: Runtime Error):
H, N = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
dp = [float('inf')] * (H + 1)
dp[0] = 0
for h in range(H + 1):
    for a, b in AB:
        h_new = min(h + a, H)
        dp[h_new] = min(dp[h] + b, dp[h_new])
print(dp[-1])
Problem p02795 (python)

Fixed submission:
W = int(input())
H = int(input())
N = int(input())
longer = max(W, H)
res = cur = 0
while cur < N:
    cur += longer
    res += 1
print(res)

Buggy submission (verdict: Runtime Error):
N, K, S = map(int, input().split())
arr = [1 if S > N else S + 1] * N
for i in range(K):
    arr[i] = S
print(arr)
Problem p02811 (python)

Fixed submission:
k, x = map(int, input().split())
if 500 * k >= x:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
k, x = map(int, input())
if 500 * k >= x:
  print('Yes')
else:
  print('No')
Problem p02861 (python)

Fixed submission:
import math
from itertools import combinations, permutations

def dist(x1, y1, x2, y2):
    return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** .5


n = int(input())
xy = [[int(i) for i in input().split()] for _ in range(n)]
edges = list(range(n))
memo = {}
res = 0
for p in permutations(edges):
    for i, a in enumerate(p[1:], start=1):
        b = p[i - 1]
        if (a, b) in memo:
            res += memo[a, b]
        else:
            d = dist(xy[a][0], xy[a][1], xy[b][0], xy[b][1])
            memo[a, b] = d
            memo[b, a] = d
            res += d
print(res / math.factorial(n))

Buggy submission (verdict: Runtime Error):
import math
from itertools import combinations, permutations

def dist(x1, y1, x2, y2):
    return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** .5


n = int(input())
xy = [[int(i) for i in input().split()] for _ in range(n)]
edges = list(range(n))
memo = {}
res = 0
for p in permutations(edges):
    for i, a in enumerate(p[1:], start=1):
        b = p[i - 1]
        if (a, b) in memo:
            res += memo[a, b]
        else:
            d = dist(*xy[a], *xy[b])
            memo[a, b] = d
            memo[b, a] = d
            res += d
print(res / math.factorial(n))

Buggy submission (verdict: Runtime Error):
import math
from itertools import combinations, permutations

def dist(x1, y1, x2, y2):
    return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** .5


n = int(input())
xy = [[int(i) for i in input().split()] for _ in range(n)]
edges = list(range(n))
memo = {}
res = 0
for p in permutations(edges):
    for i, a in enumerate(p[1:], start=1):
        b = p[i - 1]
        if (a, b) in memo:
            res += memo[a, b]
        else:
            d = dist(*xy[a], *xy[b])
            memo[a, b] = d
            memo[b, a] = d
            res += d
print(res / math.factorial(n))
Problem p02885 (python)

Fixed submission:
A, B = map(int, input().split())
diff = A - 2 * B
if diff > 0:
  print(diff)
else:
  print(0)

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

N,M,L = map(int,input().split())
ABC = [list(map(int,input().split())) for _ in [0]*M]
Q = int(input())
ST = [list(map(int,input().split())) for _ in [0]*Q]


INF = (L+1)*N
d = [[INF]*N for _ in [0]*N]
for i in range(N):
    d[i][i] = 0
for a,b,c in ABC:
    a-=1;b-=1
    d[a][b] = c
    d[b][a] = c

def Warshall_Floyd(d,N=None):
    if N==None : N = len(d)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])

Warshall_Floyd(d,N)

d2 = [None]*N
for i,row in enumerate(d):
    d2[i] = [1 if e<=L else INF for e in row]
    d2[i][i] = 0

Warshall_Floyd(d2,N)

for s,t in ST:
    s-=1;t-=1
    ans = (d2[s][t]%INF)-1
    print(ans)

Buggy submission (verdict: Runtime Error):
N, M, L = map(int,input().split())
ABC = [list(map(int, input().split())) for _ in [0] * M]
Q = int(input())
ST = [list(map(int, input().split())) for _ in [0] * Q]


INF = (L + 1) * N
d = [[INF] * N for _ in [0] * N]
for i in range(N):
    d[i][i] = 0
for a, b, c in ABC:
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c

def Warshall_Floyd(d, N=None):
    if N is None:
      N = len(d)
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

Warshall_Floyd(d, N)

d2 = [None] * N
for i, row in enumerate(d):
    d2[i] = [1 if e <= L else INF for e in row]
    d2[i][i] = 0

Warshall_Floyd(d2, N)

for s, t in ST:
    s -= 1
    t -= 1
    ans = (d2[s][t] % INF) - 1
    print(ans)
Problem p02900 (python)

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

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

    if temp != 1:
        arr.add(temp)

    if not arr:
        arr.add(n)

    return arr

if a == b == 1:
    print(1)
else:
    fa = factorization(a)
    fb = factorization(b)
    res = 1
    for n in fa:
        if n in fb:
            res += 1
    print(res)

Buggy submission (verdict: Runtime Error):
import math


def sieve_of_eratosthenes(n):
    candidate = [i for i in range(2, n+1)]
    prime = []
    limit = math.sqrt(n) + 1

    while True:
        p = min(candidate)
        if limit <= p:
            prime.extend(candidate)
            break
        prime.append(p)

        candidate = [i for i in candidate if i % p != 0]
    return prime


a, b = map(int, input().split())
if a > b:
    a, b = b, a
prime = sieve_of_eratosthenes(b)
res = 1
for p in prime:
    if a %p == b % p == 0:
        res += 1
print(res)
Problem p02909 (python)

Fixed submission:
next_weather = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
print(next_weather[input()])

Buggy submission (verdict: Runtime Error):
next_weather = {'Sunny': 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
print(next_weahter[input()])
Problem p02603 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline


n = int(input())
a = [int(item) for item in input().split()]
prev = a[0]
a_uniq = [a[0]]
for item in a:
    if item == prev:
        continue
    a_uniq.append(item)
    prev = item

if len(a_uniq) == 1:
    print(1000)
    exit()

increasing = None
if a_uniq[0] < a_uniq[1]:
    increasing = True
else:
    increasing = False

money = 1000
kabu = 0
if increasing:
    p = money // a[0]
    money -= p * a[0]
    kabu = p

prev = a_uniq[0]
ans = 1000
for item in a_uniq[1:]:
    if item < prev and increasing:
        money += kabu * prev
        kabu = 0
        increasing = False
        ans = max(ans, money)
    if item > prev and not increasing:
        p = money // prev
        money -= p * prev
        kabu = p
        increasing = True
    prev = item
if kabu:
    money += a_uniq[-1] * kabu
    ans = max(ans, money)
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline


n = int(input())
a = [int(item) for item in input().split()]
prev = a[0]
a_uniq = [a[0]]
for item in a:
    if item == prev:
        continue
    a_uniq.append(item)
    prev = item

increasing = None
if a_uniq[0] < a_uniq[1]:
    increasing = True
else:
    increasing = False

money = 1000
kabu = 0
if increasing:
    p = money // a[0]
    money -= p * a[0]
    kabu = p

prev = a_uniq[0]
ans = 1000
for item in a_uniq[1:]:
    if item < prev and increasing:
        money += kabu * prev
        kabu = 0
        increasing = False
        ans = max(ans, money)
    if item > prev and not increasing:
        p = money // prev
        money -= p * prev
        kabu = p
        increasing = True
    prev = item
if kabu:
    money += a_uniq[-1] * kabu
    ans = max(ans, money)
print(ans)
Problem p02609 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
x = [int(item) for item in list(input().rstrip())]
x.reverse()

ones = x.count(1)
aug = ones + 1
dim = ones - 1

modaug = 0
moddim = 0
for i, item in enumerate(x):
    if item == 1:
        modaug += pow(2, i, aug)
        modaug %= aug
        if dim != 0:
            moddim += pow(2, i, dim)
            moddim %= dim

cnt = [-1] * (2*10**5 + 10)
cnt[0] = 0; cnt[1] = 1
for i in range(1, 2*10**5 + 10):
    val = i
    num = bin(val).count("1")
    cnt[i] = cnt[val % num] + 1

ans = []
for i, item in enumerate(x):
    if item == 0:
        tmp = modaug + pow(2, i, aug)
        tmp %= aug
    else:
        if dim == 0:
            ans.append(0)
            continue
        else:
            tmp = moddim - pow(2, i, dim)
            tmp %= dim
    ans.append(cnt[tmp] + 1)

ans.reverse()
for item in ans:
    print(item)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
x = [int(item) for item in list(input().rstrip())]
x.reverse()

ones = x.count(1)
aug = ones + 1
dim = ones - 1

modaug = 0
moddim = 0
for i, item in enumerate(x):
    if item == 1:
        modaug += pow(2, i, aug)
        modaug %= aug
        moddim += pow(2, i, dim)
        moddim %= dim

cnt = [-1] * (2*10**5 + 1)
cnt[0] = 0; cnt[1] = 1
for i in range(1, 2*10**5 + 1):
    val = i
    num = bin(val).count("1")
    cnt[i] = cnt[val % num] + 1

ans = []
for i, item in enumerate(x):
    if item == 0:
        tmp = modaug + pow(2, i, aug)
        tmp %= aug
    else:
        tmp = moddim - pow(2, i, dim)
        tmp %= dim
    ans.append(cnt[tmp] + 1)

ans.reverse()
for item in ans:
    print(item)
Problem p02703 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import heapq
INF = 10**18

MAX_SILVER = 3000 

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
        return self.dist

n, m, s = map(int, input().split())
edge = [[] for _ in range(n * MAX_SILVER)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1; v -= 1
    for i in range(a, MAX_SILVER):
        edge[u*MAX_SILVER + i].append((v*MAX_SILVER + i-a, b))
        edge[v*MAX_SILVER + i].append((u*MAX_SILVER + i-a, b))

for v in range(n):
    c, d = map(int, input().split())
    for i in range(MAX_SILVER - 100):
        edge[v*MAX_SILVER + i].append((v*MAX_SILVER + i + c, d))

DIJK = Dijkstra(edge)
if s > 2500:
    s = 2500
dist = DIJK.calc(s)

for v in range(1, n): 
    ret = INF
    for val in range(MAX_SILVER):
        if dist[v*MAX_SILVER + val] < ret:
            ret = dist[v*MAX_SILVER + val]
    print(ret)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
import heapq
INF = 10**9

MAX_SILVER = 3000 

class Dijkstra:
    def __init__(self, adj):
        self.adj = adj
        self.dist = [INF] * len(adj)
        self.q = []

    def calc(self, start):
        self.dist[start] = 0
        heapq.heappush(self.q, (0, start))
        while len(self.q) != 0:
            prov_cost, src = heapq.heappop(self.q)
            if self.dist[src] < prov_cost:
                continue
            for dest, cost in self.adj[src]:
                if self.dist[dest] > self.dist[src] + cost:
                    self.dist[dest] = self.dist[src] + cost
                    heapq.heappush(self.q, (self.dist[dest], dest))
        return self.dist

n, m, s = map(int, input().split())
edge = [[] for _ in range(n * MAX_SILVER)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    u -= 1; v -= 1
    for i in range(a, MAX_SILVER):
        edge[u*MAX_SILVER + i].append((v*MAX_SILVER + i-a, b))
        edge[v*MAX_SILVER + i].append((u*MAX_SILVER + i-a, b))

for v in range(n):
    c, d = map(int, input().split())
    for i in range(MAX_SILVER - 100):
        edge[v*MAX_SILVER + i].append((v*MAX_SILVER + i + c, d))

DIJK = Dijkstra(edge)
dist = DIJK.calc(s)

for v in range(1, n): 
    ret = INF
    for val in range(MAX_SILVER):
        if dist[v*MAX_SILVER + val] < ret:
            ret = dist[v*MAX_SILVER + val]
    print(ret)
Problem p02734 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, s = map(int, input().split())
a = [int(item) for item in input().split()]

dp = [[0] * (s+1) for _ in range(n)]
dp[0][0] = 1
if a[0] <= s:
    dp[0][a[0]] = 1
ans = 0
for i, item in enumerate(a[1:]):
    for j in range(s+1):
        # Not use item
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        # Do use item
        if j + item <= s:
            dp[i+1][j + item] += dp[i][j]
            dp[i+1][j + item] %= MOD
    # Start from i
    if item <= s:
        dp[i+1][item] += 1
    dp[i+1][0] += 1
    ans += dp[i+1][s]
    ans %= MOD

print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
MOD = 998244353

n, s = map(int, input().split())
a = [int(item) for item in input().split()]

dp = [[0] * (s+1) for _ in range(n)]
dp[0][0] = 1
if a[0] <= s:
    dp[0][a[0]] = 1
ans = 0
for i, item in enumerate(a[1:]):
    for j in range(s+1):
        # Not use item
        dp[i+1][j] += dp[i][j]
        dp[i+1][j] %= MOD
        # Do use item
        if j + item <= s:
            dp[i+1][j + item] += dp[i][j]
            dp[i+1][j + item] %= MOD
    # Start from i
    dp[i+1][item] += 1
    dp[i+1][0] += 1
    ans += dp[i+1][s]

print(ans)