Problem:
Score : 400 points

Problem Statement

Caracal is fighting with a monster.

The health of the monster is H.

Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens:

If the monster's health is 1, it drops to 0.

If the monster's health, X, is greater than 1, that monster disappears. Then, two new monsters appear, each with the health of \lfloor X/2 \rfloor.

(\lfloor r \rfloor denotes the greatest integer not exceeding r.)

Caracal wins when the healths of all existing monsters become 0 or below.

Find the minimum number of attacks Caracal needs to make before winning.

Constraints

1 \leq H \leq 10^{12}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

H

Output

Find the minimum number of attacks Caracal needs to make before winning.

Sample Input 1

2

Sample Output 1

3

When Caracal attacks the initial monster, it disappears, and two monsters appear, each with the health of 1.

Then, Caracal can attack each of these new monsters once and win with a total of three attacks.

Sample Input 2

4

Sample Output 2

7

Sample Input 3

1000000000000

Sample Output 3

1099511627775

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Linq;
using System.Collections.Generic;

namespace Contest
{
    partial class Program
    {
        static void Main(string[] args)
        {
            ABC153_D();
        }


        static void ABC153_A()
        {
            var ha = ReadIntN();
            Console.WriteLine((ha[0] + ha[1] - 1) / ha[1]);
        }
        static void ABC153_B()
        {
            var hn = ReadIntN();
            var a = ReadIntN();
            Console.WriteLine(hn[0] <= a.Sum() ? "Yes" : "No");
        }
        static void ABC153_C()
        {
            var nk = ReadIntN();
            var h = ReadLongN();
            var N = nk[0];
            var K = nk[1];
            h = h.OrderBy(x => x).ToArray();
            Console.WriteLine(h.Take(N <= K ? 0 : N - K).Sum());
        }
        static void ABC153_D()
        {
            var H = ReadLong();
            long n = 1;
            while (H >= n)
            {
                n *= 2;
            }
            Console.WriteLine(n - 1);
        }
        static void ABC153_E()
        {
            var hn = ReadIntN();
            int H = hn[0];
            int N = hn[1];
            var ab = ReadTupleLong(N);
            var A = ab.Select(x => x.Item1).ToArray();
            var B = ab.Select(x => x.Item2).ToArray();
            long[] minMagic = new long[H + 1];
            minMagic[0] = 0;
            for(int i = 1; i < minMagic.Length; ++i)
            {
                minMagic[i] = Int32.MaxValue;
                for(int n = 0; n < N; ++n)
                {
                    var h0 = A[n] >= i  ? 0 : minMagic[i - A[n]];
                    minMagic[i] = Math.Min(minMagic[i], B[n] + h0);
                }
            }
            Console.WriteLine(minMagic[H]);
        }
        static void ABC153_F()
        {
            var nda = ReadIntN();
            var N = nda[0];
            var D = nda[1];
            var A = nda[2];
            var xh = ReadTupleLong(N).OrderBy(x => x.Item1).ToArray();
            var h = xh.Select(x => x.Item2).ToArray();
            long sum = 0;
            for(int i = 0; i < N; ++i)
            {
                var bomb = (Math.Max(0, h[i]) + A - 1) / A;
                sum += bomb;
                if (bomb >= 0)
                {
                    for (int j = i; j < N; ++j)
                    {
                        if (xh[j].Item1 - xh[i].Item1 <= D * 2)
                        {
                            h[j] -= bomb * A;
                        }
                        else { break; }
                    }
                }
            }
            Console.WriteLine(sum);
        }

        static string ReadStr()
        {
            return Console.ReadLine();
        }
        static string[] ReadStrN()
        {
            return Console.ReadLine().Split(' ');
        }
        static int ReadInt()
        {
            return Convert.ToInt32(Console.ReadLine());
        }
        static int[] ReadIntN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
        }
        static long ReadLong()
        {
            return Convert.ToInt64(Console.ReadLine());
        }
        static long[] ReadLongN()
        {
            return Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
        }
        static Tuple<long, long>[]  ReadTupleLong(int n)
        {
            List<Tuple<long, long>> list = new List<Tuple<long, long>>();
            for (int i = 0; i < n; ++i)
            {
                var ab = ReadLongN();
                list.Add(new Tuple<long, long>(ab[0], ab[1]));
            }
            return list.ToArray();
        }
    }
}