ExpertAlgorithms50 points

Contract redline: how much really changed?

A legal-tech company in London compares two versions of a contract, word by word. The tool looks for the longest sequence of words that appears in both versions in the same order (words in between may be skipped). Everything outside that shared sequence in the old version counts as removed, and everything outside it in the new version counts as added.

Task: line 1 holds the words of the old version, line 2 the words of the new version (each line has 1 to 80 words of lowercase letters, separated by single spaces). Let L be the length of the longest common subsequence of the two word lists. Print three integers separated by spaces: L, the number of removed words and the number of added words.

Sample test

Input

the buyer pays within thirty days
the buyer shall pay within sixty days

Expected output

4 2 3

Your answer is also checked against 5 hidden tests.

Need a hint?

Compare prefixes: the answer for the first i old words and first j new words depends on three smaller cases.