#P5685. Palindromic Friendship

    ID: 18913 Type: Default 1000ms 256MiB

Palindromic Friendship

Palindromic Friendship

Given two strings \(A\) and \(B\) representing the names of two of JYY's friends, we define \(A(i, j)\) as the substring of \(A\) from the \(i\)th to the \(j\)th character (1-indexed), and similarly, \(B(x, y)\) as the substring of \(B\) from the \(x\)th to the \(y\)th character.

The closeness of the two friends is defined as the number of quadruples \((i, j, x, y)\) satisfying all the following conditions:

  1. \(1 \le i \le j \le |A|\).
  2. \(1 \le x \le y \le |B|\).
  3. \(A(i, j) = B(x, y)\).
  4. \(A(i, j)\) is a palindrome.

Here, \(|A|\) denotes the length of string \(A\). Your task is to compute and output the closeness score of the two friends.

Note: Only the substring from \(A\) is required to be a palindrome; the substring from \(B\) need not be a palindrome.

inputFormat

The input consists of two lines:

  • The first line contains the string \(A\).
  • The second line contains the string \(B\).

outputFormat

Output a single integer representing the closeness score, which is the total number of quadruples \((i, j, x, y)\) meeting the described conditions.

sample

aba
aba
6