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

Fixed submission:
from fractions import gcd
from functools import reduce
 
N = int(input())
A = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
 
lcm = reduce(lambda x,y: x*(y//gcd(x,y)), A)
 
answer = sum(lcm//x for x in A)
answer %= MOD
print(answer)

Buggy submission (verdict: Runtime Error):
from fractions import gcd
from functools import reduce
 
N,*A = map(int,read().split())
 
MOD = 10 ** 9 + 7
 
lcm = reduce(lambda x,y: x*(y//gcd(x,y)), A)
 
answer = sum((lcm//x) % MOD for x in A)
answer %= MOD
Problem p02891 (python)

Fixed submission:
S = str(input())
K = int(input())
N = len(S)

count1 = 0
x = "A"
con = 1
#仮に1回でもダメなやつ
for i in range(N):
  if x == S[i]:
    con += 1 
  else:
    x = S[i]
    if con != 1:
      count1 += con //2
    con = 1
  #print(count1, i)
if con != 1:
  count1 += con //2
  
if con == N:
  print(N * K // 2)
  quit()
#print(count1)
count2 = 0
count0 = 0
countf = 0
if S[0] == S[-1]:
  p = 0
  q = 0
  count0 = 1
  countf = 1
  i = 0
  j = -1
  while p == 0:
    if S[i] == S[i + 1]:
      count0 += 1
      i += 1
    else:
      p = 1
  while q == 0:
    if S[j] == S[j - 1]:
      countf += 1
      j -= 1
    else:
      q = 1

if (count0 % 2 == 1) and (countf % 2 == 1):
  count2 = 1
print(count1 * K + count2 * (K - 1))

Buggy submission (verdict: Runtime Error):
S = str(input())
K = int(input())
N = len(S)

count1 = 0
x = "A"
con = 1
#仮に1回でもダメなやつ
for i in range(N):
  if x == S[i]:
    con += 1 
  else:
    x = S[i]
    if con != 1:
      count1 += con //2
    con = 1
  #print(count1, i)
if con != 1:
  count1 += con //2
  
if con == N:
  print(N * K // 2)
  quit()
#print(count1)
count2 = 0
if S[0] == S[-1]:
  p = 0
  q = 0
  count0 = 1
  countf = 1
  i = 0
  j = -1
  while p == 0:
    if S[i] == S[i + 1]:
      count0 += 1
      i += 1
    else:
      p = 1
  while q == 0:
    if S[j] == S[j - 1]:
      countf += 1
      j -= 1
    else:
      q = 1

if (count0 % 2 == 1) and (countf % 2 == 1):
  count2 = 1
print(count1 * K + count2 * (K - 1))
Problem p02912 (python)

Fixed submission:
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))
Ai = list(map(lambda x: x*(-1), A))
heapq.heapify(Ai)

for i in range(M):
  maxA = heapq.heappop(Ai)*(-1)
  waribiki = maxA // 2
  heapq.heappush(Ai,waribiki * (-1))
  #print(Ai)
  
print(sum(Ai) * (-1))

Buggy submission (verdict: Runtime Error):
import math
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse = True)

c = 0
for i in range(M):
  if c < M:
    x = max(math.log(A[0]/A[1] ,2)//1, 1)
    y = min(x, M - c)
    A[0] = A[0] //(2 ** y)
  A = sorted(A, reverse = True)
  
print(sum(A))
Problem p02933 (python)

Fixed submission:
a = int(input())
s = str(input())

if a >= 3200:
  print(s)
else:
  print("red")

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


N,Q=map(int,input().split())
EDGE=[list(map(int,input().split())) for i in range(N-1)]
PLUS=[list(map(int,input().split())) for i in range(Q)]

SCORE=[0]*(N+1)
for p,x in PLUS:
    SCORE[p]+=x

ELIST=[[] for i in range(N+1)]

for x,y in EDGE:
    ELIST[x].append(y)
    ELIST[y].append(x)
#print(ELIST)

from collections import deque
Q=deque([1])

USED=[0]*(N+1)
USED[1]=1
#USED = [0, 1, 0, 0, 0] Ex1
#SCORE = [0, 100, 10, 1, 0] Ex1
#ELIST = [[], [2], [1, 3, 4], [2], [2]] Ex1

while Q:
    x=Q.pop()

    for to in ELIST[x]:
        if USED[to]==0:
            USED[to]=1
            SCORE[to]+=SCORE[x]
            Q.append(to)

print(*SCORE[1:])
Problem p02948 (python)

Fixed submission:
from heapq import heappop, heappush 
N, M = map(int, input().split())
score = 0
AB = [[] for i in range(M)]
for i in range(N):
  a, b = map(int, input().split())
  if M - a >= 0:
    AB[M - a].append(b)
  
#print(AB)
queue = []
for i in range(1, M + 1):
  for j in AB[-i]:
    heappush(queue, -j)
  if queue != []:
    score += -1 * heappop(queue)
  
  #print(score, queue)  
print(score)

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab)
income = 0
day = 1 #残り日数
i = 0
list1 = []

while (day <= m):
  if i <= n-1:
    if (ab[i][0] <= day):
      list1.append(ab[i])
      i += 1 
    else:
      day += 1
      p = max(list1, key = lambda x:x[1])
      income += p[1]
      list1.pop(list1.index(p))
      #print(day,i,income)
  else:
    day += 1
    p = max(list1, key = lambda x:x[1])
    income += p[1]
    list1.pop(list1.index(p))
      
print(income)
Problem p03137 (python)

Fixed submission:
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
subX = []

if N >= M:
  print(0)
else:
  for i in range(M-1):
    subX.append(X[i+1]-X[i])
  
  subX = sorted(subX)  
  ans = sum(subX)

  if N>= 2:
    for i in range(N-1):
      ans -= subX[-i-1]

  print(ans)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))
subX = []

for i in range(M-1):
  subX.append(X[i+1]-X[i])
  
subX = sorted(subX)  
ans = sum(subX)

for i in range(N-1):
  ans -= subX[-i-1]

print(ans)
Problem p03221 (python)

Fixed submission:
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = str(X) + str(Y) #文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = X + Y#文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY1 = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY1[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY1[i][0] == PY1[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY1[i][1] = X + Y#文字列の結合
#print(PY)
PY2 = sorted(PY1, key = lambda x:x[2])

for i in range(M):
  print(PY2[i][1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY = sorted(PY)
#print(PY)

for i in range(M):
  X = str(PY[i][0])#県の番号
  if i >= 1:#市の番号
    #print(PY)
    if PY[i][0] == PY[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:#6桁にするための処理
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY[i][1] = X + Y#文字列の結合
#print(PY)
PY = sorted(PY, key = lambda x:x[2])

for i in range(M):
  print(PY[i][1])

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
PY = [list(map(int, input().split())) for i in range(M)]
for i in range(M):
  PY[i].append(i)

PY = sorted(PY)

ans = [0]*M
#print(PY)

for i in range(M):
  X = str(PY[i][0])
  if i >= 1:
    #print(PY)
    if PY[i][0] == PY[i-1][0]:
      Y = int(Y) + 1
    else:
      Y = 1
  else:
    Y = 1
  while len(str(X)) <= 5:
    X = "0" + X
  while len(str(Y)) <= 5:
    Y = "0" + str(Y)
  PY[i][1] = X + Y
#print(PY)
PY = sorted(PY, key = lambda x:x[2])

for i in range(M):
  print(PY[i][1])
Problem p02847 (python)

Fixed submission:
s = input()
if s == "SUN":
    x = 7
if s == "MON":
    x = 6
if s == "TUE":
    x = 5
if s == "WED":
    x = 4
if s == "THU":
    x = 3
if s == "FRI":
    x = 2
if s == "SAT":
    x = 1
print(x)

Buggy submission (verdict: Runtime Error):
s=input()
if(s=="SUN")x=7
if(s=="MON")x=6
if(s=="TUE")x=5
if(s=="WED")x=4
if(s=="THU")x=3
if(s=="FRI")x=2
if(s=="SAT")x=1
print(x)
Problem p02951 (python)

Fixed submission:
a = list(map(int, input().split()))
print(max(0, a[2]-(a[0]-a[1])))

Buggy submission (verdict: Runtime Error):
a=list(map(int,split().input()))
print(max(0,a[2]-(a[0]-a[1])))
Problem p03107 (python)

Fixed submission:
S=input()
print(len(S)-abs(S.count("1")-S.count("0")))

Buggy submission (verdict: Runtime Error):
S=input()
L=len(S)
for i in range(100):
    S=S.replace("01","")
    S=S.replace("10","")
print(L-L2)

Buggy submission (verdict: Runtime Error):
S=input()
L=len(S)
L1=len(S)
L2=0
while L1!=L2:
    L1=len(S)
    S=S.replace("01","")
    S=S.replace("10","")
    print(S)
    L2=len(S)
print(L2)
print(L-L2)
Problem p02881 (python)

Fixed submission:
n=int(input())

def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

a=divisor(n)
a.sort()

b=sorted(a,reverse=True)

c=[]
for i in range(len(a)//2+1):
    d=a[i]-1+b[i]-1
    c.append(d)

print(min(c))

Buggy submission (verdict: Runtime Error):
import sympy
n=int(input())
a=sympy.divisors(n)
b=sorted(a,reverse=True)

c=[]
for i in range(len(a)//2):
    d=a[i]-1+b[i]-1
    c.append(d)

print(min(c))
Problem p02627 (python)

Fixed submission:
s = input()

if s.isupper():
        print("A")
elif s.islower():
        print("a")

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

if s.isuppper():
    print("A")
elif s.islower():
    print("a")
Problem p02833 (python)

Fixed submission:
N = int(input())

if N % 2 == 1:
  print(0)
  exit()
else:
  tmp = 2
  ans = 0
  while 5 * tmp <= N:
    tmp *= 5
    ans = ans + N // tmp
print(ans)

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

if N % 2 == 1:
  print(0)
else:
  tmp = 2
  ans = 0
  while 5 * tmp <= N:
    tmp *= 5
    ans = ans + N // tmp
print(ans)
Problem p03013 (python)

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

a = [int(input()) for i in range(M)]


for i in range(M - 1):
    if a[i] + 1 == a[i+1]:
        print(0)
        exit()

dp = [0] * (N + 1)
flag_a = [0] * (N + 1)

for i in range(M):
    flag_a[a[i]] = -1


if N == 1 and M != 1:
    print(1)
    exit()
elif N == 1 and M == 1:
    print(0)
    exit()

if 1 in a and 2 in a:
    print(0)
    exit()

if 1 in a:
    dp[1] = 0
    dp[2] = 1
elif 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3,N+1):
    if flag_a[i] == -1:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(dp[N])

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

a = [int(input()) for i in range(M)]


for i in range(M - 1):
    if a[i] + 1 == a[i+1]:
        print(0)
        exit()

dp = [0] * (N + 1)

if N == 1 and M != 1:
    print(1)
elif N == 1 and M == 1:
    print(0)

if 1 in a and 2 in a:
    print(0)
    exit()

if 1 in a:
    dp[1] = 0
    dp[2] = 1
elif 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3,N+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(dp[N])

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

a = [int(input()) for i in range(M)]


for i in range(M - 1):
    if a[i] + 1 == a[i+1]:
        print(0)
        exit()

dp = [0] * (N + 1)
if 1 in a and 2 in a:
    print(0)
    exit()

if 1 in a:
    dp[1] = 0
    dp[2] = 1
elif 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3,N+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(dp[N])

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

a = [int(input()) for i in range(M)]


for i in range(M - 1):
    if a[i] + 1 == a[i+1]:
        print(0)
        exit()

dp = [0] * (N + 1)

if 1 in a and 2 in a:
    print(0)
    exit()

if 1 in a:
    dp[1] = 0
    dp[2] = 1
elif 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3,N+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(dp[N])

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

a = [int(input()) for i in range(M)]



dp = [0] * (N + 1)


if 1 in a and 2 in a:
    print(0)
    exit()

if 1 in a:
    dp[1] = 0
    dp[2] = 1
elif 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3,N+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(dp[N])

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

a = [int(input()) for i in range(M)]



dp = [0] * (N + 1)


if 1 in a and 2 in a:
    print(0)
    exit()

if 1 in a:
    dp[1] = 0
    dp[2] = 1
elif 2 in a:
    dp[1] = 1
    dp[2] = 0
else:
    dp[1] = 1
    dp[2] = 2

for i in range(3,N+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = (dp[i - 1] + dp[i - 2]) % 1000000007

print(dp[N] % 1000000007)
Problem p03017 (python)

Fixed submission:
import sys
sys.setrecursionlimit(100000000)
 
N, A, B, C, D = map(int, input().split())
s = list(input())
 
A -= 1
B -= 1
C -= 1
D -= 1
 
for i in range(len(s)):
    if i == len(s) - 1:
        continue
    else:
        if s[i] == '#' and s[i+1] == '#' and max(C, D) < i and i <= C:
            print("No")
            exit()
 
if D < C:
    tmp = 0
    for i in range(len(s)):
        if i == len(s) - 2 or i == len(s) - 1:
            continue
        else:
            if s[i] == '.' and s[i+1] == '.' and s[i+2] == '.' and B <= i + 1 <= D:
                tmp = 1
    if tmp != 1:
        print("No")
        exit()
 
 
 
def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans
 
ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

Buggy submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(100000000)

N, A, B, C, D = map(int, input().split())
s = list(input())

A -= 1
B -= 1
C -= 1
D -= 1

for i in len(s):
    if i == len(s) - 1:
        continue
    else:
        if s[i] == '#' and s[i+1] == '#':
            print("No")
            exit()




def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans

ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

Buggy submission (verdict: Runtime Error):

import sys
sys.setrecursionlimit(10000)

N, A, B, C, D = map(int, input().split())
s = list(input())

A -= 1
B -= 1
C -= 1
D -= 1


def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans

ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")

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

A -= 1
B -= 1
C -= 1
D -= 1


def check(s, start, goal, ans):
    if start == goal:
        return 1
    if s[start] == '#':
        return 0
    if start + 1 <= N - 1:
        ans += check(s, start + 1, goal, ans)
    if start + 2 <= N - 1:
        ans += check(s, start + 2, goal, ans)
    return ans

ans = 0
if not check(s, B, D, ans):
    print("No")
    exit()
#s[D] = '#'
if not check(s, A, C, ans):
    print("No")
    exit()
print("Yes")
Problem p03805 (python)

Fixed submission:
N, M = map(int, input().split())
G = [[] for _ in range(N)]
seen = [False] * N
for i in range(M):
    a, b = map(lambda x: int(x) - 1 ,input().split())
    G[a].append(b)
    G[b].append(a)

def dfs(x, G, seen):
    seen[x] = True
    flag = True
    for i in seen:
        if i == False:
            flag = False
    if flag:
        return 1
    res = 0
    for i in G[x]:
        if seen[i]:
            continue
        res += dfs(i, G, seen)
        seen[i] = False
    return res

print(dfs(0, G, seen))

Buggy submission (verdict: Runtime Error):
import itertools

N, M = map(int, input().split())
G = [[]  for _ in range(N)]
for i in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    G[a].append(b)
    G[b].append(a)
pattern = [i for i in range(N)]

ans = 0
for i in itertools.permutations(pattern):
    flag = True
    now = i[j]
    to = i[j+1]
    if i[0] != 0:
        continue
    for j in range(len(i) - 1):
        if not to in G[now]:
            flag = False
    if flag:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import itertools

N, M = map(int, input().split())
G = [[]  for _ in range(N)]
for i in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    G[a].append(b)
    G[b].append(a)
pattern = [i for i in range(N)]

ans = 0
for i in itertools.permutations(pattern):
    flag = True
    now = i[j]
    next = i[j+1]
    if i[0] != 0:
        continue
    for j in range(len(i) - 1):
        if not next in G[now]:
            flag = False
    if flag:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 6)

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

graph = [[] for i in range(M)]
for i in range(M):
    v, e = map(int, input().split())
    graph[v - 1].append(e - 1)
    graph[e - 1].append(v - 1)

def dfs(v, seen, res):
    end = True
    for i in range(len(seen)):
        if seen[i] == False and i != v:
            end = False
    if end:
        res[0] += 1
        return
    seen[v] = True
    for i in graph[v]:
        if seen[i]:
            continue
        dfs(i, seen, res)
    seen[v] = False

res = [0]
seen = [False] * N
dfs(0, seen, res)
print(res[0])

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

graph = [[] for i in range(M)]
for i in range(M):
    v, e = map(int, input().split())
    graph[v - 1].append(e - 1)
    graph[e - 1].append(v - 1)

def dfs(v, seen, res):
    end = True
    for i in range(len(seen)):
        if seen[i] == False and i != v:
            end = False
    if end:
        res[0] += 1
        return
    seen[v] = True
    for i in graph[v]:
        if seen[i]:
            continue
        dfs(i, seen, res)
    seen[v] = False

res = [0]
seen = [False] * N
dfs(0, seen, res)
print(res[0])
Problem p02831 (python)

Fixed submission:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

a, b = map(int, input().split())
print(a * b // gcd(a, b))

Buggy submission (verdict: Runtime Error):
from math import gcd

a, b = map(int, input().split())
print(a * b // gcd(a, b))
Problem p02549 (python)

Fixed submission:
n,k=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(k)]

mod = 998244353

dp = [0] * (n+1)
sdp = [0] * (n+1)
dp[1] = 1
sdp[1] = 1

for i in range(n+1):
  for j in range(k):
    left = max(0, i-lr[j][1])
    right = max(0, i-lr[j][0]+1)
    
    dp[i] += sdp[right] - sdp[left]
  if i+1 <= n:
    sdp[i+1] = sdp[i]%mod + dp[i]%mod

print(dp[n]%mod)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(k)]

mod = 998244353

dp = [0] * (n+1)
sdp = [0] * (n+1)
dp[1] = 1
sdp[1] = 1

for i in range(n+1):
  for j in range(k):
    left = max(0, i-lr[j][1])
    right = max(0, i-lr[j][0]+1)
    
    dp[i] += sdp[right] - sdp[left]
  if i+1 <= n:
    sdp[i+1] = sdp[i]%mod + dp[i]%mod

print(dp%mod)
Problem p02570 (python)

Fixed submission:
d,t,s=map(int,input().split())

if d / s <= t:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
  print('No')
Problem p02597 (python)

Fixed submission:
n = int(input())
c = input()

w = []
r = []
for i in range(n):
  if c[i] == 'W':
    w.append(i+1)
  else:
    r.append(i+1)

w_len = len(w)
r_len = len(r)
if w_len == 0 or r_len == 0:
  print(0)
  exit(0)

if w_len < r_len:
  search = w_len
else:
  search = r_len

w_min = w[0]
r_max = r[r_len-1]

if r_max < w_min:
  print(0)
  exit(0)

count = 0
for i in range(search):
  tmp = w[i]
  w[i] = r[r_len-i-1]
  r[r_len-i-1] = tmp
  count += 1
  
  if w_len > count and (r_len-count-1) >= 0:
    w_min = w[count]
    r_max = r[r_len - count - 1]
  else:
    w_min = w[w_len-1]
    r_max = r[0]
    
  if r_max < w_min:
    print(count)
    exit(0)
print(count)

Buggy submission (verdict: Runtime Error):
n = int(input())
c = input()

w = []
r = []
for i in range(n):
  if c[i] == 'W':
    w.append(i+1)
  else:
    r.append(i+1)

w_len = len(w)
r_len = len(r)
if w_len == 0 or r_len == 0:
  print(0)
  exit(0)

w_min = w[0]
r_max = r[r_len-1]
count = 0
for i in range(n):
  tmp = w[i]
  w[i] = r[r_len-i-1]
  r[r_len-i-1] = tmp
  count += 1
  
  w_min = w[count]
  r_max = r[r_len - count - 1]
  
  if r_max < w_min:
    print(count)
    exit(0)
print(count)
Problem p02623 (python)

Fixed submission:
n,m,k=map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

b = [0] * (m+1)
for i in range(m):
  b[i+1] = b[i] + B[i]

from bisect import bisect_right

result = 0
a = k
for i in range(n+1):
  index = bisect_right(b, a)
  hon = (index - 1) + (i)
  result = max(result, hon)
  if i < n:
    a -= A[i]
  if a < 0:
    break
print(result)

Buggy submission (verdict: Runtime Error):
n,m,k=map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
spend = 0
ia = 0
ib = 0
while spend < k:
  if ia < n and A[ia] < B[ib]:
    spend += A[ia]
    ia += 1
    if ia == n:
      ia = n-1
  elif ib < m and A[ia] >= B[ib]:
    spend += B[ib]
    ib += 1
    if ib < m:
      ib = m-1
  elif ia == n-1:
    spend += B[ib]
    ib += 1
    if ib < m:
      ib = m-1
  elif ib == m-1:
    spend += A[ia]
    ia += 1
    if ia == n:
      ia = n-1
    
  count += 1
print(count-1)
Problem p02688 (python)

Fixed submission:
N, K = map(int, input().split())
Aall = set(list(range(1, N+1)))
A = []
for i in range(N*2):
  try: 
    if i % 2 != 0:
      a = list(map(int, input().split()))
      A.extend(a)
    else:
      d = list(map(int, input().split()))
  except EOFError:
    d = 1
print(len(Aall-set(A)))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
Aall = set(range(1, N))
Ak = []
for i in range(N*2):
  #d = input()
  A = list(map(int, input().split()))
  if i % 2 == 1:
    Ak.extend((A))
print(len(Aall - set(Ak)))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
Aall = set(range(1, N))
Ak = []
for i in range(N):
  d = input().split()
  A = list(map(int, input().split()))
  Ak.extend((A))
print(len(Aall - set(Ak)))
Problem p02729 (python)

Fixed submission:
n,m=map(int,input().split())
print( int((n+m)*(n+m-1)/2 - n*m) )

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

import numpy as np
result = 0
for x in np.arange(l/3-0.1, l/3+0.1, 0.1):
  for y in np.arange(x, l/3+0.1, 0.1):
    z = l - (x+y)
    if z <= 0:
      break
    v = x*y*z
    result = max(v, result)
print(result)