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 Rust (1.15.1) (judge verdict: Runtime Error)

//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

#[macro_use]
mod input {

    use std;
    use std::io;

    const SPLIT_DELIMITER: char = ' ';

    #[macro_export]
    #[allow(unused_macros)]
    macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

    #[allow(dead_code)]
    pub fn input_line_str() -> String {
        let mut s = String::new();
        io::stdin().read_line(&mut s).unwrap();
        s.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn p<T>(t: T)
    where
        T: std::fmt::Display,
    {
        println!("{}", t);
    }

    #[allow(dead_code)]
    pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<Vec<T>> = Vec::new();

        for _ in 0..line {
            let vec_line = input_vector();
            v.push(vec_line);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector<T>() -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v: Vec<T> = Vec::new();

        let s = input_line_str();
        let split_result = s.split(SPLIT_DELIMITER);
        for z in split_result {
            let buf = match z.parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    #[allow(dead_code)]
    pub fn input_vector_row<T>(n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
    {
        let mut v = Vec::with_capacity(n);
        for _ in 0..n {
            let buf = match input_line_str().parse() {
                Ok(r) => r,
                Err(_) => panic!("Parse Error"),
            };
            v.push(buf);
        }
        v
    }

    pub trait ToCharVec {
        fn to_charvec(&self) -> Vec<char>;
    }

    impl ToCharVec for String {
        fn to_charvec(&self) -> Vec<char> {
            self.to_string().chars().collect::<Vec<_>>()
        }
    }
}

use input::*;

fn func(a: &Vec<char>, b: &Vec<char>, c: &Vec<char>) -> usize {
    let mut res = a.clone();

    let mut idx = res.len();
    for i in 0..res.len() {
        if res[i] == b[0] || res[i] == '?' || b[0] == '?' {
            let mut flag = true;
            for j in i + 1..std::cmp::min(res.len(), b.len() + i + 1) {
                if res[j] != b[j - i] && res[j] != '?' && b[j - i] != '?' {
                    flag = false;
                }
                if !flag {
                    break;
                }
            }
            if flag {
                idx = i;
            }
        }
        if idx != res.len() {
            break;
        }
    }

    let mut idx2 = 0;

    while idx2 < b.len() {
        if idx == res.len() {
            res.push(b[idx2]);
        } else {
            res[idx] = if res[idx] == '?' { b[idx2] } else { res[idx] }
        }
        idx += 1;
        idx2 += 1;
    }

    let mut idx = res.len();
    for i in 0..res.len() {
        if res[i] == c[0] || res[i] == '?' || c[0] == '?' {
            let mut flag = true;
            for j in i + 1..std::cmp::min(res.len(), c.len() + i + 1) {
                if res[j] != c[j - i] && res[j] != '?' && c[j - i] != '?' {
                    flag = false;
                }
                if !flag {
                    break;
                }
            }
            if flag {
                idx = i;
            }
        }
        if idx != res.len() {
            break;
        }
    }

    let mut idx2 = 0;

    while idx2 < c.len() {
        if idx == res.len() {
            res.push(c[idx2]);
        } else {
            res[idx] = if res[idx] == '?' { c[idx2] } else { res[idx] }
        }
        idx += 1;
        idx2 += 1;
    }

    res.len()
}

fn main() {
    let a = input_line_str().to_charvec();
    let b = input_line_str().to_charvec();
    let c = input_line_str().to_charvec();

    let mut ans = 999999999_usize;
    ans = std::cmp::min(ans, func(&a, &b, &c));
    ans = std::cmp::min(ans, func(&a, &c, &b));
    ans = std::cmp::min(ans, func(&b, &a, &c));
    ans = std::cmp::min(ans, func(&b, &c, &a));
    ans = std::cmp::min(ans, func(&c, &b, &a));
    ans = std::cmp::min(ans, func(&c, &a, &b));
    println!("{}", ans);
}