Language: C++

#include<iostream>
#include<cstring>
#include<cstdio>
#define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
#define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i)
using namespace std;
typedef long long ll;
const int maxn = 2010;
char s[4][maxn],re[4][maxn];
int ans,nex[maxn],extend[maxn];
int p[4][7]{{},{0,1,1,2,2,3,3},{0,2,3,1,3,1,2},{0,3,2,3,1,2,1}};

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}

inline void Get_Next(char* x)
{
	int len=strlen(x+1),pl=2,pr=1;
	nex[1]=len;
	while(pr<len&&x[pr]==x[pr+1]) ++pr;
	nex[pl]=pr-1;
	For(i,3,len)
	{
		int& ex=nex[i-pl+1];
		if(ex+i-1<pr) nex[i]=ex;
		else
		{
			int j=max(pr-i+1,0);
			while(i+j<=len&&x[i+j]==x[j+1])
				++j;
			pr=i+(nex[pl=i]=j)-1;
		}
	}
}

inline void ExKMP(char* x,char* y)
{
	int len1=strlen(x+1),len2=strlen(y+1),pl=1,pr=1;
	while(pr<=len2&&(x[pr]==y[pr]||x[pr]=='?'||y[pr]=='?')) ++pr;
	extend[pl]=--pr;
	For(i,2,len1)
	{
		int& ex=nex[i-pl+1];
		if(ex+i-1<pr) extend[i]=ex;
		else
		{
			int j=max(pr-i+1,0);
			while(i+j<=len1&&j<len2&&(x[i+j]==y[j+1]||x[i+j]=='?'||y[j+1]=='?'))
			{
				if(y[j+1]=='?') y[j+1]=x[i+j];
				++j;
			}
			pr=i+(extend[pl=i]=j)-1;
		}
	}
}

inline readin()
{
	scanf("%s",re[1]+1);
	scanf("%s",re[2]+1);
	scanf("%s",re[3]+1); 
}

inline void update(int x)
{
	int len1=strlen(re[x]+1);
	For(i,1,len1)
		s[x][i]=re[x][i];
	s[x][len1+1]='\0';
}

inline void run()
{
	int len[4];
	len[1]=strlen(re[1]+1);
	len[2]=strlen(re[2]+1);
	len[3]=strlen(re[3]+1);
	ans=len[1]+len[2]+len[3];
	For(i,1,6)
	{
		update(1),update(2),update(3);
		int a=p[1][i],b=p[2][i],c=p[3][i],now,tent;
		now=len[a];
		Get_Next(s[b]);
		ExKMP(s[a],s[b]);
		tent=len[b];
		For(i,1,len[a])
			if(i+extend[i]-1==len[a])
			{
				tent=len[b]-extend[i];
				break;
			}
		now+=tent;
		Get_Next(s[c]);
		ExKMP(s[b],s[c]);
		tent=len[c];
		For(i,1,len[b])
			if(i+extend[i]-1==len[b])
			{
				tent=len[c]-extend[i];
				break;
			}
		now+=tent;
		ans=min(ans,now);
	}
	printf("%d\n",ans);
}

int main()
{
	readin();
	run(); 
	return 0;
}


Compiler output:
a.cc: In function 'void Get_Next(char*)':
a.cc:28:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   28 |         For(i,3,len)
      |             ^
a.cc:4:40: note: in definition of macro 'For'
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                        ^
a.cc:4:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                               ^~
a.cc:28:9: note: in expansion of macro 'For'
   28 |         For(i,3,len)
      |         ^~~
a.cc: In function 'void ExKMP(char*, char*)':
a.cc:47:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   47 |         For(i,2,len1)
      |             ^
a.cc:4:40: note: in definition of macro 'For'
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                        ^
a.cc:4:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                               ^~
a.cc:47:9: note: in expansion of macro 'For'
   47 |         For(i,2,len1)
      |         ^~~
a.cc: At global scope:
a.cc:64:8: error: ISO C++ forbids declaration of 'readin' with no type [-fpermissive]
   64 | inline readin()
      |        ^~~~~~
a.cc: In function 'int readin()':
a.cc:69:1: warning: no return statement in function returning non-void [-Wreturn-type]
   69 | }
      | ^
a.cc: In function 'void update(int)':
a.cc:74:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   74 |         For(i,1,len1)
      |             ^
a.cc:4:40: note: in definition of macro 'For'
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                        ^
a.cc:4:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                               ^~
a.cc:74:9: note: in expansion of macro 'For'
   74 |         For(i,1,len1)
      |         ^~~
a.cc: In function 'void run()':
a.cc:86:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   86 |         For(i,1,6)
      |             ^
a.cc:4:40: note: in definition of macro 'For'
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                        ^
a.cc:4:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                               ^~
a.cc:86:9: note: in expansion of macro 'For'
   86 |         For(i,1,6)
      |         ^~~
a.cc:94:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   94 |                 For(i,1,len[a])
      |                     ^
a.cc:4:40: note: in definition of macro 'For'
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                        ^
a.cc:4:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                               ^~
a.cc:94:17: note: in expansion of macro 'For'
   94 |                 For(i,1,len[a])
      |                 ^~~
a.cc:104:21: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
  104 |                 For(i,1,len[b])
      |                     ^
a.cc:4:40: note: in definition of macro 'For'
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                        ^
a.cc:4:47: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
    4 | #define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
      |                                               ^~
a.cc:104:17: note: in expansion of macro 'For'
  104 |                 For(i,1,len[b])
      |                 ^~~