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

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

using namespace std;

long long t,dp[1005][1005];

string a,b,c;

void solve(){

    cin>>a>>b>>c;

    vector<pair<int,int>> v;

    int n=a.size(),m=b.size(),k=c.size();

    a=' '+a; b=' '+b; c=' '+c;

    for(int i=1; i<=n; i++){

        dp[i][0]=dp[i-1][0]+(a[i]!=c[i]);

        v.push_back({i,0});

    }

    for(int i=1; i<=m; i++){

        dp[0][i]=dp[0][i-1]+(b[i]!=c[i]);

        v.push_back({0,i});

    }

    for(int i=1; i<=n; i++){

        for(int j=1; j<=m; j++){

            dp[i][j]=min(dp[i-1][j]+(a[i]!=c[i+j]), dp[i][j-1]+(b[j]!=c[i+j]));

            v.push_back({i,j}); v.push_back({j,i});

        }

    }

    cout<<dp[n][m]<<'\n';

    for(auto x:v){

        dp[x.first][x.second]=0;

    }

}

int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);

    // freopen(".inp", "r", stdin);

    // freopen(".out", "w", stdout);

    cin>>t;

    while(t--){

        solve();

    }

}

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

using namespace std;

long long t,dp[1005][1005];

string a,b,c;

void solve(){

    cin>>a>>b>>c;

    for(int i=1; i<=1003; i++){

        for(int j=1; j<=1003; j++){

            dp[i][j]=0;

        }

    }

    int n=a.size(),m=b.size(),k=c.size();

    a=' '+a; b=' '+b; c=' '+c;

    for(int i=1; i<=n; i++){

        dp[i][0]=dp[i-1][0]+(a[i]!=c[i]);

        dp[0][i]=dp[0][i-1]+(b[i]!=c[i]);

    }

    for(int i=1; i<=n; i++){

        for(int j=1; j<=m; j++){

            dp[i][j]=min(dp[i-1][j]+(a[i]!=c[i+j]), dp[i][j-1]+(b[j]!=c[i+j]));

        }

    }

    cout<<dp[n][m]<<'\n';

}

int main(){

    ios_base::sync_with_stdio(0);

    cin.tie(0); cout.tie(0);

    // freopen(".inp", "r", stdin);

    // freopen(".out", "w", stdout);

    cin>>t;

    while(t--){

        solve();

    }

}

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

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

int minChanges(string &a, string &b, string &c) {
    int n = a.length(), m = b.length();
    vector<int> prev(m + 1, 0), curr(m + 1, 0);

    // Initialize base cases
    for (int j = 0; j <= m; ++j) {
        prev[j] = j; // Only use characters from `b`
    }

    for (int i = 0; i <= n; ++i) {
        curr[0] = i; // Only use characters from `a`

        for (int j = 0; j <= m; ++j) {
            if (i == 0 && j == 0) continue; // Base case already handled
            int k = i + j - 1; // Current index in `c`

            curr[j] = INT_MAX; // Initialize to a large value

            if (i > 0 && a[i - 1] == c[k]) { // Match with `a`
                curr[j] = min(curr[j], prev[j]);
            } else if (i > 0) { // Mismatch with `a`
                curr[j] = min(curr[j], prev[j] + 1);
            }

            if (j > 0 && b[j - 1] == c[k]) { // Match with `b`
                curr[j] = min(curr[j], curr[j - 1]);
            } else if (j > 0) { // Mismatch with `b`
                curr[j] = min(curr[j], curr[j - 1] + 1);
            }
        }

        // Swap `prev` and `curr`
        swap(prev, curr);
    }

    return prev[m];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) {
        string a, b, c;
        cin >> a >> b >> c;
        cout << minChanges(a, b, c) << '\n';
    }

    return 0;
}


Code 2:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int f(int i,int j,int k,vector<vector<int>>&dp,string a,string b,string c){
  if(i==a.length()&&j==b.length()){
    return 0;
  }
  if(dp[i][j]!=-1)return dp[i][j];
  if(i<a.length()&&j<b.length()){
    if(a[i]==b[j]){
      if(a[i]==c[k]){
        return dp[i][j]=min(f(i+1,j,k+1,dp,a,b,c),f(i,j+1,k+1,dp,a,b,c));
      }
      return dp[i][j]=1+min(f(i+1,j,k+1,dp,a,b,c),f(i,j+1,k+1,dp,a,b,c));
    }
    if(a[i]==c[k]){
      return dp[i][j]=min(f(i+1,j,k+1,dp,a,b,c),1+f(i,j+1,k+1,dp,a,b,c));
    }
    if(b[j]==c[k]){
        return dp[i][j]=min(1+f(i+1,j,k+1,dp,a,b,c),f(i,j+1,k+1,dp,a,b,c));
    }
    return dp[i][j]= 1+min(f(i+1,j,k+1,dp,a,b,c),f(i,j+1,k+1,dp,a,b,c));
  }
  if(i<a.length()){
 if(a[i]==c[k]){
      return dp[i][j]=f(i+1,j,k+1,dp,a,b,c);
    }
    return dp[i][j]=1+f(i+1,j,k+1,dp,a,b,c);
  }
    if(b[j]==c[k]){
        return dp[i][j]=f(i,j+1,k+1,dp,a,b,c);
    }
    return dp[i][j]= 1+f(i,j+1,k+1,dp,a,b,c);

}
int main(){
    int t;
    cin>>t;
    while(t--){
      
       string a,b,c;
       cin>>a>>b>>c;
vector<vector<int>>dp(a.length()+1,vector<int>(b.length()+1,-1));

     cout<<  f(0,0,0,dp,a,b,c);

   cout<<endl;


     
    }
    return 0;
}

Answer: 1
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;
    }

    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;
}

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;
    }

    int left = INT_MAX, right = INT_MAX;

    if (ia < a.size())
    {
        if (arr[ia][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)
        {
            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: 1
Problem: 2050E - Three Strings
Language: c++20 

Code 1:
#include <bits/stdc++.h>
#define ll long long 
#define pi pair<ll,ll>
#define vi vector<ll> 
#define dd double
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define lcm(a, b) ((a) * (b)) / __gcd(a, b)
#define mp make_pair
#define in insert
#define fi first
#define lb lower_bound
#define ub upper_bound
#define se second
#define yes cout<<"YES"
#define no cout<<"NO"
#define rd(n) ll n; cin>>n;
#define all(v) (v).begin(),(v).end()
#define ra(a,n) vi a(n); f(i,0,n){cin>>a[i];}
const int mod = 1e9 + 7;
using namespace std;
#define int long long

const int inf = 1e9;

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size(), m = b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, inf));
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != c[i]);
    }
    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != c[j]);
    }
    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] ;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << endl;
    }
    return 0;
}


Code 2:
#include <bits/stdc++.h>
#define ll long long 
#define pi pair<ll,ll>
#define vi vector<ll> 
#define dd double
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define lcm(a, b) ((a) * (b)) / __gcd(a, b)
#define mp make_pair
#define in insert
#define fi first
#define lb lower_bound
#define ub upper_bound
#define se second
#define yes cout<<"YES"
#define no cout<<"NO"
#define rd(n) ll n; cin>>n;
#define all(v) (v).begin(),(v).end()
#define ra(a,n) vi a(n); f(i,0,n){cin>>a[i];}
const int mod = 1e9 + 7;
using namespace std;
#define int long long

int n, m;

int fun(string a, string b, string c, int i, int j, vector<vector<vector<int>>>& dp) {
    if (i >= n && j >= m) return 0;
    if (dp[i][j][i + j] != -1) return dp[i][j][i + j];
    int ans = 1e5;
    if (i < n) {
        if (a[i] != c[i + j]) {
            ans = min(ans, fun(a, b, c, i + 1, j, dp) + 1);
        } else {
            ans = min(ans, fun(a, b, c, i + 1, j, dp));
        }
    }
    if (j < m) {
        if (b[j] != c[i + j]) {
            ans = min(ans, fun(a, b, c, i, j + 1, dp) + 1);
        } else {
            ans = min(ans, fun(a, b, c, i, j + 1, dp));
        }
    }
    return dp[i][j][i + j] = ans;
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    n = a.size(), m = b.size();
    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>(n + m + 1, -1)));
    
    
    cout << fun(a, b, c, 0, 0, dp);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long t = 1;
    cin >> t;
    while (t--) {
        solve();
        cout << endl;
    }
    return 0;
}


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

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



using namespace std;



void Tarsh() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

#ifdef gamed

    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

#endif

}



typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

#define yes cout<<"YES\n";

#define no cout<<"NO\n";

#define fi first

#define se second

#define pb push_back

#define All(x) (x).begin(),(x).end()

#define Ones(n) __builtin_popcount(n)

int dx[] = {0, 0, -1, 1, -1, 1, -1, 1};

int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1};

const ll MOD = 1e9 + 7;

const ll N = 1e3 + 5;



string a, b, c;

int dp[N][N];



int slv(int i, int j) {

    if (i == a.size() && j == b.size())

        return 0;



    int &ret = dp[i][j];

    if (~ret)

        return ret;



    if (i == a.size()) {

        ret = slv(i, j + 1) + (b[j] != c[i + j]);

    }

    if (j == b.size()) {

        ret = slv(i + 1, j) + (a[i] != c[i + j]);

    } else {

        ret = min(slv(i, j + 1) + (b[j] != c[i + j]), slv(i + 1, j) + (a[i] != c[i + j]));

    }



    return ret;

}



void solve() {

    cin >> a >> b >> c;



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

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

            dp[i][j] = -1;

        }

    }



    cout << slv(0, 0) << '\n';

}





int main() {

    Tarsh();

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

}

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



using namespace std;



void Tarsh() {

    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);

#ifdef gamed

    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);

#endif

}



typedef long long ll;

typedef long double ld;

typedef unsigned long long ull;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;

#define yes cout<<"YES\n";

#define no cout<<"NO\n";

#define fi first

#define se second

#define pb push_back

#define All(x) (x).begin(),(x).end()

#define Ones(n) __builtin_popcount(n)

int dx[] = {0, 0, -1, 1, -1, 1, -1, 1};

int dy[] = {-1, 1, 0, 0, 1, 1, -1, -1};

const ll MOD = 1e9 + 7;

const ll N = 1e3 + 5;



string a, b, c;

int dp[N][N];



int slv(int i, int j) {

    if (i == a.size() && j == b.size())

        return 0;



    int &ret = dp[i][j];

    if (~ret)

        return ret;



    if (i == a.size()) {

        ret = slv(i, j + 1) + (b[j] != c[i + j]);

    }

    else if (j == b.size()) {

        ret = slv(i + 1, j) + (a[i] != c[i + j]);

    } else {

        ret = min(slv(i, j + 1) + (b[j] != c[i + j]), slv(i + 1, j) + (a[i] != c[i + j]));

    }



    return ret;

}



void solve() {

    cin >> a >> b >> c;



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

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

            dp[i][j] = -1;

        }

    }



    cout << slv(0, 0) << '\n';

}





int main() {

    Tarsh();

    int t = 1;

    cin >> t;

    while (t--) {

        solve();

    }

}

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

Code 1:
// qdd on Dec 08, 2024

#ifdef qdd
#include <ringo>
#else
#include <bits/stdc++.h>
#define dbg(...) 42
#endif

using namespace std;

using i64 = long long;

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  bool f = 0;
  for (const T& x : v) (f ? os << ' ' : os) << x, f = 1;
  return os;
}

void sol() {
  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, 0));
  for (int k = 1; k <= l; k++) {
    for (int i = 0; i <= min(n, k); i++) {
      int j = k - i;
      if (j < 0 || j > m) continue;
      dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1;
      if (i > 0 && a[i - 1] == c[k - 1]) dp[i][j] = min(dp[i][j], dp[i - 1][j]);
      if (j > 0 && b[j - 1] == c[k - 1]) dp[i][j] = min(dp[i][j], dp[i][j - 1]);
    }
  }
  cout << dp[n][m] << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    sol();
  }
  return 0;
}

Code 2:
// qdd on Dec 08, 2024

#ifdef qdd
#include <ringo>
#else
#include <bits/stdc++.h>
#define dbg(...) 42
#endif

using namespace std;

using i64 = long long;

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v) is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  bool f = 0;
  for (const T& x : v) (f ? os << ' ' : os) << x, f = 1;
  return os;
}

void sol() {
  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 k = 1; k <= l; k++) {
    for (int i = 0; i <= min(n, k); i++) {
      int j = k - i;
      if (j < 0 || j > m) continue;
      if (i > 0) {
        dp[i][j] = min(dp[i][j], dp[i - 1][j] + (a[i - 1] != c[k - 1]));
      }
      if (j > 0) {
        dp[i][j] = min(dp[i][j], dp[i][j - 1] + (b[j - 1] != c[k - 1]));
      }
    }
  }
  cout << dp[n][m] << '\n';
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    sol();
  }
  return 0;
}

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

Code 1:
import sys
input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))


def count_changes(a, b, c, i, j, k, memo_arr):
    if memo_arr[i][j] == -1:
        if k == len(c):
            memo_arr[i][j] = 0
        elif i == len(a):
            ans = 0
            for count in range(len(b[j:])):
                if b[j + count] != c[k+count]:
                    ans += 1
            memo_arr[i][j] = ans
        elif j == len(b):           
            ans = 0
            for count in range(len(a[i:])):
                if a[i + count] != c[k+count]:
                    ans += 1
            memo_arr[i][j] = ans
        else:
            case1 = count_changes(a, b, c, i+1, j, k+1, memo_arr)
            if a[i] != c[k]:
                case1 += 1
            case2 = count_changes(a, b, c, i, j+1, k+1, memo_arr)
            if b[j] != c[k]:
                case2 += 1
            memo_arr[i][j] = min(case1, case2)
    
    return memo_arr[i][j]


t = inp()
for _ in range(t):
    a = insr()
    b = insr()
    c = insr()

    i = 0
    j = 0

    k = 0
    memo_arr = [[-1 for _ in range(len(b)+1)] for _ in range(len(a) + 1)]
    print(count_changes(a, b, c, i, j, k, memo_arr))



Code 2:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))


def count_changes(a, b, c, i, j, k, memo_arr):
    if memo_arr[i][j] == -1:
        if k == len(c):
            memo_arr[i][j] = 0
        elif i == len(a):
            ans = 0
            for count in range(len(b[j:])):
                if b[j + count] != c[k+count]:
                    ans += 1
            memo_arr[i][j] = ans
        elif j == len(b):           
            ans = 0
            for count in range(len(a[i:])):
                if a[i + count] != c[k+count]:
                    ans += 1
            memo_arr[i][j] = ans
        else:
            case1 = count_changes(a, b, c, i+1, j, k+1, memo_arr)
            if a[i] != c[k]:
                case1 += 1
            case2 = count_changes(a, b, c, i, j+1, k+1, memo_arr)
            if b[j] != c[k]:
                case2 += 1
            memo_arr[i][j] = min(case1, case2)
    
    return memo_arr[i][j]


t = inp()
for _ in range(t):
    a = insr()
    b = insr()
    c = insr()

    i = 0
    j = 0

    k = 0
    memo_arr = [[-1 for _ in range(len(b)+1)] for _ in range(len(a) + 1)]
    print(count_changes(a, b, c, i, j, k, memo_arr))



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

Code 1:
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int helper(int index1,int index2,int index3,int n,int m,int k,string &a,string&b,string &c){
    if(index1==n&&index2==m){
        return 0;
    }
    int taken=INT_MAX;
    int taken2=INT_MAX;
    if(index1<n){
        if(a[index1]==c[index3]){
            taken=helper(index1+1,index2,index3+1,n,m,k,a,b,c);
        }
        else taken=1+helper(index1+1,index2,index3+1,n,m,k,a,b,c);
    }
    if(index2<m){
          if(b[index2]==c[index3]){
            taken2=helper(index1,index2+1,index3+1,n,m,k,a,b,c);
        }
        else taken2=1+helper(index1,index2+1,index3+1,n,m,k,a,b,c);
    }
    return min(taken,taken2);
}
 void solve(){
string a,b,c;
cin >> a >> b >> c;
int n=a.size();
int m=b.size();
int k=c.size();
int ans=helper(0,0,0,n,m,k,a,b,c);
cout << ans << endl;
 }
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Code 2:
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int helper(int index1,int index2,int index3,int n,int m,int k,string &a,string&b,string &c,unordered_map<string,int>&mp){
    if(index1==n&&index2==m){
        return 0;
    }
    int taken=INT_MAX;
    int taken2=INT_MAX;
    string temp=to_string(index1)+"*"+to_string(index2);
    if(mp.find(temp)!=mp.end()){
        return mp[temp];
    }
    if(index1<n){
        if(a[index1]==c[index3]){
            taken=helper(index1+1,index2,index3+1,n,m,k,a,b,c,mp);
        }
        else taken=1+helper(index1+1,index2,index3+1,n,m,k,a,b,c,mp);
    }
    if(index2<m){
          if(b[index2]==c[index3]){
            taken2=helper(index1,index2+1,index3+1,n,m,k,a,b,c,mp);
        }
        else taken2=1+helper(index1,index2+1,index3+1,n,m,k,a,b,c,mp);
    }
    return mp[temp]=min(taken,taken2);
}
 void solve(){
string a,b,c;
cin >> a >> b >> c;
int n=a.size();
int m=b.size();
int k=c.size();
unordered_map<string,int>mp;
int ans=helper(0,0,0,n,m,k,a,b,c,mp);
cout << ans << endl;
 }
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

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

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

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, INT_MAX));

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

    for(int i=1 ; i<=l ; i++){
        for(int j=i ; j<=i+m ; j++){
            
            int val = dp[i-1][j-1] + (a[i-1]!=c[j-1]?1:0);
            val = min(val, dp[i][j-1] + (b[j-i-1]!=c[j-1]?1:0));
            dp[i][j] = val;

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

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

void solve(){

    string a,b,c;
    cin>>a>>b>>c;

    int l = a.size(), m = b.size(), n = c.size();
    vector<vector<int>> dp(l+2, vector<int>(n+2, 99));

    dp[0][0] = 0;
    for(int i=0, j=0; i<n ; i++){
        if(j<m && b[j]==c[i])
            j++;
        dp[0][i+1] = i-j+1;
    }

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

        }
    }

    // for(int i=0;i<=l;i++){
    //     for(int j=0;j<=n;j++)cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<dp[l][n]<<'\n';
    
}

signed main(){
    int t;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Answer: 1