### PROBLEM LINK:

**Author:** Pawel Kacprzak

**Tester:** Misha Chorniy

**Editorialist:** Pawel Kacprzak

### DIFFICULTY:

CAKEWALK

### PREREQUISITES:

Basic programming

### PROBLEM:

For a given list N people, where each is either a superhero or a villain, joining the fight between superheroes and villains in the given order, decide which side wins or if the fight ends up with a draw. Superheroes win immediately at the earliest time when there are 2 more superheroes fighting than villains. Villains win immediately at the earliest time when there are 3 more villains fighting than superheroes. If none of these cases happens, then the fight results in a draw.

### QUICK EXPLANATION:

Whenever a person joins the fight check if one of the sides wins. If yes, print the name of winning group, otherwise continue. If no side wins after all people joined, print draw.

### EXPLANATION:

Solutions to both subtasks are based on the approach described in quick explanation, but they differ complexity of checking if one side wins.

### Subtask 1

In the first subtask N is at most 500, so after every person joining the fight, one can count the number of superheroes already fighting and villains already fighting, and then decide if either of the sides wins. This results in O(N^2) solution, because for each of N people joining the fight, in O(N) time we are counting the number of superheroes and villains already fighting.

### Subtask 2

In the second subtask N is at most 10^5, so counting people from the scratch after every joining person will take too much time. However this can be easily avoided by keeping track of counters of superheroes and villains already fighting. After each person joining the fight, we increment exactly one of these counters depending on the type of the joining person and check if either group wins using these counters. This approach works in O(N) time.

### AUTHOR’S AND TESTER’S SOLUTIONS:

Setter's solution can be found [here][333]. Tester's solution can be found [here][444].