## Algorithm

Problem Name: 2 AD-HOC - beecrowd | 2134

# Who Will Fail?

By XI Maratona de Programação IME-USP, 2007 Brazil

Timelimit: 1

Professor Wallywow, from British Columbia University, is really worried with the falling of students attention level. He already tried most of worldwide know techniques to stimulate the students to pay more attention to the classes and to do the tasks he gives: he gave good grades to the more participatives students, offered chocolates, took his karaoke and song in the classes, etc. As this actions dind't increased the attendance of the students (the karaoke ideia was very unhappy... the second class with karaoke had only one student and he had hearing problems) he had a brilliant ideia: start a competition between the students.

Professor Wallywow gave a set of problems to the students resolve in a moth. In the end of the month, the students sent the number of problems resolved. The promisse of the brilliant professor was to flunk the student in the last place of the competition. The students were ordered by the number of problems resolved, with draws resolved with the alphabetical order of the names (there wasn't namesake in the class). That made the students with the names begging with the last letters of the alphabet worked hard in the tasks and didn't shared theirs solutions with theirs colleages (especially those who names began with previous letters). Your task in this problem is to write a program that reads the results of the Professor Wallywow students and writes the name of the unfortunate student who failed.

Any similarity between Professor Wallywow and Professor Carlinhos is purely coincidental.

## Input

The input is composed by many instances. The first line of each instance have one integer N (1 ≤ N ≤ 100) defining the number of students in the competition. Each of the following N lines have the name of the student and the number of solved problems. The name is a sequence of letters [a-z] with the maximum size of 20 letters and each person solves 0 to 10 problems.

The input finish with an end-of-file.

## Output

For each instance, you must print an identifier "Instancia K", where K is the number of the actual instance. In the following line print the name of the student who failed.

After each instance print a blank line.

## Code Examples

### #1 Code Example with C Programming

```Code - C Programming```

``````
#include <stdio.h>
#include <string.h>

typedef struct aluno{

char nome[30];
unsigned short qtsProblemasResolvidos;

} aluno;

int compara(const void *a, const void *b);

int main (void)
{

unsigned short i;
unsigned short qtsAlunos;
unsigned short qtsInstnacia = 0;

while (scanf("%hu", &qtsAlunos) != EOF)
{

aluno classe[qtsAlunos];
memset(classe, 0, sizeof(aluno));

for (i = 0; i  <  qtsAlunos; i++)
scanf("%s %hu", classe[i].nome, &classe[i].qtsProblemasResolvidos);

qsort(classe, qtsAlunos, sizeof(aluno), compara);

printf("Instancia %hu\n", ++qtsInstnacia);

printf("%s\n\n", classe[qtsAlunos - 1].nome);

}

}

int compara (const void *a, const void *b)
{

if ((*(struct aluno*)a).qtsProblemasResolvidos == (*(struct aluno*)b).qtsProblemasResolvidos)
{

if (strcmp((*(struct aluno*)a).nome, (*(struct aluno*)b).nome) == 0)
return 0;
else if (strcmp((*(struct aluno*)a).nome, (*(struct aluno*)b).nome)  <  0)
return -1;
else
return 1;

}
else if ((*(struct aluno*)a).qtsProblemasResolvidos > (*(struct aluno*)b).qtsProblemasResolvidos)
return -1;
else
return 1;

}
``````
Copy The Code &

Input

cmd
4
cardonha 9
marcel

Output

cmd
Instancia 1

### #2 Code Example with Python Programming

```Code - Python Programming```

``````
count = 1
while True:
try:
ordem = int(input())
except EOFError:
break
lista = []
for i in range(ordem):
a, b = input().split()
lista.append((-int(b), a))
lista.sort()
print("Instancia %d" % count)
count += 1
print(lista[-1][1])
print("")
``````
Copy The Code &

Input

cmd
4
cardonha 9