Buggy python submission (verdict: Time Limit Exceeded):
# TLE: 通常の DP (もらう DP)
# dp[i] = dp[i-x]
n, k = map(int, input().split())

S = []
for _ in range(k):
    l, r = map(int, input().split())
    for s in range(l, r+1):
        S.append(s)

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[1] = 1

for i in range(1, n+1): # i:[1,n]
    for s in S: # max n個ある！
        if i-s >= 0:
            dp[i] += dp[i-s]
            dp[i] %= MOD

print((dp[n] + MOD) % MOD)


Fixed submission:
n, k = map(int, input().split())
LR = []
for _ in range(k):
    l, r = map(int, input().split())
    LR.append([l, r+1])

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[0] = 1
dp[1] = -1

for i in range(n): # i:[0,n-1]
    if i > 0: dp[i] += dp[i-1]
    for j in range(k):
        l, r = LR[j]
        if i+l < n:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r < n:
            dp[i+r] -= dp[i]
            dp[i+r] %= MOD

print((dp[n-1] + MOD) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

F = [0]*(n+2) # [l,r+1): 1<=[l]<[r+1]<=n+1
for _ in range(k):
    l, r = map(int, input().split())
    F[l] += 1
    F[r+1] += -1

# print(F)
S = []
for i in range(n+1): # i:[0, n]
    if F[i] > 0: S.append(i)
    F[i+1] += F[i]

# print(F)
# print(n,k)
# print(S)

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[1] = 1

for i in range(1, n+1): # i:[1,n]
    for s in S:
        if i + s <= n:
            # print('s {} i {} n {}'.format(s,i,n))
            dp[i + s] += dp[i]
            dp[i + s] %= MOD

# print(dp)

print((dp[n] + MOD) % MOD)


Fixed submission:
n, k = map(int, input().split())
LR = []
for _ in range(k):
    l, r = map(int, input().split())
    LR.append([l, r+1])

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[0] = 1
dp[1] = -1

for i in range(n): # i:[0,n-1]
    if i > 0: dp[i] += dp[i-1]
    for j in range(k):
        l, r = LR[j]
        if i+l < n:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r < n:
            dp[i+r] -= dp[i]
            dp[i+r] %= MOD

print((dp[n-1] + MOD) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

F = [0]*(n+2) # [l,r+1): 1<=[l]<[r+1]<=n+1
for _ in range(k):
    l, r = map(int, input().split())
    F[l] += 1
    F[r+1] += -1

# print(F)
S = []
for i in range(n+1): # i:[0, n]
    if F[i] > 0: S.append(i)
    F[i+1] += F[i]

# print(F)
# print(n,k)
# print(S)

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[1] = 1

for i in range(1, n+1): # i:[1,n]
    for s in S:
        if i + s <= n:
            # print('s {} i {} n {}'.format(s,i,n))
            dp[i + s] += dp[i]

# print(dp)

print((dp[n] + MOD) % MOD)


Fixed submission:
n, k = map(int, input().split())
LR = []
for _ in range(k):
    l, r = map(int, input().split())
    LR.append([l, r+1])

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[0] = 1
dp[1] = -1

for i in range(n): # i:[0,n-1]
    if i > 0: dp[i] += dp[i-1]
    for j in range(k):
        l, r = LR[j]
        if i+l < n:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r < n:
            dp[i+r] -= dp[i]
            dp[i+r] %= MOD

print((dp[n-1] + MOD) % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

F = [0]*(n+2) # [l,r+1): 1<=[l]<[r+1]<=n+1
for _ in range(k):
    l, r = map(int, input().split())
    F[l] += 1
    F[r+1] += -1

# print(F)
S = []
for i in range(n+1): # i:[0, n]
    if F[i] > 0: S.append(i)
    F[i+1] += F[i]

# print(F)
# print(n,k)
# print(S)

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[1] = 1

for i in range(1, n+1): # i:[1,n]
    for s in S:
        if i + s <= n:
            # print('s {} i {} n {}'.format(s,i,n))
            dp[i + s] += dp[i]

# print(dp)

print((dp[n] + MOD) % MOD)


Fixed submission:
n, k = map(int, input().split())
LR = []
for _ in range(k):
    l, r = map(int, input().split())
    LR.append([l, r+1])

MOD = 998244353
dp = [0]*(n+1)  # [0,n]
dp[0] = 1
dp[1] = -1

for i in range(n): # i:[0,n-1]
    if i > 0: dp[i] += dp[i-1]
    for j in range(k):
        l, r = LR[j]
        if i+l < n:
            dp[i+l] += dp[i]
            dp[i+l] %= MOD
        if i+r < n:
            dp[i+r] -= dp[i]
            dp[i+r] %= MOD

print((dp[n-1] + MOD) % MOD)