#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
class LevenshteinDistance
{
public:
  static int edit(const string &px, const string &py)
  {
    int len1=px.size(),len2=py.size();
    vector<vector<int> > row(len1+1, vector<int>(len2+1));
    int i,j;
    int result;
    for(i=0;i<len1+1;i++) row[i][0]=i;
    for(i=0;i<len2+1;i++) row[0][i]=i;
    for(i=1;i<=len1;++i)
    {
      for(j=1;j<=len2;++j)
      {
        row[i][j] = min(min(
                      row[i-1][j-1] + ((px[i-1]==py[j-1])?0:1) , // replace
                      row[i][j-1] + 1),     // delete
                       row[i-1][j] + 1  );  // insert
      }
    }
    result=row[i-1][j-1];
    return result;
  }
};

int main()
{
  cout<<LevenshteinDistance::edit("あい","あいう")<<endl;
  return(0);
}
