import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    immutable W = 30;
    long N = lread();
    auto A = aryread!uint();
    auto S = new long[][](N + 1, W);
    foreach (i; 0 .. N)
        foreach (j; 0 .. W)
        {
            S[i + 1][j] = S[i][j] + ((A[i] & (1 << j)) != 0);
        }
    long i;
    long j;
    long ans;
    while (i < N)
    {
        incj: while (true)
        {
            if (!(j <= N))
                break incj;
            auto tmp = new long[](W);
            tmp[] = S[j][] - S[i][];
            // writeln(tmp);
            if (tmp.all!(x => x <= 1)())
                j++;
            else
                break incj;
        }
        j--;
        long len = j - i;
        // writefln("%s %s %s", i, j, len);
        ans += len;
        i++;
        inci: while (true)
        {
            if (!(i < N) || !(i <= j))
                break inci;
            auto tmp = new long[](W);
            tmp[] = S[j][] - S[i][];
            // writeln("j", tmp);
            if (!(tmp.all!(x => x <= 1)()))
                i++;
            else
                break inci;
        }
    }
    writeln(ans);
}
