Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
mod=998244353
s=set()
for _ in range(k):
  l,r=map(int,input().split())
  for j in range(l,r+1):
    s.add(j)
m=len(s)
dp=[0]*n
dp[0]=1
for i in range(1,n):
  for j in s:
    if i-j>=0:
      dp[i]+=dp[i-j]
print(dp[n-1]%mod)


Fixed submission:
n,k=map(int,input().split())
mod=998244353
l=[0]*n
r=[0]*n
for i in range(k):
  l[i],r[i]=map(int,input().split())
dp=[0]*(n+10)
dp[0]=1
sumdp=[0]*(n+10)
sumdp[1]=1
for i in range(1,n):
  for j in range(k):
    li=max(0,i-r[j])
    ri=max(0,i-l[j]+1)
    dp[i]+=sumdp[ri]-sumdp[li]
  sumdp[i+1]=(sumdp[i]+dp[i])%mod
print(dp[n-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
mod=998244353
r=[0]*k
l=[0]*k
for _ in range(k):
  l_,r_=map(int,input().split())
  l[_]=l_
  r[_]=r_
dp=[0]*n
dp[0]=1
dpsum=[0]*n
dpsum[0]=1
for i in range(1,n):
  for j in range(k):
    li=i-r[j]
    ri=i-l[j]
    if ri>=0:
      li=max(li,0)
      dp[i]+=dpsum[ri]-dpsum[li-1]
  dpsum[i]=dpsum[i-1]+dp[i]
print(dp[n-1]%mod)

Fixed submission:
n,k=map(int,input().split())
mod=998244353
l=[0]*n
r=[0]*n
for i in range(k):
  l[i],r[i]=map(int,input().split())
dp=[0]*(n+10)
dp[0]=1
sumdp=[0]*(n+10)
sumdp[1]=1
for i in range(1,n):
  for j in range(k):
    li=max(0,i-r[j])
    ri=max(0,i-l[j]+1)
    dp[i]+=sumdp[ri]-sumdp[li]
  sumdp[i+1]=(sumdp[i]+dp[i])%mod
print(dp[n-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
mod=998244353
r=[]
l=[]
for _ in range(k):
  l_,r_=map(int,input().split())
  l.append(l_)
  r.append(r_)
dp=[0]*n
dp[0]=1
dpsum=[0]*n
dpsum[0]=1
for i in range(1,n):
  for j in range(k):
    li=i-r[j]
    ri=i-l[j]
    if ri>=0:
      li=max(li,0)
      dp[i]+=dpsum[ri]-dpsum[li-1]
  dpsum[i]=dpsum[i-1]+dp[i]
print(dp[n-1]%mod)

Fixed submission:
n,k=map(int,input().split())
mod=998244353
l=[0]*n
r=[0]*n
for i in range(k):
  l[i],r[i]=map(int,input().split())
dp=[0]*(n+10)
dp[0]=1
sumdp=[0]*(n+10)
sumdp[1]=1
for i in range(1,n):
  for j in range(k):
    li=max(0,i-r[j])
    ri=max(0,i-l[j]+1)
    dp[i]+=sumdp[ri]-sumdp[li]
  sumdp[i+1]=(sumdp[i]+dp[i])%mod
print(dp[n-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
mod=998244353
s=set()
for _ in range(k):
  l,r=map(int,input().split())
  s=s|set(i for i in range(l,r+1))
dp=[0]*n
dp[0]=1
for i in range(1,n):
  for j in s:
    if i-j>=0:
      dp[i]+=dp[i-j]
print(dp[n-1]%mod)


Fixed submission:
n,k=map(int,input().split())
mod=998244353
l=[0]*n
r=[0]*n
for i in range(k):
  l[i],r[i]=map(int,input().split())
dp=[0]*(n+10)
dp[0]=1
sumdp=[0]*(n+10)
sumdp[1]=1
for i in range(1,n):
  for j in range(k):
    li=max(0,i-r[j])
    ri=max(0,i-l[j]+1)
    dp[i]+=sumdp[ri]-sumdp[li]
  sumdp[i+1]=(sumdp[i]+dp[i])%mod
print(dp[n-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
mod=998244353
s=set()
for _ in range(k):
  l,r=map(int,input().split())
  for j in range(l,r+1):
    s.add(j)
m=len(s)
dp=[0]*n
dp[0]=1
for i in range(1,n):
  for j in s:
    if i-j>=0:
      dp[i]+=dp[i-j]
print(dp[n-1]%mod)


Fixed submission:
n,k=map(int,input().split())
mod=998244353
l=[0]*n
r=[0]*n
for i in range(k):
  l[i],r[i]=map(int,input().split())
dp=[0]*(n+10)
dp[0]=1
sumdp=[0]*(n+10)
sumdp[1]=1
for i in range(1,n):
  for j in range(k):
    li=max(0,i-r[j])
    ri=max(0,i-l[j]+1)
    dp[i]+=sumdp[ri]-sumdp[li]
  sumdp[i+1]=(sumdp[i]+dp[i])%mod
print(dp[n-1]%mod)