Help Bob problem

I am solving Help Bob problem but I am unable to find where i am going wrong.

my code

#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define endl “\n” // for fast input,output file
using namespace std;

int main() {
cin.tie(NULL); // these 3 lines for fast I/P method
ll int n,k;
ll int arr[n];
for(ll int i=0;i<n;i++) cin>>arr[i];

vector<ll int>temp(n);
for(ll int i=1;i<n;i++) temp[i]=arr[i]^arr[i-1];

ll int cnt=0;
for(ll int i=0;i<n;i++){
    if((temp[i]>>(k-1))&1) cnt++;
return 0;


I have also tried using 1LL.

This is my accepted solution.Take a look and you’ll find the error in your code.

using namespace std;

const int N = 1e6;
long arr[N];

int main() {

	int n, k;
	int ele = 0;
	for(int i = 0; i < n; i++) {
	long x = arr[0], a;
	for(int i = 1; i < n; i++) {
		a = arr[i];
		arr[i] ^= x;
		x = a;

// for(auto x: arr) cout<<x;

	for(int i = 0; i < n; i++) {
		if((arr[i] >> (k - 1)) & 1)


Now I modified my code and i just took vectorarr(n) instead of array.

And ,it works.
I want to know what’s the problem when I am taking array.

i have also did the same way first then it was WA : Solution: 42139031 | CodeChef
but again did without taking extra memory it get AC :slightly_smiling_face:
Solution: 42139855 | CodeChef

i dont think both are different but difference is only that in first i have taken extra array and calculated original array then finding the result but the idea of both solution is same

can you guys figure out what is wrong with first solution

You can see my solution .I have taken extra memory and got accepted.

Only difference is that first I have taken an array and then I changed it to vector.
Now, it is working fine.

So, I think there is a problem with array.
But know what it is.
Anyone Please explain it.
Thanks in advance.