Problem:
Edit Distance (Levenshtein Distance)

Find the edit distance between given two words s1 and s2.

The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations:

insertion: Insert a character at a particular position.

deletion: Delete a character at a particular position.

substitution: Change the character at a particular position to a different character

Input

s1
s2

Two words s1 and s2 are given in the first line and the second line respectively. The words will consist of lower case characters.

Output

Print the edit distance in a line.

Constraints

1 ≤ length of s1 ≤ 1000

1 ≤ length of s2 ≤ 1000

Sample Input 1

acac
acm

Sample Output 1

2

Sample Input 2

icpc
icpc

Sample Output 2

0

Solution in Ruby (judge verdict: Accepted)

str1 = gets.chomp
str2 = gets.chomp
lenStr1 = str1.length
lenStr2 = str2.length
matrix = Array.new
(lenStr2+1).times{|i| matrix.push(Array.new(lenStr1,0))}
for i in 1..lenStr1 do
 matrix[0][i] = i
end
for i in 1..lenStr2 do
 matrix[i][0] = i
end
for i in 1..lenStr1 do
 for j in 1..lenStr2 do
  x = (str1[i-1] == str2[j-1]) ? 0 : 1
  y = matrix[j][i-1] + 1
  z = matrix[j-1][i] + 1
  matrix[j][i] = [matrix[j-1][i-1]+x,y,z].min
 end
end
print("#{matrix[lenStr2][lenStr1]}\n")