import java.util.Arrays; import java.util.HashSet; import java.util.LinkedList; import java.util.Scanner; public class Main { public static long solve(long n){ if(n == 0){ return 0; }else if(n == 1){ return 0; }else if(n % 2 == 0){ return (n / 2) + solve(n / 2); }else{ return solve(n / 2) * 2; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); final long N = sc.nextLong(); System.out.println(solve(N)); } }