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.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;

namespace E
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Replace('?', '.');
            var b = Console.ReadLine().Replace('?', '.');
            var c = Console.ReadLine().Replace('?', '.');
            var abc = merge(merge(a, b), c).Length;
            var acb = merge(merge(a, c), b).Length;
            var bac = merge(merge(b, a), c).Length;
            var bca = merge(merge(b, c), a).Length;
            var cab = merge(merge(c, a), b).Length;
            var cba = merge(merge(c, b), a).Length;
            Console.WriteLine(Math.Min(Math.Min(Math.Min(abc, acb), Math.Min(bca, bac)), Math.Min(cab, cba)));
        }

        static string merge(string a, string b)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(a, b)) return a;
            if (System.Text.RegularExpressions.Regex.IsMatch(b, a)) return b;

            int start = Math.Max(a.Length - b.Length, 0);
            bool Check = false;
            for (; start < a.Length; start++)
            {
                Check = true;
                for (int c = 0; c < Math.Min(b.Length, a.Length - start); c++)
                {
                    if (a[start + c] != b[c] && a[start + c] != '.' && b[c] != '.')
                    {
                        Check = false;
                        break;
                    }
                }
                if (Check) break;
            }
            if (!Check) return a + b;
            return a + b.Substring(a.Length - start);
        }
    }
}