-----Problem-----

			Nikki's latest work is writing a story of letters. However, she finds writing story so boring that, after working for three hours, she realized that all she has written are M long words consisting entirely of letters A and B. Having accepted that she will never finish the story in time, Nikki has decided to at least have some fun with it by counting bubbly words.


			Now Nikki is connecting pairs of identical letters (A with A, B with B) by drawing lines above the word. A given word is bubbly if each letter can be connected to exactly one other letter in such a way that no two lines intersect. So here is your task. Help Nikki count how many words are bubbly.

-----Input-----
- 
			The first line of input contains the positive integer M, the number of words written down by Nikki.
				
- 
			Each of the following M lines contains a single word consisting of letters A and B, with length

			between 2 and 10^5, inclusive. The sum of lengths of all words doesn't exceed 10^6.
				

-----Output-----

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

-----Constraints-----
- 
			1 ≤ M ≤ 100
				

-----Sample Input-----

3

ABAB

AABB

ABBA

-----Sample Output-----
2

-----Explanation-----
- 
					 ABAB - It is not bubbly as A(indexed 1) will connect to A(indexed 3) by a line and when we try to connect B(indexed 2) with B(indexed 4) by a line then it will intersect with the line b/w A and A.
				
- 
					AABB - It is bubbly as line b/w A and A will not intersect with the line b/w B and B.
			
- 
ABBA -It is also bubbly as lines will not intersect. We can draw line b/w A and A above the line b/w B and B.
				 p { text-align:justify }

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def check(s):\n arr=[s[0]]\n l=len(s)\n f1=0\n for i in range(1,l):\n  if arr==[]: arr.append(s[i])\n  elif arr[-1]!=s[i]:arr.append(s[i])\n  else: del arr[-1]\n if arr==[]: return True\n else: return False\n \ncount = 0\nfor t in range(eval(input())):\n s=input().strip()\n if check(s): count+=1\nprint(count)'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 16698