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)

def distance(str1, str2)
  str1, str2 = str1.split(//).unshift(0), str2.split(//).unshift(0)
  arr = Array.new(str1.size){Array.new(str2.size)}
  for i in 0...str2.size
    arr[0][i] = i
  end
  for i in 1...str1.size
    arr[i][0] = i
    for j in 1...str2.size
      if str1[i] == str2[j]
        arr[i][j] = [arr[i - 1][j - 1], arr[i - 1][j] + 1, arr[i][j - 1] + 1].min
      elsif i == j
        arr[i][j] = [arr[i - 1][j], arr[i][j - 1]].min
      else
        arr[i][j] = [arr[i - 1][j] + 1, arr[i][j - 1] + 1].min
      end
    end
  end
  puts arr.last.last
end
def main(input = $stdin)
  distance(input.gets.chomp, input.gets.chomp)
end
main