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

Solution 1 (runtime: 93 ms):
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define v(a) vector<(a)>
#define rep(a, i) for(int i = 0; i < (a); i++)
#define read(a, n) for(int i = 0; i < (n); i++){ cin >> a[i];}
#define pB pop_back
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define int long long
#define pi pair<int, int>
const int mod = 998244353;
#define bismillah ios::sync_with_stdio(0); cin.tie(0);
const int INF = 1e18;


void solve(){
    string aa, bb, c; cin >> aa >> bb >> c;

    int x = aa.size();
    int y = bb.size();
    vector<vector<int>> dp(x+1, vector<int>(y+1, 1e9));
    dp[0][0] = 0;
    
    for(int a = 0; a <= x; a++){
        for(int b = 0; b <= y; b++){  
            int z = a + b;

            if(z > c.size()) continue;

            if(a < x && aa[a] == c[z]){
                dp[a+1][b] = min(dp[a+1][b], dp[a][b]);
            }

            

            if(b < y && bb[b] == c[z]){
                dp[a][b+1] = min(dp[a][b+1], dp[a][b]);
            }

            if(a < x) dp[a+1][b] = min(dp[a+1][b], dp[a][b]+1);
            if(b < y) dp[a][b+1] = min(dp[a][b+1], dp[a][b]+1);
            
        }
    }

    cout << dp[x][y];
    
}

signed main() {
    bismillah
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
        cout << "\n";
    }
    return 0;
}

Solution 2 (runtime: 108 ms):
#include <iostream>
#include <vector>
#include <stack>
using namespace std;


void f(vector <vector <pair<int,int> > > &vec, int row,int col,string &a,string &b,string &c){
    if (col<a.size()){
        
        if (vec[row][col+1].first==0){
            vec[row][col+1].first = vec[row][col].first + 1;
            if (a[col]==c[vec[row][col].first]) vec[row][col+1].second = vec[row][col].second;
            else vec[row][col+1].second = vec[row][col].second + 1;
        }
        else{
            if (a[col]==c[vec[row][col].first]) vec[row][col+1].second = min(vec[row][col].second,vec[row][col+1].second);
            else vec[row][col+1].second = min(vec[row][col].second + 1,vec[row][col+1].second);
        }

    }
    
    if(row<b.size()){

        if (vec[row+1][col].first==0){
            vec[row+1][col].first = vec[row][col].first + 1;
            if (b[row]==c[vec[row][col].first]) vec[row+1][col].second = vec[row][col].second;
            else vec[row+1][col].second = vec[row][col].second + 1;
        }
        else{
            if (b[row]==c[vec[row][col].first]) vec[row+1][col].second = min(vec[row][col].second, vec[row+1][col].second);
            else vec[row+1][col].second = min(vec[row][col].second +1, vec[row+1][col].second);
        }
    }

    return;
}

int main(){
    int t;
    cin>>t;

    while (t--){
        string a,b;
        cin>>a>>b;

        string c;
        cin>>c;

        pair<int,int> p;
        p.first=0; p.second=0;

        vector <pair<int,int> > v(a.size()+1,p);
        vector <vector <pair<int,int> > > vec(b.size()+1,v);


        stack <pair<int,int> > st1,st2;

        st1.push(p);
        int row,col;
        int max_row=0;
        int min_col=0;

        while (!st1.empty()){
            while (!st1.empty()){
                p=st1.top();
                st1.pop();
                row=p.first;
                col=p.second;

                f(vec,row,col,a,b,c);

                if (col<a.size()) st2.push(make_pair(row,col+1));
            }

            while (!st2.empty()){
                p=st2.top();
                st2.pop();
                st1.push(p);
                if (max_row<p.first) max_row=p.first;
                if (min_col>p.second) min_col=p.second;
            }

            if (max_row<b.size()) st1.push(make_pair(max_row+1,min_col));
        }


        cout<<vec[b.size()][a.size()].second<<endl;

        // for (int i=0;i<=b.size();i++){
        //     for (int j=0;j<=a.size();j++){
        //         cout<<vec[i][j].first<<"-"<<vec[i][j].second<<"  ";
        //     }
        //     cout<<endl;
        // }


    }
}