Language: C++

#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 200005;
char en = '\n';
ll inf = 1e16;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1 % mod;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

bool compatible(string a, string b) {
  for (ll i = 0; i < a.length(); i++) {
    if (a[i] == '?' or b[i] == '?')
      continue;
    if (a[i] != b[i])
      return false;
  }
  return true;
}

string combine(string a, string b) {
  string res = "";
  for (ll i = 0; i < a.length(); i++) {
    res += (a[i] == '?') ? b[i] : a[i];
  }
  return res;
}

bool custComp(string &a, string &b) { return a.length() < b.length(); }

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string arr[3];
  for (ll i = 0; i < 3; i++) {
    cin >> arr[i];
  }

  ll perm[3];
  for (ll i = 0; i < 3; i++) {
    perm[i] = i;
  }

  ll res = arr[0].length() + arr[1].length() + arr[2].length();
  do {

    string a = arr[perm[0]];
    string b = arr[perm[1]];
    string c = arr[perm[2]];

    vector<string> combined;
    for (ll i = 0; i < a.length(); i++) {
      ll len = min((ll)a.length() - i, (ll)b.length());
      if (compatible(a.substr(i, len), b.substr(0, len))) {
        string curr = "";
        curr = a.substr(0, i);
        curr += combine(a.substr(i, len), b.substr(0, len));
        if (len == b.length())
          curr += a.substr(i + len, a.length() - (i + len));
        else
          curr += b.substr(len, b.length() - len);
        combined.push_back(curr);
      }
    }

    sort(combined.begin(), combined.end(), custComp);

    bitset<2001> cMask[26];

    for (ll i = 0; i < c.length(); i++) {
      if (c[i] == '?') {
        for (ll j = 0; j < 26; j++)
          cMask[j].set(i);
      }
      cMask[c[i] - 'a'].set(i);
    }

    for (string &s : combined) {

      //    cout << s << endl;
      res = min(res, (ll)s.length() + (ll)c.length());
      bitset<2001> sMask[26];
      for (ll i = 0; i < s.length(); i++) {
        if (s[i] == '?')
          continue;
        sMask[s[i] - 'a'].set(i);
      }

      for (ll i = 0; (i + c.length()) < res && i < s.length(); i++) {
        bool bad = false;
        for (ll j = 0; j < 26; j++) {
          if (((sMask[j] >> i) & cMask[j]) != (sMask[j] >> i)) {
            bad = true;
            break;
          }
        }
        if (bad)
          continue;
        res = min(res, i + c.length());
        break;
      }
    }

  } while (next_permutation(perm, perm + 3));

  cout << res << en;
  return 0;
}

Compiler output:
a.cc: In function 'int32_t main()':
a.cc:111:18: error: no matching function for call to 'min(ll&, long long unsigned int)'
  111 |         res = min(res, i + c.length());
      |               ~~~^~~~~~~~~~~~~~~~~~~~~
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:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:111:18: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
  111 |         res = min(res, i + c.length());
      |               ~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:111:18: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  111 |         res = min(res, i + c.length());
      |               ~~~^~~~~~~~~~~~~~~~~~~~~