#!/usr/bin/env python3

MOD = 10 ** 9 + 7
IMAX = 70
JMAX = 10 ** 5

def dp(n):
    assert n <= JMAX
    dp = [0 for j in range(JMAX + 1)]
    dp[0] = 1
    for i in reversed(range(IMAX + 1)):
        d = 2 ** i
        for j in reversed(range(JMAX + 1)):
            if j - d >= 0:
                dp[j] += dp[j - d]
            if j - 2 * d >= 0:
                dp[j] += dp[j - 2 * d]
    return sum(dp[:n + 1])

def main():
    n = int(input())
    print(dp(n))

main()
