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

Solution 1 (runtime: 62 ms):
#include <iostream>
#include <algorithm>

static const int inf = 1e9;

// not my solution, just checking if it gives tle or not

void solve() {
    std::string a, b, res;
    std::cin >> a >> b >> res;
    int n = (int) a.size(), m = (int) b.size();
    int dp[n + 1][m + 1];
    std::fill(&dp[0][0], &dp[0][0] + (n + 1) * (m + 1), inf);
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != res[i]);
    }
    for (int j = 0; j < m; j++) {
        dp[0][j + 1] = dp[0][j] + (b[j] != res[j]);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = std::min(dp[i - 1][j] + (a[i - 1] != res[i + j - 1]),
                                dp[i][j - 1] + (b[j - 1] != res[i + j - 1]));
        }
    }
    std::cout << dp[n][m] << std::endl;
}

int main() {
    int tests;
    std::cin >> tests;
    while (tests--) {
        solve();
    }
}

Solution 2 (runtime: 108 ms):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;


class DisjointSet {
    vector<int>rank,parent,size;
    public:
    DisjointSet(int n){
        rank.resize(n+1,0);
        size.resize(n+1,0);
    parent.resize(n+1);
        for(int i=0;i<=n;i++){
        parent[i]=i;
    }
}
int findUpar(int node){
        if(node==parent[node]){
            return node;
    }
    return parent[node]=findUpar(parent[node]);
}
void UnionByRank(int u,int v){
        int parent_u=parent[u];
        int parent_v=parent[v];
        if(parent_u==parent_v)return ;
        if(rank[parent_u]<rank[parent_v]){
            parent[parent_u]=parent_v;
        }else if(rank[parent_u]>rank[parent_v]){
        parent[parent_v]=parent_u;
    }else{
        parent[parent_v]=parent_u;
        rank[parent_u]++;

    }
}
    void UnionBySize(int u,int v){
        int parent_u=parent[u];
        int parent_v=parent[v];
        if(parent_u==parent_v)return ;

if(size[parent_u]<size[parent_v]){
parent[parent_u]=parent_v;
        size[parent_v]+=size[parent_u];
        }else{
            parent[parent_v]=parent_u;
            size[parent_u]+=size[parent_v];
        }
    }

};


int binExpRec(int a,int b){
    if(b==0)return 1;
    int res=binExpRec(a,b/2);
    if(b&1){
        return (a*((res*1LL*res)%mod))%mod;
    }else{
        return (res*1LL*res)%mod;
   }
}


int binarySearch(int a,int arr[],int n){
    int l=0,r=n-1;
    while(r-l>1){
        int mid=(l+r)/2;
        if(arr[mid]>a){
            r=mid-1;
        }else{
            l=mid;
        }
    }
    if(arr[l]==a){
        return l;
    }else if(arr[r]==a){
        return r;
    }else{
        return -1;
    }

}


int mex(int arr[],int n){
    int mx=0;
    sort(arr,arr+n);
    for(int i=0;i<n;i++){
        if(mx==arr[i])mx++;
    }
    return mx;
}


void primeFactors(int n,vector<int>&v)
{
 
while (n % 2 == 0)
{
    // cout << 2 << 
;
    v.push_back(2);
    n = n/2;
}
for (int i = 3; i <= sqrt(n); i = i + 2)
{
    while (n % i == 0)
    {
        // cout << i << 
;
        v.push_back(i);

        n = n/i;
    }
}
if (n > 2){
    v.push_back(n);
}
    // cout << n << 
;
}

int factorial(int n)
{
    return (n==1 || n==0) ? 1: n * factorial(n - 1);
}
int modInverse(int A, int M) {
    int m0 = M;
    int y = 0, x = 1;

    if (M == 1)
        return 0;

    while (A > 1) {

        int q = A / M;
        int t = M;


        M = A % M, A = t;
        t = y;


        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}


int subArrayXor(int tar,int arr[],int n){
    int xorArray[n];
    map<int,int>mp;
    xorArray[0]=arr[0];
    for(int i=1;i<n;i++){
        xorArray[i]=xorArray[i-1]^arr[i];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        int temp=xorArray[i]^tar;
        ans+=mp[temp];
        if(xorArray[i]==tar)ans++;
        mp[xorArray[i]]++;
    }
    return ans;
}

int f(string &a,string &b,string &c,int i,int j,vector<vector<int>>&dp){
    int mx=0;
    int temp1= 0;
    int temp2= 0;
    if(dp[i][j]!=-1)return dp[i][j];
    if(i==a.size()){
        int cnt=0;
        for(int k=j;k<b.size();k++){
            if(b[k]==c[k+i]){
                cnt++;
            }
        }
        return dp[i][j]=cnt;
    }
    if(j==b.size()){
        int cnt=0;
        for(int k=i;k<a.size();k++){
            if(a[k]==c[k+j]){
                cnt++;
            }
        }
        return dp[i][j]=cnt;
    }
    temp1=f(a,b,c,i+1,j,dp);
    temp2=f(a,b,c,i,j+1,dp);
    if(a[i]==c[i+j] ){
        // mx=max(mx,f())
        return dp[i][j]=max(temp1+1,temp2+(b[j]==c[i+j]));
    }
    if( b[j]==c[i+j]){
        // mx=max(mx,f())
        return dp[i][j]=max(temp2+1,temp1);
    }
    return dp[i][j]=max(temp1,temp2);
}

void solve(){
    string a,b,c;
    cin>>a>>b>>c;
    // cout<<f(a,b,c,0,0)<<endl;
    
    vector<vector<int>>dp(a.size()+1,vector<int>(b.size()+1,-1));
    cout<<c.size()-f(a,b,c,0,0,dp)<<endl;
}


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