def count(n, v): n = bin(n)[2:][::-1] v = bin(v)[2:][::-1] mx = max(len(n), len(v)) n += '0' * (mx - len(n)) v += '0' * (mx - len(v)) dp = [[0] * 2 for _ in range(2)] dp[0][0] = 1 for b in range(mx)[::-1]: ub = int(n[b]) tgt = int(v[b]) ndp = [[0] * 2 for _ in range(2)] for i in range(2): for j in range(2): for x in range(2): for y in range(2): if i == 0 and x > ub: continue if j == 0 and y > ub: continue z = x & y if b % 2 == 0 else x | y if z != tgt: continue ndp[i | (x < ub)][j | (y < ub)] += dp[i][j] dp = ndp return dp[1][1] vals = [0] for i in range(16): vals.append(vals[-1] | 1 << (2 * i + 1)) memo = [0] for i in range(16): l = 0 r = 1 while count(r, vals[i]) >= count(r, vals[i+1]): l = r r *= 2 while r - l > 1: c = (l + r) // 2 if count(c, vals[i]) >= count(c, vals[i+1]): l = c else: r = c memo.append(r) n = int(input()) + 1 ans = 0 for i in range(16): ans += (max(memo[i], min(n, memo[i+1])) - memo[i]) * vals[i] print(ans)