INOI 2019 interesting subsequences

It seems i am getting WA in lots of test cases so i think i may not have fully understood the problem. I dont understand why limit of L is 10^9.
It seems for any L above N should give the same value.
Can someone link their solution and explain it.
If you want to look at my code its here:CodeChef: Practical coding for everyone
Also maybe my approach or implementation is incorrect, idk.

There are quite a few corner cases in the problem, the solutions for which can be seen in my submitted solutions. My code is well commented.