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

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use io::*;
use std::*;

fn sub_x(a: &[u8], b: &[u8]) -> usize {
    for l in (1..=cmp::min(a.len(), b.len())).rev() {
        let lhs = &a[a.len() - l..];
        let rhs = &b[..l];
        if lhs
            .iter()
            .zip(rhs.iter())
            .all(|(&x, &y)| x == b'?' || y == b'?' || x == y)
        {
            return l;
        }
    }
    0
}

fn sub_y(a: &[u8], b: &[u8], c: &[u8]) -> usize {
    a.len() + b.len() + c.len() - sub_x(a, b) - sub_x(b, c)
}

fn solve(a: String, b: String, c: String) {
    let a = a.as_bytes();
    let b = b.as_bytes();
    let c = c.as_bytes();
    println!(
        "{}",
        [
            sub_y(a, b, c),
            sub_y(a, c, b),
            sub_y(b, a, c),
            sub_y(b, c, a),
            sub_y(c, a, b),
            sub_y(c, b, a)
        ]
        .iter()
        .cloned()
        .min()
        .unwrap()
    );
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut a: String;
    a = scanner.next();
    let mut b: String;
    b = scanner.next();
    let mut c: String;
    c = scanner.next();
    solve(a, b, c);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }
}
*/

fn main() {
    let exe = "/tmp/binCC54082C";
    std::io::Write::write_all(&mut std::fs::File::create(exe).unwrap(), &decode(BIN)).unwrap();
    std::fs::set_permissions(exe, std::os::unix::fs::PermissionsExt::from_mode(0o755)).unwrap();
    std::process::exit(std::process::Command::new(exe).status().unwrap().code().unwrap())
}

fn decode(v: &str) -> Vec<u8> {
    let mut ret = vec![];
    let mut buf = 0;
    let mut tbl = vec![64; 256];
    for i in 0..64 { tbl[TBL[i] as usize] = i as u8; }
    for (i, c) in v.bytes().filter_map(|c| { let c = tbl[c as usize]; if c < 64 { Some(c) } else { None } }).enumerate() {
        match i % 4 {
            0 => buf = c << 2,
            1 => { ret.push(buf | c >> 4); buf = c << 4; }
            2 => { ret.push(buf | c >> 2); buf = c << 6; }
            3 => ret.push(buf | c),
            _ => unreachable!(),
        }
    }
    ret
}

const TBL: &'static [u8] = b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const BIN: &'static str = "<base64-encoded ELF executable removed>";