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

Solution 1 (runtime: 140 ms):
#include<bits/stdc++.h>         
using namespace std; 
typedef vector<int> vi ;
typedef set<int> si ;
#define all(a) a.begin(), a.end()
#define ain(a)      \
    for (auto &x : a) \
    cin >> x
#define aout(a)     \
    for (auto &x : a) \
    cout << x << ' '
#define nl cout << endl;
  #define rep(j, a, b) for(int j = a; j < (b); ++j) 
 #define trav(p, x) for(auto& p : x)
#define int long long int
#define mod 1000000007


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


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


}


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


Solution 2 (runtime: 108 ms):
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

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

    int n = a.length(), m = b.length(), p = c.length();

    // If the total length of a and b is less than c, it's impossible
    if (n + m < p) {
        cout << -1 << endl;
        return;
    }

    // DP Table
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1e5));

    // Base Case: Starting with an empty prefix of `a` and `b`
    dp[0][0] = 0;

    // Fill the DP table
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            int k = i + j; // Total number of characters used so far

            if (k > p) continue; // No need to process if exceeding the length of `c`

            // Transition if the next character matches from `a`
            if (i < n && k < p && a[i] == c[k]) {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            }

            // Transition if the next character matches from `b`
            if (j < m && k < p && b[j] == c[k]) {
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j]);
            }

            // Transition if we need to insert a character
            if (i < n) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1);
            if (j < m) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1);
        }
    }

    // Final answer is in dp[n][m]
    int result = dp[n][m];
    if (result >= 1e5) {
        cout << -1 << endl; // Impossible to form `c`
    } else {
        cout << result << endl; // Minimum steps
    }
}

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