SPOJ 4226: Binary Indexed Tree + optimisations