Language: C++

/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

vector<int> Zalgo(const string& s) {
    int n = (int)s.size();
    vector<int> res(n);
    res[0] = n;
    int i = 1, j = 0;
    while(i < n) {
        while(i + j < n && (s[j] == s[i+j] || s[j] == '?' || s[i + j] == '?')) ++j;
        res[i] = j;
        if(j == 0) {++i; continue;}
        int k = 1;
        while(i + k < n && k + res[k] < j) res[i + k] = res[k], ++k;
        i += k, j -= k;
    }
    return res;
}

pair<bool, string> equal(string a, string b) {
    int l = (int)a.size();
    string res = "";
    rep(i, l) {
        if(a[i] != b[i] && a[i] != '?' && b[i] != '?') {
            return {false. res};
        }
        if(a[i] == '?' && b[i] == '?') {
            res += '?';
        } else if(a[i] == '?') {
            res += b[i];
        } else if(b[i] == '?') {
            res += a[i];
        } else {
            res += a[i];
        }
    }
    return {true, res};
}

void solve() {
	string a, b, c; cin >> a >> b >> c;
    int n = (int)a.size(), m = (int)b.size(), l = (int)c.size();
    int ans = n + m + l;
    if(m > l) {
        swap(b, c);
        swap(m, l);
    }
    if(n > m) {
        swap(a, b);
        swap(n, m);
    }
    if(m > l) {
        swap(b, c);
        swap(m, l);
    }
    vector<string> vec;
    string t = "";
    for(int i = 0; i <= l; ++i) {
        string k = a;
        k += t;
        k += b;
        vec.pb(k);
        string u = b;
        u += t;
        u += a;
        vec.pb(u);
        t += "?";
    }
    for(int i = 1; i <= n; ++i) {
        string aa = a.substr(n - i);
        string bb = b.substr(0, i);
        auto re = equal(aa, bb);
        if(re.fr == 0) continue;
        string qq = a.substr(0, n - i);
        qq += re.sc;
        qq += b.substr(i, m - i);
        vec.pb(qq);
    }
    for(int i = 1; i <= n; ++i) {
        string aa = a.substr(0, i);
        string bb = b.substr(m - i);
        auto re = equal(aa, bb);
        if(re.fr == 0) continue;
        string qq = b.substr(0, m - i);
        qq += re.sc;
        qq += a.substr(i, n - i);
        vec.pb(qq);
    }
    string qq = a + b;
    auto res = Zalgo(qq);
    for(int i = n; i <= n + m - n; ++i) {
        if(res[i] == n) {
            string pp = b.substr(0, i - n);
            pp += equal(a, b.substr(i - n, n)).sc;
            pp += b.substr(i, m - i - n);
            vec.pb(pp);
        }
    }
    for(auto u: vec) {
        if(u.size() < l) {
            int sz = u.size();
            string uu = u;
            uu += c;
            auto res = Zalgo(uu);

            for(int i = sz; i <= sz + l - sz; ++i) {
                if(res[i] == sz) {
                    chmin(ans, l);
                }
            }

                for(int i = 1; i <= sz; ++i) {
        string aa = u.substr(sz - i);
        string bb = c.substr(0, i);
        auto re = equal(aa, bb);
        if(re.fr == 0) continue;
        chmin(ans, sz + l - i)
    }
    for(int i = 1; i <= sz; ++i) {
        string aa = u.substr(0, i);
        string bb = c.substr(sz - i);
        auto re = equal(aa, bb);
        if(re.fr == 0) continue;
        chmin(ans, sz + l - i)
    }

        } else {
            int sz = u.size();
            string uu = c;
            uu += u;
            auto res = Zalgo(uu);

            for(int i = l; i <= l + sz - l; ++i) {
                if(res[i] == l) {
                    chmin(ans, sz);
                }
            }

            for(int i = 1; i <= l; ++i) {
        string aa = c.substr(l - i);
        string bb = u.substr(0, i);
        auto re = equal(aa, bb);
        if(re.fr == 0) continue;
        chmin(ans, sz + l - i)
    }
    for(int i = 1; i <= l; ++i) {
        string aa = c.substr(0, i);
        string bb = u.substr(l - i);
        auto re = equal(aa, bb);
        if(re.fr == 0) continue;
        chmin(ans, sz + l - i)
    }
        }

    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Compiler output:
a.cc: In function 'std::pair<bool, std::__cxx11::basic_string<char> > equal(std::string, std::string)':
a.cc:76:28: error: request for member 'res' in 'false', which is of non-class type 'bool'
   76 |             return {false. res};
      |                            ^~~
a.cc:76:31: error: could not convert '{<expression error>}' from '<brace-enclosed initializer list>' to 'std::pair<bool, std::__cxx11::basic_string<char> >'
   76 |             return {false. res};
      |                               ^
      |                               |
      |                               <brace-enclosed initializer list>
a.cc: In function 'void solve()':
a.cc:168:31: error: expected ';' before '}' token
  168 |         chmin(ans, sz + l - i)
      |                               ^
      |                               ;
  169 |     }
      |     ~                          
a.cc:175:31: error: expected ';' before '}' token
  175 |         chmin(ans, sz + l - i)
      |                               ^
      |                               ;
  176 |     }
      |     ~                          
a.cc:195:31: error: expected ';' before '}' token
  195 |         chmin(ans, sz + l - i)
      |                               ^
      |                               ;
  196 |     }
      |     ~                          
a.cc:202:31: error: expected ';' before '}' token
  202 |         chmin(ans, sz + l - i)
      |                               ^
      |                               ;
  203 |     }
      |     ~