generalize fenwick tree to general group