#include<stdio.h>
#include<math.h>
long int A[100005];
long int sum;
int main(){
int t,n,i,j;
scanf("%d",&t);
while(t--){
sum=0;
scanf("%d",&n);
for(i=0;i<n+1;i++)
scanf("%ld",A+i);
for(i=0;i<=n;i++){
for(j=i+1;j<=n;j++){
if(i!=0){
sum=sum+(A[i]*A[j]*pow(2,n+i-j));
}
if(i==0)
sum=sum+(A[i]*A[j]*pow(2,n+1-j));
}
}
printf("%ld\n",sum);
}
}
It means that answer can be as large as {2}^{100000} . Since we cannot store such numbers in conventional data types, we take remainder of the number when divided by {10}^{9}+7. Read about properties of % operator. The multiplication and addition properties of it (i.e. (a+b)%m=(a%m+b%m)%m and a*b%m=((a%m)*(b%m))%m can prevent overflow issues. What we have to do is, that at every step, every time we update sum, we do sum%mod , where mod = {10}^{9}+7. It is just a random large number given to make sure you dont suffer overflow. Since we do sum%mod at every step, it never exceeds mod