Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from collections import deque
def main():
    N=int(input())
    A = [deque(map(int, input().split())) for _ in range(N)]

    days = 0
    changed = True
    played = set()
    while changed:
        played.clear()
        changed = False
        for i in range(N-1):
            if len(A[i]) == 0:
                continue
            a1 = A[i][0]
            if len(A[a1-1]) == 0:
                continue
            a2 = A[a1-1][0]
            if a1 in played or a2 in played:
                continue
            if a2-1 == i:
                A[a2-1].popleft()
                A[a1-1].popleft()
                played.add(a2)
                played.add(a1)
                changed = True
        if changed:
            days+=1

    for a in A:
        if len(a) > 0:
            print(-1)
            break
    else:
        print(days)

if __name__ == '__main__':
    main()

Fixed submission:
S=input()
T=input()
ans=0
for s,t in zip(S,T):
  if s==t:
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections 
N=int(input())
S=[collections.Counter(list(input())) for i in range(N)]

count = 0
for i in range(len(S)):
    for j in range(i+1, len(S)):
        if S[i] == S[j]:
            count += 1
print(count)


Fixed submission:
N=int(input())
S=["".join(sorted(input())) for i in range(N)]

dic = {}
for s in S:
    if s in dic.keys():
        dic[s] += 1
    else:
        dic[s] = 1

count = 0
for k in dic.keys():
    c = dic[k]
    count += (c * (c - 1)) // 2
print(count)
Buggy python submission (verdict: Runtime Error):
from math import factorial
def ncr(n,r):
    return int((factorial(n)) / (factorial(r)) / (factorial(n - r)))

DIV=10**9+7

N,K=map(int, input().split())
R=N-K
for i in range(1,K+1):
    print(ncr(R+1, i) * ncr(K-1,i-1) % DIV)


Fixed submission:
# 組み合わせの計算は下記サイトから引用
# https://qiita.com/derodero24/items/91b6468e66923a87f39f#%E7%95%AA%E5%A4%96%E7%B7%A8
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,K=map(int, input().split())
R=N-K

for i in range(1,K+1):
    if N-K+1<i or K-1<i-1:
        print(0)
    else:
        print(cmb(R+1,i,mod) * cmb(K-1,i-1,mod) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
  while b:
    a, b = b, a % b
  return a

def lcm(a, b):
  return a * b // gcd (a, b)

A,B,C,D=map(int, input().split())
CD = lcm(C, D)

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

for i in range(A,B+1,1):
  if c_first == 0 and i % C == 0:
    c_first = i // C
  if d_first == 0 and i % D == 0:
    d_first = i // D
  if cd_first == 0 and i % CD == 0:
    cd_first = i // CD  
  if c_first != 0 and d_first != 0 and cd_first != 0:
    break

for i in range(B,A-1,-1):
  if c_last == 0 and i % C == 0:
    c_last = i // C
  if d_last == 0 and i % D == 0:
    d_last = i // D
  if cd_last == 0 and i % CD == 0:
    cd_last = i // CD
  if c_last != 0 and d_last != 0 and cd_last != 0:
    break

c_count = 0
d_count = 0
cd_count = 0
if c_first != 0:
  c_count = c_last - c_first + 1
if d_first != 0:
  d_count = d_last - d_first + 1
if cd_first != 0:
  cd_count = cd_last - cd_first + 1
    
#print(c_first, c_last, d_first, d_last, cd_first, cd_last)
#print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))



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

def lcm(a, b):
  return a * b // gcd (a, b)

A,B,C,D=map(int, input().split())
CD = lcm(C, D)

c_first = 0
c_last = 0
d_first = 0
d_last = 0
cd_first = 0
cd_last = 0

c_first = (A-1) // C
c_last = B // C
d_first = (A-1) // D
d_last = B // D
cd_first = (A-1) // CD
cd_last = B // CD

c_count = 0
d_count = 0
cd_count = 0
if c_last != 0:
  c_count = c_last - c_first
if d_last != 0:
  d_count = d_last - d_first
if cd_last != 0:
  cd_count = cd_last - cd_first
    
#print(c_first, c_last, d_first, d_last, cd_first, cd_last)
#print(c_count, d_count, cd_count)
print(B - A + 1 - (c_count + d_count - cd_count))
Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
count=0
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k==S:
        count+=1
        
print(count)

Fixed submission:
K,S=map(int,input().split())
count=0
for i in range(K+1):
  for j in range(K+1):
    k = S-i-j
    if 0 <= k <= K:
        count+=1      
        
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K,S=map(int,input().split())
count=0
for i in range(K+1):
  for j in range(K+1):
    for k in range(K+1):
      if i+j+k==S:
        count+=1
        
print(count)

Fixed submission:
K,S=map(int,input().split())
count=0
for i in range(K+1):
  for j in range(K+1):
    k = S-i-j
    if 0 <= k <= K:
        count+=1      
        
print(count)
Buggy python submission (verdict: Runtime Error):
def findB(tmp):
    count = 0
    for i in tmp:
        if i == "b":
            count += 1
    return count


n, a, b = list(map(int, input().split()))
if a != 0:
    tmp = "b" * a + "r" * b
    all_str = tmp
    while True:
        if len(all_str) >= n:
            break
        all_str = all_str + tmp
    print(findB(all_str[:n]))
else:
    print("0")

Fixed submission:
n, a, b = list(map(int, input().split()))
if a != 0:
    c1 = n // (a + b)
    c2 = n - ((a + b) * c1)
    print(a * c1 + (c2 if c2 < a else a))
else:
    print("0")
Buggy python submission (verdict: Runtime Error):
import numpy as np
from scipy.sparse.csgraph import shortest_path
N, M, K = tuple(map(int, input().split()))
friends = [list(map(int, input().split())) for _ in range(M)]
blocks = [list(map(int, input().split())) for _ in range(K)]

friend_matrix = np.zeros((N, N))

for friend in friends:
	friend_matrix[friend[0]-1, friend[1]-1] = 1
	friend_matrix[friend[1]-1, friend[0]-1] = 1

# matrix for direct friendship between 2
# print('friend_matrix')
# print(friend_matrix)

# matrix for friendship distance
friend_distance = shortest_path(friend_matrix)
# print('friend_distance')
# print(friend_distance)

def is_friend_candidate(a, b):
	if a == b:
		return False
	for block in blocks:
		if block == [a, b] or block == [b, a]:
			return False
	for friend in friends:
		if friend == [a, b] or friend == [b, a]:
			return False
	if friend_distance[a-1, b-1] == np.inf:
		return False
	return True

candidate_matrix = np.zeros((N, N))
for i in range(N):
	for other in range(N):
		if candidate_matrix[i, other] == 1:
			continue
		if is_friend_candidate(i+1, other+1):
			candidate_matrix[i, other] = 1
			candidate_matrix[other, i] = 1

# matrix for friendship candidate
# print('candidate_matrix')
# print(candidate_matrix)

# atcoder numpy is outdated
# print(np.__version__)
# candidate_counts = np.count_nonzero(candidate_matrix == 1, axis=0)
candidate_counts = []
for row in candidate_matrix:
	candidate_counts.append(np.count_nonzero(row == 1))

# print('candidate_counts')
# print(candidate_counts)
print(' '.join(map(str, candidate_counts)))
	


Fixed submission:
N = int(input())
if N % 2 == 1:
	n = N + 1
else:
	n = N
print(int(n / 2))

Buggy python submission (verdict: Runtime Error):
N = input()
if N % 2 == 1:
	n = N + 1
else:
	n = N
print(int(n / 2))

Fixed submission:
N = int(input())
if N % 2 == 1:
	n = N + 1
else:
	n = N
print(int(n / 2))

Buggy python submission (verdict: Runtime Error):
N = input()
if N % 2 == 1:
	n = N + 1
else:
	n = N
print(n / 2)

Fixed submission:
N = int(input())
if N % 2 == 1:
	n = N + 1
else:
	n = N
print(int(n / 2))
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = []
for x in range(N):
	i = x + 1
	a.append(list(input().split()).extend([i]))
print(a)
sorted(a, key=lambda x:(x[0],x[1]), reverse=True)
for review in a:
	print(review[2])


Fixed submission:
N = int(input())
a = []
for x in range(N):
	i = x + 1
	S_i, P_i = input().split()
	a.append([S_i, int(P_i), i])
# print(a)
a = sorted(a, key=lambda x:(x[0],-x[1]))
for review in a:
	print(review[2])
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
LRs = None
for i in range(M):
	l, r = map(int, input().split())
	if(LRs is None):
		LRs = set(range(l, r+1))
	else:
		LRs = LRs.intersection(set(range(l, r+1)))
print(str(len(LRs)))

Fixed submission:
N, M = map(int, input().split())
l_max = 0
r_min = 10**5+1
for i in range(M):
	l, r = map(int, input().split())
	l_max = max(l, l_max)
	r_min = min(r, r_min)
if(l_max <= r_min):
	print(str(r_min - l_max + 1))
else:
	print("0")
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input()split())
print(a/b)

Fixed submission:
a,b = map(int,input().split())
print(a/b)
Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
appear_list = [[]for i in range(N)]
flag = 0
for i in range(M):
  s,c = map(int, input().split())
  appear_list[s-1].append(str(c))
ans = ""

for i in range(len(appear_list)):
  if len(set(appear_list[i])) > 1:
    flag = 1
    break
  elif len(set(appear_list[i])) == 1: 
    if appear_list[i][0] == "0" and len(ans) == 0 and i < (N-1):
      flag = 1
      break
    ans += appear_list[i][0]
  else:
    if len(ans) > 0:
	    ans += "0"
if flag == 0:
  print(int(ans))
else:
  print(-1)
  
  

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

appear_list = [[]for i in range(N)]
flag = 0
ans = ""
for i in range(M):
  s,c = map(int, input().split())
  if len(appear_list[s-1]) == 0:
    appear_list[s-1].append(str(c))
  if len(appear_list[s-1]) ==1 and appear_list[s-1][0] != str(c):
    flag = 1
    break

for i in range(len(appear_list)):
  if i == 0:
    if len(appear_list[i]) == 0 and i != N-1:
      ans += "1"
    elif len(appear_list[i]) == 0 and i == N-1:
      ans += "0"
    elif appear_list[i][0] == "0" and i != N-1:
      flag = 1
      break
    else:
      ans += appear_list[i][0]
  else:
    if len(appear_list[i]) == 0:
      ans += "0"
    else:
      ans += appear_list[i][0]
if flag == 0:
  print(int(ans))
else:
  print(-1)

Buggy python submission (verdict: Runtime Error):
N,M = map(int, input().split())
appear_list = [[]for i in range(N)]
flag = 0
for i in range(M):
  s,c = map(int, input().split())
  appear_list[s-1].append(str(c))
ans = ""

for i in range(len(appear_list)):
  if len(set(appear_list[i])) > 1:
    flag = 1
    break
  elif len(set(appear_list[i])) == 1: 
    if appear_list[i][0] == "0" and len(ans) == 0:
      flag = 1
      break
    ans += appear_list[i][0]
  else:
    if len(ans) > 0:
	    ans += "0"
if flag == 0:
  print(int(ans))
else:
  print(-1)
  
  

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

appear_list = [[]for i in range(N)]
flag = 0
ans = ""
for i in range(M):
  s,c = map(int, input().split())
  if len(appear_list[s-1]) == 0:
    appear_list[s-1].append(str(c))
  if len(appear_list[s-1]) ==1 and appear_list[s-1][0] != str(c):
    flag = 1
    break

for i in range(len(appear_list)):
  if i == 0:
    if len(appear_list[i]) == 0 and i != N-1:
      ans += "1"
    elif len(appear_list[i]) == 0 and i == N-1:
      ans += "0"
    elif appear_list[i][0] == "0" and i != N-1:
      flag = 1
      break
    else:
      ans += appear_list[i][0]
  else:
    if len(appear_list[i]) == 0:
      ans += "0"
    else:
      ans += appear_list[i][0]
if flag == 0:
  print(int(ans))
else:
  print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(N-2):
  for j in range(i+1,N): 
    ans += sum([1 for k in L[j+1:] if abs(L[j]-L[i]) < k < L[j]+L[i]])
print(ans)
  

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L.sort(reverse = True)
ans = 0

def binary(L):
  left = -1
  right = len(L)
  t = (left+right)//2
  while right-left != 1:
    if L[t] > max_len - next_len:
      left = t
    else:
      right = t
    t = (left + right) // 2
  return left + 1
  
  
for i in range(N-2):
  max_len = L[i]
  for j in range(i+1,N-1):
    next_len = L[j]
    ans += binary(L[j+1:])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
L = list(map(int,input().split()))
ans = 0
for i in range(N-2):
  candidate = L[i+1:]
  candidate_array = np.array(candidate)
  ans += sum([np.count_nonzero((candidate_array[k+1:]<L[i]+l)&(candidate_array[k+1:]>abs(l-L[i]))) for k,l in enumerate(candidate)])

print(ans)
  

Fixed submission:
N = int(input())
L = list(map(int,input().split()))
L.sort(reverse = True)
ans = 0

def binary(L):
  left = -1
  right = len(L)
  t = (left+right)//2
  while right-left != 1:
    if L[t] > max_len - next_len:
      left = t
    else:
      right = t
    t = (left + right) // 2
  return left + 1
  
  
for i in range(N-2):
  max_len = L[i]
  for j in range(i+1,N-1):
    next_len = L[j]
    ans += binary(L[j+1:])
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
sride = 1
count = 0
max_num = 0
for i in range(N-1):
  for j in range(N-sride):
    if S[j] == S[j+sride]:
      count += 1
      max_num = max(max_num, count)
    else:
      count = 0
    if count == sride:
      max_num = max(max_nuzm, count)
      break
  sride += 1
  count = 0
print(max_num)


Fixed submission:
N = int(input())
S = input()
sride = 1
count = 0
max_num = 0
for i in range(N-1):
  for j in range(N-sride):
    if S[j] == S[j+sride]:
      count += 1
      max_num = max(max_num, count)
    else:
      count = 0
    if count == sride:
      max_num = max(max_num, count)
      break
  sride += 1
  count = 0
print(max_num)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = input()
sride = 1
count = 0
max_num = 0
for i in range(N-1):
  for j in range(N-sride):
    if S[j] == S[j+sride]:
      count += 1
      max_num = max(max_num, count)
    else:
      count = 0
    if count == sride:
      max_num = max(max_num, count)
      break
  sride += 1
  count = 0
print(max_num)


Fixed submission:
N = int(input())
S = input()
sride = 1
count = 0
max_num = 0
for i in range(N-1):
  for j in range(N-sride):
    if S[j] == S[j+sride]:
      count += 1
      max_num = max(max_num, count)
    else:
      count = 0
    if count == sride:
      max_num = max(max_num, count)
      break
  sride += 1
  count = 0
print(max_num)

Buggy python submission (verdict: Runtime Error):
N = int(input())
S = input()
max_range = N//2
count_list = [[0 for j in range 50005] for i in range 5005]
print(count_list.shape)
print(count_list)

Fixed submission:
N = int(input())
S = input()
sride = 1
count = 0
max_num = 0
for i in range(N-1):
  for j in range(N-sride):
    if S[j] == S[j+sride]:
      count += 1
      max_num = max(max_num, count)
    else:
      count = 0
    if count == sride:
      max_num = max(max_num, count)
      break
  sride += 1
  count = 0
print(max_num)
Buggy python submission (verdict: Runtime Error):
N = int(input())
B = list(map(int,input().split()))
ins = 0
count = 0
for i in range(N):
  if i == 0:
    count += B[i]
  if i > 0 and B[i-1] > B[i]:
    count += B[i]
  elif i > 0 and B[i-1] <= B[i]:
    count += B[i-1]
print(count)

Fixed submission:
N = int(input())
B = list(map(int,input().split()))
ins = 0
count = 0
for i in range(N-1):
  if i == 0:
    count += B[i]
  if i > 0 and B[i-1] > B[i]:
    count += B[i]
  elif i > 0 and B[i-1] <= B[i]:
    count += B[i-1]
count += B[i]
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int,input().split())
reward = [0]*N
for i in range(N):
  A,B = map(int,input().split())
  reward[i] = [A,B]
ans = 0
remain_day = 1
for i in range(M):
  max = 0
  reward_max = [j for j in reward if j[0] <= remain_day]
  reward_max = sorted(reward_max,key=lambda x:(x[1]),reverse = True)
  if len(reward_max) > 0:
    ans +=reward_max[0][1]
    reward.remove(reward_max[0])
  reward_max = []
  remain_day += 1
print(ans)
  
  
  
  


Fixed submission:
import heapq
N, M = map(int,input().split())
reward = [[] for _ in range(M)]
for i in range(N):
  A,B = map(int,input().split())
  if A <= M:
    reward[A-1].append(B)
q = []
ans = 0
for day in range(M):
  for r in reward[day]:
    heapq.heappush(q,-r)
  if len(q) >0:
    ans += -heapq.heappop(q)
print(ans)
Buggy python submission (verdict: Runtime Error):
#D問題
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

N, K = map(int, input().split())
red = N - K
for i in range(K):
    if i+1 ==1:
        ans = (red+1)
        print(ans)
    else:
        if i + 1 < K:
            divide_line = combinations_count(red+1, i+1)
            case =combinations_count(K-1,i) * divide_line
            ans = case%(10**9+7)
            print(ans)
        else:
            ans = combinations_count(red+1,K)%(10**9 + 7)
            print(ans)
    

Fixed submission:
#D問題
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

N, K = map(int, input().split())
red = N - K
for i in range(1,K+1):
        if N-K+1 < i:
            print(0)
        else:
            divide_line = combinations_count(red+1, i)
            case =combinations_count(K-1,i-1) * divide_line
            ans = case%(10**9+7)
            print(ans)

Buggy python submission (verdict: Runtime Error):
#D問題
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

N, K = map(int, input().split())
red = N - K
for i in range(K):
    if i+1 ==1:
        ans = (red+1)
        print(ans)
    else:
        if i + 1 < K:
            divide_line = combinations_count(K-1, i)
            case =combinations_count(red+1,i+1) * divide_line
            ans = case%(10**9+7)
            print(ans)
        else:
            ans = combinations_count(red+1,K)%(10**9 + 7)
            print(ans)
    

Fixed submission:
#D問題
import math
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

N, K = map(int, input().split())
red = N - K
for i in range(1,K+1):
        if N-K+1 < i:
            print(0)
        else:
            divide_line = combinations_count(red+1, i)
            case =combinations_count(K-1,i-1) * divide_line
            ans = case%(10**9+7)
            print(ans)
Buggy python submission (verdict: Runtime Error):
#D問題
N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M):
    for j in range(M-i):
        if i+j >N:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k > len(dump_num):
                break;
            if dump_num[k] >= 1:
                break;
            num -=dump_num[k]
        
        if num > ans:
            ans = num
print(ans)
            

Fixed submission:
#D問題
N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M+1):
    for j in range(M+1-i):
        if i+j >N:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k >= len(dump_num):
                break;
            if dump_num[k] >= 0:
                break;
            num -= dump_num[k]
        
        if num >= ans:
            ans = num
print(ans)

Buggy python submission (verdict: Runtime Error):
#D問題
N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M):
    for j in range(M-i):
        if i+j >M:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k >= len(dump_num):
                break;
            if dump_num[k] >= 1:
                break;
            num -=dump_num[k]
        if num > ans:
            ans = num
print(ans)
            

Fixed submission:
#D問題
N, M=map(int, input().split())
V = input().split()
V_i = [int(i) for i in V]

ans = 0
for i in range(M+1):
    for j in range(M+1-i):
        if i+j >N:
            break;
        num = 0
        dump_num = []
        for k in range(i):
            num += V_i[k]
            dump_num.append(V_i[k])
        for k in range(N-1,N-j-1,-1):
            num+=V_i[k]
            dump_num.append(V_i[k])
        dump_num.sort()
        for k in range(M-i-j):
            if k >= len(dump_num):
                break;
            if dump_num[k] >= 0:
                break;
            num -= dump_num[k]
        
        if num >= ans:
            ans = num
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#C問題
N, M = map(int, input().split())
N_list = []
for i in range (N):
    N_list.append(i+1)

L_list = []
R_list = []
for i in range(M):
    L, R = map(int, input().split())
    L_list.append(L)
    R_list.append(R)

N_list= [i for i in N_list if i >= max(L_list) and i<=min(R_list)]
print(len(N_list))

Fixed submission:
#C問題
import numpy as np
N, M = map(int, input().split())
L_list = []
R_list = []
for i in range(M):
    L, R = map(int, input().split())
    L_list.append(L)
    R_list.append(R)
if min(R_list) - max(L_list) < 0:
    print(0)
else:
    print(min(R_list) - max(L_list)+1)

Buggy python submission (verdict: Time Limit Exceeded):
#C問題
N, M = map(int, input().split())
N_list = []
for i in range (N):
    N_list.append(i+1)
for i in range(M):
    L, R = map(int, input().split())
    N_list= [i for i in N_list if i >= L and i<=R]
print(len(N_list))


Fixed submission:
#C問題
import numpy as np
N, M = map(int, input().split())
L_list = []
R_list = []
for i in range(M):
    L, R = map(int, input().split())
    L_list.append(L)
    R_list.append(R)
if min(R_list) - max(L_list) < 0:
    print(0)
else:
    print(min(R_list) - max(L_list)+1)