# [Brain-Flak], <s>65, 50,</s> 36 bytes

    ([])({<{}>{<({}[()])>[]}{}<([])>}{})

[Try it online!][TIO-j5ycf6u0]

[Brain-Flak]: https://github.com/DJMcMayhem/Brain-Flak
[TIO-j5ycf6u0]: https://tio.run/##SypKzMzTTctJzP7/XyM6VlOj2qa61q7aRqO6NlpDM1bTLjq2trrWBiRlB2Ro/v9vqGCkYAwA "Brain-Flak – Try It Online"

After lots of revising, I'm now very proud of this answer. I like the algorithm, and how nicely it can be expressed in brain-flak.

Most of the byte count comes form handling 0's in the input. In fact, if we could assume there were no 0's in the input, it would be a beautifully short 20 byte answer:

    ({{<({}[()])>[]}{}})

[Try it online!](https://tio.run/##SypKzMzTTctJzP7/X6O62kajujZaQzNW0y46tra6tlbz/39DBSMFYwA "Brain-Flak – Try It Online")

But unfortunately, brain-flak is notorious for bad handling of edge cases.