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

Fixed submission:
N, A = map(int, input().split())
x = [int(i) for i in input().split()]

table = [[[0]*(N*A+1) for i in range(N+1)] for j in range(N+1)]
table[0][0][0] = 1

for j in range(1,N+1):
  for k in range(N+1):
    for s in range(N*A+1):
      c = x[j-1]
      if s-c<0:
        table[j][k][s] = table[j-1][k][s]
      elif s-c>=0 and k>=1:
        table[j][k][s] = table[j-1][k][s] + table[j-1][k-1][s-c]
      
ans = 0
for i in range(1,N+1):
  ans += table[N][i][i*A]
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())
x= [int(i) for i in input().split()]
X = max(x)
dp = [[[0]*(X*N+1) for i in range(N+1)] for j in range(N+1)]
dp[0][0][0] = 1
ans = 0

for j in range(1,N+1):
  for k in range(j+1):
    for s in range(X*N+1):
      dp[j][k][s] = dp[j-1][k][s]
      if s >= x[j-1]:
        dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
      
for i in range(1,N+1):
  ans += dp[-1][i][i*A]
  if (i+1)*A > X*N:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())
x= [int(i) for i in input().split()]
X = max(x)
dp = [[[0]*(X*N+1) for i in range(N+1)] for j in range(N+1)]
dp[0][0][0] = 1
ans = 0

for j in range(1,N+1):
  for k in range(j+1):
    for s in range(X*N+1):
      dp[j][k][s] = dp[j-1][k][s]
      if s >= x[j-1]:
        dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
      
for i in range(1,N+1):
  ans += dp[-1][i][i*A]
  if (i+1)*A >= X*N:
    break
print(ans)

Buggy submission (verdict: Runtime Error):
N, A = map(int, input().split())
x = [int(i) for i in input().split()]
ans = 0
X = max(x)
dp = [[[0]*(X*N+1) for j in range(N+1)] for k in range(N+1)]
dp[0][0][0] = 1 
for j in range(1,N+1):
  for k in range(N+1):
    for s in range(X*N+1):
      dp[j][k][s] = dp[j-1][k][s]
      if s>=x[j-1]:
        dp[j][k][s] += dp[j-1][k-1][s-x[j-1]]
for k in range(1,N+1):
  ans += dp[N][k][k*A]
print(ans)
Problem p04020 (python)

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]
array = []
ans = 0
j = 0

for i in range(N):
  if i+1 == N:
    ans += sum(A[j:i+1])//2
    j = i+1
  elif A[i+1] == 0:
    ans += sum(A[j:i+1])//2
    j = i+1
    
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(input()) for i in range(N)]
array = []
ans = 0

for i in range(N):
  array += A[i] * [i+1]
array.sort()

for j in range(len(array)-1):
  if abs(array[j] - array[j+1]) <= 1:
    ans += 1
    array[j] = -1
    array[j+1] = -1

print(ans)
Problem p03665 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math

N, P = map(int, input().split())

A_temp = list(map(int, input().split()))
A = []

for a in A_temp:
    A.append(a % 2)

zero_num = A.count(0)
one_num = A.count(1)

def Combination(n, m):
    #print(str(n) + "C" + str(m))
    f = math.factorial
    return f(n) // f(m) // f(n - m)

combination_for_one = 0
if P == 0:
    for i in range(0, one_num + 1, 2):
        combination_for_one += Combination(one_num, i)
else:
    for i in range(1, one_num, 2):
        combination_for_one += Combination(one_num, i)

ans = combination_for_one * (2 ** zero_num)
print(ans)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os

input_text_path = __file__.replace('.py', '.txt')
fd = os.open(input_text_path, os.O_RDONLY)
os.dup2(fd, sys.stdin.fileno())

N, P = map(int, input().split())

A_temp = list(map(int, input().split()))
A = []

for a in A_temp:
    A.append(a % 2)

zero_num = A.count(0)
one_num = A.count(1)

def Permutation(n, m):
    ret = 1
    for i in range(m):
        ret *= (n - i)
    return ret

def Combination(n, m):
    #import itertools
    #lst = [1] * n
    #c = list(itertools.combinations(lst, m))
    #return len(c)
    return Permutation(n, m) // Permutation(m, m)

combination_for_one = 0
if P == 0:
    for i in range(2, one_num + 1, 2):
        combination_for_one += Combination(one_num, i)
    combination_for_one += 1
else:
    for i in range(0, one_num, 2):
        combination_for_one += Combination(one_num, i)

ans = combination_for_one * (2 ** zero_num)

print(ans)
Problem p03719 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os
import math

A, B, C = map(int, input().split())

if A <= C <= B:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os
import math

N, M = map(int, input().split())
#print('N', N)
#print('M', M)

A = [[] for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    A[a].append((b, -c))

# 始点から到達不可能な頂点は除去する
visited = [False] * N
Q = [0]
while Q:
    i = Q.pop(0)
    visited[i] = True
    for edge in A[i]:
        to = edge[0]
        if not visited[to]:
            Q.append(to)
# 到達不可能な頂点
unreachable = []
reachable = []
for i in range(N):
    if visited[i]:
        reachable.append(i)
    else:
        unreachable.append(i)
#print('unreach', unreachable)
for i in unreachable:
    A[i] = []

dists = [float('inf')] * N
dists[0] = 0
def bellman_ford(A):
    for i in reachable:
        for v in reachable:
            for edge in A[v]:
                to = edge[0]
                cost = edge[1]
                if dists[v] != float('inf') and dists[to] > dists[v] + cost:
                    dists[to] = dists[v] + cost
                    if i == N - 1:
                        return True
    return False

is_loop = bellman_ford(A)

if is_loop:
    print('inf')
else:
    # パスがある
    print(-dists[N-1])
Problem p03773 (python)

Fixed submission:
# -*- coding: utf-8 -*-

import sys
import os

a, b = list(map(int, input().split()))
c = (a + b) % 24
print(c)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import sys
import os

N, M = list(map(int, input().split()))
students = []
checkpoints = []

for i in range(N):
    a, b = list(map(int, input().split()))
    students.append([a, b])

for i in range(M):
    a, b = list(map(int, input().split()))
    checkpoints.append([a, b])

for student in students:
    min_dist = float('inf')
    min_i = None
    for i, checkpoint in enumerate(checkpoints):
        manhattan_dist = abs(checkpoint[0] - student[0]) + abs(checkpoint[1] - student[1])
        if manhattan_dist < min_dist:
            min_dist = manhattan_dist
            min_i = i
    print(min_i + 1)
Problem p02573 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())
ab_array = [list(map(int, input().split())) for _ in range(m)]

ad_sum_array = [0] * n
ad_array = [set() for _ in range(n)]

for ab in ab_array:
    a, b = ab
    ad_array[a - 1].add(b - 1)
    ad_array[b - 1].add(a - 1)

check_array = [False] * n

def bfs(node_num):
    queue = deque([node_num])
    check_array[node_num] = True
    num = 1

    while queue:
        node = queue.popleft()
        for ad in ad_array[node]:
            if not check_array[ad]:
                check_array[ad] = True
                queue.append(ad)
                num += 1
    return num

ans = 0
for i in range(n):
    if not check_array[i]:
        ans = max(ans, bfs(i))

print(ans)

Buggy submission (verdict: Runtime Error):
class union_find:
    def __init__(self, node_num):
        self.root_array = [-1] * node_num

    def root(self, x):
        if self.root_array[x] < 0:
            return x
        else:
            return self.root_array[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.root_array[x] > self.root_array[y]:
            x, y = y, x
        self.root_array[x] += self.root_array[y]
        self.root_array[y] = x

    def size(self, x):
        return -self.root_array[self.root(x)]


def solve(n, m, ab_array):
    uf = union_find(n)
    for ab in ab_array:
        a, b = ab
        uf.unite(a - 1, b - 1)

    ans = 0
    for i in range(n):
        ans = max(ans, uf.size(i))

    return ans

if __name__ == '__main__':
    n, m = map(int, input().split())
    ab_array = [list(map(int, input().split())) for _ in range(m)]
    ans = solve(n, m, ab_array)
    print(ans)
Problem p02582 (python)

Fixed submission:
S = input()

day = 0
max_day = 0
for s in S:
    if s == 'R':
        day += 1
        max_day = max(day, max_day)
    else:
        day = 0

print(max_day)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

max_score = -float('inf')

for i in range(n):
    loop_score_array = []
    loop_score = 0
    loop_len = 0
    pos = i
    while True:
        pos = p[pos] - 1
        loop_score += c[pos]
        loop_score_array.append(loop_score)
        loop_len+=1
        if pos == i:
            break
    for i, score in enumerate(loop_score_array):
        if k-i-1 < 0:
            continue
        loop_num = (k-i-1)//loop_len
        score_sum = score + max(0, loop_score)*loop_num
        max_score = max(score_sum, max_score)
print(max_score)
Problem p02606 (python)

Fixed submission:
L, R, d = list(map(int, input().split()))

num = 0
for i in range(L, R+1):
    if i%d == 0:
        num += 1

print(num)

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


for i in range(1, N+1):
    sum = 0

    range_x = int((i-5)**0.5)+1 if i-5 >0 else 0
    s = set()
    for x in range(1, range_x):
        flag = False
        if x in s:
            continue
        range_y = int((i-x**2-x-3)**0.5)+1 if i-x**2-2*x-2 > 0 else 0
        for y in range(x, range_y):
            if y in s:
                continue
            range_z = int((i-x**2-y**2-x*y-x-y)**0.5)+1 if i-x**2-y**2-x*y-x-y > 0 else 0
            for z in range(y, range_z):
                if z in s:
                    continue
                if x**2 + y**2 + z**2 + x*y + y*z + z*x == i:
                    num = len(set([x,y,z]))
                    sum += 6 if num == 3 else 3 if num==2 else 1
                    s = s | set([x,y,z])
                    flag = True
                    break
            if flag:
                break

    print(sum)
Problem p02609 (python)

Fixed submission:
N = int(input())
X = int(input(),2)

def popcount(n):
    return bin(n).count('1')


def f(n):
    if n== 0:
        return 1
    count = 1
    while n!=0:
        n = n%popcount(n)
        count += 1
    return count


X_popcount = popcount(X)
X_mod_p = X%(X_popcount+1)
if X_popcount != 1:
    X_mod_m = X%(X_popcount-1)
for i in range(N):
    X_i = X ^ (1<<(N-i-1))
    if X_i == 0:
        ans = 0
    elif X>>(N-i-1)&1 == 1:
        if X_popcount == 1:
            ans = 1
        else:
            ans = f((X_mod_m-pow(2, N-i-1, X_popcount-1))%(X_popcount-1))
    else:
        ans = f((X_mod_p+pow(2, N-i-1, X_popcount+1))%(X_popcount+1))
    print(ans)

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

def popcount(n):
    return bin(n).count('1')


def f(n):
    if n== 0:
        return 1
    count = 1
    while n!=0:
        n = n%popcount(n)
        count += 1
    return count


X_popcount = popcount(X)
X_mod_p = X%(X_popcount+1)
X_mod_m = X%(X_popcount-1)
for i in range(N):
    X_i = X ^ (1<<(N-i-1))
    if X_i == 0:
        ans = 0
    elif X>>(N-i-1)&1 == 1:
        if X_popcount == 1:
            ans = 1
        else:
            ans = f((X_mod_m-pow(2, N-i-1, X_popcount-1))%(X_popcount-1))
    else:
        ans = f((X_mod_p+pow(2, N-i-1, X_popcount+1))%(X_popcount+1))
    print(ans)
Problem p02621 (python)

Fixed submission:
a = int(input())
print(a+a**2+a**3)

Buggy submission (verdict: Runtime Error):
N, M, K = list(map(int, input().split()))
A = list(map(int, input().split()))
B = list(map(int, input().split()))

A_sum = [0]
B_sum = [0]
for i in range(N):
    A_sum.append(A_sum[i]+A[i])
for i in range(M):
    B_sum.append(B_sum[i]+B[i])


num = 0
J = M
for i in range(N+1):
    if A_sum[i] > K:
        break
    for j in (J,-1,-1):
        if A_sum[i] + B_sum[j] <= K:
            if num < i+j:
                num = i+j
            J = j
            break

print(num)
Problem p02630 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
bc = [list(map(int, input().split())) for _ in range(Q)]

mem = [0]*(10**5)

sum = 0
for i in A:
    mem[i-1] += 1
    sum += i

for q in range(Q):
    b = bc[q][0]
    if mem[b-1] != 0:
        c = bc[q][1]
        num = mem[b-1]
        mem[c-1] += num
        mem[b-1] = 0
        sum = sum - num*b + num*c
    print(sum)

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

N = int(input())
A = np.array(list(map(int, input().split())))
Q = int(input())
bc = [list(map(int, input().split())) for _ in range(Q)]

for i in range(Q):
    A[A==bc[i][0]] = bc[i][1]
    print(sum(A))
Problem p02642 (python)

Fixed submission:
from collections import Counter
N = int(input())
A = sorted(list(map(int, input().split())))
count = Counter(A)

max_len_A = 10**6+1
data = [0]*max_len_A
A = list(set(A))

for a in A:
    if data[a]==0:
        for j in range(a+a, max_len_A, a):
            data[j]+=1


ans = len([a for a in A if data[a]==0 and count[a]==1])
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N = int(input())
A = sorted(list(map(int, input().split())))
count = Counter(A)

data = [True]*N
A = list(set(A))

for i in range(N):
    if data[i]:
        for j in range(i+1,N):
            # print(i,j)
            if A[j]%A[i]==0:
                data[j]=False

ans = len([i for i in range(N) if data[i] and count[A[i]]==1])
print(ans)
Problem p02579 (python)

Fixed submission:
import heapq

H, W = map(int, input().split())
sy, sx = map(lambda x: int(x) - 1, input().split())
ty, tx = map(lambda x: int(x) - 1, input().split())
s, t = sy * W + sx, ty * W + tx
graph = [input() for _ in range(H)]

INF = 1 << 30
dist = [INF] * (H * W)
que = []

def push(v, d):
    if(dist[v] <= d):
        return
    dist[v] = d
    heapq.heappush(que, (d, v))

def move(ny, nx, d):
    if ny < 0 or ny >= H or nx < 0 or nx >= W:
        return
    if graph[ny][nx] == '.':
        push(ny * W + nx, d)

push(s, 0)

while que:
    d, v = heapq.heappop(que)
    if d > dist[v]:
        continue
    if v == t:
        break
    y, x = divmod(v, W)
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            move(y + dy, x + dx, d + (abs(dy) + abs(dx) > 1))

if dist[t] == INF:
    print(-1)
else:
    print(dist[t])

Buggy submission (verdict: Runtime Error):
import numpy as np
from heapq import *

H, W = map(int, input().split())
sy, sx = map(lambda x: int(x) - 1, input().split())
ty, tx = map(lambda x: int(x) - 1, input().split())
s, t = sy * H + sx, ty * H + tx
graph = [input() for _ in range(H)]

INF = 1 << 30
dist = np.full(H * W, INF, np.int64)
que = []

def push(v, d):
    if(dist[v] <= d):
        return
    dist[v] = d
    heappush(que, (d, v))

def move(ny, nx, d):
    if ny < 0 or ny >= H or nx < 0 or nx >= W:
        return
    if graph[ny][nx] == '.':
        push(ny * H + nx, d)

push(s, 0)

while que:
    d, v = heappop(que)
    if d > dist[v]:
        continue
    y, x = divmod(v, H)
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            move(y + dy, x + dx, d + (abs(dy) + abs(dx) > 1))

if dist[t] == INF:
    print(-1)
else:
    print(dist[t])

Buggy submission (verdict: Runtime Error):
import numpy as np
from heapq import *

H, W = map(int, input().split())
sy, sx = map(lambda x: int(x) - 1, input().split())
ty, tx = map(lambda x: int(x) - 1, input().split())
s, t = sy * H + sx, ty * H + tx
graph = [input() for _ in range(H)]

INF = 1 << 30
dist = np.full(H * W, INF, np.int64)
que = []

def push(v, d):
    if(dist[v] <= d):
        return
    dist[v] = d
    heappush(que, (d, v))

def move(ny, nx, d):
    if ny < 0 or ny >= H or nx < 0 or nx >= W:
        return
    if graph[ny][nx] == '.':
        push(ny * H + nx, d)

push(s, 0)

while que:
    d, v = heappop(que)
    if d > dist[v]:
        continue
    y, x = divmod(v, H)
    for dy in range(-2, 3):
        for dx in range(-2, 3):
            move(y + dy, x + dx, d + (abs(dy) + abs(dx) > 1))

if dist[t] == INF:
    print(-1)
else:
    print(dist[t])
Problem p02616 (python)

Fixed submission:
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
A = list(map(int, input().split()))
ans = 1
if N == K:
    for a in A:
        ans = ans * a % MOD
    print(ans)
    exit(0)

minus = []
plus = []
for a in A:
    if a < 0:
        minus.append(a)
    else:
        plus.append(a)

if len(minus) == N:
    if K % 2 == 0:
        A.sort()
    else:
        A.sort(reverse=True)
    for i in range(K):
        ans = ans * A[i] % MOD
    print(ans)
    exit(0)

minus.sort(reverse=True)
plus.sort()

if  K % 2:
    ans *= plus.pop()

B = []

while len(minus) > 1:
    a = minus.pop()
    b = minus.pop()
    B.append(a * b)

while len(plus) > 1:
    a = plus.pop()
    b = plus.pop()
    B.append(a * b)

B.sort()

for i in range(K // 2):
    ans = ans * B.pop() % MOD

print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 10 ** 9 + 7

N, K = map(int, input().split())
A = list(map(int, input().split()))
minus = []
plus = []
for a in A:
    if a < 0:
        minus.append(a)
    else:
        plus.append(a)

ans = 1
if len(minus) == N:
    if K % 2 == 0:
        A.sort()
    else:
        A.sort(reverse=True)
    for i in range(K):
        ans = ans * A[i] % MOD
    print(ans)
    exit(0)

minus.sort()
plus.sort()

if  K % 2:
    ans *= plus.pop()

B = []

while len(minus) > 1:
    a = minus.pop()
    b = minus.pop()
    B.append(a * b)

while len(plus) > 1:
    a = plus.pop()
    b = plus.pop()
    B.append(a * b)

B.sort()

for i in range(K // 2):
    ans = ans * B.pop() % MOD

print(ans)
Problem p02658 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
m = 10**18

ans = 1

for i in range(0, n):
    if a[i] == 0:
        print(0)
        exit()

for i in range(0, n):
    ans *= a[i]
    if ans > m:
        print(-1)
        exit()


if ans > m:
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
m = 10 ** 18

ans = 1

for i in range(0, n):
    if a[i] == 0:
        print(0)
        exit()

for i in range(0, n):
    ans *= a[i]
    if ans > m:
        print(-1)
        exit(-1)


if ans > m:
    print(-1)
else:
    print(ans)
Problem p03050 (python)

Fixed submission:
import math

N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
    if N % i:
        continue
    m = N // i - 1
    if m <= 0:
        continue
    if N // m == N % m:
        ans += m
print(ans)

Buggy submission (verdict: Runtime Error):
import math

N = int(input())
ans = 0
for i in range(1, int(math.sqrt(N)) + 2):
    if N % i:
        continue
    m = N // i - 1
    if N // m == N % m:
        ans += m
print(ans)
Problem p03074 (python)

Fixed submission:
N, K = map(int, input().split())
S = input()
S += '2'

A = []
if S[0] == '0':
  A.append(0)

cnt = 1
for i in range(1, len(S)):
  if S[i] == S[i-1]:
    cnt += 1
  else:
    A.append(cnt)
    cnt = 1

ans = 0
tot = 0
r = 0

for l in range(len(A)):
  while r < len(A) and r - l < 2 * K + 1:
    tot += A[r]
    r += 1
  if l % 2 == 0:
    ans = max(ans, tot)
  if l == r:
    r += 1
  else:
    tot -= A[l]

print(ans)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  S.push_back('2');
  vector<int> A;
  if(S[0] == '0') A.push_back(0);
  int cnt = 1;
  rep(i, 1, S.size()) {
    if(S[i] == S[i-1]) cnt++;
    else {
      A.push_back(cnt);
      cnt = 1;
    }
  }
  if(S.back() == '0') A.push_back(0);
  int ans = 0;
  int r = 0;
  int sum = 0;
  for(int l = 0; l < A.size(); l++){
    while(r < A.size() && r - l < 2 * K + 1){
      sum += A[r];
      r++;
    }
    if(l % 2 == 0) ans = max(ans, sum);
    if(l == r) r++;
    else sum -= A[l];
  }
  cout << ans << endl;
  return 0;
}
Problem p03238 (python)

Fixed submission:
N = int(input())
if N == 1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A + B)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print("Hello World")
else:
    A, B = map(int, input().split())
    print(A + B)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
    print("Hello World")
else:
    A, B = map(int, input().split())
    print(A + B)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
  print("Hello World")
  exit()
else:
  A, B = map(int, input().split())
  print(A + B)

Buggy submission (verdict: Runtime Error):
N = int(input())
if N == 1:
  print("Hello World")
else:
  A, B = map(int, input().split())
  print(A + B)
Problem p03680 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000)

N = int(input())
a = [int(input()) for _ in range(N)]
c = [0] * N

def f(i, n):
  if a[n] == 2: return i
  if c[n] == 1: return -1
  c[n] = 1
  return f(i + 1, a[n] - 1)

print(f(1, 0))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = [int(input()) for _ in range(N)]
c = [0] * N

def f(i, n):
  if a[n] == 2: return i
  if c[n] == 1: return -1
  c[n] = 1
  return f(i + 1, a[n] - 1)

print(f(1, 0))
Problem p03966 (python)

Fixed submission:
N = int(input())
T = []
A = []
for i in range(N):
  a, b = map(int, input().split())
  T.append(a)
  A.append(b)

t = T[0]
a = A[0]

for i in range(1, N):
  if t < T[i] and a < A[i]:
    t = T[i]
    a = A[i]
  else:
    x = (t + T[i] - 1) // T[i]
    y = (a + A[i] - 1) // A[i]
    t = T[i] * max(x, y)
    a = A[i] * max(x, y)

print(t + a)

Buggy submission (verdict: Runtime Error):
N = int(input())
T = []
A = []
for i in range(N):
  a, b = map(int, input().split())
  T.append(a)
  A.append(b)

t = T[0]
a = A[0]

for i in range(1, N):
  if t < T[i] and a < A[i]:
    t = t[i]
    a = A[i]
  else:
    x = int((t + T[i] - 1) / T[i])
    y = int((a + A[i] - 1) / A[i])
    t = T[i] * max(x, y)
    a = A[i] * max(x, y)

print(t + a)
Problem p02811 (python)

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

if k * 500 >= x: print("Yes")
else: print("No")

Buggy submission (verdict: Runtime Error):
k, x = map(int, input())

if(k * 500 >= x): print("Yes")
else: print("No")
Problem p02840 (python)

Fixed submission:
n, x, d = map(int, input().split())

if d == 0:
  if x == 0:
    print(1)
    exit()
  else:
    print(n + 1)
    exit()
if d < 0:
  y = x
  x = x + d * (n - 1)
  d = -d
else:
  y = x + d * (n - 1)
  
U = {}
ans = 0
has0 = 0
for k in range(1, n + 1):
  r = (x * k) % d
  s = k * d * (k - 1) // 2
  v1 = k * x + s
  v2 = k * y - s
  if r in U:
    u = U[r]
    if v1 > u[1] or v2 < u[0]:
      ans += (u[1] - u[0]) // d + 1
    else:
      v1 = min(v1, U[r][0])
      v2 = max(v2, U[r][1])
  U[r] = (v1, v2)
  if r == 0 and v1 <= 0 and v2 >= 0:
    has0 = 1
#  print(ans, k, v1, v2, U)

for r, u in U.items():
  ans += (u[1] - u[0]) // d + 1

if not has0: ans += 1
  
print(ans)

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

if d == 0:
  if x == 0:
    print(1)
    exit
  else:
    print(n + 1)
    exit
if d < 0:
  y = x
  x = x + d * (n - 1)
  d = -d
else:
  y = x + d * (n - 1)
  
U = {}
ans = 0
has0 = 0
for k in range(1, n + 1):
  r = (x * k) % d
  s = k * d * (k - 1) // 2
  v1 = k * x + s
  v2 = k * y - s
  if r in U:
    u = U[r]
    if v1 > u[1] or v2 < u[0]:
      ans += (u[1] - u[0]) // d + 1
    else:
      v1 = min(v1, U[r][0])
      v2 = max(v2, U[r][1])
  U[r] = (v1, v2)
  if r == 0 and v1 <= 0 and v2 >= 0:
    has0 = 1
#  print(ans, k, v1, v2, U)

for r, u in U.items():
  ans += (u[1] - u[0]) // d + 1

if not has0: ans += 1
  
print(ans)