Mike's Deal Game

5

1 votes
Easy-Medium
Problem

One fine day, Mike, Jesse and Heisenberg went to deal with Gus Fring's assistant, Victor, on a place outside the borders of Albuquerque.

"Say My Name."

"Heisenberg."

"You're goddamn right."

They bring N cards along with them, with some special cards. Each card has a string of alphabets S written on it. A special card is a card in which the string is a Palindrome.

Victor is ready to give any amount of money to Jesse and Heisenberg in exchange of the secret blue meth formula. But Heisenberg rejects his offer.

"Stay out of my territory."

enter image description here

To make things interesting, Mike points a gun towards Victor and gives him a puzzle. He spreads out all the cards they brought and asks him to tell the number of possible pairs of special cards with the same first letter.

Can you save Victor's life?

INPUT

  • First line contains an integer N denoting the number of strings.
  • Each of the N lines has a string S.

OUTPUT

  • A single line containing the answer (Number of possible pairs of special cards with the same first letter)
CONSTRAINTS
  • |S|*N ≤ 106.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

All such possible pairs are -

  1. a , aba
  2. a , abcba
  3. aba , abcba
  4. bnssnb , bob
Editor Image

?