Yet Another Counting Problem

CodeForces - 1342C