#K83072. Longest Common Subsequence Among Multiple Strings

    ID: 36116 Type: Default 1000ms 256MiB

Longest Common Subsequence Among Multiple Strings

Longest Common Subsequence Among Multiple Strings

You are given n strings, and your task is to compute the length of the longest subsequence that is common to all of them. A subsequence of a string is a sequence that can be derived from the string by deleting some or no characters without changing the relative order of the remaining characters. Formally, given strings \(S_1, S_2, \dots, S_n\), find the maximum integer \(L\) such that there exists a sequence \(X\) of length \(L\) which is a subsequence of every \(S_i\).

Note: Since the general problem of finding a common subsequence among multiple strings can be computationally expensive, you may assume that the lengths of the strings are small.

Example:

Input:
3
abcdef
acdf
ade

Output: 2

</p>

inputFormat

The input is given from standard input (stdin). The first line contains an integer \(n\) representing the number of strings. Each of the following \(n\) lines contains a non-empty string.

outputFormat

Output to standard output (stdout) a single integer representing the length of the longest subsequence common to all input strings.

## sample
3
abcdef
acdf
ade
2

</p>