atcoder#PANASONIC2020E. Three Substrings

Three Substrings

Score : 500500 points

Problem Statement

Snuke has a string ss. From this string, Anuke, Bnuke, and Cnuke obtained strings aa, bb, and cc, respectively, as follows:

  • Choose a non-empty (contiguous) substring of ss (possibly ss itself). Then, replace some characters (possibly all or none) in it with ?s.

For example, if ss is mississippi, we can choose the substring ssissip and replace its 11-st and 33-rd characters with ? to obtain ?s?ssip.

You are given the strings aa, bb, and cc. Find the minimum possible length of ss.

Constraints

  • 1a,b,c20001 \leq |a|, |b|, |c| \leq 2000
  • aa, bb, and cc consists of lowercase English letters and ?s.

Input

Input is given from Standard Input in the following format:

aa

bb

cc

Output

Print the minimum possible length of ss.

a?c
der
cod
7

For example, ss could be atcoder.

atcoder
atcoder
???????
7

aa, bb, and cc may not be distinct.