1 test case giving TLE

One test case is giving TLE, wrote this code with brute force approach. Is the code correct? and how should i optimize?

Code- https://ide.codingblocks.com/s/406835

Output Format
The answer mod 10^9+7
add this

I don’t get it?

cout<<len%(1e9)+7;

?