Given the names and grades for each student in a class of $N$ students, store them in a nested list and print the name(s) of any student(s) having the second lowest grade.

Note: If there are multiple students with the second lowest grade, order their names alphabetically and print each name on a new line.

Example 

$records=[\text{"chi"},20.0],[\text{"beta"},50.0],[\text{"alpha"},50.0]]$

The ordered list of scores is $[20.0,50.0]$, so the second lowest score is $50.0$.  There are two students with that score: $[\text{"beta"},\text{"alpha"}]$.  Ordered alphabetically, the names are printed as:

alpha
beta

Input Format

The first line contains an integer, $N$, the number of students. 

The $2N$ subsequent lines describe each student over $2$ lines. 

- The first line contains a student's name. 

- The second line contains their grade. 

Constraints

$2\leq N\leq5$  
There will always be one or more students having the second lowest grade. 

Output Format

Print the name(s) of any student(s) having the second lowest grade in. If there are multiple students, order their names alphabetically and print each one on a new line.

Sample Input 0
5
Harry
37.21
Berry
37.21
Tina
37.2
Akriti
41
Harsh
39

Sample Output 0
Berry
Harry

Explanation 0

There are $5$ students in this class whose names and grades are assembled to build the following list:

python
students = [['Harry', 37.21], ['Berry', 37.21], ['Tina', 37.2], ['Akriti', 41], ['Harsh', 39]]

The lowest grade of $37.2$ belongs to Tina. The second lowest grade of $37.21$ belongs to both Harry and Berry, so we order their names alphabetically and print each name on a new line.

Difficulty: EASY
Tags: Data structures
Skill types: Data structures

Starter code:

Solutions:
data = [[input(), float(input())] for i in range(int(input()))]

def find_lowest_scores():
	lowest_score = data[0][1]
	students_with_lowest_grades = []
	for student in data:
		if student[1] < lowest_score:
			lowest_score = student[1]
			students_with_lowest_grades = [student]
		elif student[1] == lowest_score:
			students_with_lowest_grades.append(student)
	return sorted(students_with_lowest_grades)
for student in find_lowest_scores():
	data.remove(student)
for student in find_lowest_scores():
	print(student[0])


def __starting_point():
	students = []
	for _ in range(int(input())):
		name = input()
		score = float(input())
		students.append([name, score])
	lowest = min([el[1] for el in students])
	second_low = min(list([a for a in [el[1] for el in students] if a > lowest]))
	out = [el[0] for el in students if el[1] == second_low]
	out.sort()
	print('\n'.join(out))
__starting_point()


from operator import itemgetter
n = int(input())
studs = []
while n != 0:
	name = input()
	marks = float(input())
	studs.append([name, marks])
	n -= 1
studs.sort(key=itemgetter(1))
stud = []
x = 0
flag = 0
for k in studs:
	if flag == 0:
		x = k[1]
		flag += 1
	if k[1] > x and flag == 1:
		x = k[1]
		flag += 1
	if flag == 2 and k[1] > x:
		break
	if flag == 2:
		stud.append(k[0])
stud.sort(key=itemgetter(0))
for k in stud:
	print(k)


grades = dict()
for _ in range(int(input())):
	name = input()
	grade = float(input())
	students = grades.get(grade, [])
	students.append(name)
	grades[grade] = students
for (i, (grade, names)) in enumerate(sorted(grades.items(), key=lambda i: i[0])):
	if i == 1:
		for name in sorted(names):
			print(name)
	elif i > 1:
		break


from operator import itemgetter
n = int(input())
students = []
for _ in range(n):
	students.append([input(), float(input())])
students.sort(key=itemgetter(1))
mark = students[0][1]
for s in students:
	if s[1] != mark:
		mark = s[1]
		break
print('\n'.join(sorted([s[0] for s in students if s[1] == mark])))


n = int(input())
students = [[input(), float(input())] for i in range(n)]
scores = list(set([students[i][1] for i in range(n)]))
scores.sort()
SecondLow = scores[1]
SecondLowStudents = [students[i][0] for i in range(n) if students[i][1] == SecondLow]
SecondLowStudents.sort()
for S in SecondLowStudents:
	print(S)


n = int(input())
sl = [[input(), eval(input())] for i in range(n)]
gl = [sl[i][1] for i in range(len(sl))]
m = min(gl)
while min(gl) == m:
	gl.remove(m)
m = min(gl)
l = []
for i in range(len(sl)):
	if sl[i][1] == m:
		l.append(sl[i][0])
l.sort()
for i in l:
	print(i)


test = int(input())
nested = []
marks = []
for i in range(test):
	name = input().strip()
	mark = float(input().strip())
	l = [name, mark]
	marks.append(mark)
	nested.append(l)
minm = min(marks)
while minm in marks:
	marks.remove(minm)
req = min(marks)
selected = []
for i in range(len(nested)):
	if nested[i][1] == req:
		selected.append(nested[i][0])
for x in sorted(selected):
	print(x)


num = int(input())
classData = []
for i in range(num):
	name = input()
	marks = float(input())
	classData.append([name, marks])
classData.sort(key=lambda mark: mark[1])
lowestMark = classData[0][1]
result = []
flag = False
flag2 = True
for data in classData:
	if lowestMark == data[1] and flag == False:
		continue
	else:
		flag = True
		if flag2 == True:
			prev = data[1]
			result.append(data[0])
			flag2 = False
		elif prev == data[1]:
			result.append(data[0])
			prev = data[1]
result.sort()
for i in result:
	print(i)


from operator import itemgetter
t = int(input())
a = [[0 for i in range(2)] for j in range(t)]
for i in range(t):
	a[i][0] = input()
	a[i][1] = float(input())
a = sorted(a, key=itemgetter(1))
i = 1
minv = a[0][1]
for i in range(t):
	if minv == a[i][1]:
		continue
	else:
		minv = a[i][1]
		break
b = []
while i < t:
	if minv == a[i][1]:
		b.append(a[i][0])
		i += 1
	else:
		break
b = sorted(b)
for j in b:
	print(j)


import sys

def main():
	lines = [line.strip() for line in sys.stdin]
	N = int(lines[0])
	scores = set()
	entries = []
	for i in range(N):
		i1 = 2 * i + 1
		i2 = 2 * i + 2
		scores.add(float(lines[i2]))
		entries.append([lines[i1], float(lines[i2])])
	scores = sorted(scores)
	students = []
	for (a, b) in entries:
		if b == scores[1]:
			students.append(a)
	students.sort()
	for student in students:
		print(student)
main()


n = int(input())
x = []
y = []
(min1, min2) = (0, 0)

def getkey(item):
	return item[0]
for i in range(n):
	s1 = input()
	s2 = float(input())
	y.append(s2)
	x.append([s1, s2])
x = sorted(x, key=getkey)
y = list(set(y))
y.sort()
y = y[1]
for i in x:
	if i[1] == y:
		print(i[0])


N = int(input())
students = []
for n in range(0, N):
	stud = input()
	note = float(input())
	students.append((note, stud))
students.sort()
stu = []
i = 1
while i < len(students) and students[i][0] == students[i - 1][0]:
	i += 1
if i < len(students):
	stu.append(students[i][1])
	i += 1
while i < len(students) and students[i][0] == students[i - 1][0]:
	stu.append(students[i][1])
	i += 1
for stud in sorted(stu):
	print(stud)


N = int(input())
first = 1000000000.0
second = 1000000000.0
f = []
s = []
for n in range(N):
	name = input()
	mark = float(input())
	if mark < first:
		second = first
		first = mark
		s = f
		f = [name]
	elif mark == first:
		f.append(name)
	elif mark == second:
		s.append(name)
	elif mark > first and mark < second:
		second = mark
		s = [name]
for name in sorted(s):
	print(name)


points = []
d = dict()
n = int(input())
for _ in range(n):
	(name, point) = (input().strip(), float(input().strip()))
	points.append(point)
	if point in d:
		d[point].append(name)
	else:
		d[point] = [name]
second = sorted(list(set(points)))[1]
print('\n'.join(sorted(d[second])))


num = int(input())
students = [[input(), float(input())] for x in range(num)]
students.sort(key=lambda student: student[0])
myset = set([x[1] for x in students])
new = sorted(list(myset))
minmarks = new[1]
for student in students:
	if student[1] == minmarks:
		print(student[0])


from operator import itemgetter
num_students = int(input())
student_grades = [[input(), float(input())] for student in range(num_students)]
student_grades.sort(key=itemgetter(1))
worst = student_grades[0][1]
not_worst = list(filter(lambda student: student[1] != worst, student_grades))
second_worst = not_worst[0][1]
second_worsts = [student[0] for student in not_worst if student[1] == second_worst]
second_worsts.sort()
for student in second_worsts:
	print(student)


from operator import itemgetter
students = [[input(), float(input())] for _ in range(int(input()))]
print('\n'.join(sorted((student[0] for student in students if student[1] == min((s[1] for s in students if s[1] != min(students, key=itemgetter(1))[1]))))))


N = int(input())
records = [(input(), float(input())) for i in range(N)]
min_score = min(records, key=lambda y: y[1])[1]
records = list(filter(lambda x: x[1] != min_score, records))
min_score = min(records, key=lambda y: y[1])[1]
records = list(filter(lambda x: x[1] == min_score, records))
for (name, score) in sorted(records):
	print(name)


numOfStudents = input()
studentAndMarks = [[input(), input()] for i in range(int(numOfStudents))]
marks = []
for i in range(int(numOfStudents)):
	marks.append(float(studentAndMarks[i][1]))
smallest = secondSmallest = max(marks)
for i in range(int(numOfStudents)):
	if marks[i] < smallest:
		secondSmallest = smallest
		smallest = marks[i]
	elif marks[i] < secondSmallest and marks[i] != smallest:
		secondSmallest = marks[i]
my_list = []
for i in range(int(numOfStudents)):
	if float(studentAndMarks[i][1]) == secondSmallest:
		my_list.append(studentAndMarks[i][0])
my_list.sort()
for i in range(len(my_list)):
	print(my_list[i])


N = int(input())
a = []
for i in range(N):
	a.append([input(), float(input())])
a.sort()
a.sort(key=lambda a: a[1])
num = 0
for i in range(N - 1):
	if a[i + 1][1] != a[i][1]:
		score = i + 1
		for k in range(i + 1, N - 1):
			if a[i + 1 + num][1] == a[i + 2 + num][1]:
				num = num + 1
		break
b = a[score:score + 1 + num]
c = len(b)
for i in range(c):
	print(b[i][0])


from collections import defaultdict
data = defaultdict(list)
for _ in range(int(input())):
	name = input()
	score = float(input())
	data[score].append(name)
key = sorted(data)[1]
print('\n'.join(sorted(data[key])))


n = int(input())
a = []
for i in range(n):
	l = []
	l.append(input())
	l.append(eval(input()))
	a.append(l)
temp = [i[1] for i in a]
x = min(list(filter(lambda x: x != min(temp), temp)))
y = []
for i in a:
	if i[1] == x:
		y.append(i[0])
y.sort()
for i in y:
	print(i)


from operator import itemgetter
N = int(input())
students = list()
for n in range(N):
	student = input()
	mark = float(input())
	students.append([student, mark])
students.sort(key=itemgetter(1))
new = list()
start = 0
while students[start][1] == students[0][1]:
	start += 1
new.append(students[start][0])
for x in range(start + 1, len(students)):
	if students[x][1] == students[start][1]:
		new.append(students[x][0])
new.sort()
for i in range(len(new)):
	print(new[i])


N = int(input())
S = {}
for _ in range(N):
	s = input()
	ss = float(input())
	if ss not in S:
		S[ss] = []
	S[ss].append(s)
ss = sorted(S)
for s in sorted(S[ss[1]]):
	print(s)


n = []
r = []
for i in range(int(input())):
	n.append(input())
	r.append(float(input()))
m = min(r)
re = []
for i in range(len(r)):
	if r[i] == m:
		r[i] = 1000000000
m = min(r)
for i in range(len(r)):
	if r[i] == m:
		re.append(n[i])
re.sort()
for i in re:
	print(i)


import sys
input()
lines = sys.stdin.read().split()
by_marks = zip(map(float, lines[1::2]), lines[::2])
mark = sorted(set(map(float, lines[1::2])))[1]
print('\n'.join(sorted([y for (x, y) in by_marks if x == mark])))


from operator import itemgetter
N = int(input())
student = []
for i in range(0, N):
	temp = []
	temp.append(input())
	temp.append(float(input()))
	student.append(temp)
student.sort(key=itemgetter(1))
min_marks = student[0][1]
output = []
second_min_marks = -1
for i in range(1, N):
	if student[i][1] == min_marks:
		continue
	else:
		second_min_marks = student[i][1]
		index = i
		break
for k in range(index, N):
	if student[k][1] == second_min_marks:
		output.append(student[k][0])
	else:
		break
output = sorted(output)
for k in output:
	print(k)


n = int(input())
d = {}
for x in range(n):
	n = input()
	s = eval(input())
	if s in d:
		d[s].append(n)
	else:
		d[s] = [n]
k = d.keys()
val = sorted(k)[1]
for n in sorted(d[val]):
	print(n)


from operator import itemgetter
from itertools import groupby
n = int(input())
students = [[input(), float(input())] for x in range(n)]
students.sort(key=itemgetter(1))
studentsIter = groupby(students, itemgetter(1))
next(studentsIter)
(grade, relevantStudents) = next(studentsIter)
relevantStudents = sorted(list(relevantStudents), key=itemgetter(0))
for stud in relevantStudents:
	print(stud[0])


def secondLowestMarks(students):
	lowest_mark = min(students, key=lambda stu: stu[1])[1]
	students = [stu for stu in students if stu[1] != lowest_mark]
	second_lowest_mark = min(students, key=lambda stu: stu[1])[1]
	return sorted([stu[0] for stu in students if stu[1] == second_lowest_mark])

def secondLowestMarks2(students):
	students.sort()
	picked_students = sorted(filter(lambda x: x[1] == students[1][1], students))
	return [stu[0] for stu in picked_students]
num_students = int(input())
students = [[input(), float(input())] for i in range(num_students)]
for student in secondLowestMarks(students):
	print(student)


def f(a):
	return a[1]

def f1(a):
	return a[0]
n = int(input())
a = []
for i in range(n):
	name = input()
	grade = float(input())
	a.append([name, grade])
a.sort(key=f)
g1 = a[0][1]
pos1 = 1
while pos1 < n:
	if a[pos1][1] == g1:
		pos1 += 1
	else:
		break
g = a[pos1][1]
pos = pos1 + 1
while pos < n:
	if a[pos][1] == g:
		pos += 1
	else:
		break
sub = sorted(a[pos1:pos], key=f1)
for i in sub:
	print(i[0])


from operator import itemgetter
n = int(input())
l = []
for i in range(n):
	l.append([input(), float(input())])
l.sort(key=itemgetter(1, 0))
i = 1
while l[i][1] == l[0][1]:
	i += 1
j = i
while j < n and l[j][1] == l[i][1]:
	print(l[j][0])
	j += 1


N = int(input())
students = list()
for _ in range(N):
	students.append([input(), float(input())])
minimum_marks = min(students, key=lambda a: a[1])
second_minimum_marks = min([marks for (name, marks) in students if marks != minimum_marks[1]])
lowest_students = [name for (name, marks) in students if marks == second_minimum_marks]
for name in sorted(lowest_students):
	print(name)


n = int(input())
l = []
for i in range(n):
	v = input()
	k = float(input())
	l.append([k, v])
l = sorted(l, key=lambda rec: rec[0])
m = l[0][0]
l = [x for x in l if not x[0] == m]
m = l[0][0]
l = [x for x in l if x[0] == m]
l = sorted(l, key=lambda rec: rec[1])
for a in l:
	print(a[1])


import collections
from operator import itemgetter
N = int(input())
list1 = []
for i in range(0, N):
	name = input()
	marks = float(input())
	list1.append([name, marks])
list1 = sorted(list1, key=itemgetter(1))
minValue = list1[0][1]
result = 0.0
for i in range(1, len(list1)):
	if list1[i][1] > minValue:
		result = list1[i][1]
		break
nameList = []
for i in range(0, len(list1)):
	if list1[i][1] == result:
		nameList.append(list1[i][0])
nameList = sorted(nameList)
for name in nameList:
	print(name)


s = []
for x in range(int(input())):
	(a, b) = (input(), float(input()))
	s.append([a, b])
s = sorted(s, key=lambda i: i[1])
z = sorted(list(set([i[1] for i in s])))[1]
ans = []
for i in s:
	if i[1] == z:
		ans.append(i[0])
print('\n'.join(sorted(ans)))


from decimal import Decimal
from itertools import groupby, islice
from operator import itemgetter
a = []
for i in range(int(input())):
	(x, y) = (input(), Decimal(input()))
	a.append((y, x))
a.sort()
for (k, v) in islice(groupby(a, key=itemgetter(0)), 1, 2):
	for x in v:
		print(x[1])


N = int(input())
final = list()
for i in range(N):
	lst = list()
	name = str(input())
	marks = float(input())
	lst.append(name)
	lst.append(marks)
	final.append(lst)
k = list()
for i in range(len(final)):
	k.append(final[i][1])
x = min(k)
k1 = list()
for i in range(len(k)):
	if x != k[i]:
		k1.append(k[i])
y = min(k1)
student = list()
for i in range(len(final)):
	if y == final[i][1]:
		student.append(final[i][0])
student.sort()
for i in range(len(student)):
	print(student[i])


N = int(input())
mp = {}
for i in range(0, N):
	v = input()
	k = float(input())
	if k in mp:
		mp[k].append(v)
	else:
		mp[k] = [v]
ky = sorted(mp.keys())[1]
for nm in sorted(mp[ky]):
	print(nm)


import heapq
n = int(input())
ll = []
NameList = []
l = list()
for i in range(n):
	name = input()
	mark = float(input())
	ll.append([mark, name])
ll.sort()
fmin = ll[0][0]
smin = 0
for item in ll:
	if fmin != item[0]:
		smin = item[0]
		break
for item in ll:
	if item[0] == smin:
		NameList.append(item[1])
NameList.sort()
for item in NameList:
	print(item)


n = int(input())
grades = sorted([(input(), float(input())) for _ in range(n)], key=lambda x: (x[1], x[0]))
m = grades[0][1]
i = 0
while i < len(grades) and grades[i][1] == m:
	i += 1
if i < len(grades):
	m = grades[i][1]
	while i < len(grades) and grades[i][1] == m:
		print(grades[i][0])
		i += 1


N = int(input())
students = []
smin = 101
fmin = 101
for i in range(N):
	name = input()
	mark = float(input())
	students.append([name, mark])
	if mark < fmin:
		smin = fmin
		fmin = mark
	elif mark > fmin and mark < smin:
		smin = mark
students = sorted(students, key=lambda person: person[0])
for i in range(N):
	if smin == students[i][1]:
		print(students[i][0])


cases = int(input())
students = [[input(), float(input())] for _ in range(cases)]
students.sort(key=lambda x: (x[1], x[0]))
lowest = students[0][1]
for student in students[1:]:
	if student[1] > lowest:
		lowest = student[1]
		break
for student in filter(lambda x: x[1] == lowest, students):
	print(student[0])


xs = [(input(), float(input())) for _ in range(int(input()))]
min_mark = min((x[1] for x in xs))
xs = [x for x in xs if x[1] > min_mark]
min2_mark = min((x[1] for x in xs))
xs = sorted([x[0] for x in xs if x[1] == min2_mark])
for x in xs:
	print(x)


from collections import OrderedDict
n = int(input())
ar = {}
val_ar = []
for i in range(0, n):
	tmp_name = input()
	tmp_marks = float(input())
	ar[tmp_name] = tmp_marks
	val_ar.append(tmp_marks)
set_val = set(val_ar)
val_ar = list(set_val)
val_ar.sort()
sec_mark = val_ar[1]
final_ar = []
for i in ar:
	if sec_mark == ar[i]:
		final_ar.append(i)
final_ar.sort()
for i in final_ar:
	print(i)


t = int(input())
s = []
g = []
names = []
for i in range(t):
	s.append([input(), float(input())])
	if s[i][1] not in g:
		g.append(s[i][1])
s.sort(key=lambda x: x[1])
g.sort()
for j in s:
	if j[1] == g[1]:
		names.append(j[0])
names.sort()
for k in names:
	print(k)


n = int(input())
students = []
for _ in range(n):
	(name, mark) = (input(), float(input()))
	students += [(mark, name)]
students.sort()
mark = students[0][0]
for (index, student) in enumerate(students):
	if mark != student[0]:
		break
mark = students[index][0]
for student in students:
	if student[0] == mark:
		print(student[1])
	elif student[0] > mark:
		break


n = int(input())
lst = []
for x in range(n):
	a = input()
	b = float(input())
	lst.append([a, b])
mini = 500
secmini = 600
for x in lst:
	if x[1] <= mini:
		mini = x[1]
	elif x[1] < secmini:
		secmini = x[1]
if mini < lst[0][1] < secmini:
	secmini = lst[0][1]
names = []
for x in lst:
	if x[1] == secmini:
		names.append(x[0])
names.sort()
for x in names:
	print(x)


marks = set()
res_d = {}
for i in range(int(input())):
	name = input().strip()
	mark = float(input())
	marks.add(mark)
	if mark in res_d.keys():
		res_d[mark].append(name)
	else:
		res_d[mark] = [name]
marks_list = list(marks)
marks_list.sort()
ans = res_d[marks_list[1]]
ans.sort()
for nam in ans:
	print(nam)


def students(n):
	a = []
	for i in range(n):
		name = str(input())
		score = float(input())
		a.append([score, name])
	a = sorted(a)
	i = 1
	while a[0][0] == a[i][0]:
		i += 1
		if i == len(a):
			return
	for j in sorted(filter(lambda x: x[0] == a[i][0], a)):
		print(j[1])
n = int(input())
if n > 1:
	students(n)


from collections import defaultdict
n = int(input())
d = defaultdict(list)
for i in range(n):
	person = input()
	score = float(input())
	d[score].append(person)
second = sorted(list(set(d.keys())))[1]
names = d[second]
for n in sorted(names):
	print(n)


n = int(input())
a = []
for i in range(n):
	a.append([input(), float(input())])
m = min(a, key=lambda x: x[1])[1]
m = min(a, key=lambda x: x[1] if x[1] > m else 100)[1]
res = sorted((x[0] for x in a if x[1] == m))
for x in res:
	print(x)


transposed = []
lowest = 999.0
for i in range(int(input())):
	name = input()
	mark = float(input())
	if mark < lowest:
		lowest = mark
	transposed.append([name, mark])
c = 0
ind = 0
low2 = 999.0
for el in transposed:
	if el[1] == lowest:
		ind = c
	if el[1] != lowest and el[1] < low2:
		low2 = el[1]
	c += 1
del transposed[ind]
transposed.sort()
for el in transposed:
	if el[1] == low2:
		print(el[0])


import operator
n = int(input())
r = []
for i in range(n):
	name = input()
	score = float(input())
	r.append([name, score])
r = sorted(r, key=operator.itemgetter(1, 0))
for s in r:
	if s[1] != r[0][1]:
		smin = s[1]
		break
for s in r:
	if s[1] == smin:
		print(s[0])


N = int(input())
lst = []
for i in range(N):
	lst.append([input(), float(input())])
lst = sorted(lst, key=lambda student: student[1])
score = min(lst, key=lambda student: student[1])[1]
try:
	score = min((n[1] for n in lst if n[1] > score))
	result = sorted([i[0] for i in lst if i[1] == score])
	print('\n'.join(result))
except:
	print('\n'.join([]))


n = int(input())
nlst = []
for i in range(n):
	name = str(input())
	grade = float(input())
	nlst.append([name, grade])
nlst.sort(key=lambda x: x[1])
index = 1
if nlst[0][1] == nlst[1][1]:
	for i in range(2, n):
		if nlst[i][1] != nlst[1][1]:
			index = i
			break
output_names = []
for i in range(n - index):
	if nlst[i + index][1] == nlst[index][1]:
		output_names.append(nlst[i + index][0])
output_names.sort()
for i in output_names:
	print(i)


from collections import defaultdict
scores = defaultdict(list)
for i in range(int(input())):
	name = input()
	score = float(input())
	scores[score].append(name)
for name in sorted(scores[sorted(scores.keys())[1]]):
	print(name)


from operator import itemgetter
n = int(input())
c = 0
a = []
k = []
for i in range(0, n * 2):
	c = c + 1
	k.append(input())
	if c == 2:
		a.append(k)
		k = []
		c = 0
for i in range(0, n):
	a[i][1] = float(a[i][1])
k = a
a.sort(key=itemgetter(1))
min = a[0][1]
g = min
for i in range(0, n):
	if a[i][1] != min:
		g = a[i][1]
		break
k.sort()
for i in range(0, n):
	if k[i][1] == g:
		print(k[i][0])


from collections import defaultdict
marks = defaultdict(list)
for _ in range(int(input())):
	(name, mark) = (input(), float(input()))
	marks[mark].append(name)
print('\n'.join(map(str, sorted(marks[sorted(marks.keys())[1]]))))


from operator import itemgetter
n = int(input())
students = []
for n in range(n):
	students.append([input(), float(input())])
lowest = sorted(set(map(itemgetter(1), students)))[1]
for student in sorted(filter(lambda l: l[1] == lowest, students)):
	print(student[0])


def myPrint(lst):
	lst.sort()
	for i in lst:
		print(i)
dct = {}
for n in range(int(input())):
	name = input()
	mark = float(input())
	if mark in dct:
		dct[mark].append(name)
	else:
		dct[mark] = [name]
marks = list(dct.keys())
marks.sort()
if len(marks) > 1:
	myPrint(dct[marks[1]])


studs = int(input())
studl = []
for i in range(studs):
	studl.append([str(input()), float(input())])
studl.sort(key=lambda stu: (stu[1], stu[0]))
low = studl[0][1]
second = studl[1][1]
loc = 1
while second == low:
	loc += 1
	second = studl[loc][1]
cur = second
while cur == second:
	print(studl[loc][0])
	loc += 1
	if loc == studs:
		break
	cur = studl[loc][1]


from collections import defaultdict
l = defaultdict(list)
for _ in range(int(input())):
	u = input()
	l[float(input())].append(u)
print('\n'.join(sorted(l[sorted(l.keys())[1]])))


from operator import itemgetter
n = int(input())
string = input()
lis = [[float(input()), string]]
for x in range(n - 1):
	string = input()
	val = float(input())
	found = False
	for y in range(len(lis)):
		if val == lis[y][0]:
			lis[y].append(string)
			found = True
	if found == False:
		lis.append([val, string])
lis.sort(key=itemgetter(0))
lis2 = []
for x in range(len(lis[1]) - 1):
	lis2.append(lis[1][x + 1])
lis2 = sorted(lis2)
for x in range(len(lis2)):
	print(lis2[x])


from operator import *
n = int(input())
a = [[]] * n
for i in range(n):
	s = input()
	x = float(input())
	a[i] = [s, x]
a.sort(key=itemgetter(0))
a.sort(key=itemgetter(1))
marks = a[0][1]
ma = 100000000000000
for i in range(n):
	if a[i][1] != marks and ma > a[i][1]:
		ma = a[i][1]
for i in range(n):
	if a[i][1] == ma:
		print(a[i][0])


import sys
students = []
number_of_students = int(sys.stdin.readline().strip())
for x in range(number_of_students):
	name = sys.stdin.readline().strip()
	mark = float(sys.stdin.readline().strip())
	students.append([mark, name])
students.sort()
mark_min = students[0][0]
second_min = students[-1][0]
for student in students:
	if student[0] > mark_min:
		if student[0] <= second_min:
			second_min = student[0]
			print(student[1])
		else:
			break


num = int(input())
list = []
first = 0
second = 0
for i in range(num):
	temp1 = input()
	temp2 = float(input())
	list.append([temp1, temp2])
list = sorted(list, key=lambda first: first[0])
min_ = min(list, key=lambda first: first[1])[1]
for i in range(num):
	if list[num - 1 - i][1] == min_:
		del list[num - 1 - i]
min_ = min(list, key=lambda first: first[1])[1]
list2 = []
for i in range(len(list)):
	if list[i][1] == min_:
		list2.append(list[i][0])
list2 = sorted(list2)
for i in range(len(list2)):
	print(list2[i])


from operator import itemgetter
n = int(input())
nested_list = []
for i in range(n):
	input_list = []
	try:
		name = input()
	except EOFError:
		break
	input_list.append(name)
	marks = float(input())
	input_list.append(marks)
	nested_list.append(input_list)
nested_list.sort(key=itemgetter(1))
smallest_value = nested_list[0][1]
count_list = []
second_small = 0.0
for k in range(1, n):
	if nested_list[k][1] != smallest_value:
		second_small = nested_list[k][1]
		count_list.append(k)
		break
p = count_list[0]
for l in range(p + 1, n):
	if second_small == nested_list[l][1]:
		count_list.append(l)
output_list = []
for m in count_list:
	output_list.append(nested_list[m][0])
output_list.sort()
for o in range(len(output_list)):
	print('%s' % output_list[o])


import sys
if sys.version_info[0] >= 3:
	raw_input = input
h = {}
N = int(raw_input())
for i in range(N):
	a = raw_input().rstrip()
	b = float(raw_input())
	if b not in h:
		h[b] = []
	h[b].append(a)
keys = sorted(h.keys())
for e in sorted(h[keys[1]]):
	print(e)


l = []
for i in range(int(input())):
	(nm, sc) = (input(), float(input()))
	l.append([sc, nm])
if not l:
	exit()
l = sorted(l)
minsc = l[0][0]
l = list(filter(lambda x: x[0] != minsc, l))
for s in l:
	if s[0] == l[0][0]:
		print(s[1])


n = int(input())
lst = []
for i in range(0, n):
	a = [input(), float(input())]
	lst.append(a)
srt = sorted(lst, key=lambda x: x[1])

def secondWorst(lst):
	m = lst[0][1]
	for i in range(1, len(lst)):
		if lst[i][1] != m:
			for j in range(i, len(lst)):
				if lst[j][1] == lst[i][1]:
					yield lst[j][0]
			break
[print(x) for x in sorted(secondWorst(srt))]


classroom = list()
n = int(input())
for n in range(n):
	classroom += [[input(), float(input())]]
worst = min(list(map(lambda x: x[1], classroom)))
worst = min((x[1] for x in classroom if x[1] != worst))
for student in sorted((x[0] for x in classroom if x[1] == worst)):
	print(student)


n = int(input())
students = []
for i in range(n):
	name = input()
	mark = float(input())
	students.append([name, mark])
students.sort(key=lambda x: x[1])
start = 1
while start < n and students[start][1] == students[start - 1][1]:
	start += 1
val = students[start][1]
result = [x[0] for x in students if x[1] == val]
result.sort()
for item in result:
	print(item)


nTestCase = int(input())
Grade = []
sortList = []
for i in range(nTestCase):
	Name = input()
	Point = float(input())
	Grade.append([Name, Point])
	sortList.append(Point)
sortList = list(set(sortList))
sortList.sort()
printList = []
for i in range(nTestCase):
	if Grade[i][1] == sortList[1]:
		printList.append(Grade[i][0])
printList.sort()
for i in range(len(printList)):
	print(printList[i])


cases = int(input())
a = []
mini = 10000000000000000000
secondMini = 10000000000000000
for i in range(cases):
	name = input()
	score = float(input())
	if score < mini:
		secondMini = mini
		mini = score
	if score < secondMini and score > mini:
		secondMini = score
	a.append([name, score])
a = sorted(a)
for i in a:
	if i[1] == secondMini:
		print(i[0])


from operator import itemgetter
n = int(input())
(anslist, newlist) = ([], [])
for i in range(0, n):
	name = input()
	marks = float(input())
	newlist.append([name, marks])
newlist.sort(key=itemgetter(1))
samp = newlist[0][-1]
count = 0
for i in range(1, len(newlist)):
	if newlist[i][-1] != samp:
		samp = newlist[i][-1]
		break
for j in range(1, len(newlist)):
	if newlist[j][-1] == samp:
		anslist.append(newlist[j])
anslist.sort(key=itemgetter(0))
for i in range(0, len(anslist)):
	print(anslist[i][0])


N = int(input())
l = []
for i in range(N):
	l.append([input(), float(input())])
l.sort(key=lambda x: x[1])
index = 0
while index < N:
	if l[index][1] != l[0][1]:
		break
	else:
		index = index + 1
res = []
if index == N:
	print('Error')
else:
	value = l[index][1]
	while index < N and l[index][1] == value:
		res.append(l[index][0])
		index = index + 1
res.sort()
for i in res:
	print(i)


import operator
l = []
n = int(input())
for i in range(n):
	m = []
	name = input()
	marks = float(input())
	m.append(name)
	m.append(marks)
	l.append(m)
l.sort(key=operator.itemgetter(1))
a = l[0][1]
i = 1
f = 0
while i != 0:
	if a < l[i][1]:
		a = l[i][1]
		break
	i = i + 1
m = []
while i < len(l):
	if a == l[i][1]:
		m.append(l[i][0])
		i = i + 1
	else:
		break
m.sort()
i = 0
for i in range(len(m)):
	print(m[i])


s = []
for i in range(int(input())):
	name = input()
	mark = float(input())
	s.append((mark, name))
s.sort()
low_mark = s[0][0]
i = 0
for (i, pair) in enumerate(s):
	if pair[0] == low_mark:
		continue
	break
second_lowest_mark = s[i][0]
for pair in s:
	if pair[0] == second_lowest_mark:
		print(pair[1])


num = int(input())
grades = [[input(), float(input())] for i in range(0, num)]
scores = set([x[1] for x in grades])
target = sorted(scores)[1]
grades = filter(lambda x: x[1] == target, grades)
for i in sorted([x[0] for x in grades]):
	print(i)


def get_input():
	student_list = []
	num_students = int(input())
	for i in range(num_students):
		student_list.append([input(), float(input())])
	return sorted(student_list, key=lambda x: x[1])

def find_second_lowest_grade(student_list):
	second_lowest_names = []
	lowest_grade = student_list[0][1]
	second_lowest_grade = student_list[-1][1]
	for student in student_list:
		if lowest_grade < student[1] <= second_lowest_grade:
			second_lowest_grade = student[1]
			second_lowest_names.append(student[0])
	return sorted(second_lowest_names)

def main():
	student_list = get_input()
	second_lowest_names = find_second_lowest_grade(student_list)
	for name in second_lowest_names:
		print(name)
main()


from operator import itemgetter
n = int(input())
my_list = []
for i in range(0, n):
	name = input()
	mark = float(input())
	my_list.append([name, mark])
my_list = sorted(my_list, key=itemgetter(1))
names = []
for x in range(1, len(my_list)):
	if my_list[x][1] != my_list[0][1]:
		names.append(my_list[x][0])
		for i in range(x + 1, len(my_list)):
			if my_list[i][1] != my_list[x][1]:
				break
			names.append(my_list[i][0])
		break
for name in sorted(names):
	print(name)


n = int(input())
dic = []
for i in range(n):
	name = input()
	score = float(input())
	dic.append((name, score))
Min = ('Hehe', 1111111111)
Sec = ('Hi', 111111111)
res = []
for ele in dic:
	if ele[1] < Min[1]:
		Min = ele
for ele in dic:
	if ele[1] < Sec[1] and ele[1] > Min[1]:
		Sec = ele
for ele in dic:
	if ele[1] == Sec[1]:
		res.append(ele)
res = sorted(res, key=lambda d: d[0])
for ele in res:
	print(ele[0])


t = int(input())
clas = []
marks_list = []
maax = 0.0
for _ in range(0, t):
	name = input()
	marks = float(input())
	clas.append([name, marks])
	marks_list.append(marks)
marks_list = sorted(marks_list)
j = marks_list[0]
for k in range(1, len(marks_list)):
	if marks_list[k] != j:
		break
final = sorted([student[0] for student in clas if student[1] == marks_list[k]])
for item in final:
	print(item)


n = int(input())
mark = []
smin = min = 100
sname = []
for i in range(n):
	mark.append([input(), float(input())])
	if mark[i][1] < min:
		min = mark[i][1]
for i in range(n):
	if mark[i][1] > min and mark[i][1] < smin:
		smin = mark[i][1]
for i in sorted([x[0] for x in mark if x[1] == smin]):
	print(i)


N = int(input())
min = 10000
min2 = 10000
minlist = []
for i in range(N):
	name = input()
	grade = float(input())
	if grade < min:
		answer = []
		answer.extend(minlist)
		minlist = []
		minlist.append(name)
		min2 = min
		min = grade
	elif grade == min:
		minlist.append(name)
	elif grade < min2:
		answer = []
		answer.append(name)
		min2 = grade
	elif grade == min2:
		answer.append(name)
for i in sorted(answer):
	print(i)


N = int(input())
grades = {}
while N > 0:
	(name, grade) = (input(), float(input()))
	grades[grade] = grades.get(grade, []) + [name]
	N -= 1
target = sorted(grades.keys())[1]
print('\n'.join(sorted(grades[target])))


from operator import itemgetter
num = int(input())
mylist = []
result = []
for i in range(0, num):
	name = input()
	score = float(input())
	mylist.append([name, score])
mylist.sort(key=itemgetter(1))
point = 0
for i in range(0, num):
	if mylist[0][1] == mylist[i][1]:
		point += 1
for i in range(point, num):
	if mylist[point][1] == mylist[i][1]:
		result.append(mylist[i][0])
result.sort()
for i in range(0, len(result)):
	print(result[i])


from operator import itemgetter
max = int(input())
finallist = []
studentlist = []
for i in range(0, max):
	studentname = input()
	studentgrade = float(input())
	studentlist.append([studentname, studentgrade])
studentlist.sort(key=itemgetter(1))
minscore = studentlist[0][1]
for i in range(1, max):
	if studentlist[i][1] != minscore:
		requiredscore = studentlist[i][1]
		break
for i in range(1, max):
	if studentlist[i][1] == requiredscore:
		finallist.append(studentlist[i][0])
	elif studentlist[i][1] > requiredscore:
		break
finallist.sort()
for item in finallist:
	print(item)


n = int(input())
x = []
for i in range(n):
	a = input()
	b = float(input())
	x.append([a, b])
x = sorted(x, key=lambda z: z[1])
zm = []
for i in range(n):
	if x[i][1] < x[i + 1][1]:
		c = x[i + 1][1]
		for j in range(n - i):
			if x[i + j][1] == c:
				zm.append(x[i + j][0])
		zm = sorted(zm)
		for i in zm:
			print(i)
		break


def main():
	number_students = int(input())
	students = []
	grades = set()
	for i in range(number_students):
		name = input()
		grade = float(input())
		grades.add(grade)
		students.append([name, grade])
	second_lowest_grade = sorted(grades)[1]
	second_lowest_students = sorted([student[0] for student in students if student[1] == second_lowest_grade])
	for student in second_lowest_students:
		print(student)
main()


li = []
t = int(input())
for i in range(t):
	li.append([input(), float(input())][::-1])
li.sort()
lowest = li[0][0]
i = 0
while li[i][0] == lowest:
	i += 1
secondLowest = li[i][0]
while li[i][0] == secondLowest:
	print(li[i][1])
	i += 1
	if i == t:
		break