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,string &a,string &b,string &s,vector<string>&vec){
    if(i==a.size()){
        s+=b.substr(j);
        vec.push_back(s);
        return;
    }
    if(j==b.size()){
        s+=a.substr(i);
        vec.push_back(s);
        return;
        
    }
    string s1=s+a[i];
    findsubsets(i+1,j,a,b,s1,vec);
    string s2=s+b[j];
    findsubsets(i,j+1,a,b,s2,vec);
   
    
}
 
 
 
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: 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;


   
   
    
    
  
  }
 

    
    
    

   
   
}