Febrary long Challenge 2019 - Chef and Magical Jars ( MAGICJAR)

I used STL inbuilt accumulate() function to get the solution of this problem and it gives me wrong answer but when I used the same logic but removed accummulate() and calculated the sum manually, my solution got passed. What’s wrong with accumulate() function?

Click here to go to the problem and here for the link to my solution.

using namespace std;

int main() {
int t;
    int n;
    unsigned long long a[n],b[n];
    for(int i=0;i<n;i++){
        b[i] = a[i] - 1;
    unsigned long long k = accumulate(b,b+n,1);
return 0;

Typecasting mistake -

unsigned long long k = accumulate(b,b+n,long(1));

@akil_avi17 Do I need it to type-cast it even if I used int instead of long long?
For eg. int b[] = {1,2,3,4};

yes you need. Your final answer is of type long long. So instead of int you need to typecast to long.