Now, discard the corrupted lines. The remaining lines are incomplete.

Incomplete lines don’t have any incorrect characters - instead, they’re missing some closing characters at the end of the line. To repair the navigation subsystem, you just need to figure out the sequence of closing characters that complete all open chunks in the line.

You can only use closing characters (), ], }, or >), and you must add them in the correct order so that only legal pairs are formed and all chunks end up closed.

In the example above, there are five incomplete lines:

Did you know that autocomplete tools also have contests? It’s true! The score is determined by considering the completion string character-by-character. Start with a total score of 0. Then, for each character, multiply the total score by 5 and then increase the total score by the point value given for the character in the following table:

So, the last completion string above - ])}> - would be scored as follows:

The five lines’ completion strings have total scores as follows:

Autocomplete tools are an odd bunch: the winner is found by sorting all of the scores and then taking the middle score. (There will always be an odd number of scores to consider.) In this example, the middle score is 288957 because there are the same number of scores smaller and larger than it.

Assignment

Find the completion string for each incomplete line, score the completion strings, and sort the scores. What is the middle score? Determine this in the following way:

Example

In this interactive session we assume the text files subsystem01.txt1 and subsystem02.txt`2 to be located in the current directory.

> score("subsystem01.txt")
288957
> score("subsystem02.txt")
1190420163