#[allow(unused_imports)]
use std::char::from_digit;
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::fs::File;
#[allow(unused_imports)]
use std::io::prelude::*;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufReader, BufWriter, Stdin, Stdout, Write};
#[allow(unused_imports)]
use std::mem::swap;
#[allow(unused_imports)]
use std::str::FromStr;

type BoxResult<T> = Result<T, Box<std::error::Error>>;


fn main() {
    let mut scanner = Scanner::new(stdin());
    let a = scanner.read_chars().unwrap();
    let b = scanner.read_chars().unwrap();
    let c = scanner.read_chars().unwrap();
    let ans = solve(&a, &b, &c);
    println!("{}", ans);
}

fn solve(a: &[char], b: &[char], c: &[char]) -> usize {
    let b_against_a = calc_matching(a, b);
    let c_against_a = calc_matching(a, c);
    let c_against_b = calc_matching(b, c);

    let mut minimum = std::usize::MAX;
    let offset = b.len() + c.len();
    for i in 0..(a.len() + b.len() + 2 * c.len() + 1) {
        if i + b.len() >= offset && i + b.len() - offset < a.len() + b.len() && !b_against_a[i + b.len() - offset] {
            continue;
        }
        for j in 0..(a.len() + 2 * b.len() + c.len() + 1) {
            if j + c.len() >= offset && j + c.len() - offset < a.len() + c.len() && !c_against_a[j + c.len() - offset] {
                continue;
            }
            if j + c.len() >= i && j + c.len() - i < b.len() + c.len() && !c_against_b[j + c.len() - i] {
                continue;
            }
            let s = min(offset, min(i, j));
            let e = max(offset + a.len() - 1, max(i + b.len() - 1, j + c.len() - 1));
            let length = e - s + 1;
            minimum = min(length, minimum);
        }
    }
    minimum
}

fn calc_matching(a: &[char], b: &[char]) -> Vec<bool> {
    let mut matched = vec![true; a.len() + b.len()];
    for i in 1..b.len() {
        for j in 0..min(i, a.len()) {
            if a[j] == '?' || b[b.len() - i + j] == '?' {
                continue;
            }
            if a[j] != b[b.len() - i + j] {
                matched[i] = false;
                break;
            }
        }
    }
    let offset = b.len();
    for i in 0..a.len() {
        for j in i..min(a.len(), i + b.len()) {
            if a[j] == '?' || b[j - i] == '?' {
                continue;
            }
            if a[j] != b[j - i] {
                matched[offset + i] = false;
                break;
            }
        }
    }
    matched
}


#[allow(dead_code)]
struct Scanner<R> {
    reader: BufReader<R>,
    buffer: String,
}
impl<R> Scanner<R>
where
    R: Read,
{
    #[allow(dead_code)]
    fn new(inner: R) -> Scanner<R> {
        let reader = BufReader::new(inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    #[allow(dead_code)]
    fn with_capacity(capacity: usize, inner: R) -> Scanner<R> {
        let reader = BufReader::with_capacity(capacity, inner);
        let buffer = String::new();
        Scanner {
            reader: reader,
            buffer: buffer,
        }
    }
    #[allow(dead_code)]
    fn read_line(&mut self) -> BoxResult<String> {
        self.reader.read_line(&mut self.buffer)?;
        let cloned = self.buffer.trim().to_string();
        self.buffer.clear();
        Ok(cloned)
    }
    #[allow(dead_code)]
    fn read<T>(&mut self) -> BoxResult<T>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed = self.buffer.trim().parse()?;
        self.buffer.clear();
        Ok(parsed)
    }
    #[allow(dead_code)]
    fn read_vector<T>(&mut self) -> BoxResult<Vec<T>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        self.reader.read_line(&mut self.buffer)?;
        let parsed_vec = self
            .buffer
            .trim()
            .split_whitespace()
            .map(|s| s.parse())
            .collect::<Result<Vec<_>, _>>()?;
        self.buffer.clear();
        Ok(parsed_vec)
    }
    #[allow(dead_code)]
    fn read_matrix<T>(&mut self, lines: usize) -> BoxResult<Vec<Vec<T>>>
    where
        T: FromStr,
        T::Err: std::fmt::Debug,
        T::Err: std::error::Error,
        T::Err: 'static,
    {
        let mut parsed_matrix = vec![];
        for _ in 0..lines {
            self.reader.read_line(&mut self.buffer)?;
            parsed_matrix.push(
                self.buffer
                    .trim()
                    .split_whitespace()
                    .map(|s| s.parse())
                    .collect::<Result<Vec<_>, _>>()?,
            );
            self.buffer.clear();
        }
        Ok(parsed_matrix)
    }
    #[allow(dead_code)]
    fn read_chars(&mut self) -> BoxResult<Vec<char>> {
        self.reader.read_line(&mut self.buffer)?;
        let chars = self.buffer.trim().chars().collect::<Vec<_>>();
        self.buffer.clear();
        Ok(chars)
    }
}


Measured memory_bytes: 4352