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

Fixed submission:
import sys

N, M = map(int, input().split())
EdgeTo = [[] for _ in range(N)]
sys.setrecursionlimit(N+M)

for _ in range(M):
    x, y = map(int, input().split())
    EdgeTo[x-1].append(y-1)


DP = [-1] * N
def From(i):
    if DP[i] != -1: return DP[i]
    else:
        maxLength = 0
        if not EdgeTo[i]:
            DP[i] = maxLength
        else:
            for node in EdgeTo[i]:
                maxLength = max(maxLength, 1 + From(node))
            DP[i] = maxLength
        return maxLength

Ans = 0
for i in range(N):
    Ans = max(Ans, From(i))
print(Ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
EdgeTo = [[] for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    EdgeTo[x-1].append(y-1)


DP = [-1] * N
def From(i):
    if DP[i] != -1: return DP[i]
    else:
        maxLength = 0
        if not EdgeTo[i]:
            DP[i] = maxLength
        else:
            for node in EdgeTo[i]:
                maxLength = max(maxLength, 1 + From(node))
            DP[i] = maxLength
        return maxLength

Ans = 0
for i in range(N):
    Ans = max(Ans, From(i))
print(Ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
EdgeTo = [[] for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    EdgeTo[x-1].append(y-1)


DP = [-1] * N
def From(i):
    if DP[i] != -1: return DP[i]
    else:
        maxLength = 0
        if not EdgeTo[i]:
            DP[i] = maxLength
        else:
            for node in EdgeTo[i]:
                maxLength = max(maxLength, 1 + From(node))
        DP[i] = maxLength
        return maxLength

Ans = 0
for i in range(N):
    Ans = max(Ans, From(i))
print(Ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
EdgeTo = [[] for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    EdgeTo[x-1].append(y-1)


DP = [-1] * N
def From(i, EdgeTo, DP):
    if DP[i] >= 0: return DP[i]
    else:
        maxLength = 0
        if not EdgeTo[i]:
            DP[i] = maxLength
        else:
            for node in EdgeTo[i]:
                maxLength = max(maxLength, From(node, EdgeTo, DP))
            maxLength += 1
        DP[i] = maxLength
        return maxLength
Ans = 0
for i in range(N):
    Ans = max(Ans, From(i, EdgeTo, DP))
print(Ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
EdgeTo = [[] for _ in range(N)]

for _ in range(M):
    x, y = map(int, input().split())
    EdgeTo[x-1].append(y-1)


DP = [0] * N
def From(i, EdgeTo, memo):
    if not EdgeTo[i]: return 0
    try:
        return memo[i]
    except KeyError:
        maxLength = 0
        for node in EdgeTo[i]:
            maxLength = max(maxLength, From(node, EdgeTo, memo))
        memo[i] = maxLength + 1
        return maxLength + 1

memo = {}
Ans = 0
for i in range(N):
    DP[i] = From(i, EdgeTo, memo)
    Ans = max(DP[i], Ans)
print(Ans)
Problem p03187 (python)

Fixed submission:
import math
L, N = map(int, input().split())
X = [None for i in range(N)]
DistAntiClock, DistClock = [0 for i in range(N+1)], [0 for i in range(N+1)]
for i in range(N):
    X[i] = int(input())
    DistAntiClock[i+1] = DistAntiClock[i] + 2 * X[i]
for i in range(N):
    DistClock[i+1] = DistClock[i] + (L - X[-1-i]) * 2

maxLength = max(X[N-1], L - X[0])
for i in range(1, N):
    finIndex = math.ceil((i + N)/2)
    if (i + N) % 2 == 0:
        AntiClockLength = DistAntiClock[finIndex] - DistAntiClock[i-1] - X[finIndex-1] + DistClock[N - finIndex] 
        ClockLength = DistClock[finIndex] - DistClock[i-1] - (L-X[-finIndex]) + DistAntiClock[N - finIndex]
    else:
        AntiClockLength = DistAntiClock[finIndex - 1] - DistAntiClock[i-1] + DistClock[N - finIndex + 1] - (L - X[finIndex - 1])
        ClockLength = DistClock[finIndex - 1] - DistClock[i-1] + DistAntiClock[N - finIndex + 1] - X[N - finIndex]
    maxLength = max(max(AntiClockLength, ClockLength), maxLength)

print(maxLength)

Buggy submission (verdict: Runtime Error):
L, N = map(int, input().split())
X = []
for i in range(N):
    x = int(input())
    X.append(x)
    X.append(x-L)
X.sort()

if N <= 2000:
    def DP(now, minus, plus, left):
        if left == 0:
            return max(now-X[minus], X[plus] - now)
        else:
            PlusL = X[plus] - now + DP(X[plus], minus, plus+1, left-1)
            MinusL = now - X[minus] + DP(X[minus], minus-1, plus, left-1)
            if PlusL > MinusL:
                return PlusL
            else:
                return MinusL
    print(DP(0, N-1, N, N-1))
else: print(L)
Problem p03241 (python)

Fixed submission:
import math
N, M = map(int, input().split())
ulim = M//N
mid = int(math.sqrt(M))
if ulim >= mid:
    ans = []
    for i in range(1, mid+1):
        if M%i == 0:
            ans.append(i)
            if M//i <= ulim:
                ans.append(M//i)
    print(max(ans))

else:
    for i in reversed(range(1, ulim+1)):
        if M%i == 0:
            print(i)
            break

Buggy submission (verdict: Runtime Error):
def dist(a, b, x, y, h):
    return h + abs(a - x) + abs(b - y)
 
N = int(input())
P = [[0 for i in range(101)] for j in range(101)]
x, y, h = map(int, input().split())
P[x][y] = h
for i in range(101):
    for j in range(101):
        P[i][j] = dist(i, j, x, y, h)
 
for i in range(N-1):
    a, b, c = map(int, input().split())
    if P[a][b] != c:
        P[a][b] = False
    for j in range(101):
        for k in range(101):
            if P[j][k] != False and P[j][k] != dist(j, k, a, b, c):
                P[j][k] = False
temp = (0, 0, 0)
for i in range(101):
    for j in range(101):
        if P[i][j] > temp[2]:
            temp = (i, j, P[i][j])
print(temp[0], temp[1], temp[2])

Buggy submission (verdict: Runtime Error):
def dist(a, b, x, y, h):
    return h + abs(a - x) + abs(b - y)
 
N = int(input())
P = [[0 for i in range(101)] for j in range(101)]
x, y, h = map(int, input().split())
P[x][y] = h
for i in range(101):
    for j in range(101):
        P[i][j] = dist(i, j, x, y, h)
 
for i in range(N-1):
    a, b, c = map(int, input().split())
    if P[a][b] != c:
        P[a][b] = False
    for j in range(101):
        for k in range(101):
            if P[j][k] != False and P[j][k] != dist(j, k, a, b, c):
                P[j][k] = False
temp = (0, 0, 0)
for i in range(101):
    for j in range(101):
        if P[i][j] > ans:
            temp = (i, j, P[i][j])
print(temp[0], temp[1], temp[2])
Problem p03263 (python)

Fixed submission:
H, W = map(int, input().split())
A = [[int(_) for _ in input().split()] for _ in range(H)]
N = 0
move = []
for i in range(H):
    for j in range(W):
        if A[i][j] % 2 == 1 and j <= W-2:
            A[i][j+1] += 1
            N += 1
            move.append([i+1, j+1, i+1, j+2])
        elif A[i][j]%2 == 1 and j == W-1 and i!=H-1:
            A[i+1][j] += 1
            N += 1
            move.append([i+1, j+1, i+2, j+1])

print(N)
for i in range(N):
    print(move[i][0], move[i][1], move[i][2], move[i][3])

Buggy submission (verdict: Runtime Error):
import sys

def solve():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = [[int(a) for a in input().split()] for _ in range(H)]
    Ans = []
    for n in range(H * W - 1):
        h, w = n // W, n % W
        if A[h][w] % 2 == 1:
            if w < W - 1:
                Ans.append((h+1, w+1, h+1 w+2))
                A[h][w] -= 1
                A[h][w+1] += 1
            else:
                Ans.append((h+1, w+1, h+2, w+1))
                A[h][w] -= 1
                A[h+1][w] += 1
    print(len(Ans))
    for move in Ans:
        print(" ".join(map(str, move)))
   
    return 0

if __name__ == "__main__":
    solve()
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
 
one = True
for i in range(K):
  if S[i] != "1":
    print(int(S[i]))
    one = False
    break
if one:
  print(1)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
 
if K == 1:
  print(int(S[0]))
elif len(S) == 1:
  print(int(S))
elif S[:K] == "1"*K:
  print(1)
else:
  for i in range(K+1):
    if S[i] != "1":
      print(int(S[i]))
      break

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
 
if K == 1:
  print(int(S[0]))
elif len(S) == 1:
  print(int(S))
elif S[:K] == "1"*K:
  print(1)
else:
  for i in range(K+1):
    if S[i] != "!":
      print(int(S[i]))
      break
Problem p03294 (python)

Fixed submission:
N = int(input())
a = [int(i) for i in input().split()]

modTotal = 0
for i in range(N):
    modTotal += a[i]-1
print(modTotal)

Buggy submission (verdict: Runtime Error):
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if a % b == 0:
        return b
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return int(a * b / gcd(a, b))

N = int(input())
a = [int(i) for i in input().split()]

LCM = lcm(a[0], a[1])
for i in range(1, N-1):
    LCM = lcm(LCM, a[i+1])
LCM -= 1

modTotal = 0
for i in range(N):
    modTotal += LCM % a[i]
print(modTotal)
Problem p03360 (python)

Fixed submission:
A = [int(a) for a in input().split()]
A.sort()
K = int(input())
print(A[0] + A[1] + A[2] * 2 ** K)

Buggy submission (verdict: Runtime Error):
N = [int(a) for a in input().split()]
N.sort()
K = int(input())
print(A[0] + A[1] + A[2] * 2 ** K)
Problem p03370 (python)

Fixed submission:
N, X = map(int, input().split())
sum_min = 0
use_min = 10000000
for i in range(N):
  m = int(input())
  sum_min += m
  use_min = min(use_min, m)
  
print(N + (X - sum_min) // use_min)

Buggy submission (verdict: Runtime Error):
N, X = map(int, input().split())
sum_min = 0
use_min = 10000000
for i in range(X):
  m = int(input())
  sum_min += m
  use_min = min(use_min, m)
  
print(X + (N - sum_min) // use_min)
Problem p03452 (python)

Fixed submission:
from collections import deque
N, M = map(int, input().split())
Inf = 10000000000
Edge = [[] for i in range(N)]
for i in range(M):
    l, r, d = map(int, input().split())
    Edge[l-1].append((r-1, d))
    Edge[r-1].append((l-1, -d))
 
Node = [Inf for i in range(N)]
Possible = True
for i in range(N):
    if not Possible:
        break
    elif Node[i] == Inf:
        Node[i] = 0
        Q = deque([i])
        while Q:
            now = Q.popleft()
            for e in Edge[now]:
                if Node[e[0]] == Inf:
                    Node[e[0]] = Node[now] + e[1]
                    Q.append(e[0])
                elif Node[now] + e[1] != Node[e[0]]:
                    Possible = False
                    break
print("Yes" if Possible else "No")

Buggy submission (verdict: Runtime Error):
from collections import deque
N, M = map(int, input().split())
Inf = 10000000000
Edge = [[] for i in range(N)]
for i in range(M):
    l, r, d = map(int, input().split())
    Edge[l-1].append((r-1, d))
    Edge[r-1].append((l-1, -d))
 
Node = [Inf for i in range(N)]
Possible = True
for i in range(N):
    if not Possible:
        break
    elif Node[i] == Inf:
        Node[i] = 0
        Q = [i]
        while Q:
            now = deque.popleft(Q)
            for e in Edge[now]:
                if Node[e[0]] == Inf:
                    Node[e[0]] = Node[now] + e[1]
                    Q.append(e[0])
                elif Node[now] + e[1] != Node[e[0]]:
                    Possible = False
                    break
print("Yes" if Possible else "No")
Problem p03485 (python)

Fixed submission:
a,b =map(int,input().split());print((a+b+1)//2)

Buggy submission (verdict: Runtime Error):
a, b = map(int, open(0)); print((a + b + 1) // 2)

Buggy submission (verdict: Runtime Error):
a, b = map(int, open(0)); print((a + b) // 2 + (a + b) % 2)
Problem p03490 (python)

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

MoveX, MoveY = [], []
dir = "X"
count = 0
for i in range(len(s)): 
    if s[i] == "T":
        if count:
            if dir == "X": MoveX.append(count)
            else: MoveY.append(count)
        count = 0
        dir = ("Y" if dir == "X" else "X")      
    else:
        count += 1
if s[-1] == "F":
    if dir == "X": MoveX.append(count)
    else: MoveY.append(count)

iniX = 0
if s[0] == "F":
    iniX = MoveX.pop(0)

def DP(i, z, ini, Move = list):
    canMove = set([ini])
    for j in range(i):
        temp = []
        for item in canMove:
            temp.append(item+Move[j])
            temp.append(item-Move[j])
        canMove = set(temp)
    return z in canMove

if DP(len(MoveX), x, iniX, MoveX) and DP(len(MoveY), y, 0, MoveY): print("Yes")
else: print("No")

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

MoveX, MoveY = [], []
dir = "X"
count = 0
for i in range(len(s)): 
    if s[i] == "T":
        if count:
            if dir == "X": MoveX.append(count)
            else: MoveY.append(count)
        count = 0
        dir = ("Y" if dir == "X" else "X")      
    else:
        count += 1
if s[-1] == "F":
    if dir == "X": MoveX.append(count)
    else: MoveY.append(count)

def DP(i, z, Move = list, memo = {}):
    if i == -1: 
        if z == 0: return True
        else: return False
    try:
        return memo[(i, z)]
    except KeyError:
        if DP(i-1, z-Move[i], Move, memo) or DP(i-1, z+Move[i], Move, memo): 
            memo[(i, z)] = True
            return True
        else: 
            memo[(i, z)] = False
            return False

memox, memoy = {}, {}
if DP(len(MoveX)-1, x, MoveX, memox) and DP(len(MoveY)-1, y, MoveY, memoy): print("Yes")
else: print("No")
Problem p03563 (python)

Fixed submission:
R = int(input())
G = int(input())
print(2 * G - R)

Buggy submission (verdict: Runtime Error):
R, G = map(int, input().split())
print(2 * G - R)
Problem p03569 (python)

Fixed submission:
S = list(input())
X, A = [], []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: 
        NX += S[i]
        A.append(i)
    
for i in range(len(NX)//2):
    if NX[i] != NX[-1-i]:
        print(-1)
        break
else:
    if NX == "": print(0)
    else:
        l, r = 0, len(S)-1
        midl = A[(len(NX)-1)//2]
        midr = (A[(len(NX)-1)//2] if len(NX)%2==1 else A[(len(NX)-1)//2 + 1])
        Add = 0
        while l < midl or r > midr:
            if S[l] == S[r] == "x":
                l += 1
                r -= 1
            elif S[l] == "x":
                l += 1
                Add += 1
            elif S[r] == "x":
                r -= 1
                Add += 1
            else:
                l += 1
                r -= 1
        print(Add)

Buggy submission (verdict: Runtime Error):
S = list(input())
X, A = [], []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: 
        NX += S[i]
        A.append(i)
    
for i in range(len(NX)//2):
    if NX[i] != NX[-1-i]:
        print(-1)
        break
else:
    if NX == "": print(0)
    else:
        l, r = 0, len(S)-1
        midl = A[len(NX)//2]
        midr = (A[len(NX)//2] if len(NX)%2==1 else A[len(NX)//2 + 1])
        Add = 0
        while l < midl or r > midr:
            if S[l] == S[r] == "x":
                l += 1
                r -= 1
            elif S[l] == "x":
                l += 1
                Add += 1
            elif S[r] == "x":
                r -= 1
                Add += 1
            else:
                l += 1
                r -= 1
        print(Add)

Buggy submission (verdict: Runtime Error):
S = list(input())
X = []
NX = ""

for i in range(len(S)):
    if S[i] == "x": X.append(i)
    else: NX += S[i]
    
NXr = ""
for i in reversed(range(len(NX))): NXr += NX[i]

if NXr != NX: print(-1)
else:
    mid = S.index(NX[(len(NX) - 1)//2])
    Xleft, Xright = set(), set()
    for x in X:
        if x < mid: Xleft |= {mid-x}
        else: Xright |= {x-mid}
    print(len(Xleft ^ Xright))
Problem p03579 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)
F = sys.stdin
N, M = map(int, F.readline().strip("\n").split())
Edge = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, F.readline().strip("\n").split())
    Edge[A-1].append(B-1)
    Edge[B-1].append(A-1)

Color = [0] * N


def dfs(v, c):
    Color[v] = c
    for next in Edge[v]:
        if Color[next] == c: return False
        if Color[next] == 0:
            if not dfs(next, -c): return False
    return True

Bipartite = dfs(0, 1)
if Bipartite:
    black = Color.count(1)
    print(black * (N-black) - M)
else:
    print(N * (N - 1)//2 - M)

Buggy submission (verdict: Runtime Error):
import sys
F = sys.stdin
N, M = map(int, F.readline().strip("\n").split())
Edge = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, F.readline().strip("\n").split())
    Edge[A-1].append(B-1)
    Edge[B-1].append(A-1)

Color = [0] * N


def dfs(v, c):
    Color[v] = c
    for next in Edge[v]:
        if Color[next] == c: return False
        if Color[next] == 0:
            if not dfs(next, -c): return False
    return True

Bipartite = dfs(0, 1)
if Bipartite:
    black = Color.count(1)
    print(black * (N-black) - M)
else:
    print(N * (N - 1)//2 - M)
Problem p03612 (python)

Fixed submission:
N = int(input())
P = [int(i) for i in input().split()]
i = 0
ans = 0
while i < N:
    if P[i] == i+1:
        ans += 1
        i += 2
    else:
        i += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    P = [int(p) for p in input().split()]
    swap = 0
    i = 0
    while i < N:
        if P[i] == i + 1:
            P[i], P[i+1] = P[i+1], P[i]
            swap += 1
        i += 1
    print(swap)
    return 0

if __name__ == "__main__":
    solve()
Problem p03627 (python)

Fixed submission:
import sys

def solve():
    N = int(input())
    A = [int(a) for a in input().split()]
    lengthD = dict()
    for a in A:
        if a in lengthD: lengthD[a] += 1
        else: lengthD[a] = 1
    moreThanTwo = []
    count = 0
    for key in lengthD:
        if lengthD[key] > 1: 
            moreThanTwo.append(key)
            count += 1
    
    if count == 0: print(0)
    else:
        ans = 0
        moreThanTwo.sort()
        if lengthD[moreThanTwo[-1]] > 3: ans = moreThanTwo[-1] ** 2
        if count < 2: print(ans)
        else:
            ans = max(ans, moreThanTwo[-1] * moreThanTwo[-2])
            print(ans)

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import sys

def solve():
    N = int(input())
    A = [int(a) for a in input().split()]
    lengthD = dict()
    for a in A:
        if a in lengthD: lengthD[a] += 1
        else: lengthD[a] = 1
    moreThanTwo = []
    count = 0
    for key in lengthD:
        if lengthD[key] > 1: 
            moreThanTwo.append(key)
            count += 1
    ans = 0
    moreThanTwo.sort()
    if lengthD[moreThanTwo[-1]] > 3: ans = moreThanTwo[-1] ** 2
    if count < 2: print(ans)
    else:
        ans = max(ans, moreThanTwo[-1] * moreThanTwo[-2])
        print(ans)

    return 0

if __name__ == "__main__":
    solve()
Problem p03658 (python)

Fixed submission:
N, K = map(int, input().split())
L = [int(l) for l in input().split()]
L.sort(reverse = True)
print(sum(L[:K]))

Buggy submission (verdict: Runtime Error):
def solve():
    N, K = map(int, input().split())
    L = [int(i) for i in input().split()]
    L.sort(reversed = True)
    print(sum(L[:K]))


if __name__ == "__main__":
    solve()
Problem p03682 (python)

Fixed submission:
import sys
from operator import itemgetter
import heapq

def solve():
    input = sys.stdin.readline
    N = int(input())
    town = dict()
    road = [None] * N
    roadx, roady = [None] * N, [None] * N
    for i in range(N):
        x, y = map(int, input().split())
        town[(x, y, i)] = i
        road[i] = (x, y, i)
        roadx[i] = (x, y, i)
        roady[i] = (x, y, i)
    roadx.sort()
    roadx_id = dict()
    roady.sort(key = itemgetter(1))
    roady_id = dict()
    for i in range(N):
        roadx_id[roadx[i]] = i
        roady_id[roady[i]] = i

    visited = [False] * N
    q = []
    heapq.heapify(q)
    heapq.heappush(q, (0, 0)) #(cost, town_id)
    cost = 0
    while q:
        add_cost, id = heapq.heappop(q)
        #print(add_cost, id, cost)
        #print(visited)
        if not visited[id]:
            cost += add_cost
            visited[id] = True
            for s in range(2):
                nx = roadx_id[road[id]] + (-1) ** s #roadxにおけるid
                if 0 <= nx < N:
                    if not visited[town[roadx[nx]]]: heapq.heappush(q, (min(abs(road[id][0] - roadx[nx][0]), abs(road[id][1] - roadx[nx][1])), town[roadx[nx]]))
                
                ny = roady_id[road[id]] + (-1) ** s #roadyにおけるid
                if 0 <= ny < N:
                    if not visited[town[roady[ny]]]: heapq.heappush(q, (min(abs(road[id][1] - roady[ny][1]), abs(road[id][1] - roady[ny][1])), town[roady[ny]]))
    
    print(cost)

    return 0

if __name__ == "__main__":
    solve()

Buggy submission (verdict: Runtime Error):
import heapq
def cost(a, b, c, d):
    return min(abs(a-c), abs(b-d))

N = int(input())
T, Visit = [], {}
for i in range(N):
    x, y = map(int, input().split())
    Visit[(x, y)] = False
    if (x, y) not in T:
        T.append((x, y))
lenT = len(T)
Tx, Ty = sorted(T, key = lambda t:t[0]), sorted(T, key = lambda t:t[1])

now = Tx[0]
Visit[now] = True
Q = [(cost(Tx[0][0], Tx[0][1], Tx[1][0], Tx[1][1]), Tx[1])]
nowy = Ty.index(now)
if nowy == 0:
    Q.append((cost(now[0], now[1], Ty[1][0], Ty[1][1]), Ty[1]))
elif nowy == lenT-1:
    Q.append((cost(now[0], now[1], Ty[-2][0], Ty[-2][1]), Ty[-2]))
else:
    Q.append((cost(now[0], now[1], Ty[nowy-1][0], Ty[nowy-1][1]), Ty[nowy-1]))
    Q.append((cost(now[0], now[1], Ty[nowy+1][0], Ty[nowy+1][1]), Ty[nowy-1]))
heapq.heapify(Q)
search = [-1, 1]
Total = 0
while Q:
    nowCost, now = heapq.heappop(Q)
    if Visit[now] == False:
        Total += nowCost
        Visit[now] = True
        nowx, nowy = Tx.index(now), Ty.index(now)
        for i in search:
            if 0 <= nowx + i <= lenT-1:
                if Visit[Tx[nowx+i]] == False:
                   heapq.heappush(Q, (cost(now[0], now[1], Tx[nowx+i][0], Tx[nowx+i][1]), Tx[nowx+i]))
            if 0 <= nowy + i <= lenT-1:
                if Visit[Ty[nowy+i]] == False:
                   heapq.heappush(Q, (cost(now[0], now[1], Ty[nowy+i][0], Ty[nowy+i][1]), Ty[nowy+i]))

print(Total)
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 -= map(int, input().split())
if b-a == c-b:
     print("YES")
else:
     print("NO")
Problem p03832 (python)

Fixed submission:
N, A, B, C, D = map(int, input().split())
mod = 7 + 10 ** 9

fact = [1] * (N+1)
frev = [1] * (N+1)
for i in range(1, N+1):
    temp = fact[i] = (fact[i-1] * i) % mod
    frev[i] = pow(temp, mod-2, mod)

def P(n, r):
    return (fact[n] * frev[n-r]) % mod

DP = [[0 for j in range(N+1)] for i in range(N+1)]
for i in range(N+1): DP[i][0] = 1
for i in range(A, B+1):
    revi = frev[i]
    for j in range(1, N+1):
       dpij = 0 + DP[i-1][j]
       for k in range(C, D + 1):
           if j - i * k < 0: break
           temp = (P(N-j+i*k, i*k) * pow(revi, k, mod) * frev[k]) % mod
           dpij += (temp * DP[i-1][j-i*k]) % mod
       DP[i][j] = dpij % mod

print(DP[B][N])

Buggy submission (verdict: Runtime Error):
N, A, B, C, D = map(int, input().split())
mod = 7 + 10 ** 9

fact = [1] * (N+1)
frev = [1] * (N+1)
for i in range(1, N+1):
    temp = fact[i] = (fact[i-1] * i) % mod
    frev[i] = pow(temp, mod-2, mod)

def P(n, r):
    ans = fact[n] * frev[n-r]
    return ans % mod

if A * C > N: print(0)
else:
    DP = [[0 for j in range(N+1)] for i in range(N+1)]
    for i in range(N+1): DP[i][0] = 1
    DP[A][A * C] = (P(N, A*C) * (frev[A] ** C) * frev[C]) % mod
    for i in range(A, B+1):
        for j in range(N+1):
           if i == A and j == A * C: continue
           DP[i][j] = DP[i-1][j]
           for k in range(C, D + 1):
               if j - i * k < 0: break
               temp = (P(N-j+i*k, i*k) * (frev[i]**k) * frev[k]) % mod
               DP[i][j] += (temp * DP[i-1][j-i*k]) % mod
               DP[i][j] %= mod

print(DP[B][N])