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: Runtime Error

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

import math

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

# 2つずつくみでしょりしたい
def saiki(totyuu):
    if len(totyuu) < 1000:
        mid = int(math.floor(len(totyuu)/2))
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list([m1, m2])
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Submission status: Runtime Error

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

nums=[]
count=[]

for i in range(m):
    l=[]
    a,b=map(int,input().split())
    l+=list(range(a,b+1))
    nums.append(l)

for i in range(m):
    count.extend(set(nums[i-1]) & set(nums[i]))
c=collections.Counter(count)
print(len(str(c.most_common()[0][0])) if not m==1 else n)

Submission status: Runtime Error

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

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

# 2つずつくみでしょりしたい
def saiki(totyuu):
    if len(totyuu) < 1000:
        mid = int(math.floor(len(totyuu)/2))
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list([m1, m2])
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Submission status: Runtime Error

Solution code:
import numpy as np
x = list(map(int, input().split()))
n, m = x[0], x[1]
y = [input().split() for i in range(m)]

y = np.array(y)
l,r = y[:,0], y[:,1]

c = 0
if m == 1:
    c =int(r)+1- int(l)
    print(c)
else:
    for i in range(m):
        if i ==0:
            a = np.arange(int(l[i]), int(r[i])+1)
            a = set(a)
            b = set(a)
        else:
            a = np.arange(int(l[i]), int(r[i])+1)
            a =set(a)
            c = a & b
    if c == 0:
        print(0)
    else:
        print(len(c))

Submission status: Runtime Error

Solution code:
import sys
 
N, M = map(int,input().split())
 
ls = []
 
L, R = map(int,input().split())
l = [k+L for k in range(R-L+1)]
 
if M == 1:
    print(len(l))
else:
    cs = []
    for i in range(M-1):
        L, R = map(int,input().split())
        if L in l:
            c = l[-1] - L + 1
            if c <= 0:
                print(0)
                sys.exit()
            cs.append(c)
 
    print(min(cs))

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
listA = [list(map(int,input().split())) for i in range(m)]
listB=[]
for h in range(1,n+1):
    listB.append(h)
for j in range(m):
    for k in range(1,n+1):
        if k<listA[j][0] or k>listA[j][1]:
            listB[k]=0
listB.append(0)
setA=set(listB)
print(len(setA)-1)

Submission status: Runtime Error

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

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import math
logM = int(math.floor(math.log2(M)))

# 2つずつくみでしょりしたい
def saiki(totyuu):
    for i in range(0, logM):
        if len(totyuu) < 1000:
            mid = int(math.floor(len(totyuu)/2))
            m1 = merge_list(totyuu[:mid])
            m2 = merge_list(totyuu[mid:])
            return merge_list([m1, m2])
        else:
            return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Submission status: Runtime Error

Solution code:
l = raw_input().split()
N = int(l[0])
M = int(l[1])

L = []
R = []

for i in range(M):
    l = raw_input().split()
    L.append(int(l[0]))
    R.append(int(l[1]))

l = max(L)
#r = min(R)
print(l, r)
if l > r:
    print(0)
else:
    print(r - l + 1)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

cnt = 0

NM = np.zeros([M,N])

for i in range(M):
    A = input().split()
    NM[i,int(A[0])-1:int(A[1])] = 1.0

s = np.sum(NM,axis=0)

print(np.sum(s==M))

Submission status: Runtime Error

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


#numcard
#gatenum
N, M = map(int, input().split())
card_count = range(1,N+1)

#idカードの生成
for i in range(1,M+1):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    #1ゲートの処理
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

Submission status: Runtime Error

Solution code:
    N, M = map(int, input().split())
     
    L = []
    R = []
    LR = [int(i) for i in range(1, N+1)]
    for i in range(M):
        l, r = map(int, input().split())
        L.append(l)
        R.append(r)
        LR.append(l)
        LR.append(r)
     
    tmp = []
    for gate in range(1, M+1):
        for i in range(L[gate-1], R[gate-1]+1):
            tmp.append(i)
        tmpLR = list(set(tmp) & set(LR))
        LR.clear()
        LR = tmpLR
        tmp.clear()
     
    print(len(LR))

Submission status: Runtime Error

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

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import math
logM = int(math.floor(math.log2(M)))

# 2つずつくみでしょりしたい
def saiki(totyuu):
    for i in range(0, logM):
        if len(totyuu) < 100:
            mid = int(math.floor(len(totyuu)/2))
            m1 = merge_list(totyuu[:mid])
            m2 = merge_list(totyuu[mid:])
            return merge_list([m1, m2])
        else:
            return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

cnt = 0

NM = np.zeros([M,N])

for i in range(M):
    A = input().split()
    NM[i,int(A[0])-1:int(A[1])] = 1.0

print(NM)

s = np.sum(NM,axis=0)
print(s)

print(np.sum(s==M))

Submission status: Runtime Error

Solution code:
import sys

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

ls = []

L, R = map(int,input().split())
l = [k+L for k in range(R-L+1)]

if M == 1:
    print(len(l))
else:
  	cs = []
    for i in range(M-1):
        L, R = map(int,input().split())
        if L in l:
            c = l[-1] - L + 1
            if c <= 0:
                print(0)
                sys.exit()
            cs.append(c)

    print(min(cs))

Submission status: Runtime Error

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


#numcard
#gatenum
N, M = map(int, input().split())
card_count = range(N+1)

#idカードの生成
for i in range(1,M+1):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    #1ゲートの処理
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

Submission status: Runtime Error

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

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

passIDs = [0] * 105

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

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

    maxVal = len(passIDs)

    if R < maxVal:
        for j in range(R, maxVal):
            if len(passIDs) <= j:
                break
            del passIDs[j]

    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: Runtime Error

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

def merge_list(list):
    # sortずみ
    return (list[-1][0], min(map(lambda x: x[1], list)))

data = []
for i in range(0, M):
    l, r = input().split()
    data.append((int(l), int(r)))
data = sorted(data, key=lambda x: x[0])

import math
logM = math.floor(math.log2(M))

# 2つずつくみでしょりしたい
def saiki(totyuu):
    for i in range(0, logM):
        if len(totyuu) < 100:
            mid = int(math.floor(len(totyuu)/2))
            m1 = merge_list(totyuu[:mid])
            m2 = merge_list(totyuu[mid:])
            return merge_list([m1, m2])
        else:
            return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)
L = data[0]
R = data[1]

print(max(0, R-L+1))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
N, M= map(int, raw_input().split())
i = 1
a, b = map(int, raw_input().split()) 
if i == M:
    result = b - a + 1
    print result
    sys.exit()
while 1:
  if i >= M:
    result = b - a + 1
    print result
    sys.exit()
  c, d = map(int, raw_input().split())  
  a = c
  i = i + 1
  temp = b - a
  if temp < 0
    print "0"
    sys.exit()

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
x = []
for i in range(M):
  a,b = map(int, input().split())
  x.extend(range(a,b+1))


import collections
counter = collections.Counter(x)
freqCheck = counter.most_common()
 
mode = [freqCheck[0][0]] 
maxCount = freqCheck[0][1] 

count = 1
while maxCount == freqCheck[count][1]:
    mode.append(freqCheck[count][0])
    count = count + 1
print(len(mode))

Submission status: Runtime Error

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


#numcard
#gatenum
N, M = map(int, input().split())
card_count = range(N+1)

#idカードの生成
for i in range(M):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    #1ゲートの処理
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

Submission status: Runtime Error

Solution code:
isstr=input()
n,m = [int(i) for i in isstr.split(' ')]
l=[0]*m
r=[0]*m
for i in range(m):
    l[i],r[i]=[int(i)-1 for i in input().split(' ')]
a=[0]*n
for i in range(m):
    for j in range(l[i],r[i]+1):
        a[j]+=1
print(len([_ for i in a if i==m]))

Submission status: Runtime Error

Solution code:
N, M = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
B = [0] * M
C = [0] * M
Bsum = 0
for i in range(M):
    B[i], C[i] = (int(x) for x in input().split())
    Bsum += B[i]

Submission status: Runtime Error

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

ls = []

L, R = map(int,input().split())
l = [k+L for k in range(R-L+1)]

cs = []

if M == 1:
    print(len(l))
else:
    for i in range(M-1):
        L, R = map(int,input().split())
        if L in l:
            c = l[-1] - L + 1
            cs.append(c)

    print(min(cs))

Submission status: Runtime Error

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


#numcard
#gatenum
N, M = map(int, input().split())
card_count = range(N+1)

#idカードの生成
for i in range(M):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)
    
for gate_num in range(1,M+1):
    #1ゲートの処理
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

cnt = 0

NM = np.zeros([M,N])

for i in range(M):
    A = input().split()
    NM[i,int(A[0]):int(A[1])] = 1.0

s = np.sum(NM,axis=0)

print(np.sum(s==M))

Submission status: Runtime Error

Solution code:
a, b= map(int, input().split())
A=[]
A = [list(input().split())   for i in range(a)]
B=[]
for i in A:
  s=int(i[0])
  v=int(i[1])+1
  for j in range(s,v):
    B.append(j)
C = [x for x in set(B) if B.count(x) > 1]
print(len(C))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
lim = []
res = []
for i in range(1,n+1):
    res.append(i)
for n in range(0,m):
    lim.append(list(map(int,input().split())))
for k in lim:
    if k[0] <= res[0]:
        a = 0
    #try:
    else:
        a = int(res.index(k[0]))
    #except ValueError:
    del res[:a]
    #try:
    if k[1] >= res[-1]:
        b = res[-1]
    #except ValueError:
    else:
        b = int(res.index(k[1]))
    del res[b+1:]

print(len(res))

Submission status: Runtime Error

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

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

for i in range(M):
  L, R = map(int, input().split())
  if L < answer[0]:
    L = answer[0]
  if R > answer[-1]:
    R = answer[-1]
  answer = list(range(L, R+1))

if len(answer) > 0:
  print(len(answer))
else:
  print(0)

Submission status: Runtime Error

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


#numcard
#gatenum
N, M = map(int, input().split())
card_count = range(N+1)

#idカードの生成
for i in range(M):
    l_temp,r_temp = map(int, input().split())
l.append(l_temp)
r.append(r_temp)
    
for gate_num in range(1,M+1):
    #1ゲートの処理
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

n, m = sys.stdin.readline().rstrip().split(' ')
ll, rr = None, None
for _ in range(int(m)):
  l, r = sys.stdin.readline().rstrip().split(' ')
  l, r = int(l), int(r)
  ll = l if ll is None else max(ll, int(l))
  rr = r if rr is None else min(rr, int(r))
print(rr-ll)
tomohirurinoMBP:abc tomohirofuri$ vi test.py 
tomohirurinoMBP:abc tomohirofuri$ cat test.py 
import sys
import numpy as np

n, m = sys.stdin.readline().rstrip().split(' ')
ll, rr = None, None
for _ in range(int(m)):
  l, r = sys.stdin.readline().rstrip().split(' ')
  l, r = int(l), int(r)
  ll = l if ll is None else max(ll, int(l))
  rr = r if rr is None else min(rr, int(r))
print(rr-ll+1)

Submission status: Runtime Error

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


#numcard
N = input()
card_count = range(N+1)
#gatenum
M = input()
#idカードの生成
for i in range(M):
    l_temp,r_temp = map(int, input().split())
l.append(l_temp)
r.append(r_temp)
    
for gate_num in range(1,M+1):
    #1ゲートの処理
    for card in range(1,N+1):
        num = 0
        while r[gate_num] >= l[gate_num] + num:
            if l[gate_num] + num == card:
                if card_count[card] == gate_num -1:
                    card_count[card] += 1
                    break
            num += 1

for card in range(1,N+1):
    if card_count[card] == M:
        all_gate_clear += 1

print(all_gate_clear)

Submission status: Runtime Error

Solution code:
import sys

N, M = (int(i) for i in input().split())
l = list(range(N+1))
l.pop(0)

while 1:
	try:
		L1, R1 = (int(i) for i in input().split())
		for i in l:
			if(i >= L1 and i <= R1):
				pass
			else:
				l.pop(i)
	except EOFError:
		break
print(len(l))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
l_list=[]
r_list=[]
for i in range(1, m + 1):
    l_temp, r_temp = map(int, input().split())
    l_list.append(l_temp)
    r_list.append(r_temp)

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_list[i-1] <= i <=r_list[i-1]
print(len(cards))

Submission status: Runtime Error

Solution code:
isstr=input()
n,m = [int(i) for i in isstr.split(' ')]
mini=-1
maxi=1000000000000000
for i in range(m):
    a,b=[int(i) for i in input().split(' ')]
	tmp_mini=max(mini,a)
    tmp_maxi=min(maxi,b)
    if(tmp_mini<tmp_maxi):
      mini=tmp_mini
      maxi=tmp_maxi
    elif(tmp_mini==tmp_maxi):
      if tmp_mini<=n:
        print(1)
        break
      else:
        print(0)
        break
    else:
      print(0)
      break
if(mini<maxi):      
  if n>=maxi:
    print(maxi-mini+1)
  elif maxi>n>=mini:
    print(n-mini+1)
  else:
    print(0)

Submission status: Runtime Error

Solution code:
N, M = 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)
id = []
for i in range(M):
    id += [L[i:] + R[:i + 1]]
com = set(id[0]) & set(id[1])
for j in range(1, M):
    com = com & set(id[j])
print(len(com))

Submission status: Runtime Error

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

n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
bc = sorted([list(map(int, input().split())) for i in range(m)], key = itemgetter(1), reverse=True)

ans = 0
for i in range(n):
    now = a[i]
    for rep, con in enumerate(bc):
        if now < con[1] and bc[rep][0] != 0:
            ans += con[1]
            bc[rep][0] -= 1
            break

    else:
        ans += now + sum(a[i+1:])
        break

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

N, M = input().split()

N = int(N)
M = int(M)

A = np.zeros([2,M])

cnt = 0

for i in range(M):
    A[:,i] = input().split()

A = np.array(A,dtype=np.int64)


NM = np.zeros([M,N])

for i in range(M):
    NM[i,A[0,i]-1:A[1,i]] = 1.0


s = np.sum(NM,axis=0)

print(np.sum(s==M))

Submission status: Runtime Error

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

cnt = 0
for i in range(N):
  tmp = 0
  for L, R in LR:
    if L-1 <= i <= R-1:
      tmp += 1
    else:
      break
    if tmp == M:
      cnt += 1
      break
print(cnt)

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
a, b = map(int,input().split())
if M > 1:
  for i in range(M-1):
    c, d = map(int,input().split())
    if c > b or d < a:
      continue
    elif a <= c <= b and b < d:
      l0 = list(range(c,b+1))
    elif a <= c <= b and b >= d:
      l0 = list(range(c, d+1))
    elif a <= d <= b and c < a:
      l0 = list(range(a, d+1))
    elif a <= d <= b and c >= a:
      l0 = list(range(c, d+1))
    a = l0[0]
    b = l0[-1]
else:
  l0 = list(range(a, b+1))
print(len(l0))

Submission status: Runtime Error

Solution code:
n,m =map(int,input().split())
count = [0]
result= 0
for i in range(m):
  flag =True
  l,r = map(int,input().split())
  while flag:
    if l != r:
      try:
        count[l] += 1
      except:
        count.append(1)
      l += 1
    else:
      flag = False
for x in range(n):
  if m == count[x]:
    result += 1
print(result+1)

Submission status: Runtime Error

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

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

for i in range(M):
  L, R = map(int, input().split())
  if L < answer[0]:
    L = answer[0]
  if R > answer[-1]:
    R = answer[-1]
  answer = list(range(L, R+1))

print(len(answer))

Submission status: Runtime Error

Solution code:
from functools import reduce
isstr=input()
n,m = [int(i) for i in isstr.split(' ')]
mini=-1
maxi=1000000000000000
for i in range(m):
    a,b=[int(i) for i in input().split(' ')]
	tmp_mini=max(mini,a)
    tmp_maxi=min(maxi,b)
    if(tmp_mini<tmp_maxi):
      mini=tmp_mini
      maxi=tmp_maxi
    elif(tmp_mini==tmp_maxi):
      if tmp_mini<=n:
        print(1)
        break
      else:
        print(0)
        break
    else:
      print(0)
      break
      
if n>=maxi:
  print(maxi-mini+1)
elif maxi>n>=mini:
  print(n-mini+1)
else:
  print(0)

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

n, m = sys.stdin.readline().rstrip().split(' ')
ll, rr = None, None
for _ in range(int(m)-1):
  l, r = sys.stdin.readline().rstrip().split(' ')
  l, r = int(l), int(r)
  ll = l if ll is None else max(ll, int(l))
  rr = r if rr is None else min(rr, int(r))
print(rr-ll)

Submission status: Runtime Error

Solution code:
,m = map(int,input().split())
ls = [[int(x) for x in input().split()]for i in range(m)]
lst = []
ans = 0
ans_2 = 0
for i in range(m):
    a,b = ls[i][0],ls[i][1]
    for j in range(n):
        if a<=j<=b:
          lst.append(j)
for _ in range(n):
    if lst.count(_) == m:
        ans += 1
print(ans)

Submission status: Runtime Error

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())
  l, r = max(min(ans), l), min(max(ans), r)
  ans = {i for i in range(l, r+1) if i in ans}
print(len(ans))

Submission status: Runtime Error

Solution code:
n, m = map(int, input().split())
a = sorted([int(x) for x in  input().split()])
for _ in range(m):
    b, c = map(int, input().split())
    if a[0] < c:
        for i in range(b):
            if a[i] < c:
                a[i] = c
        a.sort()
print(sum(a))

Submission status: Runtime Error

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

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

for i in range(M):
    L, R = map(int, input().split())
    
    if L < answer[0]:
        L = answer[0]
    if R > answer[-1]:
        R = answer[-1]
    del answer 
    answer = list(range(L, R+1))

print(len(answer))

Submission status: Runtime Error

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(min(res) if l < min(res) else l,r+1)}
	res = res&g
	if res == {} :
		print(0)
		break
print(len(res))

Submission status: Runtime Error

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

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

for i in range(M):
    L, R = map(int, input().split())
    
    if L < answer[0]:
        L = answer[0]
    if R > answer[-1]:
        R = answer[-1]
    if L == R:
        continue
    del answer 
    answer = list(range(L, R+1))

print(len(answer))

Submission status: Runtime Error

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

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


def check(i, l, r):
    if i == m:
        return r - l + 1
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    i += 1
    return check(i, nl, nr)


print(check(1, l, r))

Submission status: Runtime Error

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

def merge(P1, P2):
    L1, R1 = P1
    L2, R2 = P2
    return (max(L1, L2), min(R1, R2))

data = []
for i in range(0, M):
    data.append(map(int, input().split()))
data = sorted(data, lambda x: x[0])

import math
logM = math.floor(math.log2(M))

totyuu = data
# 2つずつくみでしょりしたい
for i in range(0, logM):
    half = []
    if len(totyuu)%2==1:
        half.append(totyuu[-1])
    for j in range(0, int(math.floor(len(totyuu)/2))):
        # じっさいににこずつ
        half.append(merge(totyuu[2*j], totyuu[2*j+1]))
    # halfに半分入っている
    # totyuuをおきかえる
    totyuu = half
data = totyuu

for i in range(0, len(data)):
  tmpL, tmpR = data[i]
  L = max(1, tmpL)
  R = min(tmpR, R)
  if L>R:
    print(0)
    exit()
print(max(0, R-L+1))

Submission status: Runtime Error

Solution code:
N,M = map(int,input().split())
a,b=map(int,input().split())
 
l_=[int(n) for n in range(a,b+1)]
 
for i in range(M-1):
  c,d=map(int,input().split())
  if max(c,d)<= a or min(c,d) => b:
    pass
  else:
    l__=[n for n in range(c,d+1)]
    l_=list(set(l_)&set(l__))
  
  
print(len(l_))

Submission status: Runtime Error

Solution code:
N,M= map(int,input().split())
L=[]
R=[]
A=[]
for i in range(N):
	A.append(int(i+1))
for i in range(M):
	c=0
	a,b= map(int,input().split())
	for j in A:
		if j>b:
			A.pop(j-1)
		else:
			if j<a:
				A.pop(j-1)
		
print(len(A))

Submission status: Runtime Error

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

l = [0]*10000
r = [0]*10000

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: Runtime Error

Solution code:
n,m = map(int,input().split())
r={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)}
	r = r&g
	if r == {} :
		print(0)
		break
print(len(r))

Submission status: Runtime Error

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

for h in 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 M:
        if  L[j]<=i<=R[j]:
            count+=1
        else:
            break

    if count==M:
        count_ans+=1

print(count_ans)

Submission status: Runtime Error

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

for i in range(m):
    l[i],r[i] = (int(x) for x in input().split())
j = 0
hoge = [0]*(r[0]-l[0]+1)

for i in range(l[0],r[0]+1):
    hoge[j] = i
    j += 1

for i in range(1,m):
    tmp = []
    k = 0
    for j in range(max(hoge[0],l[i]),min(hoge[-1],r[i])+1):
        tmp.append(j)
        k += 1
    hoge = tmp
print(len(hoge))

Submission status: Runtime Error

Solution code:
import numpy as np
N, M = [int(i) for i in input().split()]

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

count = 0
for i in range(1, len(gate)):
    gate[i] = gate[i] + gate[i-1]

for i in range(0, M):
    if gate[i] == M:
        count += 1

print(count)

Submission status: Runtime Error

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

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


def check(i, l, r):
    if i == m:
        print(r - l + 1)
        exit(0)
    l_, r_ = map(int, input().split())
    nl = max(l, l_)
    nr = min(r, r_)
    i += 1
    check(i, nl, nr)


check(1, l, r)

Submission status: Runtime Error

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

answer = []

L, R = map(int, input().split())
answer = list(range(L, R+1))

for i in range(M-1):
    L, R = map(int, input().split())
    
    if L < answer[0]:
        L = answer[0]
    if R > answer[-1]:
        R = answer[-1]
    del answer 
    answer = list(range(L, R+1))

print(len(answer))

Submission status: Runtime Error

Solution code:
n, m = map(int,input().split())
 
l_p = 1
r_p = n
 
for j in range(m+1):
  l, r = map(int,input().split())
  if l > l_p:
    l_p = l
  if r < r_p:
    r_p = r

a = r_p - l_p + 1

print(a)

Submission status: Runtime Error

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

#numcard
N = input()
#gatenum
M = input()
#idカードの生成
for i in range(M):
    l_temp,r_temp = map(int, input().split())
    l.append(l_temp)
    r.append(r_temp)

    
    for gate_num in range(1,M+1):
        #1ゲートの処理
        for card in range(1,N+1):
            for num in range(r[gate_num]+ 1):
                if l[gate_num] + num == card:
                    if card_count[card] == gate_num -1:
                        card_count[card] += 1
                        break

    for card in range(1,N+1):
        if card_count[card] == M:
            all_gate_clear += 1

print(all_gate_clear)

Submission status: Runtime Error

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) 
            
z+=1 for x in card if card.count(x)==M
print(z//M)

Submission status: Runtime Error

Solution code:
N, M = map(int,input().split())
a, b = map(int,input().split())
for i in range(M-1):
  l = []
  c, d = map(int,input().split())
  l1 = list(range(c,d+1))
  for j in l1:
    if a <= j <= b:
      l.append(j)
  a = l[0]
  b = l[-1]
print(len(l))

Submission status: Runtime Error

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

answer = []
tmp = []

L, R = map(int, input().split())
answer = list(range(L, R+1))

for i in range(M-1):
    L, R = map(int, input().split())
    
    if L < answer[0]:
        L = answer[0]
    if R > answer[-1]:
        R = answer[-1]
    for j in range(L, R+1):
        if j in answer:
            tmp.append(j)
    del answer 
    answer = tmp
    del tmp
    tmp = []

print(len(answer))

Submission status: Runtime Error

Solution code:
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: Runtime Error

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):
        card.append(j+1) if L<=j+1<=R
            
z+=1 for x in card if card.count(x)==M
print(z//M)

Submission status: Runtime Error

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

s=[[] for i in range(M)]

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

for i in range(M-1):
    s=set(s[i]) & set(s[i+1])

print(len(s))