Given two numbers: 'left' and 'right' (1 <= 'left' <= 'right' <= 200000000000000)
return sum of all '1' occurencies in binary representations of numbers between 'left' and 'right' (including both)

``` 
Example:
countOnes 4 7 should return 8, because:
4(dec) = 100(bin), which adds 1 to the result.
5(dec) = 101(bin), which adds 2 to the result.
6(dec) = 110(bin), which adds 2 to the result.
7(dec) = 111(bin), which adds 3 to the result.
So finally result equals 8.
```
WARNING: Segment may contain billion elements, to pass this kata, your solution cannot iterate through all numbers in the segment!

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def countOnes(left, right):\n    """\n    Each number has a particular number of digits in its binary representation.\n    There are sets of numbers with the same number of digits in their binary representation.\n    For example there is a set of 4-digit-numbers: 8,9,10,11,12,13,14,15.\n\n    num | binary representation\n      8 | 1 0 0 0\n      9 | 1 0 0 1\n     10 | 1 0 1 0\n     11 | 1 0 1 1\n     12 | 1 1 0 0\n     13 | 1 1 0 1\n     14 | 1 1 1 0\n     15 | 1 1 1 1\n\n    That kind of sets of n-digit numbers we will call \'blocks\'.\n    For whole blocks we can easily calculate sum of ones with the formula 2^(n-1) * (1 + 0.5*(n-1))\n    But \'left\' and \'right\' digits can be somewhere inside of their blocks, so we have to sum only part of ones in block.\n\n    For example, in case of range <10, 35> we have to split our calculation in 3 parts:\n    1) Sum of the incomplete 4-digit-block, which contains number 10.\n    Number 10 splits that block on two parts and we sum ones only from second part (for numbers 10-15).\n    2) Sum of 5-digit-block (ones in numbers: 16-31)\n    3) Sum of the incomplete 6-digit-block, which contains number 35.\n    Number 35 splits that block on two parts and we sum ones only from first part (for numbers 32-35).\n\n    :return: sum of ones in binary representation of all numbers in range <left, right>\n    """\n    left_binary_digits = count_binary_digits(left)\n    right_binary_digits = count_binary_digits(right)\n\n    right_binary_sum = sum([int(i) for i in str(bin(right))[2:]])\n\n    left_position_in_block = left - calculate_starting_digit(left_binary_digits) + 1\n    right_position_in_block = right - calculate_starting_digit(right_binary_digits) + 1\n\n    if left_binary_digits == right_binary_digits:\n        number_of_ones = calculate_ones_in_incomplete_block(left_binary_digits, left_position_in_block) \\\n                         - calculate_ones_in_incomplete_block(right_binary_digits, right_position_in_block) \\\n                         + right_binary_sum\n    else:\n        number_of_ones = calculate_ones_in_incomplete_block(left_binary_digits, left_position_in_block) \\\n                         + calculate_multiple_blocks(left_binary_digits + 1, right_binary_digits - 1) \\\n                         + calculate_ones_in_incomplete_block(right_binary_digits, right_position_in_block, True) \\\n                         + right_binary_sum\n    return number_of_ones\n\n\ndef count_binary_digits(number):\n    """:return: number of digits in binary representation of integer"""\n    return len(str(bin(number))) - 2\n\n\ndef calculate_starting_digit(n_digits):\n    """\n    We know, that the block of n-digits-numbers contains of 2^(n-1) numbers\n    To calculate first number of 4-digits-block we have to count numbers from previous blocks and add 1:\n    2^(1-1) + 2^(2-1) + 2^(3-1) + 1 = 1 + 2 + 4 + 1 = 8\n    :return: first number of n_digits-block\n    """\n    return sum([pow(2, i - 1) for i in range(1, n_digits)]) + 1\n\n\ndef calculate_ones_in_incomplete_block(n_digits, position, front_part=False):\n    """\n    We use of following properties:\n    - First column of block is always filled with ones.\n    - Second column contains of dwo parts: half column of zeroes and half column of ones.\n        If we split next column in half, each part will follow above pattern.\n        If we split next column into four pieces, each part will follow the same pattern from second column and so on.\n    \n    We iterate through consecutive columns, moving \'middle_row\' indicator as we split columns in smaller parts.\n    As we calculating second part of block, we add all ones under our indicator (including one on indicator) and ommit ones above.\n    \n    :param n_digits: number of digits in binary representation\n    :param position: position of number in n_digits-block\n    :param front_part: indicates whether we calculate normally (\'second part\' of block - from position to the end)\n            or we subtract second part from sum of ones in whole block and return \'first part\'\n    :return: In block split in two parts by position we return sum of one form second or first part\n    """\n    all_rows = pow(2, n_digits - 1)\n    upper_ones = 0\n    last_row = all_rows\n    result = last_row - position + 1\n    middle_row = last_row / 2\n\n    for i in range(n_digits - 1):\n        if position <= middle_row:\n            result += all_rows / 2 - upper_ones\n            temp = int(last_row)\n            last_row = middle_row\n            middle_row -= (temp - middle_row) / 2\n        else:\n            result += (last_row - position + 1 + (all_rows - last_row) / 2)\n            upper_ones += (last_row - middle_row) / 2\n            middle_row += (last_row - middle_row) / 2\n\n    if front_part:\n        return all_rows * (1 + 0.5 * (n_digits - 1)) - result\n    else:\n        return result\n\n\ndef calculate_multiple_blocks(digits_start, digits_stop):\n    """\n    :return: sum of ones in all block from digits_start-block to digits_stop-block\n    """\n    result = 0\n    if digits_stop >= digits_start:\n        for i in range(digits_start, digits_stop + 1):\n            result += pow(2, i - 1) * (1 + 0.5 * (i - 1))\n    return result'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'countOnes'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 7030