 # Getting WA in BENDSP2

Solution: 48778150 | CodeChef why is this WA’ing?? It calculates number of odd and even terms and straight away adds it to total odd and even value, pls guide

Can the sum overflow?

It might, still getting WA Solution: 48778444 | CodeChef

After so long time, found some test case where your code fails.

Input:

``````5
9 10 1 4 10
8
2
2
1 2 2 1
3
3
3
1 5 5 5
3
``````

Expected Output:

``````20
20
15
15
15
15
``````

``````20
20
14
14
14
14
``````

CPP Code
``````#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int t=1,n,a,odd=0,even=0,q,l,r,x,terms;
//  cin >> t;
while (t--){
cin >> n;
for (int i = 1; i <= n;i++){
cin >> a;
if (i & 1){
odd += a;
}
else {
even += a;
}
}
cin >> q;
for (int i = 0; i < q; i++){
cin >> a;
if (a==1){
cin >> l >> r >> x;
if (((l&1)==0) && ((r&1)==0)){
terms = (r-l+1);
even += (((terms/2)+1)*x);
odd += ((terms/2)*x);
}
else if ((l&1) && (r&1)) {
terms = (r-l+1);
odd += (((terms/2)+1)*x);
even += ((terms/2)*x);
}
else {
terms = (r-l+1);
odd += ((terms/2)*x);
even += ((terms/2)*x);
}
}
else if (a==2){
cout << odd << "\n";
}
else {
cout << even << "\n";
}
}
}
return 0;
}

``````

Lots of thanks!!! Why was my WA’ing, Solution: 48780493 | CodeChef this was the corrected code for the test case you submitted, what have you changed to AC’ify my code other than changing if’s to else if’s and else’s, or is that it.