All problems

Problem 444

Delete Operation for Two Strings

Medium · 20 pts · String, Dynamic Programming

Problem

In one step you may delete exactly one character from either of two strings. Find the minimum number of steps needed to make the two strings equal. The characters you keep must form a common subsequence of both strings, so you want to keep as many as possible: the answer is |A| + |B| - 2 · LCS(A, B), where LCS is the length of the longest common subsequence.

Input

Two lines: strings A and B of lowercase letters.

Output

Print the minimum number of deletions.

Constraints

1 <= |A|, |B| <= 500

Example input

sea
eat

Example output

2

Explanation

For 'sea' and 'eat', delete the 's' from 'sea' and the 't' from 'eat'. Both become 'ea' after 2 deletions.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Longest String Chain Next: Minimum ASCII Delete Sum