n=int(input()) a=[0]+list(map(int,input().split())) q=[(0,0)] for i in range(1,n+1): if a[i]!=-1: l=i-1 while a[l]==-1: l-=1 q+=[(a[i],i-l)] if any(q[i-1][0]&q[i][0]!=q[i-1][0] for i in range(1,len(q))): print(0) exit() M=10**9+7 fa=[1,1] fb=[1,1] for i in range(2,30+1): fa+=[fa[-1]*i%M] fb+=[fb[-1]*(M//i)*fb[M%i]*fa[M%i-1]*(-1)%M] c=lambda n,k:fa[n]*fb[k]*fb[n-k]%M if n>=k else 0 a=1 for i in range(1,len(q)): u,_=q[i-1] v,l=q[i] c1=(v^u).bit_count() c2=(v&u).bit_count() b=0 for j in range(c1+1): b+=c(c1,j)*pow(pow(2,c1-j+c2,M)-1,l,M)*((-1)**(j%2)) b%=M a*=b a%=M print(a)