import java.math.BigInteger;

public class Euler882 {

    static class Dyad {
        BigInteger num;
        int exp;

        Dyad(BigInteger num, int exp) {
            this.num = num;
            this.exp = exp;
        }
    }

    static Dyad normalize(BigInteger num, int exp) {
        if (num.equals(BigInteger.ZERO))
            return new Dyad(BigInteger.ZERO, 0);
        while (exp > 0 && !num.testBit(0)) {
            num = num.shiftRight(1);
            --exp;
        }
        return new Dyad(num, exp);
    }

    static BigInteger floorDivPow2(BigInteger x, int sh) {
        if (sh == 0)
            return x;
        if (x.compareTo(BigInteger.ZERO) >= 0)
            return x.shiftRight(sh);
        BigInteger a = x.negate();
        BigInteger oneMask = BigInteger.ONE.shiftLeft(sh).subtract(BigInteger.ONE);
        return a.add(oneMask).shiftRight(sh).negate();
    }

    static int cmpDyad(Dyad a, Dyad b) {
        BigInteger na = a.num;
        BigInteger nb = b.num;
        if (a.exp < b.exp)
            na = na.shiftLeft(b.exp - a.exp);
        else if (b.exp < a.exp)
            nb = nb.shiftLeft(a.exp - b.exp);
        return na.compareTo(nb);
    }

    static BigInteger floorDyad(Dyad a) {
        return floorDivPow2(a.num, a.exp);
    }

    static BigInteger ceilDyad(Dyad a) {
        Dyad neg = new Dyad(a.num.negate(), a.exp);
        return floorDyad(neg).negate();
    }

    static BigInteger floorScaled(Dyad a, int k) {
        BigInteger n = a.num;
        if (k >= a.exp)
            return n.shiftLeft(k - a.exp);
        return floorDivPow2(n, a.exp - k);
    }

    static BigInteger ceilScaled(Dyad a, int k) {
        Dyad neg = new Dyad(a.num.negate(), a.exp);
        return floorScaled(neg, k).negate();
    }

    static Dyad simplestBetween(Dyad L, boolean hasL, Dyad R, boolean hasR) {
        if (!hasL && !hasR)
            return new Dyad(BigInteger.ZERO, 0);
        if (hasL && !hasR)
            return new Dyad(floorDyad(L).add(BigInteger.ONE), 0);
        if (!hasL && hasR)
            return new Dyad(ceilDyad(R).subtract(BigInteger.ONE), 0);

        for (int k = 0; k <= 80; ++k) {
            BigInteger lo = floorScaled(L, k).add(BigInteger.ONE);
            BigInteger hi = ceilScaled(R, k).subtract(BigInteger.ONE);
            if (lo.compareTo(hi) > 0)
                continue;

            BigInteger m;
            if (lo.compareTo(BigInteger.ZERO) <= 0 && hi.compareTo(BigInteger.ZERO) >= 0)
                m = BigInteger.ZERO;
            else if (hi.compareTo(BigInteger.ZERO) < 0)
                m = hi;
            else
                m = lo;

            return normalize(m, k);
        }

        return new Dyad(BigInteger.ZERO, 0);
    }

    static int bitLength(int x) {
        if (x == 0)
            return 1;
        return 32 - Integer.numberOfLeadingZeros(x);
    }

    static int deleteBit(int x, int len, int idxFromLeft) {
        int p = len - 1 - idxFromLeft;
        int hi = x >>> (p + 1);
        int lo = (p == 0) ? 0 : (x & ((1 << p) - 1));
        return (hi << p) | lo;
    }

    static Dyad[] computeValues(int n) {
        Dyad[] v = new Dyad[n + 1];
        v[0] = new Dyad(BigInteger.ZERO, 0);

        for (int x = 1; x <= n; ++x) {
            int len = bitLength(x);
            Dyad bestL = new Dyad(BigInteger.ZERO, 0);
            Dyad bestR = new Dyad(BigInteger.ZERO, 0);
            boolean hasL = false, hasR = false;

            for (int i = 0; i < len; ++i) {
                int bit = (x >> (len - 1 - i)) & 1;
                int y = deleteBit(x, len, i);
                Dyad vy = v[y];

                if (bit == 1) {
                    if (!hasL || cmpDyad(vy, bestL) > 0) {
                        bestL = vy;
                        hasL = true;
                    }
                } else {
                    if (!hasR || cmpDyad(vy, bestR) < 0) {
                        bestR = vy;
                        hasR = true;
                    }
                }
            }

            v[x] = simplestBetween(bestL, hasL, bestR, hasR);
        }

        return v;
    }

    static BigInteger SValue(int n) {
        Dyad[] vals = computeValues(n);
        int maxExp = 0;
        for (int i = 1; i <= n; ++i) {
            if (vals[i].exp > maxExp)
                maxExp = vals[i].exp;
        }

        BigInteger scaledSum = BigInteger.ZERO;
        for (int i = 1; i <= n; ++i) {
            Dyad d = vals[i];
            int sh = maxExp - d.exp;
            BigInteger term = BigInteger.valueOf(i).multiply(d.num);
            scaledSum = scaledSum.add(term.shiftLeft(sh));
        }

        BigInteger den = BigInteger.ONE.shiftLeft(maxExp);
        return scaledSum.add(den).subtract(BigInteger.ONE).divide(den);
    }

    public static String solve() {
        return SValue(100000).toString();
    }

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