Felix6326727/beyond-accuracy-code-comprehension huggingface dataset:
n=int(input())
a=list(map(lambda x: int(x), input().split()))

idx=0
ans=0
sum_last=0

for i in a:
    if i!=0:
        break
    idx+=1

if idx==len(a):
    ans=2*idx-1
elif idx>0:
    ans=2*idx-1
    if a[idx]>0:
        sum_last=-1
    else:
        sum_last=1
else:
    sum_last=a[0]
    ans=0
    idx=1

for i in a[idx:]:
    sum_cur=sum_last+i
    if sum_cur*sum_last>=0:
        ans+=abs(sum_cur)+1
        if sum_last>0:
            sum_last=-1
        else:
            sum_last=1
    else:
        sum_last=sum_cur
print(ans)

# Example run
# Input:
-407
0
# Output:
1
# -*- coding: utf-8 -*-
n = int(input())
an = list(map(int, input().split()))

sum = an[0]
ans = 0
for i in range(1,n):
    if sum * (sum + an[i]) < 0:
        sum += an[i]
    else:
        if sum > 0:
            ans += abs(sum + an[i] + 1)
            sum = -1
        else:
            ans += abs(sum + an[i] - 1)
            sum = 1

ans1 = ans

sum = -an[0]
ans = an[0]
for i in range(1, n):
    if sum * (sum + an[i]) < 0:
        sum += an[i]
    else:
        if sum > 0:
            ans += abs(sum + an[i] + 1)
            sum = -1
        else:
            ans += abs(sum + an[i] - 1)
            sum = 1


print(min([ans1,ans]))


# Example run
# Input:
-525602
42329671
# Output:
0
n = int(input())
a = [int(i) for i in input().split()]

# a[0]の符号を正にするか負にするかの2択で
# 後は一意に決まる

_sum = 0
count = 0
out = 0
# a[0]の符号を正にする場合
for i in range(len(a)):
    if i % 2 == 1:  # a[i]までの和を負にする
        if _sum + a[i] >= 0:
            count += abs(_sum + a[i] - (-1))
            _sum = -1
        else:
            _sum += a[i]
    else:  # a[i]までの和を正にする
        if _sum + a[i] <= 0:
            count += abs(1 - (_sum + a[i]))
            _sum = 1
        else:
            _sum += a[i]
# print("count:{} sum:{}".format(count, _sum))
out = count
_sum = 0
count = 0
# a[0]の符号を負にする場合
for i in range(len(a)):
    if i % 2 == 0:  # a[i]までの和を負にする
        if _sum + a[i] >= 0:
            count += abs(_sum + a[i] - (-1))
            _sum = -1
        else:
            _sum += a[i]
    else:  # a[i]までの和を正にする
        if _sum + a[i] <= 0:
            count += abs(1 - (_sum + a[i]))
            _sum = 1
        else:
            _sum += a[i]
            # print("count:{} sum:{}".format(count, _sum))
print(min(out, count))


# Example run
# Input:
-1325982
57961
# Output:
0
n = int(input())
a = list(map(int,input().split()))
acc = [0]*n
acc[0] = a[0]
def solve():
  for i in range(1,n):
    acc[i] = a[i]+acc[i-1]
  oddans = 0
  odddiff = 0
  #simulation in case of odd is positive
  for i in range(n):
    if i%2 == 0 and (acc[i]+odddiff)<=0:
      oddans += abs(acc[i]+odddiff)+1
      odddiff += (abs(acc[i]+odddiff))+1
    elif i%2 != 0 and (acc[i]+odddiff)>=0:
      oddans += acc[i]+odddiff+1
      odddiff -= acc[i]+odddiff+1
  #neg
  evenans = 0
  evendiff = 0
  for i in range(n):
    if i%2 == 0 and (acc[i]+evendiff)>=0:
      evenans += (acc[i]+evendiff+1) 
      evendiff -= (acc[i]+evendiff+1)
    elif i%2 != 0 and (acc[i]+evendiff)<=0:
      evenans += (abs(acc[i]+evendiff)+1)
      evendiff += (abs(acc[i]+evendiff)+1)
  return min(evenans,oddans)
  
print(solve())
  

# Example run
# Input:
1
-1
# Output:
0
n = list(input().split())

A = list(map(int, input().split()))

# flg:True プラスの想定
def chk(A, flg):
    #print("-------")
    # 初期値
    x=0
    ans =0
    for a in A:
        # 今までの合計
        x += a
        
        # 想定と違ったら、1との差分を増減する
        if flg==True and x < 1:
            ans +=1-x
            # xは1に変える
            x=1
        elif flg == False and x> -1:
            ans += x+1
            x=-1
        #print(x)
        flg = not flg

    return(ans)
print(min(chk(A, True),chk(A, False)))

# Example run
# Input:
8u=^Atb
3
# Output:
0
n = int(input())
a = list(map(int,input().split()))

ans = float('inf')
for _ in range(2):
    tmp = 0
    if _:
        if a[0] > 0:
            x = a[0]
        else:
            x = 1
            tmp = 1 - a[0]
    else:
        if a[0] < 0:
            x = a[0]
        else:
            x = -1
            tmp = 1 + a[0]
    for i in range(1, n):
        y = x + a[i]
        if x*y >= 0:
            if x > 0:
                tmp += y+1
                y -= y+1
            elif x < 0:
                tmp -= y-1
                y -= y-1
        x = y
    ans = min(ans, tmp)
print(ans)

# Example run
# Input:
-39
2569
# Output:
0
n=int(input())
l=list(map(int,input().split()))
if l[0]!=0:
    count=0
    suml=l[0]
    for i in range(1,n):
        if suml>0 and suml+l[i]<0:
            suml+=l[i]
            continue
        elif suml<0 and suml+l[i]>0:
            suml+=l[i]
            continue
        elif suml>0 and suml+l[i]>=0:
            count+=suml+l[i]+1
            suml=-1
        else:
            count+=-suml-l[i]+1
            suml=1
    print(count)
else:
    count=1
    suml1=1
    for i in range(1,n):
        if suml1>0 and suml1+l[i]<0:
            suml1+=l[i]
            continue
        elif suml1<0 and suml1+l[i]>0:
            suml1+=l[i]
            continue
        elif suml1>0 and suml1+l[i]>=0:
            count+=suml1+l[i]+1
            suml1=-1
        else:
            count+=-suml1-l[i]+1
            suml1=1
    k1=count
    count=1
    suml2=-1
    for i in range(1,n):
        if suml2>0 and suml2+l[i]<0:
            suml2+=l[i]
            continue
        elif suml2<0 and suml2+l[i]>0:
            suml2+=l[i]
            continue
        elif suml2>0 and suml2+l[i]>=0:
            count+=suml2+l[i]+1
            suml2=-1
        else:
            count+=-suml2-l[i]+1
            suml2=1
    k2=count
    print(min(k1,k2))
    

# Example run
# Input:
-27
230
# Output:
0
#!/usr/bin/env python3
import copy

n = int(input())
am = list(map(int, input().split()))

pcnt = 0
mcnt = 0

f = 0  #前の項の符号（1:+、2:-）
wa = 0

#最初の数字を正とするとき
a = copy.copy(am)
f = 2

for i in range(n):
    wa += a[i]

    if f == 1:#-にする必要あり
        if wa > -1:
            pcnt += wa + 1
            wa = -1
        
        f = 2

    elif f == 2:  #+にする必要あり

        if wa < 1:
            pcnt += -wa + 1
            wa = 1

        f = 1

#最初の数字を負とするとき
a = copy.copy(am)
wa = 0
f = 1

for i in range(n):
    wa += a[i]

    if f == 1:  # -にする必要あり
        if wa > -1:
            mcnt += wa + 1
            wa = -1

        f = 2

    elif f == 2:  # +にする必要あり

        if wa < 1:
            mcnt += -wa + 1
            wa = 1

        f = 1

print(min(pcnt, mcnt))


# Example run
# Input:
-31
224
# Output:
0
n = int(input())
a = list(map(int, input().split()))


def solve(tmp):
    ans = 0
    for i in range(1, n):
        if tmp * (tmp + a[i]) < 0:
            tmp += a[i]
        else:
            ans += abs(tmp + a[i]) + 1
            if tmp < 0:
                tmp = 1
            else:
                tmp = - 1
    return ans

minus = min(a[0], -1)
plus = max(a[0], 1)
ans = min(solve(plus) + abs(a[0] - plus), solve(minus) + abs(a[0] - minus))
print(ans)


# Example run
# Input:
-52564348
-7737
# Output:
0
n=int(input())
a=list(map(int,input().split()))
a1,a2,s=0,0,0
def cal(a,t):
    ans,x=0,0
    for i in a:
        x+=i
        if t and x<1:
            ans+=1-x
            x=1
        elif t==False and x>-1:
            ans+=x+1
            x=-1
        t=not t
    return ans
print(min(cal(a,True),cal(a,False)))

# Example run
# Input:
-4422
-15015728
# Output:
0
N = int(input())
A = [int(_n) for _n in input().split()]
res0 = 0
s = 0
for i, a in enumerate(A):
    s += a
    if i % 2 == 0 and s >= 0:
        res0 += s + 1
        s = -1
    elif i % 2 == 1 and s <= 0:
        res0 += -s + 1
        s = 1
res1 = 0
s = 0
for i, a in enumerate(A):
    s += a
    if i % 2 == 1 and s >= 0:
        res1 += s + 1
        s = -1
    elif i % 2 == 0 and s <= 0:
        res1 += -s + 1
        s = 1
print(min(res0,res1))

# Example run
# Input:
15753484
2563
# Output:
0
n = int(input())
l = list(map(int, input().split()))
ans_l = []
for j in range(2):
    last_sum = l[0]
    ans = 0
    if j == 0:
        if last_sum <= 0:
            ans += abs(1 - last_sum)
            last_sum += 1 - last_sum
    else:
        if last_sum >= 0:
            ans += abs(-1 - last_sum)
            last_sum += -1 - last_sum
    for i in range(n - 1):
        # print(last_sum)
        if last_sum > 0:
            if last_sum + l[i + 1] < 0:
                last_sum += l[i + 1]
            else:
                a = -1 - last_sum - l[i + 1]
                ans += abs(a)
                last_sum += a + l[i + 1]
        else:
            if last_sum + l[i + 1] > 0:
                last_sum += l[i + 1]
            else:
                a = 1 - last_sum - l[i + 1]
                ans += abs(a)
                last_sum += a + l[i + 1]
    ans_l.append(ans)
print(min(ans_l))

# Example run
# Input:
-7191
-3787895
# Output:
0
import sys

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    ans1 = 0 if a[0] > 0 else abs(a[0] - 1)
    v = a[0] if a[0] > 0 else 1

    for i in range(1, n):
        if v * (v + a[i]) < 0:
            v += a[i]
        else:
            if v > 0:
                ans1 += abs(v + a[i] + 1)
                v = -1
            else:
                ans1 += abs(v + a[i] - 1)
                v = 1

    ans2 = 0 if a[0] < 0 else abs(a[0] + 1)
    v = a[0] if a[0] < 0 else -1

    for i in range(1, n):
        if v * (v + a[i]) < 0:
            v += a[i]
        else:
            if v > 0:
                ans2 += abs(v + a[i] + 1)
                v = -1
            else:
                ans2 += abs(v + a[i] - 1)
                v = 1

    ans = min(ans1, ans2)

    print(ans)

if __name__ == '__main__':
    solve()

# Example run
# Input:
-1012372
692048
# Output:
0
def z(s,l):
	for i in range(n-1):
		r=l+a[i+1]
		if r*l>=0:
			if l<=0:
				s+=1-r
				r=1
			else:
				s+=1+r
				r=-1
		print(a[i+1],r,s)
		l=r
	return s
n=int(input())
a=list(map(int,input().split()))
s1=0
l1=a[0]
if a[0]<=0:
	s1=1-a[0]
	l1=1
s2=0
l2=a[0]
if a[0]>=0:
	s2=a[0]+1
	l2=-1
print(min(z(s1,l1),z(s2,l2)))

# Example run
# Input:
-88868
-156
# Output:
0
import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    n = int(input())
    a = list(map(int, input().split()))

    cumulative = 0
    count1 = 0
    for i in range(len(a)):
        cumulative += a[i]
        if i % 2 == 0: # positive
            if cumulative <= 0:
                count1 += abs(cumulative) + 1
                cumulative += (abs(cumulative) + 1)
        else:  # negative
            if cumulative >= 0:
                count1 += abs(cumulative) + 1
                cumulative -= (abs(cumulative) + 1)
        # print('count = {} c = {}'.format(count, cumulative))

    cumulative = 0
    count2 = 0
    for i in range(len(a)):
        cumulative += a[i]
        if i % 2 == 0: # negative
            if cumulative >= 0:
                count2 += abs(cumulative) + 1
                cumulative -= (abs(cumulative) + 1)
        else:  # positive
            if cumulative <= 0:
                count2 += abs(cumulative) + 1
                cumulative += (abs(cumulative) + 1)
        # print('count = {} c = {}'.format(count, cumulative))

    print(min(count1, count2))


if __name__ == '__main__':
    main()


# Example run
# Input:
-501810
-242313086
# Output:
0
N = int(input())
a = [int(x) for x in input().split()]
stim = [0]

even_cnt = 0
odd_cnt = 0
even_opr = 0
odd_opr = 0
for i in a:
    stim.append(stim[-1]+i)
stim = stim[1:]
for ind,x in enumerate(stim):
    if(ind%2==0):
        if(x+odd_opr>0):
            odd_cnt += abs(-1-(x+odd_opr))
            odd_opr += -1-(x+odd_opr)
        elif(x+odd_opr==0):
            odd_opr -= 1
            odd_cnt += 1
        if(x+even_opr<0):
            even_cnt += abs(1-(x+even_opr))
            even_opr += 1-(x+even_opr)
        elif(x+even_opr==0):
            even_opr += 1
            even_cnt += 1
    else:
        if(x+odd_opr<0):
            odd_cnt += abs(1-(x+odd_opr))
            odd_opr += 1-(x+odd_opr)
        elif(x+odd_opr==0):
            odd_opr += 1
            odd_cnt += 1
        if(x+even_opr>0):
            even_cnt += abs(-1-(x+even_opr))
            even_opr += -1-(x+even_opr)
        elif(x+even_opr==0):
            even_opr -= 1
            even_cnt += 1
print(min(even_cnt,odd_cnt))
        

# Example run
# Input:
0
-17760757
# Output:
0
n=int(input())
p=list(map(int,input().split()))
stack=[0]*(n+1)
ans=0
if p[0]==0:
  p[0]=1
  ans+=1
  stack[1]=1
else:
  stack[1]=p[0]
for i in range(1,n):
  if i%2==1:
    if p[i]+p[i-1]+stack[i-1]>=0:
      p[i]-=(p[i]+p[i-1]+stack[i-1])+1
      ans+=(p[i]+p[i-1]+stack[i-1])+1
  else:
    if p[i]+p[i-1]+stack[i-1]<=0:
      p[i]+=-(p[i]+p[i-1]+stack[i-1])+1
      ans+=-(p[i]+p[i-1]+stack[i-1])+1
  stack=p[i]+p[i-1]+stack[i-1]
print(ans)      

# Example run
# Input:
1
4887419
# Output:
0
# -*- coding: utf-8 -*-


def check(a_list :list, flg :int) -> int:
    # flg:  1 初項(奇数の項)の和が、正の数になるように操作する
    # flg: -1 　　　　〃　　　〃　　　　　、負の数になるように操作する

    count=0
    sum=0
    for num in a_list:
        sum_next = sum + num
        
        sum_next_p_m_sign = (sum_next>0) - (sum_next<0)
        
        sign_chck = flg * sum_next_p_m_sign

        if sign_chck == -1:
            # flgと符号が一致しなかった場合、+1 or -1まで操作
            diff = (abs(sum_next) + 1) * (-1)*sum_next_p_m_sign
            sum += num + diff
            count += abs(diff)
        
        elif sign_chck == 0:
            # sum_next=0の時
            diff = (1)*flg
            sum += num + diff
            count += abs(diff)
        
        else:
            sum = sum + num
 
        flg *= (-1)
    return count
        
#----------
n = int(input().strip())
a_list = list(map(int, input().rstrip().split()))
#----------
print( min(check(a_list, 1), check(a_list, -1)) )


# Example run
# Input:
142
-30
# Output:
0
inf = float('inf')

N = int(input())
A = list(map(int,input().split()))

def accmulate(arr):
    N = len(arr)
    cs = [0]*(N+1)
    for i in range(N):
        cs[i+1] = cs[i] + arr[i]
    return cs

# [l,r)
def query(cs, l, r):
    return cs[r] - cs[l]

cs = accmulate(A)[1:]
ans = inf

res = 0
tmp = 0
for i in range(len(cs)):
    if i % 2 == 0:
        # 負にする
        d = -1 - (cs[i] + tmp)
        d = min(d, 0)
        res += -d
        tmp += d
    else:
        # 正にする
        d = 1 - (cs[i] + tmp)
        d = max(d, 0)
        res += d
        tmp += d

ans = min(ans, res)

res = 0
tmp = 0
for i in range(len(cs)):
    if i % 2 == 1:
        # 負にする
        d = -1 - (cs[i] + tmp)
        d = min(d, 0)
        res += -d
        tmp += d
    else:
        # 正にする
        d = 1 - (cs[i] + tmp)
        d = max(d, 0)
        res += d
        tmp += d

ans = min(ans, res)
print(ans)

# Example run
# Input:
1973033
-264371717
# Output:
0
N = int(input())
A = list(map(int,input().split()))

def calc(A):
  ans = 0
  s = A[0]
  if s > 0:
    flag = 1
  elif s < 0:
    flag = -1
  for i in range(1,N):
    s += A[i]
    if flag == 1 and s >= 0:
      ans += s + 1
      s = -1
    elif flag == -1 and s <= 0:
      ans += 1 - s
      s = 1
    flag *= -1
  return ans

if A[0] != 0:
  print(calc(A))
else:
  print(min(calc([1]+A[1:]),calc([-1]+A[1:]))+1)


# Example run
# Input:
-1005
39756387
# Output:
0
n = int(input())
A = list(map(int,input().split()))
s = max(A[0],1)
cnt1 = abs(A[0]-s) #sを正にするまで
for a in A[1:]:
    if s>0:
        b=min(a, -s-1) #aを何の値にするかがb
    if s<0:
        b=max(a,-s+1)
    s += b #bを足してs更新
    cnt1 += abs(a-b)

s = min(A[0],-1)
cnt2 = abs(A[0]-s)
for a in A[1:]:
    if s>0:
         b=min(a, -s-1) #aを何の値にするかがb
    if s<0:
        b=max(a,-s+1)
    s += b #bを足してs更新
    cnt2 += abs(a-b)
print(min(cnt1,cnt2))

# Example run
# Input:
211
-6815
# Output:
0
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n = ii()
A = iil()

cum = 0
ope = 0
# first plus case
for i,item in enumerate(A):
    cum += item
    if i%2 == 0 and cum <= 0:
        ope += abs(cum)+1
        cum = 1
    elif i%2 == 1 and cum >= 0:
        ope += cum+1
        cum = -1
#    print(cum)
tmp = ope

cum = 0
ope = 0
# first minus case
for i,item in enumerate(A):
    cum += item
    if i%2 == 1 and cum <= 0:
        ope += abs(cum)+1
        cum = 1
    elif i%2 == 0 and cum >= 0:
        ope += cum+1
        cum = -1
#print(tmp,ope)
print(min(tmp,ope))

# Example run
# Input:
1947279
-4
# Output:
0
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))


def solve() -> Any:
    N = read_int()
    A = read_ints()
    min_moves = 10**18
    for positive in [False, True]:
        prefix = 0
        base = 0
        moves = 0
        for a in A:
            prefix += a
            if positive:
                if prefix+base <= 0:
                    moves += 1-(prefix+base)
                    base = 1-prefix
            else:
                if prefix+base >= 0:
                    moves += prefix+base+1
                    base = -1-prefix
            positive = not positive
        min_moves = min(min_moves, moves)
    return min_moves



if __name__ == '__main__':
    print(solve())


# Example run
# Input:
-81521
1267176863
# Output:
0
n=int(input())
count=0
A=[int(i) for i in input().split()]
if A[0]==0:
  A[0]+=1
  count+=1
elif A[0]<0:
  for i in range(len(A)):
    A[i]*=(-1)
for i in range(1,len(A)):
  s=sum(A[:i+1])
  if i%2==0:
    if s<=0:
      A[i]+=1-s
      count+=1-s
  else:
    if s>=0:
      A[i]-=1+s
      count+=1+s
print(count)

# Example run
# Input:
-84521052
-2
# Output:
0
n = int(input())
array = list(map(int, input().split()))

total = 0
flag = -1
minus = 0
for tmp in range(len(array)):
    total += array[tmp]
    if total * flag <= 0:
        minus += abs(total*flag)+1
        total = flag
    flag *= -1

total = 0
flag = 1
plus = 0
for tmp in range(len(array)):
    total += array[tmp]
    if total * flag <= 0:
        plus += abs(total*flag)+1
        total = flag
    flag *= -1

print(min(minus, plus))

# Example run
# Input:
139893
5182
# Output:
0
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
n = max(A).bit_length()
S = [0]*N
for i, a in enumerate(A):
    S[i]=S[i-1]^a
index = [[-1] for _ in range(2<<n)]
cumsum = [0]*(N+1)
for i, s in enumerate(S):
    index[s].append(i)
    cumsum[i] = cumsum[i-1]
    if s == 0:
        cumsum[i]+=1
ans = 0
if S[-1] == 0:
    for i in range(1, 1<<n):
        l = len(index[i])
        if l == 1:
            continue
        dp = [0]*(l-1)
        dp_cum = [0]*(l-1)
        for j, k in enumerate(index[i][1:]):
            dp[j] = (dp_cum[j-1]*(cumsum[k]-cumsum[index[i][j]])+1)%mod
            dp_cum[j] = (dp_cum[j-1]+dp[j])%mod
        ans+=dp_cum[-1]
        ans%=mod
    ans+=pow(2, cumsum[N-1]-1, mod)
    ans%=mod
else:
    l = len(index[S[-1]])
    dp = [0]*(l-1)
    dp_cum = [0]*(l-1)
    for j, k in enumerate(index[S[-1]][1:]):
        dp[j] = (dp_cum[j-1]*(cumsum[k]-cumsum[index[S[-1]][j]])+1)%mod
        dp_cum[j] = (dp_cum[j-1]+dp[j])%mod
    ans = dp[-1]%mod
print(ans)

        



# Example run
# Input:
367663
-13
# Output:
675665993
from collections import defaultdict
from bisect import bisect_left as bisect
import sys
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
zeros = []
count = defaultdict(list)
now = -1
for i in range(N):
    S[i] = S[i-1]^A[i]
    if S[i] == 0:
        zeros.append(i)
    else:
        count[S[i]].append(i)
if S[N-1] != 0:
    a = S[N-1]
    res = []
    for i in count[a]:
        res.append(bisect(zeros, i)-cnt)
        cnt+=res[-1]
    res0 = 1
    res1 = 0
    for c in res:
        res0 = res0+res1*c
        res1 = res1+res0
        res0%=mod
        res1%=mod
    print(res0)
    sys.exit()
ans = pow(2, len(zeros)-1, mod)
for a in count.keys():
    cnt = 0
    res = []
    for i in count[a]:
        res.append(bisect(zeros, i)-cnt)
        cnt+=res[-1]
    res0 = 1
    res1 = 0
    for c in res:
        res0 = res0+res1*c
        res1 = res1+res0
        res0%=mod
        res1%=mod
    ans+=res1
print(ans)   

# Example run
# Input:
0
0
# Output:
500000004
MOD = 10 ** 9 + 7

N = int(input())
a = list(map(int, input().split()))
ma = max(a)

cum_xor = [0] * (N + 1)
for i, aa in enumerate(a):
    cum_xor[i + 1] = cum_xor[i] ^ aa
# print(cum_xor)

d = [[] for _ in range(ma + 1)]

for i in range(0, ma + 1):
    tar = i
    cnt = 0
    for j in range(1, N + 1):
        if cum_xor[j] == tar:
            if cnt > 0:
                d[i].append(cnt)
                cnt = 0
            d[i].append(0)
            tar ^= i
        elif cum_xor[j] == (tar ^ i):
            cnt += 1
if cnt > 0:
    d[i].append(cnt)
    cnt = 0


def rec(cur):
    if cur < 0: return 0
    if cur == 0:
        return 1
    mul = 1
    # print(kkk, cur)
    if d[kkk][cur] > 0:
        mul = (d[kkk][cur] + 1)
        
    if mm[cur]:
        return mm[cur]
    res = 0
    for i in range(cur - 1, -1, -2):
        res += mul * rec(i)
        mul = 1
    return res


ans = 0
if d[0].count(0) == 0:
    pass
elif d[0].count(0) == 1:
    ans += 1
else:
    ans += 1 << (d[0].count(0) - 1)
for kkk in range(1, ma + 1):
    lg_di = len(d[kkk])
    mm = [None] * (N + 1)
    ans += rec(lg_di - 1)
    ans %= MOD
    # print(d[i])
print(ans)


# Example run
# Input:
6
495
# Output:
21
N=int(input())
mod=10**9+7
X=[-1]*N
for i,a in enumerate(map(int,input().split())):
    if i==0:
        X[0]=a
    else:
        X[i]=X[i-1]^a
if X[-1]>0:
    x=X[-1]
    dp0=1
    dp1=0
    zero=0
    for i in range(N):
        if X[i]==x:
            dp0=(dp0+dp1*zero)%mod
            zero=0
            dp1=(dp1+dp0)%mod
        elif X[i]==0:
            zero+=1
        
    print(dp0)
    exit()
from collections import defaultdict
dp0=defaultdict(lambda :1)
dp1=defaultdict(int)
zero=defaultdict(int)
zeronow=0
for i in range(N-1):
    x=X[i]
    if x>0:
        dp0[x]=(dp0[x]+dp1[x]*(zeronow-zero[x]))%mod
        zero[x]=zeronow
        dp1[x]=(dp1[x]+dp0[x])%mod
    elif x==0:
        zeronow+=1

print((sum(dp1.values())+pow(2,zeronow,mod))%mod)

# Example run
# Input:
888
-1983
# Output:
1
# input
N = int(input())
A = list(map(int, input().split()))

MOD = 10 ** 9 + 7

dp = [[None for _ in range(N)] for __ in range(N+1)]
dp[0] = [0 for _ in range(N)]

def xors(i, j):
    xor = A[i-1]
    for k in range(i,j):
        xor ^= A[k]
    return xor


for i in range(1, N+1):
    dp[i][0] = 1
    for j in range(1,i):
        dp[i][j] = 0
        for k in range(j):
            if xors(k+1, j) == xors(j+1, i):
                dp[i][j] += dp[j][k]

print(sum(dp[-1]) % MOD)


# Example run
# Input:
0
-1
# Output:
0