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 Python3 (judge verdict: Accepted)

A = str(input())
n = len(A)
B = str(input())
m = len(B)
#dp[i][j], Aがi文字目、Bがj文字目までにおける最小処理回数
INF = float("inf")
dp = [[INF]*(m+1) for _ in range(n+1)]
#初期化の方法が特殊。片方が0でもう片方がi文字なら最小処理回数はi。
for i in range(n+1):
  dp[i][0] = i
for i in range(m+1):
  dp[0][i] = i

for i in range(n): #i = 0つまり、0文字目なのでdp[1][1]からスタート
  for j in range(m):
    if A[i] == B[j]: #同じ場合そのままか、片方が一つずれているところから追加挿入。
      dp[i+1][j+1] = min(dp[i][j],dp[i][j+1]+1,dp[i+1][j]+1)
    else: #異なる場合i文字目を交換か、片方が一つずれているところから追加挿入。
      dp[i+1][j+1] = min(dp[i][j]+1,dp[i][j+1]+1, dp[i+1][j]+1)
print(dp[n][m])