#P13414. [COCI 2012/2013 #4] ESEJ

[COCI 2012/2013 #4] ESEJ

题目描述

Mirko's latest homework assignment is writing an essay. However, he finds writing essays so boring that, after working for two hours, he realized that all he has written are NN long words consisting entirely of letters AA and BB. Having accepted that he will never finish the essay in time, poor Mirko has decided to at least have some fun with it by counting nice words.

Mirko is connecting pairs of identical letters (AA with AA, BB with BB) by drawing arches above the word. A given word is nice if each letter can be connected to exactly one other letter in such a way that no two arches intersect. Help Mirko count how many words are nice.

输入格式

The first line of input contains the positive integer NN (1N1001 \leq N \leq 100), the number of words written down by Mirko.

Each of the following NN lines contains a single word consisting of letters AA and BB, with length between 22 and 100000100\,000, inclusive. The sum of lengths of all words doesn't exceed 10000001\,000\,000.

输出格式

The first and only line of output must contain the number of nice words.

3
ABAB
AABB
ABBA
2
3
AAA
AA
AB
1
1
ABBABB
1