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: Wrong Answer)

s1,s2 = [gets,gets].map(&:chomp).sort_by(&:size)

s1 += ' '*(s2.size-s1.size)

dp = Array.new(s1.size+1){Array.new(s2.size+1,0)}

s1.size.times do |y|
  dp[y+1][0] = y+1
end
s2.size.times do |x|
  dp[0][x+1] = x+1
end

1.upto(s1.size) do |y|
  1.upto(s2.size) do |x|
    if s2[x-1] == s1[y-1]
      dp[y][x] = dp[y-1][x-1]
    else
      dp[y][x] = [dp[y-1][x], dp[y][x-1], dp[y-1][x-1]].min + 1
    end
  end
end

puts dp[s1.size][s2.size]