测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A1267. [COCI-2012_2013-contest4]#3 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 N long words consisting entirely of letters A and B. 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 (A with A, B with B) 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 N (1 ≤ N ≤ 100), the number of words written down by Mirko.
Each of the following N lines contains a single word consisting of letters A and B, with length between 2 and 100 000, inclusive. The sum of lengths of all words doesn't exceed 1 000 00
0.

输出格式

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

输入输出样例

输入 #1
3 
ABAB 
AABB 
ABBA
输出 #1
2 
输入 #2
3 
AAA 
AA 
AB 
输出 #2
1
输入 #3
1 
ABBABB
输出 #3
1 
上一题 去做题 下一题