import Data. List
import Data. Function
( predmeti
',birki' ) = unzip $ head $ soljushen sgruppirovaniePredmeti birki
sgruppirovaniePredmeti
= groupBy
( ( == ) `on` sort
) $ sortBy
( compare `on` sort
) $ words predmeti
soljushen _ [ ] = [ [ ] ]
soljushen gruppi birki = [ ( birka, predmet) :solushn |
( levo
, ( predmet:gruppa
) :pravo
) <- zip ( inits gruppi
) ( tails gruppi
) , sort predmet == sort birka,
solushn <- soljushen ( levo++ gruppa:pravo) ( birki\\birka) ]
aW1wb3J0IERhdGEuTGlzdAppbXBvcnQgRGF0YS5GdW5jdGlvbgoKbWFpbiA9IGZtYXAgbGluZXMgZ2V0Q29udGVudHMgPj49IFxbcHJlZG1ldGksYmlya2ldIC0+IGxldAoJKHByZWRtZXRpJyxiaXJraScpID0gdW56aXAgJCBoZWFkICQgc29sanVzaGVuIHNncnVwcGlyb3ZhbmllUHJlZG1ldGkgYmlya2kKCXNncnVwcGlyb3ZhbmllUHJlZG1ldGkgPSBncm91cEJ5ICgoPT0pIGBvbmAgc29ydCkgJCBzb3J0QnkgKGNvbXBhcmUgYG9uYCBzb3J0KSAkIHdvcmRzIHByZWRtZXRpCglpbiBtYXBNXyAocHV0U3RyTG4gLiB1bndvcmRzKSBbcHJlZG1ldGknLGJpcmtpJ10KCQpzb2xqdXNoZW4gXyBbXSA9IFtbXV0Kc29sanVzaGVuIGdydXBwaSBiaXJraSA9IFsoYmlya2EscHJlZG1ldCk6c29sdXNobiB8IAoJKGxldm8sKHByZWRtZXQ6Z3J1cHBhKTpwcmF2bykgPC0gemlwIChpbml0cyBncnVwcGkpICh0YWlscyBncnVwcGkpLAoJbGV0IGJpcmthID0gemlwV2l0aCBjb25zdCBiaXJraSBwcmVkbWV0LAoJc29ydCBwcmVkbWV0ID09IHNvcnQgYmlya2EsCglzb2x1c2huIDwtIHNvbGp1c2hlbiAobGV2bysrZ3J1cHBhOnByYXZvKSAoYmlya2lcXGJpcmthKV0=
stdin
YWJjYWJjIGFiYyBiYyBhYmMgYWJjYWJjIGFiYyBiYyBhYmMgYWJjYWJjIGFiYyBiYyBhYmMgYWJjYWJjIGFiYyBiYyBhYmMgYWJjYWJjIGFiYyBiYyBhYmMKYWJjYWJjYWJjYmNhYmNhYmNhYmNhYmNiY2FiY2FiY2FiY2FiY2JjYWJjYWJjYWJjYWJjYmNhYmNhYmNhYmNhYmNiY2FiYw==
abcabc abc bc abc abcabc abc bc abc abcabc abc bc abc abcabc abc bc abc abcabc abc bc abc
abcabcabcbcabcabcabcabcbcabcabcabcabcbcabcabcabcabcbcabcabcabcabcbcabc