Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Memory limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int p=1e9+7;
    bool valid(int k,int m){
        if(k>=1 && k<=m){
            return true;
        }
        return false;
    }
  long long  binpow(long long  a,  long long b) {
    long long ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = (ans) * (a);
        a = (a*a);
        b >>= 1;
    }
    return ans;
}
int modulo(int m){
    if(m<0){
       return (p-(abs(m))%p)%p;
    }
    else{
        return m%p;
    }
}
vector<int> printDivisors(int n) 
{ 
    vector<int>vec;

    for (int i = 1; i <= sqrt(n); i++) 
    { 
        if (n % i == 0) 
        { 
            // If divisors are equal,  
            // print only one 
            if (n / i == i) 
                vec.push_back(i);
  
            // Otherwise print both 
            else {
               vec.push_back(i);
               vec.push_back(n/i); }
        } 
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end()); 
    return vec;
}
bool check(vector<string>&vec,int i,int j){
int n=vec.size();
int m=vec[0].size();
if(i<n && i>=0 && j<m && j>=0){
    return true;
}
return false;
}
bool comp(const pair<int, int>& a, const pair<int, int>& b) {
        if(a.first==b.first){
            return a.second<b.second;
        }
        return a.first>b.first;
    }
void findsubsets(int i, int j, const string &a, const string &b, string &curr, vector<string> &result) {

    if (i == a.length()) {
        int originalSize = curr.length();
        curr.append(b.substr(j));
        result.push_back(curr);
        curr.resize(originalSize);
        return;
    }
    
    
    if (j == b.length()) {
        int originalSize = curr.length();
        curr.append(a.substr(i));
        result.push_back(curr);
        curr.resize(originalSize);
        return;
    }
    
  
    curr.push_back(a[i]);
    findsubsets(i + 1, j, a, b, curr, result);
    curr.pop_back();
    
    
    curr.push_back(b[j]);
    findsubsets(i, j + 1, a, b, curr, result);
    curr.pop_back();
}
 
 
 
int32_t main(){
int tests;
cin>>tests;
while(tests--){
   string a,b,c;
   cin>>a>>b>>c;
   vector<string>vec;
   string s="";
   findsubsets(0,0,a,b,s,vec);
   int mini=INT_MAX;
   for(string str:vec){
    int cnt=0;
    for(int i=0;i<str.size();i++){
        if(c[i]!=str[i]){
            cnt++;
        }

    }   
    mini=min(mini,cnt); 
   }
   cout<<mini<<endl;


   
   
    
    
  
  }
 

    
    
    

   
   
}

    

    
   


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int p=1e9+7;
    bool valid(int k,int m){
        if(k>=1 && k<=m){
            return true;
        }
        return false;
    }
  long long  binpow(long long  a,  long long b) {
    long long ans = 1;
    while (b > 0) {
        if (b & 1)
            ans = (ans) * (a);
        a = (a*a);
        b >>= 1;
    }
    return ans;
}
int modulo(int m){
    if(m<0){
       return (p-(abs(m))%p)%p;
    }
    else{
        return m%p;
    }
}
vector<int> printDivisors(int n) 
{ 
    vector<int>vec;

    for (int i = 1; i <= sqrt(n); i++) 
    { 
        if (n % i == 0) 
        { 
            // If divisors are equal,  
            // print only one 
            if (n / i == i) 
                vec.push_back(i);
  
            // Otherwise print both 
            else {
               vec.push_back(i);
               vec.push_back(n/i); }
        } 
    }
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end()); 
    return vec;
}
bool check(vector<string>&vec,int i,int j){
int n=vec.size();
int m=vec[0].size();
if(i<n && i>=0 && j<m && j>=0){
    return true;
}
return false;
}
bool comp(const pair<int, int>& a, const pair<int, int>& b) {
        if(a.first==b.first){
            return a.second<b.second;
        }
        return a.first>b.first;
    }
void findsubsets(int i, int j, const string &a, const string &b, string &curr, vector<string> &result) {

    if (i == a.length()) {
        int originalSize = curr.length();
        curr.append(b.substr(j));
        result.push_back(curr);
        curr.resize(originalSize);
        return;
    }
    
    
    if (j == b.length()) {
        int originalSize = curr.length();
        curr.append(a.substr(i));
        result.push_back(curr);
        curr.resize(originalSize);
        return;
    }
    
  
    curr.push_back(a[i]);
    findsubsets(i + 1, j, a, b, curr, result);
    curr.pop_back();
    
    
    curr.push_back(b[j]);
    findsubsets(i, j + 1, a, b, curr, result);
    curr.pop_back();
}
 
 
 
int32_t main(){
int tests;
cin>>tests;
while(tests--){
   string a,b,c;
   cin>>a>>b>>c;
   vector<string>vec;
   int len=a.size()+b.size();
   int i=0;
   int j=0;
   int k=0;
   int cnt=0;
   while(i<a.size() && j<b.size() && k<len){
    if(c[k]==a[i]){
        i++;
        k++;
    }
    else if(c[k]==b[j]){
        j++;
        k++;
    }
    else{
        i++;
        j++;
        k++;
        cnt++;
    }
   }
   if(i==a.size()){
    while(j<b.size() && k<len){
        if(c[k]!=b[j]){
            cnt++;
        }
        k++;
        j++;
    }
    cout<<cnt<<endl;
   }
   else{
    while(i<a.size() && k<len){
        if(c[k]!=a[i]){
            cnt++;
        }
        k++;
        i++;
    }
    cout<<cnt<<endl;
   }
   
   
   


   
   
    
    
  
  }
 

    
    
    

   
   
}