Language: C++

#include <bits/stdc++.h>
using namespace std;

template <class T>
vector<int> calc(const T &s) {
  vector<int> res;
  int n = s.size();
  res.assign(n + 1, 0);
  for(int i = 0; i < n; ++i) {
    int cnt = 0, id = 0, x = i;
    while(x < n && id < n && s[id] != '#' && s[x] != '#' &&
          (s[id] == s[x] || s[x] == '?' || s[id] == '?')) {
      ++cnt, ++id, ++x;
    }
    res[i] = cnt;
  }
  return res;
}

vector<string> v;

long long solve();

int main() {
  for(int i = 0; i < 3; ++i) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, sum = 0;
  for(auto s : v) sum += s.size();
  res = sum;
  sort(v.begin(), v.end());
  do {
    string pre, suf, mid, suf2, pre2, mid2;
    pre = v[1] + "#" + v[0];
    suf = v[2] + "#" + v[1];
    mid = v[2] + "#" + v[0];
    suf2 = v[1] + "#" + v[2];
    pre2 = v[0] + "#" + v[1];
    mid2 = v[0] + "#" + v[2];
    reverse(suf.begin(), suf.end());
    reverse(suf2.begin(), suf2.end());
    vector<int> zpre, zsuf, zmid, zpre2, zsuf2, zmid2;
    zpre = calc<string>(pre);
    zsuf = calc<string>(suf);
    zmid = calc<string>(mid);
    zpre2 = calc<string>(pre2);
    zsuf2 = calc<string>(suf2);
    zmid2 = calc<string>(mid2);
    int alen = v[0].size(), blen = v[2].size(),
        n = v[1].size();
    cout << v[0] << " " << v[1] << " " << v[2] << endl;
    cout << pre << endl;
    for(auto p : zpre) cout << p << " ";
    cout << endl;
    cout << mid << endl;
    for(auto p : zmid) cout << p << " ";
    cout << endl;
    cout << suf << endl;
    for(auto p : zsuf) cout << p << " ";
    cout << endl;
    cout << pre2 << endl;
    for(auto p : zpre2) cout << p << " ";
    cout << endl;
    cout << suf2 << endl;
    for(auto p : zsuf2) cout << p << " ";
    cout << endl;
    cout << endl;

    for(int i = 0; i <= n; ++i)
      for(int j = 0; j <= n; ++j) {
        bool ch = 1;
        if(i <= alen && zpre[n + 1 + alen - i] < i) ch = 0;
        if(i > alen && zpre2[1 + i] < alen) ch = 0;
        if(j <= blen && zsuf[n + 1 + blen - j] < j) ch = 0;
        if(j > blen && zsuf2[1 + j] < blen) ch = 0;
        int nowl = max({0, i - alen, n - j}),
            nowr = min(i, n, n - j + blen);
        if(nowl < nowr) {
          if(nowl == max(0, i - alen)) {
            if(zmid[blen + 1 + alen - (nowr - nowl)] <
               nowr - nowl)
              ch = 0;
          }
          else {
            if(zmid2[alen + 1 + blen - (nowr - nowl)] <
               nowr - nowl)
              ch = 0;
          }
        }
        if(ch) {
          res = min(res, sum - min(i, alen) - min(j, blen));
        }
      }
  } while(next_permutation(v.begin(), v.end()));
  return res;
}


Compiler output:
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare) [with _Tp = int; _Compare = int]':
a.cc:84:23:   required from here
   84 |             nowr = min(i, n, n - j + blen);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:284:17: error: '__comp' cannot be used as a function
  284 |       if (__comp(__b, __a))
      |           ~~~~~~^~~~~~~~~~