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:
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())
ans = 0
for i in range(N):
    count = 0
    for j in range(M):
        if L[j] <= (i+1) and (i+1) <= R[j]:
            count += 1
    if count == M:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    N, M = [int(x) for x in input().split()]

    answer = set()
    for i in range(M):
        L, R = [int(x) for x in input().split()]
        if i == 0:
            answer = {x for x in range(L, R + 1)}
        else:
            s = {x for x in range(L, R + 1)}
            answer &= s

    print(len(answer))




if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N,M = map(int, input().split())
cards = [1] * N
for _ in range(M):
    l,r = map(int, input().split())
    for i in range(l-1):
        cards[i] = 0
    for i in range(r,N):
        cards[i] = 0
print(sum(cards))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(N+1):
    if max(L)<=i<=min(R):
        cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

s=set()
l, r = map(int, input().split())
for i in range(l, r+1):
  s.add(i)
  
for i in range(m-1):
  l, r = map(int, input().split())
  t = set()
  for j in range(l, r+1):
    t.add(j)
    
  s = s & t
  
print(len(s))

Submission status: Time Limit Exceeded

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n,m = MAP()
l,r = MAP()
res = set(range(l,r+1))
for i in range(m-1):
    l,r = MAP()
    res = res & set(range(l,r+1))

print(len(res))

Submission status: Time Limit Exceeded

Solution code:
def main(): 


    card_cnt, gate_cnt = map(int, input().split())

    LR = set(range(1, 100000+1))

    for _ in range(gate_cnt):
        L, R = map(int, input().split())
        LR.intersection_update(range(L, R+1))
        if len(LR) == 0:
            break

    print(len(LR))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(M)]
ans=set(i for i in range(N))
for L, R in lst:
  L, R=L-1, R-1
  ans-=set(i for i in range(L))
  ans-=set(i for i in range(R+1, N))
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N, M=map(int, input().split())
lst=[list(map(int, input().split())) for _ in range(M)]
ok=[1 for _ in range(N)]
for L, R in lst:
  L, R=L-1, R-1
  for i in range(L):
    ok[i]=0
  for i in range(R+1, N):
    ok[i]=0
print(sum(ok))

Submission status: Time Limit Exceeded

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

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

    lst = [x for x in range(l,r+1)]
    if i == 0:
        sekishugo=set(lst)

    else:
       sekishugo = sekishugo.intersection(set(lst))

print(len(sekishugo))

Submission status: Time Limit Exceeded

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

print(len(s))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
li=[list(map(int,input().split())) for i in range(m)]
s=0
for i in range(m):
  l=li[i][0]
  r=li[i][1]
  temp=range(l,r+1)
  if i==0:
    s=set(temp)
  else:
    s&=set(temp)

print(len(s))

Submission status: Time Limit Exceeded

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

print(len(s))

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)
ans = 0
'''
for i in range(n):
    cnt = 0
    for j in range(m):

        for k in range(l[j], r[j]+1):
            if i + 1 == k:
                cnt += 1
        if cnt == m:
            ans += 1
print(ans)
'''
for i in range(n):
    cnt = 0
    #print('cnt rrr')
    #print('i=' + str(i))
    for j in range(m):
        #print(l[j], end=' ')
        #print(r[j])
        if i + 1 >= l[j] and r[j] >= i + 1:
            cnt += 1
            #print('cnt='+ str(cnt))
        else:
            #print('break')
            break
    if cnt == m:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

        for k in range(l[j], r[j]+1):
            if i + 1 == k:
                cnt += 1
        if cnt == m:
            ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = list(map(int, input().split()))
l = []
r = []
for i in range(m):
    x, y=[int(i) for i in input().split()]
    l.append(x)
    r.append(y)
ans = 0
for i in range(n):
    cnt = 0
    #print('i=' + str(i))
    for j in range(m):
        #print(l[j], end=' ')
        #print(r[j])
        if i + 1 < l[j] or r[j] < i + 1:
            pass
        else:
            cnt += 1
            #print('cnt='+ str(cnt))
    if cnt == m:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

l,r = map(int,input().split())
Kouho = [int(i) for i in range(l,r+1)]
for i in range(M-1):
    l,r = map(int,input().split())
    tmp = [int(i) for i in range(l,r+1)]
    for j in Kouho[:]:
        if not j in tmp:
            Kouho.remove(j)

   
print(len(Kouho))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
List = []
for i in range(M):
    l,r = map(int,input().split())
    tmp = [int(i) for i in range(l,r+1)]
    List.append(tmp)
Kouho = List[0]

for i in range(1,M):
    for j in Kouho[:]:
        if not j in List[i]:
            Kouho.remove(j)
print(len(Kouho))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys

def main():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    gate_list = []
    for i in range(M):
        L, R = map(int, input().split())
        gate_list.append([L, R])
    counter = 0
    for n in range(1, N+1):
        for gate in gate_list:
            if n < gate[0] or n > gate[1]:
                break
        else:
            counter += 1
    print(counter)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(M):
    l,r=map(int,input().split())
    if l!=1:
        cards[:l-1]=[0]*(l-1)
    if r!=N:
        cards[r:]=[0]*(N-r)
    
print(sum(cards))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans = 0
for card in cards:
    if card == m:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = [int(i) for i in input().split()]

num_set = {i for i in range(n+1)}
for i in range(m):
    s,e = [int(i) for i in input().split()]
    card_set = {i for i in range(s,e+1)}
    num_set = num_set & card_set
    
print(len(num_set))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l1, r1 = map(int, input().split())
li = set(list(range(l1, r1+1)))

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

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l1, r1 = map(int, input().split())
li = list(range(l1, r1+1))

for i in range(m-1):
    l,r = map(int, input().split())
    li = [i for i in li if l <= i <= r]
print(len(li))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(len(card))

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
ans = 0
card = [1] * N
for _ in range(M):
	L, R = map(int, input().split())
	for i in range(N):
		if i < L-1 or R-1 < i:
			card[i] = 0

print(card.count(1))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]
ans = [0 for _ in range(N)]
for i in range(M):
    start = LR[i][0]
    end = LR[i][1]
    for j in range(start-1, end):
        ans[j] += 1
cnt = 0
for k in ans:
    if k == M:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

first,last = map(int,input().split(" "))
set_cnt = set()
for i in range(first,last+1):
  set_cnt.add(i)


for m in range(M-1):
  _first, _last = map(int,input().split(" "))
  _set_cnt = set()
  for _ in range(_first,_last+1):
    _set_cnt.add(_)
  
  set_cnt = set_cnt & _set_cnt

print(len(set_cnt))

Submission status: Time Limit Exceeded

Solution code:
def main():
    N, M = map(int, input().split())
    #L = [0] * M
    #R = [0] * M
    
    for i in range(M):
        L, R = map(int, input().split())
        A = [j for j in range(L,R+1)]
        if i == 0:
            tmp = set(A)
            continue
        set_A = set(A)
        tmp = set(list(set_A.intersection(tmp)))
    
    print(len(tmp))



main()

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
L = [0] * M
R = [0] * M
L, R = map(int, input().split())
ans = set(list(range(L, R+1)))
for i in range(M-1):
  L, R = map(int, input().split())
  ans = ans & set(list(range(L, R+1)))
print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
lists = []
for i in range(M):
    L,R = map(int,input().split())
    lists.append(list(range(L,R+1)))
if len(lists) == 1:
    print(len(lists[0]))
    exit()
for i in range(M-1):
    lists[i+1] = set(lists[i]) & set(lists[i+1])
    ans = lists[-1]
print(len(ans))

Submission status: Time Limit Exceeded

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

for i in range(m):
    l,r = map(int,input().split(" "))
    tmp = set()
    for j in range(l,r+1):
        tmp.add(j)

    card = card.intersection(tmp)
print(len(card))

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
ID = [i for i in range(1, N+1)]
for i in range(M):
    L, R = list(map(int, input().split()))
    r = [i for i in range(L, R+1)]
    ID = set(ID) & set(r)
    if len(ID) == 0:
        print(0)
        exit()
if len(ID) > N:
    print(N)
else:
    print(len(ID))

Submission status: Time Limit Exceeded

Solution code:
N, M = list(map(int, input().split()))
ID = list(range(1, N+1))
for i in range(M):
    L, R = list(map(int, input().split()))
    r = list(range(L, R+1))
    ID = set(ID) & set(r)
    if len(ID) == 0:
        print(0)
        exit()
if len(ID) > N:
    print(N)
else:
    print(len(ID))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

lr = []
for _ in range(m):
    l, r = map(int, input().split())
    lr.append([l, r])

cnt = 0
for i in range(1, n+1):
    for l, r in lr:
        if not l <= i <= r:
            break
    else:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

lr = [list(map(int,input().split())) for _ in range(m)] 
card = []
ans = 0

for i in range(m):
    start = lr[i][0]
    end = lr[i][1]
    for j in range(start,end+1): 
        card.append(j)

count_gate = collections.Counter(card)

for j in count_gate.values():
    if j == m:
        ans += 1
        
print(ans)

Submission status: Time Limit Exceeded

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

I=set(i for i in range(1,n+1))

for i in range(m):
  I &= set(i for i in range(D[i][0],D[i][1]+1))
print(len(I))

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-1, r):
    c[j] += 1
print(c.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)]
common = set(range(LR[0][0], LR[0][1]+1))
for lr in LR:
    common = common & set(range(lr[0], lr[1]+1))
print(len(common))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
keys = []
for i in range(m):
  l,r = map(int, input().split())
  keys.append([l,r])
cnt = 0
for key in range(1, n+1):
  for x, y in keys:
    if key < x or key > y:
      cnt -= 1
      break
  cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
keys = []
for i in range(m):
  l,r = map(int, input().split())
  keys.append(set(range(l,r+1)))
print(len(set.intersection(*keys)))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
ans = {}
for _ in range(m):
    l,r = map(int,input().split())
    gate = []
    if ans:
        for i in range(max(l,min(ans)),min(r+1,max(ans))+1):
            gate.append(i)
        ans &= set(gate)
    else:
        for i in range(l,r+1):
            gate.append(i)
        ans = set(gate)
print(len(ans))

Submission status: Time Limit Exceeded

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

left, right = map(int, input().split())
ans = set(range(left, right+1))
               
for i in range(m-1):
  left, right = map(int, input().split())
  set_temp = set(range(left, right+1))
  ans = ans & set_temp
print(len(ans))

Submission status: Time Limit Exceeded

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

passcard = [i+l[0][0] for i in range(l[0][1] - l[0][0]+1)]
for t in range(n[1]-1):
    passcard = [i for i in passcard if l[t+1][0] <= i <= l[t+1][1]]
    
print(len(passcard))

Submission status: Time Limit Exceeded

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

passcard = []
for c in range(l[0][1] - l[0][0]+1):
    passcard.append(l[0][0]+c)

for tt in range(n[1]):
    t = n[1] - tt -1
    for i in range(len(passcard)):
        if not(l[t][0] <= passcard[i] <= l[t][1]):
            passcard[i] = 0
        else:
            passcard[i] = passcard[i]

    passcard = [i for i in passcard if i!=0]
            
print(len(passcard))

Submission status: Time Limit Exceeded

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

passcard = []
for c in range(l[0][1] - l[0][0]+1):
    passcard.append(l[0][0]+c)

for tt in range(n[1]):
    t = n[1] - tt -1
    for i in range(len(passcard)):
        if not(l[t][0] <= passcard[i] <= l[t][1]):
            passcard[i] = 0
        else:
            passcard[i] = passcard[i]

    passcard = [i for i in passcard if i!=0]
            
out = [i for i in passcard if i!=0]
print(len(out))

Submission status: Time Limit Exceeded

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

passcard = []
for c in range(l[0][1] - l[0][0]+1):
    passcard.append(l[0][0]+c)

for t in range(n[1]):
    for i in range(len(passcard)):
        if not(l[t][0] <= passcard[i] <= l[t][1]):
            passcard[i] = 0
        else:
            passcard[i] = passcard[i]
    passcard = [i for i in passcard if i!=0]
            
out = [i for i in passcard if i!=0]
print(len(out))

Submission status: Time Limit Exceeded

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

passcard = []
for c in range(l[0][1] - l[0][0]+1):
    passcard.append(l[0][0]+c)

#print(passcard)

for t in range(n[1]):
    for i in range(len(passcard)):
        if not(l[t][0] <= passcard[i] <= l[t][1]):
            passcard[i] = 0
            #print(passcard)
        else:
            passcard[i] = passcard[i]
            
out = [i for i in passcard if i!=0]
#print(out)
print(len(out))

Submission status: Time Limit Exceeded

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

cnt = lst.count(m)
print(cnt)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

ans = S[0]
for i in range(1, m):
    ans = ans & S[i]

print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
input1 = input()

door_num = int(input1.split()[1])
max_left = 1
min_right = int(input1.split()[0])

for i in range(door_num):
    a = input()
    new_inputs = [int(i) for i in a.split()]
    max_left = np.max([new_inputs[0], max_left])
    min_right = np.min([new_inputs[1], min_right])
    if not min_right >= max_left:
        break

if min_right >= max_left:
    print(min_right - max_left + 1)
else:
    print(0)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
input1 = input()

door_num = int(input1.split()[1])
max_left = 1
min_right = int(input1.split()[0])

for i in range(door_num):
    a = input()
    new_inputs = [int(i) for i in a.split()]
    max_left = np.max([new_inputs[0], max_left])
    min_right = np.min([new_inputs[1], min_right])

if min_right >= max_left:
    print(min_right - max_left + 1)
else:
    print(0)

Submission status: Time Limit Exceeded

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

print(len(N))

Submission status: Time Limit Exceeded

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

ans = 0
for tmp_id in ids:
  if tmp_id == m:
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
for i in card:
    if len(i) == m:
        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)]

ID = [1]*N #IDカードの配列を用意する
for i in range(M):
    for j in range(N):
        if LR[i][0]-1<=j and j<=LR[i][1]-1: #通過できる場合は1をかける
            ID[j] = ID[j]*1
        else: #通過できない場合は0をかける
            ID[j] = ID[j]*0
print(sum(ID)) #全てのゲートをチェックした後、1のままのカードは全てのゲートを通過可能

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, m = [int(x) for x in input().split(' ')]
l, r = [int(x) for x in input().split(' ')]
res = set(range(l, r+1))

for i in range(int(m-1)):
    l, r = [int(x) for x in input().split(' ')]
    res &= set(range(l, r+1))

print(len(res))

Submission status: Time Limit Exceeded

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

A = set(x for x in range(1,N+1))
for i in range(M):
  L, R = map(int, input().split())
  A &= {x for x in range(L,R+1)}

print (len(A))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
a = {i for i in range(1,n+1)}
for _ in range(m):
  l,r = map(int,input().split())
  temp = list(range(l,r+1))
  a = a.intersection(temp)
print(len(a))

Submission status: Time Limit Exceeded

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

counter = 0
 
for i in unq:
  if list.count(i) == M:
    counter +=1
    
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline

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

g = set(i for i in range(1,N+1))
for i in range(M):
    l,r = map(int, input().split())
    t = set(i for i in range(l,r+1))
    g = g & t

print(len(g))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
L = []
R = []
for i in range(m):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
ans = 0
for i in range(n+1):
    count = 0
    for j in range(m):
        if i>=L[j] and i <=R[j]:
            count+=1
        if count==m:
            ans +=1
print(ans)

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())
count = 0
for i in range(N):
	count += 1
	for j in range(M):
		if i+1 < L[j] or i+1 > R[j]:
			count -= 1
			break
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
L, R = map(int, input().split())
l1 = list(range(L, R+1))

if M > 1:
    for i in range(1, M):
        L, R = map(int, input().split())
        l2 = list(range(L, R+1))
        l1 = list(set(l1)&set(l2))
print(len(l1))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
list_open = []
for i in range(m):
  list_open.append(list((int(i) for i in input().split())))
dict_open = {}
for i in range(m):
  for j in range(list_open[i][0], list_open[i][1] + 1):
    try:
      dict_open[j] += 1
      if dict_open[j] < i:
        del dict_open[j]
    except:
      if i == 0:
      	dict_open[j] = 1
print(list(dict_open.values()).count(m))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
list_open = []
for i in range(m):
  list_open.append(list((int(i) for i in input().split())))
dict_open = {}
for i in range(m):
  for j in range(list_open[i][0], list_open[i][1] + 1):
    try:
      dict_open[j] += 1
    except:
      dict_open[j] = 1
print(list(dict_open.values()).count(m))

Submission status: Time Limit Exceeded

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

for _ in range(m):
    a, b = map(int, input().split())
    sub_set = {x for x in range(a, b+1)}
    ans_set = ans_set & sub_set
    
ans = len(ans_set)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
c,g=map(int,input().split())

import numpy as np

cd=np.array([1]*c)

for i in range(g):
	cd2=np.array([0]*c)
	st,ed=map(int,input().split())
	cd2[st-1:ed]=[1]*(ed-st+1) 
	cd=cd*cd2
    
print(sum(cd))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
s=[0]*n
for _ in range(m):
    b,c=map(int,input().split())
    for i in range(b-1,c):
        s[i]+=1
print(s.count(m))

Submission status: Time Limit Exceeded

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

for i in range(m):
    l.append(x[i][0])
    r.append(x[i][1])


for i in range(1,n+1):
    if max(l) <= i <= min(r):
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
# ABC 127 c
n, m = [int(el) for el in input().split(' ')]
for i in range(m):
    l, r = [int(el) for el in input().split(' ')]
    if i == 0:
        cards = set(range(l, r + 1))
    else:
        newcards = set(range(l, r + 1))
        cards = cards.intersection(newcards)
print(len(cards))

Submission status: Time Limit Exceeded

Solution code:
import collections

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

l = []
l2 = []
count = 0

for i in range(m):
    array = list(map(int, input().split()))
    l.append(array)

for i in range(m):
    for j in range(l[i][0], l[i][1]+1):
        l2.append(j)

c = collections.Counter(l2)
d = sorted(list(c.values()),reverse=True)

for i in d:
    if i == m:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

l=[]
for _ in range(m):
  a,b=map(int,input().split())
  l1=list(range(a,b+1))
  l.append(l1)
  
con=0
for x in range(1,n+1):
  ans=[x in i for i in l]
  con+=all(ans)
  
print(con)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
an=[1]*n
for i in range(m):
    l,r=map(int,input().split())
    for j in range(1,n+1):
        if l <= j <= r:
            pass
        else:
            an[j-1]=0

print(sum(an))

Submission status: Time Limit Exceeded

Solution code:
import collections
n,m = map(int,input().split())
r = []
ans = 0
for i in range(m):
    ll,rr = map(int,input().split())
    for j in range(ll-1,rr):
        r.append(j)
cnt = collections.Counter(r)
for i in cnt.values():
    if i == m:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
r = []
ans = [True] * n
for i in range(m):
    ll,rr = map(int,input().split())
    a = set()
    for j in range(ll-1,rr):
        a.add(j)
    r.append(a)
for i in range(n):
    for j in range(m):
        if not i in r[j]:
            ans[i] = False
print(ans.count(True))

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())
    B = list(range(L,R+1))
    A.append(B)
S = set(A[0])
for i in range(M):
    S = set(S) & set(A[i])
print(len(S))

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(m)]
print(sum([all([l <= i+1 <= r for l, r in L]) for i in range(n)]))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
L=[list(map(int,input().split()))for _ in range(m)]
N=[1]*n
for l,r in L:N[:l-1]=[0]*(l-1);N[r:]=[0]*(n-r)
print(sum(N))

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N,M = map(int,input().split())
#    LL,RR = [],[]
#    for i in range(M):
#        L,R = map(int,input().split())
#        LL.append(L)
#        RR.append(R)

    ans = 0
#    print()
#    print(N,M)
#    print(LL,RR)
    bool_id = [1]*N
#    print(bool_id)
    for i in range(M): #Gate num
#        print(LL[i],RR[i])
#        l,r = LL[i]-1,RR[i]
        l,r = map(int,input().split())
        #bool_id[l:r] = [True]*(r-l)
        bool_id[:l-1] = [0]*(l-1)
        bool_id[r:] = [0]*(N-r)
#        print(bool_id)
    print(sum(bool_id))

resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    N,M = map(int,input().split())
    LL,RR = [],[]
    for i in range(M):
        L,R = map(int,input().split())
        LL.append(L)
        RR.append(R)

    ans = 0
#    print()
#    print(N,M)
#    print(LL,RR)
    bool_id = [1]*N
#    print(bool_id)
    for i in range(M): #Gate num
#        print(LL[i],RR[i])
        l,r = LL[i]-1,RR[i]
        #bool_id[l:r] = [True]*(r-l)
        bool_id[:l] = [0]*(l)
        bool_id[r:] = [0]*(N-r)
#        print(bool_id)
    print(sum(bool_id))

resolve()

Submission status: Time Limit Exceeded

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

for _ in range(m):
  l, r = map(int,input().split())
  for i in range(l-1, r):
    ans[i] += 1
print(ans.count(m))