i checked for indivitual case how to solve this getting WA
Problem: https://www.spoj.com/problems/CPTTRN2/ My Solution : https://ideone.com/cbe2pk
You do realise there will be more test cases, with different values, than those shown in the problem statement?
Try this:
1 5 5