ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: python

Code 1:
def min_changes_needed(t, test_cases):
    results = []
    
    for a, b, c in test_cases:
        n, m = len(a), len(b)
        dp = [[0] * (m + 1) for _ in range(n + 1)]
        
        for i in range(n + 1):
            for j in range(m + 1):
                c_index = i + j - 1
                if i == 0 and j == 0:
                    continue
                if c_index >= len(c):
                    continue
                if i > 0 and a[i - 1] == c[c_index]:
                    dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1)
                if j > 0 and b[j - 1] == c[c_index]:
                    dp[i][j] = max(dp[i][j], dp[i][j - 1] + 1)
        max_matched = dp[n][m]
        changes_needed = (n + m) - max_matched
        results.append(changes_needed)
    return results
t = 7 
test_cases = [
    ("a", "b", "cb"),
    ("ab", "cd", "acbd"),
    ("ab", "ba", "aabb"),
    ("xxx", "yyy", "xyxyxy"),
    ("a", "bcd", "decf"),
    ("codes", "horse", "codeforces"),
    ("egg", "annie", "egaegaeg")
]
outputs = min_changes_needed(t, test_cases)
for output in outputs:
    print(output)

Code 2:
def min_changes(a, b, c):
    n, m = len(a), len(b)
    dp = [[float('inf')] * (m + 1) for _ in range(n + 1)]
    dp[0][0] = 0

    for i in range(n + 1):
        for j in range(m + 1):
            if i > 0:
                dp[i][j] = min(dp[i][j], dp[i-1][j] + (a[i-1] != c[i + j - 1]))
            if j > 0:
                dp[i][j] = min(dp[i][j], dp[i][j-1] + (b[j-1] != c[i + j - 1]))
    
    return dp[n][m]

t = int(input())
for _ in range(t):
    a = input().strip()
    b = input().strip()
    c = input().strip()
    print(min_changes(a, b, c))


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

Code 1:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string a,b,c;
vector<vector<int>> dp;
int fnc(int i, int j)
{
  if(i>=a.length() && j >= b.length())
  {
    return 0;
  }
  if(dp[i][j] != -1)
  {
    return dp[i][j];
  }
  int x1 = 1e9;
  int x2 = 1e9;
  if(i < a.length())
  {
  x1 = fnc(i+1,j) + (a[i] != c[i+j]);
  }
  if(j < b.length())
  {
  x2 = fnc(i,j+1) + (b[j] != c[i+j]);
  }
  return dp[i][j] =  min(x1,x2);
}
void solve()
{
  cin >> a >> b >> c;
vector<vector<int>> ddp(a.length()+1,vector<int> (b.length()+1,-1));
dp = ddp;
  cout << fnc(0,0) << endl;
}
int32_t main(){
    int tt;
   cin >> tt;
   while(tt>0){
   solve();
   --tt;
   }


  //solve();
}

Code 2:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string a,b,c;
vector<vector<int>> dp(1e3+1,vector<int> (1e3+1,-1));
int fnc(int i, int j)
{
  if(i>=a.length() && j >= b.length())
  {
    return 0;
  }
  if(dp[i][j] != -1)
  {
    return dp[i][j];
  }
  int x1 = 1e9;
  int x2 = 1e9;
  if(i < a.length())
  {
  x1 = fnc(i+1,j) + (a[i] != c[i+j]);
  }
  if(j < b.length())
  {
  x2 = fnc(i,j+1) + (b[j] != c[i+j]);
  }
  return dp[i][j] =  min(x1,x2);
}
void solve()
{
  cin >> a >> b >> c;
vector<vector<int>> ddp(1e3+1,vector<int> (1e3+1,-1));
dp = ddp;
  cout << fnc(0,0) << endl;
}
int32_t main(){
    int tt;
   cin >> tt;
   while(tt>0){
   solve();
   --tt;
   }


  //solve();
}

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

Code 1:
/* Coding the path to follow.... */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define gcd(m, n) __gcd(m,n)
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)

int f(int i, int j, int &m, int &n, string& a, string& b, string& c, vector<vector<int>>& dp){
    if(i == m && j == n) return 0;

    if(dp[i][j] != -1) return dp[i][j];

    int minChanges = 1e9;
    int k = i+j;
    if(i < m){
        if(a[i] == c[k]) minChanges = min(minChanges, f(i+1, j, m, n, a, b, c, dp));
        else minChanges = min(minChanges, 1 + f(i+1, j, m, n, a, b, c, dp));
    }
    if(j < n){
        if(b[j] == c[k]) minChanges = min(minChanges, f(i, j+1, m, n, a, b, c, dp));
        else minChanges = min(minChanges, 1 + f(i, j+1, m, n, a, b, c, dp));
    }

    return dp[i][j] = minChanges;
}

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

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

    // vector<vector<vector<int>>> dp(m+1, vector<vector<int>>(n+1, vector<int>(s+1, -1)));
    vector<vector<int>> dp(m+1, vector<int>(n+1, -1));

    cout << f(0, 0, m, n, a, b, c, dp) << endl;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    ll test=1;
    cin>>test;
    while(test--)
    {
        solve();
    }
    return 0;
}


Code 2:
/* Coding the path to follow.... */
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define gcd(m, n) __gcd(m,n)
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)

int f(int i, int j, int k, int &m, int &n, string& a, string& b, string& c, vector<vector<vector<int>>>& dp){
    if(i == m && j == n) return 0;

    if(dp[i][j][k] != -1) return dp[i][j][k];

    int minChanges = 1e9;
    if(i < m){
        if(a[i] == c[k]) minChanges = min(minChanges, f(i+1, j, k+1, m, n, a, b, c, dp));
        else minChanges = min(minChanges, 1 + f(i+1, j, k+1, m, n, a, b, c, dp));
    }
    if(j < n){
        if(b[j] == c[k]) minChanges = min(minChanges, f(i, j+1, k+1, m, n, a, b, c, dp));
        else minChanges = min(minChanges, 1 + f(i, j+1, k+1, m, n, a, b, c, dp));
    }

    return dp[i][j][k] = minChanges;
}

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

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

    vector<vector<vector<int>>> dp(m+1, vector<vector<int>>(n+1, vector<int>(s+1, -1)));

    cout << f(0, 0, 0, m, n, a, b, c, dp) << endl;
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    ll test=1;
    cin>>test;
    while(test--)
    {
        solve();
    }
    return 0;
}


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

Code 1:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int minChanges(const string& a, const string& b, const string& c) {
    int n = a.size();
    int m = b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

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

    return dp[n][m];
}

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

Code 2:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int minChanges(const string& a, const string& b, const string& c) {
    int n = a.size();
    int m = b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            int k = i + j;
            if (k == c.size()) break;

            if (i < n) {
                dp[i + 1][j] = dp[i][j] + (a[i] != c[k] ? 1 : 0);
            }

            if (j < m) {
                dp[i][j + 1] = dp[i][j] + (b[j] != c[k] ? 1 : 0);
            }
        }
    }

    return dp[n][m];
}

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

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

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

int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector<vector<int>> &dp) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    return dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    vector<vector<int>> dp(a.size() + 1, vector<int> (b.size() + 1, -1));
    cout << minChange(0, 0, a, b, c, dp) << endl;
  }
}

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

int minChange(int aIndex, int bIndex, string &a, string &b, string &c, vector<vector<int>> &dp) {
  if(aIndex + bIndex >= c.size())
    return 0;

  if(dp[aIndex][bIndex] != -1)
    dp[aIndex][bIndex];

  int cIndex = aIndex + bIndex;
  int mn = c.size() - cIndex + 1;
  if(aIndex < a.size()) {
    if(a[aIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp));
    mn = min(mn, minChange(aIndex + 1, bIndex, a, b, c, dp) + 1);
  }
  if(bIndex < b.size()) {
    if(b[bIndex] == c[cIndex])
      mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp));
    mn = min(mn, minChange(aIndex, bIndex + 1, a, b, c, dp) + 1);
  }
  return dp[aIndex][bIndex] = mn;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  int t;
  cin >> t;
  while(t--) {
    string a, b, c;
    cin >> a >> b >> c;

    vector<vector<int>> dp(a.size() + 1, vector<int> (b.size() + 1, -1));
    cout << minChange(0, 0, a, b, c, dp) << endl;
  }
}

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

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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pii>
#define F first
#define S second
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7;
const int INF = 1e9;

int solve(string &a,string &b,string &c,int i,int j,vector<vi> &dp){

    // if(k>=c.size()){
    //     return 0;
    // }

    int k = i+j;

    if (i == a.size() && j == b.size())
        return 0;

    if(dp[i][j]!=-1){
        return dp[i][j];
    }

    int left = INT_MAX;
    int right = INT_MAX;

    if(i<a.size() && a[i]==c[k]){
        left = solve(a,b,c,i+1,j,dp);
    }
    else if(i<a.size() && a[i]!=c[k]) {
        left = 1+solve(a,b,c,i+1,j,dp);
    }

    if(j<b.size() && b[j]==c[k]){
        right = solve(a,b,c,i,j+1,dp);
    }
    else if(j<b.size() && b[j]!=c[k]){
        right = 1+solve(a,b,c,i,j+1,dp);
    }

    return dp[i][j] = min(left,right);

}

void solve() {

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

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

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

int main() {
    fast_io;

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pii>
#define F first
#define S second
#define fast_io ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7;
const int INF = 1e9;

int solve(string a,string b,string c,int i,int j,int k,vector<vector<vi>> &dp){

    if(k>=c.size()){
        return 0;
    }

    if(dp[i][j][k]!=-1){
        return dp[i][j][k];
    }

    int left = INT_MAX;
    int right = INT_MAX;

    if(i<a.size() && a[i]==c[k]){
        left = solve(a,b,c,i+1,j,k+1,dp);
    }
    else if(i<a.size() && a[i]!=c[k]) {
        left = 1+solve(a,b,c,i+1,j,k+1,dp);
    }

    if(j<b.size() && b[j]==c[k]){
        right = solve(a,b,c,i,j+1,k+1,dp);
    }
    else if(j<b.size() && b[j]!=c[k]){
        right = 1+solve(a,b,c,i,j+1,k+1,dp);
    }

    return dp[i][j][k] = min(left,right);

}

void solve() {

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

    vector<vector<vi>> dp(a.size()+1,vector<vi> (b.size()+1,vector<int> (c.size()+1,-1)));

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

int main() {
    fast_io;

    int t;
    cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}

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

Code 1:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef tuple<ll,ll,ll> tii;
const int mod = 1e9+7;
const int maxn = 1005;
const ll inf = 0x3f3f3f3f3f3f3f3f;

int dp[maxn][maxn];


void solve(){
    string a, b, c; cin >> a >> b >> c;
    int n = a.size(), m = b.size();
    for(int i = n; ~i; i--){
        for(int j = m; ~j; j--){
            if(i == n and j == m) dp[i][j] = 0;
            else if (i == n) dp[i][j] = dp[i][j+1]+(c[i+j]!=b[j]);
            else if (j == m) dp[i][j] = dp[i][j+1]+(c[i+j]!=a[i]);
            else dp[i][j] = min(dp[i+1][j]+(c[i+j]!=a[i]),dp[i][j+1]+(c[i+j]!=b[j]));
        }
    }
    cout << dp[0][0] << endl;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t; cin >> t;
    while(t--)
        solve();
    return 0;
}

// "Pensa simples, joga leve, coda fofo."

Code 2:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef tuple<ll,ll,ll> tii;
const int mod = 1e9+7;
const int maxn = 1005;
const ll inf = 0x3f3f3f3f3f3f3f3f;

int dp[maxn][maxn];

void solve(){
    string a, b, c; cin >> a >> b >> c;
    int n = a.size(), m = b.size();
    for(int i = n; ~i; i--){
        for(int j = m; ~j; j--){
            if(i == n and j == m) dp[i][j] = 0;
            else if (i == n) dp[i][j] = dp[i][j+1]+(c[i+j]!=b[j]);
            else if (j == m) dp[i][j] = dp[i+1][j]+(c[i+j]!=a[i]);
            else dp[i][j] = min(dp[i+1][j]+(c[i+j]!=a[i]),dp[i][j+1]+(c[i+j]!=b[j]));
        }
    }
    cout << dp[0][0] << endl;
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t; cin >> t;
    while(t--)
        solve();
    return 0;
}

// "Pensa simples, joga leve, coda fofo."

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

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

#define int long long
#define inf 1e9

signed main() {
    int t;
    cin >> t;
    while(t--) {
        string a, b, c;
        cin >> a >> b >> c;
        int lenA = a.size(), lenB = b.size();
        vector<vector<int>> dp(lenA + 1, vector<int>(lenB + 1, inf));
        dp[0][0] = 0;
        for (int i = 0; i <= lenA; ++i) {
            for (int j = 0; j <= lenB; ++j) {
                if (i < lenA) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (a[i] != c[i + j]));
                if (j < lenB) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + (b[j] != c[i + j]));
            }
        }
        cout << dp[lenA][lenB] << endl;
    }
    return 0;
}

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

#define int long long

signed main(){
    int t;
    cin >> t;
    while(t--) {
        vector<int> fq(26, 0);
        string a, b, c;
        cin >> a >> b >> c;
        for(const auto& it : a) fq[it - 'a']++;
        for(const auto& it : b) fq[it - 'a']++;
        for(const auto& it : c) fq[it - 'a']--;
        int sum = 0;
        for(const auto& it : fq) sum += max(it, 0LL);
        cout << sum << endl;
    }
    return 0;
}

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

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



using namespace std;



#define ll long long

#define ld long double

#define mp make_pair

#define F first 

#define S second

#define pb push_back

#define upb upper_bound

#define lwb lower_bound



const int maxn = (1 << 10);

int n, m, dp[maxn][maxn];

string a, b, c;



void clear_array() {

    for (int i = 0; i < 3 + n; i++) {

        fill(dp[i], dp[i] + 3 + m, 0);

    }

    a.clear(), b.clear(), c.clear();

    n = m = 0;

}



void solve() {

    cin >> a >> b >> c;

    n = (int)(a.size());

    m = (int)(b.size());

    a = "#" + a; b = "#" + b; c = "#" + c;

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

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

            dp[i][j] = n + n + m + m;

        }

    }

    dp[0][0] = 0;

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

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

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

    }

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

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

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

    }

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

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

            int from_a = (a[i] == c[i + j] ? dp[i - 1][j] : dp[i - 1][j] + 1);

            int from_b = (b[j] == c[i + j] ? dp[i][j - 1] : dp[i][j - 1] + 1);

            dp[i][j] = min(from_a, from_b);

        }

    }

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

    clear_array();

}



void boost() {

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

    ios_base :: sync_with_stdio(false);

}



int main() {

    boost();

    int TT;

    cin >> TT;

    while (TT--) {

        solve();

    }

    return 0;

}

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

using namespace std;

vector<vector<int>>dp;

int fxn(string a,string b,string c,int i,int j)

{

    int n=c.length();

    

    if(i+j==n)return 0;

    //if(i==a.length()||j==b.length())return 1e9;

    if(dp[i][j]!=-1)return dp[i][j];

    int a1=1e9,b1=1e9;

    if(i<a.length()&&a[i]==c[i+j])

    {

        a1=fxn(a,b,c,i+1,j);

    }

    else if(i<a.length())

    {

         a1=1+fxn(a,b,c,i+1,j);

    }

     if(j<b.length()&&b[j]==c[i+j])

    {

        b1=fxn(a,b,c,i,j+1);

    }

    else if(j<b.length())

    {

         b1=1+fxn(a,b,c,i,j+1);

    }

    return dp[i][j]=min(a1,b1);

}

int main() {

    int t;

    cin>>t;

      

    while(t--){

         string a,b,c;

         cin>>a>>b>>c;

         //memset(dp,-1,sizeof(dp));

         dp=vector<vector<int>>(a.length()+1,vector<int>(b.length(),-1));

         int z=fxn(a,b,c,0,0);

         

         cout<<z<<endl;

         

  

    }

    return 0;

}

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

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



using namespace std;



#define forn(i, n) for (int i = 0; i < int(n); i++)

#define ll long long

#define pii pair<ll, ll>

ll INF = 10000000000000000; 

ll MOD = 1000000007; 

const int N = 1 << 17; 

const int inf = 100000000;



string a, b, c;

int as, bs, cs; 

int dp[1002][1002];



int solve(int charc, int chara) {

    if(chara < 0 or chara > charc) return inf;  

    if(charc == 0) return 0; 





    if(dp[charc][chara] != -1) return dp[charc][chara];

    int ans = 0; 

    int charb = charc - chara; 

    int x, y; 







    if(a[chara - 1] == c[charc - 1])

        x = solve(charc - 1, chara - 1);

    else

        x = 1 + solve(charc - 1, chara - 1);

    



    if(b[charb - 1] == c[charc - 1]) 

        y = solve(charc - 1, chara);

    else 

        y = 1 + solve(charc - 1, chara);



    

    ans = min(x, y);



    return dp[charc][chara] = ans;

}









void solve() {

    int i, j; 

    cin >> a >> b >> c; 

    as = a.size(), bs = b.size(), cs = c.size(); 



    for(i = 0; i <= cs; i++) for(j = 0; j <= as; j++) dp[i][j] = -1; 



    cout << solve(cs, as) << endl;   

}





































 



int main() {

    #ifdef LOCAL

        freopen("input.txt", "r", stdin);

    #endif

    std::ios::sync_with_stdio(false);

    // doo(); return 0; 

    

    ll t = 1; 

    cin >> t;

    while (t--) {

        solve();

    }

}





/*



1  1   0 

2  4   2

3  9   6



*/

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



using namespace std;



#define forn(i, n) for (int i = 0; i < int(n); i++)

#define ll long long

#define pii pair<ll, ll>

ll INF = 10000000000000000; 

ll MOD = 1000000007; 

const int N = 1 << 17; 

const int inf = 100000000;



string a, b, c;

int as, bs, cs; 

int dp[2002][2002];



int solve(int charc, int chara) {

    if(chara < 0 or chara > charc) return inf;  

    if(charc == 0) return 0; 





    if(dp[charc][chara] != -1) return dp[charc][chara];

    int ans = 0; 

    int charb = charc - chara; 

    int x, y; 







    if(a[chara - 1] == c[charc - 1])

        x = solve(charc - 1, chara - 1);

    else

        x = 1 + solve(charc - 1, chara - 1);

    



    if(b[charb - 1] == c[charc - 1]) 

        y = solve(charc - 1, chara);

    else 

        y = 1 + solve(charc - 1, chara);



    

    ans = min(x, y);



    return dp[charc][chara] = ans;

}









void solve() {

    int i, j; 

    cin >> a >> b >> c; 

    as = a.size(), bs = b.size(), cs = c.size(); 



    for(i = 0; i <= cs; i++) for(j = 0; j <= as; j++) dp[i][j] = -1; 



    cout << solve(cs, as) << endl;   

}





































 



int main() {

    #ifdef LOCAL

        freopen("input.txt", "r", stdin);

    #endif

    std::ios::sync_with_stdio(false);

    // doo(); return 0; 

    

    ll t = 1; 

    cin >> t;

    while (t--) {

        solve();

    }

}





/*



1  1   0 

2  4   2

3  9   6



*/

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[2005];
    char* b = new char[2005];
    char* c = new char[2005];
    cin.getline(a, 2000, '\n');
    cin.getline(b, 2000, '\n');
    cin.getline(c, 2000, '\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