Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>
#include <chrono> 
using namespace std;
using namespace chrono; 
#define TxtIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define int long long
#define Varun ios_base::sync_with_stdio(false); cin.tie(NULL);
const int M = 1e9+7;
// functions
int ceil_div(int a,int b){return a%b==0?(a/b):(a/b)+1;}
int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(int a, int b, int *v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return;} extendgcd(b, a % b, v); int x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an array of size 3
int mminv(int a, int b) {int arr[3]; extendgcd(a, b, arr); return arr[0];} 
int mminvprime(int a, int b) {return expo(a, b - 2, b);}
bool revsort(int a, int b) {return a > b;}
int combination(int n, int r, int m, int *fact, int *ifact) {int val1 = fact[n]; int val2 = ifact[n - r]; int val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
vector<int> sieve(int n) {int *arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++) if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i) arr[j] = 1;} return vect;}
int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m
int phin(int n) {int number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (int i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0) n /= i; number = (number / i * (i - 1));}} if (n > 1) number = (number / n * (n - 1)); return number;} //O(sqrt(N))
 
void solve(){
    string s, t, c;
    cin >> s>>t>>c;
    int n = s.size();
    int m = t.size();
    vector<string>v;
    function<void(int, int, string)>f = [&](int i, int j, string x){
        if(i == n){
            x += t.substr(j);
            v.push_back(x);
            return;
        }
        if(j == m){
            x += s.substr(i);
            v.push_back(x);
            return;
        }
        f(i, j+1, x+t[j]);
        f(i+1, j, x+s[i]);
    };
    
    f(0, 0, "");
    int ans = LLONG_MAX;
    for(int i = 0; i < v.size(); ++i){
        string x = v[i];
        int cnt = 0;
        for(int j = 0; j < n+m; ++j){
            if(x[j] != c[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans  << "\n";
    




    
}

signed main(){
    Varun
    // TxtIO

    int t = 1; 
    cin >> t;
    auto start = high_resolution_clock::now(); 
    while(t--){
        solve();
    }
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start); 
    
    // cerr << "Time: " << duration.count() << " ms" << endl;

    return 0;
}

Submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>
#include <chrono> 
using namespace std;
using namespace chrono; 
#define TxtIO freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define int long long
#define Varun ios_base::sync_with_stdio(false); cin.tie(NULL);
const int M = 1e9+7;
// functions
int ceil_div(int a,int b){return a%b==0?(a/b):(a/b)+1;}
int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
int expo(int a, int b, int mod) {int res = 1; while (b > 0) {if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
void extendgcd(int a, int b, int *v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return;} extendgcd(b, a % b, v); int x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an array of size 3
int mminv(int a, int b) {int arr[3]; extendgcd(a, b, arr); return arr[0];} 
int mminvprime(int a, int b) {return expo(a, b - 2, b);}
bool revsort(int a, int b) {return a > b;}
int combination(int n, int r, int m, int *fact, int *ifact) {int val1 = fact[n]; int val2 = ifact[n - r]; int val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m;}
void google(int t) {cout << "Case #" << t << ": ";}
vector<int> sieve(int n) {int *arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++) if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i) arr[j] = 1;} return vect;}
int mod_add(int a, int b, int m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
int mod_mul(int a, int b, int m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
int mod_sub(int a, int b, int m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
int mod_div(int a, int b, int m) {a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m;} //only for prime m
int phin(int n) {int number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (int i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0) n /= i; number = (number / i * (i - 1));}} if (n > 1) number = (number / n * (n - 1)); return number;} //O(sqrt(N))
 
void solve(){
    string s, t, c;
    cin >> s>>t>>c;
    int n = s.size();
    int m = t.size();
    vector<string>v;
    int ans = LLONG_MAX;
    function<void(int, int, string)>f = [&](int i, int j, string x){
        if(i == n){
            x += t.substr(j);
            int cnt = 0;
            for(int j = 0; j < n+m; ++j){
                if(x[j] != c[j]) cnt++;
            }
            ans = min(ans, cnt);
            return;
        }
        if(j == m){
            x += s.substr(i);
            int cnt = 0;
            for(int j = 0; j < n+m; ++j){
                if(x[j] != c[j]) cnt++;
            }
            ans = min(ans, cnt);
            return;
        }
        f(i, j+1, x+t[j]);
        f(i+1, j, x+s[i]);
    };
    
    f(0, 0, "");
    cout << ans  << "\n";
    




    
}

signed main(){
    Varun
    // TxtIO

    int t = 1; 
    cin >> t;
    auto start = high_resolution_clock::now(); 
    while(t--){
        solve();
    }
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start); 
    
    // cerr << "Time: " << duration.count() << " ms" << endl;

    return 0;
}