Problem:


Score : 500 points

Problem Statement

There are N integers X_1, X_2, \cdots, X_N, and we know that A_i \leq X_i \leq B_i.
Find the number of different values that the median of X_1, X_2, \cdots, X_N can take.

Notes

The median of X_1, X_2, \cdots, X_N is defined as follows. Let x_1, x_2, \cdots, x_N be the result of sorting X_1, X_2, \cdots, X_N in ascending order.

If N is odd, the median is x_{(N+1)/2};

if N is even, the median is (x_{N/2} + x_{N/2+1}) / 2.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 B_1
A_2 B_2
:
A_N B_N

Output

Print the answer.

Sample Input 1

2
1 2
2 3

Sample Output 1

3

If X_1 = 1 and X_2 = 2, the median is \frac{3}{2};

if X_1 = 1 and X_2 = 3, the median is 2;

if X_1 = 2 and X_2 = 2, the median is 2;

if X_1 = 2 and X_2 = 3, the median is \frac{5}{2}.

Thus, the median can take three values: \frac{3}{2}, 2, and \frac{5}{2}.

Sample Input 2

3
100 100
10 10000
1 1000000000

Sample Output 2

9991



Sample input:
2
1 2
2 3


Sample output:
3

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 998244353

#############
# Main Code #
#############

N = getN()
A = []
B = []
for i in range(N):
    a, b = getNM()
    A.append(a)
    B.append(b)
A.sort()
B.sort()
# 範囲がN個ある
# Xは整数
# 中央値のmin, maxは？
# Nが偶数、奇数の場合
# 奇数の場合 中央値は絶対に整数
# 中央値のmin: Aの中央値、max: Bの中央値
# 偶数の場合
# 中央値のmin: (Ai-1 + Ai) / 2 max: (Bi-1 + Bi) / 2
# いくつある？

# 中央値は最低でも0.5刻み
# 偶数の場合は奇数の2N - 1になる？
# Ai-1とAiを自由にいじることで0.5, 1, 1.5と言う風に中間値を作れそう
if N % 2 == 0:
    opt_a = (A[(N // 2) - 1] + A[N // 2]) / 2
    opt_b = (B[(N // 2) - 1] + B[N // 2]) / 2
    # opt_b - opt_aを0.5で割って +1
    print((opt_b - opt_a) * 2 + 1)
else:
    opt_a = A[N // 2]
    opt_b = B[N // 2]
    # 中央値は絶対に整数
    print(opt_b - opt_a + 1)

Submission status: Wrong Answer

Solution code:
import statistics
N = int(input())
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
  
if N % 2 == 1:
  med_min = A[N // 2]
  med_max = B[N // 2]
  print(med_max - med_min + 1)  
else:
  med_min_db = A[N // 2] + A[N // 2 - 1]
  med_max_db = B[N // 2] + B[N // 2 - 1]
  print(med_max_db - med_min_db + 1)

Submission status: Wrong Answer

Solution code:
from statistics import median


def main():
    n = int(input())
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i], b[i] = map(int, input().split())
    ans = int(median(b) - median(a))
    if n % 2 == 0:
        ans *= 2
    ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# ABC169 E

N=int(input())
AB=[tuple(map(int,input().split())) for _ in [0]*N]

def med(A):
    N=len(A)
    if N%2:
        return A[(N+1)//2-1]
    else:
        return (A[N//2-1]+A[N//2])//2
    
A=[i[0] for i in AB]  
B=[i[1] for i in AB]
medA=med(sorted(A))
medB=med(sorted(B))

if N%2:
    print(medB-medA+1)
else:
    print(2*medB-2*medA+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = []
Bs = []

for _ in range(N):
  a,b = map(int,input().split())
  As.append(a)
  Bs.append(b)
  
As.sort()
Bs.sort()

if N%2 == 1:
  ma = As[N//2]
  mb = Bs[N//2]
  print(mb-ma+1)
else:
  ma = (As[N//2-1] + As[N//2])//2
  mb = (Bs[N//2-1] + Bs[N//2])//2
  print(int((mb-ma)*2)+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range(N):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)

A.sort()
B.sort()

if N % 2 == 1:
	A_median = A[N // 2]
	B_median = B[N // 2]
	print(A_median, B_median)
	print(B_median - A_median + 1)
else:
	A_median2 = A[(N - 1) // 2] + A[N // 2]
	B_median2 = B[(N - 1) // 2] + B[N // 2]
	print(B_median2 - A_median2 + 1)

Submission status: Wrong Answer

Solution code:
n = int(input())
mn = []
mx = []
for _ in range(n):
    a,b = map(int,input().split())
    mn.append(a)
    mx.append(b)
if n % 2 != 0:
    m = (n-1)//2
    p,q = mn[m],mx[m]
    print(q-p+1)
else:
    m1,m2 = (n//2)-1,n//2
    p,q = mn[m1]+mn[m2],mx[m1]+mx[m2]
    print(q-p+1)

Submission status: Wrong Answer

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

def solve():
    N = int(input())
    Ls, Rs = [], []
    for i in range(N):
        a, b = list(map(int, input().split()))
        Ls.append(a), Rs.append(b)

    ans = 0
    if N%2 == 1:
        # Nが奇数なら
        l = Ls[N//2]
        r = Rs[N//2]
        ans = r-l+1
    else:
        # Nが偶数なら
        l2 = Ls[N//2-1]+Ls[N//2]
        r2 = Rs[N//2-1]+Rs[N//2]
        ans = r2-l2+1

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

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

def solve():
    N = int(input())
    Ls, Rs = [], []
    for i in range(N):
        a, b = list(map(int, input().split()))
        Ls.append(a), Rs.append(b)

    ans = 0
    if N%2 == 0:
        # Nが偶数なら
        l = Ls[N//2]
        r = Rs[N//2]
        ans = r-l+1
    else:
        # Nが奇数なら
        l2 = Ls[N//2-1]+Ls[N//2]
        r2 = Rs[N//2-1]+Rs[N//2]
        ans = r2-l2+1

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.sort()
  B.sort()
  A.append(a)
  B.append(b)
def median(x):
  l=len(x)
  if l%2==0:
    return (x[l//2-1]+x[l//2])/2
  else:
    return x[l//2]
if N%2==1:
  print(median(B)-median(A)+1)
else:
  print(int((median(B)-median(A))*2+1))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[]
B=[]
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
def median(x):
  l=len(x)
  if l%2==0:
    return (x[l//2-1]+x[l//2])/2
  else:
    return x[l//2]
if N%2==1:
  print(median(B)-median(A)+1)
else:
  print(int((median(B)-median(A))*2+1))

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def is_median(k, xl, is_odd):
	over = 0
	under = 0
	inner = 0
	same = 0
	for a,b in xl:
		if b < k:
			under+=1
		elif k<a:
			over+=1
		elif a==k and b == k:
			same+=1
		else:
			inner+=1
	
	if abs(under-over) < same+inner:
		return 0
	else:
		return 1 if under > over else -1

def main2():
	n = int(input())
	#b , c = tin()
	xl=[]
	for _ in range(n):
		a,b = tin()
		xl.append((a,b))
	#s = input()
	min_v=0
	max_v=mod
	for a,b in xl:
		min_v=min(min_v, a)
		max_v=max(max_v, b)
	
	d = 1 if n % 2 == 0 else 1/2
	
	k_max_ok = min_v
	k_max_ng = max_v
	while k_max_ng - k_max_ok > d:
		pass
	
	k_min_ok = min_v
	
def main():
	n = int(input())
	al=[]
	bl=[]
	for i in range(n):
		a,b = tin()
		al.append(a)
		bl.append(b)
		
	al.sort()
	bl.sort()
	
	if n % 2 == 1:
		pos = ((n + 1) // 2) - 1
		d = bl[pos] - al[pos] + 1
		return d
	else:
		pos_l = ((n) // 2) - 1
		pos_r = pos_l + 1
		
		if al[pos_r] < bl[pos_l]:
			r = bl[pos_l] - al[pos_l] + bl[pos_r] - al[pos_r] + 1 - max(0, al[pos_r]-bl[pos_l])
		else:
			#return 1/0
			median_min = bl[pos_l] + al[pos_l]
			median_max = bl[pos_r] + al[pos_r]
			r = median_max - median_min + 1
			#pa((median_min,median_max))
		return r
		
			
		
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def is_median(k, xl, is_odd):
	over = 0
	under = 0
	inner = 0
	same = 0
	for a,b in xl:
		if b < k:
			under+=1
		elif k<a:
			over+=1
		elif a==k and b == k:
			same+=1
		else:
			inner+=1
	
	if abs(under-over) < same+inner:
		return 0
	else:
		return 1 if under > over else -1

def main2():
	n = int(input())
	#b , c = tin()
	xl=[]
	for _ in range(n):
		a,b = tin()
		xl.append((a,b))
	#s = input()
	min_v=0
	max_v=mod
	for a,b in xl:
		min_v=min(min_v, a)
		max_v=max(max_v, b)
	
	d = 1 if n % 2 == 0 else 1/2
	
	k_max_ok = min_v
	k_max_ng = max_v
	while k_max_ng - k_max_ok > d:
		pass
	
	k_min_ok = min_v
	
def main():
	n = int(input())
	al=[]
	bl=[]
	for i in range(n):
		a,b = tin()
		al.append(a)
		bl.append(b)
		
	al.sort()
	bl.sort()
	
	if n % 2 == 1:
		pos = ((n + 1) // 2) - 1
		d = bl[pos] - al[pos] + 1
		return d
	else:
		pos_l = ((n) // 2) - 1
		pos_r = pos_l + 1
		
		if al[pos_r] < bl[pos_l]:
			r = bl[pos_l] - al[pos_l] + bl[pos_r] - al[pos_r] + 1 - max(0, al[pos_r]-bl[pos_l])
		else:
			#return 1/0
			median_min = bl[pos_l] - al[pos_l]
			median_max = bl[pos_r] - al[pos_l]
			r = median_max - median_min + 1
		return r
		
			
		
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def is_median(k, xl, is_odd):
	over = 0
	under = 0
	inner = 0
	same = 0
	for a,b in xl:
		if b < k:
			under+=1
		elif k<a:
			over+=1
		elif a==k and b == k:
			same+=1
		else:
			inner+=1
	
	if abs(under-over) < same+inner:
		return 0
	else:
		return 1 if under > over else -1

def main2():
	n = int(input())
	#b , c = tin()
	xl=[]
	for _ in range(n):
		a,b = tin()
		xl.append((a,b))
	#s = input()
	min_v=0
	max_v=mod
	for a,b in xl:
		min_v=min(min_v, a)
		max_v=max(max_v, b)
	
	d = 1 if n % 2 == 0 else 1/2
	
	k_max_ok = min_v
	k_max_ng = max_v
	while k_max_ng - k_max_ok > d:
		pass
	
	k_min_ok = min_v
	
def main():
	n = int(input())
	al=[]
	bl=[]
	for i in range(n):
		a,b = tin()
		al.append(a)
		bl.append(b)
		
	al.sort()
	bl.sort()
	
	if n % 2 == 1:
		pos = ((n + 1) // 2) - 1
		d = bl[pos] - al[pos] + 1
		return d
	else:
		pos_l = ((n) // 2) - 1
		pos_r = pos_l + 1
		
		if al[pos_r] < bl[pos_l]:
			r = bl[pos_l] - al[pos_l] + bl[pos_r] - al[pos_r] + 1 - max(0, al[pos_r]-bl[pos_l])
		else:
			r = bl[pos_l] - al[pos_l] + bl[pos_r] - al[pos_r] + 1 - max(0, al[pos_r]-bl[pos_l])
		return r
		
			
		
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def is_median(k, xl, is_odd):
	over = 0
	under = 0
	inner = 0
	same = 0
	for a,b in xl:
		if b < k:
			under+=1
		elif k<a:
			over+=1
		elif a==k and b == k:
			same+=1
		else:
			inner+=1
	
	if abs(under-over) < same+inner:
		return 0
	else:
		return 1 if under > over else -1

def main2():
	n = int(input())
	#b , c = tin()
	xl=[]
	for _ in range(n):
		a,b = tin()
		xl.append((a,b))
	#s = input()
	min_v=0
	max_v=mod
	for a,b in xl:
		min_v=min(min_v, a)
		max_v=max(max_v, b)
	
	d = 1 if n % 2 == 0 else 1/2
	
	k_max_ok = min_v
	k_max_ng = max_v
	while k_max_ng - k_max_ok > d:
		pass
	
	k_min_ok = min_v
	
def main():
	n = int(input())
	al=[]
	bl=[]
	for i in range(n):
		a,b = tin()
		al.append(a)
		bl.append(b)
		
	al.sort()
	bl.sort()
	
	if n % 2 == 1:
		pos = ((n + 1) // 2) - 1
		d = bl[pos] - al[pos] + 1
		return d
	else:
		pos_l = ((n) // 2) - 1
		pos_r = pos_l + 1

		r = bl[pos_l] - al[pos_l] + bl[pos_r] - al[pos_r] + 1 - min(0, al[pos_r]-bl[pos_l])
		return r
			
		
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def is_median(k, xl, is_odd):
	over = 0
	under = 0
	inner = 0
	same = 0
	for a,b in xl:
		if b < k:
			under+=1
		elif k<a:
			over+=1
		elif a==k and b == k:
			same+=1
		else:
			inner+=1
	
	if abs(under-over) < same+inner:
		return 0
	else:
		return 1 if under > over else -1

def main2():
	n = int(input())
	#b , c = tin()
	xl=[]
	for _ in range(n):
		a,b = tin()
		xl.append((a,b))
	#s = input()
	min_v=0
	max_v=mod
	for a,b in xl:
		min_v=min(min_v, a)
		max_v=max(max_v, b)
	
	d = 1 if n % 2 == 0 else 1/2
	
	k_max_ok = min_v
	k_max_ng = max_v
	while k_max_ng - k_max_ok > d:
		pass
	
	k_min_ok = min_v
	
def main():
	n = int(input())
	al=[]
	bl=[]
	for i in range(n):
		a,b = tin()
		al.append(a)
		bl.append(b)
		
	al.sort()
	bl.sort()
	
	if n % 2 == 1:
		pos = ((n + 1) // 2) - 1
		d = bl[pos] - al[pos] + 1
		return d
	else:
		pos_l = ((n) // 2) - 1
		pos_r = pos_l + 1
		#if al[pos_r] < bl[pos_l]:
		r = min(bl[pos_l] - al[pos_l] + 1, bl[pos_r] - al[pos_r] + 1)
		return r
		
		
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
b=[0]*n
for i in range(n):
  a[i],b[i]=map(int,input().split())
a.sort()
b.sort()
if n%2:ans=b[n//2]-a[n//2]+1
else:ans=b[(n-1)//2+1]-a[(n-1)//2]+1
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
m=[]
M=[]
for _ in range(n):
    x,y=map(int,input().split())
    m.append(x)
    M.append(y)
m=sorted(m)
M=sorted(M)

z=n//2
if n%2==1:
    a=m[z]
    b=M[z]
    print(b-a+1)
else:
    a=(m[z]+m[z-1])//2
    b=(M[z]+M[z-1])//2
    print(2*(b-a)+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
A, B = zip(*AB)

def median(a):
    n = N
    return a[(n+1)//2-1] if n%2 else (a[n//2-1]+a[n//2])/2

A_mid = median(A)
B_mid = median(B)

r = int((B_mid-A_mid) * [2, 1][N%2]) + 1

print(r)

Submission status: Wrong Answer

Solution code:
def median(array):
    L = len(array)
    if L%2==0:
        return (array[L//2-1]+array[L//2])/2
    else:
        return array[L//2]



N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

if N%2==1:
    print(median(B) - median(A) + 1)
else:
    print(int((median(B) - median(A) +0.5)*2))

Submission status: Wrong Answer

Solution code:
def median(array):
    L = len(array)
    if L%2==0:
        return (array[L//2-1]+array[L//2])/2
    else:
        return array[L//2]



N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

print(int(median(B) - median(A)) + 1)

Submission status: Wrong Answer

Solution code:
def median(array):
    L = len(array)
    if L%2==0:
        return (array[L//2-1]+array[L//2])/2
    else:
        return array[L//2]

from math import ceil, floor

N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

print(ceil(median(B))-floor(median(A))+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for n in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
#AB = sorted(AB, key=lambda x: x[0])
#print(AB)
A.sort()
B.sort()

if N % 2 == 1:
    print(int(B[N//2] - A[N//2] + 1))

elif N % 2 == 0:
    print(int((B[N//2] - A[N//2])*2 + 1))
    
else:
    print('RE')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for n in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
#AB = sorted(AB, key=lambda x: x[0])
#print(AB)
A.sort()
B.sort()

if N % 2 == 1:
    print(int(B[N//2] - A[N//2] + 1))

elif N % 2 == 0:
    print(int((B[N//2] - A[N//2])/(1/2) + 1))
    
else:
    print('RE')

Submission status: Wrong Answer

Solution code:
n=int(input())
import bisect as bi
A=[] ; B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

A.sort() ; B.sort()
if n%2==1:
    a=A[(n-1)//2] ; b=B[(n-1)//2]
    print(a,b)
    print(b-a+1)
else:
    a=(A[n//2-1]+A[n//2])/2 ; b=(B[n//2-1]+B[n//2])/2
    print(a,b)
    print(int((b-a)/0.5)+1)

Submission status: Wrong Answer

Solution code:
n=int(input())
import bisect as bi
A=[] ; B=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

if n%2==1:
    a=A[(n-1)//2] ; b=B[(n-1)//2]
    print(b-a+1)
else:
    a=(A[n//2-1]+A[n//2])/2 ; b=(B[n//2-1]+B[n//2])/2
    print(int((b-a)/0.5)+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-

import heapq

n = int(input())

aa = []
bb = []
for i in range(n):
    a , b = list(map(int, input().split()))

    aa.append(a)
    bb.append(b)

if n % 2 == 0:
    m_a = (aa[n // 2 - 1] + aa[n // 2])
    m_b = (bb[n // 2 - 1] + bb[n // 2])

    print(m_b - m_a+1)
    sys.exit()

else:
    median_a = aa[n // 2]
    median_b = bb[n // 2]

    print(median_b-median_a+1)
    sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-

import heapq

n = int(input())

aa = []
bb = []
for i in range(n):
    a , b = list(map(int, input().split()))

    aa.append(a)
    bb.append(b)

if n % 2 == 0:
    median_a = (aa[n // 2 - 1] + aa[n // 2]) / 2
    median_b = (bb[n // 2 - 1] + bb[n // 2]) / 2

    print(int((median_b-median_a+0.1)*2)+1)
    sys.exit()

else:
    median_a = aa[n // 2]
    median_b = bb[n // 2]

    print(median_b-median_a+1)
    sys.exit()

Submission status: Wrong Answer

Solution code:
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-

import heapq

n = int(input())

aa = []
bb = []
for i in range(n):
    a , b = list(map(int, input().split()))

    aa.append(a)
    bb.append(b)

if n % 2 == 0:
    median_a = (aa[n // 2 - 1] + aa[n // 2]) / 2
    median_b = (bb[n // 2 - 1] + bb[n // 2]) / 2

    print(int((median_b-median_a)*2)+1)
    sys.exit()

else:
    median_a = aa[n // 2]
    median_b = bb[n // 2]

    print(median_b-median_a+1)
    sys.exit()

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a
    B[i] = b
A.sort()
B.sort()
N_q, N_mod = divmod(N, 2)
if N_mod == 1:
    ans = B[N_q] - A[N_q] + 1
else:
    ans_list = []
    for x in range(A[N_q - 1], B[N_q - 1] + 1, 1):
        for y in range(A[N_q], B[N_q] + 1, 1):
            ans_list.append((x + y) / 2)
    c = collections.Counter(ans_list)
    values, counts = zip(*c.most_common())
    print(values)
    ans = len(values)
print(ans)

Submission status: Wrong Answer

Solution code:

N = int(input())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

A.sort()
B.sort(reverse=True)
mid1 = A[(N + 1) // 2 - 1]
mid2 = B[(N + 1) // 2 - 1]

if N % 2 == 1:
    print(mid2 - mid1 + 1)
else:
    print((mid2 - mid1) * 2 - 1)

Submission status: Wrong Answer

Solution code:
N=int(input())
L=[]
for i in range(N):
    A, B=list(map(int,input().split()))
    L.append((A,B))
L1=sorted(L,key=lambda x: x[0])
L2=sorted(L,key=lambda x: x[1])
if N%2==1:
    n=N//2
    print(min(L2[n][1],L1[n][1]) -L1[n][0]+1)
else:
    n=N//2
    m=(L1[n-1][1]+L1[n][1])/2
    print(min(L2[n-1][1]+L2[n][1],L1[n-1][1]+L1[n][1])-L1[n-1][0]-L1[n][0]+1)

Submission status: Wrong Answer

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())
l1=[]
l2=[]
for i in range(n):
  a,b=nii()
  l1.append(a)
  l2.append(b)

l1.sort()
l2.sort()

if n%2==1:
  ans=l2[n//2]-l1[n//2]
else:
  m1=(l2[n//2]+l2[n//2-1])//2
  m2=(l1[n//2]+l1[n//2-1])//2
  ans=(m1-m2)*2

print(ans+1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = []
Bs = []
for _ in range(N):
    A, B = mapint()
    As.append(A)
    Bs.append(B)

if N%2==1:
    left = As[N//2]
    right = Bs[N//2]
else:
    left = (As[N//2]+As[N//2-1])
    right = (Bs[N//2]+Bs[N//2-1])

print(right-left+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = []
B = []
for i in range (0,N):
	a, b = map(int, input().split())
	A.append(a)
	B.append(b)
    
A = sorted(A)
B = sorted(B)

if N%2 ==1:
	print(B[int((N+1)/2)-1]-A[int((N+1)/2)-1]+1)
else:
	print(B[int(N/2)]+A[int(N/2)]-B[int(N/2)-1]-A[int(N/2)-1]+1)

Submission status: Wrong Answer

Solution code:
def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
        print(int(ma - mi + 1))
    else:
        mi = (a[N // 2 - 1] + a[N // 2]) / 2
        ma = (b[N // 2 - 1] + b[N // 2]) / 2
        print(int(ma - mi + 1 + 1))


N = int(input())
lines = []
for i in range(N):
    lines.append(list(map(int, input().split())))
main(N, lines)

Submission status: Wrong Answer

Solution code:
import math


def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
        print(int(ma - mi + 1))
    else:
        mi = math.floor((a[N // 2 - 1] + a[N // 2]) / 2)
        ma = math.ceil((b[N // 2 - 1] + b[N // 2]) / 2)
        print(int(ma - mi + 1))


N = int(input())
lines = []
for i in range(N):
    lines.append(list(map(int, input().split())))
main(N, lines)

Submission status: Wrong Answer

Solution code:
import math


def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
    else:
        mi = math.floor((a[N // 2 - 1] + a[N // 2]) / 2)
        ma = math.ceil((b[N // 2 - 1] + b[N // 2]) / 2)
        print(a, b, mi, ma)
        print(int(ma - mi + 1))


N = int(input())
lines = []
for i in range(N):
    lines.append(list(map(int, input().split())))
main(N, lines)

Submission status: Wrong Answer

Solution code:
def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
    else:
        mi = (a[N // 2 - 1] + a[N // 2]) / 2
        ma = (b[N // 2 - 1] + b[N // 2]) / 2
        print(a, b, mi, ma)
        print(int(ma - mi + 1 + 1))


N = int(input())
lines = []
for i in range(N):
    lines.append(list(map(int, input().split())))
main(N, lines)

Submission status: Wrong Answer

Solution code:
def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
        print(ma - mi + 1)
    else:
        mi = (a[N // 2 - 1] + a[N // 2]) / 2
        ma = (b[N // 2 - 1] + b[N // 2]) / 2
        print(int(ma - mi + 1))


N = int(input())
lines = []
for i in range(N):
    lines.append(list(map(int, input().split())))
main(N, lines)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
import statistics
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  print(statistics.median(B) - statistics.median(A) +1)
else:
  print((statistics.median(B) - statistics.median(A))*2 +1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2 +1):
    mlist = [A[2*k], A[2*k-1], medianmin]
    mlist.sort()
    medianmin = mlist[1]
    Mlist = [B[2*k], B[2*k-1], medianmax]
    Mlist.sort()
    medianmax = Mlist[1]
  print(medianmax-medianmin+1)
else:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2):
    mlist = [A[2*k], A[2*k-1], medianmin]
    mlist.sort()
    medianmin = mlist[1]
    Mlist = [B[2*k], B[2*k-1], medianmax]
    Mlist.sort()
    medianmax = Mlist[1]
  mi = abs(medianmin + A[-1])
  ma = abs(medianmax + B[-1])
  print(ma-mi+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2 +1):
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmin:
      medianmin = medianmin
    elif B[2*k] < medianmin and B[2*k-1] < medianmin:
      medianmin = max(A[2*k], A[2*k-1])
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmin:
      medianmax = medianmax
    elif A[2*k] > medianmax and A[2*k-1] > medianmax:
      medianmax = min(B[2*k], B[2*k-1])
    elif B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  print(medianmax-medianmin+1)
else:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2):
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmin:
      medianmin = medianmin
    elif B[2*k] < medianmin and B[2*k-1] < medianmin:
      medianmin = max(A[2*k], A[2*k-1])
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmin:
      medianmax = medianmax
    elif A[2*k] > medianmax and A[2*k-1] > medianmax:
      medianmax = min(B[2*k], B[2*k-1])
    elif B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  mi = abs(medianmin + A[-1])
  ma = abs(medianmax + B[-1])
  print(ma-mi+1)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
for k in range(N):
  A[k], B[k] = map(int, input().split())

if N%2 == 1:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2 +1):
    if min(B[2*k-1], B[2*k]) < medianmin and max(A[2*k], A[2*k-1]) > medianmin:
      medianmin = medianmin
    elif B[2*k] < medianmin and B[2*k-1] < medianmin:
      medianmin = max(A[2*k], A[2*k-1])
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmax:
      medianmax = medianmax
    elif A[2*k] > medianmax and A[2*k-1] > medianmax:
      medianmax = min(B[2*k], B[2*k-1])
    elif B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  print(medianmax-medianmin+1)
else:
  medianmax = B[0]
  medianmin = A[0]
  for k in range(1, N//2):
    if min(B[2*k-1], B[2*k]) < medianmin and max(A[2*k], A[2*k-1]) > medianmin:
      medianmin = medianmin
    elif B[2*k] < medianmin and B[2*k-1] < medianmin:
      medianmin = max(A[2*k], A[2*k-1])
    elif A[2*k] > medianmin and A[2*k-1] > medianmin:
      medianmin = min(A[2*k], A[2*k-1])
    else:
      medianmin = min(medianmin, max(A[2*k-1], A[2*k]))
    if min(B[2*k-1], B[2*k]) < medianmax and max(A[2*k], A[2*k-1]) > medianmax:
      medianmax = medianmax
    elif A[2*k] > medianmax and A[2*k-1] > medianmax:
      medianmax = min(B[2*k], B[2*k-1])
    elif B[2*k] < medianmax and B[2*k-1] < medianmax:
      medianmax = max(B[2*k], B[2*k-1])
    else:  
      medianmax = max(medianmax, min(B[2*k-1], B[2*k]))
  mi = abs(medianmin + A[-1])
  ma = abs(medianmax + B[-1])
  print(ma-mi+1)