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: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


a = S()
b = S()
c = S()
total_len = len(a) + len(b) + len(c)

def check(x, y):
    # xの後にy
    x_len = len(x)
    y_len = len(y)
    L = [0] * (x_len + 1)
    for y_start in range(x_len + 1):
        for j in range(y_len):
            if y_start + j < x_len and x[y_start + j] != y[j] and x[y_start + j] != '?' and y[j] != '?':
                break
        else:
            L[y_start] = 1
    return L


ans = total_len
for i, j, k in permutations((a, b, c)):
    ij_list = check(i, j)
    jk_list = check(j, k)
    ik_list = check(i, k)
    i_len = len(i)
    j_len = len(j)
    k_len = len(k)
    for ij_gap in range(len(i) + 1):
        for jk_gap in range(len(j) + 1):
            if ij_list[ij_gap] == 0 or jk_list[jk_gap] == 0:
                continue
            if ij_gap + jk_gap < i_len and ik_list[ij_gap + jk_gap] == 0:
                continue
            ans = min(ans, max(ij_gap + jk_gap + k_len, ij_gap + j_len, i_len))

print(ans)

Submission status: Wrong Answer

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

X=[a,b,c]
LEN=[len(a),len(b),len(c)]

MF=[[[0]*2001 for i in range(3)] for j in range(3)]

for i in range(3):
    for j in range(3):
        if i==j:
            continue
        for k in range(2001):
            for l in range(LEN[j]):
                if k+l>=LEN[i]:
                    MF[i][j][k]=1
                    break
                if X[i][k+l]!="?" and X[j][l]!="?" and X[i][k+l]!=X[j][l]:
                    break
            else:
                MF[i][j][k]=1

def mix_search(A,B,C,i,j):
    if mix_find(A,B,i)==1 and mix_find(B,C,j)==1:
        return 1
    return 0

ANS=1000000
for i in range(3):
    for j in range(3):
        if i==j:
            continue
        for k in range(2001):
            if MF[i][j][k]==1:
                for l in range(2001):
                    if ANS<=max(LEN[i],LEN[j]+k,LEN[3-i-j]+k+l):
                        break
                    if MF[j][3-i-j][l]==1:
                        ANS=max(LEN[i],LEN[j]+k,LEN[3-i-j]+k+l)

print(ANS)

Submission status: Wrong Answer

Solution code:
def th_char(s, n):
    if 0 <= n < len(s):
        return s[n]
    else:
        return '?'
def match(c, d):
    return len(set([c, d, '?'])) <= 2
a = input()
b = input()
c = input()
offset_max = max(len(a) + len(b), len(b) + len(c), len(c) + len(a))
def match_list(x, y, offset_max):
    res = [True] * (offset_max * 2 + 1)
    for i in range(-offset_max, offset_max + 1):
        for j in range(min(0, i), max(len(x), len(y) + i)):
            if not match(th_char(x, j), th_char(y, j + i)):
                res[i] = False
    return res
ab = match_list(a, b, offset_max)
bc = match_list(b, c, offset_max)
ca = match_list(c, a, offset_max)
ans = 10000
for b_offset in range(-offset_max, offset_max + 1):
    for c_offset in range(-offset_max, offset_max + 1):
        if ab[b_offset] and ca[-c_offset] and bc[c_offset - b_offset]:
            ans_cand = max(len(a), len(b) + b_offset, len(c) + c_offset) - min(0, b_offset, c_offset)
            if ans > ans_cand:
                ans = ans_cand
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


a = S()
b = S()
c = S()
total_len = len(a) + len(b) + len(c)

def check(x, y):
    # xの後にy
    x_len = len(x)
    y_len = len(y)
    L = [0] * (x_len + 1)
    for y_start in range(x_len + 1):
        for j in range(y_len):
            if y_start + j < x_len and x[y_start + j] != y[j] and x[y_start + j] != '?' and y[j] != '?':
                break
        else:
            L[y_start] = 1
    return L


ans = total_len
for i, j, k in permutations((a, b, c)):
    ij_list = check(i, j)
    jk_list = check(j, k)
    ik_list = check(i, k)
    i_len = len(i)
    j_len = len(j)
    k_len = len(k)
    for ij_gap in range(len(i) + 1):
        for jk_gap in range(len(j) + 1):
            if ij_list[ij_gap] == 0 or jk_list[jk_gap] == 0:
                continue
            if ij_gap + jk_gap < i_len and ik_list[i_len - ij_gap - jk_gap] == 0:
                continue
            ans = min(ans, max(ij_gap + jk_gap + k_len, ij_gap + j_len, i_len))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


a = S()
b = S()
c = S()
total_len = len(a) + len(b) + len(c)

def check(x, y):
    # xの後にy
    x_len = len(x)
    y_len = len(y)
    L = [0] * (x_len + 1)
    for y_start in range(x_len + 1):
        for j in range(y_len):
            if y_start + j >= x_len:
                continue
            elif x[y_start + j] != y[j] and x[y_start + j] != '?' and y[j] != '?':
                break
        else:
            L[y_start] = 1
    return L


ans = total_len
for i, j, k in permutations((a, b, c)):
    ij_list = check(i, j)
    jk_list = check(j, k)
    ik_list = check(i, k)
    i_len = len(i)
    j_len = len(j)
    k_len = len(k)
    for ij_gap in range(len(i) + 1):
        for jk_gap in range(len(j) + 1):
            if ij_list[ij_gap] == 0 or jk_list[jk_gap] == 0:
                continue
            if ij_gap + jk_gap < i_len and ik_list[i_len - ij_gap - jk_gap] == 0:
                continue
            ans = min(ans, max(ij_gap + jk_gap + k_len, ij_gap + j_len, i_len))

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


a = S()
b = S()
c = S()
total_len = len(a) + len(b) + len(c)

def check(x, y):
    # xの後にy
    x_len = len(x)
    y_len = len(y)
    L = [0] * (x_len + 1)
    for y_start in range(x_len + 1):
        for j in range(y_len):
            if y_start + j >= x_len:
                continue
            elif x[y_start + j] != y[j] and x[y_start + j] != '?' and y[j] != '?':
                break
        else:
            L[y_start] = 1
    return L


ans = total_len
for i, j, k in permutations((a, b, c)):
    ij_list = check(i, j)
    jk_list = check(j, k)
    ik_list = check(i, k)
    i_len = len(i)
    j_len = len(j)
    k_len = len(k)
    for ij_gap in range(len(i) + 1):
        for jk_gap in range(len(j) + 1):
            if ij_list[ij_gap] == 0 or jk_list[jk_gap] == 0:
                continue
            if ij_gap + jk_gap - j_len > 0 and ik_list[ij_gap + jk_gap - j_len] == 0:
                continue
            ans = min(ans, max(ij_gap + jk_gap + k_len, ij_gap + j_len, i_len))

print(ans)

Submission status: Wrong Answer

Solution code:
a = input()
b = input()
c = input()
 
def common(s1, s2):
	l1 = len(s1)
	l2 = len(s2)
	memo = [[0 for i in range(l1+2)] for j in range(l2+2)]
 
	for idx1,w1 in enumerate(s1):
		for idx2,w2 in enumerate(s2):
			if w1==w2 or w1=='?'or w2=='?':
				memo[idx2+1][idx1+1] = memo[idx2][idx1] + 1
 
	return memo
m1 = 0
m2 = 0
m3 = 0
for l in common(a,b):
	if max(l)>m1:
		m1 = max(l)
for l in common(a,c):
	if max(l)>m2:
		m2 = max(l)
for l in common(b,c):
	if max(l)>m3:
		m3 = max(l)
ans=len(a)+len(b)+len(c)-m1-m2-m3+min([m1,m2,m3])
 
print(ans)

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
c=input()
d=a+b+c
s=[i for i in d]
s1=set(s)
if a==b and c=='?'*len(a):
 print(len(s1)-1)
else:
    print(len(s1))

Submission status: Wrong Answer

Solution code:
K=4000
R=range
y=min
l=len
S=[input()for i in R(3)]
A,B,C=S
def F(S,T):
 Q=[1]*(K*2+1)
 for i in R(-l(T),l(S)):
  for j in R(max(i,0),y(l(S),l(T)+i)):
   if l(set([S[j],T[j-i],'?']))>2:Q[i]=0
 return Q
S=F(A,B)
T=F(A,C)
U=F(B,C)
m=K*3
k=R(-K,K+1)
for p in k:
 if S[p]!=0:
  for q in k:
   if T[q]!=0 and U[q-p]!=0:m=y(m,max(p+l(A),q+l(C),l(A))-y(p,q,0))
print(m)

Submission status: Wrong Answer

Solution code:
#!python3

import itertools

import numpy as np


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


def judge_array(x, y):
    l = [None] * 2001
    for i in range(2001):
        s = x[i:]
        t = y[:2001 - i]
        l[i] = np.all(np.where((s == t) | (s == 0) | (t == 0), True, False))
    return l


def main():
    an, bn, cn = len(a), len(b), len(c)
    n = [an, bn, cn]
    d = {chr(ord('a') + i - 1): i for i in range(1, 27)}
    d['?'] = 0
    abc = np.full((3, 2001), np.zeros(2001))
    for i in range(2000):
        if i < an:
            abc[0][i] = d[a[i]]
        if i < bn:
            abc[1][i] = d[b[i]]
        if i < cn:
            abc[2][i] = d[c[i]]

    w = [[None] * 3, [None] * 3, [None] * 3]
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            w[i][j] = judge_array(abc[i], abc[j])
    
    l = itertools.permutations([0, 1, 2])
    ans = 6000
    for x, y, z in l:
        xy = w[x][y]
        xz = w[x][z]
        yz = w[y][z]
        for i in range(2001):
            for j in range(2001):
                if xy[i] and yz[j] and xz[min(2000, i + j)]:
                    ans = min(ans, i + j + n[z])
                    break
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from itertools import permutations

ABC = [input().rstrip(), input().rstrip(), input().rstrip()]

cache = [-1] * (3 * 3)


def canMatchShifted(index1, index2, shift):
    # Whether ABC[index1] can match with ABC[index2] shifted to the right by `shift`
    k = 3 * index1 + index2
    if cache[k] == -1:
        S1 = ABC[index1]
        S2 = ABC[index2]
        temp = [True] * (4003)
        for s in range(len(S1)):
            temp[s] = all(x == y or x == "?" or y == "?" for x, y in zip(S1[s:], S2))
        cache[k] = temp

    return cache[k][shift]


# Try all permutation orders of ABC
best = float("inf")
for a, b, c in permutations(range(3)):
    A = ABC[a]
    B = ABC[b]
    C = ABC[c]
    # Match A with `('?' * i) + B`
    for i in range(len(A) + 2):
        if not canMatchShifted(a, b, i):
            continue
        # Match B with `('?' * j) + C`
        # Match A with `('?' * (i + j)) + C`
        for j in range(len(B) + 2):
            if canMatchShifted(b, c, j) and canMatchShifted(a, c, i + j):
                l = max(len(A), i + len(B), i + j + len(C))
                best = min(best, l)
print(best)

Submission status: Wrong Answer

Solution code:
from itertools import permutations

ABC = [input().rstrip(), input().rstrip(), input().rstrip()]

cache = [-1] * (3 * 3)


def canMatchShifted(index1, index2, shift):
    # Whether ABC[index1] can match with ABC[index2] shifted to the right by `shift`
    k = 3 * index1 + index2
    if cache[k] == -1:
        S1 = ABC[index1]
        S2 = ABC[index2]
        temp = [True] * (4001)
        for s in range(len(S1)):
            temp[s] = all(x == y or x == "?" or y == "?" for x, y in zip(S1[s:], S2))
        cache[k] = temp

    return cache[k][shift]


# Try all permutation orders of ABC
best = float("inf")
for a, b, c in permutations(range(3)):
    A = ABC[a]
    B = ABC[b]
    C = ABC[c]
    # Match A with `('?' * i) + B`
    for i in range(len(A) + 1):
        if not canMatchShifted(a, b, i):
            continue
        # Match B with `('?' * j) + C`
        # Match A with `('?' * (i + j)) + C`
        for j in range(len(B) + 1):
            if canMatchShifted(b, c, j) and canMatchShifted(a, c, i + j):
                l = max(len(A), i + len(B), i + j + len(C))
                best = min(best, l)
print(best)

Submission status: Wrong Answer

Solution code:
from itertools import permutations

ABC = [input().rstrip(), input().rstrip(), input().rstrip()]

cache = {}


def canMatchShifted(index1, index2, shift):
    # Whether ABC[index1] can match with ABC[index2] shifted to the right by `shift`
    k = (index1, index2)
    if k not in cache:
        S1 = ABC[index1]
        S2 = ABC[index2]
        temp = [True] * (4001)
        for s in range(len(S1)):
            temp[s] = all(x == y or x == "?" or y == "?" for x, y in zip(S1[s:], S2))
        cache[k] = temp

    return cache[k][shift]


# Try all permutation orders of ABC
best = float("inf")
for a, b, c in permutations(range(3)):
    A = ABC[a]
    B = ABC[b]
    C = ABC[c]
    # Match A with `('?' * i) + B`
    for i in range(len(A) + 1):
        if not canMatchShifted(a, b, i):
            continue
        # Match B with `('?' * j) + C`
        # Match A with `('?' * (i + j)) + C`
        for j in range(len(B) + 1):
            if canMatchShifted(b, c, j) and canMatchShifted(a, c, i + j):
                l = max(len(A), i + len(B), i + j + len(C))
                best = min(best, l)
print(best)

Submission status: Wrong Answer

Solution code:
from itertools import permutations


cache = {}


def canMatchShifted(S1, S2, shift):
    # Whether S1 can match with S2 shifted to the right by `shift`
    k = (id(S1), id(S2), shift)
    if k not in cache:
        canMatch = True
        for x, y in zip(S1[shift:], S2):
            if x != "?" and y != "?" and x != y:
                canMatch = False
                break
        cache[k] = canMatch

    return cache[k]


A = input().rstrip()
B = input().rstrip()
C = input().rstrip()
# Try all permutation orders of ABC
best = len(A) + len(B) + len(C)
for A, B, C in permutations([A, B, C]):
    # Match A with `('?' * i) + B`
    for i in range(len(A) + 1):
        if not canMatchShifted(A, B, i):
            continue
        # Match B with `('?' * j) + C`
        # Match A with `('?' * (i + j)) + C`
        for j in range(len(B) + 1):
            if canMatchShifted(B, C, j) and canMatchShifted(A, C, i + j):
                l = max(len(A), i + len(B), i + j + len(C))
                best = min(best, l)
print(best)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


A = list(input())
B = list(input())
C = list(input())


def compare(arr1, arr2):
    for x, y in zip(arr1, arr2):
        if x == y or x == '?' or y == '?':
            continue
        return False

    return True


CONST = 2005
ans = len(A) + len(B) + len(C)

for A, B, C in itertools.permutations([A, B, C]):

    A_to_B = [True] * CONST
    B_to_C = [True] * CONST
    A_to_C = [True] * (CONST * 2)

    lenA = len(A)
    lenB = len(B)
    lenC = len(C)

    for i in range(lenA+1):
        A_to_B[i] = compare(A[i:], B)

    for i in range(lenB+1):
        B_to_C[i] = compare(B[i:], C)

    for i in range(lenA+1):
        A_to_C[i] = compare(A[i:], C)

    for i in range(lenA+1):
        for j in range(lenB+1):
            if A_to_B[i] and B_to_C[j] and A_to_C[i + j]:
                right = max(lenA, i + lenB, i + j + lenC)
                ans = min(ans, right)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


A = list(input())
B = list(input())
C = list(input())


def compare(arr1, arr2):
    for x, y in zip(arr1, arr2):
        if x == y or x == '?' or y == '?':
            continue
        return False

    return True


CONST = 2005
ans = len(A) + len(B) + len(C)

for A, B, C in itertools.permutations([A, B, C]):

    A_to_B = [True] * CONST
    B_to_C = [True] * CONST
    A_to_C = [True] * (CONST * 2)

    lenA = len(A)
    lenB = len(B)
    lenC = len(C)

    for i in range(lenA):
        A_to_B[i] = compare(A[i:], B)

    for i in range(lenB):
        B_to_C[i] = compare(B[i:], C)

    for i in range(lenA):
        A_to_C[i] = compare(A[i:], C)

    for i in range(lenA):
        for j in range(lenB):
            if A_to_B[i] and B_to_C[j] and A_to_C[i + j]:
                right = max(lenA, i + lenB, i + j + lenC)
                ans = min(ans, right)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import itertools
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


A = list(input())
B = list(input())
C = list(input())

N = len(A)


def compare(arr1, arr2):
    for x, y in zip(arr1, arr2):
        if x == y or x == '?' or y == '?':
            continue
        return False

    return True


CONST = 2005
ans = N * 3

for A, B, C in itertools.permutations([A, B, C]):

    A_to_B = [True] * CONST
    B_to_C = [True] * CONST
    A_to_C = [True] * (CONST * 2)

    lenA = len(A)
    lenB = len(B)
    lenC = len(C)

    for i in range(lenA):
        A_to_B[i] = compare(A[i:], B)

    for i in range(lenB):
        B_to_C[i] = compare(B[i:], C)

    for i in range(lenA):
        A_to_C[i] = compare(A[i:], C)

    for i in range(lenA):
        for j in range(lenB):
            if A_to_B[i] and B_to_C[j] and A_to_C[i + j]:
                right = max(lenA, i + lenB, i + j + lenC)
                ans = min(ans, right)

print(ans)

Submission status: Wrong Answer

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

# 文字のマッチング(?はワイルドカード)
def match(a, b):
    return a=="?" or b=="?" or a==b

ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか？
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか？
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか？

def check(a, b, ab):
    for i in range(len(a)):
        for j in range(len(b)):
            if not match(a[i], b[j]):
                ab[i-j+50000] = False

check(a, b, ab)
check(a, c, ac)
check(b, c, bc)

len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)

ans = len_a + len_b + len_c

# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
    # j = CをAに対していくつスライドして置くか
    for j in range(-2 * len_max, 2 * len_max + 1):
        if ab[i+50000] and ac[j+50000] and bc[j-i+50000]:
            ans = min(ans, min(0, i, j) - max(len_a, len_b+i, len_c+j))

print(ans)

Submission status: Wrong Answer

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

# 二つの文字列の場合を考える。
# 二つの文字列を生み出せるような最小の文字列を求める関数。
# print(a,b,c)

#文字列sとtが等しいか判定する関数。(?込)
def equal(s,t):
    #sとtは同じ長さ。
    l = len(s)
    for i in range(l):
        if s[i] != t[i] and s[i] != "?" and t[i] != "?":
            return False
            break
    return True
    
def merge(s,t):
    #sとtは同じ長さ。
    u = ""
    l = len(s)
    for i in range(l):
        if s[i] == "?":
            if t[i] == "?":
                u += "?"
            else:
                u += t[i]
        else:
            u += s[i]
    return u


def sub_2(a0,b0):
    Y0 = []
    # a>=bとする。
    if len(a0) >= len(b0):
        a,b=a0,b0
    else:
        a,b=b0,a0
    
    # aがbを含む場合。
    for i in range(len(a)-len(b)+1):
        # print(a[i:i+len(b)])
        if equal(a[i:i+len(b)],b):
            # print(a,b,[a[:i] + merge(a[i:i+len(b)],b) + a[i+len(b):]])
            Y0.append(a[:i] + merge(a[i:i+len(b)],b) + a[i+len(b):])
    
    # aの右がbの左と重なる場合。
    for i in range(len(b)-1):
        # print(a[-len(b)+i+1:],b[:-i-1])
        if equal(a[-len(b)+i+1:],b[:-i-1]):
            Y0.append(a[:-len(b)+i+1] + merge(a[-len(b)+i+1:],b[:-i-1]) + b[-i-1:])
            break
    
    # aの左がbの右と重なる場合。
    for i in range(len(b)-1):
        # print(b[i+1:],a[:len(b)-i-1])
        if equal(b[i+1:],a[:len(b)-i-1]):
            Y0.append(b[:i+1] + merge(b[i+1:],a[:len(b)-i-1]) + a[len(b)-i-1:])
            break
    
    if not Y0:
        return [a+b,b+a]
    else:
        return Y0


Y = []
for i in sub_2(a,b):
    # print(i,c,1)
    for j in sub_2(i,c):
        # print(j)
        Y.append(len(j))
for i in sub_2(b,c):
    # print(i,a,2)
    for j in sub_2(i,a):
        Y.append(len(j))
        # print(j)
for i in sub_2(c,a):
    # print(i,b,3)
    for j in sub_2(i,b):
        Y.append(len(j))
        # print(j)

# print(Y)
print(min(Y))

Submission status: Wrong Answer

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

# 二つの文字列の場合を考える。
# 二つの文字列を生み出せるような最小の文字列を求める関数。
# print(a,b,c)

#文字列sとtが等しいか判定する関数。(?込)
def equal(s,t):
    #sとtは同じ長さ。
    l = len(s)
    for i in range(l):
        if s[i] != t[i] and s[i] != "?" and t[i] != "?":
            return False
            break
    return True
    
def merge(s,t):
    #sとtは同じ長さ。
    u = ""
    l = len(s)
    for i in range(l):
        if s[i] == "?":
            if t[i] == "?":
                u += "?"
            else:
                u += t[i]
        else:
            u += s[i]
    return u


def sub_2(a0,b0):
    Y0 = []
    # a>=bとする。
    if len(a0) >= len(b0):
        a,b=a0,b0
    else:
        a,b=b0,a0
    
    # aがbを含む場合。
    for i in range(len(a)-len(b)+1):
        # print(a[i:i+len(b)])
        if equal(a[i:i+len(b)],b):
            return [a[:i] + merge(a[i:i+len(b)],b) + a[i+len(b):]]
            break
    
    # aの右がbの左と重なる場合。
    for i in range(len(b)-1):
        # print(a[-len(b)+i+1:],b[:-i-1])
        if equal(a[-len(b)+i+1:],b[:-i-1]):
            Y0.append(a[:-len(b)+i+1] + merge(a[-len(b)+i+1:],b[:-i-1]) + b[-i-1:])
            break
    
    # aの左がbの右と重なる場合。
    for i in range(len(b)-1):
        # print(b[i+1:],a[:len(b)-i-1])
        if equal(b[i+1:],a[:len(b)-i-1]):
            Y0.append(b[:i+1] + merge(b[i+1:],a[:len(b)-i-1]) + a[len(b)-i-1:])
            break
    
    if not Y0:
        return [a+b,b+a]
    else:
        return Y0


Y = []
for i in sub_2(a,b):
    for j in sub_2(i,c):
        # print(j)
        Y.append(len(j))
for i in sub_2(b,c):
    for j in sub_2(i,a):
        Y.append(len(j))
for i in sub_2(c,a):
    for j in sub_2(i,b):
        Y.append(len(j))

# print(Y)
print(min(Y))

Submission status: Wrong Answer

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

# 二つの文字列の場合を考える。
# 二つの文字列を生み出せるような最小の文字列を求める関数。
# print(a,b,c)

#文字列sとtが等しいか判定する関数。(?込)
def equal(s,t):
    #sとtは同じ長さ。
    l = len(s)
    for i in range(l):
        if s[i] != t[i] and s[i] != "?" and t[i] != "?":
            return False
            break
    return True
    
def merge(s,t):
    #sとtは同じ長さ。
    u = ""
    l = len(s)
    for i in range(l):
        if s[i] == "?":
            if t[i] == "?":
                u += "?"
            else:
                u += t[i]
        else:
            u += s[i]
    return u


def sub_2(a0,b0):
    Y0 = []
    # a>=bとする。
    if len(a0) >= len(b0):
        a,b=a0,b0
    else:
        a,b=b0,a0
    
    # aがbを含む場合。
    for i in range(len(a)-len(b)+1):
        # print(a[i:i+len(b)])
        if equal(a[i:i+len(b)],b):
            return [a]
            break
    
    # aの右がbの左と重なる場合。
    for i in range(len(b)-1):
        # print(a[-len(b)+i+1:],b[:-i-1])
        if equal(a[-len(b)+i+1:],b[:-i-1]):
            Y0.append(a[:-len(b)+i+1] + merge(a[-len(b)+i+1:],b[:-i-1]) + b[-i-1:])
            break
    
    # aの左がbの右と重なる場合。
    for i in range(len(b)-1):
        # print(b[i+1:],a[:len(b)-i-1])
        if equal(b[i+1:],a[:len(b)-i-1]):
            Y0.append(b[:i+1] + merge(b[i+1:],a[:len(b)-i-1]) + a[len(b)-i-1:])
            break
    
    if not Y0:
        return [a+b,b+a]
    else:
        return Y0


Y = []
for i in sub_2(a,b):
    for j in sub_2(i,c):
        # print(j)
        Y.append(len(j))
for i in sub_2(b,c):
    for j in sub_2(i,a):
        Y.append(len(j))
for i in sub_2(c,a):
    for j in sub_2(i,b):
        Y.append(len(j))

# print(Y)
print(min(Y))

Submission status: Wrong Answer

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

# 二つの文字列の場合を考える。
# 二つの文字列を生み出せるような最小の文字列を求める関数。
# print(a,b,c)

#文字列sとtが等しいか判定する関数。(?込)
def equal(s,t):
    #sとtは同じ長さ。
    l = len(s)
    for i in range(l):
        if s[i] != t[i] and s[i] != "?" and t[i] != "?":
            return False
            break
    return True

def sub_2(a0,b0):
    
    Y0 = []
    
    # a>=bとする。
    if len(a0) >= len(b0):
        a,b=a0,b0
    else:
        a,b=b0,a0
    
    # aがbを含む場合。
    for i in range(len(a)-len(b)+1):
        # print(a[i:i+len(b)])
        if equal(a[i:i+len(b)],b):
            return [a]
            break
    
    # aの右がbの左と重なる場合。
    for i in range(len(b)-1):
        # print(a[-len(b)+i+1:],b[:-i-1])
        if equal(a[-len(b)+i+1:],b[:-i-1]):
            Y0.append(a+b[-i-1:])
            break
    
    # aの左がbの右と重なる場合。
    for i in range(len(b)-1):
        # print(b[i+1:],a[:len(b)-i-1])
        if equal(b[i+1:],a[:len(b)-i-1]):
            Y0.append(b+a[len(b)-i-1:])
            break
    
    if not Y0:
        return [a+b,b+a]
    else:
        return Y0

Y = []
for i in sub_2(a,b):
    for j in sub_2(i,c):
        Y.append(len(j))
for i in sub_2(b,c):
    for j in sub_2(i,a):
        Y.append(len(j))
for i in sub_2(c,a):
    for j in sub_2(i,b):
        Y.append(len(j))

# print(Y)
print(min(Y))

Submission status: Wrong Answer

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

# 二つの文字列の場合を考える。
# 二つの文字列を生み出せるような最小の文字列を求める関数。
# print(a,b,c)

def sub_2(a0,b0):
    
    Y0 = []
    
    # a>=bとする。
    if len(a0) >= len(b0):
        a,b=a0,b0
    else:
        a,b=b0,a0
    
    # aがbを含む場合。
    for i in range(len(a)-len(b)+1):
        # print(a[i:i+len(b)])
        if a[i:i+len(b)] == b:
            return [a]
            break
    
    # aの右がbの左と重なる場合。
    for i in range(len(b)-1):
        # print(a[-len(b)+i+1:],b[:-i-1])
        if a[-len(b)+i+1:] == b[:-i-1]:
            Y0.append(a+b[-i-1:])
            break
    
    # aの左がbの右と重なる場合。
    for i in range(len(b)-1):
        # print(b[i+1:],a[:len(b)-i-1])
        if b[i+1:] == a[:len(b)-i-1]:
            Y0.append(b+a[len(b)-i-1:])
            break
    
    if not Y0:
        return [a+b,b+a]
    else:
        return Y0

Y = []
for i in sub_2(a,b):
    for j in sub_2(i,c):
        Y.append(len(j))
for i in sub_2(b,c):
    for j in sub_2(i,a):
        Y.append(len(j))
for i in sub_2(c,a):
    for j in sub_2(i,b):
        Y.append(len(j))

# print(Y)
print(min(Y))

Submission status: Wrong Answer

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

# 二つの文字列の場合を考える。
# 二つの文字列を生み出せるような最小の文字列を求める関数。
# print(a,b,c)

def sub_2(a0,b0):
    # a>=bとする。
    if len(a0) >= len(b0):
        a,b=a0,b0
    else:
        a,b=b0,a0
    
    # aがbを含む場合。
    for i in range(len(a)-len(b)+1):
        # print(a[i:i+len(b)])
        if a[i:i+len(b)] == b:
            return a
            break
    
    # aの右がbの左と重なる場合。
    for i in range(len(b)-1):
        # print(a[-len(b)+i+1:],b[:-i-1])
        if a[-len(b)+i+1:] == b[:-i-1]:
            return a+b[-i-1:]
            break
    
    # aの左がbの右と重なる場合。
    for i in range(len(b)-1):
        # print(b[i+1:],a[:len(b)-i-1])
        if b[i+1:] == a[:len(b)-i-1]:
            return b+a[len(b)-i-1:]
            break
    
    return a+b
  
Y = [] 
Y.append(len(sub_2(sub_2(a,b),c)))
Y.append(len(sub_2(sub_2(b,c),a)))
Y.append(len(sub_2(sub_2(c,a),b)))
print(min(Y))