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 main():
    n, m = map(int, input().split())
    G = [0] * m
    ans = 0
    for i in range(m):
        G[i] = list(map(int, input().split()))
    for i in range(1, n+1):
        f = 0
        for j in range(m):
            if i < G[j][0] or G[j][1] < i:
                f = 0
                break
            else:
                f = 1
        if f == 1:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

for i in range(N):
    li.append(M)

# print(li)

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

for i in range(0, len(li)):
    if li[i] == 0:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N,M=(int(x) for x in input().split())
ans=range(1,N+1)
for x in range(M):
    l,r=(int(_) for _ in input().split())
    aa=list(range(l,r+1))
    ans=set(ans)&set(aa)
print(len(ans))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
def f(x,y):
    return x&y

n,m = map(int,input().split())
l=[]
r=[]
for i in range(m):
    l1,r1 = map(int,input().split())
    l.append(l1)
    r.append(r1)
xlist = [1]*n
for i in range(m):
    ylist = [0]*n
    ylist[l[i]-1:r[i]] = [1]*(r[i]-l[i]+1)
    xlist = list(map(f,xlist,ylist))
print(sum(xlist))

Submission status: Time Limit Exceeded

Solution code:
N,M=(int(x) for x in input().split())
L_R = list()

A,B = (int(x) for x in input().split())
L_R.append([A,B])
L_R.append([A,B])
for i in range(2,M+1):
    A,B = (int(x) for x in input().split())
    L_R.append([A,B])

mini = 1000000
for i in range(len(L_R)):
    if L_R[i][0] < mini:
        mini = L_R[i][0]
maxi = 0
for i in range(len(L_R)):
    if L_R[i][1] > maxi:
        maxi = L_R[i][1]

num = 0
for x in range(mini,maxi+1):
    n = 0
    for i in range(1,M+1):
        if L_R[i][0] <= x <= L_R[i][1]:
            n += 1
    if n == M:
        num += 1
    else:
        pass
print(num)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int,input().split())
 
l = [""] * m
ans3 = set([1,n+1])

for i in range(m):
    s,t = map(int,input().split())
    ans2 = [j for j in range(s,t+1) if s <= j <= t]
    if i == 0:
        ans3 = set(ans2)
        ans2.clear()
        if len(ans3) == 0:
            break
    else:
        ans3 = ans3 & set(ans2)
        ans2.clear()
        if len(ans3) == 0:
            break

print(len(ans3))

Submission status: Time Limit Exceeded

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

C = 0

if M == 1:
    l1, r1 = map(int, input().split())
    print(r1 - l1 + 1)
else:
    l1, r1 = map(int, input().split())
    for _ in range(M-1):
        l2, r2 = map(int, input().split())

        A = list(range(l1,r1+1))
        B = list(range(l2, r2+1))

        C = len(set(A) & set(B))
    print(C)

Submission status: Time Limit Exceeded

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

for i in range(M):
    L_in, R_in = list(map(int, input().split()))
    L.append(L_in)
    R.append(R_in)

cnt = 0
for n in range(N):
    counter = 0
    for m in range(M):
        if (n + 1) == R[m] or (L[m] <= (n + 1) and (n + 1) <= R[m]):
            counter += 1
            if counter == M:
                cnt += 1
        else:
            break
print(cnt)

Submission status: Time Limit Exceeded

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

for i in range(m):
    st, en = input().split()
    st = int(st)
    en = int(en)
    for j in range(st-1, en):
        #print(j)
        l[j] += 1

print(l.count(m))

Submission status: Time Limit Exceeded

Solution code:
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=ls[0]    
for j in range(M):
    set2=set2&ls[j]    
print(len(set2))

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(x) for x in input().split()]
LR = [[int(x) for x in input().split()] for i in range(M)]
LR = [list(range(x,y+1)) for (x,y) in LR]
res = set(LR[0])
for x in LR[1:]:
    # print(res)
    # print(x)
    res = res.intersection(set(x))
    # print(res)
print(len(res))

Submission status: Time Limit Exceeded

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

    n1 = []
    s = L
    e = R
    for j in range(s,e+1):
        n1.append(j)
    if o:
        n2 = []
        for k1 in range(len(o)):
            for k2 in range(len(n1)):
                if o[k1] == n1[k2]:
                    n2.append(o[k1])
        n1 = n2
    o = n1

print(len(o))

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import collections
N,M = [int(x) for x in input().split()]
idls =[]
for i in range(N):
    idls.append(i+1)
ans =[]
LR =[]
for i in range (M):
    L,R = [int(x) for x in input().split()]
    LR.append((L,R))

for i in range (M):
    
    iidls = idls[LR[i][0]-1:LR[i][1]]
    ans+=iidls
c= collections.Counter(ans)

a = c.most_common()

count = 0
for i in a:
    if i[1] == M:
        count+= 1
       

print(count)

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

skylist = []
for i in range(M):
    key = list(range(L[i], R[i] + 1))
    skylist.append(key)

for i in range(M):
    if M != 1:
        nice_key = list(set(skylist[0])&set(skylist[1]))
        try:
            nice_key = list(set(nice_key)&set(skylist[i+1]))
        except:
            last_key = list(set(nice_key)&set(skylist[-1]))
    elif M ==1:
            last_key = skylist[0][::]

print(len(last_key))

Submission status: Time Limit Exceeded

Solution code:
import sys

n, m = map(int, input().split())
nums = []

# for i in range(n):
#     nums.append(i + 1)

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

    if i == 0:
        for j in range(l, r + 1):
            nums.append(j)

    nums = list(filter(lambda x: l <= x <= r, nums))

    if len(nums) == 0:
        print(0)
        sys.exit()

print(len(nums))

Submission status: Time Limit Exceeded

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

li = list(range(1,n+1))
for i in range(m):
  l,r = map(int,input().split())
  if li[len(li)-1] < l or r < li[0]:
    break
  li = list(range(max(min(li),l),min(max(li),r)+1))
else:
  print(len(li))
  exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

c = np.array([], dtype=np.int64)

for i in range(M):
    c = np.append(c, np.arange(LR[i][0], LR[i][1]+1))
    
u = np.bincount(c)
print(len(np.where(u==M)[0]))

Submission status: Time Limit Exceeded

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

import numpy as np

rets = np.array([0] * n)
ls = []
rs = []
for _ in range(m):
  l, r = map(int, input().split())
  ret = np.array([0] * n)
  ret[l-1:r] = 1
  rets += ret
cnt = 0
for i in range(n):
  if rets[i] == m:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
LR = [list(map(int, input().split())) for i in range(M)]
cnt = []
for i in range(M):
    li = [k for k in range(LR[i][0], LR[i][1]+1)]
    cnt.extend(li)
    
import collections
import numpy as np
cnt = np.array(cnt)
cnt = cnt.flatten()
c = collections.Counter(cnt)

ans = 0
for j, c_val in enumerate(c.most_common()):
    if c_val[1] == M:
        ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N, M = map(int, input().split())
vote  = np.zeros(N,dtype='float32')
for i in range(0,M):
    Li, Ri = map(int, input().split())
    vote[Li-1:Ri] += 1
   
print(len(np.where(vote==M)[0]))

Submission status: Time Limit Exceeded

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

keys = [0] * N
count = N

for i in range(N):
    keys[i] = i + 1

for _ in range(M):
    L, R = list(map(int, input().split()))

    for i in range(N):
        if keys[i] != 0:
            if keys[i] < L or keys[i] > R:
                keys[i] = 0
                count -= 1

print(count)

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_list = []
for i in range(m):
    min_list.append(min(l_list[i:]))

r_l, r_r = min_list[0], r_list[0]
for l, r in zip(min_list[1:], r_list[1:]):
    if r_r >= l:
        r_l = l
    elif r_l >= r:
        r_r = r
    else:
        r_l, r_r = 0, -1
        break

print(r_r - r_l + 1)

Submission status: Time Limit Exceeded

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

a = []
for _ in range(n):
    a.append(0)

for _ in range(m):
    l,r = map(int, input().split())
    for i in range(l-1, r):
        a[i] += 1
        
for i in range(n):
    if a[i] == m:
        c += 1

print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N,M=(int(x) for x in input().split())
c=1
ans=[]
while c<=N:
    ans.append(c)
    c=c+1
for x in range(M):
    l,r=(int(x) for x in input().split())
    aa=list(range(l,r+1))
    ans=set(ans)&set(aa)
print(len(ans))

Submission status: Time Limit Exceeded

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

for i in range(m):
    l,r = map(int,input().split())
    tmp = [i for i in range(l,r+1)]
    if i == 0:
        kyotu = tmp
    else:
        kyotu = list(set(tmp)&set(kyotu))
        # print(kyotu)

print (len(kyotu))

Submission status: Time Limit Exceeded

Solution code:
import sys
import copy

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

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
    if i != 0:
        if Rs[i-1] < Ls[i]:
            print(0)
            sys.exit( )
ls = []

for i in range(M):
    l = [k+Ls[i] for k in range(Rs[i]-Ls[i]+1)]
    ls.append(l)
    
if M == 1:
    print(len(l))
else:
    for i in range(M-1):
        l_set = set(ls[i]) & set(ls[i+1])
        ls[i+1] = copy.deepcopy(l_set)

    print(len(l_set))

Submission status: Time Limit Exceeded

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

li = list(range(1,n+1))
for i in range(m):
  l,r = map(int,input().split())
  if li[len(li)-1] < l or r < li[0]:
    break
  li = list(range(max(li[0],l),min(li[len(li)-1],r)+1))
else:
  print(len(li))
  exit()
print(0)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
N, M = [int(x) for x in stdin.readline().rstrip().split()]
l = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]

listT = []
for t in l:
  listT = listT + t

s = min(list(set(listT)))
e = max(list(set(listT)))
cnt = 0
for i in range(s, e+1):
  isOk = True
  for start, end in l:
    if i < start or i > end:
      isOk = False
      break
  if isOk == True:
    cnt = cnt + 1

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
lst=[]
for i in range(m):
  a,b=map(int,input().split())
  for j in range(a,b+1):
    lst.append(j)
cnt=0
for k in range(1,n+1):
  if lst.count(k)==m:
    cnt+=1
print(cnt)

Submission status: Time Limit Exceeded

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

l = [0]*100000
r = [0]*100000

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

count = 0
num = 0

for key in range(1,n + 1):#鍵の番号
    for i in range(0,m):#
        if(key >= l[i] and key <= r[i]):
            count += 1
    if(count == m):
        num += 1
    count = 0
        
print(num)

Submission status: Time Limit Exceeded

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

from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]

clear_list = [1] * N
    
for i in range(M):
    start, end  = [int(x) for x in stdin.readline().rstrip().split()]
    for i in range(1,N+1):
        if i < start or end < i:
            clear_list[i-1] = 0

print(clear_list.count(1))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
res={i for i in range(1,n+1)}
for i in range(m):
	l,r = map(int,input().split())
	g = { i for i in range(l,r+1)}
	res = res&g
	if res == {} :
		print(0)
		break
print(len(res))

Submission status: Time Limit Exceeded

Solution code:
N, M = map(int, input().split())
m = 0b0
exec("m = 0b" + "1"*N)
for i in range(M):
	L, R = map(int, input().split())
	exec("_m = 0b" + "1"*(R - L + 1) + "0"*(N - R))
	m = m & _m
	if m == 0b0 : break

print(bin(m).count("1"))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

for i in range(1,N+1):
    flg=1
    for j in range(1,M+1):
        if i >= L[j] and i <= R[j]:
            continue
        flg=0

    if flg==1:
        ans+=1
print(ans)

Submission status: Time Limit Exceeded

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


def remove_smaller_num(target_ids, target_num):
    results = []
    for i in target_ids:
        if i >= target_num:
            results.append(i)
    return results


def remove_larger_num(target_ids, target_num):
    results = []
    for i in target_ids:
        if i <= target_num:
            results.append(i)
    return results


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

for i in range(0, m):
    ids = remove_smaller_num(ids, gates[i][0])
    ids = remove_larger_num(ids, gates[i][1])

print(len(ids))

Submission status: Time Limit Exceeded

Solution code:
from functools import reduce
isstr=input()
n,m = [int(i) for i in isstr.split(' ')]
gate=[0]*m
for i in range(m):
    a,b=[int(i) for i in input().split(' ')]
    gate[i]=set([j for j in range(a,b+1)])
result=reduce(lambda x,y:x&y, gate)
count=0
for re in result:
  if re <=n:
    count+=1
print(count)

Submission status: Time Limit Exceeded

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

cards = [i for i in range(1, n + 1)]
for i in range(1, m + 1):
    l, r = map(int, input().split())
    for card in cards:
        if card == 0:
            continue
        else:
            if card < l or r < card:
                cards[card - 1] = 0
            else:
                pass

cards = [i for i in cards if i is not 0]
print(len(cards))

Submission status: Time Limit Exceeded

Solution code:
import functools 

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

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

found = functools.reduce(lambda x, y: list(set(x) & set(y)), cards)
print(len(found))

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int, input().split())
a = []
for i in range(m):
  a.append(list(map(int, input().split())))
 
b = []
for i in range(m):
  c = a[i][0]
  d = a[i][1]
  for e in range(c,d+1):
    b.append(e)

c = [t for t in set(b) if b.count(t) == m]

print(len(c))

Submission status: Time Limit Exceeded

Solution code:
N,M=(int(x) for x in input().split())
c=1
ans=[]
while c<=N:
    ans.append(c)
    c=c+1
for x in range(M):
    l,r=(int(x) for x in input().split())
    aa=list(range(r+1))
    for n in range(l):
        aa.remove(n)

    ans=set(ans)&set(aa)
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

c = np.array([], dtype=np.int64)

for i in range(M):
    c = np.append(c, np.arange(LR[i][0], LR[i][1]+1))
    
u = np.bincount(c)

res = 0
for i in u:
    if i == M:
        res = res + 1
        
print(res)

Submission status: Time Limit Exceeded

Solution code:
import copy
n,m = map(int,input().split())
l = []
for i in range(m):
  l.append([int(i) for i in input().split()])
ll = []
for k in range(l[0][0],l[0][1]+1):
  ll.append(k)
for j in range(1,m):
  for i in ll:
    lll = copy.copy(ll)
    if i < l[j][0] or i > l[j][1]:
      lll.remove(i)
    ll = lll
print(len(ll))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N, M = map(int, input().split())
vote  = np.zeros(N)
for i in range(0,M):
    Li, Ri = map(int, input().split())
    vote[Li-1:Ri] += 1
   
print(len(np.where(vote==M)[0]))

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import collections
N,M = [int(x) for x in input().split()]
idls =[]
for i in range(N):
    idls.append(i+1)
ans =[]
for i in range (M):
    L,R = [int(x) for x in input().split()]
    iidls = idls[L-1:R]
    ans+=iidls
c= collections.Counter(ans)

a = c.most_common()

count = 0
for i in a:
    if i[1] == M:
        count+= 1
       

print(count)

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
gates = []
res = 0
for i in range(m):
	l,r = map(int,input().split())
	gates.append({ i for i in range(l,r+1)})
r={i for i in range(1,n+1)}

for g in gates :
	r = r & g
print(len(r))

Submission status: Time Limit Exceeded

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

for i in range(M):
    L_in, R_in = list(map(int, input().split()))
    L.append(L_in)
    R.append(R_in)

cnt = 0
for n in range(N):
    counter = 0
    for m in range(M):
        if (n + 1) == R[m] or (L[m] <= (n + 1) and (n + 1) <= R[m]):
            counter += 1
        else:
            break
    if counter == M:
        cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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


def prison():
    N, M = (int(_) for _ in input().split())
    id_l = set(range(1, N+1))
    for _ in range(M):
        L, R = (int(_) for _ in input().split())
        id_l = id_l & set(range(L, R+1))
    return len(id_l)


print(prison())

Submission status: Time Limit Exceeded

Solution code:
n,m = map(int,input().split())
answers = [i for i in range(1,n+1)]
for i in range(m):
    l,r = map(int,input().split())
    for ans in answers[:]:
        if ans < l or ans > r:
            answers.remove(ans)
print(len(answers))

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

a=[0]*n

for i in range(m):
    for j in range(l[i]-1):
        a[j]=1
    for j in range(r[i],n):
        a[j]=1



print(a.count(0))

Submission status: Time Limit Exceeded

Solution code:
N,M=map(int,input().split())
OUT=set()
for m in range(M):
    L,R=map(int,input().split())

    for n in range(1,N+1,1):
        #print('check',n)
        if n>=L and n<=R:
            pass
        else :
            OUT.add(n)
print(N-len(OUT))

Submission status: Time Limit Exceeded

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


def remove_smaller_num(target_ids, target_num):
    results = []
    for i in target_ids:
        if i >= target_num:
            results.append(i)
    return results


def remove_larger_num(target_ids, target_num):
    results = []
    for i in target_ids:
        if i <= target_num:
            results.append(i)
    return results


ids = []
for i in range(1, n+1):
    ids.append(i)

for i in range(0, m):
    ids = remove_smaller_num(ids, gates[i][0])
    ids = remove_larger_num(ids, gates[i][1])

print(len(ids))

Submission status: Time Limit Exceeded

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

b = []
for i in range(m):
  c = a[i][0]
  d = a[i][1]
  for e in range(c,d+1):
    b.append(e)
  if i >= 1:
    c = [t for t in set(b) if b.count(t) == 2]
    b = c
  
print(len(b))

Submission status: Time Limit Exceeded

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

for i in range(M):
    L,R=map(int, input().split())
    for j in range(N):
        if L<=j+1<=R:
            card.append(j+1) 
            
for x in card:
    if card.count(x)==M:
        z+=1
print(z//M)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,M = map(int,input().split())
L = np.array([])
X = np.array([])
for i in range(M):
  l, m = map(int,input().split())
  L=np.append(L,l)
  X=np.append(X,m)
ans= np.zeros(N,dtype = np.int32)
for k in range(M):
  ans[L[k]-1:X[k]] += 1
ans_new = np.where(ans == M, 1, 0)
print(np.sum(ans_new))

Submission status: Time Limit Exceeded

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

rets = [1] * n
ls = []
rs = []
for _ in range(m):
  l, r = map(int, input().split())
  for i in range(n):
    if i < l-1 or i > r-1:
      rets[i] = 0
print(sum(rets))

Submission status: Time Limit Exceeded

Solution code:
# スペース区切りの整数の入力
N,M = map(int, input().split())
LR_list=[]
Card_list=[]

#LR読み込み
for i in range(M):
  LR_list.append([int(e) for e in input().split()])

#初期化
for i in range(N):
  Card_list.append(0)

#LRをCardListに適用
for i in range(M):
  #print("")
  for j in range(LR_list[i][0],LR_list[i][1]+1,1):
    Card_list[j-1]+=1
    #print(j,end="")
    
ans=0
    
for i in range(N):
  if Card_list[i]==M:
    ans+=1
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, M = [int(x) for x in input().split(' ')]

P = {}
for i in range(M):
  l,r = [int(x) for x in input().split(' ')]
  for s in range(l,r+1):
    if s not in P:
      P[s] = 0
    P[s] += 1
    #print(s)
    
cnt = 0
for k,v in P.items():
  if v == M:
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin

def main():
    N, M = map(int, input().split())
    seki = set(list(range(1,N+1)))
    for i in range(M):
        l, r = map(int, stdin.readline().rstrip().split())
        #l, r = map(int, input().split())
        seki &= set(list(range(l, r+1)))

    print(len(seki))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
n, m = (int(i) for i in input().split())
ok = [1] * n
for i in range(1,m+1):
  tmp_l, tmp_r = (int(j) for j in input().split())
  filter_array = [1 if tmp_l<=k<=tmp_r else 0 for k in range(1,n+1)]
  ok = [x*y for (x,y) in zip(ok, filter_array)]
print(sum(ok))

Submission status: Time Limit Exceeded

Solution code:
# c

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

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

c = set(range(a[0][0],a[0][1]+1))


for i, j in enumerate(a):
    a2, b2 = j
    d = set(range(a2,b2+1))
    c = c & d

print(len(c))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
inputs = input().split()

N = int(inputs[0])
M = int(inputs[1])

passIDs = [0] * (10**5 + 10)

for i in range(M):
    inputs = input().split()

    L = int(inputs[0])
    R = int(inputs[1])

    for j in range(L, R+1):
        passIDs[j] += 1


IDs = 0
passIDs = [i for i in passIDs if i > 0]

for passId in passIDs:
    if passId == M:
        IDs += 1

print(IDs)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
d = input().split(" ")
id_list = np.arange(1,int(d[0])+1)
 
for i in range(int(d[1])):
  	tmp = input().split(" ")
  	id_list = np.intersect1d(id_list,np.arange(int(tmp[0]),int(tmp[1])+1))

print(len(id_list))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, M = map(int, input().split())
l = np.full_like(N,M)
for i in range(M):
  N_i = np.zeros(N)
  l_i, r_i = map(int, input().split())
  N_i[l_i-1:r_i] = -1
  l = l + N_i
ans = np.sum(l == 0)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, m = map(int, input().split())
ls = []
count = 0
ans_count = 0
while count < m:
    temp = list(map(int, input().split()))
    ls.append(temp)
    count = count + 1
count2 = 0
while count2 < n:
    flg = True
    for i in ls:
        a = i[0]
        b = i[1]
        if count2+1 < a or count2+1 > b:
            flg = False
            break
    if flg:    
        ans_count = ans_count + 1
    count2 = count2 + 1
print(ans_count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

count = np.zeros(n)

arr = [[int(i) for i in input().split()] for _ in range(m)]

for i in range(m):
    count[arr[i][0]-1:arr[i][1]]+=1

print(np.sum(count==m))

Submission status: Time Limit Exceeded

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

keys = [0] * N

for i in range(N):
    keys[i] = i + 1

for _ in range(M):
    L, R = list(map(int, input().split()))

    for i in range(N):
        if keys[i] < L or keys[i] > R:
            keys[i] = 0

count = 0

for i in range(N):
    if keys[i] != 0:
        count += 1

print(count)

Submission status: Time Limit Exceeded

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

for jk in range(M):
    l, r = map(int,input().split())
    L.append(l)
    R.append(r)

count=0
count_ans=0

for i in range(1,N+1):
    count=0
    for j in range(M):
        if  L[j]<=i<=R[j]:
            count+=1
        else:
            break

    if count==M:
        count_ans+=1

print(count_ans)

Submission status: Time Limit Exceeded

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

for i in range(M):
    L_in, R_in = list(map(int, input().split()))
    L.append(L_in)
    R.append(R_in)

cnt = 0
for n in range(N):
    counter = 0
    for m in range(M):
        # print(" n = " + str(n + 1) + " m = " + str(m + 1))
        if (n + 1) == R[m] or (L[m] <= (n + 1) and (n + 1) <= R[m]) :
            counter += 1
    if counter == M:
        # print("OK")
        cnt += 1

print(cnt)

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())
    for j in range(R - L + 1):
        list.append(L + j)
max = max(list)
min = min(list)
ans_list = []
for k in range(max - min + 1):
    if list.count(min + k) == M:
        ans_list.append(min + k)
print(len(ans_list))

Submission status: Time Limit Exceeded

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

ans = []
anss = None
for i in range(m):
    l,r = [int(s) for s in input().split(' ')]
    temp = set(i for i in range(l,r+1))
    ans.append(temp)
    if i == 0:
        anss = ans[0]
    else:
        anss &= ans[i] 
print(len(anss))

Submission status: Time Limit Exceeded

Solution code:
def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))

N, M = s_input()
L, R = [], []

cards = []
for i in range(M):
    Li, Ri = s_input()
    L.extend([Li])
    R.extend([Ri])
    cards.extend(list(range(Li, Ri+1)))

cards = set(cards)

ng_cards = set()
for card in cards:
    for i in range(M):
        if card < L[i] or card > R[i]:
            ng_cards.add(card)
            break

print(len(cards - ng_cards))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
card, gate = map(int, input().split())
l, r = map(int, input().split())
ans = {i for i in range(l, r+1)}
for i in range(gate-1):
  l, r = map(int, input().split())
  ans = ans & {i for i in range(l, r+1)}
print(len(ans))

Submission status: Time Limit Exceeded

Solution code:
import sys

n, m = map(int, input().split())
nums = []

for i in range(n):
    nums.append(i + 1)

for i in range(m):
    l, r = map(int, input().split())
    nums = list(filter(lambda x: l <= x <= r, nums))
    if len(nums) == 0:
        print(0)
        sys.exit()

print(len(nums))

Submission status: Time Limit Exceeded

Solution code:
inputs = input().split()

N = int(inputs[0])
M = int(inputs[1])

passIDs = [0] * (10**5 + 10)

for i in range(M):
    inputs = input().split()

    L = int(inputs[0])
    R = int(inputs[1])

    for j in range(L, R+1):
        passIDs[j] += 1


IDs = 0

for passId in passIDs:
    if passId < M:
        continue
    IDs += 1

print(IDs)

Submission status: Time Limit Exceeded

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

for jk in range(M):
    l, r = map(int,input().split())
    L.append(l)
    R.append(r)

count=0
count_ans=0

for i in range(1,N+1):
    count=0
    for j in range(M):
        if not L[j]<=i<=R[j]:
            break
        else:
            count+=1

    if count==M:
        count_ans+=1

print(count_ans)

Submission status: Time Limit Exceeded

Solution code:
Input = input().split()
N = int(Input[0])
M = int(Input[1])

import numpy as np
x = np.ones(N+1, np.bool)
x[0] = False

for i in range(M):
    Input = input().split()
    L = int(Input[0])
    R = int(Input[1])
    y = np.zeros(N+1, np.bool)
    y[L:R+1] = True
    x = x * y

z = int(0)
for i in x:
    if i:
        z += 1

print(z)

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

a=[0]*n
for i in range(n):
    a[i]=i+1


for i in range(m):
    for j in range(l[i]-1):
        a[j]=0
    for j in range(r[i],n):
        a[j]=0

answer=0

for i in a:
    if i!=0:
        answer+=1

print(answer)