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

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

#define int long long

void solve() {
	string a, b, c; cin >> a >> b >> c;
	int n = a.size(); int m = b.size();

	vector<vector<int>> dp(n+1, vector<int>(m+1, 1e9));
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			bool changeA = !(a[i-1] == c[i+j-1]);
			bool changeB = !(b[j-1] == c[i+j-1]);

			dp[i][j] = min(dp[i-1][j] + changeA, dp[i][j-1] + changeB);
		}
	}

	cout << dp[n][m] << endl;
}

signed main() {
	int t; cin >> t;

	while (t--) {
		solve();
	}
}


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

#define int long long

void solve() {
	string a, b, c; cin >> a >> b >> c;
	int n = a.size(); int m = b.size();

	vector<vector<int>> dp(n+1, vector<int>(m+1, 1e9));
	dp[0][0] = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i < n) {
				int changeA = (a[i] != c[i+j]);
				dp[i+1][j] = min(dp[i+1][j], dp[i][j] + changeA);
			} 

			if (j < m) {
				int changeB = (b[j] != c[i+j]);
				dp[i][j+1] = min(dp[i][j+1], dp[i][j] + changeB);
			}
		}
	}

	cout << dp[n][m] << endl;
}

signed main() {
	int t; cin >> t;

	while (t--) {
		solve();
	}
}


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

Code 1:
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;




void solve() {
    string a, b, c;
    cin >> a >> b >> c;    
    int na = a.size();
    int nb = b.size();
    vector<vector<int>> dp(na + 1, vector<int>(nb + 1, na + nb + 1));
    for (int i = 0; i <= a.size();i++) {
        for (int j = 0; j <= b.size();j++) {
            dp[i][j] = 1e7;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i <= a.size();i++) {
        for (int j = 0; j <= b.size();j++) {
            if (i == 0 && j == 0) {
                dp[i][j] = 0;
            }
            else {
                if (i == 0) {
                    dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[j - 1]));
                }
                else if (j == 0) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != a[i - 1]));
                }
                else {
                    dp[i][j] = min(dp[i][j], min(dp[i - 1][j] + (c[i + j - 1] != a[i - 1]), dp[i][j - 1] + (c[i + j - 1] != b[j - 1])));
                }
            }
        }
    }
    cout << dp[a.size()][b.size()] << '\n';
}
int main() {
    int te;
    cin >> te;
    while (te--) {
        solve();
    }
}

Code 2:
#include<iostream>
#include<cstring>
using namespace std;




void solve() {
    char* a = new char[1005];
    char* b = new char[1005];
    char* c = new char[1005];
    cin.getline(a, 1000, '\n');
    cin.getline(b, 1000, '\n');
    cin.getline(c, 1000, '\n');
    int** dp = new int*[strlen(a) + 1];
    for (int i = 0; i <= strlen(a);i++) {
        dp[i] = new int[strlen(b) + 1];
    }
    for (int i = 0; i <= strlen(a);i++) {
        for (int j = 0; j <= strlen(b);j++) {
            dp[i][j] = 1e7;
        }
    }
    dp[0][0] = 0;
    for (int i = 0; i <= strlen(a);i++) {
        for (int j = 0; j <= strlen(b);j++) {
            if (i == 0 && j == 0) {
                dp[i][j] = 0;
            }
            else {
                if (i == 0) {
                    dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[j - 1]));
                }
                else if (j == 0) {
                    dp[i][j] = min(dp[i][j], dp[i - 1][j] + (c[i - 1] != a[i - 1]));
                }
                else {
                    dp[i][j] = min(dp[i][j], min(dp[i - 1][j] + (c[i + j - 1] != a[i - 1]), dp[i][j - 1] + (c[i + j - 1] != b[j - 1])));
                }
            }
        }
    }
    cout << dp[strlen(a)][strlen(b)] << '\n';
    for (int i = 0; i <= strlen(a);i++) {
        delete[] dp[i];
        dp[i] = NULL;
    }
    delete[] dp;
    dp = NULL;
    delete[] a;
    a = NULL;
    delete[] b;
    b = NULL;
    delete[] c;
    c = NULL;
}
int main() {
    int te;
    cin >> te;
    cin.ignore();
    while (te--) {
        solve();
    }
}

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

Code 1:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int md= 998244353;
const int N=200005;
const int M=1<<13;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
string dir="RLDU";
vector<vector<int>>dp;
string a,b,c;
int n,m;
int rec(int i,int j)
{
    if(i>a.size()||j>b.size())return 1e9;

    if(i==a.size())
    {
        int rem=0;
        for(int k=j;k<b.size();k++)
            if(b[k]!=c[k+a.size()])rem++;
        return rem;
    }
    if(j==b.size())
    {
        int rem=0;
        for(int k=i;k<a.size();k++)
            if(a[k]!=c[k+b.size()])rem++;
        return rem;
    }
    int &ret=dp[i][j];
    if(~ret)return ret;
    ret=1e9;
    if(i+1<=a.size())ret=min(ret,rec(i+1,j)+(c[i+j]!=a[i]));
    if(j+1<=b.size())ret=min(ret,rec(i,j+1)+(c[i+j]!=b[j]));

    return ret;
}
signed main()
{
    //freopen("distinct.in","r",stdin);
   //freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
    int t=1;cin>>t;
    while(t--)
    {
        cin>>a>>b>>c;
        dp=vector<vector<int>>(a.size()+5,vector<int>(b.size()+5,-1));
        cout<<rec(0,0)<<'\n';
    }
}


Code 2:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int md= 998244353;
const int N=200005;
const int M=1<<13;
int dx[]={0,0,-1,1};
int dy[]={1,-1,0,0};
string dir="RLDU";
vector<vector<int>>dp;
string a,b,c;
int n,m;
int rec(int i,int j)
{
    if(i>a.size()||j>b.size())return 1e9;

    if(i==a.size())
    {
        int rem=0;
        for(int k=j;k<b.size();k++)
            if(b[k]!=c[j+a.size()])rem++;
        return rem;
    }
    if(j==b.size())
    {
        int rem=0;
        for(int k=i;k<a.size();k++)
            if(a[k]!=c[i+b.size()])rem++;
        return rem;
    }
    int &ret=dp[i][j];
    if(~ret)return ret;
    ret=1e9;
    if(i+1<=a.size())ret=min(ret,rec(i+1,j)+(c[i+j]!=a[i]));
    if(j+1<=b.size())ret=min(ret,rec(i,j+1)+(c[i+j]!=b[j]));

    return ret;
}
signed main()
{
    //freopen("distinct.in","r",stdin);
   //freopen("out.txt","w",stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
    int t=1;cin>>t;
    while(t--)
    {
        cin>>a>>b>>c;
        dp=vector<vector<int>>(a.size()+5,vector<int>(b.size()+5,-1));
        cout<<rec(0,0)<<'\n';
    }
}


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

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

typedef long long int lli;
const int modd = 1e9 + 7;

#define int long long
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define bac(i, a, b) for (int i = a; i >= b; i--)
#define yes "YES"
#define no "NO"
#define nl " \n"
#define ak(x) cout << x << "\n";
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
template <class T>using max_heap = priority_queue<T>;
template <class T>using min_heap = priority_queue<T, vector<T>, greater<T>>;


int solve(int l,int m,int n,string &a,string &b,string &c,vector<vector<int>>&dp){
	if(n==0) return 0;
	if(l == 0){
		// cout<<"AK:"<<"M:"<<m<<" N:"<<n<<nl;
		int cnt=0;
		for(int i=0;i<n;i++){
			if(b[i] != c[i]) cnt++;
		}
		return cnt;
	}
	if(m == 0){
		// cout<<"AK:"<<"L:"<<l<<" N:"<<n<<nl;
		int cnt=0;
		for(int i=0;i<n;i++){
			if(a[i] != c[i]) cnt++;
		}
		return cnt;
	}

	if(dp[l][m] != -1) return dp[l][m];

	if(a[l-1] == c[n-1] && b[m-1] == c[n-1]){
		return dp[l][m] = min(solve(l-1,m,n-1,a,b,c,dp),solve(l,m-1,n-1,a,b,c,dp));
	}
	if(a[l-1] == c[n-1]){
		return dp[l][m] = min(solve(l-1,m,n-1,a,b,c,dp),1+solve(l,m-1,n-1,a,b,c,dp));
	}
	if(b[m-1] == c[n-1]){
		return dp[l][m] = min(solve(l,m-1,n-1,a,b,c,dp),1+solve(l-1,m,n-1,a,b,c,dp));
	}
	else {
		// not matches with anyone then skip it
		return dp[l][m] = 1 + min(solve(l-1,m,n-1,a,b,c,dp),solve(l,m-1,n-1,a,b,c,dp));
	}
}

void solve(){
	string a,b,c; cin>>a>>b>>c;

	int l=a.size();
	int m=b.size();
	int n=c.size();
	vector<vector<int>>dp(l+1,vector<int>(m+1,-1));
	cout<<solve(l,m,n,a,b,c,dp)<<nl;
}


int32_t main(){
	fastio();
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	cin >> t;

	while (t--){
		solve();
	}
}

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

typedef long long int lli;
const int modd = 1e9 + 7;

#define int long long
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define all(x) begin(x), end(x)
#define allr(x) rbegin(x), rend(x)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define bac(i, a, b) for (int i = a; i >= b; i--)
#define yes "YES"
#define no "NO"
#define nl " \n"
#define ak(x) cout << x << "\n";
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
template <class T>using max_heap = priority_queue<T>;
template <class T>using min_heap = priority_queue<T, vector<T>, greater<T>>;


void solve(){
	
}


int32_t main(){
	fastio();
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	cin >> t;

	while (t--){
		solve();
	}
}

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

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

const int MAX_N = (int) 1e3;
const int INF = (int) 1e9;
int dp[MAX_N][MAX_N];
string a, b, c;
int n, m;

int sol (int i = 0, int j = 0) {
    if (i == n and j == m) {
        return 0;
    }
    int& ans = dp[i][j];
    if (ans != -1) {
        return ans;
    }
    ans = INF;
    int k = i + j;
    if (i < n) {
        ans = min(ans, sol(i + 1, j) + (a[i] != c[k]));
    }
    if (j < m) {
        ans = min(ans, sol(i, j + 1) + (b[j] != c[k]));
    }
    return ans;
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while (tt--) {
        cin >> a >> b >> c;
        n = (int) a.size();
        m = (int) b.size();
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= m; ++j) {
                dp[i][j] = -1;
            }
        }   
        cout << sol() << '\n';
    }
    return 0;
}

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

const int MAX_N = (int) 1e3;
const int INF = (int) 1e9;
int dp[MAX_N + 1][MAX_N + 1];
string a, b, c;
int n, m;

int sol (int i = 0, int j = 0) {
    if (i == n and j == m) {
        return 0;
    }
    int& ans = dp[i][j];
    if (ans != -1) {
        return ans;
    }
    ans = INF;
    int k = i + j;
    if (i < n) {
        ans = min(ans, sol(i + 1, j) + (a[i] != c[k]));
    }
    if (j < m) {
        ans = min(ans, sol(i, j + 1) + (b[j] != c[k]));
    }
    return ans;
}

int main () {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt;
    cin >> tt;
    while (tt--) {
        cin >> a >> b >> c;
        n = (int) a.size();
        m = (int) b.size();
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= m; ++j) {
                dp[i][j] = -1;
            }
        }   
        cout << sol() << '\n';
    }
    return 0;
}

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

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

string a, b, c;
char v[1010];
int t, lenc, minc = 1010;
int lena, lenb;

void dfs(int x, int i, int j)
{
    if (x > lenc - 1)
    {
        int cnt = 0;
        for (int k = 0; k < lenc; k++)
        {
            if (v[k] != c[k])
                cnt++;
        }
        if (cnt < minc)
            minc = cnt;
        return;
    }
    if (i >lena || j > lenb)
        return;

    if (i < lena)
    {
        v[x] = a[i];
        dfs(x + 1, i + 1, j);
    }
    if (j < lenb)
    {
        v[x] = b[j];
        dfs(x + 1, i, j + 1);
    }
}

int main()
{
    cin >> t;
    while (t--)
    {
        cin >> a >> b >> c;
        lena = a.size();
        lenb = b.size();
        lenc = c.size();
        dfs(0, 0, 0);
        cout << minc << endl;
        minc = 1010;
    }
}


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

template <typename T>
bool cmin(T &a, const T &b)
{
    return b < a ? a = b, 1 : 0;
}

template <typename T>
bool cmax(T &a, const T &b)
{
    return b > a ? a = b, 1 : 0;
}

void go()
{
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size();
    int m = b.size();
    vector<vector<int>> f(n + 1, vector<int>(m + 1, -1));
    f[0][0] = 0;
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            if (f[i][j] == -1)
            {
                continue;
            }
            if (i + 1 <= n)
            {
                cmax(f[i + 1][j], f[i][j] + (a[i] == c[i + j] ? 1 : 0));
            }
            if (j + 1 <= m)
            {
                cmax(f[i][j + 1], f[i][j] + (b[j] == c[i + j] ? 1 : 0));
            }
        }
    }
    cout << n + m - f[n][m] << endl;
}

int main()
{
    int caseCnt;
    cin >> caseCnt;
    for (int i = 1; i <= caseCnt; i++)
        go();
    return 0;
}

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

Code 1:
#include<bits/stdc++.h>
using namespace std;
int helper(int i , int j, string &a, string &b , string &c,vector<vector<int>> &dp) {
    if(i + j >= c.size()){
        return  dp[i][j] = 0 ;
    }
    int temp1 =1;
    if(a[i]==c[i+j]){
        temp1--;
    }
    int temp2 = 1;
    if(b[j] == c[i+j]){
        temp2--;
    }
    if(i==a.size()){
        
        return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp);
    }
    if(j==b.size()){
       
        return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp);
    }
    return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) );
}
int main()
{
    
    int n;
    cin>>n;
    
    while(n--)
    {
        string a  , b , c;
        cin>>a>>b>>c;
        vector<vector<int>> dp(a.size() + 1, vector<int> (b.size()+1));
        cout<<helper(0,0,a,b,c,dp);
        cout<<"\n";
      

    }
    return 0;
}


Code 2:
#include<bits/stdc++.h>
using namespace std;
int helper(int i , int j, string &a, string &b , string &c,vector<vector<int>> &dp) {
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(i + j >= c.size()){
        return  dp[i][j] = 0 ;
    }
    int temp1 =1;
    if(a[i]==c[i+j]){
        temp1--;
    }
    int temp2 = 1;
    if(b[j] == c[i+j]){
        temp2--;
    }
    if(i==a.size()){
        
        return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp);
    }
    if(j==b.size()){
       
        return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp);
    }
    return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) );
}
int main()
{
    
    int n;
    cin>>n;
    
    while(n--)
    {
        string a  , b , c;
        cin>>a>>b>>c;
        vector<vector<int>> dp(a.size() + 1, vector<int> (b.size()+1 , -1));
        cout<<helper(0,0,a,b,c,dp);
        cout<<"\n";
      

    }
    return 0;
}


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

Code 1:
#include <cstdio>
#include <string>
#include <vector>
char buf[2000 + 3], buf1[1000 + 3], buf2[1000 + 3];
struct triple {
    int ind1;
    int ind2;
    int count;
};
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf(" %s %s %s", buf1, buf2, buf);
        std::string str1(buf1), str2(buf2), str(buf);
        int n = str1.size(), m = str2.size();
        std::vector<std::vector<int>> dp(n + 5, std::vector<int> (m + 5));
        dp[0][0] = 0;
        for (int i = 0; i < n; i++) {
            dp[i + 1][0] = dp[i][0] + (str1[i] != str[i]);
        }
        for (int i = 0; i < m; i++) {
            dp[0][i + 1] = dp[0][i] + (str2[i] != str[i]);
        }
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= m; j++) {
                dp[i][j] = std::min(dp[i - 1][j] + (str1[i - 1] != str[i + j - 1]),
                                    dp[i][j - 1] + (str2[j - 1] != str[i + j - 1]));
            }
        }
        printf("%d\n", dp[n][m]);
    }
}


Code 2:
#include <cstdio>
#include <string>
#include <queue>
char buf[2000 + 3], buf1[1000 + 3], buf2[1000 + 3];
struct triple {
    int ind1;
    int ind2;
    int count;
};
int main() {
    int t = 1;
    scanf("%d", &t);
    while (t--) {
        scanf(" %s %s %s", buf1, buf2, buf);
        std::string str1(buf1), str2(buf2), str(buf);
        std::queue<triple> q;
//        printf("\n\n%s %s %s\n\n", str1.c_str(), str2.c_str(), str.c_str());
//        if (str1.size() < str2.size()) std::swap(str1, str2);
        q.push({1, 0, int(str1[0] != str[0])});
        q.push({0, 1, int(str2[0] != str[0])});
        int index = 1;
        int ans = 1000'000'000;
        int counter = 1;
        while (!q.empty()) {
            triple &cur = q.front(); bool bl1 = 1, bl2 = 1;
            q.pop();
//            printf("%d.%d %d %d -> \n", counter++, cur.ind1, cur.ind2, cur.count);
            if (cur.ind1 < str1.size()) {
                q.push({cur.ind1 + 1, cur.ind2, cur.count + int(str1[cur.ind1] != str[cur.ind1 + cur.ind2])});
                bl1 = 0;
            }
            if (cur.ind2 < str2.size()) {
                q.push({cur.ind1, cur.ind2 + 1, cur.count + int(str2[cur.ind2] != str[cur.ind1 + cur.ind2])});
                bl2 = 0;
            }
            if (bl1 & bl2) {
                ans = std::min(ans, cur.count);
//                printf("END!!!");
            }
//            printf("\n");
        }
        printf("%d\n", ans);
    }
}


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

Code 1:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[1005][1005];
string a,b,c;
int solve(int i,int j)
{
    int k=i+j;
    if(dp[i][j]==-1)
    {
        dp[i][j]=1e18;
        if(i<a.size())dp[i][j]=solve(i+1,j)+(a[i]!=c[k]);
        if(j<b.size())dp[i][j]=min(dp[i][j],solve(i,j+1)+(b[j]!=c[k]));
        if(dp[i][j]==1e18)dp[i][j]=0;
    }

    return dp[i][j];
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   int t;
   cin>>t;
   while(t--)
   {
       memset(dp,-1,sizeof(dp));
       cin>>a>>b>>c;
       cout<<solve(0,0)<<'\n';
   }
}


Code 2:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int dp[1000][1000];
string a,b,c;
int solve(int i,int j)
{
    int k=i+j;
    if(dp[i][j]==-1)
    {
        dp[i][j]=1e18;
        if(i<a.size())dp[i][j]=solve(i+1,j)+(a[i]!=c[k]);
        if(j<b.size())dp[i][j]=min(dp[i][j],solve(i,j+1)+(b[j]!=c[k]));
        if(dp[i][j]==1e18)dp[i][j]=0;
    }

    return dp[i][j];
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   int t;
   cin>>t;
   while(t--)
   {
       memset(dp,-1,sizeof(dp));
       cin>>a>>b>>c;
       cout<<solve(0,0)<<'\n';
   }
}


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

Code 1:
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()];

    }

}













Code 2:
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main() 

{

    int t;

    cin >> t;

    for (; t > 0; --t)

    {

        string a, b, c;

        cin >> a >> b >> c;

        vector<vector<int>> ans(a.size() + 1, vector<int>(b.size() + 1, 0));

        for (int i = 1; i <= a.size(); ++i)

        {

            if (c[i - 1] != a[i - 1])

                ans[i][0] = ans[i - 1][0] + 1;

            else

                ans[i][0] = ans[i - 1][0];

        }

        for (int i = 1; i <= b.size(); ++i)

        {

            if (c[i - 1] != b[i - 1])

                ans[0][i] = ans[0][i - 1] + 1;

            else

                ans[0][i] = ans[0][i - 1];

        }

        for (int i = 1; i <= a.size(); ++i)

        {

            for (int j = 1; j <= b.size(); ++j)

            {

                if (a[i - 1] == c[i + j - 1])

                    ans[i][j] = ans[i - 1][j];

                else

                    ans[i][j] = ans[i - 1][j] + 1;

                if (b[j - 1] == c[i + j - 1])

                    ans[i][j] = min(ans[i][j], ans[i][j - 1]);

                else

                    ans[i][j] = min(ans[i][j], ans[i][j - 1] + 1);

            }

        }

        cout << ans[a.size()][b.size()] << endl;

    }

}













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

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

#define ll long long
#define ld long double
#define INF 1000000000

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        a = "`" + a;
        b = "`" + b;
        vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
        // for (int i = 0; i < n + 2; i++) {
        //     dp[i][0] = 0;
        // }
        // for (int i = 0; i < m + 2; i++) {
        //     dp[0][i] = 0;
        // }
        dp[1][1] = 0;
        int k = 0;
        while (k < n + m) {
            k++;
            for (int i = 0; i < min(n, k) + 1; i++) {
                int j = k - i;
                if (j < 0 || j > m) continue;
                dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j]));
            }
        }
        // for (int i = 0; i < n + 2; i++) {
        //     for (int j = 0; j < m + 2; j++) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << "\n";
        // }
        // cout << "\n";
        cout << dp[n + 1][m + 1] << "\n";
    }
    return 0;
}

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

#define ll long long
#define ld long double
#define INF 1000000000

using namespace std;

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    for (int q = 0; q < t; q++) {
        string a, b, c;
        cin >> a >> b >> c;
        int n = a.size();
        int m = b.size();
        a = "`" + a;
        b = "`" + b;
        vector<vector<int>> dp(n + 2, vector<int>(m + 2, INF));
        // for (int i = 0; i < n + 2; i++) {
        //     dp[i][0] = 0;
        // }
        // for (int i = 0; i < m + 2; i++) {
        //     dp[0][i] = 0;
        // }
        dp[1][1] = 0;
        int k = 0;
        while (k < n + m) {
            k++;
            for (int i = 0; i < min(n, k) + 1; i++) {
                int j = k - i;
                if (j < 0 || j > m) continue;
                dp[i + 1][j + 1] = min(dp[i][j + 1] + (c[k - 1] != a[i]), dp[i + 1][j] + (c[k - 1] != b[j]));
            }
        }
        for (int i = 0; i < n + 2; i++) {
            for (int j = 0; j < m + 2; j++) {
                cout << dp[i][j] << " ";
            }
            cout << "\n";
        }
        cout << "\n";
        cout << dp[n + 1][m + 1] << "\n";
    }
    return 0;
}

Answer: 1