Problem E
Fallen Chimney
Languages
da
en
As a homeowner, you tend to experience many problems: Water pipes can burst, fuses can blow, and—most annoyingly—your chimney can fall over. Bamse has been particularly suffering from the last problem, and is tired of constantly having to get the ladder so he can climb up on the roof. Since slamming the door is the most frequent cause of fallen chimneys, Bamse has painstakingly measured and noted every time he closes his door. His notes show how hard he closed the door in mBp (milli Bamse power), and whether or not his chimney fell over as a result.
Now, Bamse has just returned from a particularly bad day. He would like to know how hard he can slam his door without making it even worse. How hard can he slam the door, and be guaranteed not to make his chimney fall over?
Input
First line consists of a single integer $n$ with $2 \leq n \leq 1000$, the number of notes that Bamse has written. The next $n$ lines consists of an integer $i$ with $1 \leq i \leq 1000$, followed by a word, either “ja” meaning yes, or “nej” meaning no, denoting whether the closing of the door caused the chimney to fall over. It is guaranteed the the list of notes will contain at least one yes and one no.
Output
Print on one line a single integer: How many mBp can Bamse at most slam his door with, and be guaranteed to not make his chimney fall over.
Sample Input 1 | Sample Output 1 |
---|---|
5 901 ja 123 nej 666 ja 500 nej 612 nej |
612 |
Sample Input 2 | Sample Output 2 |
---|---|
2 1000 ja 1 nej |
1 |