local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
  if i % 2 == 0 then a[i] = 1 - a[i] end
end
local right = {}
for i = 1, n do right[i] = n end
for i = n - 1, 1, -1 do
  if a[i] ~= a[i + 1] then
    right[i] = i
  else
    right[i] = right[i + 1]
  end
end
local ret = 0
for i = 1, n do
  if i % 2 == 1 then
    if a[i] == 1 then
      ret = ret + right[i] - i + 1
      if right[i] == n then ret = ret - 1 end
    end
  else
    if a[i] == 0 then
      ret = ret + right[i] - i + 1
      if right[i] == n then ret = ret - 1 end
    end
  end
  -- print(i, ret)
end
print(ret)