function Main(s){
  s = s.split("\n");
  var a = s[1].split(" ").map(a=>+a);
  var n = +s[0];
  if(n === 1){console.log(1);return;}
  var b = Array(n).fill(1e6);
  b[0] = 1;
  for(var j = 0; j < 20; j++){
    var x = 1 << j;
    var f = 0, g = 0;
    if(a[0] & x)f = 1;
    for(var i = 1; i < n; i++){
      if(a[i] & x){
        b[i] = Math.min(b[i], i-f+1);
        g = f; f = i+1;
      }else b[i] = Math.min(b[i], i-g+1);
    }
  }
  console.log(b.reduce((a,b)=>a+b));
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));
