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:
# AtCoder Beginner Contest 127
# C - Prison

import numpy as np

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

# cards=[0]*N+1

G=[0]*(N+1)

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

print(G.count(M))

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Beginner Contest 127
# C - Prison

import numpy as np

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

# cards=[0]*N+1

G=[0]*(N+1)
Garr=np.array(G)

for i in range (M):
    l,r=map(int,input().split())
    g=[1 if ( l<=i and i<=r ) else 0 for i in range (N+1)]
    garr=np.array(g)
    Garr+=garr

ans=np.count_nonzero(Garr==M)

print (ans)

Submission status: Time Limit Exceeded

Solution code:
# AtCoder Beginner Contest 127
# C - Prison

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

Gates=[]
for i in range (M):
    l,r=map(int,input().split())
    Gates.append([l,r])

ans =0

for i in range (1,N+1):
    for j in range (M):
        # print(i,Gates[j])
        # print(Gates[j][0]<=i and i<=Gates[j][1]) 
        if Gates[j][0]<=i and i<=Gates[j][1]:
            pass
        else:
            break
    else:
        ans+=1
    # print(ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

n,m = map(int, input().split())
l = [list(map(int,input().split())) for i in range(m)]

# n,mが10^5なのでO(n)は間に合わない
ans = 0
for i in range(1,n+1):
    flg = True
    for j in range(m):
        if i < l[j][0] or i > l[j][1]:
            flg = False
    if (flg):
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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

count = set(range(L_list[0],R_list[0]+1))
for i in range(1,M):
    count = count & set(range(L_list[i],R_list[i]+1))

ans = len(count)
print(ans)

Submission status: Time Limit Exceeded

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

count = [0]*(N+1)
for i in range(M):
    for j in range(L_list[i],R_list[i]+1):
        count[j] += 1

ans = count.count(M)
print(ans)

Submission status: Time Limit Exceeded

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

L, R = map(int, input().split())
ans = set(range(L, R + 1))

for i in range(1, M):
    L, R = map(int, input().split())
    ans &= set(range(L, R + 1))

print(len(ans))

Submission status: Time Limit Exceeded

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

count = 0
for i in range(n):
    if max(lst_l) <= i+1 <= min(lst_r):
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

dynamic_lst = list(range(l1,r1+1))
for _ in range(m-1):
    l,r = map(int,input().split())
    temp_lst = list(range(l,r+1))
    lst_wa = dynamic_lst + temp_lst
    new_lst = [i for i in set(lst_wa) if lst_wa.count(i) > 1]
    dynamic_lst = new_lst

print(len(dynamic_lst))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,M= map(int, input().split())
li=[]
for i in range(N):
    li.append(0)
for i in range(M):
    L,R= map(int, input().split())
    for t in range(L-1,R):
        li[t] +=1
print(li.count(M))

Submission status: Time Limit Exceeded

Solution code:
N,M= map(int, input().split())
li=[]
for i in range(N):
    li.append(0)
L,R= map(int, input().split())
for i in range(L-1,R):
    li[i] = 1
for i in range(M-1):
    L,R= map(int, input().split())
    for t in range(0,L-1):
        li[t] = 0
    for t in range(R,len(li)):
        li[t] = 0
print(li.count(1))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

li = [0]*n

for i in lr:
    for j in range(i[0]-1,i[1]):
        li[j] += 1
    

print(li.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)]
cnt=0
for i in range(1,N+1):
    for l,r in LR:
        if i<l or r<i:
            break
    else:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

ans = set(range(l, r + 1))
for _ in range(m - 1):
    l, r = map(int, input().split())
    ans &= set(range(l, r + 1))

print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
N_List = list(range(1,N+1))
for i in range(M):
    st,sp = map(int,input().split())
    N_List = set(list(range(st,sp + 1))) & set(N_List)
print(len(N_List))

Submission status: Time Limit Exceeded

Solution code:
import collections
n,m = map(int,input().split())
card = [list(map(int,input().split())) for c in range(m)]
nums = []
for index,c in enumerate(card):
  nums += [i for i in range(c[0],c[1]+1)]
ans = 0
for k,v in collections.Counter(nums).items():
  if v == m:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

l, r = lr[0]
ans = set()
for k in range(l, r+1):
        ans.add(k)

for i, j in lr[1:]:
    ID = set()
    for k in range(i, j+1):
        ID.add(k)
    ans = ans & ID
print(len(ans))

Submission status: Time Limit Exceeded

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

print(len(line))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
cards=[i for i in range(n)]
for j in range(m):
    l,r=map(int,input().split())
    for i in range(l-1):
        cards[i]=-1
    for i  in range(r,n):
        cards[i]=-1

ans=sum(1 for cars in cards if cars>=0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(m)]
l = []
r = []
for i in range(m):
  l.append(lr[i][0])
  r.append(lr[i][1])
ans = 0
for i in range(1, n+1):
  if max(l) <= i <= min(r):
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(m)]
ans = 0
for i in range(1, n+1):
  b = True
  for j in range(m):
    if i < lr[j][0] or lr[j][1] < i:
      b = False
  if b:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(M):
  L,R = map(int,input().split())
  ID_new = [j for j in range(L,R+1)]
  ID = set(ID) & set(ID_new)

print(len(ID))

Submission status: Time Limit Exceeded

Solution code:
#<127>

N, M = map(int, input().split())
gate = [0] * N
#rang = []
for m in range(M):
    L, R = map(int, input().split())
    for x in range(L, R + 1):
        gate[x - 1] += 1
        #print(gate)

print(gate.count(M))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
s={k for k in range(1,100001)}
for i in range(m):
  l,r=map(int,input().split())
  b={j for j in range(l,r+1)}
  s=s&b
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
s={k for k in range(1,100001)}
for i in range(m):
  l,r=map(int,input().split())
  b=set()
  for j in range(l,r+1):
    b.add(j)
  s=s&b
print(len(s))

Submission status: Time Limit Exceeded

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


s = []
count = 0
for _ in range(M):
  a,b = map(int,input().split())
  if M==1:
    print(b-a+1)
    exit()
  for i in range(a,b+1):
    s.append(i)
    k = collections.Counter(s)
    
for d in k.values():
    if d==M:
      count+=1
      
print(count)

Submission status: Time Limit Exceeded

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

for _ in range(M):
  l, r = map(int, input().split())
  for i in range(l, r+1):
    id[i-1] += 1

print(id.count(M))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

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

passed = [1 for _ in range(n)]

for card in range(1,n+1):
    for gate in gates:
        if not gate[0] <= card <= gate[1]:
            passed[card-1] = 0
            break

print(sum(passed))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

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

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

passed = [1 for _ in range(n)]

for card in range(1,n+1):
    for gate in gates:
        if not gate[0] <= card <= gate[1]:
            passed[card-1] = 0

print(sum(passed))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#36
N,M = map(int,input().split())
li = []
ri = []
x = []
y = [i for i in range(1,N+1)]
cou = 0
for i in range(M):
    L,R = map(int,input().split())
    for i in y:
        if L<=i and R>=i:
            x.append(i)
    y = x
    x = []
          
cou = len(y)
print(cou)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
n,m=map(int,input().split())
c=Counter()
for i in range(m):
    l,r=list(map(int,input().split()))
    idcard=list(range(l,r+1))
    c+=Counter(idcard)
cnt=0
for i in range(1,n+1):
    if c[i]==m:
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

ids = list(range(1, N+1))

for _ in range(M):
    (L, R) = map(int, input().split(" "))
    ids = [i for i in ids if L <= i <= R]
print(len(ids))

Submission status: Time Limit Exceeded

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

ids = list(range(1, N+1))

for _ in range(M):
    (L, R) = map(int, input().split(" "))
    ids = list(filter(lambda x: (L <= x) and (x <= R), ids))

print(len(ids))

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8

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

ids = list(range(1, N+1))

for _ in range(M):
    (L, R) = map(int, input().split(" "))
    ids = list(filter(lambda x: (L <= x) and (x <= R), ids))

print(len(list(ids)))

Submission status: Time Limit Exceeded

Solution code:
import collections as co
N,M =list(map(int,input().split()))
card=[]
ans=0
for i in range(M):
  st,en=list(map(int,input().split()))
  for cn in range(st,en+1):
    card.append(cn)
vv=co.Counter(card)
for k in range(N+1):
  if M==vv[k]:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
data=input().split()
N=int(data[0])
M=int(data[1])
data_gate=[input().split() for i in range(M)]
ans=0
for i in range(1,N+1):
    for j in range(M):
        minimum=int(data_gate[j][0])
        maximum=int(data_gate[j][1])
        if j<=M-2:
            if minimum<=i<=maximum:
                continue
            else:
                break
        else:
            if minimum<=i<=maximum:
                ans+=1
            else:
                break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = list(map(int,input().split()))
for i in range(m):
    l,r=list(map(int,input().split()))
    if i == 0:
        ans = set(range(l,r+1))
    else:
        ans = ans & set(range(l,r+1))
print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#ABC 127 C - Prison
from collections import Counter

n, m = map(int, input().split())
gates = []
for i in range(m):
    l, r = map(int, input().split())
    temp_l = range(l-1,r)
    gates.extend(temp_l)

c = Counter(gates)
res = 0
for v in c.values():
    if v == m: res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:
#ABC 127 C - Prison
from collections import Counter

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

c = Counter(gates)
res = 0
for v in c.values():
    if v == m: res += 1
print(res)

Submission status: Time Limit Exceeded

Solution code:

def solve():
#    dp = [1]*(N)
    dp = [0] * N
    for i in range(M):
#        for j in range(0, LR[i][0]-1):
#            dp[j] = 0
#        for j in range(LR[i][1], N):
#            dp[j] = 0
        for j in range(LR[i][0]-1,LR[i][1]):
            dp[j] += 1
#    print(dp)
    print(dp.count(M))
#    print(sum(dp))


if __name__ == "__main__":
    N,M = list(map(int, input().split()))
    LR = [list(map(int, input().split())) for _ in range(M)]
    solve()

Submission status: Time Limit Exceeded

Solution code:

def solve():
#    num = list(range(N+1))
#    l = [0]*M
    dp = [1]*(N)
    for i in range(M):
#        dp = [dp[j] for j in range(0,LR[i][0])]
#        dp = [dp[j] for j in range(LR[i][1], M)]
        for j in range(0, LR[i][0]-1):
            dp[j] = 0
        for j in range(LR[i][1], N):
            dp[j] = 0
#    print(dp)
    print(sum(dp))


if __name__ == "__main__":
    N,M = list(map(int, input().split()))
    LR = [list(map(int, input().split())) for _ in range(M)]
    solve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = (int(x) for x in input().split())
Now = np.zeros((N),dtype=int)
for T in range(0,M):
    L,R = (int(x) for x in input().split())
    Now[L-1:R] += 1
print(sum(Now==M))

Submission status: Time Limit Exceeded

Solution code:
N,M = (int(x) for x in input().split())
Now = range(1,N+1)
for T in range(0,M):
    L,R = (int(x) for x in input().split())
    Now = set(Now)&set(range(L,R+1))
print(len(Now))

Submission status: Time Limit Exceeded

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

for g in range(M):
  L,R = map(int,input().split())
  for i in range(L-1):
    cards[i] = False
  for i in range(R,N):
    cards[i] = False
print(cards.count(True))

Submission status: Time Limit Exceeded

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

cards = [True]*N

for g in gateInfos:
  L = g[0]
  R = g[1]
  for i in range(L-1):
    cards[i] = False
  for i in range(R,N):
    cards[i] = False
print(cards.count(True))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
gateInfos = [list(map(int,input().split()))for i in range(M)]
c = 0
for i in range(1,N+1):
  al = True
  for g in gateInfos:
    L = g[0]
    R = g[1]
    if not L <= i <= R:
      al = False
      break
 
  if al:
    c+= 1
print(c)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

ans = np.array(range(N + 1))

for i in range(M):
	l = list(map(int, input().split()))
	ans = ans[ans >= l[0]]
	ans = ans[ans <= l[1]]

print(ans.shape[0])

Submission status: Time Limit Exceeded

Solution code:

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

ans = set(range(1,n+1))

for i in range(m):
    l,r = map(int,input().split())
    x = set(range(l,r+1))
    ans = ans & x
    
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
Authority = [list(map(int, input().split())) for _ in range(m)]
cards = set(range(1, n + 1))

for i in range(m):
    gate = set(range(Authority[i][0], Authority[i][1] + 1))
    cards &= gate
print(len(cards))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
gate=[]
cnt=0
for i in range(m):
    lr=list(map(int,input().split()))
    gate.append(lr)
for j in range(1,n+1):
    if all(j in range(gate[i][0],gate[i][1]+1) for i in range(len(gate))):
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

c = [0 for _ in range(N)]
cnt = 0
for i, (l, r) in enumerate(LR):
    for j in range(l - 1, r):
        c[j] += i + 1
    cnt += i + 1

s = [1 if k == cnt else 0 for k in c]

print(sum(s))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

n, m = map(int, input().split())
A = []
for i in range(m):
    l, r = map(int, input().split())
    A.extend(list(range(l, r + 1)))
    
cnt = 0
for v in Counter(A).values():
    if v == m:
        cnt += 1
        
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(m):
  l,m = map(int, input().split())
  tmp_set = set([i for i in range(l,m+1)])
  if init_set is None:
    init_set = tmp_set
  else:
    init_set = init_set.intersection(tmp_set)
print(min(n,len(init_set)))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
LR=list(range(N+1))
for i in range(M):
    L,R=map(int,input().split())
    LR=list(set(list(range(L,R+1))) & set(LR))
print(len(LR))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(M)]

count_dict = {}

gate = set(range(10**5 + 1))

for i in range (M):
    l = LR[i][0]
    r = LR[i][1]
    temp = set(range(l, r+1))

    gate = gate & temp

print(len(gate))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LR = [tuple(map(int, input().split())) for _ in range(M)]

count_dict = {}

for i in range (M):
    l = LR[i][0]
    r = LR[i][1]

    for j in range(l, r+1):
        if j in count_dict:
            count_dict[j] += 1
        else:
            count_dict[j] = 1

total = 0
for i in count_dict.values():
    if i == M:
        total += 1

print(total)

Submission status: Time Limit Exceeded

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

cards = set([i for i in range(lrs[0][0], lrs[0][1]+1)])
for lr in lrs[1:]:
    tmp = set([i for i in range(lr[0], lr[1]+1)])
    cards.intersection_update(tmp)
    

print(len(cards))

Submission status: Time Limit Exceeded

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

for i in range(m):
    l, r = map(int,input().split())
    rg = range(l, r + 1)
    if i == 0:
        s = set(rg)
    else:
        x = s & set(rg)
        s = x

rg2  = set(range(1, n + 1))
ans = rg2 & s

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
cards = {i: False for i in range(1, n+1)}

for _ in range(m):
    l, r = map(int, input().split())
    for i in cards:
        if i < l or i > r:
            cards[i] = True

sum = 0
for v in cards.values():
    if not v:
        sum += 1

print(sum)

Submission status: Time Limit Exceeded

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

a = [i for i in range(1,N+1)]
for i in range(M):
    L, R = list(map(int,input().split()))
    aa = [i for i in range(L, R+1)]
    a = set(a) & set(aa)

print(len(a))

Submission status: Time Limit Exceeded

Solution code:
N,M = (int(x) for x in input().split())
lr = []
for i in range(1,N+1):
  lr.append(i)
l,r = (int(x) for x in input().split())
d = set(lr[l-1:r])
for i in range(1,M):
  l,r = (int(x) for x in input().split())
  d = d & set(lr[l-1:r])
print(len(d))

Submission status: Time Limit Exceeded

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

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

for id, val in dic.items():
    if val == M:
        c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
st = set(range(1, N+1))
for _ in range(M):
    a, b = map(int, input().split())
    st.intersection_update(set(range(a, b+1)))
print(len(st))

Submission status: Time Limit Exceeded

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

res = 0
for i in range(1, n+1):
    if max(L) <= i <= min(R):
        res += 1
print(res)

Submission status: Time Limit Exceeded

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

res = 0
for i in range(n):
    flag = False
    for j in range(m):
        if gates[j][0]-1 <= i < gates[j][1]:
            flag = True
        else:
            flag = False
            break
    
    if flag == True:
        res += 1

print(res)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
gates = []
for _ in range(m):
    l, r = map(int, input().split())
    #gates.append(list(range(l-1, r)))
    gates.append([l-1, r])

res = 0
for i in range(n):
    flag = False
    for j in range(m):
        if gates[j][0] <= i < gates[j][1]:
            flag = True
        else:
            flag = False
            break
    
    if flag == True:
        res += 1

print(res)

Submission status: Time Limit Exceeded

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

arr=[list(map(int,input().split())) for i in range(gate)]

ans=0

for i in range(N):
    count=0
    for j in range(gate):
        if i+1<arr[j][0] or i+1>arr[j][1]:
            break
        else:
            count+=1    
    if count==gate:
        ans+=1

print(ans)

Submission status: Time Limit Exceeded

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

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

ans = 0
for i in range(N):
    if C[i] == M:
        ans += 1

print(ans)

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 j in range(l,r+1):
    a[j-1] += 1
print(a.count(m))

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 j in range(l, r+1):
    a[j-1] += 1

print(a.count(m))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
A = [0] * (N+1)
for _ in range(M):
  l,r = map(int,input().split())
  for i in range(l, r+1):
    A[i] += 1

print(A.count(M))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(m)]
ANS = []
for i in range(m):
  ANS.append(list(range(LR[i][0],LR[i][1]+1)))
  
def f(A,B):
  if set(A)&set(B) == set():
    print(0)
    exit()
  else:
    return(list(set(A)&set(B)))
X = ANS[0]
for i in range(1,m):
  X = f(X,ANS[i])

print(len(X))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
n = set([i for i in range(1,n+1)])

for i in range(m):
    a, b = map(int, input().split())
    ab = set([j for j in range(a,b+1)])
    n = n & ab
    if len(n) == 0:
        print(0)
        exit()

print(len(n))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
n = set([i for i in range(1,n+1)])

for i in range(m):
    a, b = map(int, input().split())
    ab = set([j for j in range(a,b+1)])
    n = n & ab

print(len(n))

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, m = map(int, input().split())
    counts = [0] * n
    for _ in range(m):
        l, r = map(int, input().split())
        for i in range(l - 1, r):
            counts[i] += 1
    print(counts.count(m))


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, raw_input().split(' '))
keys = set(range(1,n+1))
for _ in range(m):
	a,b = map(int, raw_input().split(' '))
	keys = keys.intersection(set( range(a,b+1)  ))
	if len(keys) == 0: break
print len(keys)

Submission status: Time Limit Exceeded

Solution code:
import sys

input = lambda: sys.stdin.readline().rstrip()


def solve():
    N, M = map(int, input().split())
    l1, r1 = map(int, input().split())
    card = set(range(l1, r1 + 1))
    for _ in range(M - 1):
        l, r = map(int, input().split())
        card &= set(range(l, r + 1))

    print(len(card))


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)

def judge(c,l,r,counter):
  if counter == 0:
    return c
  elif len(c) == 0:
    return c
  else:
    return judge(list(filter(lambda x: l[0]<=x<=r[0],c)),l[1:],r[1:],counter-1)

def solve(c,l,r,m):
  return len(judge(c,l,r,m))
  
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())
cards = range(1,N+1)
print(solve(cards,L,R,M))

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N, M = list(map(int,input().split()))
L = [None for _ in range(M)]
card = [None for _ in range(M)]
ans = 0

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

for j in range(M):
  card[j] = [a for a in range(L[j][0], L[j][1]+1)]

a = len(card)

card2 = []

for i in range(M):
  m = len(card[i])
  for j in range(m):
    card2.append(card[i][j])
    
cout = Counter(card2)
cout = list(cout.values())

for i in range(len(cout)):
  if cout[i] == a:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter

N, M = list(map(int,input().split()))
L = [None for _ in range(M)]
card = [None for _ in range(M)]
ans = 0

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

for j in range(M):
  card[j] = [a for a in range(L[j][0], L[j][1]+1)]

a = len(card)

card2 = []

for i in range(M):
  m = len(card[i])
  for j in range(m):
    card2.append(card[i][j])
    
MIN = min(card2)
MAX = max(card2)

cout = Counter(card2)
cout = list(cout.values())

for i in range(len(cout)):
  if cout[i] == a:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = []
for i in range(M):
    L, R = map(int, input().split())
    if i == 0:
        S = set(list(range(L, R + 1)))
    else:
        S = S & set(list(range(L, R + 1)))
        if len(S) == 0:
            break

# L = set(A[0])
# for i in range(1, M):
#     L = L & set(A[i])

print(len(S))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
A = []
for i in range(M):
    L, R = map(int, input().split())
    if i == 0:
        S = set(list(range(L, R + 1)))
    else:
        S = S & set(list(range(L, R + 1)))

# L = set(A[0])
# for i in range(1, M):
#     L = L & set(A[i])

print(len(S))

Submission status: Time Limit Exceeded

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

L = set(A[0])
for i in range(1, M):
    L = L & set(A[i])

print(len(L))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N, M = list(map(int, input().split()))
    interval = []
    for i in range(M):
        L, R = list(map(int, input().split()))
        interval.append(list(range(L, R + 1)))
    # print(interval)
    interval = [set(l) for l in interval]
    interval = set.intersection(*interval)

    print(len(set(range(1, N + 1)) & interval))

    return


resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def solve():
    N,M = map(int, input().split())
    LR = [list(map(int, input().split())) for _ in range(M)]
    data = np.array([0 for _1 in range(N+1)])

    for i in range(M):
        data[LR[i][0]:LR[i][1]+1] += 1
    print(len(data[data==M]))



if __name__ == '__main__':
    solve()

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)))

flag = [0] * n
for i in range(n):
    count = 0
    for j in k:
        if (i + 1) in j:
            count += 1
    if count == m:
        flag[i] = 1

print(sum(flag))