Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)

Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this ridge: if Rick and Morty begin crying simultaneously from different mountains, their cry would be heard between these mountains up to the height equal the bitwise OR of mountains they've climbed and all the mountains between them. 

Bitwise OR is a binary operation which is determined the following way. Consider representation of numbers x and y in binary numeric system (probably with leading zeroes) x = xk... x1x0 and y = yk... y1y0. Then z = x | y is defined following way: z = zk... z1z0, where zi = 1, if xi = 1 or yi = 1, and zi = 0 otherwise. In the other words, digit of bitwise OR of two numbers equals zero if and only if digits at corresponding positions is both numbers equals zero. For example bitwise OR of numbers 10 = 10102 and 9 = 10012 equals 11 = 10112. In programming languages C/C++/Java/Python this operation is defined as «|», and in Pascal as «or».

Help Rick and Morty calculate the number of ways they can select two mountains in such a way that if they start crying from these mountains their cry will be heard above these mountains and all mountains between them. More formally you should find number of pairs l and r (1 ≤ l < r ≤ n) such that bitwise OR of heights of all mountains between l and r (inclusive) is larger than the height of any mountain at this interval.

Input

The first line contains integer n (1 ≤ n ≤ 200 000), the number of mountains in the ridge.

Second line contains n integers ai (0 ≤ ai ≤ 109), the heights of mountains in order they are located in the ridge.

Output

Print the only integer, the number of ways to choose two different mountains.

Examples

Input

5
3 2 1 6 5


Output

8


Input

4
3 3 3 3


Output

0

Note

In the first test case all the ways are pairs of mountains with the numbers (numbering from one):

(1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)

In the second test case there are no such pairs because for any pair of mountains the height of cry from them is 3, and this height is equal to the height of any mountain.
import java.io.*;
import java.util.*;

import static java.util.stream.Collectors.toList;

public class Solution {


    static MyScanner sc;
    private static PrintWriter out;
    static long M = 1000000007;

    //(1, 4), (1, 5), (2, 3), (2, 4), (2, 5), (3, 4), (3, 5), (4, 5)
    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();
//        stringBuilder.append("69\n" +
//                "3 4 2 4 5 2 0 5 2 8 8 0 0 8 6 4 3 0 0 1 2 5 8 1 7 4 6 0 6 1 8 4 2 0 4 3 5 6 2 8 3 7 7 6 0 3 8 6 2 6 0 2 4 5 0 3 6 8 8 8 3 2 2 6 7 8 5 3 5\n");
//        stringBuilder.append("4  1 2 2 1 ");
//        for (int i = 0; i < 10000; i++) {
//            stringBuilder.append(" " + 100_000_000_000L);
//        }
////

        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }

        out = new PrintWriter(new OutputStreamWriter(System.out));

        initData();
        solve();
        out.flush();
    }

    private static void initData() {

    }

    static List<Integer>[] dd;
    static boolean[] cap;
    static int[][] w;


    static int[][] edges;

    private static void solve() throws IOException {
        int n = sc.nextInt();
        int[] rr = sc.na(n);

        int[][] bits = new int[n + 1][31];
        for (int l = 0; l < n; l++) {
            for (int i = 0; i < 31; i++) {
                bits[l + 1][i] = bits[l][i];
                if ((rr[l] & (1 << i)) > 0) {
                    bits[l + 1][i] += 1;
                }
            }
        }

        int[] le = left(rr);
        int[] rh = right(rr);
        long res = 0;

        for (int i = 0; i < n; i++) {
            int[] cur = bit(rr[i]);
            int st = le[i];
            int en = rh[i];

            long k = ct(st, i, en, n);
            int k1 = ctl(i, cur, bits, st + 1, i);
            int k2 = cth(i, cur, bits, i, en == -1 ? n : en) + 1;
            k -= ct(k1, i, k2, n);
            res += k;
        }
        out.println(res);
    }

    private static int cth(int lll, int[] cur, int[][] bits, int from, int to) {
        while (from + 1 < to) {
            int m = (from + to) >>> 1;
            boolean f = false;
            for (int r = 0; r < 31 && !f; r++) {
                if (cur[r] == 1) continue;
                if (bits[lll][r] < bits[m + 1][r]) {
                    f = true;
                }
            }
            if (!f) {
                from = m;
            } else {
                to = m;
            }
        }
        return from;
    }

    private static int ctl(int lll, int[] cur, int[][] bits, int from, int to) {
        for (int r = 0; r < 31; r++) {
            if (cur[r] == 1) continue;
            if (bits[from][r] < bits[lll + 1][r]) {
                break;
            }
            if (r == 30) {
                return from - 1;
            }
        }
        while (from + 1 < to) {
            int m = (from + to) >>> 1;
            boolean f = false;
            for (int r = 0; r < 31 && !f; r++) {
                if (cur[r] == 1) continue;
                if (bits[m][r] < bits[lll + 1][r]) {
                    f = true;
                }
            }
            if (f) {
                from = m;
            } else {
                to = m;
            }
        }

        return from;
    }

    private static int[] bit(int i) {
        int[] res = new int[31];
        for (int r = 0; r < 31; r++) {
            res[r] = (i & (1 << r)) > 0 ? 1 : 0;
        }
        return res;
    }


    private static long ct(int st, int i, int en, int n) {
        long cur = i - st;
        cur *= (en != -1 ? en : n) - i;
        return cur;
    }

    private static int[] right(int[] rr) {
        int[] lll = new int[rr.length];
        ArrayList<Integer> xxx = new ArrayList<>();
        for (int i = rr.length - 1; i >= 0; i--) {
            int r = rr[i];
            while (xxx.size() > 0 && rr[xxx.get(xxx.size() - 1)] <= r) {
                xxx.remove(xxx.size() - 1);
            }
            lll[i] = xxx.size() == 0 ? -1 : xxx.get(xxx.size() - 1);
            xxx.add(i);
        }
        return lll;
    }


    private static int[] left(int[] rr) {
        int[] lll = new int[rr.length];
        ArrayList<Integer> xxx = new ArrayList<>();
        for (int i = 0; i < rr.length; i++) {
            int r = rr[i];
            while (xxx.size() > 0 && rr[xxx.get(xxx.size() - 1)] < r) {
                xxx.remove(xxx.size() - 1);
            }
            lll[i] = xxx.size() == 0 ? -1 : xxx.get(xxx.size() - 1);
            if (xxx.size() > 0 && rr[xxx.get(xxx.size() - 1)] == r) {
                xxx.remove(xxx.size() - 1);
            }
            xxx.add(i);
        }
        return lll;
    }

    private static int f1(int i) {
        return (!cap[i] ? 1_000_000 : 0) + i;
    }

    private static void solveT() throws IOException {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }


    private static long gcd(long l, long l1) {
        if (l > l1) return gcd(l1, l);
        if (l == 0) return l1;
        return gcd(l1 % l, l);
    }

    private static long pow(long a, long b, long m) {
        if (b == 0) return 1;
        if (b == 1) return a;
        long pp = pow(a, b / 2, m);
        pp *= pp;
        pp %= m;
        return (pp * (b % 2 == 0 ? 1 : a)) % m;
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        Integer[] nab(int n) {
            Integer[] k = new Integer[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.fi();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int fi() {
            String t = next();
            int cur = 0;
            boolean n = t.charAt(0) == '-';
            for (int a = n ? 1 : 0; a < t.length(); a++) {
                cur = cur * 10 + t.charAt(a) - '0';
            }
            return n ? -cur : cur;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    private static final class STree {
        private final boolean maxt;
        int rs;
        int[] val1;
        int[] from1;
        int[] to1;
        int[] metric;

        public STree(int c, boolean maxt) {
            rs = c;
            this.maxt = maxt;
            int size = Integer.highestOneBit(c);
            if (size != c) {
                size <<= 1;
            }
            int rs = size << 1;
            val1 = new int[rs];
            from1 = new int[rs];
            metric = new int[rs];
            to1 = new int[rs];

            Arrays.fill(from1, Integer.MAX_VALUE);
            if (!maxt)
                Arrays.fill(metric, Integer.MAX_VALUE);
            for (int r = rs - 1; r > 1; r--) {
                if (r >= size) {
                    from1[r] = r - size;
                    to1[r] = r - size;
                }
                from1[r / 2] = Math.min(from1[r / 2], from1[r]);
                to1[r / 2] = Math.max(to1[r / 2], to1[r]);
            }
        }

        public STree(int c) {
            this(c, true);
        }

        public int max(int from, int to) {
            return max(1, from, to);
        }

        private int max(int cur, int from, int to) {
            if (cur >= val1.length) return 0;
            if (from <= from1[cur] && to1[cur] <= to) {
                return metric[cur];
            }
            if (from1[cur] > to || from > to1[cur]) {
                return 0;
            }
            cur <<= 1;
            return Math.max(max(cur, from, to), max(cur + 1, from, to));
        }


        public void put(int x, int val) {
            x += val1.length >> 1;
            val1[x] = val;
            metric[x] = val;
            addToParent(x);
        }


        private void addToParent(int cur) {
            while (cur > 1) {
                cur >>= 1;
                if (maxt) {
                    metric[cur] = Math.max(metric[cur << 1], metric[1 + (cur << 1)]);
                } else {
                    metric[cur] = Math.min(metric[cur << 1], metric[1 + (cur << 1)]);
                }

            }
        }

        public long x(int i) {
            return val1[i + val1.length >> 1];
        }
    }
}