def sum_equals_xor(l)
  count = {0 => 1}

  sum = 1
  1.upto(l) do |n|
    b = n.to_s(2)
    prev = b[1..-1].to_i(2)
    count[n] = count[prev] * 2
    sum += count[n]
  end
  
  sum % 1000000007
end

puts sum_equals_xor(gets.chomp.to_i(2))