Pyeongseok, who is taking Introduction to Psychology in this seasonal (intersession) term, has to submit a report by midnight tonight. Writing the report was so boring that he dozed off face-down on his laptop and woke up only one hour before the deadline. To his dismay, while he was asleep the keyboard got pressed by mistake and every single letter of his report had turned into an A or a B! So Pyeongseok gave up on the report and decided to count the "good words" in it instead.
Pyeongseok pairs up equal letters (A with A, B with B) by drawing arch-shaped curves over the word. If every letter can be paired with exactly one other equal letter at a different position so that no two arcs cross, the word is a "good word". Help Pyeongseok count the number of good words.
The first line contains the number of words $N$ ($1 \le N \le 100$).
Each of the next $N$ lines contains one word made up only of the letters A and B. Each word has length between $2$ and $100,000$, and the total length of all words does not exceed $1,000,000$.
Print the number of good words on the first line.