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

Fixed submission:
N,D=map(int,input().split())
n=0
for i in range(N):
    x,y=map(int,input().split())
    if (x**2+y**2)**(1/2)<=D:
        n+=1
print(n)

Buggy submission (verdict: Runtime Error):
N,D=map(int,input().split())
n=0
for x,y=map(int,input().split()) in range(N):
    if (x**2+y**2)**(1/2)<=D:
        n+=1
print(n)

Buggy submission (verdict: Runtime Error):
while True:
    i=0
    x,y=map(int,input().split())
    (x**2+y**2)**(1/2)
    i+=1
    print(i)
Problem p02623 (python)

Fixed submission:
from collections import deque
 
def solve():
    N, M, K = map(int, input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))
 
    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M):
        b.append(b[i] + B[i])
 
    ans = 0
    j = M
 
    for i in range(len(a)):
        if a[i] > K:
            break
        while b[j] > K - a[i]:
            j -= 1
        ans = max(ans, i+j)
    
    print(ans)
            
solve()

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

def solve():
    N, M, K = map(int, input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M):
        b.append(b[i] + B[i])

    ans = 0
    j = M

    for i in range(len(A)):
        if a[i] > K:
            break
        while b[j] < K - a[i]:
            j -= 1
        ans = max(ans, i+j)
    
    print(ans)
            
solve()

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

def solve():
    N, M, K = map(int, input().split())
    A = list(map(int,input().split()))
    B = list(map(int,input().split()))

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])
    for i in range(M)
        b.append(b[i] + B[i])

    ans = 0
    j = M

    for i in range(len(A)):
        if a[i] > K:
            break
        while b[j] < K - a[i]:
            j -= 1
        ans = max(ans, i+j)
    
    print(ans)
            
solve()
Problem p02547 (python)

Fixed submission:
N = int(input())

count = 0
yes = False

for i in range(N):
  a , b = map(int, input().split())
  
  if a==b:
    count +=1
    if count >= 3:
      print("Yes")
      yes = True
      break
  else:
    count = 0

if not(yes):
  print("No")

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

count = 0
yes = False

for i in range(N):
  a , b = map(int, input().split())
  
  if a==b:
    count +=1
    if count >= 3:
      print("Yes")
      yes = True
      break
  else:
    count = 0

if not(yes):
  print("No")

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

count = 0
yes = False

for i in range(N):
  a , b = map(int, input().split())
  
  if a==b:
    count +=1
    if count >= 3:
      print("Yes")
      yes = True
      break
  else:
    count = 0

if !yes:
  print("No")
Problem p02571 (python)

Fixed submission:
S = input()
T = input()

min = len(T)

for index in range( len(S)-len(T)+1 ):
  temp = 0
  for index2 in range(len(T)):
    if T[index2] != S[index+index2]:
      temp += 1
  if temp < min:
    min = temp

print(min)

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

min = length(T)

for index in range( length(S)-length(T)+1 ):
  temp = 0
  for index2 in range(T):
    if T[index2] == S[index+index2]:
      temp += 1
  if temp < min:
    min = temp

print(min)
Problem p02688 (python)

Fixed submission:
a,b = map(int, input().split())
 
p = [1]*a
 
while True:
  try:
    input()
  except EOFError:
    break
  c = input().split()
  for d in c:
    p[int(d)-1]=0
 
print(sum(p))

Buggy submission (verdict: Runtime Error):
a,b = map(int, input().split())
 
p = [1]*a
 
while True:
  try:
    input()
  except EOFError:
    break
  c = input().split()
  for d in c:
    p[int(d)]=0
 
print(sum(p))

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

p = [1]*a

while True:
  if !input():
    break
  c = input().split()
  for d in c:
    p[d]=0

print(sum(p))
Problem p02546 (python)

Fixed submission:
S= input()
if S[-1]=='s':
	S+='es'
else:
	S+='s'
print(S)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""Untitled3.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1VVfPJl7_dXodPfxyID5RNKhqW1ZRqVux
"""

N= int(input())
count=0
for i in range(N):
  p,q=map(int,input().split(' '))
  if count<3:
    if p==q:
      count+=1
    else:
      count=0
  else:
    pass

if count>=3:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N= int(input())
count=0
for i in range(N):
	p,q=map(int,input().split(' '))
	if p==q:
		count+=1
	else:
		count=0

if count>=3:
	print('Yes')
else:
  	print('No')
Problem p02547 (python)

Fixed submission:
N= int(input())
count=0
for i in range(N):
  p,q=map(int,input().split(' '))
  if count<3:
    if p==q:
      count+=1
    else:
      count=0
  else:
    pass

if count>=3:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
count=0
for i in range(N):
  p,q=map(int,input().split(' '))
  if count<3:
	if p==q:
      count+=1
    else:
      count=0
  else:
    pass
if count>=3:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N= int(input())
count=0
for i in range(N):
  p,q=map(int,input().split(' '))
  if p==q:
    count+=1
	else:
    count=0

if count>=3:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N= int(input())
count=0
for i in range(N):
	p,q=list(map(int,input().split(' ')))
    if p==q:
		count+=1
	else:
      	count=0

if count>=3:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N= int(input())
count=0
for i in range(N):
	p,q=map(int,input().split(' '))
    if p==q:
		count+=1
	else:
      	count=0

if count>=3:
  print('Yes')
else:
  print('No')
Problem p02629 (python)

Fixed submission:
def main():
    #input
    N=int(input())
    l=list("zabcdefghijklmnopqrstuvwxy")
    if N<26:
        print(l[N])
    else:
        name=[]
        n=N
        while n>=26:
            mod=n%26
            if mod!=0:
                n//=26
            else:
                n//=26
                n-=1
            name.append(l[mod])
        if n!=0:
            name.append(l[n])
        name=[name[n] for n in reversed(range(len(name)))]
        print("".join(name))

if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    #input
    N=int(input())
    l=list("zabcdefghijklmnopqrstuvwxy")

    name=[]
    n=N
    while n>=26:
        mod=n%26
        if mod!=0:
            n//=26
        else:
            n//=26
            n-=1
        name.append(l[mod])
    if mod!=0:
       name.append(l[n])
    name=[name[n] for n in reversed(range(len(name)))]
    print("".join(name))

if __name__=="__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    #input
    N=int(input())
    l=list("zabcdefghijklmnopqrstuvwxy")

    name=[]
    n=N
    while n>26:
        mod=n%26
        n//=26
        name.append(l[mod])
    name.append(l[n])
    name=[name[n] for n in reversed(range(len(name)))]
    print("".join(name))

if __name__=="__main__":
    main()
Problem p02759 (python)

Fixed submission:
N=int(input())
print((1+N)//2)

Buggy submission (verdict: Runtime Error):
A=[list(map(int,input().strip().split())) for n in range(3)]
A_input=[]
for n in range(3):
    for m in range(3):
        A_input.append(A[n][m])
N=int(input())
b=[int(input()) for n in range(N)]

def bingo_judge(A_input,b):
    bingo=0
    judge_list=[0,0,0,0,0,0,0,0,0]
    for number in b:
        for i in range(9):
            if number==A_input[i]:
                judge_list[i]=1
            else:
                pass
    #horizonal
    for i in range(3):
        if judge_list[3*i]*judge_list[3*i+1]*judge_list[3*i+2]==1:
            bingo=1
        else:
            pass
    #vertical
    for i in range(3):
        if judge_list[i]*judge_list[i+3]*judge_list[i+6]==1:
            bingo=1
        else:
            pass
    #diagonal
    if judge_list[0]*judge_list[4]*judge_list[8]==1:
        bingo=1
    if judge_list[2]*judge_list[4]*judge_list[6]==1:
        bingo=1
    #test display
    # judge_disp=[[judge_list[i+3*n] for i in range(3)] for n in range(3)] 
    # print(*judge_disp,sep="\n")
    
    return bingo

def main():
    ans=bingo_judge(A_input,b)
    if ans==1:
        print("yes")
    elif ans==0:
        print("No")
main()
Problem p02820 (python)

Fixed submission:
def f(c):
    """
    入力に対する勝ち手を出力
    """
    if c=="r":
        return "p"
    elif c=="s":
        return "r"
    else:
        return "s"

def main():
    """
    まずは全て勝つ組み合わせを作って、合計ポイントを求める。
    iを0からN-Kまで変化させ、T(i)=T(k+i)となる時、
    T(k+i)をT(i)、T(i+2K)と異なる手に変更する。
    ※T(i)を変更すると、T(i)=T(i+k)=T(i+2K)=...=と連続した時に、
    全て変更されてスコアが最大にならない。
    T(k+i)は勝ちから"あいこまたは負け"に変化するので、合計ポイントから差っ引く。
    """

    #input
    N,K=map(int,input().strip().split())
    R,S,P=map(int,input().strip().split())
    T=list(input())
    
    win_T=list(map(lambda x:f(x),T))
    point={"r":R,"s":S,"p":P}
    score=sum([point[win_T[n]] for n in range(N)])
    for i in range(N-K):
        l=["r","s","p"]
        if win_T[i]==win_T[i+K]:
            score-=point[win_T[i+K]]
            l.remove(win_T[i])
            if i<=N-2*K-1 and win_T[i]!=win_T[i+2*K]:
                l.remove(win_T[i+2*K])
            win_T[i+K]=l[0]
    return score

if __name__=="__main__":
    print(main())

Buggy submission (verdict: Runtime Error):
def f(c):
    """
    入力に対する勝ち手を出力
    """
    if c=="r":
        return "p"
    elif c=="s":
        return "r"
    else:
        return "s"

def main():
    """
    まずは全て勝つ組み合わせを作って、合計ポイントを求める。
    iを0からN-Kまで変化させ、T(i)=T(k+i)となる時、
    T(k+i)をT(i)、T(i+2K)と異なる手に変更する。
    ※T(i)を変更すると、T(i)=T(i+k)=T(i+2K)=...=と連続した時に、
    全て変更されてスコアが最大にならない。
    T(k+i)は勝ちから"あいこまたは負け"に変化するので、合計ポイントから差っ引く。
    """

    #input
    N,K=map(int,input().strip().split())
    R,S,P=map(int,input().strip().split())
    T=list(input())
    win_T=list(map(lambda x:f(x),T))
    point={"r":R,"s":S,"p":P}
    score=sum([point[win_T[n]] for n in range(N)])
    for i in range(N-K):
        l=["r","s","p"]
        if win_T[i]==win_T[i+K]:
            score-=point[win_T[i+K]]
            l.remove(win_T[i])
            if i<=N-2*K and win_T[i]!=win_T[i+2*K]:
                l.remove(win_T[i+2*K])
            win_T[i+K]=l[0]
    return score

if __name__=="__main__":
    print(main())
Problem p02831 (python)

Fixed submission:
A,B=map(int,input().strip().split())

def gcd(a,b):
    num=[a,b]
    GCD=0
    for i in range(1,min(num)+1):
        if a%i==0 and b%i==0:
            GCD=i
    return GCD
            
print(int(A*B/gcd(A,B)))

Buggy submission (verdict: Runtime Error):
import math

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

gcb=math.gcd(A,B)

print(int(A*B/gcb))

Buggy submission (verdict: Runtime Error):
import math

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

gcb=math.gcd(A,B)

print(int(A*B/gcb))
Problem p03038 (python)

Fixed submission:
from collections import deque
N,M=map(int,input().strip().split())
A=list(map(int,input().strip().split()))
BC=[list(map(int,input().strip().split())) for _ in range(M)]
A.sort()
A=deque(A)
BC.sort(key=lambda x:x[1],reverse=True)

ans=0
fin=False
for m in range(M):
    if fin==True:
        break
    i=0
    while i<BC[m][0]:
        if A:
            if BC[m][1]>=A[0]:
                ans+=BC[m][1]
                A.popleft()
                i+=1
            else:
                ans+=sum(A)
                fin=True
                break
        else:
            fin=True
            break
if fin==False and A:
    ans+=sum(A)
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M=map(int,input().strip().split())
A=list(map(int,input().strip().split()))
BC=[list(map(int,input().strip().split())) for _ in range(M)]
A.sort()
A=deque(A)
BC.sort(key=lambda x:x[1],reverse=True)

ans=0
fin=False
for m in range(M):
    if fin==True:
        break
    i=0
    while i<BC[m][0]:
        if BC[m][1]>=A[0]:
            ans+=BC[m][1]
            A.popleft()
            i+=1
        else:
            ans+=sum(A)
            fin=True
            break
if fin==False and A:
    ans+=sum(A)
print(ans)
Problem p02546 (python)

Fixed submission:
s=input()
s_list=list(s)
 
x=len(s_list)

if s_list[x-1]=="s":
  s_list.append("es")
else:
  s_list.append("s")

print("".join(s_list))

Buggy submission (verdict: Runtime Error):
s=input()
s_list=list(s)
 
x=len(s_list)

if s_list[x-1]=="s":
  s_list[x-1]="e"
  s_list[x]="s"
else:
  s_list.append("s")

print(s_list)

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

x=len(s_list)

a_list=reversed(s_list)
if a_list[0]=="s":
  s_list[x]="e"
  s_list[x+1]="s"
else:
  s_list[x+1]="s"

print(s_list)
Problem p02570 (python)

Fixed submission:
a=list(map(int,input().split()))
D=a[0]
T=a[1]
S=a[2]
 
v=D/T
if S>=v:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split()))
D=a[0]
T=a[0]
S=a[0]

v=D/T
if s>=v:
  print("Yes")
else:
  print("No")
Problem p02577 (python)

Fixed submission:
N=input()
a=[int(i) for i in N]
b=sum(a)

if b%9==0:
	print("Yes")
else:
	print("No")

Buggy submission (verdict: Runtime Error):
N=input()
a=[int(i) for i in N
b=sum(a)

if b%9==0:
	print("Yes")
else:
	print("No")

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

if N%9==0:
	print("Yes")
else:
	print("No")
Problem p02623 (python)

Fixed submission:
N, M ,K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

Sa = [0]*(N+1)
Sb = [0]*(M+1)
Sa[0] = 0
Sb[0] = 0
for i in range(N):
    Sa[i+1] = Sa[i] + A[i]
for i in range(M):
    Sb[i+1] = Sb[i] + B[i]
ans = 0
for i in range(N+1):
    if Sa[i] > K:
        break
    for j in range(M, -1, -1):
        if Sa[i]+Sb[j] <= K:
            ans = max(ans, i+j)
            M = j
            break
    else:
        ans = max(ans, i)
print(ans)

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

Sa = [0]*N
Sb = [0]*M
Sa[0] = A[0]
Sb[0] = B[0]
a = 0
b = 0
if Sa[0] > K:
    a = 0
else: 
    for i in range(1, N):
        Sa[i] = Sa[i-1] + A[i]
        if Sa[i] > K:
            a = i
            break
    else:
        a = N
if Sb[0] > K:
    b = 0
else:
    for i in range(1, M):
        Sb[i] = Sb[i-1] + B[i]
        if Sb[i] > K:
            b = i
            break
    else:
        b = M

ans = max(a, b)
for i in range(a):
    temp = K - Sa[i]
    if i+1+b =< ans:
        break
    for j in range(b):
        if Sb[j] > temp:
            ans = max(ans, i+1+j)
            break
    else:
        ans = max(ans, i+1+b)
print(ans)
Problem p02753 (python)

Fixed submission:
S = input()
if S[0] != S[1] or S[1] != S[2]:
    print("Yes")
else:
    print("No")

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

l = len(S)
if P == 2:
    ans = 0
    for i in range(l):
        if int(S[i])%2 == 0:
            ans += i+1
elif P == 5:
    ans = 0
    for i in range(l):
        if int(S[i])%5 == 0:
            ans += i+1
else:
    data = [0]*P
    temp = 0
    for i in range(l-1, -1, -1):
        temp += int(S[i])*10**i
        temp %= P
        data[temp] += 1
    ans = data[0]
    for item in data:
        if item > 1:
            ans += item*(item-1)//2

print(ans)
Problem p02757 (python)

Fixed submission:
N, P = map(int, input().split())
S = list(map(int, list(input())))

l = len(S)
if P == 2:
    ans = 0
    for i in range(l):
        if S[i]%2 == 0:
            ans += i+1
elif P == 5:
    ans = 0
    for i in range(l):
        if S[i]%5 == 0:
            ans += i+1
else:
    data = [0]*P
    temp = 0
    ans = 0
    for i in range(l-1, -1, -1):
        temp += S[i]*pow(10, l-i-1, P)
        temp %= P
        ans += data[temp]
        data[temp] += 1
    ans += data[0]

print(ans)

Buggy submission (verdict: Runtime Error):
from math import pow
N, P = map(int, input().split())
S = list(map(int, list(input())))

l = len(S)
if P == 2:
    ans = 0
    for i in range(l):
        if S[i]%2 == 0:
            ans += i+1
elif P == 5:
    ans = 0
    for i in range(l):
        if S[i]%5 == 0:
            ans += i+1
else:
    data = [0]*P
    temp = 0
    ans = 0
    for i in range(l-1, -1, -1):
        temp += S[i]*pow(10, l-i-1, P)
        temp %= P
        ans += data[temp]
        data[temp] += 1
    ans += data[0]

print(ans)
Problem p02571 (python)

Fixed submission:
s = input()
t = input()

c = []
for i in range(len(s) - len(t) + 1):
    count = 0
    for j in range(len(t)):
        if s[j+i] == t[j]:
            count += 1
    c.append(count)
print(len(t) - max(c))

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

c = []
for i in range(len(s) - len(t) + 1):
    count = 0
    for j in range(len(t)):
        if s[j+i] == t[j]:
            if flag:
                count += 1
            else:
                count = 1
            flag = True
        else:
            flag = False
    c.append(count)

print(len(t) - max(c))
Problem p02571 (python)

Fixed submission:
S = input()
T = input()
ans = [0] * (len(S) - len(T)+1)
for a in range(len(S) - len(T)+1):
    for b in range(len(T)):
        if S[a + b] != T[b]:
            ans[a] += 1

print(min(ans))

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
ans=[0]*(len(S) - len(T))
for a in range(len(S) - len(T)):
    for b in range(len(T)):
        if S[a + b] != T[b]:
            ans[a] += 1

print(min(ans))

Buggy submission (verdict: Runtime Error):
S = input()
T = input()
ans=[0]*(len(S) - len(T))
for a in range(len(S) - len(T)):
    for b in range(len(T)):
        if S[a + b] != T[b]:
            ans[a] += 1

print(min(ans))
Problem p02546 (python)

Fixed submission:
S = input()
if S[-1] == "s":
  print( S + "es" )
else: 
  print( S + "s" )

Buggy submission (verdict: Runtime Error):
S = input()
if S[-1] == "s":
	print( S, "es" )
else print( S, "s" )

Buggy submission (verdict: Runtime Error):
S = input()
if S[-1] == "s":
	print( S + "es" )
else print( S + "s" )

Buggy submission (verdict: Runtime Error):
S = input()
if S[-1] = "s"
	print( S, "es" )
else print( S, "s" )

Buggy submission (verdict: Runtime Error):
S = input()
if S[-1] = "s"
print( S + "es" )
else print( S + "s" )

Buggy submission (verdict: Runtime Error):
S = input()
if S[-1] = "s"
	print( S + "es" )
else print( S + "s" )

Buggy submission (verdict: Runtime Error):
S = input()
	if S[-1] = "s"
		print( S + "es" )
		else print( S + "s" )

Buggy submission (verdict: Runtime Error):
S = input()
if S[-1] = "s"
	print( S + "es" )
	else print( S + "s" )

Buggy submission (verdict: Runtime Error):
S = input()
if re.findall('[a-z]+$', S) = 's'
	print( S + 'es')
	else print( S + 's')
Problem p02547 (python)

Fixed submission:
n = int(input())
x, y = [], []
for i in range(n):
  x_, y_ = map(int, input().split())
  x.append(x_)
  y.append(y_)
for i in range(n-2):
  if x[i]==y[i] and x[i+1]==y[i+1] and x[i+2]==y[i+2]:
    print("Yes")
    break
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
x, y = [], []
for i in range(n)
  x_, y_ = map(int, input().split())
  x.append(x_)
  y.append(y_)
for i in range(n-2)
  if x[i]==y[i] and x[i+1]==y[i+1] and x[i+2]==y[i+2]:
    print("Yes")
    break
  else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
x, y = [], []
for i in range(n)
  x_, y_ = map(int, input().split())
  x.append(x_)
  y.append(y_)
for i in range(n-2)
  if x[i]==y[i] and x[i+1]==y[i+1] and x[i+2]==y[i+2]:
    print("Yes")
    break
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
x, y = [], []
for i in range(n)
x_, y_ = map(int, input().split())
x.append(x_)
y.append(y_)
for i in range(n-2)
if x[i]==y[i] and x[i+1]==y[i+1] and x[i+2]==y[i+2]:
  print("Yes")
  break
else:
  print("No")
Problem p02577 (python)

Fixed submission:
n = input()
cur = 0

for x in n:
    cur += int(x)

if cur % 9 == 0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n = input()
cur = 0
for x in n:
cur += int(x)
if cur % 9 == 0:
print("Yes")
else:
print("No")

Buggy submission (verdict: Runtime Error):
n = input()
cur = 0

for x in n:
  cur += int(x)
  if cur % 9 == 0:
    print("Yes")
    else:
      print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
if n % 9 == 0:
print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
i = input()
s = str(i)
l = len(s)

while num < l+1
ptint("num=" + int(s[-num]))
Problem p02594 (python)

Fixed submission:
i = int(input())
 
if i >=30:
  print("Yes")
else:
  print("No")

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

if i >=30:
  print("Yes")
  else:
    print("No")
Problem p02549 (python)

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

def input_int_array():
    return map(int, input().split())


MOD = 998244353


def answer():
    n, k = input_int_array()
    spans = [tuple(input_int_array()) for x in range(k)]

    count = [0] * (n)
    count[0] = 1
    accum = [0] * (n + 1)
    accum[1] = 1

    for i in range(1, n):
        j = i + 1
        for l, r in spans:
            start = max(0, j - r - 1)
            end = max(0, j - l)
            count[i] += accum[end] - accum[start]
        accum[j] = accum[j-1] + count[i] % MOD
    print(count[n-1] % MOD)


answer()

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

def input_int_array():
    return map(int, input().split())


def answer():
    n, k = input_int_array()
    spans = [tuple(input_int_array()) for x in range(k)]

    count = [0 for x in range(n)]
    count[0] = 1

    for i in range(n):
        if i > 0:
            count[i] += count[i-1]
        for j in range(k):
            l, r = spans[j]
            for lr in range(l, r + 1):
                if i + lr < n:
                    count[i + lr] += count[i]
                else:
                    break
    print(count[-1] % 998244353)


answer(