Time limit
2s
Memory limit
128 MB
Music uses seven notes: C, D, E, F, G, A, and B. You are given three pieces of music. You may insert the rest symbol & at any positions in each piece, and after the insertions all three resulting strings must have the same length.
However, no single piece may contain two or more consecutive & symbols.
Look at the aligned pieces column by column from left to right. The score of one column is defined as follows.
& symbols does not score 1 point.Find the maximum total score obtainable by inserting & symbols into the three pieces. If it is impossible to make the three pieces have the same length while satisfying the rule above, output -1.
Three lines are given, one piece of music per line. Each piece consists only of the seven notes above, and its length is between 1 and 100 inclusive.
Print the maximum total score among all valid alignments on the first line. If no valid alignment exists, print -1.