#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
namespace Useful_Helpers {
void Unused(...) {}
#ifndef DEBUG
  #define echo(...) Unused(__VA_ARGS__)
#else
  #define echo(...) fprintf(stderr, __VA_ARGS__)
#endif
#define Reps(var, init, delim, step) for (int var = (init); var <= (delim); var += (step))
#define Rep(var, init, delim) Reps(var, init, delim, 1)  //for (int var = init; var <= delim; ++var)
#define Repr(var, init, delim) Reps(var, init, delim, -1)  //for (int var = init; var >= delim; --var)
template<typename DstTy, typename SrcTy>
DstTy set(DstTy &dst, const SrcTy &src) { return dst = static_cast<DstTy>(src); }
//
typedef long long i64t;
typedef unsigned long long u64t;
typedef unsigned u32t;
typedef int i32t;
//
namespace IO_Helper {
template<typename Ty>
void read(Ty &var);  // Read a variable
//
#define ImplRead(type, fmt) \
    template<> void read<type>(type& i) { scanf(fmt, &i); }
ImplRead(int, "%d");
ImplRead(char, "%c");
ImplRead(long long, "%lld");
template<> void read<char*>(char *&i) { scanf("%s", i); }
template<int Size> void read(char (&i)[Size]) { scanf("%s", i); }
#undef ImplRead
//
struct IO {
private:
    void read() {}
public:
    template<typename Ty, typename ...Rest>
    void read(Ty &car, Rest& ...cdr) { IO_Helper::read(car); this->read(cdr...); }
    template<typename Ty, int Size>
    void read(Ty (&arr)[Size], int beg, int end) { Rep(i, beg, end) this->read(arr[i]); }
}io;
}  // End namespace IO_Helper
using IO_Helper::io;
} using namespace Useful_Helpers;

const int MaxN = int(2e5) + 7;
const i64t Mod = int(1e9) + 7;
const int Inf = 0x3f3f3f3f;
const i64t Inf64 = 0x3f3f3f3f3f3f3f3f;
const int MaxS = 1 << 20;

int n;
int ai[MaxN];

class FHQTreap
{
private:
    int width[MaxN];
    int weight[MaxN];
    int child[MaxN][2];
    int value[MaxN], tag[MaxN];

    int root, id;
    int alloc(int val)
    {
        int res = ++id;
        width[res] = 1;
        weight[res] = rand();
        child[res][0] = child[res][1] = 0;
        value[res] = val;
        tag[res] = 0;
        return res;
    }

    void push(int now)
    {
        int lch = child[now][0], rch = child[now][1];
        if (lch)
        {
            value[lch] |= tag[now];
            tag[lch] |= tag[now];
        }
        if (rch)
        {
            value[rch] |= tag[now];
            tag[rch] |= tag[now];
        }
        tag[now] = 0;
    }
    void update(int now)
    {
        if (now)
        {
            width[now] = width[child[now][0]] + 1 + width[child[now][1]];
        }
    }

    void split(int now, int val, int &left, int &right)
    {
        if (!now)
        {
            left = right = 0;
            return;
        }
        push(now);
        if (value[now] & val)
        {
            left = now;
            split(child[now][1], val, child[now][1], right);
        }
        else
        {
            right = now;
            split(child[now][0], val, left, child[now][0]);
        }
        update(now);
    }
    int merge(int left, int right)
    {
        if (!left || !right)
            return left + right;
        push(left);
        push(right);
        int res;
        if (weight[left] > weight[right])
        {
            res = left;
            child[res][1] = merge(child[res][1], right);
        }
        else
        {
            res = right;
            child[res][0] = merge(left, child[res][0]);
        }
        update(res);
        return res;
    }

public:
    // amount of elem that & val = 0
    int query(int val)
    {
        int rest;
        split(root, val, rest, root);
        return width[root];
    }
    // push val and all |= val
    void insert(int val)
    {
        root = merge(root, alloc(val));
        value[root] |= val;
        tag[root] |= val;
        echo("tree width:%d\n", width[root]);
    }
}tree;

i32t main()
{
    // Scan
    io.read(n);
    io.read(ai, 1, n);

    // Reduce ans
    i64t ans = 0;
    Rep(pos, 1, n)
    {
        // amount of inv that & ai[pos] = 0
        ans += tree.query(ai[pos]);
        // insert and update all prev inv
        tree.insert(ai[pos]);
    }
    printf("%lld\n", ans + n);
    return 0;
}



Measured memory_bytes: 5632