TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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?

Submission attempts (in order):

lst_1 = input().split()

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

lst_A = []

count = 0

ans_min = 1
ans_max = N

for i in range(M):
    lst_A.append(input().split())

print(lst_A)

for m in range(M):

    com_min = int(lst_A[m][0])

    if com_min > ans_min:
        ans_min = com_min

    com_max = int(lst_A[m][1])

    if com_max < ans_max:
        ans_max = com_max

ans = ans_max - ans_min + 1

print(ans)


lst_1 = input().split()

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

lst_A = []

ans_min = 1
ans_max = N

for i in range(M):
    lst_A.append(input().split())

for m in range(0, M, 1):

    com_min = int(lst_A[m][0])

    if com_min > ans_min:
        ans_min = com_min

    com_max = int(lst_A[m][1])

    if com_max < ans_max:
        ans_max = com_max

ans = ans_max - ans_min + 1

if ans < 1:
    ans = 0

print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, m = map(int, input().split())
l, r = map(int, input().split())
tmp = list(map(int, range(l-1, r)))
for i in range(m-1):
    l, r = map(int, input().split())
    for j in range(l-1, r):
        if j in tmp:
            tmp.remove(j)

print(len(tmp))

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)

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

Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int, input().split())
l, r = map(int, input().split())
for i in range(M-1):
  L, R = map(int, input().split())
  if (L >= l):
    l = L
  if (R =< r):
    r = R
print(r - l + 1)

N, M = map(int, input().split())
l, r = map(int, input().split())
cnt = 0
num = 0
if (l == r):
  cnt += 1
  num = l
for i in range(M-1):
  L, R = map(int, input().split())
  if (cnt == 1 and L == R and num == L):
    num = L
  elif (cnt == 1 and L == R and num != L):
    cnt += 1
    print(0)
    break
  elif (cnt == 0 and L == R):
    cnt += 1
    num = L
  elif ((cnt == 0 or cnt == 1) and L != R):
    if (L >= l):
      l = L
    if (R <= r):
      r = R
      
if (l > r and (cnt == 0 or cnt == 1)):
  print(0)
elif(l <= r and (cnt == 0 or cnt == 1)):
  if (num != 0 and cnt == 1):
    if (num >= l and num <= r):
      print(1)
    else:
      print(0)
  elif(cnt == 0 or cnt == 1):
    print(r - l + 1)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
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(max(0,min(r)-max(l)))

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(max(0,min(r)-max(l)+1))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,m=(int(i) for i in input().split())
a=0
b=0
for i in range(m):
  l,r=(int(i) for i in input().split())
  if l>a,r<b:
    a=l
    b=r
  elif l>a and r>=b:
    a=l
  elif r<b and l<=a:
    b=r
if n>a and n<b:
  print(n-a)
elif n>a and n>=b:
  print(b-a)
else:
  print(0)

n,m=(int(i) for i in input().split())
a=0
b=0
for i in range(m):
  l,r=(int(j) for j in input().split())
  if l>a and r<b:
    a=l
    b=r
  elif l>a and r>=b:
    a=l
  elif r<b and l<=a:
    b=r
if n>a and n<b:
  print(n-a)
elif n>a and n>=b:
  print(b-a)
else:
  print(0)


n,m=(int(i) for i in input().split())
a=0
b=0
for i in range(m):
  l,r=(int(j) for j in input().split())
  if l>a and r<b:
    a=l
    b=r
  elif l>a and r>=b:
    a=l
  elif r<b and l<=a:
    b=r
if b>=a:
	if n>a and n<b:
  		print(n-a+1)
	elif n>a and n>=b:
  		print(b-a+1)
	else:
  		print(0)
else:
  print(0)


n,m=(int(i) for i in input().split())
a=0
b=0
for i in range(m):
  l,r=(int(j) for j in input().split())
  if l>a and r<b:
    a=l
    b=r
  elif l>a and r>=b:
    a=l
  elif r<b and l<=a:
    b=r
if b>=a:
	if n>a and n<b:
  		print(n-a)
	elif n>a and n>=b:
  		print(b-a)
	else:
  		print(0)
else:
  print(0)

n,m=(int(i) for i in input().split())
a=0
b=0
for i in range(m):
  l,r=(int(g) for g in input().split())
  if l>a,r<b:
    a=l
    b=r
  elif l>a and r>=b:
    a=l
  elif r<b and l<=a:
    b=r
if n>a and n<b:
  print(n-a)
elif n>a and n>=b:
  print(b-a)
else:
  print(0)


n,m=(int(i) for i in input().split())
a=0
b=10**6
for i in range(m):
  l,r=(int(j) for j in input().split())
  if l>a and r<b:
    a=l
    b=r
  elif l>a and r>=b:
    a=l
  elif r<b and l<=a:
    b=r
if b>=a:
	if n>=a and n<b:
  		print(n-a+1)
	elif n>=a and n>=b:
  		print(b-a+1)
	elif n<a:
  		print(0)
else:
  	print(0)


Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int, input().split())

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

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

N, M = map(int, input().split())
 
l_list = []
r_list = []
for i in range(M):
  l, r = map(int, input().split())
  l_list.append(l)
  r_list.append(r)
  
l = max(l_list)
r = min(r_list)
 
if r < l:
  print(0)
else:
  print(r-l+1)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, M = (int(i) for i in input().split())

LR = [list(map(int, input().split())) for _ in range(M)]
L = [i[0] for i in LR]
R = [i[1] for i in LR]

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

N, M = (int(i) for i in input().split())

LR = [list(map(int, input().split())) for _ in range(M)]
L = [i[0] for i in LR]
R = [i[1] for i in LR]

# print(L)
# print(R)
result =  min(R) - max(L) + 1
if (result < 0):
    result = 0
print(result)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int,input().split())

if M == 1:
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    print(len(l))
else:
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    l_tmp = copy.deepcopy(l)

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

    l_set = list(set(l) & set(l_tmp))
    l_tmp = copy.deepcopy(l)
    for i in range(M-2):
        L, R = map(int,input().split())
        l = [k+L for k in range(R-L+1)]

        l_set = list(set(l) & set(l_set))
        l_tmp = copy.deepcopy(l)

    print(len(l_set))

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

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

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

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):

n,m = map(int, input().split())
L = [0]*m
R = [0]*m

ans = 0

infi = 1000000000000000

l_max =0
r_min =infi

for i in range(m):
    L[i],R[i] = map(int, input().split())
    if(l_max<L[i]):
        l_max = L[i]
        continue
    if(r_min>R[i]):
        r_min = R[i]
if(l_max<r_min):
    ans = 0
else:
    ans = (r_min - l_max)+1
        
print(ans)


n,m = map(int, input().split())
L = [0]*m
R = [0]*m

ans = 0

infi = 1000000000000000

l_max =0
r_min =infi

for i in range(m):
    L[i],R[i] = map(int, input().split())
    if(l_max<L[i]):
        l_max = L[i]
    if(r_min>R[i]):
        r_min = R[i]

ans = (r_min - l_max)+1
if(ans<=0):
    ans =0
        
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
ss=input().split(" ")
N=int(ss[0])
M=int(ss[1])
x=0
y=N
for i in range(M):
  tt=input().split(" ")
  if int(tt[0])>x:
    x=int(tt[0])
  if int(tt[1])<y:
    y=int(tt[1])
print(int(y-x+1)
  

ss=input().split(" ")
N=int(ss[0])
M=int(ss[1])
x=0
y=N
for i in range(M):
  tt=input().split(" ")
  if int(tt[0])>x:
    x=int(tt[0])
  if int(tt[1])<y:
    y=int(tt[1])
print(int(y-x+1)
  

ss=input().split(" ")
N=int(ss[0])
M=int(ss[1])
x=1
y=N
for i in range(M):
  tt=input().split(" ")
  if int(tt[0])>x:
    x=int(tt[0])
  if int(tt[1])<y:
    y=int(tt[1])
last=int(y-x+1)
if last>0:
  print(last)
else:
  print(0)

  

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n, m = map(int, input().split())
cnt = 0
id = []
for _ in range(m):
        l= list(map(int, input().split()))
        if len(id) == 0:
                id = l
        else:
                if id[0] < l[0]:
                        id[0] = l[0]
                elif id[1] > l[1]:
                        id[1] = l[1]
print(id)
if id[1] < id[0]:
        cnt = 0
else:
        cnt = id[1]-id[0]+1
print(cnt)


n, m = map(int, input().split())
cnt = 0
id = []
for _ in range(m):
        l= list(map(int, input().split()))
        if len(id) == 0:
                id = l
        else:
                if id[0] < l[0]:
                        id[0] = l[0]
                elif id[1] > l[1]:
                        id[1] = l[1]
if id[1] < id[0]:
        cnt = 0
else:
        cnt = id[1]-id[0]+1
print(cnt)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,m=map(int,input().split())
lr=[list(map(int,input().split())) for i in range(m)]
l=[0]*n
for l,r in lr:
  for t in range(l,r+1):
    l[t-1]+=1
ans=0
for ll in l:
  if ll==m:
    ans+==1
print(ans)

n,m=map(int,input().split())
l,r=map(int,input().split())
for i in range(m-1):
  x,y=map(int,input().split())
  l=max(l,x)
  r=min(r,y)
print(r-l+1 if l<=r else(0))


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n,m=map(int,input().split())
maxl=1
minr=n
for i in range(m):
  l,r=map(int,input().split())
  maxl=max(maxl,l)
  minr=min(minr,r)

print(maxl-minr+1)
  

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

print(max(minr-maxl+1,0))


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,m = map(int, input().split())
low=[]
high=[]

for i in range(m):
    b,c = map(int, input().split())
    low.append(b)
    high.append(c)
min(high)-max(low)+1

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

for i in range(m):
    b,c = map(int, input().split())
    low.append(b)
    high.append(c)
    
print(max(min(high)-max(low)+1, 0))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (max(l)  - min(r)  +1) 
if answer > 0:
    print(answer)
else:
    print("0")

n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (max(r)  - min(l)  +1) 
if answer > 0:
    print(answer)
else:
    print("0")

n,m=map(int, input().split())
lr = [map(int, input().split()) for _ in range(m)]
l, r = [list(i) for i in zip(*lr)]
answer = (min(r) - max(l)   +1) 
if answer > 0:
    print(answer)
else:
    print("0")

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N,M = map(int,input().split())
range_l = 1
range_r = N
for i in range(M):
  L,R = map(int,input().split())
  range_l = max(range_l, L)
  range_r = min(range_r, R)
if range_r - range_l < 0:
  print(0)
else:
  print(range_l - range_r + 1)

N,M = map(int,input().split())
L,R = [],[]
for i in range(M):
  l,r = map(int,input().split())
  L.append(l)
  R.append(r)
l = max(L)
r = min(R)
if l > r:
  print(0)
else:
  print(r - l + 1)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
ans=0
for i in range(1,N+1):
    if all([i in range(l[k][0],l[k][1]+1) for k in range(m)]):
        ans+=1
print(ans)

n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
print(l)
a=0
z=10**5
for i in range(m):
    a=max(a,l[i][0])
    z=min(z,l[i][1])
print(z-a+1)

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

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,m=map(int,input().split())
maxl=1
minr=n
while m:
  l,r=map(int,input().split())
  maxl=max(maxl,l)
  minr=min(minr,r)
  m-=1
print(max(0,maxl-minr+1))

n,m=map(int,input().split())
maxl=1
minr=N
while m:
  l,r=map(int,input().split())
  maxl=max(maxl,l)
  minr=min(minr,r)
  m-=1
print(max(0,maxl-minr+1))


    n,m=map(int,input().split())
    maxl=1
    minr=n
    while m:
      l,r=map(int,input().split())
      maxl=max(maxl,l)
      minr=min(minr,r)
      m-=1
    print(max(0,minr-maxl+1))

n,m=map(int,input().split())
maxl=1
minr=n
while m:
  l,r=map(int,input().split())
  maxl=max(maxl,l)
  minr=min(minr,r)
  m-=1
print(max(0,minr-maxl+1))

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
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()


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


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
n,m=map(int,input().split())
lr = [list(map(int,input().split())) for _ in range(m)]
s = {i:0 for i in range(1,n+1)}
for i in range(m):
    for j in range(lr[i][0],lr[i][1]+1):
        s[j] += 1
for k,v in s.items():
    if v == m:
        print(k)

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(max(min(r) - max(l) + 1, 0))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int, input().split())
D = []
for i in range(M):
    D.append(list(map(int, input().split())))

L = 1
R = N
for d in D:
    if L<=d[0]<=R or L<=d[1]<=R:
        L = max(L, d[0])
        R = min(R, d[1])
    else:
        print(0)
        break
    print("[{}, {}]".format(L, R))
else:
    print(R-L+1)

N, M = map(int, input().split())
L, R = 1, N
for _ in range(M):
    l, r = map(int, input().split())
    L = max(l, L)
    R = min(r, R)
if R<L:
    print(0)
else:
    print(R-L+1)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, m = map(int, input().split())
l, r = map(int, input().split())
A = [l, r]
for i in range(m-1):
  l, r = map(int, input().split())
  if A[0] < l:
    A[0] = l
  if A[1] > r:
    A[1] = r
print(r-l+1)

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

n, m = map(int, input().split())
l, r = map(int, input().split())
L = [l]
R = [r]
for i in range(m-1):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)

L.sort()
R.sort()

n =  R[0] -L[m-1] +1
if n > 0:
    print(n)
else:
    print(0)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,m=map(int,input().split())
cards=[i for i in range(1,n+1)]
for i in range(m):
  a,b=map(int,input().split())
  l=[i for i in range(a,b+1)]
  cards=list(set(l)&set(cards))
  print(cards)
print(len(cards))

n,m=map(int,input().split())
cards=[i for i in range(1,n+1)]
for i in range(m):
  a,b=map(int,input().split())
  l=[i for i in range(a,b+1)]
  cards=list(set(l)&set(cards))
print(cards)

import sys
input=sys.stdin.readline

n,m=map(int,input().split())
leftgate=[]
rightgate=[]
for i in range(m):
  l,r=map(int,input().split())
  leftgate.append(l)
  rightgate.append(r)
if (min(rightgate)-max(leftgate))>-1:
  print(min(rightgate)-max(leftgate)+1)
else:
  print(0)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
 N, M= (int(i) for i in input().split())

 ans = set(range(1,N+1))

 for i in range(M):
     L_tmp, R_tmp = map(int, input().split())
     ans = ans & set(range(L_tmp,R_tmp+1))

 print(len(ans))


N, M= (int(i) for i in input().split())

L_max = 1
R_min = N

for i in range(M):
    L, R = map(int, input().split())
    L_max = max(L_max,L)
    R_min = min(R_min,R)

ans = set(range(L_max,R_min+1))

print(len(ans))


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
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)

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)

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=min(mas)-max(mis)+1
print(ans if ans>0 else 0)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np
N, M = map(int, input().split())
X = np.ones((N), dtype=np.int)
for i in range(M):
    L, R = map(int, input().split())
    if L > 1 : X[:L]=0
    if R < 100000 : X[R+1:]=0
print(np.sum(X, dtype=np.int))

import numpy as np
N, M = map(int, input().split())
LL, RR = map(int, input().split())
for i in range(M-1):
    L, R = map(int, input().split())
    LL = max(L, LL)
    RR = min(R, RR)
print(max(RR-LL+1,0))

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
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)

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

l_max = 0
r_min = 10**6
for i in range(m):
    l, r = map(int, input().split())
    l_max = max(l_max, l)
    r_min = min(r_min, r)
    
if l_max <= r_min:
    print(r_min - l_max + 1)
else:
    print(0)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
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)

n,m=map(int, input().split()) 
s=[list(map(int, input().split())) for i in range(m)]
R=0
L=0
s=sorted(s)
L=s[m-1][0]
s=sorted(s, key=lambda x:x[1])
R=s[0][1]
if R-L>=0:
    print(R-L+1)
else:
    print(0)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
# -*- coding: utf-8 -*-
def main():
    N,M= map(int,input().split())
    List=[list(map(int,input().split())) for i in range(M)]
    print(List)#[[1, 3], [2, 4]]
    ListN = list()
    List3 = list()
    for k in range(1,N+1):
        ListN.append(k)
    for i in range(M):
        List2 = list()
        x = List[i][0]
        y = List[i][1]
        for j in range(x,y):
            List2.append(j)
        for Li in List2:
            for Ln in ListN:
                if Li == Ln:
                    List3.append(Li)
    List3 = list(set(List2))
    print(len(List3))

if __name__ == '__main__':
    main()

# -*- coding: utf-8 -*-
def main():
    N,M= map(int,input().split())
    List=[list(map(int,input().split())) for i in range(M)]
    ListN = list()
    List3 = list()
    for k in range(1,N+1):
        ListN.append(k)
    for i in range(M):
        List2 = list()
        x = List[i][0]
        y = List[i][1]
        for j in range(x,y+1):
            List2.append(j)
        for Li in List2:
            for Ln in ListN:
                if Li == Ln:
                    List2.append(Ln)
    List3 = list(set(List2))
    print(len(List3))

if __name__ == '__main__':
    main()

# -*- coding: utf-8 -*-
def main():
    N,M = map(int,input().split())
    L = []
    R = []
    for _ in range(M):
        l,r = map(int,input().split())
        L.append(l)
        R.append(r)
    L.sort(reverse=True)
    R.sort()
    lmax = L[0]
    rmin = R[0]
    print(max(0,rmin-lmax+1))



if __name__ == '__main__':
    main()

Verdicts: Wrong Answer

Time Limit Exceeded

Accepted
Problem: 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?

Submission attempts (in order):
#ABC-127-C
N, M = map(int, input().split())
L_list  = []
R_list = []
for _ in range(M):
    Li, Ri = map(int, input().split())
    L_list.append(Li)
    R_list.append(Ri)

max_L = max(L_list)
min_R = min(R_list)

if max_L < min_R:
    print(0)
else:
    print(min_R-max_L+1)


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

memo = [0]*(N+1)

for _ in range(M):
    L, R = map(int, input().split())
    memo[L-1] += 1
    memo[R] -= 1

memo_sum = memo[0]
for i in range(1, N):
    memo_sum += memo[i]
    memo[i] = memo_sum

ans = 0
for a in memo:
    if a == M:
        ans += 1

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
#import numpy as np
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with

#A = int(input())
N,M= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())
left=1
right=N
for m in range(M):
    l,r = map(int,input().split())
    if left<=l and l<=right:
        left=l
    if left<=r and r<=right:
        right=r

    if right<l or r<left:
        p=0

if not p:
    print(p)
    exit()
print(right-left+1)


#import numpy as np
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with

#A = int(input())
N,M= map(int,input().split())
#A = list(map(int,input().split()))
#B = list(map(int,input().split()))
#S= str(input())
p=1
left=1
right=N
for m in range(M):
    l,r = map(int,input().split())
    if left<=l and l<=right:
        left=l
    if left<=r and r<=right:
        right=r

    if right<l or r<left:
        p=0

if not p:
    print(p)
    exit()
print(right-left+1)


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N,M = map(int,input().split())
L = []
for _ in range(M):
  k = list(map(int,input().split()))
  L.append(k)

sup = []
inf = []
  
for i in range(len(L)):
  sup.append(L[i][1])
  inf.append(L[i][0])
  
sup = min(sup)
inf = max(inf)

if sup - inf >= 0:
  print(0)
else:
  print(sup - inf + 1)

N,M = map(int,input().split())
L = []
for _ in range(M):
  k = list(map(int,input().split()))
  L.append(k)

sup = []
inf = []
  
for i in range(len(L)):
  sup.append(L[i][1])
  inf.append(L[i][0])
  
sup = min(sup)
inf = max(inf)

if sup - inf < 0:
  print(0)
else:
  print(sup - inf + 1)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n,m = map(int,input().split())
mn = 1
mx = n

for i in range(m):
    l,r = map(int,input().split())
    if l > mn:
        mn = l
    if r < mx:
        mx = r
        
if mx > mn:
    print(0)
else:
    print(mn - mx + 1)


n,m = map(int,input().split())
left = 1
right = n

for i in range(m):
    l,r = map(int,input().split())
    if l > left:
        left = l
    if r < right:
        right = r

if left > right:
    print(0)
else:
    print(right - left + 1)


Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    S = input().split()
    L.append(int(S[0]))
    R.append(int(S[1]))
if min(R) <= max(L):
    print(min(R)-max(L)+1)
else:
    print(0)

N, M = map(int, input().split())
L = []
R = []
for i in range(M):
    S = input().split()
    L.append(int(S[0]))
    R.append(int(S[1]))
if min(R) >= max(L):
    print(min(R)-max(L)+1)
else:
    print(0)

Verdicts: Wrong Answer

Accepted
Problem: 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?

Submission attempts (in order):
n, m = map(int, input().split())
l0, r0 = 1, n
for j in range(m):
    l1, r1 = map(int, inp)
    l0 = max(l0, l1)
    r0 = min(r0, r1)
print(max(0, r0-l0+1))


n, m = map(int, input().split())
l0, r0 = 1, n
for j in range(m):
    l1, r1 = map(int, input().split())
    l0 = max(l0, l1)
    r0 = min(r0, r1)
print(max(0, r0-l0+1))


Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
import numpy as np
N, M = [int(i) for i in input().split()]
L = [0]*M
R = [0]*M
for i in range(M):
    L[i], R[i] = [int(i) for i in input().split()]

Rmin = np.min(R)
Lmax = np.max(L)
if Rmin >= Lmax:
    num = np.min(R) - np.max(L) + 1
else
    num = 0
print(num)

import numpy as np
N, M = [int(i) for i in input().split()]
L = [0]*M
R = [0]*M
for i in range(M):
    L[i], R[i] = [int(i) for i in input().split()]

Rmin = np.min(R)
Lmax = np.max(L)
if Rmin >= Lmax:
    num = np.min(R) - np.max(L) + 1
else:
    num = 0
print(num)

Verdicts: Runtime Error

Accepted
Problem: 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?

Submission attempts (in order):
N, M = map(int, input().split())
Lmax = 0
Rmin = N
for i in range(M):
  L, R = map(int, input().split())
  Lmax = max(Lmax, L)
  Rmin = min(Rmin, R)
print(Rmin-Lmax)

N, M = map(int, input().split())
Lmax = 0
Rmin = N
for i in range(M):
  L, R = map(int, input().split())
  Lmax = max(Lmax, L)
  Rmin = min(Rmin, R)
print(max(0, Rmin-Lmax+1))


Verdicts: Wrong Answer

Accepted
Problem: There is a function f(x), which is initially a constant function f(x) = 0.  We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:    * An update query `1 a b`: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).   * An evaluation query `2`: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.  We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Submission attempts (in order):
Q = int(input())
queries = []
for _ in range(Q):
    queries.append(input())

from bisect import insort_left

ary, bry, c = [], [], 0
for query in queries:
    if query[0] == '2':
        absum = sum(abs(a - ary[c//2]) for a in ary)
        print(' '.join(map(str, (ary[c//2], absum + sum(bry)))))
    else:
        _, a, b = map(int, query.split())
        insort_left(ary, a)
        insort_left(bry, b)
        c += 1


Q = int(input())
INF = 10 ** 9

queries = []
for _ in range(Q):
    queries.append(input())

from bisect import insort_left
from heapq import heappush, heappop

absum, bsum, c = 0, 0, 0
# left, right = -INF, INF
lefts, rights = [INF], [INF]
for query in queries:
    if query[0] == '2':
        # absum = sum(abs(a - ary[(c-1)//2]) for a in ary)
        # absum = asum - (c//2 + 1) * ary[(c-1)//2]
        # print(' '.join(map(str, (ary[(c-1)//2], absum + bsum))))
        
        print(-lefts[0], absum + bsum)
    else:
        _, a, b = map(int, query.split())
        if c % 2 == 0:
            if -lefts[0] <= a <= rights[0]:
                heappush(lefts, -a)
                heappush(rights, a)
                absum += 0
            elif a < -lefts[0]:
                heappush(lefts, -a)
                heappush(rights, -lefts[0])
                absum += -lefts[0] - a
            else:
                heappush(rights, a)
                heappush(lefts, -rights[0])
                absum += a - rights[0]
        else:
            if a < -lefts[0]:
                absum += -lefts[0] - a
                heappop(lefts)
                heappush(lefts, -a)
            else:
                absum += a - rights[0]
                heappop(rights)
                heappush(rights, a)
        # left, right = ary[(c-1)//2], ary[c - (c-1)//2 - 1]        
        bsum += b
        c += 1


Verdicts: Wrong Answer

Accepted
Problem: There is a function f(x), which is initially a constant function f(x) = 0.  We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:    * An update query `1 a b`: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).   * An evaluation query `2`: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.  We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Submission attempts (in order):
import heapq

q = int(input())

minheap = [] # right
maxheap = [] # left
heapq.heapify(minheap)
heapq.heapify(maxheap)

s = 0
m = 0

for _ in range(0, q):
    token = input().split()
    if len(token) > 1:
        a = int(token[1])
        b = int(token[2])
        print(a, b)
        s += b
        heapq.heappush(minheap, a)
        heapq.heappush(maxheap, -a)
        if -maxheap[0] > minheap[0]:
            maxv = -heapq.heappop(maxheap)
            minv = heapq.heappop(minheap)
            m += abs(maxv - minv)
            heapq.heappush(minheap, maxv)
            heapq.heappush(maxheap, -minv)
    else:
        print('{} {}'.format(-maxheap[0], s + m))


import heapq

q = int(input())

minheap = [] # right
maxheap = [] # left
heapq.heapify(minheap)
heapq.heapify(maxheap)

s = 0
m = 0

for _ in range(0, q):
    token = input().split()
    if len(token) > 1:
        a = int(token[1])
        b = int(token[2])
        s += b
        heapq.heappush(minheap, a)
        heapq.heappush(maxheap, -a)
        if -maxheap[0] > minheap[0]:
            maxv = -heapq.heappop(maxheap)
            minv = heapq.heappop(minheap)
            m += abs(maxv - minv)
            heapq.heappush(minheap, maxv)
            heapq.heappush(maxheap, -minv)
    else:
        print('{} {}'.format(-maxheap[0], s + m))


Verdicts: Wrong Answer

Accepted
Problem: There is a function f(x), which is initially a constant function f(x) = 0.  We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:    * An update query `1 a b`: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).   * An evaluation query `2`: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.  We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Submission attempts (in order):
import bisect

Q=int(input())

b=0
a=[]
min=0
tmp=0
for i in range(Q):
    que=list(map(int,input().split()))
    if que[0]==1:
        b+=que[2]
        a.insert(  bisect.bisect_left(a,que[1]), que[1] )
        p= bisect.bisect_left(a,tmp)
        q= bisect.bisect_right(a,tmp)


        if p>len(a)-p:
            min+=abs(que[1]-tmp)-abs(a[p-1]-tmp) 
            tmp=a[p-1]
        elif q<len(a)-q:
            min+=abs(que[1]-tmp)-abs(a[q]-tmp) 
            tmp=a[q]
        else:
            min+=abs(que[1]-tmp)


    elif que[0]==2:
        print(tmp,min+b)

import bisect
from heapq import heappush as hpush 
from heapq import heappushpop as hpushpop 

Q=int(input())

que=list(map(int,input().split()))
b=que[2]
l,r=[-que[1]],[que[1]]
a=0
tmp=que[1]
j=1
for i in range(Q-1):
    que=list(map(int,input().split()))
    if que[0]==1:
        j+=1
        b+=que[2]
        q1=que[1]
        if j%2==0:
            if q1<-l[0]:
                hpushpop(l,-q1)
            else:
                hpushpop(r,q1)

        else:
            if q1<-l[0]:
                hpush(l,-q1)
                hpush(r,-l[0])
            else:
                hpush(r,q1)
                hpush(l,-r[0])
        

        if -l[0]!=r[0]: a+=abs(tmp-q1)
        else: a+=abs(tmp-q1)-abs(-l[0]-tmp)
        tmp=-l[0]

    elif que[0]==2:
        print(tmp,a+b)

Verdicts: Wrong Answer

Accepted
Problem: There is a function f(x), which is initially a constant function f(x) = 0.  We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:    * An update query `1 a b`: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).   * An evaluation query `2`: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.  We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Submission attempts (in order):


q=int(input())
qq,aa,bb=map(int,input().split())
x=aa
a,b=0,bb
for i in range(1,q):
  s=input()
  if s=="2":
    print(x,a+b)
    continue
  qq,aa,bb=map(int,s.split())
  a+=abs(x-aa);b+=bb



import statistics
q=int(input())
qq,aa,bb=map(int,input().split())
x=[aa]
a,b=0,bb
n=aa
for i in range(1,q):
  s=input()
  if s=="2":
    print(n,a+b)
    continue
  qq,aa,bb=map(int,s.split())
  x.append(aa)
  nn=n
  n=statistics.median(x)
  a+=abs(nn-n)+abs(aa-n)
  b+=bb

from heapq import heappop,heappush
q=int(input())
queries=[list(map(int,input().split()))for _ in range(q)]
l=[]
r=[]
ans=0
quecount=0
for query in queries:
  if query[0]==1:
    quecount+=1
    _,a,b=query
    ans+=b
    if quecount==1:
      mid=a
    elif quecount%2==1:
      if a<-l[0]:
        mid=-heappop(l)
        heappush(l,-a)
      elif r[0]<a:
        mid=heappop(r)
        heappush(r,a)
      else:
        mid=a
      ans+=abs(a-mid)
    else:
      ans+=abs(a-mid)
      heappush(l,-min(a,mid))
      heappush(r,max(a,mid))
  if query[0]==2:
    if quecount%2==1:
      ansind=mid
    else:
      ansind=-l[0]
    print(ansind,ans)

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a function f(x), which is initially a constant function f(x) = 0.  We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:    * An update query `1 a b`: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).   * An evaluation query `2`: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.  We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from bisect import bisect

def main():
    q = II()
    Q = []
    for _ in range(q):
        Q.append(LI())
    A = []
    bias = 0
    for q in Q:
        if q == [2]:
            idx = (len(A) - 1) // 2
            ans = A[idx], (sum(A[idx:]) - sum(A[:-idx]) + bias)
            print(*ans)
        else:
            _, a, b = q
            bias += b
            index = bisect(A, a)
            A.insert(index, a)
    return

main()

import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from heapq import heappush, heappop

def main():
    q = II()
    Q = []
    for _ in range(q):
        Q.append(LI())
    lows, highs = [], []
    slow, shigh = 0, 0
    bias = 0
    for q in Q:
        if q[0] == 2:
            odd = -lows[0] if len(highs) != len(lows) else 0
            ans = -lows[0], bias + shigh - slow + odd
            print(*ans)
        else:
            _, a, b = q
            bias += b
            if not lows:
                lows = [-a]
                slow = a
            else:
                if a <= -lows[0]:
                    heappush(lows, -a)
                    slow += a
                    if len(lows) > len(highs) + 1:
                        x = -heappop(lows)
                        heappush(highs, x)
                        slow -= x
                        shigh += x
                else:
                    heappush(highs, a)
                    shigh += a
                    if len(highs) > len(lows):
                        x = heappop(highs)
                        heappush(lows, -x)
                        shigh -= x
                        slow += x
    return

main()

Verdicts: Wrong Answer

Accepted
Problem: There is a function f(x), which is initially a constant function f(x) = 0.  We will ask you to process Q queries in order. There are two kinds of queries, update queries and evaluation queries, as follows:    * An update query `1 a b`: Given two integers a and b, let g(x) = f(x) + |x - a| + b and replace f(x) with g(x).   * An evaluation query `2`: Print x that minimizes f(x), and the minimum value of f(x). If there are multiple such values of x, choose the minimum such value.  We can show that the values to be output in an evaluation query are always integers, so we ask you to print those values as integers without decimal points.

Submission attempts (in order):

import heapq as hq

Q = int(input())



low = []
high = []

_,mid,val = map(int,input().split())

for _ in range(Q-1):
    s = input()
    if s[0] == '1':
        _,a,b = map(int,s.split())
        if mid is None:
            if a < -low[0]:
                mid = -hq.heapreplace(low, -a)
            elif a > high[0]:
                mid = hq.heapreplace(high, a)
            else:
                mid = a
            val += abs(mid-a)+b
        else:
            val += abs(mid-a)+b
            x,y = sorted((a,mid))
            hq.heappush(high, y)
            hq.heappush(low, -x)
            mid = None

    else:
        print(high[0] if mid is None else mid, val)


import heapq as hq

Q = int(input())



low = []
high = []

_,mid,val = map(int,input().split())

for _ in range(Q-1):
    s = input()
    if s[0] == '1':
        _,a,b = map(int,s.split())
        if mid is None:
            if a < -low[0]:
                mid = hq.heapreplace(low, -a)
            elif a > high[0]:
                mid = hq.heapreplace(high, a)
            else:
                mid = a
            val += abs(mid-a)+b
        else:
            val += abs(mid-a)+b
            x,y = sorted((a,mid))
            hq.heappush(high, y)
            hq.heappush(low, -x)
            mid = None

    else:
        print(high[0] if mid is None else mid, val)


import heapq as hq

Q = int(input())



low = []
high = []

_,mid,val = map(int,input().split())

for _ in range(Q-1):
    s = input()
    if s[0] == '1':
        _,a,b = map(int,s.split())
        if mid is None:
            if a < -low[0]:
                mid = -hq.heapreplace(low, -a)
            elif a > high[0]:
                mid = hq.heapreplace(high, a)
            else:
                mid = a
            val += abs(mid-a)+b
        else:
            val += abs(mid-a)+b
            x,y = sorted((a,mid))
            hq.heappush(high, y)
            hq.heappush(low, -x)
            mid = None

    else:
        print(-low[0] if mid is None else mid, val)

Verdicts: Wrong Answer

Wrong Answer

Accepted