1 '''
2 Sorts are guaranteed to be stable.
3 That means that when multiple records have the same key,
4 their original order is preserved.
5 所以,按相同分数排列自然先录入的参数先排在前,不需要做特殊处理
6 '''
7 import sys
8 a=[]
9 for line in sys.stdin:
10 a.append(line.strip().split())
11 if line=='\n':
12 break
13 b=a[2:]
14 if a[1][0]=='0':
15 highfirst=True
16 else:
17 highfirst=False
18 b=sorted(b, key= lambda x: int(x[1]), reverse=highfirst)
19 for i in b:
20 print(" ".join(i))
21 '''
22 排序要用int排序,
23 否则出错,如下面例子
24 a=['3','0',['kfgse', '42'],
25 ['vkg', '3'],
26 ['oeipw', '26'],
27 ['os', '25']]
28 '''