#P5555. Longest Common Palindromic Substring

    ID: 18785 Type: Default 1000ms 256MiB

Longest Common Palindromic Substring

Longest Common Palindromic Substring

Two modern wizards, L and K, are investigating ancient spells. They discovered that in order for a spell to be considered valid, it must satisfy two conditions:

  • It must appear as a substring in both order sequences. Each order sequence is a string consisting exclusively of lowercase English letters.
  • It must be symmetric; that is, the spell (or incantation) must be a palindrome. In other words, the first character must equal the last character, the second must equal the second last, and so on.

The strength of a spell is determined by its length – longer spells are stronger. Your task is to help the wizards determine the maximum possible spell length among all valid spells (i.e. common palindromic substrings) and count how many distinct spells have that maximum length.

If no such spell exists, output 0 0.

Note: When counting spells, consider only distinct substrings.

inputFormat

The input consists of two lines. The first line contains the first order sequence, and the second line contains the second order sequence. Both strings only consist of lowercase English letters.

outputFormat

Output two integers separated by a space. The first integer is the maximum length of a valid spell and the second is the number of distinct spells of that length.

If there is no valid spell, output 0 0.

sample

abac
cab
1 3