Buggy python submission (verdict: Runtime Error):
# 配るDP
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  LRs = []
  for _ in range(K):
    (L, R) = map(int, input().split(" "))
    LRs.append((L, R))

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

  for i in range(1, N):
    dp[i] += dp[i-1]

    for lr in LRs:
      left = i + lr[0]
      right = i + lr[1] + 1
      if left <= N:
        dp[left] += dp[i]
        dp[left] = mod(dp[left], base)
      if right <= N:
        dp[right] -= dp[i]
        dp[right] = mod(dp[right], base)
  print(mod(dp[-1], base))

if __name__ == "__main__":
  resolve()

Fixed submission:
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  LRs = []
  for _ in range(K):
    (L, R) = map(int, input().split(" "))
    LRs.append((L, R))

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

  for i in range(2, N+1):
    for lr in LRs:
      left = max(i - lr[1] - 1, 0)
      right = max(i - lr[0], 0)
      dp[i] += dp_sum[right] - dp_sum[left]
      if dp[i] >= base:
        dp[i] %= base
      dp_sum[i] = dp_sum[i-1] + dp[i]
  print(dp[-1])

if __name__ == "__main__":
  resolve()

Buggy python submission (verdict: Time Limit Exceeded):
# 配るDP
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  LRs = []
  for _ in range(K):
    (L, R) = map(int, input().split(" "))
    LRs.append((L, R))

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

  for i in range(1, N+1):
    dp_sum[i] = dp[i] + dp_sum[i-1]
    if dp_sum[i] > base:
      dp_sum[i] %= base
    for lr in LRs:
      left = i + lr[0]
      right = i + lr[1] + 1
      if left <= N:
        dp[left] += dp_sum[i]
      if right <= N:
        dp[right] -= dp_sum[i]
    
  print(dp[-1]%base)

if __name__ == "__main__":
  resolve()

Fixed submission:
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  LRs = []
  for _ in range(K):
    (L, R) = map(int, input().split(" "))
    LRs.append((L, R))

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

  for i in range(2, N+1):
    for lr in LRs:
      left = max(i - lr[1] - 1, 0)
      right = max(i - lr[0], 0)
      dp[i] += dp_sum[right] - dp_sum[left]
      if dp[i] >= base:
        dp[i] %= base
      dp_sum[i] = dp_sum[i-1] + dp[i]
  print(dp[-1])

if __name__ == "__main__":
  resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  step_lengthes = []
  for _ in range(K):
    L, R = map(int, input().split(" "))
    step_lengthes.extend(range(L, R+1))
  step_lengthes.sort()
  dp = [0] * (N+1)
  dp[1] = 1

  for i in range(1, N+1):
    for d in step_lengthes:
      if i+d <= N:
        dp[i+d] += dp[i]
        if i+d == N and dp[i+d] >= base:
          dp[i+d] %= base
      else:
        break
  print(dp[-1]%base)

if __name__ == "__main__":
  resolve()

Fixed submission:
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  LRs = []
  for _ in range(K):
    (L, R) = map(int, input().split(" "))
    LRs.append((L, R))

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

  for i in range(2, N+1):
    for lr in LRs:
      left = max(i - lr[1] - 1, 0)
      right = max(i - lr[0], 0)
      dp[i] += dp_sum[right] - dp_sum[left]
      if dp[i] >= base:
        dp[i] %= base
      dp_sum[i] = dp_sum[i-1] + dp[i]
  print(dp[-1])

if __name__ == "__main__":
  resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  step_lengthes = []
  for _ in range(K):
    L, R = map(int, input().split(" "))
    step_lengthes.extend(range(L, R+1))
  step_lengthes.sort()
  dp = [0] * (N+1)
  dp[1] = 1

  for i in range(1, N+1):
    for d in step_lengthes:
      if i+d <= N:
        dp[i+d] += dp[i]
      else:
        break
  print(dp[-1]%998244353)

if __name__ == "__main__":
  resolve()

Fixed submission:
def resolve():
  base = 998244353
  N, K = map(int, input().split(" "))

  LRs = []
  for _ in range(K):
    (L, R) = map(int, input().split(" "))
    LRs.append((L, R))

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

  for i in range(2, N+1):
    for lr in LRs:
      left = max(i - lr[1] - 1, 0)
      right = max(i - lr[0], 0)
      dp[i] += dp_sum[right] - dp_sum[left]
      if dp[i] >= base:
        dp[i] %= base
      dp_sum[i] = dp_sum[i-1] + dp[i]
  print(dp[-1])

if __name__ == "__main__":
  resolve()