YODA - Yoda Goes Palindromic !


According to a very famous web site, which in this case we will trust, defines a palindrome as ‘a word, phrase, verse, or sentence that reads the same backward or forward’. For example, the phrase A man, a plan, a canal, Panama! is a palindrome. Actually, writing texts consisting of only palindromes is part of a literary technique called constrained writing.

Now imagine the wise Yoda, the master of all, whose proficiency putting words together in sentences is one of his well-known abilities. He is now interested in enriching his long- lasting, and maybe boring, inactivity periods by ‘composing’ palindromic sentences. That is, he has plans to use only palindromic sentences for his chats. For this matter, he needs to practice. The first task in his practice plan is to count all the palindromes that can be arranged out of a collection of characters.

Today, you will be Yoda’s assistant for this first task. Your only mission is to, given a sequence of characters, determine how many palindromes can be obtained with some of the characters in the sequence; you will only take into account uppercase or lowercase letters. Put in other way, you need to determine how many permutations of a give sequence of characters are palindromes. Your solution will help definitively master Yoga.

Input

The input consists of several test cases, one per line. For each test case, the input consist of a sequence of ASCII characters.

Output

For each test case you should print in a single line, and according to the order of the test cases, the total number of palindromes generated by the input sequence of ASCII characters. For your purpose, you should only consider uppercase or lowercase characters appearing in the input; any other character should be ignored in the calculations. Uppercase and lowercase characters are not considered different; for example, A and a should not be considered different. In any case, the total number of palindromes will not exceed the number e^43 , where e is approximately 2.71828. Remember that the empty sequence is a palindrome itself.

Example

Input:
A man, a plan, a canal, Panama!
arD,R!A
B.a.C1/
12[’;. =1

Output:
15120
2
0
1

hide comments
Tamilselvan: 2010-08-22 10:14:55

couldn't understand the question. What we actually need to do ? find all possible palindromes ? r something else

what ll be the output for abaaba

~!(*(@*!@^&: 2010-04-13 23:50:55

self assumption : 10^5

~!(*(@*!@^&: 2010-04-13 23:16:19

there is no upper bound of the length of the string?


Added by:Daniel Gómez Didier
Date:2008-11-18
Time limit:3.950s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO
Resource:2007 U.Nacional - Circuito de Maratones ACIS / REDIS