import java.math.BigInteger;

public class Euler704 {
    public static String solve() {
        long N = 10000000000000000L;
        if (N == 0) {
            return "0";
        }

        int K = 63 - Long.numberOfLeadingZeros(N);
        BigInteger ans = BigInteger.ZERO;

        for (int k = 1; k < K; ++k) {
            BigInteger p2 = BigInteger.ONE.shiftLeft(k);
            BigInteger term = BigInteger.valueOf(k - 1).multiply(p2).add(BigInteger.ONE);
            ans = ans.add(term);
        }

        long blockStart = 1L << K;
        long M = N - blockStart + 1L;
        long A = blockStart + 1L;
        long B = N + 1L;

        BigInteger sumMin = BigInteger.ZERO;
        for (int t = 1; t <= K; ++t) {
            long p2 = 1L << t;
            long count = (B / p2) - ((A - 1L) / p2);
            sumMin = sumMin.add(BigInteger.valueOf(count));
        }

        BigInteger valK = BigInteger.valueOf(K);
        BigInteger valM = BigInteger.valueOf(M);
        ans = ans.add(valK.multiply(valM)).subtract(sumMin);

        return ans.toString();
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
