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:
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    intersects = set()
    for i in range(m):
        o = list(map(int, input().split(" ")))
        l = []
        for k in range(o[0], o[1]+1):
            l.append(k)
        if i == 0:
            intersects = set(l)
        else:
            intersects = intersects & set(l)

    print(len(intersects))


if '__main__' == __name__:
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, m = map(int, input().split())
c = np.array([True for _ in range(n)])
for _ in range(m):
    l, r = map(int, input().split())
    l = np.array([i for i in range(l-1)])
    r = np.array([i for i in range(r, n)])
    if len(l) != 0:
        c[l] = False
    if len(r) != 0:
        c[r] = False
print(sum(c))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(200000)
n, m = list(map(int, input().split()))
def cutterl(l, lst) :
    if lst == [] :
        return []
    elif lst[0] < l :
        return cutterl(l, lst[1:])
    else :
        return lst
def cutterr(r, lst) :
    if lst == [] :
        return []
    elif r < lst[-1] :
        return cutterr(r, lst[:-1])
    else :
        return lst
nlist = list(map(lambda x : x + 1, range(n)))
llist=[]
rlist=[]
for i in range(m) :
    l, r = list(map(int, input().split()))
    llist.append(l)
    rlist.append(r)
nlist = cutterl(max(llist), nlist)
nlist = cutterr(min(rlist), nlist)
print(len(nlist))

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    sinputl = sys.stdin.readline

    num_card, num_gate = [int(x) for x in sinputl().split()]
    input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]

    min_interval = [1, num_card]

    for gate in input:
        if (min_interval[1] - min_interval[0]) > (gate[1] - gate[0]):
            min_interval = gate

    cards = list(range(min_interval[0], min_interval[1] + 1))

    for gate in input:
        cards = list(filter(lambda x: gate[0] <= x <= gate[1], cards))

    print(len(cards))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

def main():
    sinputl = sys.stdin.readline

    num_card, num_gate = [int(x) for x in sinputl().split()]
    input = [[int(x) for x in sinputl().split()] for _ in range(num_gate)]

    cards = list(range(1, num_card + 1))

    for gate in input:
        cards = list(filter(lambda x: gate[0] <= x <= gate[1], cards))

    print(len(cards))



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
L = []
R = []
for idx in range(M):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

lst = []
result = 0
for idx in range(M):
    lst.append(range(L[idx],R[idx]+1))
for id in range(1,max(R)+1):
    flag = True
    for i in range(M):
        if (id in lst[i]) == False:
            flag = False
            break
    if flag == True:
        result += 1
print(result)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int, input().split())
L = []
R = []
for idx in range(M):
    l,r = map(int, input().split())
    L.append(l)
    R.append(r)

lst = []
result = 0
for idx in range(M):
    lst.append(range(L[idx],R[idx]+1))
for id in range(1,N+1):
    flag = True
    for i in range(M):
        if (id in lst[i]) == False:
            flag = False
            break
    if flag == True:
        result += 1
print(result)

Submission status: Time Limit Exceeded

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

l_list = []
r_list = []

for i in range(M):
    l,r = map(int, input().split())
    l_list.append(l)
    r_list.append(r)

min = min(l_list)
max = max(r_list)
ans = 0

for i in range(min, max+1):

    flag = True

    for index in range(M):

        if (i >= l_list[index]) and (i <= r_list[index]):
            pass
        else:
            flag = False

    if flag == True:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

cards = [x for x in range(N)]

tmp = cards
for i in range(M):
    L,R = map(int,input().split())
    tmp = list(filter(lambda x: L - 1 <= x <= R - 1,tmp))

print(len(tmp))

Submission status: Time Limit Exceeded

Solution code:
#n: id card
#m: gate
n, m = map(int, input().split())
data = [0 for i in range(n+1)]
ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#n: id card
#m: gate
n, m = map(int, input().split())
data = [0 for i in range(n+1)]
ans = 0

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

for i in range(1, n+1):
    if data[i] == m:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
 
listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
    
count = 0
for i in range(1,N+1):
  for j in range(M):
    if  i < listA[j][0] or listA[j][1] < i:
      break;
    if j == M-1:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
        #または、quit(),os.exit()をして止める。

#print(listA)
#[[1, 2, 2, 3, 1], [4, 5, 3, 4, 1, 2, 3, 4], [2, 3, 5, 6, 0, 2]]
    
count = 0
for i in range(1,N+1):
  count1 = 0
  for j in range(M):
    if  i < listA[j][0] or listA[j][1] < i:
      break;
    if j == M-1:
      count += 1
print(count)

Submission status: Time Limit Exceeded

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

listA=[] #appendのために宣言が必要
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
        #または、quit(),os.exit()をして止める。

#print(listA)
#[[1, 2, 2, 3, 1], [4, 5, 3, 4, 1, 2, 3, 4], [2, 3, 5, 6, 0, 2]]
    
count = 0
for i in range(1,N+1):
  count1 = 0
  for j in range(M):
    if listA[j][0] <= i <= listA[j][1]:
      count1 += 1
  if count1 == M:
  	count += 1
  count1 = 0
print(count)

Submission status: Time Limit Exceeded

Solution code:
#ABC 127 C Prison
N,M= map(int,input().split())
ans=None
for i in range(M):
    L,R= map(int,input().split())
    tmp=set([i for i in range(L,R+1)])
    if ans is None:
        ans=tmp
    else:
        ans=ans & tmp
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import functools
N,M=map(int,input().split())
ls=[]
for i in range(M):
    Li,Ri=map(int,input().split())
    set1=set([x for x in range(Li,Ri+1)])
    ls.append(set1)
set2=functools.reduce(lambda x,y: x&y,ls)
print(len(set2))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
ls=[]
for i in range(M):
    ls.append(list(map(int,input().split())))
n=0
for card in range(1,N+1):
    n+=1
    for gate in range(M):
        if  not ls[gate][0]<=card<=ls[gate][1]:
            n=n-1
            break
print(n)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
ls=[]
for i in range(M):
    ls.append(list(map(int,input().split())))
n=0
for card in range(1,N+1):
    n+=1
    for gate in range(M):
        if ls[gate][0]<=card<=ls[gate][1]:
            continue
        else:
            n=n-1
            break
print(n)

Submission status: Time Limit Exceeded

Solution code:
#inputどうすんの
N,M = map(int,input().split())

sum_list=[]

for i in range(M):
    l,r = map(int,input().split())
    sum_list.extend(list(range(l,r+1)))

l_d = [x for x in set(sum_list) if not sum_list.count(x) != M]
print(len(l_d))

Submission status: Time Limit Exceeded

Solution code:
#inputどうすんの
N,M = map(int,input().split())

sum_list=[]

for i in range(M):
    l,r = map(int,input().split())
    sum_list.extend(list(range(l,r+1)))

s = sum_list
l_d = [x for x in set(s) if s.count(x) == M]
print(len(l_d))

Submission status: Time Limit Exceeded

Solution code:
#inputどうすんの
N,M = map(int,input().split())

sum_list=[]

for i in range(M):
    l,r = map(int,input().split())
    sum_list.extend(list(range(l,r+1)))
    # print(sum_list)

l_d = [x for x in set(sum_list) if sum_list.count(x) == M]
print(len(l_d))

Submission status: Time Limit Exceeded

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

agg = None
for m in range(M):
    L,R=map(int,input().split())
    if agg is None:
        agg = set([r for r in range(L,R+1)])
    agg &= set([r for r in range(L,R+1)])


print(len(agg))

Submission status: Time Limit Exceeded

Solution code:
n,m= list(map(int,input().split()))
l = [0]*m
r =[0]*m
count = 0
for i in range(m):
    l[i], r[i] = list(map(int, input().split()))
for j in range(n):
    flag = False
    #print (j)
    for i in range(m):
        if j+1<l[i] or j+1>r[i]:
            flag = True
            #print(j)
            #print('break inner loop')
            break
    if flag:
            continue
    count +=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding utf-8 -*-
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(M)]

ids = [1] * N
for i in range(M):
    ids[:LR[i][0]-1] = [0] * len(ids[:LR[i][0]-1])
    ids[(LR[i][1]):] = [0] * len(ids[(LR[i][1]):])

print(sum(ids))

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
l=[]
h=[]
count=0
for i in range(m):
    a,b=map(int,input().split())
    l.append(a)
    h.append(b)

for i in range(n):
    judge=True
    for j in range(m):
        #if not (((i+1) >= l[j]) and ((i+1) <= h[j])):
        if not ((i+1) >= l[j] and (i+1) <= h[j]):
            judge^=True
            break
    if judge:
        count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
l = []
r = []
count = 0
def check(a,b,c):
    if a >= max(b) and a <= min(c):
        return 1
    else:
        return 0
for i in range(m):
    l0,r0 = map(int,input().split())
    l.append(l0)
    r.append(r0)
for y in range(n+1):
    count = count + check(y,l,r)
print(count)

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
count = 0
for i in range(M):
    a,b = map(int,input().split())
    if count == 0:
        set = {i for i in range(a,b+1)}
        count = 1
    else:
        set = set & {i for i in range(a,b+1)}
print(len(set))

Submission status: Time Limit Exceeded

Solution code:
N,M = map(int,input().split())
count = 0
for i in range(M):
    a,b = map(int,input().split())
    if count == 0:
        set = {i for i in range(a,b+1)}
        count = 1
    else:
        set2 ={i for i in range(a,b+1)}
        set = set & set2
print(len(set))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

print(sum(l))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import sys
#input = sys.stdin.readline
N, M = map(int, input().split())
lr = [list(map(int, input().split())) for i in range(M)]


# In[9]:


union = set(range(1, N+1))
for i in range(M):
    union = union & set(range(lr[i][0], lr[i][1]+1))
print(len(union))


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
gates = []
count = 0
for gate in range(m):
    gates.append(list(map(int, input().split())))
for card in range(n):
    card+=1
    token = True
    for gate in range(m):
        if (card < gates[gate][0] or gates[gate][1] < card):
            token = False
            break
    if token:
        count +=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
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-1,r):
        arr[j]+=1
print (arr.count(m))

Submission status: Time Limit Exceeded

Solution code:
import sys
 
n=0
m=0
id_list=[]

n, m  = map(int, input().split())
for i in range(0, m):
  gate_min, gate_max = map(int, input().split())
  id_list.append([gate_min, gate_max])
 

result = 0
for i in range(1, n+1):
  is_passed = True
  for gate in id_list:
    if not((i >= gate[0]) and (i <= gate[1])) :
      is_passed = False
      break

  if is_passed:
    result = result + 1	
print(result)
sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
def calculate(n, m, id_list):
  result = 0
  for i in range(1, n+1):
    is_passed = True
    for gate in id_list:
      if not((i >= gate[0]) and (i <= gate[1])) :
        is_passed = False
        break
        
    if is_passed:
      result = result + 1
    
  return result
  
  
import sys
 
n=0
m=0
id_list=[]
is_arg_ok = False
try:
  n, m  = map(int, input().split())
  for i in range(0, m):
    gate_min, gate_max = map(int, input().split())
    id_list.append([gate_min, gate_max])
  is_arg_ok = True
  
except:
  print('arg error')
  sys.exit(1)
 
calculated_num = calculate(n, m, id_list)
print(calculated_num)
sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
def calculate(n, m, id_list):
  result = 0
  for i in range(1, n+1):
    is_passed = True
    for id_list_index in range(0, m):
      if not((i >= id_list[id_list_index][0]) and (i <= id_list[id_list_index][1])) :
        is_passed = False
        break
        
    if is_passed:
      result = result + 1
    
  return result
  
  
import sys
 
n=0
m=0
id_list=[]
is_arg_ok = False
try:
  n, m  = map(int, input().split())
  for i in range(0, m):
    gate_min, gate_max = map(int, input().split())
    id_list.append([gate_min, gate_max])
  is_arg_ok = True
  
except:
  print('arg error')
  sys.exit(1)
 
calculated_num = calculate(n, m, id_list)
print(calculated_num)
sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys
 
n=0
m=0
id_list=[]
 
def calculate(x):
  _x = x + 1
  for id_list_index in range(0, m):
    if not((_x >= id_list[id_list_index][0]) and (_x <= id_list[id_list_index][1])) :
      return False
 
  return True
  
  
is_arg_ok = False
try:
  n, m  = map(int, input().split())
  for i in range(0, m):
    gate_min, gate_max = map(int, input().split())
    id_list.append([gate_min, gate_max])
  is_arg_ok = True
  
except:
  print('arg error')
  sys.exit(1)
 
 
result = len(list(filter(lambda n: calculate(n), range(0, n))))
print(result)
sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys

n=0
m=0
id_list=[]

def calculate(x):
  c = len(list(filter(lambda id_list_index: (x >= id_list[id_list_index][0]) and (x <= id_list[id_list_index][1]) , range(0, m))))
  if m == c:
    return True
  return False

is_arg_ok = False
try:
  n, m  = map(int, input().split())
  for i in range(0, m):
    gate_min, gate_max = map(int, input().split())
    id_list.append([gate_min, gate_max])
  is_arg_ok = True
  
except:
  print('arg error')
  sys.exit(1)


result = len(list(filter(lambda x: calculate(x), range(1, n + 1))))
print(result)
sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
import sys

n=0
m=0
id_list=[]

def calculate(x):
  _x = x +1
  is_passed = True
  for id_list_index in range(0, m):
    if not((_x >= id_list[id_list_index][0]) and (_x <= id_list[id_list_index][1])) :
      is_passed = False

  return is_passed
  
  
is_arg_ok = False
try:
  n, m  = map(int, input().split())
  for i in range(0, m):
    gate_min, gate_max = map(int, input().split())
    id_list.append([gate_min, gate_max])
  is_arg_ok = True
  
except:
  print('arg error')
  sys.exit(1)


result = len(list(filter(lambda n: calculate(n), range(0, n))))
print(result)
sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
def calculate(n, m, id_list):
  result = 0
  for i in range(1, n+1):
    is_passed = True
    for id_list_index in range(0, m):
      if not((i >= id_list[id_list_index][0]) and (i <= id_list[id_list_index][1])) :
        is_passed = False
        
    if is_passed:
      result = result + 1
    
  return result
  
  
import sys

n=0
m=0
id_list=[]
is_arg_ok = False
try:
  n, m  = map(int, input().split())
  for i in range(0, m):
    gate_min, gate_max = map(int, input().split())
    id_list.append([gate_min, gate_max])
  is_arg_ok = True
  
except:
  print('arg error')
  sys.exit(1)

calculated_num = calculate(n, m, id_list)
print(calculated_num)
sys.exit(0)

Submission status: Time Limit Exceeded

Solution code:
nm = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for i in range(nm[1])]


a = [{j for j in range(lr[i][0], lr[0][1]+1)} for i in range(nm[1])]
b = set()
for i in range(len(a)):
    if b == set():
        b = a[i]
    b = b & a[i]
print(len(b))

Submission status: Time Limit Exceeded

Solution code:
import collections

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

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

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

lr_gate = map(str, lr_gate)
lr_collect = collections.Counter(lr_gate)

count = 0
for v in lr_collect.values():
    if v == m:
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
nm = [int(i) for i in input().split()]
lr = [[int(i) for i in input().split()] for i in range(nm[1])]

a = [{j for j in range(lr[i][0], lr[i][1]+1)} for i in range(nm[1])]
b = set()
for i in range(len(a)):
    if b == set():
        b = a[i]
    b = b & a[i]
print(len(b))

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(m-1):
    l, r = map(int, input().split())
    ans = ans & set(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[i],R[i]=map(int,input().split())
  LR.append([L[i],R[i]])
a=max(L)
b=min(R)
ans=0
for i in range(a,b+1):
  count=0
  for j in range(M):
    if LR[j][0]<=i<=LR[j][1]:
      count+=1
  if count==M:
      ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
LR=[]
for i in range(M):
  a=list(map(int,input().split()))
  LR.append(a)
ans=0
for i in range(1,N+1):
  count=0
  for j in range(M):
    if LR[j][0]<=i<=LR[j][1]:
      count+=1
  if count==M:
    ans+=1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(x) for x in input().split()]
def check(n, LR):
  return 1 if all(l <= n <=r for l, r in LR) else 0

LR = []
for _ in range(M):
  LR.append([int(x) for x in input().split()])

print(sum(check(n, LR) for n in range(1, N+1)))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
data=[[int(x) for x in input().split()] for m in range(M)]
_min=min([m[0] for m in data])
_max=max([m[1] for m in data])
data=[list(range(m[0],m[1]+1)) for m in data]
#print(data)
count=0
for i in range(_min,_max+1):
    count+=(sum([(i in m) for m in data])==len(data))
print(count)

Submission status: Time Limit Exceeded

Solution code:

N,M = input().split()

N = int(N)
M = int(M)
LRs = []
ans = 0

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

for i in range(N):

    bul = True
    for j in range(M):

        if LRs[j][0] > i+1 or LRs[j][1] < i+1:
            bul = False
            break

    if bul :
        ans += 1

print (ans)

Submission status: Time Limit Exceeded

Solution code:

N,M = input().split()

N = int(N)
M = int(M)
LRs = []
ans = 0

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

for i in range(N):

    bul = True
    for j in range(M):

        if LRs[j][0] > i+1 or LRs[j][1] < i+1:
            bul = False

    if bul :
        ans += 1

print (ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
[n,m] = [int(i) for i in input().split()]
ls = []
for i in range(n):
    ls.append(i+1)
for i in range(m):
    [l,r] = [int(i) for i in input().split()]
    ls = [0] * (l-1) + ls[l-1:r] + [0] * (n-r)
print(len([i for i in ls if i != 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())
    tmp=set(range(l,r+1))
    ans=ans&tmp
print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
a,b = map(int,input().split(" "))
ar = []
l = list(map(int,input().split(" ")))
for i in range(l[0],l[1]+1):
    ar.append(i)
br = []
for i in range(b-1):
    l = list(map(int,input().split(" ")))
    for r in ar:
        if r < l[0] or r > l[1]:
            br.append(r)
    for r in br:
        ar.remove(r)
    br.clear()
#print(ar)
print(len(ar))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys

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

L = []
R = []
for _ in range(M):
    l, r = map(int, input().rstrip().split())
    L.append(l)
    R.append(r)

Ans = set(range(L[0], R[0] + 1))
for i in range(1, len(L)):
    Ans = set(range(L[i], R[i] + 1)) & Ans
    if not Ans:
        print(0)
        sys.exit(0)

print(len(Ans))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
li = {i+1 for i in range(N)}
# print(li)
box = []
for _ in range(M):
    l, r = map(int, input().split())
    # print(l, r)
    for i in li:
        # print(i)
        if l <= i and i <= r:
            box.append(i)
    li = list(set(li) & set(box))
    box.clear()
    # print(li)
print(len(li))

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(1, n+1):
  c = 0
  for ll in l:
    if i>=ll[0] and i<=ll[1]:
      c += 1
    else:
      break
  if c == m:
    ans += 1
    
print(ans)

Submission status: Time Limit Exceeded

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

ans = 0

for i in range(1, n+1):
    flag = True
    for li, ri in zip(L, R):
        if not (i >= li and i <= ri):
            flag = False
            break
    if flag:
        ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
l, r = map(int, input().split())
tmpa = list(map(int, range(l, r+1)))
for i in range(m-1):
    l, r = map(int, input().split())
    ret = []
    for j in range(l, r+1):
        if j in tmpa:
            ret.append(j)

    tmpa = ret.copy()

print(len(tmpa))

Submission status: Time Limit Exceeded

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

s = set(range(LR[0][0], LR[0][1]+1))
for lr in LR:
  s = s.intersection(s, set(range(lr[0], lr[1]+1)))

print(len(s))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LRs = None
for i in range(M):
	l, r = map(int, input().split())
	if(LRs is None):
		LRs = set(range(l, r+1))
	else:
		LRs = LRs.intersection(set(range(l, r+1)))
print(str(len(LRs)))

Submission status: Time Limit Exceeded

Solution code:
# ABC127C - Prison
n, m = list(map(int, input().rstrip().split()))
a, b = list(map(int, input().rstrip().split()))
ans = {i for i in range(a, b + 1)}
for _ in range(m - 1):
    a, b = list(map(int, input().rstrip().split()))
    ans = ans & {i for i in range(a, b + 1)}
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
# ABC127C - Prison
n, m = list(map(int, input().rstrip().split()))
lst = [list(map(int, input().rstrip().split())) for _ in range(m)]
gates = [{j for j in range(i[0], i[1] + 1)} for i in lst]
ans = gates[0]
for i in gates[1:]:
    ans = ans & i
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
L,R=map(int,input().split())
l=list(range(L,R+1))
for i in range(M-1):
    L,R=map(int,input().split())
    cnt=0
    for y in range(len(l)):
        if l[y-cnt] not in range(L,R+1):
                l.pop(y-cnt)
                cnt+=1
print (len(l))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
l=[]
L,R=map(int,input().split())
l.extend(list(range(L,R+1)))
for i in range(M-1):
    L,R=map(int,input().split())
    cnt=0
    if len==[]:break
    for y in range(len(l)):
        if l[y-cnt] not in range(L,R+1):
                l.pop(y-cnt)
                cnt+=1
print (len(l))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
l=[]
L,R=map(int,input().split())
l.extend(list(range(L,R+1)))
for i in range(M-1):
    L,R=map(int,input().split())
    cnt=0
    for y in range(len(l)):
        if l[y-cnt] not in range(L,R+1):
                l.pop(y-cnt)
                cnt+=1
print (len(l))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
l=[]
L,R=map(int,input().split())
l.extend(list(range(L,R+1))) 
if M>1:
    for i in range(M-1):
        L,R=map(int,input().split())
        x=list(range(L,R+1))
        l=set(l) & set(x)
print (len(l))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
l=[]
cnt=0
for i in range(M):
    L,R=map(int,input().split())
    x=list(range(L,R+1))
    if cnt==0:
        l.extend(x)
        cnt=1
    l=set(l) & set(x)
print (len(l))

Submission status: Time Limit Exceeded

Solution code:
from math import ceil

N,M=map(int,input().split())
l=[]
for i in range(M):
    L,R=map(int,input().split())
    x=list(range(L,R+1))
    l.append(x)
m=l[0]
n=l[M-1]
for i in range(1,ceil(M//2)):
    m=set(m)&set(l[i])
    n=set(n)&set(l[M-1-i])
print (len(set(m) & set(n)))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, M =map(int, input().split())
li = []
l, r = map(int, input().split())
for j in range(r-l+1):
    li.append(j + l)
for i in range(M-1):
    l, r = map(int, input().split())
    # for j in range(r-l+1):
    li = [s for s in li if l <= s and s <= r]
print(len(li))

Submission status: Time Limit Exceeded

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

gates = [0]*(N+1)
for line in LR:
    for i in range(line[0],line[1]+1):
        gates[i] += 1

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
l = [] 
r = []
count = 0

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

#idカードの生成
    
for i in range(1,N+1):
    if max(l) <= i and i <= min(r):
        count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
# 標準入力
# n ,m
n, m = (int(x) for x in input().split())
# 1~m行までl, 入力
g = []
for i in range(m):
    g.append(list(map(int, input().split())))

# 計算
#### print(g)
#print(g[0][1])
##
# 1~M
cnt = 0
for i in range(1, n+1):
    flag = 0
    #### print("-card:{a}".format(a = i))

    for j in range(m):
        #### print("gate:{a}".format(a = j+1))
        clr = 0

        for k in range(g[j][0],g[j][1]+1):
            #### print("card{a} vs key{b}".format(a = i, b = k))
            if i == k:
                #### print("match key!:{a}".format(a = k))
                clr += 1
            else:
                #### print("unmath.")
                pass

        if clr > 0:
            flag += 1
            #### print("clar!gate{a}".format(a = j+1))
        else:
            #### print("failed.")
            pass

    if flag == m:
        #### print("--------All success!!card{a}".format(a=i))
        cnt += 1

print(cnt)