/* package codechef; // don’t place package name! */
import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
static long mod = 1000000007;
static long mul(long a, long b,long mod)
{
long res = 0;
a = a % mod;
while (b > 0)
{
if (b % 2 == 1)
{
res = (res + a) % mod;
}
a = (a * 2) % mod;
b /= 2;
}
return res % mod;
}
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader b = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(b.readLine());
System.out.println(mul(0,1,mod));
while(t–!=0){
String[] in = b.readLine().split(" ");
long n = Long.parseLong(in[0]);
long k = Long.parseLong(in[1]);
long prev =0; // before reaching 1st time on k
if(n>1){
prev = mul(n-1,n,mod);
}
if(n==0){
System.out.println(mul(k,k-1,mod));
continue;
}
long first = 0; // first time on reaching n
if(k==1){
first=n;
}else{
first=mul(n,2,mod);
}
long next = 0;
k-=1; // k-1 times left
if(k==0){
System.out.println((prev+first)%mod);
continue;
}
if(k%2==0){
long steps = k/2;
next= (next+mul(n+steps+1,n+steps,mod)- mul(n,n+1,mod))%mod;
next= (next-n)%mod;
}else{
long steps = k/2;
next= (next+mul(n+steps+1,n+steps,mod)- mul(n,n+1,mod))%mod;
next= (next+n)%mod;
}
System.out.println((prev+first+next)%mod);
}
}
}
What is wrong with my solution ? Any tc ? Its giving WA.