Language: C++

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

vector<vector<long long>> memo[3][3];
vector<int> id = {0, 1, 2};
vector<string> v;

long long solve();

int main() {
  for(int i = 0; i < 3; ++i) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j) {
      int llen = v[i].size(), rlen = v[j].size();
      memo[i][j].assign(v[i].size(),
                        vector<long long>(v[j].size(), -1));
      for(int l = 0; l < v[i].size(); ++l)
        for(int r = 0; r < v[j].size(); ++r)
          if(memo[i][j][l][r] == -1) {
            int cnt = 0;
            while(l + cnt < llen && r + cnt < rlen &&
                  (v[i][l + cnt] == '?' ||
                   v[j][r + cnt] == '?' ||
                   v[i][l + cnt] == v[j][r + cnt]))
              ++cnt;
            for(int p = 0; p < cnt; ++p) {
              memo[i][j][l + p][r + p] = cnt - p;
            }
          }
    }

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, sum = 0;
  for(auto s : v) sum += s.size();
  res = sum;
  do {
    int flen = v[id[0]].size(), mlen = v[id[1]].size(),
        llen = v[id[2]].size();
    for(int i = 0; i <= flen; ++i)
      for(int j = 0; j <= i + mlen; ++j) {
        bool ch = 1;
        if(i != flen &&
           memo[id[0]][id[1]][i][0] != flen - i)
          ch = 0;
        if(j < flen && memo[id[0]][id[2]][j][0] != flen - j)
          ch = 0;
        if(j != i + mlen && i <= j &&
           memo[id[1]][id[2]][j - i][0] !=
               min({llen, mlen - (j - i)}))
          ch = 0;
        if(i >= j && i - j + 1 <= llen &&
           memo[id[1]][id[2]][0][i - j] !=
               min(mlen, llen - (i - j)))
          ch = 0;
        if(ch) {
          res =
              min(res,
                  max({(long long)flen, (long long)i + mlen,
                       (long long)j + v[id[2]].size()}));
        }
      }
  } while(next_permutation(id.begin(), id.end()));
  return res;
}


Compiler output:
a.cc: In function 'long long int solve()':
a.cc:66:22: error: no matching function for call to 'max(<brace-enclosed initializer list>)'
   66 |                   max({(long long)flen, (long long)i + mlen,
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   67 |                        (long long)j + v[id[2]].size()}));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   template argument deduction/substitution failed:
a.cc:66:22: note:   deduced conflicting types for parameter '_Tp' ('long long int' and 'long long unsigned int')
   66 |                   max({(long long)flen, (long long)i + mlen,
      |                   ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   67 |                        (long long)j + v[id[2]].size()}));
      |                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   candidate expects 2 arguments, 1 provided