Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

int main() {
    // your code goes here
    char a[5][2005];
    ll l[5],r[5]={0},ans=100000000;
    bool z[5015][5][5]={0};
    cin >> a[0] >> a[1] >> a[2];
    rep(i,0,2) l[i]=strlen(a[i]);
    rep(i,0,2){
        rep(j,0,2){
            if(i==j) continue;
            rep(k,0,l[i]-1){
                bool memo=true;
                rep(s,0,min(l[j]-1ll,l[i]-k-1)){
                    if(a[i][k+s]=='?') continue;
                    if(a[j][s]=='?') continue;
                    if(a[i][k+s]!=a[j][s]) memo=false;
                }
                if(memo) z[k][i][j]=true;
                //if(memo) cout << i << " " << j << " " << k << endl;
            }
            rep(k,l[i],5000) z[k][i][j]=true;
        }
    }
    vector<ll> p;
    p.push_back(0); p.push_back(1); p.push_back(2);
    do {
        rep(i,0,l[p[0]]){
            rep(j,0,l[p[1]]){
                if(z[i][p[0]][p[1]]&&z[j][p[1]][p[2]]&&z[i+j][p[0]][p[2]]){
                    ans=min(ans,l[p[0]]+max(0,l[p[1]]-(l[p[0]]-i))+max(0,l[p[2]]-(l[p[1]]-j)));
                }
            }
        }
    } while (next_permutation(p.begin(),p.end()));
    cout << ans << endl;
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:36:44: error: no matching function for call to 'max(int, ll)'
   36 |                     ans=min(ans,l[p[0]]+max(0,l[p[1]]-(l[p[0]]-i))+max(0,l[p[2]]-(l[p[1]]-j)));
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~
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:   template argument deduction/substitution failed:
a.cc:36:44: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   36 |                     ans=min(ans,l[p[0]]+max(0,l[p[1]]-(l[p[0]]-i))+max(0,l[p[2]]-(l[p[1]]-j)));
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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, 2 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:   candidate expects 1 argument, 2 provided
/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:   template argument deduction/substitution failed:
a.cc:36:44: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |                     ans=min(ans,l[p[0]]+max(0,l[p[1]]-(l[p[0]]-i))+max(0,l[p[2]]-(l[p[1]]-j)));
      |                                         ~~~^~~~~~~~~~~~~~~~~~~~~~~
a.cc:36:71: error: no matching function for call to 'max(int, ll)'
   36 |                     ans=min(ans,l[p[0]]+max(0,l[p[1]]-(l[p[0]]-i))+max(0,l[p[2]]-(l[p[1]]-j)));
      |                                                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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:   template argument deduction/substitution failed:
a.cc:36:71: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   36 |                     ans=min(ans,l[p[0]]+max(0,l[p[1]]-(l[p[0]]-i))+max(0,l[p[2]]-(l[p[1]]-j)));
      |                                                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~
/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, 2 provided
/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:   candidate expects 1 argument, 2 provided
/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:   template argument deduction/substitution failed:
a.cc:36:71: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   36 |                     ans=min(ans,l[p[0]]+max(0,l[p[1]]-(l[p[0]]-i))+max(0,l[p[2]]-(l[p[1]]-j)));
      |                                                                    ~~~^~~~~~~~~~~~~~~~~~~~~~~