Again Counting Arrays (Hard Version)

Problem Name:
Again Counting Arrays (Hard Version)
Site:CodeForces
Links:
Tags:
Problem setters: