#K48707. Longest Common Substring
Longest Common Substring
Longest Common Substring
Given two strings A and B, your task is to compute the length of the longest common substring between them. A substring is defined as a contiguous sequence of characters within a string.
The problem can be formulated using the following recurrence:
\( dp(i, j) = \begin{cases} dp(i-1, j-1) + 1 & \text{if } A[i-1] = B[j-1] \\ 0 & \text{otherwise} \end{cases}\)
The answer is \( \max dp(i, j) \) over all valid \(i\) and \(j\).
Your solution should efficiently handle larger inputs. Input is provided via standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The input consists of two lines. The first line contains string A and the second line contains string B.
outputFormat
Output a single integer which represents the length of the longest common substring of A and B.
## sampleinvestment
vestment
8