I have referred this editorial link for SEP14 CHEFLR problem.
I too used the same logic during test. I addition to this I have added the mod operation(mod=1000000007). At each level I have done this.
ans=ans%mod;
if(0==ans)
{
ans=mod.
}
Will this if
condition cause any problem ? I dint find this condition in other successful submission
At the end:
ans=ans%mod;
printf ("%d\n", ans);
But faced WA when submitting the solution.
The complete code is available here