johnny and the bean stalk-whats wrong in the code??

#include <stdio.h>
#include <stdlib.h>

             int main()
                {
                   int t,j;
                 scanf("%d",&t);
                  for(j=0;j<t;j++)
                {
                    long long int n=0,b=0,flag=0,i=0,stem=0;
                       scanf("%lld",&n);
                    scanf("%lld",&b);
                    stem=1-b;

                    if(b>1)
                          flag==1;


        for(i=2;i<=n-1;i++)
        {
            scanf("%lld",&b);
            if(flag==0)
            {
            stem*=2;
            if(b<=stem) {stem=stem-b;} else {flag=1;};
            }
        }
        scanf("%lld",&b);
        if(flag==0)
        {
            if(b==(2*stem)) {printf("Yes\n");} else {printf("No\n");};
        }
        else if(flag!=0) {printf("No\n");};


}
return 0;

}