n = int(input('Введите кол-во блоков'))
chisla = []
for x in range:
chisla.append([int for y in input().split()])
n=999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
vis = 0
for i in range:
if chisla == []:
break
else:
maxl = max(chisla)
if maxl[0] < n:
n = maxl[0]
vis = vis + maxl [1]
chisla.remove(maxl)
else:
chisla.remove(maxl)
print('Высота пирамиды будет равна:' + str(vis))
chisla = []
for x in range:
chisla.append([int for y in input().split()])
n=999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
vis = 0
for i in range:
if chisla == []:
break
else:
maxl = max(chisla)
if maxl[0] < n:
n = maxl[0]
vis = vis + maxl [1]
chisla.remove(maxl)
else:
chisla.remove(maxl)
print('Высота пирамиды будет равна:' + str(vis))