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)

// This code is generated by [cargo-atcoder](https://github.com/tanakh/cargo-atcoder)
// Original source code:
/*
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn lcs(x: &Vec<char>, y: &Vec<char>) -> usize {
    let nx = x.len() as usize;
    // let ny = y.len() as usize;
    let mut result = 0;
    for i in 1..=nx {
        if (0..i).all(|j| y[j] == x[nx + j - i] || y[j] == '?' || x[nx + j - i] == '?') {
            result = i;
        }
    }
    result
}

fn main() {
    input! {
        s: [Chars; 3],
    }
    let mut q = vec![false; 3];
    for i in 0..3 {
        q[i] = s[i].iter().all(|&cj| cj == '?');
    }
    let mut q_count = 0;
    for i in 0..3 {
        if q[i] {
            q_count += 1;
        }
    }
    if q_count == 1 {
        if q[0] {
            println!(
                "{}",
                max(s[1].len() + s[2].len() - lcs(&s[1], &s[2]), s[0].len())
            );
        } else if q[1] {
            println!(
                "{}",
                max(s[0].len() + s[2].len() - lcs(&s[0], &s[2]), s[1].len())
            );
        } else {
            println!(
                "{}",
                max(s[0].len() + s[1].len() - lcs(&s[0], &s[1]), s[2].len())
            );
        }
    } else if q_count == 2 {
        println!("{}", max(max(s[0].len(), s[1].len()), s[2].len()));
    } else {
        let mut result = INF;
        for p in s.iter().permutations(3) {
            eprintln!("{:?}", p);
            eprintln!("{}", lcs(&p[0], &p[1]));
            eprintln!("{}", lcs(&p[1], &p[2]));
            let na = p[0].len();
            let nb = p[1].len();
            let nc = p[2].len();
            result = min(result, na + nb + nc - lcs(&p[0], &p[1]) - lcs(&p[1], &p[2]));
        }
        println!("{}", result);
    }
}
*/

fn main() {
    let exe = "/tmp/binD81E80B9";
    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>";