Link to this code: https://cses.fi/paste/9841dd4525100f493fd1cf/
#include <bits/stdc++.h>
#define int long long int
void solve(){
std::string a = "", b = "";
std::cin >> a >> b;
int n = a.size(), m = b.size();
int dp[n+1][m+1];
memset(dp, 0, sizeof(dp));
for(int i=0; i<=n; i++)
dp[i][0] = i;
for(int i=0; i<=m; i++)
dp[0][i] = i;
for(int i=1; i<=n; i++){
for(int j=1; j<=m; j++){
if(a[i-1] == b[j-1])
dp[i][j] = dp[i-1][j-1];
else
dp[i][j] = 1+std::min({dp[i-1][j], dp[i][j-1], dp[i-1][j-1]});
}
}
std::cout << dp[n][m] << "\n";
}
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
int t = 1;
//std::cin >> t;
while(t--){
solve();
}
}