Why this java solution is not getting accepted ?

I covered almost all the edge cases given in the problem statement and which I can think of but still I am getting “WA”.

Here is my solution in Java: CodeChef: Practical coding for everyone

Try out the test case

monday tuesday 16 16

I think your output will be many but output should be 16

Thank you. It worked. Feels so stupid that I missed such an obvious case.