Problem:


Score : 300 points

Problem Statement

We have N ID cards, and there are M gates.

We can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.

How many of the ID cards allow us to pass all the gates alone?

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq M \leq 10^5

1 \leq L_i \leq R_i \leq N

Input

Input is given from Standard Input in the following format:

N M
L_1 R_1
L_2 R_2
\vdots
L_M R_M

Output

Print the number of ID cards that allow us to pass all the gates alone.

Sample Input 1

4 2
1 3
2 4

Sample Output 1

2

Two ID cards allow us to pass all the gates alone, as follows:

The first ID card does not allow us to pass the second gate.

The second ID card allows us to pass all the gates.

The third ID card allows us to pass all the gates.

The fourth ID card does not allow us to pass the first gate.

Sample Input 2

10 3
3 6
5 7
6 9

Sample Output 2

1

Sample Input 3

100000 1
1 100000

Sample Output 3

100000



Sample input:
4 2
1 3
2 4


Sample output:
2

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m = map(int, readline().split())
lr = [list(map(int, readline().split())) for _ in range(m)]

id_list = [i for i in range(lr[0][0], lr[0][1] + 1)]
for i in range(1, m):
    x = 1
    id_list = [j for j in id_list if lr[i][0] <= j <= lr[i][1]]
print(len(id_list))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
k = []
for i in range(m):
    l, r = map(int, input().split())
    k.append(list(range(l, r + 1)))
c = [0] * n
for i in range(m):
    for j in range(n):
        if (j + 1) in k[i]:
            c[j] += 1
count = 0
for i in c:
    if m == i:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())

max_L = []
min_R = []

cnt = 0
for i in range(m):
    L,R = map(int,input().split())
    max_L.append(L)
    min_R.append(R)

for i in range(1,n+1):
    if max(max_L) <= i <= min(min_R):
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
lr = [[] for i in range(m)]
cnt = 0
for _ in range(m):
    l,r = map(int,input().split())
    lr[_].append(l)
    lr[_].append(r)

for nn in range(1,n+1):
    ok = True
    for ran in lr:
        if ran[0] > nn or ran[1] < nn:
            ok = False
    if ok:
        cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
B=[0]*N
for i in range(M):
    l,r=map(int,input().split())
    for j in range(l-1,r):
        B[j]+=1
print(B.count(M))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
A=set(i for i in range(1,N+1))
for i in range(M):
    l,r=map(int,input().split())
    A=set(j for j in range(l,r+1) if j in A)
print(len(A))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
count=0
A=[i for i in range(1,N+1)]
for i in range(M):
    l,r=map(int,input().split())
    A=[j for j in range(l,r+1) if j in A]
print(len(A))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import numpy as np

n, m = map(int, input().split())
tar = [0] * (1 + 10 ** 5)
tar = np.array(tar)

for i in range(m):
    l, r = map(int, input().split())
    tar[l:r + 1] += 1
    #print(tar[:10])

#tar = tar.tolist()
# print(tar[0:5])
count = Counter(tar)
ans = count[m]
print(ans)
'''
n, m = map(int, input().split())

ll, rr = map(int, input().split())
for i in range(m - 1):
    l, r = map(int, input().split())

    #lについて
    if (l <= ll):
      pass
    elif (ll < l )

ans = max(ll - rr, 0)
print(ans)

'''

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import numpy as np

n, m = map(int, input().split())

tar = [1] * (1 + 10 ** 5)
tar = np.array(tar)

for i in range(m):
    l, r = map(int, input().split())
    tar[:l-1] = 0
    tar[r:] = 0

#tar = tar.tolist()
# print(tar[0:5])
count = Counter(tar)
ans = count[1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import numpy as np

n, m = map(int, input().split())

tar = [1] * (1 + 10 ** 5)
tar = np.array(tar)

for i in range(m):
    l, r = map(int, input().split())
    tar[:l-1] = 0
    tar[r:] = 0

tar = tar.tolist()
#print(tar[0:5])
count = Counter(tar)
ans = count[1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0
M_list = list(range(M))
for i in M_list:
    L,R=map(int,input().split())
    L_list.append(L)
    R_list.append(R)


for i in range(1,N+1):
    for j in M_list:
        if(i >= L_list[j] and i<=R_list[j]):
           
            if j==M-1:
                count+=1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
L_list = []
R_list = []
count = 0

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

for i in range(1,N+1):
    for j in range(M):
        if(i >= L_list[j] and i<=R_list[j]):
           
            if j==M-1:
                count+=1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

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

for i in range(1,N+1):

    for j in range(M):
        if(i in range(L_list[j],R_list[j]+1)):
            if j==M-1:
                count+=1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
'''
4 2
1 3
2 4
'''

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

for i in range(1,N+1):

    for j in range(M):
        if(i in range(L_list[j],R_list[j]+1)):
            if j==M-1:
                count+=1
        else:
            break
print(count)

Submission status: Time Limit Exceeded

Solution code:
'''
4 2
1 3
2 4
'''

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

for i in range(1,N+1):
    check = True
    for j in range(M):
        if(i in range(L_list[j],R_list[j]+1)):
            if check:
                if j==M-1:
                    count+=1
        else:
            check = False
print(count)

Submission status: Time Limit Exceeded

Solution code:

N, M=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
LR=[[int(i) for i in input().split()] for i in range(M)]  # 二次元配列入力　二次元マップみたいな入力のとき

ret = set(range(LR[0][0], LR[0][1]+1))

for i in LR[1:]:
    ret = set(range(i[0], i[1]+1)) & ret

print(len(ret))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l = [0 for _ in range(n)]

for _ in range(m):
  a, b = [int(x)-1 for x in input().split()]
  for i in range(b-a+1):
    l[a+i] += 1
  
print(l.count(m))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]

nums = list(range(1,n+1))
ans = 0
for i in nums:
  for j in lr:
    if i < j[0] or i > j[1]:
      break
  else:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())


LR = [list(map(int,input().split())) for _ in range(M)]

set_ans = set(range(int(LR[0][0]),int(LR[0][1]+1)))
for m in range(1,M):
  set_ans = set_ans & set(range(int(LR[m][0]),int(LR[m][1])+1))
  if len(set_ans) == 0:
    break
print(len(set_ans))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
flag=n*[0]
for i in range(m):
    l,r=map(int,input().split())
    flag[l-1:r]=list(map(lambda n: n+1,flag[l-1:r]))

print(flag.count(m))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
cn = [i for i in range(1,n+1)]
for i in range(m):
    l,r = map(int, input().split())
    lr = [i for i in range(l,r+1)]
    cn = set(cn)&set(lr)
print(len(cn))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l, r = map(int, input().split())
S = set(range(l, r + 1))
for i in range(m - 1):
	l, r = map(int, input().split())
	S &= set(range(l, r + 1))
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
L = [0]*M
R = [0]*M

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

d={}

cnt = 0

for i in range(M):
    l = L[i]
    r=R[i]
    
    for j in range(l,r+1):
        
        if j in d:
            d[j] += 1
        else:
            d[j] = 1
            
        if d[j] >= M:
            cnt+=1
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
L = [0]*M
R = [0]*M

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

d={}

for i in range(M):
    l = L[i]
    r=R[i]
    
    for j in range(l,r+1):
        
        if j in d:
            d[j] += 1
        else:
            d[j] = 1
    
cnt = 0
for i in d.values():
    if i >=M:
        cnt+=1
        
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
a = [0]*N
for i in range(M):
    L, R = map(int, input().split())
    for b in range(R-L+1):
        a[L+b-1] += 1
count = 0
for c in a:
    if c == M:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
"""
i番目のゲートは LiからRiまでのIDカードのうちどれか1枚を持っていれば通過できます
"""

N, M = map(int, input().split())
arr = [0]*N

for i in range(M):
    L, R = map(int, input().split())
    for j in range(L,R+1,1):
        arr[j-1] += 1

print(arr.count(M))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())

card = [0] * N
for i in range(M):
  L,R = map(int,input().split())
  for j in range(L,R+1):
    card[j-1] +=1
    
print(card.count(M))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
row1 = list(map(int, input().split()))
lis = list(range(row1[0], row1[1]+1))
#print(lis)

for i in range(m-1):
  rowi = list(map(int, input().split()))
  rowi = list(range(rowi[0], rowi[1]+1))
  newlis = []
  for j in lis:
    #print(j)
    if j in rowi:
      newlis.append(j)
    #print(newlis)
  lis = newlis
      
print(len(lis))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=list(range(1,n+1))
for i in range(m):
	b=list(map(int,input().split()))
	c=list(range(b[0],b[1]+1))
	a=list(set(c) & set(a))
print(len(list(a)))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
ans = set(range(1, N + 1))
for lr in LR:
  ans = ans & set(range(lr[0], lr[1] + 1))
  
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l, r = [0]*m, [0]*m
for i in range(m):
    l[i], r[i] = map(int, input().split())

ans = [0]*n
for i in range(m):
    memo = [0]*n
    for j in range(l[i]-1, r[i]):
        memo[j] = 1        
    for k in range(n):
        ans[k] += memo[k]

print(ans.count(m))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
f=2**n-1
for _ in range(m):
    l,r=map(int,input().split())
    b=0
    for i in range(l-1,r):
        b=b+(1<<i)
    f=f&b
a=0
while f:
    a+=f&1
    f=f>>1
print(a)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int,input().split())

a = [0]*(N+1)
ans = 0

for  i in range(M):
  L,R = map(int,input().split())
  for _ in range(L,R+1):
    a[_] += 1
    
for j in range(N+1):
  if a[j] == M:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(m)]
ans = 0

for j in range(1, n+1):
    flag = True
    for k in range(m):
        if l[k][0] <= j <= l[k][1]:
            continue
        else:
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
 
hashset = None
 
for _ in range(M):
  L, R = map(int, input().split())
  if hashset is None:
    hashset = set(range(L, R+1))
  else:
    hashset = hashset & set(range(L, R+1))

print(len(hashset))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
ll = [0 for i in range(n+1)]
for _ in range(m):
    l, r = map(int, input().split())
    for i in range(l, r+1, 1):
        ll[i] += 1

print(ll.count(m))

Submission status: Time Limit Exceeded

Solution code:
N,M = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(M)]

B = [0] * (N)
for i in range(M):

    for j in range(A[i][0]-1,A[i][1]):
        B[j] += 1
print(B.count(M))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())

result = [0]*N

for m in range(M):
    L, R = map(int, input().split())
    for i in range(L, R+1):
        result[i-1] += 1

counter = 0
for i in result:
    if i == M:
        counter += 1
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N, M = map(int, input().split())

result = []

for m in range(M):
    L, R = map(int, input().split())
    result = result + list(range(L, R+1))

counter = 0
for v in Counter(result).values():
    if v == M:
        counter += 1
    else:
        continue

print(counter)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
a=[0]*n
for i in range(m):
  l,r=map(int,input().split())
  for k in range(l-1,r):
    a[k]+=1
ans=0
for i in range(n):
  if a[i]==m:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
s=[0]*n

for i in range(m):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        s[j-1]+=1


print(s.count(m))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
s=[0]*n

for i in range(m):
    l,r=map(int,input().split())
    for j in range(l,r+1):
        s[j-1]+=1

cnt=0
for k in range(n):
    if s[k]==m:
        cnt+=1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# input
N, M = map(int, input().split())
mastar_keys = set(list(range(1, N + 1)))
check = []
c_append = check.append
for i in range(1, M + 1):
    L, R = map(int, input().split())
    c = set(list(range(L, R + 1)))
    mastar_keys = mastar_keys & c

print(len(mastar_keys))

Submission status: Time Limit Exceeded

Solution code:
# input
N, M = map(int, input().split())
check = []
c_append = check.append
for i in range(1, M + 1):
    L, R = map(int, input().split())
    c = set(list(range(L, R + 1)))
    if c not in check:
        c_append(c)

# check
mastar_keys = set(list(range(1, N + 1)))
for c in sorted(check, key=lambda x: len(x)):
    mastar_keys = mastar_keys & c
    if len(mastar_keys) == 0:
        break

print(len(mastar_keys))

Submission status: Time Limit Exceeded

Solution code:
# input
N, M = map(int, input().split())
check = []
c_append = check.append
for i in range(1, M + 1):
    L, R = map(int, input().split())
    c_append(set(list(range(L, R + 1))))

# check
mastar_keys = set(list(range(1, N + 1)))
for c in sorted(check, key=lambda x: len(x)):
    mastar_keys = mastar_keys & c
    if len(mastar_keys) == 0:
        break

print(len(mastar_keys))

Submission status: Time Limit Exceeded

Solution code:
# input
N, M = map(int, input().split())
check = {}
for i in range(1, M + 1):
    L, R = map(int, input().split())
    check[i] = set(list(range(L, R + 1)))

# check
mastar_keys = set(list(range(1, N + 1)))
for k in check.keys():
    mastar_keys = mastar_keys & check[k]

print(len(mastar_keys))

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,m = map(int, input().split())
d = [0]*n
for i in range(m):
    l,r = map(int, input().split())
    for i in range(l-1,r):
        d[i]+=1
count = 0
for i in d:
    if i == m:
        count+=1       
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
gate = [0] * N
maxL, minR = 0, N
for i in range(M):
    L, R = map(int, input().split())
    maxL = max(maxL, L-1)
    minR = min(minR, R-1)
    for j in range(maxL, minR+1):
        gate[j] += 1

count = 0
for k in gate:
    if k == M:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
gate = [0] * N
for i in range(M):
    L, R = map(int, input().split())
    for j in range(L-1, R):
        gate[j] += 1

count = 0
for k in gate:
    if k == M:
        count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
L = [None] * M
R = [None] * M
for i in range(M):
    L[i], R[i] = list(map(int, input().split()))

l = [0] * N
for i in range(M):
    for j in range(L[i], R[i] + 1):
        l[j - 1] += 1
a = 0
for i in range(N):
    if l[i] == M:
        a += 1
print(a)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for i in range(m)]
a=set(range(lr[0][0],lr[0][1]+1))
for j in range(1,m):
  a=a&set(range(lr[j][0],lr[j][1]+1))
print(len(a))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for i in range(m)]
lis=[0]*n
for l,r in lr:
  for t in range(l,r+1):
    lis[t-1]+=1
ans=0
for ll in lis:
  if ll==m:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
A =[]
for _ in range(m):
    l,r = map(int,input().split())
    tmp = [i for i in range(l,r+1)]
    A += tmp

from collections import Counter
cnt = Counter(A)
ans = []

for k,v in cnt.items():
    if v == m:
        ans.append(k)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = [list(map(int, input().split())) for i in range(M)]
B = {x for x in range(A[0][0], A[0][1]+1)}
for i in range(1,M):
  C = {x for x in range(A[i][0],A[i][1]+1)}
  B = B & C
ans = len(B)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    n, m = map(int, input().split())
    ans = set([i for i in range(1 , n + 1)])
    for _ in range(m):
        l, r = map(int, input().split())
        card = set([i for i in range(l, r + 1)])
        ans = ans & card
    print(len(ans))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
L, R = map(int, input().split())
CARDS = {i for i in range(L,R+1)}

for i in range(M-1):
    L, R = map(int, input().split())
    CARDS &= {card for card in range(L,R+1)}
    if CARDS == set():
        break

print(len(CARDS))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
CARDS = {i for i in range(1,N+1)}

for i in range(M):
    L, R = map(int, input().split())
    CARDS &= {card for card in range(L,R+1)}

print(len(CARDS))

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import Counter


def main():
    N, M = map(int, input().split())
    LR = []
    for _ in range(M):
        L, R = map(int, input().split())
        LR.append(list(range(L, R + 1)))
    LR = list(itertools.chain.from_iterable(LR))
    C = Counter(LR)

    ans = 0
    for c in C.values():
        if c == M:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import Counter


def main():
    N, M = map(int, input().split())
    LR = []
    for _ in range(M):
        L, R = map(int, input().split())
        LR.append(list(range(L, R + 1)))
    LR = list(itertools.chain.from_iterable(LR))
    C = Counter(LR)

    ans = 0
    for c in C.values():
        if c == M:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import fractions
import functools
import copy
n, m = map(int, input().split())
lr = []
for i in range(m):
    l, r = map(int, input().split())
    lr.append([l,r])

result = list(range(lr[0][0],lr[0][1]+1))

for i in range(len(result)):
    for pair in lr:
        if not(pair[0] <= result[i] and pair[1] >= result[i]):
            result[i] = -1

print(len(result)-result.count(-1))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
B = set()
for i in range(M):
  L, R = map(int, input().split())
  A = set(j for j in range(L, R+1))
  if i == 0:
    B = A
  B = A & B
print(len(B))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
lr_list = list()
for _ in range(m):
    lr_list.append(list(map(int, input().split())))

card_list = [i for i in range(1, n + 1)]

max_l = 0
min_r = 1e6

for l, r in lr_list:
    # print(f"{card_list=}")
    # print(f"{max_l=}, {min_r=}")
    if l > max_l or r < min_r:
        max_l = l
        min_r = r
        new_card_list = []
        for card in card_list:
            if card >= max_l and card <= min_r:
                new_card_list.append(card)
        card_list = new_card_list


print(len(card_list))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
lr_list = list()
for _ in range(m):
    lr_list.append(list(map(int, input().split())))

card_list = [i for i in range(1, n + 1)]

for l, r in lr_list:
    new_card_list = []
    for card in card_list:
        if card >= l and card <= r:
            new_card_list.append(card)
    card_list = new_card_list

print(len(card_list))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
lr_list = list()
for _ in range(m):
    lr_list.append(list(map(int, input().split())))

master_card_set = {i for i in range(1, n + 1)}

for l, r in lr_list:
    card_set = {i for i in range(l, r + 1)}
    master_card_set = master_card_set & card_set

print(len(master_card_set))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
lr_list = list()
for _ in range(m):
    lr_list.append(list(map(int, input().split())))

card_list = [i for i in (1, n + 1)]

set_list = list()
for l, r in lr_list:
    set_list.append({i for i in range(l, r + 1)})

u = set.intersection(*set_list)
print(len(u))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
L = [0] * M
R = [0] * M
for i in range (0,M):
    L[i],R[i] = map(int,input().split())

S = [set(range(L[i],R[i]+1)) for i in range(0,M)]

temp = S[0]

for i in range(1,M):
    temp = temp & S[i]

print(len(temp))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
def main():
    N, M = map(int, input().split())
    arr = [list(map(int, input().split())) for i in range(M)]
    ID = [True]*N
    for arrs in arr:
        L, R = arrs
        for i in range(N):
            if L-1 <= i and i < R:
                continue
            else:
                ID[i] = False
    print(ID.count(True))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    ini_inp=list(map(lambda x:int(x),input().split()))
    N=ini_inp[0]
    M=ini_inp[1]

    L=[]
    R=[]
    for i in range(M):
        sec_inp=list(map(lambda x:int(x),input().split()))
        L.append(sec_inp[0])
        R.append(sec_inp[1])

    temp=[]
    for i in range(M):
        if i==0:
           temp=set([i for i in range(L[i],R[i]+1)])
        number=set([i for i in range(L[i],R[i]+1)])
        temp=number & temp
        if len(temp)==0:
            break
    print(len(temp))

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    ini_inp=list(map(lambda x:int(x),input().split()))
    N=ini_inp[0]
    M=ini_inp[1]

    L=[]
    R=[]
    for i in range(M):
        sec_inp=list(map(lambda x:int(x),input().split()))
        L.append(sec_inp[0])
        R.append(sec_inp[1])

    temp=set([i for i in range(1,N+1)])
    for i in range(M):
        number=set([i for i in range(L[i],R[i]+1)])
        temp=number & temp
        if len(temp)==0:
            break
    print(len(temp))

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    ini_inp=list(map(lambda x:int(x),input().split()))
    N=ini_inp[0]
    M=ini_inp[1]

    L=[]
    R=[]
    for i in range(M):
        sec_inp=list(map(lambda x:int(x),input().split()))
        L.append(sec_inp[0])
        R.append(sec_inp[1])

    counter=0
    for i in range(1,N+1):
        flag=0
        for j in range(M):
            if i<L[j] or i>R[j]:
                flag=1
        if flag==0:
            counter+=1

    print(counter)

if __name__=="__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
lr = [list(map(int, input().split())) for _ in range(m)]
cnt = [0]*n
for i in range(m):
    for j in range(lr[i][0]-1, lr[i][1]):
        cnt[j] += 1
ans = sum(i==m for i in cnt)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
def hani(x,min_,max_):
    ret=x
    if x<min_:ret=min_
    if x>max_:ret=max_
    return ret
def seifu(x):
    return x//abs(x)
###################################################
def main():
    N,M=list(map(int,list(input().split())))
    sset=set()
    for a in range(M):
        l,r=map(int,input().split())
        if a==0:
            sset=set(range(l,r+1))
        else:
            sset=sset&set(range(l,r+1))
    print(len(sset))
main()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    n, m = map(int, input().split())
    lst = [list(map(int, input().split())) for _ in range(m)]

    ans = set(range(lst[0][0], lst[0][1] + 1))
    for l in lst[1:]:
        ans = ans.intersection(set(range(l[0], l[1] + 1)))

    print(len(ans))


resolve()

Submission status: Time Limit Exceeded

Solution code:

[N,M] = list(map(int,input().split()))

LR = []
for i in range(M):
    LR.append(list(map(int,input().split())))

ls = [[0]*M for i in range(N)]

for i in range(M):
    ran = range(LR[i][0]-1, LR[i][1])
    for j in ran:
        ls[j][i] = 1

count=0
for i in range(N):
    if sum(ls[i])==M:
        count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input("").split(" ")))
permit = [list(map(int, input("").split(" "))) for i in range(M)]
able = [0 for i in range(N)]
for i,j in permit:
  for k in range(i,j+1):
    able[k-1] += 1
print(able.count(M))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
card=[0]*n

for i in range(m):
    l,r=lr[i]
    for j in range(l-1,r):
        card[j]+=1
print(card.count(m))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for _ in range(m)]
card=[0]*n

for i in range(m):
    l,r=lr[i]
    for j in range(l-1,r):
        card[j]+=1
ans=0
for k in range(n):
    if card[k] == m:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LR = [None]*M

for i in range(M):
    l, r = map(int, input().split())
    if i==0:
        ans = set(range(l, r+1))
    else:
        ans = ans & set(range(l, r+1))

print(min(len(ans), N))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LR = []

for i in range(M):
    l, r = map(int, input().split())
    LR.append(set(range(l, r+1)))

ans = LR[0]

for i in range(1, M):
    ans = ans & LR[i]

print(min(len(ans), N))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())

cards=set([i+1 for i in range(n)])


for j in range(m):

    l,r = map(int,input().split())

    gates = set([j for j in range(l,r+1)])

    cards = cards&gates


print(len(cards))