Powering the Hero (hard version)

Problem Name:
Powering the Hero (hard version)
Site:CodeForces
Links:
Tags:
Problem setters: