I am getting RTE with this code http://www.codechef.com/viewplaintext/3150374 I think there's something wrong with my implementation. I studied BIT from here : http://karthikpresumes.blogspot.in/2011/01/binary-indexed-tree.html
Problem link : Funny Marbles