#P2516. [HAOI2010] 最长公共子序列

[HAOI2010] 最长公共子序列

Description

A subsequence of a character sequence is a character sequence formed by arbitrarily deleting any number of characters (possibly zero), not necessarily contiguous, from the given sequence. Let the given character sequence be X={x0,x1,,xm1}X=\{x_0,x_1,\cdots,x_{m-1}\}, and let Y={y0,y1,,yk1}Y=\{y_0,y_1,\cdots,y_{k-1}\} be a subsequence of XX if and only if there exists a strictly increasing index sequence {i0,i1,,ik1}\{i_0,i_1,\cdots,i_{k-1}\} of XX such that for all j=0,1,,k1j=0,1,\cdots,k-1, we have xij=yjx_{i_j}=y_j. For example, X="ABCBDAB"X=\verb!"ABCBDAB"!, and Y="BCDB"Y=\verb!"BCDB"! is a subsequence of XX. For two given character sequences, compute the length of their longest common subsequence, and the number of longest common subsequences. Two subsequences ii and jj are different if and only if their lengths are different, or there exists k\exists k such that ikjki_k \neq j_k.

Input Format

The first line is the first character sequence, consisting of uppercase letters, ending with .. The number of uppercase letters does not exceed 50005000.

The second line is the second character sequence, consisting of uppercase letters, ending with .. The number of uppercase letters does not exceed 50005000.

Output Format

On the first line, output the length of the longest common subsequence of the two sequences.

On the second line, output the number of all possible longest common subsequences. The answer may be large; output the answer modulo 10810^{8}.

ABCBDAB.
BACBBD.
4
7

Hint

Translated by ChatGPT 5