Problem:


Score : 500 points

Problem Statement

Snuke has a string s.
From this string, Anuke, Bnuke, and Cnuke obtained strings a, b, and c, respectively, as follows:

Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with ?s.

For example, if s is mississippi, we can choose the substring ssissip and replace its 1-st and 3-rd characters with ? to obtain ?s?ssip.

You are given the strings a, b, and c.
Find the minimum possible length of s.

Constraints

1 \leq |a|, |b|, |c| \leq 2000

a, b, and c consists of lowercase English letters and ?s.

Input

Input is given from Standard Input in the following format:

a
b
c

Output

Print the minimum possible length of s.

Sample Input 1

a?c
der
cod

Sample Output 1

7

For example, s could be atcoder.

Sample Input 2

atcoder
atcoder
???????

Sample Output 2

7

a, b, and c may not be distinct.



Sample input:
a?c
der
cod


Sample output:
7

Submission status: Runtime Error

Solution code:
A = input()
B = input()
C = input()


def check(S, T):
    """
    S,Tの順に結合する
    """
    Ns = len(S)

    for i, t in enumerate(T):
        if t != "?":
            break
    T = T[i:]
    Nt = len(T)
    match = 0

    for i, s in enumerate(S):
        if s == T[0] or s == "?" or T[0] == "?":
            x = i
            y = 0
            while x < Ns or y < Nt:
                if S[x] == "?" or T[y] == "?" or S[x] == T[y]:
                    x += 1
                    y += 1
                    continue
                else:
                    break
            else:
                match = max(match, y)
    suffix = T[match:]
    return S + suffix


abc = check(check(A, B), C)
acb = check(check(A, C), B)
bac = check(check(B, A), C)
bca = check(check(B, C), A)
cab = check(check(C, A), B)
cba = check(check(C, B), A)
# print(abc)
# print(acb)
# print(bac)
# print(bca)
# print(cab)
# print(cba)

ans = min(len(x) for x in [abc, acb, bac, bca, cab, cba])
print(ans)

Submission status: Runtime Error

Solution code:
from itertools import permutations as pe
a=[input()for i in range(3)]
def f(a,b):
    n=len(a)+len(b)
    s=b+a
    t=[0]*n
    i=len(b)+1;j=0
    t[0]=n
    while i<n:
        while i+j<n and (s[j]==s[i+j] or s[j]=="?" or s[i+j]=="?"):
            j+=1
        if not j:
            i+=1
            continue
        t[i]=j
        k=1
        while n-i>k<j-t[k]:
            t[i+k]=t[k]
            k+=1
        i+=k; j-=k
    t=t[-len(a):]
    for i in range(len(a)):
        if t[i]>=len(a)-i:
            t[i]=1
    return t[-len(a):]
b=[[0 if i==j else f(a[i],a[j])for i in range(3)]for j in range(3)]
an=len(a[0])+len(a[1])+len(a[2])
do=len(a[0])+len(a[1])+len(a[2])
for i,j,h in pe([0,1,2],3):
    for p in range(len(a[i])):
        for q in range(len(a[j])):
            if b[i][j][p] and b[j][h][q]:
                if len(a[i])>=p+q:
                    if b[i][h][p+q-1]>=len(a[i])-p-q:
                        an=min(an,p+q+len(a[h]))
                else:
                    an=min(an,p+q+len(a[h]))
print(an)

Submission status: Runtime Error

Solution code:
def main():
    a = [c for c in input()]
    b = [c for c in input()]
    c = [c for c in input()]

    ans = 7000
    for x, y, z in [(a, b, c), (a, c, b), (b, a, c), (b, c, a), (c, a, b), (c, b, a)]:
        for m in cct(x, y):
            x = binsearch(0, 7000, lambda i: ok(i, m, y))
            ans = min(x, ans)
    print(ans)

def ok(n, xs, b):
    for a in xs:
        if len(a) + len(b) <= n:
            return True
        o = True
        for i in range(n-len(b), len(a)):
            if a[i] != b[n-len(b)+i] and a[i] != '?' and b[n-len(b)+1] != '?':
                o = False
                break
        if o:
            return True
    
def binsearch(i, j, ok):
    if i+1 == j:
        return j
    m = (i + j) // 2
    if ok(m):
        return binsearch(i, m, ok)
    else:
        return binsearch(m, j, ok)


def cct(a, b):
    c = [a+b]
    for i in range(len(a)):
        z = list(a)
        f = True
        for j in range(len(b)):
            if i+j >= len(a):
                break
            elif a[i+j] != b[j]:
                if a[i+j] == '?':
                    z[i+j] = b[j]
                elif b[j] != '?':
                    f = False
                    break
        if f:
            if i+len(b) > len(a):
                z.extend(b[len(a)-i:])
            c.append(z)
    return c



main()

Submission status: Runtime Error

Solution code:
a=input()
a_l=len(a)
b=input()
b_l=len(b)
c=input()
c_l=len(c)
def check(s1,s2):
    l1=len(s1)
    l2=len(s2)
    ret=[0]*(l1+l2-1)
    for i in range(l1+l2-1):
        flag=True
        if i-l2+1<0:
            for j in range(i+1):
                if s1[j]!="?" and s2[l2-i+j-1]!="?" and s1[j]!=s2[l2-i+j-1]:
                    flag=False
                    break
        elif i-l2+1>=0 and i<=l1-1:
            for j in range(l2):
                if s1[i-l2+j+1]!="?" and s2[j]!="?" and s1[i-l2+j+1]!=s2[j]:
                    flag=False
                    break
        else:
            for j in range(l1+l2-i-1):
                if s1[i-l2+j+1]!="?" and s2[j]!="?" and s1[i-l2+j+1]!=s2[j]:
                    flag=False
                    break
        ret[i]=flag
    return ret
ab=check(a,b)
ab_l=len(ab)
ac=check(a,c)
ac_l=len(ac)
bc=check(b,c)
bc_l=len(bc)
ans=a_l+b_l+c_l
for i in range(-2000,ab_l+2000):
    if i<0 or i>=ab_l or ab[i]:
        for j in range(-2000,ac_l+2000):
            if j<0 or j>=ac_l or ac[j]:
                if j-i+b_l+1<0 or j-i+b_l+1>=bc_l or bc[j-i+b_l+1]:
                    l=max(a_l-1,i,j)-min(0,i-b_l+1,j-c_l+1)+1
                    ans=min(ans,l)
print(ans)

Submission status: Runtime Error

Solution code:


def get_str(st, i, len_val):
    ret = '?'*len_val
    for s in st:
        ret[i] = s
        i += 1
    return ret

def main():
    a = input()
    b = input()
    c = input()


    total_len = 6001

    def f(a1, b1, c1):
        nonlocal total_len
        for A,B,C in zip(a1,b1,c1):
            if len(set([char for char in [A,B,C] if char != '?'])) > 1:
                return False
        while a1[-1] != '?':
            a1 = a1[:-1]
        if len(a1) < total_len:
            total_len = len(a1)
        return True

    a_temp = get_str(a,0,len(a)+len(b)+len(c))

    for i in range(len(a)+len(b)+len(c)):
        try:
            b_temp = get_str(b,i,len(a)+len(b)+len(c))
            for j in range(len(a)+len(b)+len(c)):
                try:
                    c_temp = get_str(c,j,len(a)+len(b)+len(c))

                except:
                    pass
        except:
            pass

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from itertools import permutations as pe
a=[input()for i in range(3)]
def f(a,b):
    n=len(a)+len(b)
    s=b+a
    t=[0]*n
    i=len(b)+1;j=0
    t[0]=n
    while i<n:
        while i+j<n and (s[j]==s[i+j] or s[j]=="?" or s[i+j]=="?"):
            j+=1
        if not j:
            i+=1
            continue
        t[i]=j
        k=1
        while n-i>k<j-t[k]:
            t[i+k]=t[k]
            k+=1
        i+=k; j-=k
    t=t[-len(a):]
    for i in range(len(a)):
        if t[i]>=len(a)-i:
            t[i]=1
    return t[-len(a):]
b=[[0 if i==j else f(a[i],a[j])for i in range(3)]for j in range(3)]
print(b)
an=len(a[0])+len(a[1])+len(a[2])
do=len(a[0])+len(a[1])+len(a[2])
for i,j,h in pe([0,1,2],3):
    for p in range(len(a[i])):
        for q in range(len(a[j])):
            if b[i][j][p] and b[j][h][q]:
                if len(a[i])>=p+q:
                    if b[i][h][p+q-1]>=len(a[i])-p-q:
                        an=min(an,p+q+len(a[h]))
                else:
                    an=min(an,p+q+len(a[h]))
print(an)

Submission status: Runtime Error

Solution code:


def get_str(st, i, len_val):
    ret = '?'*len_val
    for s in st:
        ret[i] = s
        i++
    return ret

def main():
    a = input()
    b = input()
    c = input()


    total_len = 6001

    def f(a1, b1, c1):
        nonlocal total_len
        for A,B,C in zip(a1,b1,c1):
            if len(set([char for char in [A,B,C] if char != '?'])) > 1:
                return False
        while a1[-1] != '?':
            a1 = a1[:-1]
        if len(a1) < total_len:
            total_len = len(a1)
        return True

    a_temp = get_str(a,0,len(a)+len(b)+len(c))

    for i in range(len(a)+len(b)+len(c)):
        try:
            b_temp = get_str(b,i,len(a)+len(b)+len(c))
            for j in range(len(a)+len(b)+len(c)):
                try:
                    c_temp = get_str(c,j,len(a)+len(b)+len(c))

                except:
                    pass
        except:
            pass

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
a, b, c = input(), input(), input()
la, lb, lc = len(a), len(b), len(c)

# a <= b <= c
if la > lb:
    a, b = b, a
    la, lb = lb, la
if lb > lc:
    b, c = c, b
    lb, lc = lc, lb

def check(x, y):
    if x == y:
        return 1
    if x == "?" or y == "?":
        return 1
    return 0

# x <= y
def merge(x, y):
    res = []
    lx, ly = len(x), len(y)
    
    # y に 内包
    for i in range(ly - lx + 1):
        flag = 1
        for j in range(lx):
            if check(x[j], y[j + i]) == 0:
                flag = 0
                break
        if flag:
            res.append(y)
            break
    
    # y の 左
    for i in range(1, lx):
        flag = 1
        for j, xx in enumerate(x[i:]):
            if check(xx, y[j]) == 0:
                flag = 0
                break
        if flag:
            res.append(x[:i] + y)
    
    # y の 右
    x = x[::-1]
    y = y[::-1]
    for i in range(1, lx):
        flag = 1
        for j, xx in enumerate(x[i:]):
            if check(xx, y[j]) == 0:
                flag = 0
                break
        if flag:
            res.append((x[:i] + y)[::-1])
    return res

ans = []
for s in  merge(a, b):
    if len(s) <= len(c):
        ans += merge(s, c)
    else:
        ans += merge(c, s)

for s in  merge(a, c):
    if len(s) <= len(b):
        ans += merge(s, b)
    else:
        ans += merge(b, s)
answer = la + lb + lc
for a in ans:
    answer = min(answer, len(a))

print(answer)

Submission status: Runtime Error

Solution code:
a = input()
b= input()
c=input()


def matchAndjoin(a,b):
    for i in range(len(a)):
        ans = [x for x in a]
        for j in range(len(a)-i):
            if a[i+j] != b[j] and a[i+j] !='?' and b[j] !='?' :
             #   print(a[i+j] , b[j] )
                break

            else:
                if a[i+j]=='?':
                    ans[i+j]=b[j]
        else:
            return ''.join(ans)+b[j+1:]

    return a+b

def join3(a,b,c):
    return len(matchAndjoin( matchAndjoin(a,b),c))
print(matchAndjoin(a,c))
ans = min(join3(a,b,c),join3(a,c,b),join3(b,a,c),join3(b,c,a),join3(c,a,b),join3(c,b,a))
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
#N = 4
def to_str(n):
    s = [chr(i + 97) for i in reversed(n)]
    s = "".join(s)
    return s
n = [0] * N
n_max = list(reversed(list(range(N))))

s = to_str(n)
print(s)
while True:
    for j in range(N-1):
        #if n[j] < n[j+1]+1:
        if n[j] < max(n[j+1:]) + 1:
            n[j] += 1
            for k in range(j):
                n[k] = 0
            s = to_str(n)
            print(s)
            break
    if n == n_max:
        break

Submission status: Runtime Error

Solution code:
k = input()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'

a, b, c = k.split(' ')

if a == b == c:
  print(len(a))
elif a == b:
  for i in reversed(range(0, len(c))):
    if a.endswith(c[i:]) or a.startswith(c[:i]):
      print(len(a) + len(c) - i)
      break
elif a == c:
  for i in reversed(range(0, len(c))):
    if a.endswith(b[i:]) or a.startswith(b[:i]):
      print(len(a) + len(c) - i)
      break
elif b == c:
  for i in reversed(range(0, len(c))):
    if b.endswith(a[i:]) or b.startswith(c[:i]):
      print(len(b) + len(a) - i)
      break

Submission status: Runtime Error

Solution code:
a = input()
b= input()
c=input()


def matchAndjoin(a,b):
    for i in range(len(a)):
        ans = [x for x in a]
        for j in range(len(a)-i):
            if a[i+j] != b[j] and a[i+j] !='?' and b[j] !='?' :
                print(a[i+j] , b[j] )
                break

            else:
                if a[i+j]=='?':
                    ans[i+j]=b[j]
        else:
            return ''.join(ans)+b[j+1:]

    return a+b

def join3(a,b,c):
    return len(matchAndjoin( matchAndjoin(a,b),c))
print(matchAndjoin(a,c))
ans = min(join3(a,b,c),join3(a,c,b),join3(b,a,c),join3(b,c,a),join3(c,a,b),join3(c,b,a))
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c = input(),input(),input()
ma = len(a)+len(b)+len(c)
m = ma
def check1(i,j,l):
  f = 0
  for n in range(l):
    if i[len(i)-l+n] != j[n] and i[len(i)-l+n] != '?' and j[n] != '?':
      f = 1
      break
  if f == 0:
    return True
  else:
    return False
def check2(i,j,k,o):
  f = 0
  for n in range(o):
    if j[len(j)-o+n] != k[n]:
      if k[n] == '?':
        continue
      elif j[len(j)-o+n] == '?':
        try:
          if i[len(i)-l+len(j)-o+n] == k[n] or i[len(i)-l+len(j)-o+n] == '?':
            continue
          else:
            f = 1
            break
        except:
          continue
      else:
        f = 1
        break
  if f == 0:
    return True
  else:
    return False
for i,j,k in [[a,b,c],[a,c,b],[b,a,c],[b,c,a],[c,a,b],[c,b,a]]:
  for l in range(len(j),-1,-1):
    if check1(i,j,l) == False:
      continue
    for o in range(len(k),-1,-1):
      if ma-m >= l+o:
        break
      if check2(i,j,k,o):
        m = min(m,ma-l-o)
        break
print(m)

Submission status: Runtime Error

Solution code:
a=input()
a_l=len(a)
b=input()
b_l=len(b)
c=input()
c_l=len(c)
def check(s1,s2):
    l1=len(s1)
    l2=len(s2)
    ret=[0]*(l1+l2-1)
    for i in range(l1+l2-1):
        flag=True
        if i-l2+1<0:
            for j in range(i+1):
                if s1[j]!="?" and s2[l2-i+j-1]!="?" and s1[j]!=s2[l2-i+j-1]:
                    flag=False
                    break
        elif i-l2+1>=0 and i<=l1-1:
            for j in range(l2):
                if s1[i-l2+j+1]!="?" and s2[j]!="?" and s1[i-l2+j+1]!=s2[j]:
                    flag=False
                    break
        else:
            for j in range(l1+l2-i-1):
                if s1[i-l2+j+1]!="?" and s2[j]!="?" and s1[i-l2+j+1]!=s2[j]:
                    flag=False
                    break
        ret[i]=flag
    return ret
ab=check(a,b)
ab_l=len(ab)
ac=check(a,c)
ac_l=len(ac)
bc=check(b,c)
bc_l=len(bc)
ans=a_l+b_l+c_l
for i in range(-3000,ab_l+3000):
    if i<0 or i>=ab_l or ab[i]:
        for j in range(-3000,ac_l+3000):
            if j<0 or j>=ac_l or ac[j]:
                if (0<=j-i+b_l+1<bc_l and bc[j-i+b_l+1]) or j-i+b_l+1<0 or j-i+b_l+1>=bc_l:
                    l=max(a_l-1,i,j)-min(0,i-b_l+1,j-c_l+1)+1
                    ans=min(ans,l)
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from itertools import permutations as permi
input = sys.stdin.readline
a = list(input())[: -1]
b = list(input())[: -1]
c = list(input())[: -1]
res = len(a) + len(b) + len(c)
def check(k):
  for p in permi([a, b, c], 3):
    x = p[0]
    y = p[1]
    z = p[2]
    for i in range(k + 1):
      if len(x) < i: continue
      if len(y) < k - i: continue
      isok = 1
      s = x[: ]
      t = y[: ]
      for j in range(i):
        if s[-i + j] != t[j]:
          if s[-i + j] == "?": s[-i + j] = t[j]
          elif t[j] == "?": t[j] = s[-i + j]
          else:
            isok = 0
            break
      if isok == 0: continue
      u = z[: ]
      for j in range(k - i):
        if t[-i + j] != u[j]:
          if t[-i + j] == "?": t[-i + j] = u[j]
          elif u[j] == "?": u[j] = t[-i + j]
          else:
            isok = 0
            break
      #print(s, t, u, isok, k, k - i)
      if isok: return True
  return False

ok = 0
ng = len(a) + len(b) + len(c) - max(len(a), len(b), len(c)) + 1
while ng - ok > 1:
  m = (ok + ng) // 2
  if check(m): ok = m
  else: ng = m
print(len(a) + len(b) + len(c) - ok)

Submission status: Runtime Error

Solution code:
a =input()
b=input()
c=input()
if a==b or b==c or c==a:
  print(len(a))
else:
  	k=(3*len(a)-2)
    print(k)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

typedef int64_t ll;

template <class T1, class T2>
using dict = std::unordered_map<T1, T2>;

vector<int> compare(string d, string e){
   vector<int> ans;
   ans.push_back(-d.size());
    for(int i=-(int)e.size()+1;i<(int)d.size();i++){
        bool ok = true;
        int d_end = min((int)e.size()+i, (int)d.size());
        int d_start = max(i, 0);
        int e_start = max(-i,0);
        //cout << e_start << " " << d_start << " " << d_end << endl;
        rep(j,d_end - d_start){
            if(!(d.at(d_start+j) == e.at(e_start+j) || d.at(d_start+j) == '?' ||
                    e.at(e_start+j) == '?')){
                    ok = false;
                    break;
                }
        }
        if (ok)
            ans.push_back(i);
    }
        
    ans.push_back(d.size());
    return ans;

}

unordered_set<int> seter(vector<int> ab){
    unordered_set<int> ans;
    for (auto i:ab) ans.insert(i);
    return ans;
}

int main(){

    string a,b,c;
    cin >> a >> b >> c;
    vector<int> ab = compare(a,b);
    vector<int> bc = compare(b,c);
    vector<int> ac = compare(a,c);
    unordered_set<int> abs = seter(ab);
    unordered_set<int> bcs = seter(bc);
    unordered_set<int> acs = seter(ac);
    //for (auto i:ab) cout<< i <<endl;
    //for (auto i:bc) cout<< i <<endl;
    //for (auto i:ac) cout<< i <<endl;
    int ans = 1000000;
    for (auto i :ab){
        for (auto j : ac){
            if (bcs.count(j-i)>0 || j-i<0 || j-i>=(int)a.size()){
                int left = min(i,min(j,0));
                int right = max((int)a.size(),max(i+(int)b.size(),j+(int)c.size()));
                ans = min(right-left,ans);
            }
        }
    }
    for (auto i :ab){
        for (auto j : bc){
            if (acs.count(j+i)>0|| j+i<0 || j+i>=(int)b.size()){
                int left = min(-i,min(j,0));
                int right = max(-i+(int)a.size(),max((int)b.size(),j+(int)c.size()));
                ans = min(right-left,ans);
            }
        }
    }
    for (auto i :ac){
        for (auto j : bc){
            if (abs.count(-j+i)>0|| -j+i<0 || -j+i>=(int)c.size()){
                int left = min(-i,min(-j,0));
                int right = max(-i+(int)a.size(),max(-j+(int)b.size(),(int)c.size()));
                ans = min(right-left,ans);
            }
        }
    }
    cout << ans+1 << endl;
}

Submission status: Runtime Error

Solution code:
import numpy as np

a = input()
b = input()
c = input()


dic = {"a" : 1, "b" : 2, "c" : 3, "d" : 4, "e" : 5, "f" : 6, 
 "g" : 7,
 "h" : 8,
 "i" : 9,
 "j" : 10,
 "k" : 11,
 "l" : 12,
 "m" : 13,
 "n" : 14,
 "o" : 15,
 "p" : 16,
 "q" : 17,
 "r" : 18,
 "s" : 19,
 "t" : 20,
 "u" : 21,
 "v" : 22,
 "w" : 23,
 "x" : 24,
 "y" : 25,
 "z" : 26,
 "?" : np.nan,
}


aa = []
for s in a:
    aa.append(dic[s])
aa = np.array(aa)

bb = []
for s in b:
    bb.append(dic[s])
bb = np.array(bb)

cc = []
for s in c:
    cc.append(dic[s])
cc = np.array(cc)


def comp(aa, bb):
    ma = min([len(aa), len(bb)])
    sames = []
    for k in range(ma):
        x = np.abs(aa[-k-1:] - bb[:k+1])
        if np.mean(np.isnan(x)) == 1:
            x = [0]
        a = np.nanmax(x)
        if np.isnan(a):
            a = 0
        if a == 0:
            same = k + 1
            sames.append(same)
    return sames

def comp_all(aa, bb, cc):
    sames_ab = comp(aa, bb)
    maxs = []
    for same_ab in sames_ab:
        ab = np.zeros(len(aa) + len(bb) - same_ab) + np.nan
        ab[:len(aa)] = aa
        ab2 = np.zeros(len(aa) + len(bb) - same_ab) + np.nan
        ab2[-len(bb):] = bb
        ind = (np.isnan(ab) * (ab2!=0)) == 1
        ab[ind] = ab2[ind]

        sames = comp(ab, cc)
        if len(sames) == 0:
            continue
        same_max = max(sames)
        ma = len(ab) + len(cc) - same_max
        maxs.append(ma)
    if len(maxs) == 0:
        return np.nan
    return min(maxs)

ans = int(np.nanmin([comp_all(aa, bb, cc),
comp_all(aa, cc,  bb),
comp_all(bb, aa, cc),
comp_all(bb, cc, aa),
comp_all(cc, aa, bb),
comp_all(cc, bb, aa)]))

print(ans)

Submission status: Runtime Error

Solution code:
import sys
a = sys.stdin.readline().strip()
b = sys.stdin.readline().strip()
c = sys.stdin.readline().strip()
def match(x, y):
    for i in range(len(x)):
        if x[i] != "?":
            if y[i] != "?":
                if x[i] != y[i]:
                    return False
    return True

def do(a,b,c):
    #print (a,b,c)
    res = ""
    # a b c
    for p in range(len(a)):
        if match(a[p:], b[:len(b)-p]):
            # merge the string
            res = a[:p]
            for j in range(len(b)-p):
                if a[j+p] != "?":
                    res += a[j+p]
                else:
                    res += b[j]
            res += b[-p:]
    if res == "":
        res = a+b
    #print(res)
    a = res[len(res)-len(b):]
    before = len(res)-len(b)
    b = c

    res = ""
    for p in range(len(a)):
        if match(a[p:], b[:len(b)-p]):
            # merge the string
            res = a[:p]
            for j in range(len(b)-p):
                if a[j+p] != "?":
                    res += a[j+p]
                else:
                    res += b[j]
            res += b[-p:]
    if res == "":
        res = a + b
    
    return len(res) + before

tests = []
tests.append(do(a,b,c))
tests.append(do(a,c,b))
tests.append(do(b,a, c))
tests.append(do(b,c, a))
tests.append(do(c, b, a))
tests.append(do(c, a, b))
print(min(tests))

Submission status: Runtime Error

Solution code:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()

string solve_sub(const string &a, const string &b)
{
	int n = a.size();
	int m = b.size();
	int x = n;
	REP(i, n){
		int l = min(n - i, m);
		bool ok = true;
		REP(j, l){
			if(a[i + j] != b[j] && a[i + j] != '?' && b[j] != '?'){
				ok = false;
				break;
			}
		}
		if(ok){
			x = i;
			break;
		}
	}
	// cerr << x << endl;
	string c(max(n, m + x), '?');
	REP(i, max(n, m + x)){
		int j = i - x;
		if(j < 0) c[i] = a[i];
		else if(i < n && j < m) c[i] = a[i] != '?' ? a[i] : b[j];
		else if(i < n) c[i] = a[i];
		else c[i] = b[j];
	}
	return c;
}

int solve(const string &a, const string &b, const string &c)
{
	string d = solve_sub(a, b);
	string e = solve_sub(d, c);
	// cerr << d << endl;
	// cerr << e << endl;
	return e.size();
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string a, b, c;
	cin >> a >> b >> c;

	int ret = 1e9;

	ret = min(ret, solve(a, b, c));
	ret = min(ret, solve(a, c, b));
	ret = min(ret, solve(b, a, c));
	ret = min(ret, solve(b, c, a));
	ret = min(ret, solve(c, a, b));
	ret = min(ret, solve(c, b, a));

	cout << ret << endl;

	return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np

a = input()
b = input()
c = input()


dic = {"a" : 1, "b" : 2, "c" : 3, "d" : 4, "e" : 5, "f" : 6, 
 "g" : 7,
 "h" : 8,
 "i" : 9,
 "j" : 10,
 "k" : 11,
 "l" : 12,
 "m" : 13,
 "n" : 14,
 "o" : 15,
 "p" : 16,
 "q" : 17,
 "r" : 18,
 "s" : 19,
 "t" : 20,
 "u" : 21,
 "v" : 22,
 "w" : 23,
 "x" : 24,
 "y" : 25,
 "z" : 26,
 "?" : np.nan,
}


aa = []
for s in a:
    aa.append(dic[s])
aa = np.array(aa)

bb = []
for s in b:
    bb.append(dic[s])
bb = np.array(bb)

cc = []
for s in c:
    cc.append(dic[s])
cc = np.array(cc)


def comp(aa, bb):
    ma = min([len(aa), len(bb)])
    sames = []
    for k in range(ma):
        a = np.nanmax(np.abs(aa[-k-1:] - bb[:k+1]))
        if np.isnan(a):
            a = 0
        if a == 0:
            same = k + 1
            sames.append(same)
    return sames

def comp_all(aa, bb, cc):
    sames_ab = comp(aa, bb)
    maxs = []
    for same_ab in sames_ab:
        ab = np.zeros(len(aa) + len(bb) - same_ab) + np.nan
        ab[:len(aa)] = aa
        ab2 = np.zeros(len(aa) + len(bb) - same_ab) + np.nan
        ab2[-len(bb):] = bb
        ind = (np.isnan(ab) * (ab2!=0)) == 1
        ab[ind] = ab2[ind]

        sames = comp(ab, cc)
        if len(sames) == 0:
            continue
        same_max = max(sames)
        ma = len(ab) + len(cc) - same_max
        maxs.append(ma)
    if len(maxs) == 0:
        return np.nan
    return min(maxs)

ans = int(np.nanmin([comp_all(aa, bb, cc),
comp_all(aa, cc,  bb),
comp_all(bb, aa, cc),
comp_all(bb, cc, aa),
comp_all(cc, aa, bb),
comp_all(cc, bb, aa)]))

print(ans)

Submission status: Runtime Error

Solution code:
a =input()
b=input()
c=input()
if a==b or b==c or c==a:
  print(len(a))
else:
  	k=(3*len(a))-2)

Submission status: Runtime Error

Solution code:
a=input()
b=input()
c=input()
l=len(a)+len(b)+len(c)

def hatena_equal(p,q):
    F=1
    for i in range(len(p)):
        if not(p[i]==q[i] or p[i]=='?' or q[i]=='?'):
            F=0
    return F

def gattai(x,y):
    mm=min(len(x),len(y))
    score=0
    for i in range(mm):
        xx=x[i:]
        yy=y[:mm-i]
        if hatena_equal(xx,yy):
            score=len(xx)
            break
    return score

ABC=l-gattai(a,b)-gattai(b,c)
ACB=l-gattai(a,c)-gattai(c,b)
BAC=l-gattai(b,a)-gattai(a,c)
BCA=l-gattai(b,c)-gattai(c,a)
CAB=l-gattai(c,a)-gattai(a,b)
CBA=l-gattai(c,b)-gattai(b,a)

print(min([ABC,ACB,BAC,BCA,CAB,CBA]))

Submission status: Runtime Error

Solution code:
a = input()
b = input()
c = input()


def match(a, b):
    for i in range(len(a)):
        if a[i] == '?' or b[i] == '?':
            pass
        elif a[i] == b[i]:
            pass
        else:
            return False
    return True


def diff_match(a, b, d):
    aa = a[d:]
    bb = b[:len(aa)]
    return match(aa, bb)


def check(a, b, c):
    ans = 10 ** 9
    la, lb, lc = len(a), len(b), len(c)
    for db in range(0, la + lc + 1):
        for dc in range(0, la + lb + 1):
            if not diff_match(a, b, db):
                continue
            if not diff_match(a, c, dc):
                continue
            if db < dc:
                if not diff_match(b, c, dc - db):
                    continue
            else:
                if not diff_match(c, b, db - dc):
                    continue
            ans = min(ans, max(max(la, db + lb), max(la, dc + lc)))
    return ans


ans = min(
    check(a, b, c),
    check(a, c, b),
    check(b, a, c),
    check(b, c, a),
    check(c, a, b),
    check(c, b, a),
)
print(ans)

Submission status: Runtime Error

Solution code:
a,b,c = input(),input(),input()
ma = len(a)+len(b)+len(c)
m = ma
def check1(i,j,l):
  f = 0
  for n in range(l):
    if i[len(i)-l+n] != j[n] and i[len(i)-l+n] != '?' and j[n] != '?':
      f = 1
      break
  if f == 0:
    return True
  else:
    return False
def check2(i,j,k,o):
  f = 0
  for n in range(o):
    if j[len(j)-o+n] != k[n]:
      if k[n] == '?':
        continue
      elif j[len(j)-o+n] == '?':
        try:
          if i[len(i)-l+len(j)-o+n] == k[n] or i[len(i)-l+len(j)-o+n] == '?':
            continue
          else:
            f = 1
            break
        except:
          continue
      else:
        f = 1
        break
  if f == 0:
    return True
  else:
    return False
for i,j,k in [[a,b,c],[a,c,b],[b,a,c],[b,c,a],[c,a,b],[c,b,a]]:
  for o in range(len(k),-1,-1):
    if ma-m >= o:
      break
    for l in range(len(j),-1,-1):
      if ma-m >= l+o:
        break
      if check1(i,j,l):
        if check2(i,j,k,o):
          m = min(m,ma-l-o)
          break
print(m)

Submission status: Runtime Error

Solution code:
from itertools import permutations
import collections
abc = [input() for i in range(3)]


ans = 10000

for x in permutations(range(3)):
    a = abc[x[0]]
    b = abc[x[1]]
    c = abc[x[2]]

    id = 0
    ab = len(a)
    bc = len(b)
    for i in range(len(a)):
        if a[i] == b[0] or a[i] == "?" or b[0] == "?":
            count = 1
            for j in range(1, min(len(a) - i, len(b))):
                if a[i+j] == b[j] or a[i+j] == "?" or b[j] == "?":
                    count += 1
                else:
                    break
            if count + i == len(a):
                ab = i
                break
            elif count == len(b):
                ab = -1
                break
            else:
                continue
    if ab >= 0:
        for i in range(len(b)):
            if b[i] == c[0] or b[i] == "?" or c[0] == "?":
                count = 1
                for j in range(1, min(len(a) - i, len(c))):
                    if b[i+j] == c[j] or b[i+j] == "?" or c[j] == "?":
                        count += 1
                    else:
                        break
                if count + i == len(b):
                    bc = i
                    break
                elif count == len(b):
                    bc = -1
                    break
                else:
                    continue
    else:
        for i in range(len(a)):
            if a[i] == c[0] or a[i] == "?" or c[0] == "?":
                count = 1
                for j in range(1, min(len(a) - i, len(c))):
                    if a[i+j] == c[j] or a[i+j] == "?" or c[j] == "?":
                        count += 1
                    else:
                        break
                if count + i == len(a):
                    bc = i
                    break
                elif count == len(c):
                    bc = -1
                    break
                else:
                    continue
    tmp = 0
    if ab >= 0 and bc >= 0:
        tmp = ab + bc + len(c)
    elif ab >= 0 and bc < 0:
        tmp = len(b) + ab
    elif ab < 0 and bc >= 0:
        tmp = bc + len(c)
    else:
        tmp = len(a)
    ans = min(ans, tmp)

print(ans)