ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        string a, b, c;
        cin>>a>>b>>c;
        
        int l = a.length(), m = b.length(), n = c.length();

        int dp[l+1][m+1];
        dp[0][0] = 0;

        for(int i = 0; i <= l; i++) {
            for(int j = 0; j <= m; j++) {       
                if(i == 0 && j == 0) continue; 
                if(i == 0) dp[i][j] = dp[i][j-1] + (b[j-1] != c[i+j-1]);
                else if(j == 0) dp[i][j] = dp[i-1][j] + (a[i-1] != c[i+j-1]);
                else dp[i][j] = min(dp[i-1][j] + (a[i-1] != c[i+j-1]), dp[i][j-1] + (b[j-1] != c[i+j-1]));
            }
        }

        cout<<dp[l][m]<<endl;
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;

int minChange(int i, int j, string a, string b, string c) {
    if(i >= a.length() && j >= b.length()) return 0;
    else if(i >= a.length()) return (b[j] != c[i+j]) + minChange(i, j+1, a, b, c);
    else if(j >= b.length()) return (a[i] != c[i+j]) + minChange(i+1, j, a, b, c);
    else return min((a[i] != c[i+j])+minChange(i+1, j, a, b, c), (b[j] != c[i+j]) + minChange(i, j+1, a, b, c));
}

int main()
{
    int t;
    cin>>t;
    while(t--) {
        string a, b, c;
        cin>>a>>b>>c;
        cout<<minChange(0, 0, a, b, c)<<endl;
    }
    return 0;
}

Answer: 1
Problem: 2050E - Three Strings
Language: c++20 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
const int MOD = 1e9+7;
const int maxn = 1e3 + 10;
 
void solve(){
    string a,b,c;
    cin >> a >> b >> c;
    int na = a.length();
    int nb = b.length();
    vector<vector<int>> dp(maxn, vector<int>(maxn, 1e15));
    dp[0][0] = 0;
    for(int i = 0; i <= na; i++){
        for(int j = 0; j <= nb; j++){
            if(i + j == 0) continue;
            if(i - 1 >= 0){
                dp[i][j] = min(dp[i][j], dp[i-1][j] + (c[i + j - 1] != a[i-1]));
            }
            if(j - 1 >= 0){
                dp[i][j] = min(dp[i][j], dp[i][j-1] + (c[i + j - 1] != b[j-1]));
            }
        }
    }

    cout << dp[na][nb] << endl;
}

int32_t main(){

    int t=1;
    cin >> t;
    while(t--) solve();

    return 0;
}


Code 2:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
const int MOD = 1e9+7;
 
void solve(){
    string a,b,c;
    cin >> a >> b >> c;
    int na = a.length();
    int nb = b.length();
    vector<vector<int>> dp(na + 1, vector<int>(nb + 1, 1e15));
    dp[0][0] = 0;
    for(int i = 0; i <= na; i++){
        for(int j = 0; j <= nb; j++){
            if(i + j == 0) continue;
            if(i - 1 >= 0){
                dp[i][j] = min(dp[i][j], dp[i-1][j] + (c[i + j - 1] != a[i-1]));
            }
            if(j - 1 >= 0){
                dp[i][j] = min(dp[i][j], dp[i][j-1] + (c[i + j - 1] != b[j-1]));
            }
        }
    }

    cout << dp[na][nb] << endl;
}

int32_t main(){

    int t=1;
    cin >> t;
    while(t--) solve();

    return 0;
}


Answer: 2
Problem: 2050E - Three Strings
Language: c++23 

Code 1:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mod=1e9+7;

void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n=a.size();
    int m=b.size();
    int l=c.size();
    vector<vector<int>>dp(n+1,vector<int>(m+1,1e9));
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        if(c[i-1]==a[i-1]){
            dp[i][0]=dp[i-1][0];
        }
        else{
            dp[i][0]=dp[i-1][0]+1;
        }
    }
    for(int i=1;i<=m;i++){
        if(c[i-1]==b[i-1]){
            dp[0][i]=dp[0][i-1];
        }
        else{
            dp[0][i]=dp[0][i-1]+1;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            dp[i][j] = min(dp[i - 1][j] + (a[i - 1] != c[i + j - 1]),
                                dp[i][j - 1] + (b[j - 1] != c[i + j - 1]));
        }
    }
    cout<<dp[n][m]<<endl;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mod=1e9+7;

void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n=a.size();
    int m=b.size();
    int l=c.size();
    vector<vector<int>>dp(n+1,vector<int>(m+1,1e9));
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        if(c[i-1]==a[i-1]){
            dp[i][0]=dp[i-1][0];
        }
        else{
            dp[i][0]=dp[i-1][0]+1;
        }
    }
    for(int i=1;i<=m;i++){
        if(c[i-1]==b[i-1]){
            dp[0][i]=dp[0][i-1];
        }
        else{
            dp[0][i]=dp[0][i-1]+1;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(c[i+j-1]==a[i-1]){
                dp[i][j]=min(dp[i][j],dp[i-1][j]);
            }
            if(c[i+j-1]==b[j-1]){
                dp[i][j]=min(dp[i][j],dp[i][j-1]);
            }
            else{
                dp[i][j]=min(dp[i][j],min(dp[i-1][j]+1,dp[i][j-1]+1));
            }
        }
    }
    cout<<dp[n][m]<<endl;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    cin>>t;
    while(t--)solve();
    return 0;
}

Answer: 1
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define FORI(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
typedef vector < ll > vl; 
typedef set < ll > setl;
#define ff first
#define ss second    
#define all(v) v.begin(), v.end() 
#define pll pair<ll, ll> 
#define db double
#define nll cout << "\n"
#define nl "\n"
#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

const ll mod =  1000007;
const int MAX = 1e3 + 5;
const int imax = 2147483647;
ll n, m, k, res;
string a, b, c;
void solve(){
    cin >> a >> b >> c;
    n = a.size();
    m = b.size();
    a = '0' + a;
    b = '0' + b;
    c = '0' + c;
    vector < vl > dp(n + 5, vl (m + 5, INT_MAX));
    dp[0][0] = 0;
    FORI(i, n + 1){
        FORI(j, m + 1){
            if(!i && !j)break;
            if(!i){
                dp[i][j] = dp[i][j - 1] + 1;
            }
            else if(!j)dp[i][j] = dp[i - 1][j] + 1;
            else dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
            if(i && c[i + j] == a[i]){
                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            }
            if(j && c[i + j] == b[j]){
                dp[i][j] = min(dp[i][j], dp[i][j - 1]);
            }
        }
    }
    cout << dp[n][m];
}
signed main(){      
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    sync;
    ll t = 1;
    cin >> t;
    FOR(i, t){
        // cout << "Case #" << i << ": ";
        solve();
        nll;
    }
}

Code 2:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define FORI(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
typedef vector < ll > vl; 
typedef set < ll > setl;
#define ff first
#define ss second    
#define all(v) v.begin(), v.end() 
#define pll pair<ll, ll> 
#define db double
#define nll cout << "\n"
#define nl "\n"
#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

const ll mod =  1000007;
const int MAX = 1e3 + 5;
const int imax = 2147483647;
ll n, m, k, res;
string a, b, c;
void solve(){
    cin >> a >> b >> c;
    n = a.size();
    m = b.size();
    a = '0' + a;
    b = '0' + b;
    c = '0' + c;
    vector < vl > dp(n + 5, vl (m + 5, INT_MAX));
    dp[0][0] = 0;
    FORI(i, n + 1){
        FORI(j, m + 1){
            if(!i && !j)continue;
            if(!i){
                dp[i][j] = dp[i][j - 1] + 1;
            }
            else if(!j)dp[i][j] = dp[i - 1][j] + 1;
            else dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] + 1);
            if(i && c[i + j] == a[i]){
                dp[i][j] = min(dp[i][j], dp[i - 1][j]);
            }
            if(j && c[i + j] == b[j]){
                dp[i][j] = min(dp[i][j], dp[i][j - 1]);
            }
        }
    }
    cout << dp[n][m];
}
signed main(){      
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    sync;
    ll t = 1;
    cin >> t;
    FOR(i, t){
        // cout << "Case #" << i << ": ";
        solve();
        nll;
    }
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int dp(string a, string b, string c, int ia, int ib, vector<vector<int>> arr)
{
    if (ia == a.size() && ib == b.size())
    {
        return 0;
    }

    int left = INT_MAX, right = INT_MAX;

    if (ia < a.size())
    {
        if (arr[ia + 1][ib] != -1)
        {
            left = arr[ia + 1][ib] + (a[ia] != c[ia + ib]);
        }
        else
        {
            left = dp(a, b, c, ia + 1, ib, arr) + (a[ia] != c[ia + ib]);
        }
    }
    if (ib < b.size())
    {
        if (arr[ia][ib + 1] != -1)
        {
            right = arr[ia][ib + 1] + (b[ib] != c[ia + ib]);
        }
        else
        {
            right = dp(a, b, c, ia, ib + 1, arr) + (b[ib] != c[ia + ib]);
        }
    }

    arr[ia][ib] = min(left, right);
    return arr[ia][ib];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        string a, b, c;
        cin >> a >> b >> c;

        vector<vector<int>> arr(a.size() + 1, vector<int>(b.size() + 1, -1));

        cout << dp(a, b, c, 0, 0, arr) << endl;
    }

    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int dp(string &a, string &b, string &c, int ia, int ib, vector<vector<int>> &arr)
{
    if (ia == a.size() && ib == b.size())
    {
        return 0;
    }

    if (arr[ia][ib] != -1)
    {
        return arr[ia][ib];
    }

    int left = INT_MAX, right = INT_MAX;

    if (ia < a.size())
    {
        if (arr[ia + 1][ib] != -1)
        {
            left = arr[ia + 1][ib] + (a[ia] != c[ia + ib]);
        }
        else
        {
            left = dp(a, b, c, ia + 1, ib, arr) + (a[ia] != c[ia + ib]);
        }
    }
    if (ib < b.size())
    {
        if (arr[ia][ib + 1] != -1)
        {
            right = arr[ia][ib + 1] + (b[ib] != c[ia + ib]);
        }
        else
        {
            right = dp(a, b, c, ia, ib + 1, arr) + (b[ib] != c[ia + ib]);
        }
    }

    arr[ia][ib] = min(left, right);
    return arr[ia][ib];
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;
    while (t--)
    {
        string a, b, c;
        cin >> a >> b >> c;

        vector<vector<int>> arr(a.size() + 1, vector<int>(b.size() + 1, -1));

        cout << dp(a, b, c, 0, 0, arr) << endl;
    }

    return 0;
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++23 

Code 1:
#include <bits/stdc++.h>
using namespace std;
#define  ull unsigned long long 
#define int long long

int32_t main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

	ull t;cin >> t;
    
    while (t--) {
        
        string a, b, c; cin >>a >> b >> c;
        int l1 = a.length(),l2=b.length(),l3=c.length();
        vector<int> prev(l3,0),curr(l3);
        for (int i = 0;i < l1;i++) {
            for (int j = 0;j < l3;j++) {
                if (j != 0){
                    if (a[i] == c[j]) curr[j] = 1 + prev[j - 1];
                    else curr[j] = max(curr[j - 1], prev[j]);
                }
                else {
                    if (a[i] == c[j]) curr[j] = 1 ;
                    else curr[j] = prev[j];
                }
                
            }
            prev = curr;
        }
        int a1 = curr[l3 - 1];string n;
        int count = 0;vector<int>r;
        for (int j = 0;j < l3;j++) {
            if (curr[j] <=count) {
                
                n += string(1,c[j]);
            }
            else count = curr[j];
        }
        l3 = n.size();
        vector<int> prev1(l3, 0), curr1(l3);
        for (int i = 0;i < l2;i++) {
            for (int j = 0;j < l3;j++) {
                if (j != 0) {
                    if (b[i] == n[j]) curr1[j] = 1 + prev1[j - 1];
                    else curr1[j] = max(curr1[j - 1], prev1[j]);
                }
                else {
                    if (b[i] == n[j]) curr1[j] = 1;
                    else curr1[j] = prev1[j];
                }

            }
            prev1 = curr1;
        }
        int a2 = curr[l3 - 1];
        cout << c.size() - a1 - a2<<endl;
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
using namespace std;
#define  ull unsigned long long 
#define int long long

int32_t main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

	ull t;cin >> t;
    
    while (t--) {
        
        string a, b, c; cin >>a >> b >> c;
        int x = a.length();
        int y = b.length();
        int z = c.length();
        vector<vector<int>> dp(x+1, vector<int>(y+1));
        dp[0][0] = 0;
        for (int i = 1;i <= x;i++) dp[i][0] = dp[i - 1][0] + (int)(a[i - 1] != c[i - 1]);
        for (int j = 1;j <= y;j++) dp[0][j] = dp[0][j-1] + (int)(b[j - 1] != c[j - 1]);
        for (int i = 1;i <= x;i++) {
            for (int j = 1;j <= y;j++) {
                if (c[i + j - 1] != a[i - 1] && c[i + j - 1] != b[j - 1]) {
                    dp[i][j] = min(dp[i - 1][j]+1, dp[i][j - 1]+1);
                }
                if (c[i + j - 1] == a[i - 1] && c[i + j - 1] != b[j - 1]) {
                    dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1] + 1);
                }
                if (c[i + j - 1] != a[i - 1] && c[i + j - 1] == b[j - 1]) {
                    dp[i][j] = min(dp[i - 1][j] + 1, dp[i][j - 1] );
                }
                if (c[i + j - 1] == a[i - 1] && c[i + j - 1] == b[j - 1]) {
                    dp[i][j] = min(dp[i - 1][j] , dp[i][j - 1] );
                }
            }
        }
        cout << dp[x][y] << endl;


    }
    return 0;
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++20 

Code 1:
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int t; cin >>t;
    while(t--){
        string a; string b; string c; cin >> a >> b >> c;
        vector<vector<int>> dp(sz(a)+1,vector<int>(sz(b)+1,1e9));
        dp[0][0]=0;
        for (int k = 0; k < sz(c); k++)
        {
            for (int i = 0; i <= min(k,sz(a)-1)+1; i++)
            {
                int j=(k+1)-i;
                if(i>0){
                    dp[i][j]=dp[i-1][j];
                    if(c[k]!=a[i-1]) dp[i][j]++;
                }
                if(j>0){
                    if(c[k]!=b[j-1]) dp[i][j]=min(dp[i][j-1]+1,dp[i][j]);
                    else dp[i][j]=min(dp[i][j-1],dp[i][j]);
                }
            }
        }
        cout << dp[sz(a)][sz(b)] << "\n";        
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
#define int long long
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
 
using namespace std;
 
signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    int t; cin >>t;
    while(t--){
        string a; string b; string c; cin >> a >> b >> c;
        vector<vector<int>> dp(sz(a)+1,vector<int>(sz(b)+1,1e9));
        dp[0][0]=0;
        for (int k = 0; k < sz(c); k++)
        {
            for (int i = 0; i <= min(k,sz(a)-1)+1; i++)
            {
                int j=(k+1)-i;
                if(j>sz(b)) continue;
                if(i>0){
                    dp[i][j]=dp[i-1][j];
                    if(c[k]!=a[i-1]) dp[i][j]++;
                }
                if(j>0){
                    if(c[k]!=b[j-1]) dp[i][j]=min(dp[i][j-1]+1,dp[i][j]);
                    else dp[i][j]=min(dp[i][j-1],dp[i][j]);
                }
            }
        }
        cout << dp[sz(a)][sz(b)] << "\n";        
    }
    return 0;
}

Answer: 2
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl "\n"
#define float long double
#define int long long int
#define ll long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define PI 3.141592653589793238462643383279
#define all(v) (v).begin(), (v).end() 
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n=a.size(),m=b.size(),sz=c.size();
    vector<vector<int>> dp(sz+1,vector<int> (n+1,1e9));
    dp[0][0]=0;
    for(int i=1;i<=sz;i++){
        for(int j=0;j<=n;j++){
            if(i-j<=m && i-j>0)dp[i][j]=min(dp[i-1][j]+!(b[i-j-1]==c[i-1]),dp[i][j]);
            if(j>0)dp[i][j]=min(dp[i-1][j-1]+!(a[j-1]==c[i-1]),dp[i][j]);
        }
    }
    cout<<dp[sz][n]<<endl;
}
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl "\n"
#define float long double
#define int long long int
#define ll long long
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mod 1000000007
#define PI 3.141592653589793238462643383279
#define all(v) (v).begin(), (v).end() 
#define rall(v) (v).rbegin(), (v).rend()
#define pb push_back
void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    int n=a.size(),m=b.size(),sz=c.size();
    vector<vector<int>> dp(sz+1,vector<int> (n+1,1e9));
    dp[0][0]=0;
    for(int i=1;i<=sz;i++){
        for(int j=0;j<=n;j++){
            if(i-j<=m)dp[i][j]=min(dp[i-1][j]+!(b[i-j-1]==c[i-1]),dp[i][j]);
            dp[i][j]=min(dp[i-1][j-1]+!(a[j-1]==c[i-1]),dp[i][j]);
        }
    }
    cout<<dp[sz][n]<<endl;
}
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Answer: 1
Problem: 2050E - Three Strings
Language: python

Code 1:
import math
def solve():
    a = input()
    b = input()
    c = input()

    n1,n2,n3 = len(a),len(b),len(c)

    dp = {}
    def util(i,j,k):
        if k >= n3:
            return 0
        
        if (i,j,k) in dp:
            return dp[(i,j,k)]
        
        res = 1+min(util(i+1,j,k+1),util(i,j+1,k+1))
        if i<n1 and a[i] == c[k]:
            res = min(res,util(i+1,j,k+1))
        if j<n2 and b[j] == c[k]:
            res = min(res,util(i,j+1,k+1))

        dp[(i,j,k)] = res
        return res
    
    print(util(0,0,0))
    

if __name__ == '__main__':
    t = int(input())
    while t > 0:
        solve()
        t -= 1





Code 2:
def solve():
    # Read input strings
    s1 = input()
    s2 = input()
    s3 = input()
    
    n = len(s1)
    m = len(s2)
    
    # If lengths don't match the requirements, it's impossible
    if len(s3) != n + m:
        print(-1)
        return
        
    # Create DP table
    dp = [[float('inf')] * (m + 1) for _ in range(n + 1)]
    dp[0][0] = 0  # Base case: empty strings need 0 changes
    
    # Fill dp table
    for i in range(n + 1):
        for j in range(m + 1):
            if i + j == 0:
                continue
                
            # Current position in s3 we're trying to match
            k = i + j - 1
            
            # Try taking from s1
            if i > 0:
                cost = 0 if s1[i-1] == s3[k] else 1
                dp[i][j] = min(dp[i][j], dp[i-1][j] + cost)
            
            # Try taking from s2
            if j > 0:
                cost = 0 if s2[j-1] == s3[k] else 1
                dp[i][j] = min(dp[i][j], dp[i][j-1] + cost)
    
    # Answer is in dp[n][m]
    ans = dp[n][m]
    print(ans if ans != float('inf') else -1)

if __name__ == '__main__':
    t = int(input())
    while t > 0:
        solve()
        t -= 1





Answer: 2
Problem: 2050E - Three Strings
Language: c++17 

Code 1:
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007 
using namespace std;
int solve(int i,int j,string& s,string &n,string& m,vector<vector<int>>&dp){
    if(i==n.size() && j==m.size())return 0;
    if(dp[i][j]!=-1)return dp[i][j];
    int ans=INT_MAX;
    if(i<n.size())ans=min(ans,solve(i+1,j,s,n,m,dp)+(n[i]!=s[i+j]));
    if(j<m.size())ans=min(ans,solve(i,j+1,s,n,m,dp)+(m[j]!=s[i+j]));
    return dp[i][j]=ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
 long long a,b,c=0,k,d=0,cnt=0,sum=0,ans=0,e=1;
 string s,m,n;
 cin>>n>>m>>s;
 vector<vector<int>>dp(n.size()+1,vector<int>(m.size()+1,-1));
 cout<< solve(0,0,s,n,m,dp)<<endl;
 
    }
    return 0;
}

Code 2:
#include <bits/stdc++.h>

using namespace std;

int dp[100001][100001];

int solve(int i, int j, const string& a, const string& b, const string& res) {
    if (i == a.size() && j == b.size()) {
        return 0;
    }
    if (dp[i][j] != -1) {
        return dp[i][j];
    }
    int ans = INT_MAX;
    if (i < a.size()) {
        ans = min(ans, solve(i + 1, j, a, b, res) + (a[i] != res[i + j]));
    }
    if (j < b.size()) {
        ans = min(ans, solve(i, j + 1, a, b, res) + (b[j] != res[i + j]));
    }
    dp[i][j] = ans;
    return dp[i][j];
}

int main() {
    int tests;
    cin >> tests;
    while (tests--) {
        string a, b, res;
        cin >> a >> b >> res;
        fill(&dp[0][0], &dp[0][0] + sizeof(dp) / sizeof(int), -1);
        cout << solve(0, 0, a, b, res) << endl;
    }
}


Answer: 1