will that make a significant change ?

what is fast IO ?

It will, yes.

āFast IOā. (Also, please google it)

```
#include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long int t;
const long long mod = 1000000007;
cin >>t;
while(t--) {
long long int n, q, r, sum, turns, extra, ans, oneat;
oneat = 0;
sum = 0;
cin >>n;
long long int a[n], b[n];
for (int i=1; i<n; i++) {
cin >>a[i];
sum += a[i]-a[i]%2;
sum = sum%mod;
b[i] = sum;
if (a[i]==1)
oneat = i;
}
cin >>a[0];
sum += a[0] - 1 + a[0]%2;
sum = sum%mod;
cin >>q;
if (oneat == 0) {
for (int i=0; i<q; i++) {
ans = 0;
cin >>r;
turns = r/n;
extra = r%n;
ans = (turns*sum)%mod;
if (extra-1 > 0)
ans += b[extra-1];
if (extra != 0)
ans += a[extra];
if (r%n==0 && a[r%n]%2==0)
ans += 1;
ans = ans%mod;
cout <<ans <<endl;
}
}
else if (oneat == 1) {
for (int i=0; i<q; i++) {
ans = 0;
cin >>r;
turns = r/n;
extra = r%n;
if (extra > 1)
ans += 1;
ans += turns;
if (turns==0 && extra==1)
ans += 1;
ans = ans%mod;
cout <<ans <<endl;
}
}
else {
for (int i=0; i<q; i++) {
ans = 0;
cin >>r;
turns = r/n;
extra = r%n;
ans = (sum*turns)%mod;
if (a[oneat-1]%2 == 0)
ans -= turns;
else
ans += turns;
if (extra-1 > 0)
ans += b[extra-1];
if (extra != 0)
ans += a[extra];
if (extra > oneat) {
if (a[oneat-1]%2 == 1)
ans += 1;
else
ans -= 1;
}
if (r%n==0 && a[r%n]%2==0)
ans += 1;
ans = ans%mod;
cout <<ans <<endl;
}
}
}
return 0;
}
```

This should get rid of the TLE.

Thanks Let me try, lets see

Thank You Very Much

I was stuck on this question from 6 days !!!

but I am still taking 0.9 seconds ? shouldnāt it be 0.3-0.5 sec at most

It depends. You can also use \n in place of endl for printing newline

Yes, use `\n`

instead of `endl`

. `endl`

is slower because it forces a flush, which actually unnecessary.

Yes now it is taking only 0.1 sec Thanks

Thank You Very Much

Finally its accepted !!!

Nice qsn

**Can someone please tell why i am getting WA for subtask 1ā¦ its giving right answer for every sample testcase mentioned in the editorial above and other combinations which comes into my mind too!**

**this code is for 15 points only**

the sample test cases donāt help much, try all possible combinations, check the video on youtube

its working for the sample testcases mentioned in the editorial above and other combinations which came into my mind too

Let me try, if I get something Iāll post it

Sorry I tried, but couldnāt find the problem, Its a hard question

Anyone please help me with this code, I checked my solution with all the cases and it is giving all correct answers as compared to the correct solution. Please tell me that, is the problem occuring due to mod or is due to any other edge test case.

https://www.codechef.com/viewsolution/39667278

As a beginner, this problem taught me to first understand the problem thoroughly and to only dive into coding when Iām absolutely sure of its implementation! A big thanks to the Admin!

Any test-case on which my code goes wrong (only for 15pts). It will be really helpful. Thank you

https://www.codechef.com/viewsolution/39674365

You are not missing any test case.

You just need to print the sum as cout<<sum%mod<<endl;

mod=1000000007

Then also first sub-task should pass but it gives WA

it showing correct now

Can anyone help me to find out my mistake .It will be really helpful. Pleaseā¦

https://www.codechef.com/viewsolution/39679731