Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. 

For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In the end, Polycarpus got a list of n tasks that went to the SMSC of the corporation. Each task was described by the time it was received by the SMSC and the number of text messages to send. More formally, the i-th task was described by two integers t_{i} and c_{i} — the receiving time (the second) and the number of the text messages, correspondingly.

Polycarpus knows that the SMSC cannot send more than one text message per second. The SMSC uses a queue to organize its work. Consider a time moment x, the SMSC work at that moment as follows:

  If at the time moment x the queue is not empty, then SMSC sends one message from the queue (SMSC gets the message from the head of the queue). Otherwise it doesn't send messages at the time moment x.  If at the time moment x SMSC receives a task, then it adds to the queue all the messages from this task (SMSC adds messages to the tail of the queue). Note, that the messages from the task cannot be send at time moment x. That's because the decision about sending message or not is made at point 1 before adding these messages to the queue. 

Given the information about all n tasks, Polycarpus wants to count two values: the time when the last text message was sent and the maximum size of the queue at some time. Help him count these two characteristics he needs to evaluate the efficiency of the SMSC.


-----Input-----

The first line contains a single integer n (1 ≤ n ≤ 10^3) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers t_{i} and c_{i} (1 ≤ t_{i}, c_{i} ≤ 10^6) — the time (the second) when the i-th task was received and the number of messages to send, correspondingly.

It is guaranteed that all tasks were received at different moments of time. It is guaranteed that the tasks are sorted in the chronological order, that is, t_{i} < t_{i} + 1 for all integer i (1 ≤ i < n).


-----Output-----

In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.


-----Examples-----
Input
2
1 1
2 1

Output
3 1

Input
1
1000000 10

Output
1000010 10

Input
3
3 3
4 3
5 3

Output
12 7



-----Note-----

In the first test sample: 

  second 1: the first message has appeared in the queue, the queue's size is 1;  second 2: the first message is sent, the second message has been received, the queue's size is 1;  second 3: the second message is sent, the queue's size is 0, 

Thus, the maximum size of the queue is 1, the last message was sent at the second 3.

Difficulty: interview

Starter code:

Solutions:
import re
import itertools
from collections import Counter, deque

class Task:
    tasks = []
    answer = "" 
	
    def getData(self):
        numberOfTasks = int(input())
        for i in range(0, numberOfTasks):
            self.tasks += [[int(x) for x in input().split(' ')]]
        #inFile = open('input.txt', 'r')
        #inFile.readline().rstrip()
        #self.childs = inFile.readline().rstrip()

    def solve(self):
        queueSize, maxQueueSize = 0, 0
        time, timeOfLastMessage = 1, 1
        currentTask = 0
        while currentTask < len(self.tasks) or queueSize > 0:
            maxQueueSize = max(maxQueueSize, queueSize)
            if currentTask < len(self.tasks):
                timeDelta = self.tasks[currentTask][0] - time
                queueSize -= min(queueSize, timeDelta)
                time += timeDelta
            else:
                timeOfLastMessage = time + queueSize
                break
                
            if currentTask < len(self.tasks) and \
                    self.tasks[currentTask][0] == time:
                queueSize += self.tasks[currentTask][1]
                currentTask += 1
        self.answer = str(timeOfLastMessage) + " " + str(maxQueueSize)

    def printAnswer(self):
        print(self.answer)
        #outFile = open('output.txt', 'w')
        #outFile.write(self.answer)

task = Task()
task.getData()
task.solve()
task.printAnswer()


n = int(input())

mt = 0
mq = 0

t = 0
q = 0

for i in range(n):
    (ti, ci) = list(map(int, input().split()))
    q = max(0, q-ti+t)
    t = ti
    q += ci
    mq = max(mq, q)
    mt = t+q

print(mt, mq)


n = int(input())
q = max_q = t0 = 0
for i in range(n):
  t, c = map(int, input().split())
  q = max(0, q - t + t0) + c
  if q > max_q:
    max_q = q
  t0 = t
print(t0 + q, max_q)

n = int(input())
ans, p, s = 0, 0, 0
for i in range(n):
    t, c = map(int, input().split())
    s -= min(s, t - p)
    p = t
    s += c
    if s > ans: ans = s
print(p + s, ans)

import sys
import math

n = int(input())

a, b = list(map(int, input().split()))
vmax = b
for i in range(1, n):
    c, d = list(map(int, input().split()))
    b = max(0, b - (c - a))
    a = c
    b += d
    vmax = max(b, vmax)

print(a + b, vmax)


pt, s, vs = 0, 0, 0
for i in range(int(input())):
    t, c = map(int, input().split())
    s = max(s - (t - pt), 0) + c
    vs = max(vs, s)
    pt = t
print(pt + s, vs)

n = int(input())

q = max_q = t0 = 0

for i in range(n):

  t, c = map(int, input().split())

  q = max(0, q - t + t0) + c

  if q > max_q:

    max_q = q

  t0 = t

print(t0 + q, max_q)

n = int(input())
ct = 0
cq = 0
mcq = 0

for i in range(n):
	t, c = list(map(int, input().split()))
	mcq = max(cq, mcq)	
	cq = max(cq - (t - ct), 0)
	cq += c
	ct = t
	#print(cq)
	

mcq = max(cq, mcq)
ct += cq
print(ct, mcq)	


n = int(input())

que = []

for i in range(n):
    t, c = map(int, input().split())
    que += [[t, c]]


numMessages = None
lasReceive = None

maxQ, end = None, None
for i, q in enumerate(que):
    if numMessages == None:
        numMessages = q[1]
        lasReceive = q[0]
        maxQ = numMessages
    
    else:
        numMessages = max(numMessages - (q[0] - lasReceive), 0) + q[1]

        lasReceive = q[0]
    maxQ = max(maxQ, numMessages)
    if i == n - 1:
        print(lasReceive + numMessages, end=' ')
        print(maxQ, end=' ')
        
        
    

r = lambda: int(input())
ra = lambda: [*list(map(int, input().split()))]
a = []
t, q, mq, s = 0, 0, 0, 0
n = r()
for i in range(n):
    a.append(ra())
for i in range(n):
    if i==0:
        q = a[i][1]
        t = a[i][0]
    else:
        s = a[i][0] - t
        q-=s
        if q<0:
            q = 0
        q+=a[i][1]
    if q>mq:
        mq = q
    t = a[i][0]
t = a[i][0]+q
print(t, mq)


n = int(input())
a1,a2 = 0,0
r = 0
for _ in range(n):
    b1,b2 = list(map(int,input().split()))
    a2 = max(0,a2-(b1-a1))+b2
    r = max(r,a2)
    a1 = b1
print(a1+a2,r)



n=int(input())
a,b=map(int,input().split())
l=b
x=a
q=0
m=0
m=max(m,l)
for i in range(n-1):
	a,b=map(int,input().split())
	l-=(a-x)
	l=max(l,0)
	l+=b
	m=max(m,l)
	x=a
print("{} {}".format(x+l,m))

Messages, Max, Last = 0, 0, 0
for i in range(int(input())):
    X = list(map(int, input().split()))
    Messages = max(0, Messages - (X[0] - Last))
    Messages += X[1]
    Max = max(Messages, Max)
    Last = X[0]
print(Last + Messages, Max)

# UB_CodeForces
# Advice: Falling down is an accident, staying down is a choice
# Location: Mashhad for few days
# Caption: Finally happened what should be happened
# CodeNumber: 692


n = int(input())

message = 0
m = 0
l = 0

for _ in range(n):
    t, c = list(map(int, input().split()))
    message = max(0, message-(t-l))
    message += c
    m = max(message, m)
    l = t

print(l+message, m)
    


n = int(input())
l = []
for i in range(n):
	c,t = list(map(int,input().split()))
	l.append((c,t))
queue = l[0][1]
z = queue
for i in range(1,n):
	queue = queue - min((l[i][0]-l[i-1][0]),queue)
	queue = queue + l[i][1]
	z = max(z,queue)
print(l[-1][0]+queue,z)



max_q = q = 0
t0 = 0

for _ in range(int(input())):
    t, c = map(int, input().split())
    q = max(0, t0-t+q) + c
    max_q = max(q, max_q)
    t0 = t

print(t+q, max_q)

import sys
import math

#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print fast
pt = lambda x: sys.stdout.write(str(x)+'\n')

#--------------------------------WhiteHat010--------------------------------------#
n = get_int()
prev_t,s = get_int_list()
mx_q = s
q_size = s

for i in range(n-1):
    t,s = get_int_list()
    diff = t-prev_t
    q_size = max(0,q_size - diff) 
    q_size = q_size + s
    mx_q = max(mx_q, q_size)
    prev_t = t
print(prev_t+q_size, mx_q)

n = int(input())
arr = []
for _ in range(n):
    arr.append([int(i) for i in input().split()])
arr.sort(key=lambda x: x[0])
queue_size = 0
time = 0
max_queue_size = 0
last_time = 0
for t, c in arr:
    # print("Queue:", queue_size, "Time:", time)
    sent = t - last_time
    queue_size = max(0, queue_size - sent)
    queue_size += c
    time = t
    max_queue_size = max(max_queue_size, queue_size)
    last_time = time
print(time + queue_size, max_queue_size)