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 = gets.chomp.split('')
$s2 = gets.chomp.split('')

s1_length = $s1.length

s2_length = $s2.length

$table = Array.new(s1_length + 1).map { Array.new(s2_length + 1, 0) }

def max(a, b)
  a < b ? b : a
end

s1_length.times do |i|
  s2_length.times do |j|
    $table[i + 1][j + 1] = if s1_length[i] == s2_length[j]
                             $table[i][j] + 1
                           else
                             max($table[i + 1][j], $table[i][j + 1])
                          end
  end
end

common = $table.last.last

puts max(s1_length, s2_length) - common