Help me Solve "Weird Requirements" from ACM International Collegiate Programming Contest, Damascus University Collegiate Programming Contest(2018)

I’m trying to solve this problem of for last 2 days.But I didn’t get any clue. Then I read editorial. But cannot understand 3,4 and 5th number case. Please help me to solve this problem.

Thanks In advance.