import java.util.*; public class Main_yukicoder378 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long n = sc.nextLong(); long tmp = n; long ret = 0; while (tmp > 0) { ret += tmp; tmp /= 2; } System.out.println(Math.abs(2 * n - ret)); sc.close(); } }