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

Solution 1 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;

int recursion(string s1, string s2, string c, int index1, int index2, vector<vector<int>> &dp)
{
    if (index1 == 0 && index2 == 0)
        return dp[index1][index2] = 0;
    if (dp[index1][index2] != -1)
        return dp[index1][index2];

    int a = INT_MAX;
    if (index1 > 0)
    {
        if (s1[index1 - 1] == c[index1 + index2 - 1])
        {
            a = min(a, recursion(s1, s2, c, index1 - 1, index2, dp));
        }
        else
        {
            a = min(a, 1 + recursion(s1, s2, c, index1 - 1, index2, dp));
        }
    }
    if (index2 > 0)
    {
        if (s2[index2 - 1] == c[index1 + index2 - 1])
        {
            a = min(a, recursion(s1, s2, c, index1, index2 - 1, dp));
        }
        else
        {
            a = min(a, 1 + recursion(s1, s2, c, index1, index2 - 1, dp));
        }
    }
    return dp[index1][index2] = a;
}
void solve()
{
    string s1, s2, c;
    cin >> s1 >> s2 >> c;

    int n1 = s1.size();
    int n2 = s2.size();

    vector<vector<int>> dp(n1 + 1, vector<int>(n2 + 1, 0));
    for (int i = 0; i <= n1; i++)
    {
        for (int j = 0; j <= n2; j++)
        {
            if(i==0 && j==0) continue;
            int a = INT_MAX;
            if (i > 0){
                if (s1[i - 1] == c[i + j - 1]){
                    a = min(a, dp[i - 1][ j]);
                }
                else{
                    a = min(a, 1 + dp[i - 1][j]);
                }
            }
            if (j > 0){
                if (s2[j - 1] == c[i + j - 1])
                {
                    a = min(a, dp[i][ j - 1]);
                }
                else
                {
                    a = min(a, 1 + dp[i][j - 1]);
                }
            }
            dp[i][j] = a;
        }
    }

    cout << dp[n1][n2]<< endl;
}

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

Solution 2 (runtime: 93 ms):
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define pb push_back
#define mpair make_pair
#define fo(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
#define log(x) (64 - __builtin_clzll(x) - 1)
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll mod_inverse(ll x) {
ll res = 1;
ll exp = mod - 2;
while (exp > 0) {
if (exp % 2 == 1) {
res = (res * x) % mod;
}
x = (x * x) % mod;
exp /= 2;
}
return res;
}
// here I solve my question
void solve(){
    string a,b,r;
    cin>>a;
    cin>>b;
    cin>>r;
    ll n=a.size();
    ll m=b.size();
    vector<vector<ll>>dp(n+1,vector<ll>(m+1,INT_MAX));
    dp[n][m]=0;
    for(ll i=n;i>=0;i--){
        for(ll j=m;j>=0;j--){
            if(i==n && j==m){
                continue;
            }
            else{
                ll i_pick=INT_MAX;
                ll j_pick=INT_MAX;
                if(i<n){
                    if(r[i+j]==a[i]){
                        i_pick=dp[i+1][j];
                    }
                    else{
                        i_pick=1+dp[i+1][j];
                    }
                }
                if(j<m){
                    if(r[i+j]==b[j]){
                        j_pick=dp[i][j+1];
                    }
                    else{
                        j_pick=1+dp[i][j+1];
                    }
                }
                dp[i][j]=min(i_pick,j_pick);
            }
        }
    }
    cout<<dp[0][0]<<'\n';
}

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