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())
res = [0,10**5]
for i in ragne(m):
    l, r = map(int, input().split())
    res[0] = max(res[0], l)
    res[1] = min(res[1], r)

print(max(res[1]-res[0]+1),0)

Submission status: Runtime Error

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

if M == 1:
    print(N)
    exit()
else:
    for i in range(0, M-1, 1):
        if gate[i][1] >= gate[i+1][0]:
            ava = list(range(gate[i+1][0], gate[i][1]+1, 1))
        else:
            none = 1
            break
        gate[i+1] = ava

print(0 if none == 1 else len(ava))

Submission status: Runtime Error

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

for i in range(0, M-1, 1):
    if gate[i][1] >= gate[i+1][0]:
        ava = list(range(gate[i+1][0], gate[i][1]+1, 1))
    else:
        none = 1
        break
    gate[i+1] = ava

print(0 if none == 1 else len(ava))

Submission status: Runtime Error

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

for i in range(0, M-1, 1):
    if gate[i][1] >= gate[i+1][0]:
        ava = list(range(gate[i+1][0], gate[i][1]+1, 1))
    else:
        none = 1
        break
    gate[i+1] = ava

print (ava)
print(0 if none == 1 else len(ava))

Submission status: Runtime Error

Solution code:
idCards, gates = input().split(" ")
idCards = int(idCards)
gates = int(gates)

for count in range(0, gates, 1):
    num1, num2 = input().split(" ")
    minNum.append(int(num1))
    maxNum.append(int(num2))

minId = max(minNum)
maxId = min(maxNum)
if minId > maxId:
    print("0")
else:
    print((maxId - minId) + 1)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
l, m = map(int, input().split())
for _ in range(M-1):
    new_l, new_r = map(int, input().split())
    if l < new_l:
        l = new_l
    if new_r < r:
        r = new_r

print(r-l+1)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
lim = list()
res = list()
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())
    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:
c = []
d = []
n,m = map(int, input().split())
for i in range(m):
    a,b = map(int,input().split())
    c.append(a)
    d.append(b)
minl = max(c)   
maxr = min(d)
if min1>maxr:
    print(0)
else:
    print(maxr-minl+1)

Submission status: Runtime Error

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

l = max(L)
r = min(R)

res = 0
for i in range(1,N+1):
	if l<=i and i<=r:
		res+=1
print(res)

Submission status: Runtime Error

Solution code:
a = []
b = []
n,m = map(int, input().split())
for i in range(m):
    a,b = map(int,input().split())
    a.append(a)
    b.append(b)
minl = max(a)   
maxr = min(b)
print(maxr-minl)

Submission status: Runtime Error

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

print(max(min(rs)-max(ls)+1),0)

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
l,r = 1,N
for i in range(m):
  L,R = map(int,input().split())
  L = max(l,L)
  R = min(r,R)
print(max(0,L-R+1))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
min = 0
max = 0
for i in range(m):
    l,r = map(int,input().split())
    min = min(min,l)
    max = max(max,r)
print(int(n-max+min))

Submission status: Runtime Error

Solution code:
ID_num, gate_num = tuple([int(i) for i in input().split(" ")])
min_list = []
max_list = []
for i in range(gate_num):
  	min_ID, max_ID = tuple([int(i) for i in input().split(" ")])
    min_list.append(min_ID)
    max_list.append(max_ID)
print(min(max_list) - max(min_list) + 1)

Submission status: Runtime Error

Solution code:
ID_num, gate_num = tuple([int(i) for i in input().split(" ")])
min_list = []
max_list = []
for i in range(gate_num):
  	min_ID, max_ID = tuple([int(i) for i in input().split(" ")])
    min_list.append(min_ID)
    max_list.append(max_ID)
print(min(max_list) - max(min_list))

Submission status: Runtime Error

Solution code:
n,m = map(int,input().split())
min,max = map(int,input().split())
for k in range(m-1):
  a,b = map(int,input().split())
  if min < a:
    min = a
  if max > b:
    max = b
if b < a:
  print(0)
else:
  print(b-a+1)

Submission status: Runtime Error

Solution code:
def prison():
    N, M = (int(i) for i in input().split())
    L_max = 0
    R_min = float("inf")
    for _ in range(M):
        L, R = (int(i) for i in input().split())
        L_max = max(L, L_max)
        R_min = min(R, R_min)
	result = max(R_min - L_max + 1, 0)
    return result


print(prison())

Submission status: Runtime Error

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


maxa=0
maxb=0
for i in range (1,m):
    if maxa<gird[i][0]:
        maxa=gird[i][0]
    if grid[i][1]<grid[i][0]:
        maxb=grid[i][1]

v=maxb-maxa+1
if v>0:
    print(v)
else:
    print(0)

Submission status: Runtime Error

Solution code:
N,M=map(int,input().split())
l=[]
L,R=map(int,input().split())
l.extend(list(range(L,R+1)))
z=len(l)
cnt=0

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

Submission status: Runtime Error

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=l & x
print (len(l))

Submission status: Runtime Error

Solution code:
from itertools import accumulate

n, m = map(int, input().split())
cards = [0] * (n+1)
for i in range(m):
  s, e = map(int, input().split())
  cards[s] += 1
  cards[e] -= 1
valids = accumulate(cards)
print(valids.count(n))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
L1, R1 = map(int, input().split())
flag = 0
def find_key(L1,R1,L2,R2):
  if R1 < L2 or R2 < L1:
    return(False)
  else:
    a = [R1,L1,R2,L2]
    a.sort()
    return(a[1],a[2])

for i in range(M - 1):
  L,R = map(int, input().split())
  if find_key(L1,R1,L,R) != False:
    L1,R1 = find_key(L1,R1,L,R)
  else:
    flag = 1
    print(0)
    break
if flag = 0:
  print(R1-L1+1)

Submission status: Runtime Error

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

N, M = map(int, input().split())
l = [0] * N
r = [0] * N
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: Runtime Error

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

N, M = map(int, input().split())
l = [0] * N
r = [0] * N
for i in range(0,N):
    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: Runtime Error

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

N, M = map(int, input().split())
l = [0] * N
r = [0] * N
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: Runtime Error

Solution code:
N, M = map(int, input().split())
L1, R1 = map(int, input().split())
flag = 0
def find_key(L1,R1,L2,R2):
  if R1 < L2 or R2 < L1:
    print(0)
    flag = 1
    break
  elif:
    a = [R1,L1,R2,L2]
    a.sort()
    return(a[1],a[2])
for i in range(M - 1):
  L,R = map(int, input().split())
  L1,R1 = find_key(L1,R1,L,R)
if flag == 1:
  print(L1,R1)

Submission status: Runtime Error

Solution code:
N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = min(B) - max(A) + 1

if ans < 1:
    print(0)
else:
    print(ans)

Submission status: Runtime Error

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

min_card = max(l[0] for l in gate_l)
max_card = min(l[1] for l in gate_l)

if max_card > min_card:
    print(max_card - min_card +1)
    
else:
    print(0)

Submission status: Runtime Error

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

min_card = max(l[0] for l in gate_l)
max_card = min(l[1] for l in gate_l)

print(max_card - min_card +1)

Submission status: Runtime Error

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

from itertools import accumulate
imos = [0]*(N+1)
for i in range(M):
    L,R = map(int,input().split())
    imos[L] += 1
    imos[R+1] -= 1
acc = list(accumulate(imos))
print(sum([1 for a in acc if a == M]))

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 max(r - l + 1, 0)
    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:
import sys
import math
 
N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))
 
_min, _max = -math.inf, math.inf
for i in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
print(_max - _min + 1)

Submission status: Runtime Error

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

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


def check(i, l, r):
    if i == m:
        try:
            return r - l + 1
        except:
            return 0

    l_, r_ = li[i]
    nl = max(l, l_)
    nr = min(r, r_)
    return check(i + 1, nl, nr)


l, r = li[0]
print(check(1, l, r))

Submission status: Runtime Error

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

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


def check(i, l, r):
    if r - l + 1 == 0:
        return 0
    if i == m:
        return r - l + 1
    l_, r_ = li[i]
    nl = max(l, l_)
    nr = min(r, r_)
    return check(i + 1, nl, nr)


l, r = li[0]
print(check(1, l, r))

Submission status: Runtime Error

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

import math

def merge_list(target):
    L = target[-1][0]
    print(target)
    R = sorted(target, key=lambda x: x[1])[0][1]
    return (L, R)

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 numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu[0]) < 10:
        return merge_list(map(merge_list, totyuu))
    else:
        return saiki(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

Solution code:
import sys
import math

N, M = map(lambda x: int(x), sys.stdin.readline().split(" "))

_min, _max = -math.inf, math.inf
for i in range(0, M):
    L, R = map(lambda x: int(x), sys.stdin.readline().split(" "))
    _min = max(_min, L)
    _max = min(_max, R)
print(_max - _min + 1)

Submission status: Runtime Error

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

"""
i番目のゲートを通れるのは
if i=1
    id = L[0] or R[0]
else
    i-1番目のゲートが通れる
    かつ
    id = L[i] or R[i]
"""
if not (L[M] == R[M]):
    for i in range(M-1):
        if (R[M] == L[i] or R[M] == R[i]):
            print(2)
        else:
            print(1)

else:
    print(1)
#output

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin

def main():
    nm = [int(x) for x in stdin.readline().rstrip().split()]
    gate = np.zeros([nm[1], 2])
    card = np.full([nm[0]], True)
    
    for i in range(nm[1]):
        g = [int(x) for x in stdin.readline().rstrip().split()]
        gate[i] = g
    for g in gate:
        for k in range(len(card)):
            if k < g[0]-1 or k >= g[1]:
                card[k] = False
    
    c = np.zeros_like(card)[card]
    print(len(c))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n, m = readmi()
a = readl()
a.sort()
d = defaultdict(int)
for i in a:
    if d[i]:
        d[i] += 1
    else:
        d[i] = 1

for i in range(m):
    x, y = map(int, input().split())
    for j in sorted(d):
        if y > j:
            w = d[j]
            ww = x
            d[j] -= ww
            x -= w
            d[y] += min(ww, w)
            if d[j] <= 0:
                del d[j]
            if x <= 0:
                break
        else:
            break
count = 0
for i in d:
    count += max(int(d[i]) * int(i),0)
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin

def main():
    nm = [int(x) for x in stdin.readline().rstrip().split()]
    card = np.full([nm[0]], True)
    
    for i in range(nm[1]):
        g = [int(x) for x in stdin.readline().rstrip().split()]
        for k in range(len(card)):
            if k < g[0]-1 or k >= g[1]:
                card[k] = False
    
    c = np.zeros_like(card)[card]
    print(len(c))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

import math

def merge_list(target):
    L = target[-1][0]
    R = sorted(target, key=lambda x: x[1])[0][1]
    return (L, R)

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 numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(list(totyuu))
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

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

import math

def merge_list(target):
    L = target[-1][0]
    R = sorted(target, key=lambda x: x[1])[-1][1]
    return (L, R)

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 numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(list(totyuu))
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

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

import math

def merge_list(list):
    L = list[-1][0]
    R = sorted(data, key=lambda x: x[1])[-1][1]
    return (L, R)

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 numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(list(totyuu))
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

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

import math

def merge_list(list):
    L = list[-1][0]
    R = sorted(data, key=lambda x: x[1])[-1][1]
    return (L, R)

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

print(1)

import numpy as np
def saiki(totyuu):
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(list(totyuu))
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

Solution code:
import numpy as np
from sys import stdin

def main():
    nm = [int(x) for x in stdin.readline().rstrip().split()]
    gate = np.full([nm[1], nm[0]], False)
    
    for i in range(nm[1]):
        g = [int(x) for x in stdin.readline().rstrip().split()]
        for k in range(g[0]-1, g[1]):
            gate[i,k] = True

    count = 0
    for i in range(len(gate[0])):
        tmp = gate[:, i]
        if tmp.all():
            count += 1
        
    print(count)

if __name__ == "__main__":
    main()

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], m[i] = map(int, input().split())

L = max(l)
R = min(r)

if L <= R:
    print(R - L + 1)
else:
    print(0)

Submission status: Runtime Error

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

max_L = int(max(L))
min_R = int(min(R))
count = 1
for i in range(max_L, min_R):
    count += 1
print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
n,m = map(int,input().split())

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

Submission status: Runtime Error

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

import math

def merge_list(list):
    L = list[-1][0]
    R = sorted(data, key=lambda x: x[1])[-1][1]
    return (L, R)

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 numpy as np
def saiki(totyuu):
    mid = int(math.floor(len(totyuu)/2))
    D = 2 # ぶんかつすう
    if len(totyuu) < 100:
        return merge_list(totyuu)
    else:
        return merge_list(np.array_split(totyuu, D))

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

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

s = (input().split(' '))

n,m = [int(i) for i in s]

l_list = []
r_list = []

for i in range(m):
    s = (input().split(' '))
    l,r = [int(i) for i in s]
    l_list.append(l)
    r_list.append(r)

range = (max(l_list), min(r_list))

if range[0] > range[1]:
    print(0)
else:
    print(range[1] - range[0] + 1))

Submission status: Runtime Error

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

"""
i番目のゲートを通れるのは
if i=1
    id = L[0] or R[0]
else
    i-1番目のゲートが通れる
    かつ
    id = L[i] or R[i]
"""
if not (L[M] == R[M]):
    for i in range(M-1):
        if (R[M] == L[i] or R[M] == R[i]):
            print(2)
        else:
            print(1)

else:
    print(1)
#output

Submission status: Runtime Error

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

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


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


print(check(1, l, r))

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
id = [list(map(int, input().split())) for _ in range(M)]
ans = 0
for i in range(1, N+1):
    a = id[0]
    b = id[1]
    if a[0] <= i <= a[1] and b[0] <= i <= b[1]:
        ans = ans + 1
print(ans)

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
lmax,rmin=0,n+1
for i in range(m):
  l,r=map(int, input().split()
  lmax=max(l,lmax)
  rmin=min(r,rmin)
print(max(0,lmax-rmin+1))

Submission status: Runtime Error

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

L=[]
R=[]

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


ans=max(R)-max(L)+1
if ans<0:
  print(0)
else:
  prnit(ans)

Submission status: Runtime Error

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

for m in range(M):
  code="name{}=[]".format(m)
  exec(code)

for j in range(M):
  "name{}=range(l[j][0],l[j][1]+1)".format(j)
  codea=print("name{}").format(j)
  exec(codea)
  
  
for k in range(M):
  co="kyotu=set(name{}) & set(name{})".format(k,k+1)
  za="name{}=kyotu".format(k+1)
  exec(co)
  exec(za)
  
  
print(kyotu)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
     
id, gate = map(int, input().split())
a = [list(map(int,input().split())) for i in range(gate)]
b = []

for i in range(gate)
    c = range(a[i, 0], a[i, 1])
    b.extend(c)

d = range(id)

d = set(d)
b = set(b)

list = list(b&d)
print(len(list))

Submission status: Runtime Error

Solution code:
import numpy as np
N,M = map(int,input().split())
for i in range(M):
    L, X = map(int, input().split())
    l = max(l,L)
    x = min(x,X)
print(x-l+1)

Submission status: Runtime Error

Solution code:
import sys

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

l, r = [],[]

count = 0

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

    if l[i] <= m and m <= r[i] :
        count = count + m - l[i]

Submission status: Runtime Error

Solution code:
import collections
N,M=map(int,input().split())
lr=[]
nu=[]
count=0
for i in range(0,M):
    lr.append(input())
    zero=int(lr[i][0])
    one=int(lr[i][2])+1
    for j in range(zero,one):
        nu.append(j)

ans= collections.Counter(nu)
answ=ans.most_common(M)
for k in range(M):
    if answ[k][1]>=M:
        count+=1

if N==int(lr[2]):
    count=N
print(count)

Submission status: Runtime Error

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

import math

def merge_list(list):
    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])

def saiki(totyuu):
    mid = int(math.floor(len(totyuu)/2))
    if len(totyuu) < 10000:
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list(totyuu)
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

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

"""
i番目のゲートを通れるのは
if i=1
    id = L[0] or R[0]
else
    i-1番目のゲートが通れる
    かつ
    id = L[i] or R[i]
"""
if not (L[M] == R[M]):
    for i in range():
        if (R[M] == L[i] or R[M] == R[i]):
            print(2)
        else:
            print(1)

else:
    print(1)
#output

Submission status: Runtime Error

Solution code:
n,m = map(int, input().split())
lmax,rmin=0,n+1
for i in range(m):
  l,r=map(int, input().split()
  lmax=max(l,lmax)
  rmin=min(r,rmin)
print(max(0,lmax-rmin+1)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
     
id, gate = map(int, input().split())
for i in range(gate)
    a = [list(map(int,input().split()))]
b = []

for i in range(gate)
    c = range(a[i, 0], a[i, 1])
    b.extend(c)

d = range(id)

d = set(d)
b = set(b)

list = list(b&d)
print(len(list))

Submission status: Runtime Error

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

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

passIDs = [0] * 10**5

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

print(len([passId for passId in passIDs if passId == M]))

Submission status: Runtime Error

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

import math

def merge_list(list):
    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])

def saiki(totyuu):
    mid = int(math.floor(len(totyuu)/2))
    if len(totyuu) < 10000000:
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list(totyuu)
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
l = [0] 
r = [0]
all_gate_clear = 0
num = 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:
N, M = map(int, input().split())
L, R = 1, N

import math

def merge_list(list):
    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])

def saiki(totyuu):
    mid = int(math.floor(len(totyuu)/2))
    if len(totyuu) < 100:
        m1 = merge_list(totyuu[:mid])
        m2 = merge_list(totyuu[mid:])
        return merge_list(totyuu)
    else:
        return merge_list([saiki(totyuu[:mid]), saiki(totyuu[mid:])])

data = saiki(data)

print(max(0, data[1]-data[0]+1))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
inputData = input()
ID, Gate = map(int, inputData.split())
x = []
for i in range(Gate):
    inputId = input()
    idStart, idEnd = map(int, inputId.split())
    idList = list(range(idStart, idEnd + 1))
    x.append(idList)

# print(x[0])


def solve():

    for i in range(len(x)):
        if i == 0:
            matched = set(x[0])
            continue

        tempX = set(x[i])
        # print('++')
        # print(matched)
        # print(tempX)
        matched = list(matched & tempX)
        # print(matched)
        if matched == []:
            #
            return 0

    return len(matched)


ans = solve()
print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
     
z = []
id, gate = map(int, input().split())
for i in range(gate)
    a = [list(map(int,input().split()))]
    z.append(a)
b = []

for i in range(gate)
    c = range(a[i, 0], a[i, 1])
    b.extend(c)

d = range(id)

d = set(d)
b = set(b)

list = list(b&d)
print(len(list))

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())
  if l > min(ans) or max(ans) > r:
    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=(int(x) for x in input().split())
L_R = list()

maxi_L = 0
mini_R = 10000000
A,B = (int(x) for x in input().split())
L_R.append([A,B])
L_R.append([A,B])
if A > maxi_L:
    maxi_L = A
if B < mini_R:
    mini_R = B
for i in range(2,M+1):
    A,B = (int(x) for x in input().split())
    L_R.append([A,B])
    if A > maxi_L:
        maxi_L = A
    if B < mini_R:
        mini_R = 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
#maxi = max(maxi,N)
#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



if mini_R  - maxi_L < 0:
    n = 0
elif:
    n = mini_R  - maxi_L + 1
print(n)

Submission status: Runtime Error

Solution code:
n,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)
        if lst(j) == m:
          break
for k in range(n):
    if (lst.count(k)) == m:
        ans_2 += 1
print(ans_2)

Submission status: Runtime Error

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

import math

def merge_list(list):
    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])

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)

print(max(0, data[1]-data[0]+1))