#include <bits/stdc++.h>
using namespace std;
int minDistance(string word1, string word2) {
auto min3=[](int a,int b,int c)
{
return min(a,min(b,c));
};
int m=word1.size();
int n=word2.size();
int dp[m+1][n+1];
memset(dp,0,sizeof(dp));
for(int i=1;i<=m;++i)
{
dp[i][0]=i;
}
for(int i=1;i<=n;++i)
{
dp[0][i]=i;
}
for(int i=1;i<=m;++i)
{
for(int j=1;j<=n;++j)
{
if(word1[i-1]==word2[j-1])
{
dp[i][j]=dp[i-1][j-1];
}
else
{
dp[i][j]=1+min3(dp[i-1][j-1],dp[i-1][j],dp[i][j-1]);
}
}
}
return dp[m][n];
}
int main() {
string word1 = "ioana";
string word2 = "dana";
cout<<minDistance(word1, word2);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1pbkRpc3RhbmNlKHN0cmluZyB3b3JkMSwgc3RyaW5nIHdvcmQyKSB7CiAgICBhdXRvIG1pbjM9W10oaW50IGEsaW50IGIsaW50IGMpCiAgICB7CiAgICAgICAgcmV0dXJuIG1pbihhLG1pbihiLGMpKTsKICAgIH07CiAgICBpbnQgbT13b3JkMS5zaXplKCk7CiAgICBpbnQgbj13b3JkMi5zaXplKCk7CiAgICBpbnQgZHBbbSsxXVtuKzFdOwogICAgbWVtc2V0KGRwLDAsc2l6ZW9mKGRwKSk7CiAgICBmb3IoaW50IGk9MTtpPD1tOysraSkKICAgIHsKICAgICAgICBkcFtpXVswXT1pOwogICAgfQogICAgZm9yKGludCBpPTE7aTw9bjsrK2kpCiAgICB7CiAgICAgICAgZHBbMF1baV09aTsKICAgIH0KICAgIGZvcihpbnQgaT0xO2k8PW07KytpKQogICAgewogICAgICAgIGZvcihpbnQgaj0xO2o8PW47KytqKQogICAgICAgIHsKICAgICAgICAgICAgaWYod29yZDFbaS0xXT09d29yZDJbai0xXSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZHBbaV1bal09ZHBbaS0xXVtqLTFdOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZHBbaV1bal09MSttaW4zKGRwW2ktMV1bai0xXSxkcFtpLTFdW2pdLGRwW2ldW2otMV0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIGRwW21dW25dOwp9CgppbnQgbWFpbigpIHsKCQoJc3RyaW5nIHdvcmQxID0gImlvYW5hIjsKCXN0cmluZyB3b3JkMiA9ICJkYW5hIjsKCQoJY291dDw8bWluRGlzdGFuY2Uod29yZDEsIHdvcmQyKTsKfQ==