Close Tuples (hard version)

Problem Name:
Close Tuples (hard version)
Site:CodeForces
Links:
Tags:
Problem setters: