Minimum edit

Compute the Levenshtein distance between two lowercase strings, using the fewest insert, delete, and replace operations to change A into B.

Medium6Dynamic programmingStringArrayPrefix sumInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Given two strings AA and BB, the task of turning AA into BB with the fewest operations is called the minimum edit problem.

Three operations apply to AA.

  1. Insert: put one character at any position of AA.
  2. Delete: remove one character of AA.
  3. Replace: change one character of AA into another character.

Given the two strings, write a program that computes the minimum number of edits.

Input

The first line has the string AA and the second line has the string BB. Both strings consist of lowercase letters only, and neither is longer than 1000 characters.

Output

Print on the first line the minimum number of edits that turn AA into BB.