Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const ll mod = 1e9 + 7;

// Function declarations
ll nCr(ll n, ll r);
int string_to_int(const string& str);
ll string_to_ll(const string& str);
string int_to_string(int num);
string ll_to_string(ll num);

ll powermod(ll x, ll y, ll p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
ll mod_mult(ll a,ll b,ll m){return ((a%m)*(b%m))%m;}
ll mod_mul_inverse(ll a,ll b) {return powermod(a , b-2, b);}
ll mod_div(ll a,ll b,ll m){ return mod_mult(a,mod_mul_inverse(b,m),m);}



int ask(int l, int r) {
    cout << "? " << l << ' ' << r << endl;
    fflush(stdout);
    int ans;
    cin >> ans;
    return ans;
}





//***********************************************
// Function to perform binary search and return index
ll binarySearch_index(ll low, ll high, vector<ll> &a, ll element) {
    ll mid;
    while (low <= high) {
        mid = (low + high) / 2;
        if (a[mid] >= element)
            high = mid - 1;
        else
            low = mid + 1;
    }
    return max(mid, low);
}

//***********************************************
// Function to calculate GCD of two numbers
ll g_c_d(ll a, ll b) {
    if (b == 0)
        return a;
    return g_c_d(b, a % b);
}

//***********************************************
// Function to calculate LCM of two numbers
ll l_c_m(int a, int b) {
    return (a / g_c_d(a, b)) * b;
}

// Method to calculate xor
int computeXOR(int n){

   // If n is a multiple of 4
   if (n % 4 == 0) return n;

   // If n%4 gives remainder 1
   if (n % 4 == 1) return 1;

   // If n%4 gives remainder 2
   if (n % 4 == 2) return n + 1;

   // If n%4 gives remainder 3
   return 0;
}
//***********************************************
// Function to convert string to int
int string_to_int(const string& str) {
    int num = 0;
    bool is_negative = false;
    size_t i = 0;

    if (str[i] == '-') {
        is_negative = true;
        i++;
    } else if (str[i] == '+') {
        i++;
    }

    for (; i < str.length(); ++i) {
        num = num * 10 + (str[i] - '0');
    }

    return is_negative ? -num : num;
}

//***********************************************
// Function to convert string to ll
ll string_to_ll(const string& str) {
    ll num = 0;
    bool is_negative = false;
    size_t i = 0;

    if (str[i] == '-') {
        is_negative = true;
        i++;
    } else if (str[i] == '+') {
        i++;
    }

    for (; i < str.length(); ++i) {
        num = num * 10 + (str[i] - '0');
    }

    return is_negative ? -num : num;
}

//***********************************************
// Function to convert int to string
string int_to_string(int num) {
    bool is_negative = num < 0;
    if (is_negative) num = -num;
    string result;
    do {
        result.push_back((num % 10) + '0');
        num /= 10;
    } while (num > 0);
    if (is_negative) result.push_back('-');
    reverse(result.begin(), result.end());
    return result;
}

//***********************************************
// Function to convert ll to string
string ll_to_string(ll num) {
    bool is_negative = num < 0;
    if (is_negative) num = -num;
    string result;
    do {
        result.push_back((num % 10) + '0');
        num /= 10;
    } while (num > 0);
    if (is_negative) result.push_back('-');
    reverse(result.begin(), result.end());
    return result;
}

//***********************************************
// Solve function to handle test cases
void solve(){
    string a,b,c;cin>>a>>b>>c;
    ll n1=a.length();
    ll n2=b.length();
    ll n3=c.length();

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

    ll dp[n1+1][n2+1];
    for(ll i=0;i<=n1;i++){for(ll j=0;j<=n2;j++)dp[i][j]=0;}

    for(ll i=1;i<=n1;i++){
        dp[i][0]=dp[i-1][0];
        if(a[i]==c[i]) dp[i][0]++;
    }

    for(ll i=1;i<=n2;i++){
        dp[0][i]=dp[0][i-1];
        if(b[i]==c[i])dp[0][i];
    }

    for(ll i=1;i<=n1;i++){
        for(ll j=1;j<=n2;j++){

            if(a[i]==c[i+j]) dp[i][j]=1+dp[i-1][j]; 
            if(b[j]==c[i+j]) dp[i][j]=max(dp[i][j],1+dp[i][j-1]);
            else dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
        }        
    }

    ll ans=n3-dp[n1][n2];
    cout<<ans<<endl;

    // pair<ll,ll> dp[n1+1][n2+1];
    // for(ll i=0;i<=n1;i++){for(ll j=0;j<=n2;j++)dp[i][j].first=dp[i][j].second=0;}

    // for(ll i=1;i<=n1;i++){
    //     dp[i][0].first=dp[i-1][0].first;
    //     if(a[i]==c[i]) dp[i][0].first++;
    // }
    // for(ll i=1;i<=n2;i++){
    //     dp[0][i].second=dp[0][i-1].second;
    //     if(b[i]==c[i]) dp[0][i].second++;
    // }

    // for(ll i=1;i<=n1;i++){
    //     for(ll j=1;j<=n2;j++){
    //         dp[i][j].first=max(dp[i-1][j].first,dp[i-1][j].second);
    //         dp[i][j].second=max(dp[i-1][j].first,dp[i-1][j].second);

    //         if(a[i]==c[i+j]) dp[i][j].first++;
    //         if(b[j]==c[i+j]) dp[i][j].second++;
    //     }
    // }

    // for(ll i=1;i<=n1;i++){
    //     for(ll j=1;j<=n2;j++) cout<<dp[i][j].first<<dp[i][j].second<<" ";cout<<endl;
    // }

    // ll ans=n3-max(dp[n1][n2].first,dp[n1][n2].second);
    // cout<<ans<<endl;
}

//***********************************************
// Main function
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll t;
    cin >> t;

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

    return 0;
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const ll mod = 1e9 + 7;

// Function declarations
ll nCr(ll n, ll r);
int string_to_int(const string& str);
ll string_to_ll(const string& str);
string int_to_string(int num);
string ll_to_string(ll num);

ll powermod(ll x, ll y, ll p){ll res = 1;x = x % p;if (x == 0) return 0;while (y > 0){if (y & 1)res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
ll mod_mult(ll a,ll b,ll m){return ((a%m)*(b%m))%m;}
ll mod_mul_inverse(ll a,ll b) {return powermod(a , b-2, b);}
ll mod_div(ll a,ll b,ll m){ return mod_mult(a,mod_mul_inverse(b,m),m);}



int ask(int l, int r) {
    cout << "? " << l << ' ' << r << endl;
    fflush(stdout);
    int ans;
    cin >> ans;
    return ans;
}





//***********************************************
// Function to perform binary search and return index
ll binarySearch_index(ll low, ll high, vector<ll> &a, ll element) {
    ll mid;
    while (low <= high) {
        mid = (low + high) / 2;
        if (a[mid] >= element)
            high = mid - 1;
        else
            low = mid + 1;
    }
    return max(mid, low);
}

//***********************************************
// Function to calculate GCD of two numbers
ll g_c_d(ll a, ll b) {
    if (b == 0)
        return a;
    return g_c_d(b, a % b);
}

//***********************************************
// Function to calculate LCM of two numbers
ll l_c_m(int a, int b) {
    return (a / g_c_d(a, b)) * b;
}

// Method to calculate xor
int computeXOR(int n){

   // If n is a multiple of 4
   if (n % 4 == 0) return n;

   // If n%4 gives remainder 1
   if (n % 4 == 1) return 1;

   // If n%4 gives remainder 2
   if (n % 4 == 2) return n + 1;

   // If n%4 gives remainder 3
   return 0;
}
//***********************************************
// Function to convert string to int
int string_to_int(const string& str) {
    int num = 0;
    bool is_negative = false;
    size_t i = 0;

    if (str[i] == '-') {
        is_negative = true;
        i++;
    } else if (str[i] == '+') {
        i++;
    }

    for (; i < str.length(); ++i) {
        num = num * 10 + (str[i] - '0');
    }

    return is_negative ? -num : num;
}

//***********************************************
// Function to convert string to ll
ll string_to_ll(const string& str) {
    ll num = 0;
    bool is_negative = false;
    size_t i = 0;

    if (str[i] == '-') {
        is_negative = true;
        i++;
    } else if (str[i] == '+') {
        i++;
    }

    for (; i < str.length(); ++i) {
        num = num * 10 + (str[i] - '0');
    }

    return is_negative ? -num : num;
}

//***********************************************
// Function to convert int to string
string int_to_string(int num) {
    bool is_negative = num < 0;
    if (is_negative) num = -num;
    string result;
    do {
        result.push_back((num % 10) + '0');
        num /= 10;
    } while (num > 0);
    if (is_negative) result.push_back('-');
    reverse(result.begin(), result.end());
    return result;
}

//***********************************************
// Function to convert ll to string
string ll_to_string(ll num) {
    bool is_negative = num < 0;
    if (is_negative) num = -num;
    string result;
    do {
        result.push_back((num % 10) + '0');
        num /= 10;
    } while (num > 0);
    if (is_negative) result.push_back('-');
    reverse(result.begin(), result.end());
    return result;
}

//***********************************************
// Solve function to handle test cases
void solve(){
    string a,b,c;cin>>a>>b>>c;
    ll n1=a.length();
    ll n2=b.length();
    ll n3=c.length();

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

    ll dp[n1+1][n2+1];
    for(ll i=0;i<=n1;i++){for(ll j=0;j<=n2;j++)dp[i][j]=0;}

    for(ll i=1;i<=n1;i++){
        dp[i][0]=dp[i-1][0];
        if(a[i]==c[i]) dp[i][0]++;
    }

    for(ll i=1;i<=n2;i++){
        dp[0][i]=dp[0][i-1];
        if(b[i]==c[i])dp[0][i]++;
    }

    for(ll i=1;i<=n1;i++){
        for(ll j=1;j<=n2;j++){

            if(a[i]==c[i+j]) dp[i][j]=1+dp[i-1][j]; 
            if(b[j]==c[i+j]) dp[i][j]=max(dp[i][j],1+dp[i][j-1]);
            else dp[i][j]=max(dp[i][j],max(dp[i-1][j],dp[i][j-1]));
        }        
    }

    ll ans=n3-dp[n1][n2];
    cout<<ans<<endl;

    // pair<ll,ll> dp[n1+1][n2+1];
    // for(ll i=0;i<=n1;i++){for(ll j=0;j<=n2;j++)dp[i][j].first=dp[i][j].second=0;}

    // for(ll i=1;i<=n1;i++){
    //     dp[i][0].first=dp[i-1][0].first;
    //     if(a[i]==c[i]) dp[i][0].first++;
    // }
    // for(ll i=1;i<=n2;i++){
    //     dp[0][i].second=dp[0][i-1].second;
    //     if(b[i]==c[i]) dp[0][i].second++;
    // }

    // for(ll i=1;i<=n1;i++){
    //     for(ll j=1;j<=n2;j++){
    //         dp[i][j].first=max(dp[i-1][j].first,dp[i-1][j].second);
    //         dp[i][j].second=max(dp[i-1][j].first,dp[i-1][j].second);

    //         if(a[i]==c[i+j]) dp[i][j].first++;
    //         if(b[j]==c[i+j]) dp[i][j].second++;
    //     }
    // }

    // for(ll i=1;i<=n1;i++){
    //     for(ll j=1;j<=n2;j++) cout<<dp[i][j].first<<dp[i][j].second<<" ";cout<<endl;
    // }

    // ll ans=n3-max(dp[n1][n2].first,dp[n1][n2].second);
    // cout<<ans<<endl;
}

//***********************************************
// Main function
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll t;
    cin >> t;

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

    return 0;
}