"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var ans;
var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var a = next(1).split("");
  var b = next(1).split("");
  var c = next(1).split("");
  ans = a.length+b.length+c.length;
  solve1(a,b,c);
  solve1(a,c,b);
  solve1(b,a,c);
  solve1(b,c,a);
  solve1(c,a,b);
  solve1(c,b,a);
  return ans;
}

function solve1(a,b,c){
  var al = a.length;
  for(var i = 0; i < al; i++){
    var t = a.concat(), flag = 1;
    for(var j = 0; j < b.length && flag; j++){
      var x = i+j;
      if(x >= al)t.push(b[j]);
      else{
        if(a[x] === "?")t[x] = b[j];
        else if(b[j] !== "?" && a[x] !== b[j])flag = 0;
      }
    }
    if(flag)solve2(t,c);
  }
}

function solve2(a,b){
  var al = a.length, bl = b.length;
  for(var i = 0; i <= al; i++){
    if(Math.max(al, i+bl) >= ans)return;
    var flag = 1;
    for(var j = 0; j < bl && i+j < al && flag; j++){
      if(a[i+j] === "?" || b[j] === "?")continue;
      if(a[i+j] !== b[j])flag = 0;
    }
    if(flag)return ans = Math.max(al, i+bl);
  }
}