Multi-Bracket Validity with Minimum Fix Cost

VERY HARD · C · 5000ms

The freshmen's code now uses three different kinds of brackets, and half of it doesn't balance at all — Rina's editor must now report the minimum number of characters needed to fix it, not just yes/no. Read a string of '(', ')', '[', ']', '{', '}'. If it's already balanced print "VALID". Otherwise print the MINIMUM number of characters you must insert to make it balanced (insertions only, no deletions or substitutions allowed).

Input

One string S of the six bracket characters.

Output

"VALID" or an integer: minimum insertions needed.

Constraints

1 ≤ |S| ≤ 10^5

Sample Input

([)]

Sample Output

2
main.c
Loading editor…

Write C, then Run (custom I/O) or Submit (sample tests). ⌘/Ctrl+Enter submits.

Multi-Bracket Validity with Minimum Fix Cost · DIU ContestHub