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

using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{


    class Program
    {

        const int INF = 1000000000;

        static int Solve(string X, string Y)
        {
            int xn = X.Length;
            int yn = Y.Length;

            int[,] dp = new int[xn + 1, yn + 1];

            dp[0, 0] = 0; 
            
            for(int i = 1; i <= xn; i++)
            {
                dp[i, 0] = i;
            }
            for(int j = 1;j <= yn; j++)
            {
                dp[0, j] = j;
            }
            
            for(int i = 1; i <= xn; i++)
            {
                for(int j = 1; j <= yn; j++)
                {
                    dp[i, j] = INF;
                    if(X[i - 1] == Y[j - 1])
                    {
                        dp[i, j] = dp[i - 1, j - 1];
                    }
                    else
                    {
                        if(i - 1 >= 0 && j - 1 >= 0)
                        {
                            dp[i, j] = Math.Min(dp[i, j], dp[i - 1, j - 1] + 1);
                        }
                        if(i - 1 >= 0)
                        {
                            dp[i, j] = Math.Min(dp[i, j], dp[i - 1, j] + 1);
                        }
                        if(j - 1 >= 0)
                        {
                            dp[i, j] = Math.Min(dp[i, j], dp[i, j - 1] + 1);
                        }
                    }


                }
            }
            
            return dp[xn, yn];
        }



        static void Main(string[] args)
        {
            string X = Console.ReadLine();
            string Y = Console.ReadLine();

            Console.WriteLine(Solve(X, Y));
        }
    }
}