Language: C++

#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

Vs solve2(string a,string b){
    if(a.size()<b.size()) swap(a,b);
    Vs ret;
    ret.pb(b+a);
    REP(i,1,b.size()+1){
        bool check=true;
        REP(j,0,i){
//            cout<<a[i-1+j]<<" "<<b[b.size()-1-j]<<endl;
            if(!(a[i-1-j]==b[b.size()-1-j] || a[i-1-j]=='?' || b[b.size()-1-j]=='?')){
                check=false;
                break;
            }
        }
        if(check){
            ret.pb(b+a.substr(i));
        }
    }
    ret.pb(a+b);
    REP(i,1,b.size()+1){
        bool check=true;
        REP(j,0,i){
            if(!(a[a.size()-i+j]==b[j] || a[a.size()-i+j]=='?' || b[j]=='?')){
//                cout<<a[a.size()-i+j]<<" "<<b[j]<<endl;
                check=false;
                break;
            }
        }
        if(check){
            ret.pb(a+b.substr(i));
        }
    }
    REP(i,1,a.size()-b.size()){
        bool check=true;
        REP(j,0,b.size()){
            if(!(a[i+j]==b[j] || a[i+j]=='?' || b[j]=='?')){
                check=false;
                break;
            }
        }
        if(check){
            ret.pb(a);
            break;
        }
    }
    int n=INF;
    for(auto x: ret) chmin(n,x.size());
    Vs ret2;
    for(auto x: ret) if(x.size()==n) ret2.pb(x);
    return ret2;
}

void solve(std::string a, std::string b, std::string c){
    int ans=INF;
    Vs t1=solve2(a,b);
    for(auto x : t1){
        Vs t2=solve2(x,c);
        REP(i,0,t2.size()){
            chmin(ans,(int)t2[i].size());
        }
    }

    t1=solve2(b,c);
    for(auto x : t1){
        Vs t2=solve2(x,a);
        REP(i,0,t2.size()){
            chmin(ans,(int)t2[i].size());
        }
    }

    t1=solve2(a,c);
    for(auto x : t1){
        Vs t2=solve2(x,b);
        REP(i,0,t2.size()){
            chmin(ans,(int)t2[i].size());
        }
    }

    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    std::string a;
    std::cin >> a;
    std::string b;
    std::cin >> b;
    std::string c;
    std::cin >> c;
    solve(a, b, c);
    return 0;
}


Compiler output:
a.cc: In function 'Vs solve2(std::string, std::string)':
a.cc:98:27: error: no matching function for call to 'chmin(long long int&, std::__cxx11::basic_string<char>::size_type)'
   98 |     for(auto x: ret) chmin(n,x.size());
      |                      ~~~~~^~~~~~~~~~~~
a.cc:30:31: note: candidate: 'template<class T> bool chmin(T&, T)'
   30 | template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
      |                               ^~~~~
a.cc:30:31: note:   template argument deduction/substitution failed:
a.cc:98:27: note:   deduced conflicting types for parameter 'T' ('long long int' and 'long unsigned int')
   98 |     for(auto x: ret) chmin(n,x.size());
      |                      ~~~~~^~~~~~~~~~~~