// Codeforces 1.12.6
// AtCoder 1.6
// Paiza 1.7.3

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func cout(a ...interface{}) {
	// simply an alias for:
	fmt.Println(a...)
}

func consoleIn() reader {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	max := 1048576
	buf := make([]byte, max)
	scn.Buffer(buf, max)
	return reader{Scanner: scn}
}

type reader struct {
	Scanner *bufio.Scanner
}

func (in *reader) s() string {
	in.Scanner.Scan()
	return in.Scanner.Text()
}
func (in *reader) i() int64 {
	return in.ibase(10)
}
func (in *reader) j() int {
	i, _ := strconv.Atoi(in.s())
	return i
}
func (in *reader) ibase(base int) int64 {
	i, _ := strconv.ParseInt(in.s(), base, 64)
	return i
}
func (in *reader) f() float64 {
	i, _ := strconv.ParseFloat(in.s(), 64)
	return i
}
func (in *reader) ss(n int64) []string {
	a := make([]string, n)
	for i := range a {
		a[i] = in.s()
	}
	return a
}
func (in *reader) is(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = in.i()
	}
	return a
}
func (in *reader) js(n int64) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = in.j()
	}
	return a
}
func (in *reader) fs(n int64) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = in.f()
	}
	return a
}
func (in *reader) imat(h int64, w int64) [][]int64 {
	a := make([][]int64, h)
	for y := range a {
		a[y] = make([]int64, w)
		for x := range a[y] {
			a[y][x] = in.i()
		}
	}
	return a
}

type int64Math struct{}

func (*int64Math) max(a ...int64) int64 {
	t := a[0]
	for _, v := range a {
		if t < v {
			t = v
		}
	}
	return t
}
func (*int64Math) min(a ...int64) int64 {
	t := a[0]
	for _, v := range a {
		if t > v {
			t = v
		}
	}
	return t
}
func (*int64Math) sum(a ...int64) int64 {
	t := int64(0)
	for _, v := range a {
		t += v
	}
	return t
}
func (*int64Math) abs(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}
func (int64Math *int64Math) gcd(a, b int64) int64 {
	// returns greatest common divisor.
	if a < b {
		a, b = b, a
	}
	if b == 0 {
		return a
	}
	return int64Math.gcd(b, a%b)
}
func (int64Math *int64Math) lcm(a, b int64) int64 {
	// returns least common multiple.
	gcd := int64Math.gcd(a, b)
	return gcd * (a / gcd) * (b / gcd)
}
func (*int64Math) countValues(a []int64) map[int64]int64 {
	mp := make(map[int64]int64)
	for _, v := range a {
		mp[v]++
	}
	return mp
}

type stringifier struct{}

func (*stringifier) join(slice []int64) string {
	// int slice to a line.
	ret := make([]string, len(slice))
	for i, x := range slice {
		ret[i] = strconv.FormatInt(x, 10)
	}
	return strings.Join(ret, " ")
}
func (*stringifier) lines(slice []int64) string {
	// int slice to lines.
	ret := make([]string, len(slice))
	for i, x := range slice {
		ret[i] = strconv.FormatInt(x, 10)
	}
	return strings.Join(ret, "\n")
}
func (stringifier *stringifier) mat(matrix [][]int64) string {
	// int slice matrix to lines.
	ret := make([]string, len(matrix))
	for i := range matrix {
		ret[i] = stringifier.join(matrix[i])
	}
	return strings.Join(ret, "\n")
}
func (*stringifier) bl(b bool) str {
	if b {
		return "Yes"
	}
	return "No"
}

// OO string
type str string

func (s str) upper() string { return strings.ToUpper(string(s)) }
func (s str) lower() string { return strings.ToLower(string(s)) }

// sortable characters
type runes []rune

func (p runes) Len() int           { return len(p) }
func (p runes) Less(i, j int) bool { return p[i] < p[j] }
func (p runes) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

// heap/sort int slices
type comps [][]int64

func (p comps) Len() int { return len(p) }
func (p comps) Less(i, j int) bool {
	for x := range p[0] {
		if p[i][x] == p[j][x] {
			continue
		} else if p[i][x] < p[j][x] {
			return true
		} else {
			return false
		}
	}
	return false
}

func (p comps) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p *comps) Push(slice interface{}) {
	x := slice.([]int64)
	*p = append(*p, x)
}
func (p *comps) push(a ...int64) {
	// alias of:
	p.Push(a)
}
func (p *comps) Pop() interface{} {
	// https://golang.org/pkg/container/heap/
	var ret []int64
	n := len(*p)
	ret, *p = (*p)[n-1], (*p)[0:n-1]
	return ret
}
func (p *comps) pop() []int64 {
	// alias of:
	x := heap.Pop(p).([]int64)
	return x
}

// utilities.
const zr int64 = int64(0)
const mod int64 = int64(1000000007)

var cin = consoleIn()
var lmt = int64Math{}
var sfy = stringifier{}
var dyx = [][]int64{{-1, 0}, {0, -1}, {1, 0}, {0, 1}}

func main() {
	// --- read here.
	n := cin.i()
	a := cin.is(n)

	// --- solve here.
	ans := zr

	m := uint(20)
	// add stopping record (binary 1s)
	a = append(a, 1<<m-1)

	// dsum[j][i] = sum of j-th digits in binary integers from first to i-th(1-based)
	dsum := make([][]int64, m)
	for i := uint(0); i < m; i++ {
		dsum[i] = make([]int64, n+2)
	}
	for i, v := range a {
		for j, t := uint(0), v; j < m; j, t = j+1, t/2 {
			dsum[j][i+1] = dsum[j][i] + t%2
		}
	}
	// cout(dsum)

	nearest := n + 1
	for i := zr + 1; i <= n; i++ {
		nearest = n + 1

		// if j-th digit of a[i] (1-based) hasBit then following integers are ok until 2 bits are found in the digit.
		// if not hasBit then ok till you've got next 1 bit.
		for j, ds := range dsum {
			hasBit := (a[i-1] >> uint(j)) % 2
			nxtBitCount := ds[i] + 2 - hasBit
			// binary search
			l, r := zr, n+1
			for l+1 != r {
				m := (l + r) / 2
				if ds[m] < nxtBitCount {
					l = m
				} else {
					r = m
				}
			}
			nearest = lmt.min(nearest, r)
		}
		// cout(i, nearest)
		ans += nearest - i
	}

	cout(ans)
}

func check(n int64, a []int) int64 {
	// 検算
	ans := zr
	// x^x=0, x^x^y=y
	xor := make([]int, n)
	sum := make([]int, n)
	x, s := 0, 0
	for i, v := range a {
		x ^= v
		s += v
		xor[i], sum[i] = x, s
	}
	for i := range a {
		// left, right approach would fail,
		// because n <= 200000
		xor[i], sum[i] = x, s
	}
	return ans
}


Measured memory_bytes: 38272