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: Wrong Answer

Solution code:
n, m = map(int, input().split())
l, r = [],[]
i_max = n -1
i_min = 0
for x in range(m):
    l, r = map(int, input().split())
    if l >= i_min:
        i_min = l
    if r <= i_max:
        i_max = r
    if (i_max - i_min) < 0:
        i_max = i_min - 1
        break

print(i_max - i_min + 1)

Submission status: Wrong Answer

Solution code:
def enter_card(L, R, f_point, e_point):
    if f_point < L:
        f_point = L
    if e_point > R:
        e_point = R
    return f_point, e_point

def open_list(L, R):
    return R - L + 1
   

N, M = map(int, input().split(' '))
f_point = 1
e_point = N
for i in range(M):
    L,  R = map(int, input().split(' '))
    f_point, e_point = enter_card(L, R, f_point, e_point)
a = open_list(f_point, e_point)
print(a)

Submission status: Wrong Answer

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


class CountedAcID():
    def __init__(self, gates):
        self.gates = gates
        self.scope = [1, N]

    def run(self):
        self.__get_range()
        self.total = self.__return_num()


    def __get_range(self):
        for element in self.gates:
            self.scope[0] = self.__get_left(element[0], self.scope[0])
            self.scope[1] = self.__get_right(element[1], self.scope[1])

    def __get_left(self, element, left):
        if element > left:
            return element
        else:
            return left

    def __get_right(self, element, right):
        if element < right:
            return element
        else:
            return right

    def __return_num(self):
        if self.scope[1] > N:
            return N - self.scope[0] + 1

        else:
            return self.scope[1] - self.scope[0] + 1


c = CountedAcID(gates)
c.run()
print(c.scope)
num = c.total

if num < 0:
    print(0)
else:
    print(num)

Submission status: Wrong Answer

Solution code:
# C - Prison
# https://atcoder.jp/contests/abc127/tasks/abc127_c

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


scope = [1, n]

for element in gates:
    """
    ここで範囲の左右を取得する
    Lは0番目の最大値
    Rは1番目の最小値を検索する
    """

    if element[0] > scope[0]:
        scope[0] = element[0]

    if element[1] < scope[1]:
        scope[1] = element[1]


"""
範囲の最大値がnを超えていた場合について
最小値~nまでの範囲で処理を行う

超えていない場合について
普通にR-Lを行う
"""

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

Submission status: Wrong Answer

Solution code:
# C - Prison
# https://atcoder.jp/contests/abc127/tasks/abc127_c

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


scope = [1, n]

for element in gates:
    """
    ここで範囲の左右を取得する
    Lは0番目の最大値
    Rは1番目の最小値を検索する
    """

    if element[0] > scope[0]:
        scope[0] = element[0]

    if element[1] < scope[1]:
        scope[1] = element[1]


"""
範囲の最大値がnを超えていた場合について
最小値~nまでの範囲で処理を行う

超えていない場合について
普通にR-Lを行う
"""

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

print(scope)

Submission status: Wrong Answer

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

l = [0]*m
r = [0]*m
for i in range(m):
  l[i], r[i] = list(map(int, input().split()))
print(min(r)-max(l)+1)

Submission status: Wrong Answer

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

L_max = max(L)
R_min = min(R)
print(R_min-L_max+1)

Submission status: Wrong Answer

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

li_w = list()

for _ in range(m):
    li_w.append(tuple(map(int, input().split())))

w_l = 0
w_r = 999999

for w in li_w:
    w_l = max(w_l, w[0])
    w_r = min(w_r, w[1])

print(w_r - w_l + 1)

Submission status: Wrong Answer

Solution code:
n,m = map(int,input().split())
l = [-1]*(m)
r = [-1]*m
for i in range(m):
    a,b = map(int,input().split())
    l[i]=a
    r[i]=b
right = n
left = 0 
#print(r)
#print(l)
count = 0
k = 0
for i in range(m):
    right = min(r[i],right)
    left = max(l[i],left)

print(right - left +1)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
left = 0
right = 10**5
for _ in range(m):
    l,r = map(int,input().split())
    left = max(left, l)
    right = min(right,r)
print(right-left+1)

Submission status: Wrong Answer

Solution code:
n,m = map(int, input().split())
left = 0
right = 10**5
for _ in range(m):
    l,r = map(int,input().split())
    left = max(left, l)
    right = min(right,r)
print(r-l+1)

Submission status: Wrong Answer

Solution code:
N, M  = map(int, input().split())
x_min, x_max = [], []
for i in range(M):
  L, R = map(int, input().split())
  x_min.append(L)
  x_max.append(R)
  
print(max(x_max) - min(x_min) + 1)

Submission status: Wrong Answer

Solution code:
s=list(map(int,input().split()))
t=[list(map(int,input().split())) for i in range(s[1])]
a=0
b=10001
for i in range(s[1]):
  if a<t[i][0]:
    a=t[i][0]
  if b>t[i][1]:
    b=t[i][1]
if b-a>=0:
  print(b-a+1)
else:
  print(0)

Submission status: Wrong Answer

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

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

l_list = []
r_list = []

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

print(min(r_list) - max(l_list) + 1)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

l_list = []
r_list = []

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

print(min(r_list) - max(l_list) + 1)

Submission status: Wrong Answer

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

answer = min(R) - max(L) + 1
print(answer)

Submission status: Wrong Answer

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

answer = R[0] - L[-1] + 1
print(answer)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  a,b=LI()

  l=[]
  for i in range(b):
    x,y=LI()
    l.append([x,1])
    l.append([y,-1])

  l=sorted(l,key=lambda x:x[1],reverse=True)
  l=sorted(l,key=lambda x:x[0])

  sm=0
  f=0
  e=0
  for x in l:
    sm+=x[1]
    if sm==b:
      f=x[0]
    else:
      if f!=0:
        e=x[0]
        break

  return e-f+1

print(main())

Submission status: Wrong Answer

Solution code:
N, M = [int(i) for i in input().split()]
cards = [0] * (N + 1)

for _ in range(M):
  l, r = [int(i) for i in input().split()]
  cards[l - 1] = 1 
  cards[r] = -1

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

print(len([i for i in cards if i == M]))

Submission status: Wrong Answer

Solution code:
N_M = list(map(int, input().split()))
Lock_min = []
Lock_max = []
for i in range(1,N_M[1]+1):
    ADD = list(map(int,input().split()))
    Lock_min.append(ADD[0])
    Lock_max.append(ADD[1])
if min(Lock_max) - max(Lock_min) >= 1:
        print(min(Lock_max) - max(Lock_min))
else:
        print(0)

Submission status: Wrong Answer

Solution code:
N_M = list(map(int, input().split()))
Lock_sum = []
for i in range(1,N_M[1]+1):
    ADD = list(map(int,input().split()))
    Lock_sum.extend(ADD)
for k in range(1,N_M[0]+1):
    Lock_sum.count(k)
    if k == N_M[1]:
        print(k)

Submission status: Wrong Answer

Solution code:
import math

if __name__ == "__main__":
    _, M = map(int, input().split())

    A, B = map(int, input().split())

    for i in range(1, M):
        a, b = map(int, input().split())
        A = max(A, a)
        B = min(B, b)

    print(B - A + 1)

Submission status: Wrong Answer

Solution code:
#
import sys
import math
import numpy as np
import itertools


# いくつか入力
n, m = (int(i) for i in input().split())  


# n行複数列の数をリストに
lr = [[int(i) for i in input().split()] for i in range(m)] 

l=1
r=n
for i in range(m):
    l=max(l,lr[i][0])
    r=min(r,lr[i][1])

print(l,r)

a=r-l+1
if a < 0:
    a=0
print(a)

Submission status: Wrong Answer

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

card_list = [1] * n

minr = 10**9
maxl = 0

for i in range(m):
    l, r  = map(int, input().split())
    maxl = max(maxl, l)
    minr = min(minr, r)
print(minr - maxl + 1)

Submission status: Wrong Answer

Solution code:
n,m = list(map(int,input().split()))
l=[]
r=[]
for j in range(m):
	a,b = list(map(int,input().split()))
	l.append(a)
	r.append(b)
low = max(l)
high = min(r)
count = min(high - low + 1, n)
print(count)

Submission status: Wrong Answer

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

gates = []
for i in range(M):
    gates.append(tuple(map(int, input().split())))


s = set(range(gates[0][0], gates[0][-1] +1))

for i in range(1, M):
    bef_tail = gates[i-1][1] 
    cur_head = gates[i][0]

    if bef_tail - cur_head >= 0:
        tmp_s = range(cur_head, bef_tail+1)
        s = s.intersection(tmp_s)        

print(len(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M = map(int,input().split())
pool = []
for i in range(M):
    i_1,i_2 = map(int,input().split())
    pool.append([i_1,i_2])
min_val = max([int(pool[i][0]) for i in range(M)])
max_val = min([int(pool[i][1]) for i in range(M)])
print(max_val-min_val+1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
l=[[int(i) for i in input().split()] for j in range(m)]
lr=[[int(i) for i in range(l[j][0],l[j][1]+1)] for j in range(m)]
x=0
for i in range(n):
  a=0
  for j in range(m):
    a+=lr[j].count(i)
  if a==m:
    x+=1
print(x)

Submission status: Wrong Answer

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

for i in range(M):
  l, r = map(int, input().split())
  if i==0:
    myminlist = list(range(l,r+1))  
  if i== M-1:
    mymaxlist = list(range(l,r+1))
    
print(len(set(myminlist) & set(mymaxlist)))

Submission status: Wrong Answer

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

left = 1
right = N
for i in range(M):
    if left<List[i][0]:
        left = List[i][0]
    if List[i][1]<right:
        right = List[i][1]
        
print(right-left+1)

Submission status: Wrong Answer

Solution code:

N,M=map(int,input().split())#ID,ゲート


LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=0
Rmax=10000
for j in LR:

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

    if Lmax<L:
        Lmax=L
    if Rmax>R:
        Rmax=R
result=0

for i in numbers:

    if i>=Lmax:

        if i<=Rmax:
            result+=1



print(result)

Submission status: Wrong Answer

Solution code:

N,M=map(int,input().split())#ID,ゲート

result=0
LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




Lmax=0
Rmax=0
for j in LR:

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

    if Lmax<L:
        Lmax=L
    if Rmax<R:
        Rmax=R
for i in numbers:
    if i>Lmax:
        if i<Rmax:
            result+=1


print(result)

Submission status: Wrong Answer

Solution code:
input_line = input()
N,M = [int(s) for s in input_line.split(' ') if s]
Ls = []
Rs = []
for _ in range(M):
    input_line = input()
    L,R = [int(s) for s in input_line.split(' ')if s]
    Ls.append(L)
    Rs.append(R)

print(min(Rs)-max(Ls)+1)

Submission status: Wrong Answer

Solution code:

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

result=0
LR=[]
for i in range(M):
        LR.append(input().split())


numbers=[]
for i in range(N+1):
    numbers.append(i)




for j in LR:

    L=int(j[0])
    R=int(j[1])
    for i in numbers:
        if i<L or R<i:
            numbers.remove(i)


print(len(numbers))

Submission status: Wrong Answer

Solution code:

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

result=0
LR=[]
for i in range(M):
        LR.append(input().split())


for i in range(N+1):#0からNまで
    counter=0
    flag=False
    for j in LR:

        L=int(j[0])
        R=int(j[1])
        if i<L or R<i:
            flag=True
            break
        if L<=i and i<=R:
            counter+=1
    if flag:
        break
    if counter==M:
        result+=1
print(result)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-

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

L = 0
R = N

for i in xrange(M):
	li,ri = map(int,raw_input().split())
	L = max(L,li)
	R = min(R,ri)

print max(L,R+1)

Submission status: Wrong Answer

Solution code:
# -*- Coding: utf-8 -*-

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

L = 0
R = N

for i in xrange(M):
	li,ri = map(int,raw_input().split())
	L = max(L,li)
	R = min(R,ri)

print R-L+1

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
count=0
listl=[]
listr=[]
for i in range(m):
  l,r=map(int,input().split())
  listl.append(l)
  listr.append(r)
maxl=max(listl)
minr=min(listr)
print(minr-maxl+1)

Submission status: Wrong Answer

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

lmax = max(gates, key=lambda x: x[0])[0]
rmin = min(gates, key=lambda x: x[1])[1]

print(rmin-lmax+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin

N, M = [int(x) for x in stdin.readline().rstrip().split()]
G = [[int(x) for x in stdin.readline().rstrip().split()] for _ in range(M)]
L = [G[k][0] for k in range(M)]
R = [G[k][1] for k in range(M)]
L.sort(reverse=True)
R.sort()
print(R[0] - L[0] + 1)

Submission status: Wrong Answer

Solution code:
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            lmax = o[0]
            rmin = o[1]
        else:
            lmax = max(lmax, o[0])
            rmin = min(rmin, o[1])

    print(rmin-lmax+1 if rmin > lmax else 0)


if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    (n, m) = list(map(int, input().split(" ")))
    
    for i in range(m):
        o = list(map(int, input().split(" ")))
        if i == 0:
            lmax = o[0]
            rmin = o[1]
        else:
            lmax = max(lmax, o[0])
            rmin = min(rmin, o[1])

    print(rmin-lmax+1)


if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def is_MM(s):
    num = int(s)
    return 0 < num <= 12


def solve():
    N, M = il()
    L_max = 0
    R_min = float("inf")
    for m in range(M):
        lr = il()
        L_max = max(L_max, lr[0])
        R_min = min(R_min, lr[1])
    return R_min - L_max + 1 if R_min < L_max else 0


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
from functools import reduce
from itertools import combinations

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def is_MM(s):
    num = int(s)
    return 0 < num <= 12


def solve():
    N, M = il()
    L_max = 0
    R_min = float("inf")
    for m in range(M):
        lr = il()
        L_max = max(L_max, lr[0])
        R_min = min(R_min, lr[1])
    return R_min - L_max + 1


if __name__ == "__main__":
    print(solve())

Submission status: Wrong Answer

Solution code:
import sys


scan = sys.stdin.readline


def main():
  n, m = map(int, scan().rstrip().split())
  l = 0
  r = n
  
  for _ in range(m):
    l_i, r_i = map(int, scan().rstrip().split())
    l = max(l, l_i)
    r = min(r, r_i)
    
  cards = r - l + 1 if r > l else 0
  
  print(cards)
  

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m_=map(int,input().split())
m=0
M=9**9
for i in range(m_):
    l,r= map(int, input().split())
    m=max(m,l)
    M=min(M,r)
print(M-m+1if M>m else 0)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    l = []
    r = []
    for _ in range(m):
        a, b = list(map(int, input().split()))
        l.append(a)
        r.append(b)

    print(min(r) - max(l) + 1)

Submission status: Wrong Answer

Solution code:
import sys

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

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

    card = [1, num_card]

    for gate in input:
        card[0] = max(card[0], gate[0])
        card[1] = min(card[1], gate[1])

    print(card[1] - card[0] + 1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

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

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

    under_limit = [x[0] for x in input]
    over_limit = [x[1] for x in input]

    print(min(over_limit) - max(under_limit) + 1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
N, M = [int(_) for _ in input().split()]
LR = [[int(_) for _ in input().split()] for _ in range(M)]
lmax = 1
rmin = N
for l, r in LR:
    lmax = max(lmax, l)
    rmin = min(rmin, r)
print(rmin - lmax + 1)

Submission status: Wrong Answer

Solution code:
n, m = [int(v) for v in input().split()]
#print(n, m)
gates = [[int(v) for v in input().split()] for i in range(m)]
#print(gates)
left = max(gates, key=lambda x: x[0])[0]
right = min(gates, key=lambda x: x[1])[1]

print(right - left + 1)

Submission status: Wrong Answer

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

l = []
r = []

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

print(min(r) - max(l) + 1)

Submission status: Wrong Answer

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

lis = [0] * 10 ** 6

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

print(lis.count(max(lis)))

Submission status: Wrong Answer

Solution code:
minlist=[]
maxlist=[]
 
n,m=map(int,input().split())
for i in range(m):
  l,r=list(map(int,input().split()))
  minlist.append(l)
  if r>0:
    maxlist.append(r)
ans=0
dif=max(minlist)-min(maxlist)
if(dif>=0):
  ans=dif+1
else:
  ans=0
print(ans)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
list1=[list(map(int,input().split())) for i in range(M)]
start=[]
end=[]
for i in range(M):
    start.append(list1[i][0])
    end.append(list1[i][1])
stmax=max(start)
#print(stmax)
enmax=min(end)
#print(enmax)
print(enmax-stmax+1)

Submission status: Wrong Answer

Solution code:
N,M=map(int,input().split())
list1=[list(map(int,input().split())) for i in range(M)]
start=[]
end=[]
for i in range(M):
    start.append(list1[i][0])
    end.append(list1[i][1])
stmax=max(start)
print(stmax)
enmax=min(end)
print(enmax)
print(enmax-stmax+1)

Submission status: Wrong Answer

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

def prison(n,m,id1,id2):
    if min(id2) != max(id1):
        print(min(id2)+1-max(id1))
    else:
        print(min(id2))


def main():
    n,m = [int(i) for i in input().split()] 
    l = []
    r = []
    for _ in range(m):
        l1, r1 = [int(i) for i in input().split()] 
        l.append(l1)
        r.append(r1)
    prison(n,m,l,r)
    
# main関数呼び出し
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def prison(n,m,id1,id2):
    print(min(id2)+1-max(id1))


def main():
    n,m = [int(i) for i in input().split()] 
    l = []
    r = []
    for _ in range(m):
        l1, r1 = [int(i) for i in input().split()] 
        l.append(l1)
        r.append(r1)
    prison(n,m,l,r)
    
# main関数呼び出し
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

print(min(r)-max(l)+1)

Submission status: Wrong Answer

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

max_l = 0
min_r = float('inf')

for l,r in LR:
    max_l = max(max_l,l)
    min_r = min(min_r,r)

print(min_r - max_l + 1)

Submission status: Wrong Answer

Solution code:
N,M = [int(i) for i in input().split()]
L = []
R = []
for i in range(M):
    L1,R1 = [int(i) for i in input().split()]
    L.append(L1)
    R.append(R1)
result = min(R) - max(L)  +1
print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, m = map(int, input().split())
v = np.array([0]*(n+1))
for _ in range(m):
    a,b = map(int, input().split())
    v[a:b+1] = v[a:b+1] + 1

print(len(v[v == max(v)]))

Submission status: Wrong Answer

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

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

id_l,id_r = max(L),min(R)
width = id_r - id_l + 1 if max(L)>=min(R) else 0

print(width)

Submission status: Wrong Answer

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

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

gate_l,gate_r = max(L),min(R)
width = gate_l - gate_r + 1 if max(L)>=min(R) else 0

print(width)

Submission status: Wrong Answer

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

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

gate_l = max(L)
gate_r = min(R)
width = gate_l - gate_r + 1
sum = N*width

# for i in range(M):
#     if L[i]<=gate_l:
#         sum -= 0
#     elif gate_l<L[i] and L[i]<=gate_r:
#         sum -= abs(gate_l,L[i])
#     else:
#         sum -= width
#         break
# 
#     if gate_r<=R[i]:
#         sum -= 0
#     elif gate_r<R[i] and R[i]<=gate_r:
#         sum -= abs(gate_r,R[i])
#     else:
#         sum -= width
#         break

print(width)

Submission status: Wrong Answer

Solution code:

n, m = map(int, input().split())
card = [0 for _ in range(n+2)]

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

#print(card)

for i in range(n+1):
    card[i+1] += card[i]

#print(card)
print(card.count(3))

Submission status: Wrong Answer

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())
mL = max(L)
mR = min(R)
ans = 0
for i in range(N):
    if ((mL <=i) and (i<=mR)):
        ans += 1
print(ans)

Submission status: Wrong Answer

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

print(min(R) - max(L) + 1)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
mis,mas=[],[]
for _ in range(m):
  tmp=list(map(int,input().split()))
  mis.append(tmp[0])
  mas.append(tmp[1])
ans=max(mas)-min(mis)
print(ans if ans>0 else 0)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
mi,ma=0,0
for _ in range(m-1):
  mi=list(map(int,input().split()))[0]
ma=list(map(int,input().split()))[0]
print(ma-mi+1 if ma-mi+1>0 else 0)

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
mi,ma=0,0
for _ in range(m-1):
  mi=list(map(int,input().split()))[0]
ma=list(map(int,input().split()))[0]
print(ma-mi if ma-mi>0 else 0)

Submission status: Wrong Answer

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

#print(n, m)
#print(table)
#print(light)

maxtable1 = sorted(table, key = lambda x: x[0])
maxtable2 = sorted(table, key = lambda x: x[1])

print(maxtable2[0][1] - maxtable1[m-1][0] + 1)

Submission status: Wrong Answer

Solution code:
#ABC 127 C Prison
N,M= map(int,input().split())
MIN=None
MAX=None
for i in range(M):
    L,R= map(int,input().split())
    if MIN is None:
        MIN=L
        MAX=R
    if MIN <L:
        MIN=L
    if MAX > R:
        MAX =R
print(MAX-MIN+1)

Submission status: Wrong Answer

Solution code:
#ABC 127 C Prison
N,M= map(int,input().split())
MIN=None
MAX=None
for i in range(M):
    L,R= map(int,input().split())
    if MIN is None:
        MIN=L
        MAX=R
    elif MIN <L:
        MIN=L
    elif MAX > R:
        MAX =R
    print()
print(MAX-MIN+1)

Submission status: Wrong Answer

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

L = 1
R = N
for LR in LR_list:
    if LR[0] > L:
        L = LR[0]
    if LR[1] < R:
        R = LR[1]

print (R - L + 1)

Submission status: Wrong Answer

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

agg = None
card_rooms = {}
for m in range(M):
    L,R=map(int,input().split())
    for card in range(L,R+1):
        if card_rooms.get(card) is None:
            card_rooms[card] = set()
        card_rooms[card].add(L)
cnt = 0
for card, rooms in card_rooms.items():
    if len(rooms) == M:
        cnt += 1

#print(card_rooms)
print(cnt)

Submission status: Wrong Answer

Solution code:
N ,M = map(int , input().split())
max_L = []
min_R = []
gate_number = [i for i in range(1, M+1)]
for j in range(M):
    L , M = map(int,input().split())
    max_L.append(L)
    min_R.append(M)
print(len([s for s in range(max(max_L) , min(min_R))]))

Submission status: Wrong Answer

Solution code:
N ,M = map(int , input().split())
max_L = []
min_R = []
gate_number = [i for i in range(1, M+1)]
for j in range(M):
    L , M = map(int,input().split())
    max_L.append(L)
    min_R.append(M)
print(len([i for i in range(max(max_L) , min(min_R))]))

Submission status: Wrong Answer

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

print(count)

Submission status: Wrong Answer

Solution code:
N, M = [int(nm) for nm in input().split()]
L, R = [int(lr) for lr in input().split()]
LR = [L, R]
for m in range(M-1):
  L_2, R_2 = [int(lr) for lr in input().split()]
  if (L_2 <= LR[0]) and (LR[1] <= R_2):
    continue
  elif (L_2 <= LR[0]) and (R_2 < LR[1]):
    LR = [LR[0], R_2]
  elif (LR[0] < L_2) and (LR[1] <= R_2):
    LR = [L_2, LR[1]]
  else:#(LR[0] < L_2) and (R_2 < LR[1]):
    LR = [L_2, R_2]
card = LR[1] - LR[0] + 1
print(card)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
gate_number = [i for i in range(1, M+1)]
all_IDs = []

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

# all_IDsの中から重複した要素を抽出
unique_ID = [x for x in set(all_IDs) if all_IDs.count(x) > 1]
print(len(unique_ID))

Submission status: Wrong Answer

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

L_max = max(L)
R_min = min(R)

count = 0
for i in range(N):
    if i >= L_max and i <= R_min:
        count += 1
print(count)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m=map(int,input().split())
L=[]
R=[]
for _ in range(m):
    a,b=map(int,input().split())
    L.append(a)
    R.append(b)
print(min(R)-max(L)+1,0)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m=map(int,input().split())
L=[]
R=[]
for _ in range(m):
  a,b=map(int,input().split())
  L.append(a)
  R.append(b)
print(min(R)-max(L)+1)

Submission status: Wrong Answer

Solution code:
N, M = map(int, input().split())
l = 0
r = N + 1
for _ in range(M):
  ll, rr = map(int, input().split())
  l = max(l, ll)
  r = min(r, rr)
print(max(0, r - l))