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: Wrong Answer)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var H = BigInteger.Parse(Read());


            //for (int i = 1; i <= H; i++)
            //{
            //    if (i == 1) list.Add(0);
            //    else if (i == 2) list.Add(3);
            //    else if (i == 3) list.Add(3);
            //    else
            //    {
            //        var a = Floor(i / 2.0);
            //        list.Add(list[int.Parse(a.ToString())] * 2 + 1);
            //    }
            //}
            //foreach (var item in list)
            //{
            //    Write(item + " ");
            //}
            //WriteLine(list[int.Parse(H.ToString())]);

            var list = new List<BigInteger>()
            {2, 4
, 8
, 16
, 32
, 64
, 128
, 256
            , 512
            , 1024
            , 2048
            , 4096
            , 8192
            , 16384
            , 32768
            , 65536
            , 131072
            , 262144
            , 524288
            , 1048576
            , 2097152
            , 4194304
            , 8388608
            , 16777216
            , 33554432
            , 67108864
            , 134217728
            , 268435456
            , 536870912
            , 1073741824
            , 2147483648
            , 4294967296
            , 8589934592
            , 17179869184
            , 34359738368
            , 68719476736
            , 137438953472
            , 274877906944
            , 549755813888
            , 1099511627776 };
            var ans = 0;
            if (H == 1)
            {
                ans = 0;
            }
            else if (H == 2)
            {
                ans = 2;
            }
            else
            {
                for (int i = 0; i < list.Count-1; i++)
                {
                    var a = list[i];
                    var b = list[i + 1] - 1;
                    if (a <= H && H <= b)
                    {
                        WriteLine(b);
                    }
                }
            }
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}