the-monk-and-class-marks
Source: hackerearth
Difficulty: EASY

Monk is a multi-talented person, and prepares results for his college in his free time. (Yes, he is still in love with his old college!)  He gets a list of students with their marks. The maximum marks which can be obtained in the exam is 100.

The Monk is supposed to arrange the list in such a manner that the list is sorted in decreasing order of marks. And if two students have the same marks, they should be arranged in lexicographical manner.

Help Monk prepare the same!

Input format:
On the first line of the standard input, there is an integer  N, denoting the number of students. N lines follow, which contain a string and an integer, denoting the name of the student and his marks.

Output format:
You must print the required list.

Constraints:
1 ≤ N ≤ 10^5
1 ≤ | Length of the name | ≤ 100  
1 ≤ Marks ≤ 100

SAMPLE INPUT
3
Eve 78
Bob 99
Alice 78

SAMPLE OUTPUT
Bob 99
Alice 78
Eve 78


def solve(xs):
	return '\n'.join('{} {}'.format(*x) for x in sorted(xs, key=lambda x: (-int(x[1]), x[0])))

if __name__ == '__main__':
	print(solve([input().split() for _ in range(int(input()))]))


arr=[]
for _ in range(eval(input())):
	a=list(map(str,input().split()))
	a[1]=int(a[1])
	a=a[::-1]
	arr.append(a)
	
arr=sorted(arr,reverse=True)
#arr=sorted(arr,key=
#print arr
art=sorted(arr,key=lambda arr:arr[0])
#print art
art=art[::-1]
for item in art:
	
	item=item[::-1]
	
	for it in item:
		print(it, end=' ')
	print("")


# parallel sort

import operator

N       = int(input())

My_list = []

for i in range(N):
	name,marks  = [x for x in input().split()]
	marks       =  int(marks)
	My_list.append((name,marks))

My_list.sort(key=operator.itemgetter(0))
My_list.sort(key=operator.itemgetter(1),reverse=True)

for tupli in My_list:
	print(tupli[0],tupli[1])


noofstudents = int(input())
studenthash = {}

def processRecord(record):
	(name, marks) = record.split()
	marks = int(marks)
	if marks in studenthash:
		studenthash[marks].append(name)
	else:
		studenthash[marks] = [name]

count = 0
while count < noofstudents:
	record = input()
	processRecord(record)
	count += 1

markslist = list(studenthash.keys())
markslist.sort(reverse=True)
for marks in markslist:
	names = studenthash[marks]
	if len(names) > 1:
		names.sort()
	for name in names:
		print(("{} {}".format(name, marks)))


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
#import operator
N = int(input())
classroom = {}
for x in range(N):
	inp = input().split()
	if int(inp[1]) in classroom:
		classroom[int(inp[1])].append(inp[0])
	else:
		classroom[int(inp[1])] = []
		classroom[int(inp[1])].append(inp[0])
#print classroom
marks = sorted(list(classroom.keys()), reverse = True)
#print marks
for num in marks:
	names = sorted(classroom[num])
	for val in names:
		print(val + " " + str(num))
#sorted_x = sorted(classroom.items(), key=operator.itemgetter(1), reverse = True)


from sys import stdin
di = {}
x = stdin.readline()
a = stdin.readlines()
for i in a:
	m,n = i.split()
	n = int(n)
#	print "looking ",n," for ",di
	b = di.get(n,[])
	b.append(m)
	di[n] = b
l = list(di.keys())

l.sort()

n = len(l)
for i in range(n):
	cur = l[n-1-i]
	b = di[cur]
	b.sort()
	for j in b:
		print(j,cur)


n = int(input())

l = []
for t in range(n):
	name, marks = input().split()
	marks = int(marks)
	l.append((marks*-1, name))

l.sort()

for item in l:
	print(item[1], item[0]*-1)


__author__ = "Sankar"

def start():
	n = eval(input())
	i = []
	while n != 0:
		l = input().split(" ")
		l[1] = int(l[1])
		i.append(l)
		n -= 1
	i = sorted(i, key=lambda i:i[1])
	i.sort(key=lambda i:i[0])
	i.sort(key=lambda i:i[1], reverse=True)
	for x in range(len(i)):
		print(i[x][0], i[x][1])

if __name__ == "__main__":
	start()


num=eval(input())
lst_mark={}
lst=[[] for i in range(101)]
for _ in range(num):
	a,b=input().split()
	lst[int(b)].append(a)
for i in range(1,101):
	lst[101-i].sort()
	for j in lst[101-i]:
		print(j,101-i)
		
	


marks_map={}
for i in range(int(input())):
	name,marks=input().split()
	marks=int(marks)
	if marks in list(marks_map.keys()) :
		marks_map[marks].append(name)
	else:
		marks_map[marks]=[name]
for m in sorted(list(marks_map.keys()),reverse=True):
	for n in sorted(marks_map[m]):
		print(n,m)


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
N = int(input())
if (N<0 or N>100000):
	sys.exit()

marks_map = {}
for i in range(N):
	(name, marks) = input().split()
	marks = int(marks)
	if (marks in marks_map):
		marks_map[marks].append(name)
	else:
		marks_map[marks] = [name]
for m in sorted(list(marks_map.keys()), reverse = True):
	for n in sorted(marks_map[m]):
		print(n, m)
	



from operator import itemgetter as it
ary = sorted( [(name, int(marks)) for k in range(eval(input())) for name, marks in [input().split()]], key = it(0) )
for i in sorted(ary, key = it(1), reverse = True):
	print(i[0], i[1])
	
	


lis = []
for i in range(int(input())):
	name,marks = input().split()
	marks = int(marks)
	lis.append((name,marks))

lis.sort(key=lambda t:(-t[1],t[0]))

for li in lis:
	print(li[0],li[1])


t = int(input())
A = []
for i in range(t):
	N,M = input().split(' ')
	M = int(M)
	A.append([N,M])

A = sorted(A, key=lambda x: x[1], reverse=True)
#print A
l = len(A)
#print l
i = 0
while i < l:
	j = i+1
	temp = [A[i]]
	while j < l and A[i][1] == A[j][1]:
		temp.append(A[j])
		j = j+1
	temp = sorted(temp, key=lambda x: x[0])
 	#pr/int temp
 	if i == j:
 		print(A[i][0], A[i][1])
 	for k in temp:
 		print(k[0], k[1])
	i = j	


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

name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys
def compare(x,y):
	if x[1] > y[1] or (x[1] == y[1] and x[0] < y[0]):
		return -1
	return 1
	
N = int(sys.stdin.readline())
stud = []
for i in range(N):
	line = sys.stdin.readline().split()
	stud.append((line[0],int(line[1])))

stud = sorted(stud,cmp=compare)
#print stud
for tup in stud:
	print(tup[0],tup[1])


import sys
def getItem(c):
	return (-c[1],c[0])

n=int(input())
a=[]
m=n
while(n>0):
	name,marks=list(map(str,sys.stdin.readline().split(" ")))
	a.append((name,int(marks)))
	n-=1
a.sort(key=getItem,reverse=False)

for i in range(0,m):
	print(a[i][0],a[i][1])


import sys
def getItem(c):
	return (-c[1],c[0])

n=int(input())
a=[]
m=n
while(n>0):
	name,marks=list(map(str,sys.stdin.readline().split(" ")))
	a.append((name,int(marks)))
	n-=1
a.sort(key=getItem,reverse=False)

for i in range(0,m):
	print(a[i][0],a[i][1])


t = int(input())
d={}
while t>0:
	val=input().split()
	if int(val[1]) in d:
		d[int(val[1])].append(val[0])
	else:
		d.setdefault(int(val[1]), [])
		d[int(val[1])].append(val[0])	
	t-=1
for key,value in sorted(iter(d.items()),key=lambda k_v: -k_v[0]):
		value.sort()
		for x in value:
			print(x,key)		 



__author__ = 'srikanth'
d = []
for _ in range(int(input())):
	N, M = input().split()
	d.append((N, int(M)))
for w in sorted(d, key=lambda x: (-x[1], x[0])):
	print(w[0], w[1])


n=eval(input())
i=0
s=[]

while i<n:
	s.append(input().split())
	s[i][1]=int(s[i][1])
	i+=1
	
s=sorted(s,key=lambda l:l[1], reverse=True)
newlist, dicpos = [],{}
for val,k in s:
	if k in dicpos:
		newlist[dicpos[k]].append(val)
	else:
		newlist.append([val])
		dicpos[k] = len(dicpos)

i=0
temp=[]
while i<len(newlist):
	newlist[i].sort()
	j=0
	while j<len(newlist[i]):
		temp.append(newlist[i][j])
		j+=1
	i+=1

i=0
while i<n:
	print(temp[i],s[i][1])
	i+=1
   


from operator import itemgetter
names = []

def compare(a, b):
#	print a, b
	if a[1] == b[1]: return 1 if a[0] > b[0] else -1
	return b[1] - a[1]
	
for tc in range(eval(input())):
	a, b = input().split()
	names.append((a, int(b)))

for name, marks in sorted(names, cmp=compare):
	print(name, marks)

#print 'bnupam' > 'anu'