During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range $(1, 10^9)$! Therefore, the planet was named Longlifer.

In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!


-----Input-----

The first line contains an integer $n$ ($1 \le n \le 10^5$) — the number of people.

Each of the following $n$ lines contain two integers $b$ and $d$ ($1 \le b \lt d \le 10^9$) representing birth and death year (respectively) of each individual.


-----Output-----

Print two integer numbers separated by blank character, $y$  — the year with a maximum number of people alive and $k$  — the number of people alive in year $y$.

In the case of multiple possible solutions, print the solution with minimum year.


-----Examples-----
Input
3
1 5
2 4
5 6

Output
2 2

Input
4
3 4
4 5
4 6
8 10

Output
4 2



-----Note-----

You can assume that an individual living from $b$ to $d$ has been born at the beginning of $b$ and died at the beginning of $d$, and therefore living for $d$ - $b$ years.

Difficulty: EASY
Tags: Sorting

Data structures
Skill types: Sorting

Data structures

Starter code:

Solutions:
years = {}
for k in range(int(input())):
	(b, d) = map(int, input().split())
	if b in years:
		years[b] += 1
	else:
		years[b] = 1
	if d in years:
		years[d] -= 1
	else:
		years[d] = -1
keys = sorted(years.keys())
y = 0
c = 0
cur = 0
for year in keys:
	cur += years[year]
	if cur > c:
		y = year
		c = cur
print(y, c)


anos = {}
for _ in range(int(input())):
	(ini, fim) = [int(x) for x in input().split()]
	if ini in anos:
		anos[ini] += 1
	else:
		anos[ini] = 1
	if fim in anos:
		anos[fim] -= 1
	else:
		anos[fim] = -1
vivos = 0
maior = 0
anoMaior = 0
for (ano, saldo) in sorted(anos.items()):
	vivos += saldo
	if maior < vivos:
		maior = vivos
		anoMaior = ano
print(anoMaior, maior)


n = int(input())
years = []
for i in range(n):
	vals = input().split()
	years.append((int(vals[0]), 1))
	years.append((int(vals[1]), -1))
years.sort()
max_population = 0
population = 0
for year in years:
	if year[1] == -1:
		population -= 1
	else:
		population += 1
		if population > max_population:
			max_population = population
			max_year = year[0]
print(max_year, max_population)


def year():
	dct = {}
	t = int(input())
	for i in range(t):
		(a, b) = map(int, input().strip().split())
		if a in dct:
			dct[a] += 1
		else:
			dct[a] = 1
		if b in dct:
			dct[b] -= 1
		else:
			dct[b] = -1
	count = 0
	curr = 0
	y = 0
	for i in sorted(dct.keys()):
		curr += dct[i]
		if curr > count:
			count = curr
			y = i
	print(y, count)
year()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
from collections import defaultdict as dc
born = dc(int)
die = dc(int)
for _ in range(N()):
	(a, b) = RL()
	born[a] += 1
	die[b] += 1
s = list(sorted(set(born.keys()) | set(die.keys())))
m = 0
now = 0
for i in s:
	now += born[i] - die[i]
	if now > m:
		res = i
		m = now
print(res, m)


import sys
input = sys.stdin.readline
segs = []
n = int(input())
for _ in range(n):
	(a, b) = map(int, input().split())
	segs += [(a, 1)]
	segs += [(b, 0)]
segs.sort()
(y, k) = (-1, 0)
res = 0
for seg in segs:
	if seg[1] == 1:
		res += 1
		if res > k:
			y = seg[0]
			k = res
	else:
		res -= 1
print(y, k)


cases = int(input())
lst = []
for case in range(cases):
	(x, y) = input().split()
	lst.append([int(x), 1])
	lst.append([int(y), 0])
lst.sort()
count = 0
count_max = 0
year_max = lst[-1][0]
start = 0
for temp in lst:
	if temp[1] == 1:
		count += 1
	else:
		count -= 1
	if count_max < count:
		count_max = count
		year_max = temp[0]
count = 0
print(year_max, count_max)


n = int(input())
v = []
for i in range(n):
	(a, b) = map(int, input().split())
	v.append((a, 1))
	v.append((b, -1))
v.sort()
ans = ct = 0
for i in v:
	ct += i[1]
	if ans < ct:
		(ans, year) = (ct, i[0])
print(year, ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def bucketsort(order, seq):
	buckets = [0] * (max(seq) + 1)
	for x in seq:
		buckets[x] += 1
	for i in range(len(buckets) - 1):
		buckets[i + 1] += buckets[i]
	new_order = [-1] * len(seq)
	for i in reversed(order):
		x = seq[i]
		idx = buckets[x] = buckets[x] - 1
		new_order[idx] = i
	return new_order

def ordersort(order, seq, reverse=False):
	bit = max(seq).bit_length() >> 1
	mask = (1 << bit) - 1
	order = bucketsort(order, [x & mask for x in seq])
	order = bucketsort(order, [x >> bit for x in seq])
	if reverse:
		order.reverse()
	return order

def long_ordersort(order, seq):
	order = ordersort(order, [int(i & 2147483647) for i in seq])
	return ordersort(order, [int(i >> 31) for i in seq])

def multikey_ordersort(order, *seqs, sort=ordersort):
	for i in reversed(range(len(seqs))):
		order = sort(order, seqs[i])
	return order

def solve(case):
	n = int(inp())
	b = []
	type = []
	for i in range(n):
		(x, y) = sep()
		b.append(x)
		b.append(y)
		type.append(1)
		type.append(0)
	order = multikey_ordersort(range(2 * n), b, type)
	have = []
	for i in order:
		have.append((b[i], type[i]))
	year = 0
	cnt = 0
	currin = 0
	for i in range(len(have)):
		curr = have[i]
		if curr[1] == 1:
			currin += 1
		else:
			currin -= 1
		if currin > cnt:
			cnt = currin
			year = curr[0]
	print(year, cnt)
testcase(1)


v = []
for _ in range(int(input())):
	t = list(map(int, input().split()))
	v.append((t[0], 1))
	v.append((t[1], -1))
v.sort()
ans = ct = 0
for i in v:
	ct += i[1]
	if ans < ct:
		(ans, year) = (ct, i[0])
print(year, ans)


N = int(input())
starts = []
ends = []
for i in range(N):
	year = input().split(' ')
	starts.append(int(year[0]))
	ends.append(int(year[1]))
starts.sort()
ends.sort()
ans = (0, 0)
res = i = j = 0
while i < N:
	if starts[i] < ends[j]:
		res += 1
		if res > ans[0]:
			ans = (res, starts[i])
		i += 1
	elif starts[i] == ends[j]:
		i += 1
		j += 1
	else:
		res -= 1
		j += 1
print('{} {}'.format(ans[1], ans[0]))


import sys
import collections
cin = sys.stdin
cout = sys.stdout
n = int(cin.readline().strip())
increments = collections.OrderedDict()
for p in range(0, n):
	line = cin.readline().strip().split(' ')
	by = int(line[0])
	dy = int(line[1])
	increments[by] = increments.get(by, 0) + 1
	increments[dy] = increments.get(dy, 0) - 1
increments = {k: v for (k, v) in sorted(increments.items(), key=lambda pair: pair[0])}
population_point = collections.OrderedDict()
max_year = 0
max_population = 0
running_sum = 0
for (cur_year, cur_inc) in increments.items():
	running_sum += cur_inc
	if running_sum > max_population:
		max_year = cur_year
		max_population = running_sum
result = f'{max_year} {max_population}\n'
cout.write(result)


def readInt():
	return int(input())

def readLine():
	return [int(s) for s in input().split(' ')]

def readString():
	return input()

def ask(od):
	allData = []
	for (a, b) in od:
		allData.append((a, True))
		allData.append((b, False))
	allData = sorted(allData)
	maxL = 0
	maxYear = 0
	current = 0
	for (num, b) in allData:
		if b:
			current += 1
		else:
			current -= 1
		if current > maxL:
			maxL = current
			maxYear = num
	return (maxYear, maxL)
n = readInt()
ret = []
for _ in range(n):
	params = readLine()
	ret.append((params[0], params[1]))
(a, b) = ask(ret)
print(a, b)


x = []
for __ in range(int(input())):
	(a, b) = map(int, input().split())
	x.append([a, 1])
	x.append([b, -1])
x.sort()
y = []
maxx = -1
curr = 0
for i in range(len(x)):
	curr += x[i][1]
	if curr > maxx:
		maxx = curr
		y = x[i][0]
print(y, maxx)


n = int(input())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append([x, 1])
	a.append([y, -1])
a.sort()
k = 0
y = 0
m = 0
for i in range(len(a)):
	k += a[i][1]
	if m < k:
		m = k
		y = a[i][0]
print(y, m)


n = int(input())
li = []
for i in range(n):
	(a, b) = list(map(int, input().split()))
	li.append([a, 1])
	li.append([b, 0])
li.sort()
c = 0
m = 0
y = 0
l = len(li)
for i in range(l):
	if li[i][1] == 1:
		c += 1
	else:
		c -= 1
	if m < c:
		m = c
		y = li[i][0]
print(y, m)


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
n = int(input())
q = []
w = []
e = []
r = []
for i in range(n):
	(a, b) = map(int, input().split())
	q.append(a)
	w.append(b)
q = sorted(q)
w = sorted(w)
i = 0
j = 0
while i < n and j < n:
	if q[i] < w[j]:
		e.append(1)
		r.append(q[i])
		i += 1
	elif w[j] < q[i]:
		e.append(-1)
		r.append(w[j])
		j += 1
	else:
		e.append(-1)
		r.append(w[j])
		j += 1
k = 0
l = 0
if i != n:
	e += [1] * len(q[i:])
	r += q[i:]
elif j != n:
	e += [-1] * len(w[j:])
	r += w[j:]
y = []
for i in range(2 * n):
	k += e[i]
	l = max(l, k)
for i in range(2 * n):
	k += e[i]
	if l == k:
		y.append(i)
u = max(w)
for i in y:
	u = min(u, r[i])
print(u, l)


A = []
(year_most_alive, max_quant, c) = (0, 0, 0)
for i in range(int(input())):
	(b, d) = map(int, input().split())
	A.append((b, 1))
	A.append((d, -1))
A.sort()
for i in A:
	c += i[1]
	if c > max_quant:
		(max_quant, year_most_alive) = (c, i[0])
print(year_most_alive, max_quant)


import math
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(100000)

def put():
	return map(int, stdin.readline().split())
for _ in range(1):
	n = int(input())
	start = []
	end = []
	for i in range(n):
		(a, b) = put()
		start.append(a)
		end.append(b)
	start.sort()
	end.sort()
	numalive = 0
	startyear = 0
	indstart = 0
	indend = 0
	mx = 0
	while indstart < n:
		if start[indstart] < end[indend]:
			numalive += 1
			indstart += 1
			if numalive > mx:
				mx = max(mx, numalive)
				startyear = start[indstart - 1]
		elif start[indstart] == end[indend]:
			indstart += 1
			indend += 1
		else:
			numalive -= 1
			indend += 1
	print(startyear, mx)


num_of_people = int(input())
events = []
diff_in_year = dict()
for person in range(num_of_people):
	(birth_year, death_year) = map(int, input().split(' '))
	diff_in_year.setdefault(birth_year, 0)
	diff_in_year.setdefault(death_year, 0)
	diff_in_year[birth_year] += 1
	diff_in_year[death_year] -= 1
years = sorted(diff_in_year.keys())
current_population = 0
max_population = 0
best_year = 0
for year in years:
	current_population += diff_in_year[year]
	if current_population > max_population:
		max_population = current_population
		best_year = year
print(best_year, max_population)


import math
from collections import *
import math

def solve():
	n = int(input())
	a = []
	b = []
	for i in range(n):
		(x, y) = map(int, input().split())
		a.append(x)
		b.append(y)
	a.sort()
	b.sort()
	(i, j, maxi, y, c) = (0, 0, float('-inf'), -1, 0)
	while i < n and j < n:
		if a[i] < b[j]:
			c += 1
			if c > maxi:
				y = a[i]
				maxi = c
			i += 1
		else:
			c -= 1
			j += 1
	print(y, maxi)
solve()


import heapq
import sys
from math import *
import threading
from heapq import *
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

	def npr(self, n, k):
		if k < 0 or n < k:
			return 0
		f = self.factorial
		return f.calc(n) * f.invFactorial(n - k) % self.MOD

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

def lower_bound(li, num):
	answer = len(li)
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = len(li)
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			start = middle + 1
		else:
			answer = middle
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [{1, i} for i in range(n + 1)]
	p = 2
	while p <= n:
		for i in range(p * 2, n + 1, p):
			prime[i].add(p)
		p += 1
	return prime

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def given():
	a = list(map(int, input().split()))
	return a

def givenString():
	s = list(input())
	return s

def givenStringInt():
	s = [int(x) for x in givenString()]
	return s

def main():
	karmanya = 1
	while karmanya != 0:
		karmanya -= 1
		n = given()[0]
		peep = []
		ans = 0
		year = -1
		for i in range(n):
			(a, b) = given()
			peep += [(a, 1)]
			peep += [(b, -1)]
		peep.sort()
		temp = 0
		for i in range(2 * n):
			temp += peep[i][1]
			if temp > ans:
				ans = temp
				year = peep[i][0]
		print(year, ans)
main()


years = {}
for k in range(int(input())):
	(b, d) = map(int, input().split())
	if b in years:
		years[b] += 1
	else:
		years[b] = 1
	if d in years:
		years[d] -= 1
	else:
		years[d] = -1
keys = sorted(years.keys())
maxLivingYear = 0
maxLivingCount = 0
cur = 0
for year in keys:
	cur += years[year]
	if cur > maxLivingCount:
		maxLivingYear = year
		maxLivingCount = cur
print(maxLivingYear, maxLivingCount)


n = int(input())
l1 = []
l2 = []
for i in range(n):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
l1.sort(reverse=True)
l2.sort(reverse=True)
cur = 0
mx = 0
ans = 0
while l1:
	if l1[-1] < l2[-1]:
		t = l1.pop()
		cur += 1
		if cur > mx:
			mx = cur
			ans = t
	else:
		l2.pop()
		cur -= 1
print(ans, mx)


import re
import sys
exit = sys.exit
from bisect import bisect_left as bsl, bisect_right as bsr
from collections import Counter, defaultdict as ddict, deque
from functools import lru_cache
cache = lru_cache(None)
from heapq import *
from itertools import *
from math import inf
from pprint import pprint as pp
enum = enumerate
ri = lambda : int(rln())
ris = lambda : list(map(int, rfs()))
rln = sys.stdin.readline
rl = lambda : rln().rstrip('\n')
rfs = lambda : rln().split()
cat = ''.join
catn = '\n'.join
mod = 1000000007
d4 = [(0, -1), (1, 0), (0, 1), (-1, 0)]
d8 = [(-1, -1), (0, -1), (1, -1), (-1, 0), (1, 0), (-1, 1), (0, 1), (1, 1)]

def solve():
	n = ri()
	d = ddict(int)
	for _ in range(n):
		(a, b) = ris()
		d[a] += 1
		d[b] -= 1
	y = k = s = 0
	for x in sorted(d):
		s += d[x]
		if k < s:
			(y, k) = (x, s)
	return (y, k)
print(*solve())


pop = {}
order = set()
for i in range(int(input())):
	(b, d) = map(int, input().split())
	if b in pop:
		pop[b] += 1
	else:
		pop[b] = 1
	if d in pop:
		pop[d] -= 1
	else:
		pop[d] = -1
	order.add(b)
	order.add(d)
order = sorted(list(order))
currPop = 0
maxPop = 0
maxYear = order[0]
for i in order:
	currPop += pop[i]
	if currPop > maxPop:
		maxPop = currPop
		maxYear = i
print(maxYear, maxPop)


n = int(input())
interv = []
for i in range(n):
	(deb, fin) = map(int, input().split())
	interv.append((deb, +1))
	interv.append((fin, -1))
interv.sort()
m = 0
y = 0
c = 0
for (t, dx) in interv:
	c += dx
	if c > m:
		m = c
		y = t
print(y, m)


n = int(input())
masb = []
masd = []
for i in range(n):
	(z1, z2) = list(map(int, input().split()))
	masb.append(z1)
	masd.append(z2)
masb.sort()
masd.sort()
j = 0
k = 0
y = 0
mx = [0, 0]
for i in range(len(masb)):
	y = masb[i]
	k += 1
	while y >= masd[j]:
		k -= 1
		j += 1
	if k > mx[1]:
		mx = [y, k]
print(*mx)


def findMaxGuests(arrl, exit, n):
	arrl.sort()
	exit.sort()
	guests_in = 1
	max_guests = 1
	time = arrl[0]
	i = 1
	j = 0
	while i < n and j < n:
		if arrl[i] < exit[j]:
			guests_in = guests_in + 1
			if guests_in > max_guests:
				max_guests = guests_in
				time = arrl[i]
			i = i + 1
		else:
			guests_in = guests_in - 1
			j = j + 1
	print(time, max_guests)
n = int(input())
arrl = []
exit = []
for i in range(n):
	(a, b) = map(int, input().split())
	arrl.append(a)
	exit.append(b)
findMaxGuests(arrl, exit, n)


a = []
y = mx = c = 0
for i in range(int(input())):
	(b, d) = map(int, input().split())
	a.append((b, 1))
	a.append((d, -1))
a.sort()
for i in a:
	c += i[1]
	if c > mx:
		(mx, y) = (c, i[0])
print(y, mx)


from sys import stdin, stdout

def u():
	return stdin.readline().rstrip().split()
l = list()
for _ in range(int(input())):
	(b, d) = map(int, u())
	l.append((b, 1))
	l.append((d, -1))
l.sort()
(year, mx, population) = (0, 0, 0)
for el in l:
	population += el[1]
	if population > mx:
		(year, mx) = (el[0], population)
print(year, mx)


n = int(input())
a = dict()
for i in range(n):
	(b, d) = map(int, input().split())
	if b in a:
		a[b] += 1
	else:
		a[b] = 1
	if d in a:
		a[d] -= 1
	else:
		a[d] = -1
year = sorted(a.keys())
cur = 0
m = 0
x = 0
for y in year:
	cur += a[y]
	if cur > m:
		x = y
		m = cur
print(x, m)


def fast3():
	import os, sys, atexit
	from io import BytesIO
	sys.stdout = BytesIO()
	_write = sys.stdout.write
	sys.stdout.write = lambda s: _write(s.encode())
	atexit.register(lambda : os.write(1, sys.stdout.getvalue()))
	return BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import *
input = fast3()
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
n = rint()
(a, mem) = (rints_2d(n), defaultdict(int))
for (l, r) in a:
	mem[l] += 1
	mem[r] -= 1
sor = sorted(mem.keys())
ans = [sor[0], mem[sor[0]]]
for i in range(1, len(sor)):
	mem[sor[i]] += mem[sor[i - 1]]
	if mem[sor[i]] > ans[1]:
		ans = [sor[i], mem[sor[i]]]
print(*ans)


def years():
	n = int(input())
	birth = []
	death = []
	for _ in range(n):
		line = input().split()
		birth.append(int(line[0]))
		death.append(int(line[1]))
	birth.sort()
	death.sort()
	cont = 0
	max = 0
	ano_max = 0
	i_death = 0
	for i in range(len(birth)):
		cont += 1
		while death[i_death] <= birth[i]:
			cont -= 1
			i_death += 1
		if cont > max:
			max = cont
			ano_max = birth[i]
	print(ano_max, max)
years()


n = int(input())
i = 0
b = list()
a = list()
while i < n:
	c = input().split()
	a.append(int(c[0]))
	b.append(int(c[1]))
	i += 1
a.sort()
b.sort()
i = 0
j = 0
count = 0
ans = 0
while i < n:
	count += 1
	while j < n:
		if a[i] >= b[j]:
			count -= 1
			j += 1
		else:
			break
	if ans < count:
		ans = count
		k = a[i]
	i += 1
print(k, end=' ')
print(ans)


def years(a, b):
	c = []
	for x in a:
		c.append([x, 's'])
	for x in b:
		c.append([x, 'e'])
	c.sort()
	max_el = 0
	el = 0
	ind = 0
	x = 0
	while x < len(c):
		y = x
		while y < len(c) and c[y] == c[x]:
			if c[y][1] == 's':
				el += 1
			else:
				el -= 1
			y += 1
		x = y
		if el > max_el:
			max_el = el
			ind = c[x - 1][0]
	return (ind, max_el)
n = int(input())
(p, q) = ([], [])
for _ in range(n):
	(a, b) = map(int, input().split())
	p.append(a)
	q.append(b)
ans = years(p, q)
print(ans[0], ans[1])


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import heapq
n = int(input())
dates = []
for s in range(n):
	(a, b) = map(int, input().split())
	dates.append((a, b))
dates.sort(key=lambda x: x[0])
search = [s[0] for s in dates]
maxsofar = 0
year = 0
greater = []
for s in range(n):
	left = dates[s][0]
	right = dates[s][1]
	while len(greater) > 0 and greater[0] <= left:
		heapq.heappop(greater)
	if len(greater) + 1 > maxsofar:
		maxsofar = len(greater) + 1
		year = left
	heapq.heappush(greater, right)
print(year, maxsofar)


dct = {}
for i in range(int(input())):
	(a, b) = map(int, input().split())
	dct[a] = dct.get(a, 0) + 1
	dct[b] = dct.get(b, 0) - 1
cnt = curr = y = 0
for i in sorted(dct.keys()):
	curr += dct[i]
	if curr > cnt:
		cnt = curr
		y = i
print(y, cnt)


import sys
from collections import defaultdict

def load_sys():
	return sys.stdin.readlines()

def load_local():
	with open('input.txt', 'r') as f:
		input = f.readlines()
	return input

def years(arr):
	events = [[x[0], 'b'] for x in arr] + [[x[1], 'd'] for x in arr]
	events.sort(key=lambda x: x[0])
	population = ans = 0
	mx = float('-inf')
	for i in range(len(events)):
		(y, event) = events[i]
		if event == 'b':
			population += 1
		else:
			population -= 1
		if (i == len(events) - 1 or events[i + 1][0] != y) and population > mx:
			mx = population
			ans = y
	return str(ans) + ' ' + str(mx)
input = load_sys()
N = int(input[0])
arr = []
for i in range(1, len(input)):
	person = input[i].split()
	person = [int(x) for x in person]
	arr.append(person)
print(years(arr))


from sys import stdin, stdout
from math import ceil, floor, sqrt, log, log2, log10
from collections import Counter
int_max = float('inf')
int_min = -float('inf')
input = stdin.readline

def solve():
	pass
t = 1
for i in range(t):
	n = int(input())
	ages = []
	for i in range(n):
		(a, b) = map(int, input().split())
		ages.append([a, 1])
		ages.append([b, 0])
	ages.sort()
	c = 0
	m = 0
	output = 0
	for i in range(2 * n):
		if ages[i][1] == 1:
			c += 1
		else:
			c -= 1
		if m < c:
			m = c
			output = ages[i][0]
	print(output, m)


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi
import math
from itertools import permutations
from copy import deepcopy

def main():
	from collections import Counter
	n = int(input())
	a = set()
	b = Counter()
	for i in range(n):
		(x, y) = map(int, input().split())
		a.add(x)
		a.add(y)
		b[x] += 1
		b[y] -= 1
	a = sorted(a)
	(c, ma, y) = (0, 0, 0)
	for i in a:
		c += b[i]
		if ma < c:
			ma = c
			y = i
	print(y, ma)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


def main():
	people = int(input())
	births_and_deaths = []
	for _ in range(people):
		(birth, death) = [int(i) for i in input().split()]
		births_and_deaths.append([birth, 1])
		births_and_deaths.append([death, -1])
	births_and_deaths.sort()
	info = [0, 0]
	count = 0
	for i in range(len(births_and_deaths)):
		count += births_and_deaths[i][1]
		if info[0] < count:
			info[0] = count
			info[1] = births_and_deaths[i][0]
	print(f'{info[1]} {info[0]}')
main()


import sys
pl = 1
sys.setrecursionlimit(10 ** 5)
if pl:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('outpt.txt', 'w')

def li():
	return [int(xxx) for xxx in input().split()]

def fi():
	return int(input())

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())
t = 1
while t > 0:
	t -= 1
	n = fi()
	maxi = [0] * 2
	a = []
	for i in range(n):
		(l, r) = mi()
		a.append([l, 0])
		a.append([r - 1, 1])
	a.sort()
	c = 0
	for i in range(len(a)):
		if a[i][1] == 0:
			c += 1
			if c > maxi[0]:
				maxi = [c, a[i][0]]
		else:
			c -= 1
	print(*maxi[::-1])


n = int(input())
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append([a, 1])
	arr.append([b, -1])
arr = sorted(arr)
ans = 0
year = 0
c = 0
for i in range(2 * n):
	c += arr[i][1]
	if c > ans:
		ans = c
		year = arr[i][0]
print(year, ans)


import sys
l = sys.stdin.readlines()
i = 0
n = int(l[i].replace('\n', ''))
b = []
d = []
for i in range(n):
	a = [int(x) for x in l[i + 1].replace('\n', '').split()]
	b.append(a[0])
	d.append(a[1])
anoMax = -1
numP = 0
vivos = 0
b.sort()
d.sort()
i = 0
j = 0
while i < n and j < n:
	nasceu = b[i]
	if b[i] < d[j]:
		vivos += 1
		i += 1
	elif b[i] == d[j]:
		i += 1
		j += 1
	else:
		vivos -= 1
		j += 1
	if vivos > numP:
		numP = vivos
		anoMax = nasceu
print(str(anoMax) + ' ' + str(numP))


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
n = inn()
bir = []
dea = []
for i in range(n):
	(x, y) = value()
	bir += [x]
	dea += [y]
bir.sort()
dea.sort()
(i, j, res) = (1, 0, 1)
ans = 1
year = bir[0]
while i < n:
	if bir[i] < dea[j]:
		res += 1
		if res > ans:
			ans = res
			year = bir[i]
		i += 1
	else:
		res -= 1
		j += 1
print(year, ans)


n = int(input())
year = {}
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	if a in year:
		year[a] += 1
	else:
		year[a] = 1
	if b in year:
		year[b] -= 1
	else:
		year[b] = -1
ansyear = 0
maxpop = 0
currpop = 0
for key in sorted(year):
	currpop += year[key]
	if currpop > maxpop:
		maxpop = currpop
		ansyear = key
print(ansyear, maxpop)


from sys import stdin

def input():
	return stdin.readline().strip()
n = int(input())
birth_arr = []
death_arr = []
for i in range(n):
	(b, d) = list(map(int, input().split()))
	birth_arr.append(b)
	death_arr.append(d)
birth_arr = sorted(birth_arr)
death_arr = sorted(death_arr)
num_ppl = len(birth_arr)
curr = 0
curr_year = 0
max_year = None
max_ppl = 0
b_pointer = 0
d_pointer = 0
while b_pointer < num_ppl:
	if birth_arr[b_pointer] < death_arr[d_pointer]:
		curr += 1
		curr_year = birth_arr[b_pointer]
		if curr > max_ppl:
			max_year = curr_year
			max_ppl = curr
		b_pointer += 1
	elif birth_arr[b_pointer] == death_arr[d_pointer]:
		curr_year = birth_arr[b_pointer]
		b_pointer += 1
		d_pointer += 1
	else:
		curr -= 1
		curr_year = death_arr[d_pointer]
		d_pointer += 1
print(f'{max_year} {max_ppl}')


import sys
input = sys.stdin.readline
n = int(input())
t = []
for i in range(n):
	(a, b) = map(int, input().split())
	t.append([a, 1])
	t.append([b, -1])
c = 0
peoplealive = 0
year = 0
t.sort()
for j in range(2 * n):
	c += t[j][1]
	if c > peoplealive:
		peoplealive = c
		year = t[j][0]
print(str(year) + ' ' + str(peoplealive))


import sys
import string
from heapq import *
from bisect import *
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
en = lambda x: list(enumerate(x))
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = []
for i in range(n):
	(a, b) = r()
	arr += ([a, 1],)
	arr += ([b, -1],)
arr.sort()
c = 0
x = 0
d = 0
for (i, j) in arr:
	c += j
	if c > d:
		d = c
		x = i
print(x, d)


n = int(input())
births = []
deaths = []
for _ in range(n):
	(b, d) = list(map(int, input().split(' ')))
	births.append(b)
	deaths.append(d)
births.sort()
deaths.sort()
i = 0
j = 0
count = 0
ind = 0
maximum = -1
checker = 0
indexer = 0
while i < n and j < n:
	if births[i] < deaths[j]:
		count += 1
		indexer = i
		i += 1
	else:
		j += 1
		count -= 1
		indexer = i
	if count > maximum:
		ind = births[indexer]
		maximum = count
print(ind, maximum)


n = int(input())
l = []
l1 = []
for i in range(n):
	(b, d) = map(int, input().split())
	l.append(b)
	l1.append(d)
l.sort()
l1.sort()
count = 0
val = 0
max = 1
b = l[0]
i = 1
j = 0
while i < n and j < n:
	if l[i] < l1[j]:
		count = i - j + 1
		if max < count:
			max = count
			b = l[i]
		i += 1
	elif l[i] == l1[j]:
		i += 1
		j += 1
	else:
		j += 1
print(b, max)


def main():
	timeline = []
	n = int(input())
	for _ in range(n):
		(birth, death) = [int(ele) for ele in input().split()]
		timeline.append([birth, True])
		timeline.append([death, False])
	timeline.sort()
	year = 0
	population = 0
	max_population = 0
	for element in timeline:
		if element[1]:
			population += 1
			if population > max_population:
				year = element[0]
				max_population = population
		else:
			population -= 1
	print(year, max_population)
main()


book = []
for _ in range(int(input())):
	(b, d) = [int(i) for i in input().split()]
	book.append((b, 1))
	book.append((d, -1))
book.sort()
(y, k, p) = (-10 ** 11, 0, 0)
for elem in book:
	p += elem[1]
	if p > k:
		(k, y) = (p, elem[0])
print(y, k)


numeroDePessoas = int(input())
vetor = []
maximoVIVOS = 0
maximoANO = 0
vivos = 0
for i in range(numeroDePessoas):
	(nasce, morre) = map(int, input().split())
	vetor.append([nasce, 1])
	vetor.append([morre, -1])
vetor = sorted(vetor)
for i in range(2 * numeroDePessoas):
	vivos += vetor[i][1]
	if vivos > maximoVIVOS:
		maximoVIVOS = vivos
		maximoANO = vetor[i][0]
print(maximoANO, maximoVIVOS)


from sys import stdin, stdout
import math
t = int(stdin.readline())
bir = {}
dea = {}
maxyear = 0
minyear = 10 ** 9
arr = set()
for _ in range(t):
	(b, d) = map(int, stdin.readline().split())
	if b in bir:
		bir[b] += 1
	else:
		bir[b] = 1
	if d in dea:
		dea[d] += 1
	else:
		dea[d] = 1
	arr.add(b)
	arr.add(d)
maxlive = 0
year = -1
alive = 0
for i in sorted(arr):
	if i in bir:
		alive += bir[i]
	if i in dea:
		alive -= dea[i]
	if alive > maxlive:
		maxlive = alive
		year = i
print('{} {}'.format(year, maxlive))


from sys import stdin, stdout
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from collections import defaultdict as dd, Counter as C, deque
import math
v = []
for _ in range(it()):
	(b, d) = mp()
	v.append([b, 1])
	v.append([d, -1])
v.sort()
(ans, c) = (0, 0)
for i in v:
	c += i[1]
	if ans < c:
		(ans, y) = (c, i[0])
print(y, ans)


n = int(input())
a = []
for i in range(n):
	(x, y) = list(map(int, input().split()))
	a.append([x, 1])
	a.append([y, 0])
a.sort()
c = 0
m = 0
y = 0
for i in range(len(a)):
	if a[i][1] == 1:
		c += 1
	else:
		c -= 1
	if m < c:
		m = c
		y = a[i][0]
print(y, m)


import sys

def fi():
	return sys.stdin.readline()
counter = 0
max1 = 0
years = 0
l = []
for _ in range(int(fi())):
	(a, b) = map(int, fi().split())
	l.append([a, 1])
	l.append([b, -1])
l.sort()
for i in l:
	counter += i[1]
	if counter > max1:
		max1 = counter
		year = i[0]
print(year, max1)


n = int(input())
(x, y) = ([], [])
for i in range(n):
	c = [int(k) for k in input().split()]
	x.append(c[0])
	y.append(c[1])
res = 0
zxc = 0
z = 0
x.sort()
y.sort()
(x, y) = (x[::-1], y[::-1])
while x:
	if x[-1] == y[-1]:
		eta = x[-1]
		while y and x[-1] == y[-1]:
			y.pop()
			z -= 1
		while x and x[-1] == eta:
			x.pop()
			z += 1
		if z > res:
			res = z
			zxc = eta
	elif x[-1] > y[-1]:
		eta = y[-1]
		while y and y[-1] == eta:
			y.pop()
			z -= 1
	else:
		eta = x[-1]
		while x and x[-1] == eta:
			x.pop()
			z += 1
		if z > res:
			res = z
			zxc = eta
print(zxc, res)


n = int(input())
a = n * [0]
b = n * [0]
for i in range(n):
	(a[i], b[i]) = map(int, input().split())
a = sorted(a)
b = sorted(b)
j = 0
ans = 0
i_ans = 0
for i in range(n):
	while b[j] <= a[i]:
		j += 1
	if i - j + 1 > ans:
		ans = i - j + 1
		i_ans = i
print(a[i_ans], ans)


births = []
deaths = []
for k in range(int(input())):
	(b, d) = list(map(int, input().split()))
	births.append(b)
	deaths.append(d)
births = sorted(births)
deaths = sorted(deaths)
i = 0
j = 0
cnt = 0
mxyear = -1
mxcnt = -1
while i < len(births) and j < len(deaths):
	if births[i] < deaths[j]:
		cnt += 1
		if cnt > mxcnt:
			mxcnt = cnt
			mxyear = births[i]
		i += 1
	elif births[i] == deaths[j]:
		i += 1
		j += 1
	else:
		cnt -= 1
		j += 1
print(mxyear, mxcnt)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}
from bisect import bisect_right, bisect_left

def smaller(lst, x):
	return bisect_left(lst, x)

def smallerEq(lst, x):
	return bisect_right(lst, x)

def solve(n, born, die):
	death = {}
	for i in die:
		if death.get(i) == None:
			death[i] = 1
		else:
			death[i] += 1
	lst = sorted(born + die)
	for i in range(len(lst)):
		if death.get(lst[i]) != None:
			death[lst[i]] -= 1
			if death[lst[i]] == 0:
				del death[lst[i]]
			lst[i] *= -1
	maxx = 0
	alive = 0
	when = 0
	for i in lst:
		if i < 0:
			alive -= 1
		else:
			alive += 1
		if alive > maxx:
			maxx = alive
			when = i
	print(when, maxx)
born = []
die = []
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	born.append(a)
	die.append(b)
solve(n, born, die)


t = int(input())
sy = []
ey = []
for i in range(t):
	(s, e) = map(int, input().split())
	sy.append(s)
	ey.append(e)
sy.sort(reverse=True)
ey.sort(reverse=True)
maxc = 0
c = 0
while len(sy) != 0 or len(ey) != 0:
	if len(sy) == 0:
		k = ey.pop()
	elif sy[-1] < ey[-1]:
		k = sy.pop()
		c += 1
		if c > maxc:
			maxc = c
			maxk = k
	else:
		k = ey.pop()
		if c > maxc:
			maxc = c
			maxk = k - 1
		c -= 1
print(maxk, maxc)


def findMaxGuests(arrl, exit, n):
	arrl.sort()
	exit.sort()
	guests_in = 1
	max_guests = 1
	time = arrl[0]
	i = 1
	j = 0
	while i < n and j < n:
		if arrl[i] <= exit[j]:
			guests_in = guests_in + 1
			if guests_in > max_guests:
				max_guests = guests_in
				time = arrl[i]
			i = i + 1
		else:
			guests_in = guests_in - 1
			j = j + 1
	print(time, max_guests)
t = int(input())
arrl = []
exit = []
for _ in range(t):
	(a, b) = list(map(int, input().strip().split(' ')))
	arrl.append(a)
	exit.append(b - 1)
n = len(arrl)
findMaxGuests(arrl, exit, n)


from os import path
import sys
from collections import defaultdict, Counter
maxx = float('inf')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
	I = lambda : int(sys.stdin.buffer.readline())
	tup = lambda : map(int, sys.stdin.buffer.readline().split())
	lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
	S = lambda : sys.stdin.readline().replace('\n', '').strip()
	stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
	star = lambda x: print(' '.join(map(str, x)))
else:
	I = lambda : int(sys.stdin.buffer.readline())
	tup = lambda : map(int, sys.stdin.buffer.readline().split())
	lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
	S = lambda : sys.stdin.readline().replace('\n', '').strip()
	stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
	star = lambda x: print(' '.join(map(str, x)))
d = defaultdict(int)
(m1, m2) = (-1, -1)
for _ in range(I()):
	(a, b) = tup()
	d[a] += 1
	d[b] -= 1
(m1, m2, c) = (-1, -1, 0)
for i in sorted(d):
	c += d[i]
	if c > m1:
		m1 = c
		m2 = i
print(m2, m1)


n = int(input())
dates = []
for i in range(n):
	data = input().split(' ')
	dates.append((int(data[0]), 1))
	dates.append((int(data[1]), -1))
dates.sort()
result = [0, 0]
living_people = 0
for i in range(len(dates)):
	living_people += dates[i][1]
	if result[0] < living_people:
		result[0] = living_people
		result[1] = dates[i][0]
print(f'{result[1]} {result[0]}')


import sys, math
from collections import defaultdict, deque
input = sys.stdin.readline
l = []
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, 1))
	l.append((b, -1))
l.sort()
(maxcity, maxpop) = (0, 0)
s = 0
for i in l:
	s += i[1]
	if s > maxpop:
		maxpop = s
		maxcity = i[0]
print(maxcity, maxpop)


n = int(input())
a = []
left = dict()
right = dict()
visited = set()
for i in range(n):
	(l, r) = map(int, input().split())
	if l not in left.keys():
		left[l] = 0
	if r not in right.keys():
		right[r] = 0
	left[l] += 1
	right[r] += 1
	if l not in visited:
		a.append(l)
		visited.add(l)
	if r not in visited:
		a.append(r)
		visited.add(r)
a.sort()
curr = 0
ans = 0
ans_i = 0
for i in range(len(a)):
	if a[i] in left.keys():
		curr += left[a[i]]
	if a[i] in right.keys():
		curr -= right[a[i]]
	if curr > ans:
		ans = curr
		ans_i = a[i]
print(ans_i, ans)


n = int(input())
a = []
for i in range(n):
	(l, r) = map(int, input().split())
	a.append((l, +1))
	a.append((r, -1))
a.sort()
y = -1
m = 0
c = 0
for u in a:
	c = c + u[1]
	if c > m:
		y = u[0]
		m = c
print(y, m)


n = int(input())
births = []
deaths = []
for i in range(n):
	(b, d) = map(int, input().split())
	births.append(b)
	deaths.append(d)
births = sorted(births)
deaths = sorted(deaths)
living = 0
i = 0
j = 0
year = 0
current = 0
change = 0
while i < n and j < n:
	current = min(births[i], deaths[j])
	if births[i] <= current:
		change += 1
		i += 1
	if deaths[j] <= current:
		change -= 1
		j += 1
	if change > living:
		living = change
		year = current
if i < n:
	if change + n - i + 1 > living:
		living = change + n - i + 1
		year = births[-1]
print(f'{year} {living}')


import sys

def maxOverlapInterval(intervals):
	heads = sorted([x[0] for x in intervals], reverse=True)
	tails = sorted([x[1] for x in intervals], reverse=True)
	(pos, cnt) = (0, 0)
	res = [0, 0]
	while heads and tails:
		if heads[-1] < tails[-1]:
			pos = heads.pop()
			cnt += 1
			if cnt > res[1]:
				res = [pos, cnt]
		else:
			pos = tails.pop()
			cnt -= 1
	print(f'{res[0]} {res[1]}')
n_people = int(sys.stdin.readline().strip())
intervals = []
for i in range(n_people):
	interval = [int(x) for x in sys.stdin.readline().strip().split(' ')]
	intervals.append(interval)
maxOverlapInterval(intervals)


a = []
for i in range(int(input())):
	(x, y) = map(int, input().split())
	a.append((x, 1))
	a.append((y, 0))
a.sort()
k = ans = curr = 0
for i in a:
	if i[1] == 1:
		curr += 1
	else:
		curr -= 1
	if k < curr:
		k = curr
		ans = i[0]
print(ans, k)


import sys
t = int(input())
d = dict()
lst = []
for tc in range(t):
	lst = list(map(int, input().split()))
	d[lst[0]] = d.get(lst[0], 0) + 1
	d[lst[1]] = d.get(lst[1], 0) - 1
key_set = set(d.keys())
ans = (0, 0)
alive = 0
key_set = sorted(key_set)
for i in key_set:
	alive += d[i]
	ans = (i, alive) if alive > ans[1] else ans
print(*ans)


N = int(input())
li = []
for i in range(N):
	(birth, death) = [int(x) for x in input().split(' ')]
	li.append((death, 0))
	li.append((birth, 1))
li.sort()
curr = 0
maxx = 0
year = 0
for e in li:
	if e[1] == 0:
		curr -= 1
	else:
		curr += 1
		if curr > maxx:
			maxx = curr
			year = e[0]
print(str(year) + ' ' + str(maxx))


n = int(input())
freq = dict()
for idx in range(n):
	interval = list(map(int, input().split()))
	freq[interval[0]] = freq.get(interval[0], 0) + 1
	freq[interval[1]] = freq.get(interval[1], 0) - 1
last = 0
ans = (1000000000.0 + 1, 0)
for x in sorted(freq.keys()):
	last = freq[x] = last + freq[x]
	ans = (x, last) if last > ans[1] else ans
print(*ans)


n = int(input())
births = []
deaths = []
for i in range(n):
	(b, d) = map(int, input().strip().split())
	births.append(b)
	deaths.append(d)
births.sort()
deaths.sort()
p1 = 0
p2 = 0
timeline = []
while p1 < n or p2 < n:
	if p1 < n and p2 < n:
		if births[p1] == deaths[p2]:
			p1 += 1
			p2 += 1
		elif births[p1] < deaths[p2]:
			if len(timeline) == 0 or births[p1] > timeline[-1][0]:
				timeline.append([births[p1], 1])
			else:
				timeline[-1][1] += 1
			p1 += 1
		elif births[p1] > deaths[p2]:
			if len(timeline) == 0 or deaths[p2] > timeline[-1][0]:
				timeline.append([deaths[p2], -1])
			else:
				timeline[-1][1] -= 1
			p2 += 1
	elif p1 == n:
		if deaths[p2] > timeline[-1][0]:
			timeline.append([deaths[p2], -1])
		else:
			timeline[-1][1] -= 1
		p2 += 1
	elif p2 == n:
		if births[p1] > timeline[-1][0]:
			timeline.append([births[p1], 1])
		else:
			timeline[-1][1] += 1
		p1 += 1
mx = 0
mxYear = 0
cur = 0
for i in range(len(timeline)):
	cur += timeline[i][1]
	if cur > mx:
		mxYear = timeline[i][0]
		mx = cur
print(mxYear, mx)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
n = int(input())
l = []
w = []
for i in range(n):
	(a, b) = map(int, input().split())
	l.append((a, b))
	w.append(b)
l.sort()
ans = 0
cur = 0
heapq.heapify(w)
ind = -1
for i in range(n):
	cur += 1
	(r, l1) = l[i]
	while len(w) > 0:
		e = heapq.heappop(w)
		if e <= r:
			cur -= 1
		else:
			heapq.heappush(w, e)
			break
	if cur > ans:
		ans = cur
		ind = r
print(ind, ans)


n = int(input())
vidas = []
for i in range(n):
	(a, b) = map(int, input().split())
	vidas.append([a, 1])
	vidas.append([b, -1])
vidas.sort()
maximo = [0, 0]
pos = 0
for i in range(2 * n):
	pos += vidas[i][1]
	if maximo[0] < pos:
		maximo[0] = pos
		maximo[1] = vidas[i][0]
print(maximo[1], maximo[0])


n = int(input())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append([x, 1])
	a.append([y, -1])
count = 0
max_peoplealive = 0
max_index = 0
a.sort()
for i in range(2 * n):
	count = count + a[i][1]
	if count > max_peoplealive:
		max_index = a[i][0]
		max_peoplealive = count
print(str(max_index) + ' ' + str(max_peoplealive))


import math
n = int(input())
birth = []
death = []
for i in range(n):
	(b, d) = map(int, input().split())
	birth.append(b)
	death.append(d)
birth.sort()
death.sort()
answer = [0, 0]
alive = 0
b = 0
d = 0
while b != n:
	if birth[b] < death[d]:
		b += 1
		alive += 1
		if alive > answer[0]:
			answer[0] = alive
			answer[1] = birth[b - 1]
	elif birth[b] == death[d]:
		b += 1
		d += 1
	else:
		d += 1
		alive -= 1
print(answer[1], answer[0])


n = int(input())
pop = []
for _ in range(n):
	(b, d) = map(int, input().split())
	pop.append((b, 1))
	pop.append((d, -1))
pop.sort()
maxpop = 0
counter = 0
year = 0
for i in pop:
	counter += i[1]
	if counter > maxpop:
		(maxpop, year) = (counter, i[0])
print(year, maxpop)


d = {}
for _ in range(int(input())):
	(birth, death) = map(int, input().split())
	d[birth] = d.get(birth, 0) + 1
	d[death] = d.get(death, 0) - 1
max_alive_year = 0
max_alive = 0
alive = 0
for year in sorted(d):
	alive += d[year]
	if alive > max_alive:
		max_alive = alive
		max_alive_year = year
print(max_alive_year, max_alive)


from collections import deque
from math import ceil
import sys
input = sys.stdin.buffer.readline

def print(val):
	sys.stdout.write(str(val) + '\n')
n = int(input())
a = []
for i in range(n):
	(b, d) = [int(i) for i in input().split()]
	a.append((b, 1))
	a.append((d, -1))
a.sort()
mx = k = y = 0
for i in a:
	k += i[1]
	if k > mx:
		y = i[0]
		mx = k
sys.stdout.write(str(y) + ' ' + str(mx) + '\n')


from collections import deque
n = int(input())
years = []
for i in range(n):
	vals = input().split()
	years.append((int(vals[0]), 1))
	years.append((int(vals[1]), -1))
years.sort(key=lambda x: (x[0], x[1]))
max_population = 0
population = 0
for year in years:
	if year[1] == 1:
		population += 1
		if population > max_population:
			max_population = population
			max_year = year[0]
	else:
		population -= 1
print(max_year, max_population)


n = int(input())
a = {}
for i in range(n):
	(b, d) = [int(x) for x in input().split(' ')]
	if b in a:
		a[b] += 1
	else:
		a[b] = 1
	if d in a:
		a[d] -= 1
	else:
		a[d] = -1
years = sorted(a.keys())
p = 0
m = 0
x = 0
for y in years:
	p += a[y]
	if p > m:
		x = y
		m = p
print(x, m)


n = int(input())
V = []
for i in range(n):
	(a, b) = map(int, input().split())
	V.append([a, 1])
	V.append([b, -1])
V.sort()
mx = [0, 0]
pos = 0
for i in range(2 * n):
	pos += V[i][1]
	if mx[0] < pos:
		mx[0] = pos
		mx[1] = V[i][0]
print(mx[1], mx[0])


x = []
for _ in range(int(input())):
	(a, b) = map(int, input().split())
	x.append([a, 1])
	x.append([b, -1])
x.sort()
y = []
max = -1
cur = 0
for i in range(len(x)):
	cur += x[i][1]
	if cur > max:
		max = cur
		y = x[i][0]
print(y, max)


n = int(input())
l1 = []
l2 = []
for i in range(n):
	(a, b) = map(int, input().split())
	l1.append(a)
	l2.append(b)
l1.sort()
l2.sort()
ans = 0
kk = 0
c = 0
cc = 0
i = 0
while i < n:
	if l1[i] < l2[cc]:
		c += 1
		if c > ans:
			kk = l1[i]
			ans = c
		i += 1
	else:
		cc += 1
		c -= 1
print(kk, ans)


nun = int(input())
birth = []
death = []
for i in range(nun):
	(birth_year, death_year) = map(int, input().split(' '))
	birth.append(birth_year)
	death.append(death_year)
birth.sort()
death.sort()
current_population = 0
max_population = 0
index_death = 0
max_year = 0
for i in range(nun):
	current_population += 1
	while death[index_death] <= birth[i]:
		current_population -= 1
		index_death += 1
	if current_population > max_population:
		max_population = current_population
		max_year = birth[i]
print(max_year, max_population)


n = int(input())
mp = {}
for _ in range(n):
	(a, b) = map(int, input().split())
	mp[a] = mp.get(a, 0) + 1
	mp[b] = mp.get(b, 0) - 1
cur = 0
maxi = 0
maxiy = 0
for i in sorted(mp):
	cur += mp[i]
	if cur > maxi:
		maxi = cur
		maxiy = i
print(maxiy, maxi)


numeroDePessoas = int(input())
vetor = []
maximoVIVOS = 0
maximoANO = 0
vivos = 0
for i in range(numeroDePessoas):
	(a, b) = map(int, input().split())
	vetor.append([a, 1])
	vetor.append([b, -1])
vetor = sorted(vetor)
for i in range(2 * numeroDePessoas):
	vivos += vetor[i][1]
	if vivos > maximoVIVOS:
		maximoVIVOS = vivos
		maximoANO = vetor[i][0]
print(maximoANO, maximoVIVOS)


from sys import stdin

class Input:

	def __init__(self):
		self.it = iter(stdin.readlines())

	def line(self):
		return next(self.it).strip()

	def array(self, sep=' ', cast=int):
		return list(map(cast, self.line().split(sep=sep)))

def testcases(unknown=False):
	inpt = Input()

	def testcases_decorator(func):
		(cases,) = [float('Inf')] if unknown else inpt.array()
		while cases > 0:
			try:
				func(inpt)
				cases -= 1
			except StopIteration:
				break
	return testcases_decorator

@testcases(unknown=True)
def solve(inpt):
	(n,) = inpt.array()
	a = []
	for i in range(n):
		(b, d) = inpt.array()
		a.append((b, 1))
		a.append((d, 0))
	a.sort()
	year = 0
	population = 0
	count = 0
	for (y, evt) in a:
		if evt:
			count += 1
			if count > population:
				year = y
				population = count
		else:
			count -= 1
	print(year, population)


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	births = []
	deaths = []
	for n in range(N):
		(b, d) = getInts()
		births.append(b)
		deaths.append(d)
	births.sort(reverse=True)
	deaths.sort(reverse=True)
	alive = 0
	best = -10 ** 9
	best_year = 0
	while births and deaths:
		if births[-1] == deaths[-1]:
			x = births[-1]
			while births and births[-1] == x:
				births.pop()
				alive += 1
			while deaths and deaths[-1] == x:
				deaths.pop()
				alive -= 1
		elif births[-1] < deaths[-1]:
			x = births[-1]
			while births and births[-1] == x:
				births.pop()
				alive += 1
		else:
			x = deaths[-1]
			while deaths and deaths[-1] == x:
				deaths.pop()
				alive -= 1
		if alive > best:
			best = alive
			best_year = x
	return (best_year, best)
print(*solve())


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import bisect
from collections import Counter
import bisect
from collections import deque
n = int(input())
di = {}
for i in range(n):
	(b, d) = map(int, input().split())
	di[b] = di.get(b, 0) + 1
	di[d] = di.get(d, 0) - 1
curr = 0
ma = 0
ans = 0
for i in sorted(di):
	curr += di[i]
	if curr > ma:
		ma = curr
		ans = i
print(ans, ma)


import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
yearChanges = defaultdict(lambda : 0)
n = int(input())
for _ in range(n):
	(b, d) = [int(x) for x in input().split()]
	yearChanges[b] += 1
	yearChanges[d] -= 1
yearsWithChanges = list(yearChanges.keys())
yearsWithChanges.sort()
maxpop = 0
maxpopYear = 0
pop = 0
for y in yearsWithChanges:
	pop += yearChanges[y]
	if pop > maxpop:
		maxpop = pop
		maxpopYear = y
print('{} {}'.format(maxpopYear, maxpop))


n = int(input())
a = []
for i in range(n):
	(x, y) = map(int, input().split())
	a.append([x, 1])
	a.append([y, -1])
a.sort()
total = 0
y = 0
ans = 0
for i in range(2 * n):
	total += a[i][1]
	if ans < total:
		ans = total
		y = a[i][0]
print(y, ans)


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
n = int(input())
bds = []
for i in range(n):
	(b, d) = map(int, input().split())
	bds.append((b, 1))
	bds.append((d, -1))
bds.sort(key=lambda x: (x[0], x[1]))
c = ma = 0
last = -1
for bd in bds:
	if bd[1] == 1:
		c += 1
	else:
		c -= 1
	if c > ma:
		ma = c
		last = bd[0]
print(last, ma)


from bisect import bisect_right
n = int(input())
bs = []
ds = []
for i in range(n):
	(b, d) = map(int, input().split())
	bs.append(b)
	ds.append(d)
bs.sort()
ds.sort()
maxpop = 0
bestyear = 0
for i in range(len(bs)):
	died_at_this_point = bisect_right(ds, bs[i])
	if maxpop < i + 1 - died_at_this_point:
		maxpop = i + 1 - died_at_this_point
		bestyear = bs[i]
print(bestyear, maxpop)


numPeople = int(input())
listYears = []
maxIndividuals = 0
maxYear = 0
individualAlive = 0
for i in range(numPeople):
	(yearBorn, yearDead) = map(int, input().split())
	listYears.append((yearBorn, 'B'))
	listYears.append((yearDead, 'A'))
listYears.sort()
for (j, year) in enumerate(listYears):
	if year[1] == 'B':
		individualAlive = individualAlive + 1
	else:
		individualAlive = individualAlive - 1
	if individualAlive > maxIndividuals:
		maxIndividuals = individualAlive
		maxYear = year[0]
print(maxYear, end=' ')
print(maxIndividuals)


n = int(input())
b = []
d = []
for i in range(n):
	line = [int(j) for j in input().split()]
	b.append(line[0])
	d.append(line[1])
b.sort()
d.sort()
max = [0, 0]
(j, i, bTotal) = (0, 0, 0)
while i < n and j < n:
	if b[i] == d[j]:
		(bCount, dCount) = (0, 0)
		while i + 1 < n and b[i] == b[i + 1]:
			i += 1
			bCount += 1
		while j + 1 < n and d[j] == d[j + 1]:
			j += 1
			dCount += 1
		i += 1
		j += 1
		bTotal += bCount - dCount
	elif b[i] > d[j]:
		dCount = 0
		while j < n and b[i] > d[j]:
			j += 1
			dCount += 1
		bTotal -= dCount
	elif b[i] < d[j]:
		bCount = 0
		while i < n and b[i] < d[j]:
			i += 1
			bCount += 1
		bTotal += bCount
	if max[0] < bTotal:
		max[0] = bTotal
		max[1] = b[i - 1]
print(f'{max[1]} {max[0]}')


n = int(input())
l = []
s = set()
for _ in range(n):
	(b, d) = map(int, input().split())
	l.append([b, d])
	s.add(b)
	s.add(d)
temp = list(s)
temp.sort()
mp = {i: 0 for i in temp}
for i in l:
	mp[i[0]] += 1
	mp[i[1]] -= 1
ma = [mp[temp[0]], temp[0]]
for i in range(len(temp) - 1):
	mp[temp[i + 1]] += mp[temp[i]]
	if mp[temp[i + 1]] > ma[0]:
		ma = [mp[temp[i + 1]], temp[i + 1]]
print(ma[1], ma[0])


from sys import stdin, stdout
from bisect import bisect_right, bisect_left
from math import gcd
n = int(stdin.readline())
b = []
d = []
for i in range(n):
	(a, c) = map(int, stdin.readline().split())
	b += [a]
	d += [c]
b.sort()
d.sort()
ans = 0
n = 1
prev = -1
for i in b:
	die = bisect_right(d, i)
	ans = max(ans, n - die)
	if n - die == ans and ans != prev:
		prev = ans
		k = i
	n += 1
stdout.write(str(k) + ' ' + str(ans))


n = int(input())
events = []
for _ in range(n):
	(b, d) = tuple(input().split(' '))
	b = int(b)
	d = int(d)
	events.append((b, 1))
	events.append((d, -1))
events.sort(key=lambda x: x[0])
pop_per_year = dict()
current_pop = 0
max_pop = 0
max_year = -1
for event in events:
	current_pop += event[1]
	year = event[0]
	pop_per_year[year] = current_pop
max_pop = 0
max_year = -1
for year in pop_per_year.keys():
	if pop_per_year[year] > max_pop:
		max_pop = pop_per_year[year]
		max_year = year
print(max_year, max_pop)


n = int(input())
arr = []
for i in range(n):
	(a, b) = map(int, input().split())
	arr.append((a, +1))
	arr.append((b, -1))
arr.sort()
sum = 0
max = 0
year = 0
for (a, b) in arr:
	sum += b
	if sum > max:
		max = sum
		year = a
print(year, max)


n = int(input())
y = 0
k = 0
lst = []
for i in range(n):
	(b, d) = [int(x) for x in input().split()]
	lst.append((b, 1))
	lst.append((d, -1))
lst.sort()
cont = 0
for i in range(2 * n):
	cont += lst[i][1]
	if cont > k:
		k = cont
		y = lst[i][0]
print(y, k)


from sys import stdin
input = stdin.readline

def mp():
	return map(int, input().split())

def it():
	return int(input())
n = it()
v = []
for i in range(n):
	l = list(mp())
	v.append((l[0], 1))
	v.append((l[1], -1))
v.sort()
(ans, c) = (0, 0)
for i in v:
	c += i[1]
	if ans < c:
		(ans, y) = (c, i[0])
print(y, ans)


def main():
	iloL = int(input())
	ur = [0] * iloL
	zm = [0] * iloL
	wsu = 0
	wsz = 0
	wyn = [0, 0]
	akt = 0
	for i in range(iloL):
		(ur[i], zm[i]) = list(map(int, input().split()))
	ur.sort()
	zm.sort()
	while wsu != iloL:
		if ur[wsu] < zm[wsz]:
			akt += 1
			if wyn[1] < akt:
				wyn[1] = akt
				wyn[0] = ur[wsu]
			wsu += 1
		else:
			akt -= 1
			wsz += 1
	print(*wyn)
main()


import os
import sys
from io import BytesIO, IOBase
import math
from collections import defaultdict, deque
from itertools import combinations
import random
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
l = []
for _ in range(int(input())):
	(a, b) = map(int, input().split(' '))
	l.append((a, 1))
	l.append((b, -1))
l.sort()
c = y = m = 0
for i in l:
	c += i[1]
	if c > m:
		m = c
		y = i[0]
print(y, m)


events = {}
for _ in range(int(input())):
	(birthyear, deathyear) = map(int, input().split())
	if birthyear not in events:
		events[birthyear] = 0
	if deathyear not in events:
		events[deathyear] = 0
	events[birthyear] += 1
	events[deathyear] -= 1
count = 0
best_count = 0
best_year = 0
for year in sorted(events):
	count += events[year]
	if count > best_count:
		best_count = count
		best_year = year
print(best_year, best_count)


from sys import stdout, stdin, setrecursionlimit
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from bisect import *
from string import *
from queue import *
from heapq import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = getInt()
lst = []
for i in range(n):
	(x, y) = zzz()
	lst.append((x, 1))
	lst.append((y, -1))
lst = sorted(lst)
(ans, c) = (0, 0)
for i in lst:
	c += i[1]
	if ans < c:
		(ans, y) = (c, i[0])
print(y, ans)


import sys, functools, collections, bisect, math, heapq
input = sys.stdin.readline
sys.setrecursionlimit(300000)
for _ in range(1):
	n = int(input())
	birth = collections.Counter()
	for i in range(n):
		(b, d) = map(int, input().strip().split())
		birth[b] += 1
		birth[d] -= 1
	arr = list(birth.items())
	arr.sort()
	curr = 0
	ans = 0
	year = 0
	for (y, c) in arr:
		curr += c
		if curr > ans:
			ans = curr
			year = y
	print(year, ans)


n = int(input())
book = []
for i in range(n):
	(b, d) = map(int, input().split())
	book.append((b, 1))
	book.append((d, -1))
book = sorted(book)
peop = 0
y = -10 ** 11
k = 0
for elem in book:
	peop += elem[1]
	if peop > k:
		k = peop
		y = elem[0]
print(y, k)


n = int(input())
peopleMap = {}
keys = []
for i in range(n):
	info = [int(i) for i in input().split()]
	if info[0] not in peopleMap:
		peopleMap[info[0]] = 1
		keys.append(info[0])
	else:
		peopleMap[info[0]] += 1
	if info[1] not in peopleMap:
		peopleMap[info[1]] = -1
		keys.append(info[1])
	else:
		peopleMap[info[1]] -= 1
amount = 0
max = 0
keys.sort()
for i in keys:
	amount += peopleMap[i]
	if amount > max:
		max = amount
		max_year = i
print(max_year, max)


years = {}
for k in range(int(input())):
	(b, d) = map(int, input().split())
	if b in years:
		years[b] += 1
	else:
		years[b] = 1
	if d in years:
		years[d] -= 1
	else:
		years[d] = -1
keys = sorted(years.keys())
maxLiving = 0
maxCount = 0
cur = 0
for year in keys:
	cur += years[year]
	if cur > maxCount:
		maxLiving = year
		maxCount = cur
print(maxLiving, maxCount)


l1 = []
for i in range(int(input())):
	(a, b) = map(int, input().split())
	l1.append((a, 1))
	l1.append((b, -1))
l1.sort()
ans = year = temp = 0
for i in l1:
	temp += i[1]
	if temp > ans:
		(ans, year) = (temp, i[0])
print(year, ans)


num = int(input())
a = dict()
for i in range(num):
	(b, d) = map(int, input().split())
	if b in a:
		a[b] += 1
	else:
		a[b] = 1
	if d in a:
		a[d] -= 1
	else:
		a[d] = -1
y = sorted(a.keys())
al = 0
n = 0
c = 0
for i in y:
	al += a[i]
	if al > n:
		c = i
		n = al
print(c, n)


from collections import defaultdict
n = int(input())
anos = defaultdict(int)
for i in range(n):
	(b, d) = map(int, input().split())
	anos[b] += 1
	anos[d] -= 1
max_vivos = 0
max_ano = 0
vivos = 0
for ano in sorted(anos.keys()):
	vivos += anos[ano]
	if vivos > max_vivos:
		max_vivos = vivos
		max_ano = ano
print(max_ano, max_vivos)


numPeople = int(input())
mapR = {}
for _ in range(numPeople):
	temp = [int(x) for x in input().split()]
	birth = temp[0]
	death = temp[1]
	if birth not in mapR:
		mapR[birth] = 1
	else:
		mapR[birth] += 1
	if death not in mapR:
		mapR[death] = -1
	else:
		mapR[death] -= 1
years = sorted(mapR.keys())
currPeople = 0
maxPeople = 0
maxYear = 0
for year in years:
	currPeople += mapR[year]
	if currPeople > maxPeople:
		maxPeople = currPeople
		maxYear = year
print(str(maxYear) + ' ' + str(maxPeople))


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = defaultdict(int)
for i in range(n):
	(x, y) = value()
	a[x] += 1
	a[y] -= 1
a = [(i, a[i]) for i in a]
a.sort()
MA = 0
y = -1
cur = 0
for (c, f) in a:
	cur += f
	if cur > MA:
		MA = cur
		y = c
print(y, MA)


import os, io, sys, time, collections, math, pprint, itertools as it, operator as op, bisect as bs, functools as fn
(maxx, localsys, mod) = (float('inf'), 0, int(1000000000.0 + 7))
nCr = lambda n, r: reduce(mul, range(n - r + 1, n + 1), 1) // factorial(r)
ceil = lambda n, x: (n + x - 1) // x
(osi, oso) = ('/home/priyanshu/Documents/cp/input.txt', '/home/priyanshu/Documents/cp/output.txt')
if os.path.exists(osi):
	sys.stdin = open(osi, 'r')
	sys.stdout = open(oso, 'w')
input = sys.stdin.readline

def maps():
	return map(int, input().split())
n = int(input())
d = collections.defaultdict(int)
for _ in range(n):
	(a, b) = maps()
	d[a] += 1
	d[b] -= 1
a = sorted(d.keys())
(peoplealive, year, s) = (0, 0, 0)
for i in a:
	s += d[i]
	if s > peoplealive:
		peoplealive = s
		year = i
print(year, peoplealive)