import Data.List.Split
sep s
= concat $ map sepBr
(splitOn
" " s
) where sepBr "" = []
sepBr " " = []
sepBr word
| a `
elem` brackets
= [[a
]] ++ sepBr bc
| c `
elem` brackets
= sepBr ab
++ [[c
]] where a
= if word
== [] then [] else head word
b
= if word
== [] then [] else init $ tail word
c
= if word
== [] then [] else last word
ab = [a] ++ b
bc = b ++ [c]
brackets = ['(', ')']
main = do
aW1wb3J0IERhdGEuQ2hhcgppbXBvcnQgRGF0YS5MaXN0LlNwbGl0CmltcG9ydCBEYXRhLk1heWJlCmltcG9ydCBUZXh0LlJlYWQKCgpzZXAgOjogU3RyaW5nIC0+IFtTdHJpbmddCnNlcCBzID0gY29uY2F0ICQgbWFwIHNlcEJyIChzcGxpdE9uICIgIiBzKSB3aGVyZQogICAgc2VwQnIgOjogU3RyaW5nIC0+IFtTdHJpbmddCiAgICBzZXBCciAiIiAgPSBbXQogICAgc2VwQnIgIiAiID0gW10KICAgIHNlcEJyIHdvcmQKICAgICAgICB8IGEgYGVsZW1gIGJyYWNrZXRzID0gW1thXV0gKysgc2VwQnIgYmMKICAgICAgICB8IGMgYGVsZW1gIGJyYWNrZXRzID0gc2VwQnIgYWIgKysgW1tjXV0KICAgICAgICB8IG90aGVyd2lzZSAgICAgICAgID0gKFthIDogYmNdKQogICAgICAgIHdoZXJlIGEgICAgICAgID0gaWYgd29yZCA9PSBbXSB0aGVuIFtdIGVsc2UgaGVhZCB3b3JkCiAgICAgICAgICAgICAgYiAgICAgICAgPSBpZiB3b3JkID09IFtdIHRoZW4gW10gZWxzZSBpbml0ICQgdGFpbCB3b3JkCiAgICAgICAgICAgICAgYyAgICAgICAgPSBpZiB3b3JkID09IFtdIHRoZW4gW10gZWxzZSBsYXN0IHdvcmQKICAgICAgICAgICAgICBhYiAgICAgICA9IFthXSArKyBiCiAgICAgICAgICAgICAgYmMgICAgICAgPSBiICsrIFtjXQogICAgICAgICAgICAgIGJyYWNrZXRzID0gWycoJywgJyknXQoKbWFpbiA6OiBJTygpCm1haW4gPSBkbwogICAgcHV0U3RyTG4gJCBzaG93ICQgc2VwICIoKyAxMiAoKiAzIDQgKCsgMSAyIDMpIDUpIDEpIg==