local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.func(self.stage[i][j], self.stage[i + 1][j * 2 - 1], self.stage[i + 1][j * 2])
    end
  end
end
SegTree.create = function(self, n, func)
  self.func = func
  local stagenum, mul = 1, 1
  self.stage = {{}}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.stage[stagenum] = {}
  end
  self.stagenum = stagenum
  for i = 1, mul do self.stage[stagenum][i] = {0, 0, 0} end
  for i = self.stagenum - 1, 1, -1 do
    local cnt = bls(1, i - 1)
    for j = 1, cnt do
      self.stage[i][j] = {0, 0, 0}
    end
  end
end
SegTree.setValue = function(self, idx, value)
  self.stage[self.stagenum][idx] = value
end
SegTree.right_bound = function(self, val, left, right)
  local ret, retpos = {0, 0, 0}, left - 1
  local stage, l, r = 1, left, right
  local stagenum = self.stagenum
  while true do
    local sz = bls(1, stagenum - stage)
    while (l - 1) % sz ~= 0 or r + 1 - l < sz do
      stage = stage + 1
      sz = bls(1, stagenum - stage)
    end
    local tmp = {unpack(ret)}
    self.func(tmp, ret, self.stage[stage][mce(l / sz)])
    if tmp[3] < val then
      ret, retpos = {unpack(tmp)}, l + sz - 1
      if retpos == right then break end
      if l + sz <= r then stage, l, r = 1, l + sz, r
      else break end
    else
      if sz ~= 1 then stage, l, r = stage + 1, l, l + sz - 2
      else break end
    end
  end
  return retpos + 1
end
SegTree.new = function(n, func)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func)
  return obj
end

local n = io.read("*n")
local xor = bit.bxor
local function merge(dst, a, b)
  dst[1] = a[1] + b[1]
  dst[2] = xor(a[2], b[2])
  dst[3] = dst[1] - dst[2]
end
local st = SegTree.new(n, merge)
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
  st:setValue(i, {a[i], a[i], 0})
end
st:updateAll()
local ret = 0
for i = 1, n do
  local rpos = st:right_bound(1, i, n)
  ret = ret + rpos - i
end
print(ret)
