Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <iomanip>
#include <climits>
#include <string>
#include <sstream>
#include <numeric>
#include <stack>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;
template < typename T >
vector< int > KMPTable(T &B) {
	int N = B.size();
	vector< int > table(N + 1, -1);
	int j = -1;
	for (int i = 0; i < N; i++) {
		while (j >= 0 && B[i] != B[j])
			j = table[j];
		table[i + 1] = ++j;
	}
	return table;
}
template < typename T >
vector< int > KMPSearch(T &A, T &B) {
	int N = A.size(), M = B.size();
	vector< int > table = KMPTable(B);
	vector< int > ret;
	for (int i = 0, k = 0; i < N; i++) {
		while (k >= 0 && A[i] != B[k] && A[i] != '?' && B[k] != '?')
			k = table[k];
		++k;
		if (k >= M) {
			ret.push_back(i - M + 1);
			k = table[k];
		}
	}
	return ret;
}
int N, M, K, T, Q, H, W;
signed main() {
	vector< string > S(3);
	rep(i, 3) cin >> S[i];
	int ans = LINF;
	vector< int > p(3);
	rep(i, 3) p[i] = i;
	do {
		string a = S[p[0]], b = S[p[1]], c = S[p[2]];

		string a2 = a + a;
		vector< int > res;
		rep(i, a.size() + 1) {
			if (i == a.size())
				res.push_back(i);
			else {
				bool f = false;
				rep(j, b.size()) {
					if (i + j >= a.size())
						break;
					if (a[i + j] != b[j] && a[i + j] != '?' && b[j] != '?') {
						f = true;
						break;
					}
				}
				if (!f) {
					res.push_back(i);
					break;
				}
			}
		}
		string a3((int)max((int)a.size(), (int)res[0] + b.size()), '?');
		rep(i, res[0]) a3[i] = (a[i]);
		rep(i, b.size()) {
			if (i + res[0] < a.size() && a[i + res[0]] != '?')
				a3[i + res[0]] = (a[i + res[0]]);
			else if (b[i] != '?')
				a3[i + res[0]] = (b[i]);
			else {
				a3[i + res[0]] = ('?');
			}
		}
		res.clear();
		a2 = a3 + a3;
		rep(i, a3.size() + 1) {
			if (i == a3.size())
				res.push_back(i);
			else {
				bool f = false;
				rep(j, c.size()) {
					if (i + j >= a3.size())
						break;
					if (a3[i + j] != c[j] && a3[i + j] != '?' && c[j] != '?') {
						f = true;
						break;
					}
				}
				if (!f) {
					res.push_back(i);
					break;
				}
			}
		}
		string a4((int)max((int)a3.size(), (int)res[0] + c.size()), '?');
		rep(i, res[0]) a4[i] = (a3[i]);
		rep(i, c.size()) {
			if (i + res[0] < a3.size() && a3[i + res[0]] != '?')
				a4[i + res[0]] = (a3[i + res[0]]);
			else if (c[i] != '?')
				a4[i + res[0]] = (c[i]);
			else {
				a4[i + res[0]] = ('?');
			}
		}
		//cout << a4 << endl;
		chmin(ans, a4.size());
	} while (next_permutation(p.begin(), p.end()));
	cout << ans << endl;
	/*
	string s, t;
	cin >> s >> t;
	vector< int > tmp = KMPSearch(s, t);
	cout << tmp;*/
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:168:35: error: no matching function for call to 'max(long long int, long long unsigned int)'
  168 |                 string a3((int)max((int)a.size(), (int)res[0] + b.size()), '?');
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:168:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
  168 |                 string a3((int)max((int)a.size(), (int)res[0] + b.size()), '?');
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:4:
/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:168:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  168 |                 string a3((int)max((int)a.size(), (int)res[0] + b.size()), '?');
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:200:35: error: no matching function for call to 'max(long long int, long long unsigned int)'
  200 |                 string a4((int)max((int)a3.size(), (int)res[0] + c.size()), '?');
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:200:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long long unsigned int')
  200 |                 string a4((int)max((int)a3.size(), (int)res[0] + c.size()), '?');
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:200:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
  200 |                 string a4((int)max((int)a3.size(), (int)res[0] + c.size()), '?');
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~