here is my code
/*
Valences
submitted by
Arjun Mishra
*/
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
long long int A;
long long int compare[21];
void function()
{long long int i;
compare[0]=1;
for(i=1;i<=20;i++)
compare[i]=(long long int)pow(2,i);
}
int main()
{long long int N,i,a,sum=0;
function();
//for(i=0;i<=20;i++)
//cout<<compare[i]<<endl;
while(1)
{sum=0;
cin>>N;
if(N==0)
return 0;
for(i=0;i<=20;i++)
{
if(N>=compare[i]&&N<compare[i+1])
{a=compare[i];
//cout<<i<<endl;
break;}
}
//cout<<a<<endl;
for(i=1;i<=a-1;i++)
cin>>A;
for(i=a;i<=N;i++)
{cin>>A;
sum+=A;
//cout<<sum<<endl;
}
cout<<sum<<endl;
}
}
i don’t know why it is producing WA after 50s of execution