using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; class Magatro { static void Main() { long N = long.Parse(Console.ReadLine()); Console.WriteLine(spe(N) - norm(N)); } static long norm(long n) { if (n == 0) { return 0; } return norm(n / 2) + n; } static long spe(long n) { List L = new List(); L.Add(n); while (n != 1) { n /= 2; L.Add(n); } long max = 0; for(int i = 1; i <= L.Count; i++) { long c = 0; for(int j = 0; j < i; j++) { c += L[j]; } c += L[i - 1]; max = Math.Max(c, max); } return max; } }