fix task D in Codeforces round 221 - there was a bug in avl implementation, changed it to nicer, functional avl implementation