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

Solution 1 (runtime: 108 ms):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define nl "\n"
#define py cout << "YES" << nl;
#define pn cout << "NO" << nl;
#define PI 3.141592653589793238
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define ff first
#define ss second
#define fastio()                    \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
ll MOD = 1e9 + 7;
ll MOD1 = 998244353;
#ifndef ONLINE_JUDGE
#define debug(x) cerr << x << nl;
#else
#define debug(x)
#endif
void printarr(vector<ll> &arr)
{
  for (auto i : arr)
    cout << i << " ";
  cout << nl;
}
ll power(ll n, ll p)
{
  if (p == 0)
    return 1;
  if (p == 1)
    return n;
  if (p % 2 == 0)
  {
    ll smallans = power(n, p / 2);
    return (smallans * smallans);
  }
  else
  {
    ll smallans = power(n, p / 2);
    return ((smallans * smallans) * n);
  }
}
// (a^b)%m here m=modulo
//(a#b)%m=((a%m)#(b%m))%m  #-> (+ or *)
// (a-b)%m=((a%m)-(b%m)+m)%m
//(a/b)%m=((a%m)*(inverse(b,m)))%m

/*
    // 1 2 4 5 5 5 7 8 25
   // lower_bound(5)= index 3 if the ele present then first occurance
   // lower_bound(6)= index 6 if not present then the value greater than that present on the array
   // upper_bound(5)= index 6 the value which is greater than the element present on the array
   // upper_bound(6)=index 6
  //  it1=lower_bound(v.begin(),v.end(),7);
   // it2=upper_bound(v.begin(),v.end(),7);
   // cout<<(it1-v.begin())<<endl;
   // cout<<(it2-v.begin())<<endl;
*/

ll powermod(ll a, ll b, ll m)
{
  ll res = 1;
  while (b > 0)
  {
    if (b & 1)
    {
      res = (res * a) % m;
    }
    a = (a * a) % m;
    b >>= 1;
  }

  return res;
}

// (1/a)%m
ll inverse(ll a, ll MOD)
{
  return powermod(a, MOD - 2, MOD);
}

ll GCD(ll a, ll b)
{
  if (a == 0)
  {
    return b;
  }
  return GCD(b % a, a);
}
// calculate how many set bit in n
int cal_setbit(int n)
{
  int c = 0, x;
  while (n > 0)
  {
    x = n & (-n); // This calculate the  right most set bit
    c++;
    n = n - x;
  }
  return c;
}
ll nCr(ll n, ll r, ll m)
{
  if (n < r)
    return 0;
  if (r == 0)
    return 1;
  vector<ll> fact(n + 1, 0);
  fact[0] = 1;
  for (ll i = 1; i <= n; i++)
    fact[i] = (fact[i - 1] * i) % m;
  return ((((fact[n] % m) * inverse(fact[r], m)) % m) * inverse(fact[n - r], m)) % m;
}

vector<ll> sieve()
{
  ll n = 1e6 + 1;
  vector<ll> arr(n, 1);
  for (ll i = 2; i <= n; i++)
  {
    if (arr[i] == 1)
    {
      for (ll j = i * i; j <= n; j += i)
      {
        arr[j] = 0;
      }
    }
  }
  arr[1] = 0;

  return arr;
}

ll  find(ll x,ll y,string &a,string &b,string &c, vector<vector<ll>>&dp)
{
    if(dp[x][y]!=-1)
    return dp[x][y];
    if(x==0)
    {
        ll ans=0;
        for(ll i=0;i<y;i++)
        ans+=(b[i]!=c[i]);

        return dp[x][y]=ans;
    }
    else if(y==0)
    {
        ll ans=0;
        for(ll i=0;i<x;i++)
        ans+=(a[i]!=c[i]);

        return dp[x][y]=ans; 
    }
    else
    return dp[x][y]=min((a[x-1]!=c[x+y-1])+(find(x-1,y,a,b,c,dp)),(b[y-1]!=c[x+y-1])+(find(x,y-1,a,b,c,dp)));
}

void solve()
{
    string a,b,c;
    cin>>a>>b>>c;
    vector<vector<ll>>dp(a.size()+1,vector<ll>(b.size()+1,-1));
    cout<<find(a.size(),b.size(),a,b,c,dp)<<endl;

}
int main()
{
  fastio();
  cout << setprecision(12) << fixed;

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

    solve();
  }
}



Solution 2 (runtime: 93 ms):
#include <iostream>

#include <vector>

#include <algorithm>



int res = 1e9;



/*

    egg

    annie

    egaegaeg

*/ 

void solve(std::string& a,std::string& b, const std::string& c, std::string cur, int i, int j, int k) {

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

        int temp = 0;

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

                if (cur[i] != c[i])            

                    temp++;

            }

            

        res = std::min(res, temp);

        return;

    }

    

    if (j < a.size())

        solve(a, b, c, cur + a[j], i + 1, j + 1, k);



    if (k < b.size())

        solve(a, b, c, cur + b[k], i + 1, j, k + 1);

}



int main() {

    int t;

    std::cin >> t;

    while (t--) {

        std::string a;

        std::string b;

        std::string c;

        std::cin >> a >> b >> c; 

        solve(a, b, c, "", 0, 0, 0);

        std::cout << res << '\n';

    }

}