haunted
Source: hackerearth
Difficulty: EASY

The king of ghosts is really disappointed when he sees that all the human beings on Planet Earth have stopped fearing the ghost race. He knows the reason for this. The existing ghost race has become really lazy and has stopped visiting Planet Earth to scare the human race. Hence, he decides to encourage the entire ghost race into scaring the humans by holding a competition. The king, however, never visits Planet Earth.

This competition will go on for N days. Currently, there are a total of M ghosts (apart from the king) existing in the ghost race such that :
- The youngest ghost is 1 year old.
- The oldest ghost is M years old.
- No two ghosts have the same age.
- The age of each and every ghost is a positive integer.

On each day of the competition, ghosts have to visit Planet Earth to scare people. At the end of each day, a "Ghost of the Day" title is awarded to the ghost who scares the most number of humans on that particular day. However, the king of ghosts believes in consistency. Once this title has been given, the ghost who has won the most number of such titles until that particular moment is presented with a "Consistency Trophy". If there are many such ghosts, the oldest among them is given the trophy. Note that this "Title Giving" and "Trophy Giving" happens at the end of each day of the competition.

You will be given the age of the ghost who won the "Ghost of the Day" title on each day of the competition. Your job is to find out the age of the ghost who was awarded with the "Consistency Trophy" on each day of the competition.  

Input
The first line consists of 2 space separated integers N and M. The next line consists of N space separated integers such that the i^th integer denotes the age of the ghost who was awarded with the "Ghost of the Day" title on the i^th day of the competition.  

Output
Print N lines. The i^th line should contain 2 space separated integers such that the first integer denotes the age of the ghost who was awarded with the "Consistency Trophy" on the i^th day and the second integer denotes the number of "Ghost of the Day" titles won by this ghost until the end of the i^th day of the competition.  

Constraints
1 ≤ N ≤ 10^5
1 ≤ M ≤ 10^9

SAMPLE INPUT
7 5
1 3 1 3 2 2 2

SAMPLE OUTPUT
1 1
3 1
1 2
3 2
3 2
3 2
2 3


import sys

def fun():
	n, m = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
	a = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]
	count = { }
	
	maxm=a[0]
	
	for i in range(0,n):
		if a[i] not in count:
			count[a[i]]=1
		else:			
			count[a[i]]+=1
		
		if (count[a[i]]>count[maxm]) or (count[a[i]]==count[maxm] and a[i]>maxm):
			maxm=a[i]
		print("{0} {1}".format(maxm, count[maxm]))
if __name__ == "__main__":
    fun()


N,M=list(map(int,input().split()))
arr = input().split()
reqdict = {}
currage = arr[0]
currcount = 1
reqdict[currage] = currcount
print(currage + " " + str(currcount))

for i in range(1,N):
	arri=arr[i]
	if(arri==currage):
		reqdict[currage]+=1
		currcount+=1		
	else:
		if(arri not in reqdict):
			reqdict[arri] = 1
		else:
			reqdict[arri] += 1
			
		if(currcount == reqdict[arri]):
			if(int(currage)<int(arri)):				
				currage = arri
				currcount = reqdict[arri]
		elif(currcount<reqdict[arri]):
			currage = arri
			currcount = reqdict[arri]	
	print(currage + " " + str(currcount))	
		


m,n=list(map(int,input().split()))
ar=[int(i) for i in input().split()]
dic={}
maxCount = 0
maxAge = 0
for i in ar:
	if dic.get(i):
		dic[i]+=1
	else:
		dic[i]=1
	if dic[i]>maxCount:
		maxCount=dic[i]
		maxAge=i
	elif dic[i]==maxCount and i>maxAge:
		maxAge=i
	
	print(maxAge,maxCount)
		


N, M = list(map(int,input().split()))
G = [int(i) for i in input().split()]
maxCount = 0
maxAge = 0
ageCount = {}
for age in G:
	if age in ageCount:
		ageCount[age] = ageCount[age] + 1
	else:
		ageCount[age] = 1
	if ageCount[age] > maxCount:
		maxCount = ageCount[age]
		maxAge = age
	elif ageCount[age] == maxCount and age > maxAge:
			maxAge = age
	print(maxAge,maxCount)


Input = input()
IN = Input.split(' ')
N = int(IN[0])
M = int(IN[1])
Input = input().split(' ')
IN = []
for i in Input :
	IN.append(int(i))
max_win = 0
consitency_trophy = 0
d = dict() 
for j in IN :
	if (j in d) == True :
		d[j] = d[j] + 1
	else :
		d.update({j : 1})
	if max_win < d[j] :
		max_win = d[j]
		consitency_trophy = j
	elif max_win == d[j] :
		if j > consitency_trophy :
			consitency_trophy = j
	print(("%d %d" % (consitency_trophy,max_win)))



'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
[n, m]=[int(x) for x in input().split()]

L={}
c=0
max=0
s=input()
X=[int(x) for x in s.split()]
for i in range(n):
	e=X[i]
	if e not in L:
		L[e]=1
	else:
		L[e]+=1
	if L[e]>=max:
		if L[e]>max:
			max=L[e]
			c=e
		else:
			if e>c:
				c=e
	print(c, max)
	


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
inputs=[int(i) for i in input().split()]
N=inputs[0]
M=inputs[1]
ages=[int(i) for i in input().split()]

hash_ages=dict()
P_age=0
P_title=0
for age in ages:
	if hash_ages.__contains__(age):
		hash_ages[age]+=1
	else:
		hash_ages[age]=1
	
	if hash_ages[age] == P_title :
		if age < P_age :
			print(P_age,P_title)
		else:
			print(age,hash_ages[age])
			P_age=age
			P_title=hash_ages[age]
	elif hash_ages[age] < P_title :
		print(P_age,P_title)
	else:
		print(age,hash_ages[age])
		P_age=age
		P_title=hash_ages[age]


'''
# Read input from stdin and provide input before running code

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
[n, m]=[int(x) for x in input().split()]

L={}
c=0
max=0
s=input()
X=[int(x) for x in s.split()]
for i in range(n):
	e=X[i]
	if e not in L:
		L[e]=1
	else:
		L[e]+=1
	if L[e]>=max:
		if L[e]>max:
			max=L[e]
			c=e
		else:
			if e>c:
				c=e
	print(c, max)
	


nm = list(map(int,input().split(' ')));
n = nm[0];
m = nm[1];
arrs = list(map(int,input().split(' ')));
mapper = {};
mapper[arrs[0]]=1;
max1 = 1;
maxa = arrs[0];
print(str(arrs[0])+' '+str(1))
for i in range(1,len(arrs)):
	if(arrs[i] in mapper):
		mapper[arrs[i]] = mapper[arrs[i]]+1;
	else:
		mapper[arrs[i]] = 1;
	if(mapper[arrs[i]]>max1 or (mapper[arrs[i]]==max1 and arrs[i]>maxa)):
		max1 = mapper[arrs[i]]
		maxa = arrs[i];
	print(str(maxa)+' '+str(max1));






from collections import Counter
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
d = Counter()
mv = -1
mq = []
for i in a:
	d[i] += 1
	if d[i] > mv:
		mv = d[i]
		mq = [i]
	elif d[i] == mv:
		mq.append(i)
	print(max(mq), mv)
	


import operator
ls = list(map(int,input().split()))
n = ls[0]
m = ls[1]
lst = list(map(int,input().split()))
d = {}
key=0
maxval=0
for num in lst:
	d[num] = d.get(num,0) + 1
	tmp = d[num]
	if key == 0 or (tmp > maxval) or (tmp == maxval and num>key):
		key=num
		maxval=d[num]

	#sorted_x = sorted(d.items(), key=operator.itemgetter(1,0), reverse=True)

	print(str(key) + " " + str(maxval))