Your mission, should you choose to accept it, is to add the minimum number of parentheses, braces, and brackets to make a given string (containing only parentheses, braces, and brackets) have correct brace matching. Ties of symbols added must be broken by having the maximum distance between paired braces. You must return only one correct answer that matches these two rules; Further ties, should they exist, may be broken any way you see fit.
Examples:
input output
// Empty String is a legal input
[ [] // Boring example
[()] [()] // Do nothing if there's nothing to be done
({{ ({{}}) // NOT (){}{} (0 + 0 + 0). Maximum distance is 4 + 2 + 0, ({{}})
[([{])]} {[([{}])]} // NOT [([])]{[([])]} or similar
You may write a program or function, receives the input via STDIN as a string argument to your function, which returns the output as a string or prints it to STDOUT (or closest alternative). You may optionally include a single trailing newline in the output.
You may assume the input string consists only of the following 6 characters (or lack thereof): [](){}
(You do not need to support <>
)
This is code-golf, shortest program wins. Standard loopholes are banned, of course.