You have N strings S1,S2,S3,...,SN of lowercase characters. You’ll need to support Q operations of two types. You have to process the operations/queries online. After each operations, you need to print how many strings are currently palindrome. A palindrome is a string that reads the same forward or backward.
Operattion Type 1: 1AB : That means SB will be added at the end of SA and SBwill be deleted. It is guaranteed that A≠B and SB will not be given in any other opertaion as it is deleted.
Operattion Type 2: 2AKC : That means you need to insert character C at K′th position of SA.
Note that the operations are encoded. That is, you need to write an online solution, please read the input format carefully.
Input Format
First line will contain two integers N and Q (1<=N,Q<=105), they are number of strings and number of operations.
Each of next N lines will contain a string of lowercase characters. Summation of lengths of initial N strings <= 105.
Each of the next Q lines will describe a operation.
It contains one integer OP (1<=OP<=2) — the type of operation.
The given opeartions will be encoded in the following way: let Pr be the number of palindromes that you have printed after executing the previous operation (initially, Pr=0).
Output Format
After completeing each operation, print one integer - that is currently how many strings are palindrome.
Constraints
For 10 points: 1<=N,Q<=10 and summation of lengths of initial N strings <= 100.
For full point: Original constarints.
Initially there are three strings. Palindromic strings will be bold and deleted strings will be denoted by null.
After the 1st operation: yaaa, bbb, aaa (the answer is 2)
After the 2nd operation: yaaabbb, null, aaa (added at the end of, and is deleted, now it's denoted by 'null', it will be ignored from rest of the operations. And we have one palindrome)
After the 3rd operation: yaaabbbaaa, null, null (is added at the end of and is deleted. Now there is no palindrome, the answer is 0)
After the 4th operation: yaaabbbaaay, null, null (We have one palindrome)
After the 5th operation: yaaaxbbbaaay, null, null (No palindrome)
After the 6th operation: yaaaxbbbxaaay, null, null (Lastly, we have one palindrome)