DISCLAIMER: This problem statement contains NO spoilers to the film Avengers: Endgame and is in no way, shape, or form affiliated to Marvel Entertainment. Uses of characters, settings, and scenes are parodical only.
To celebrate finally defeating the Avengers, Thanos decides to retire from his titanous ways and work on his garden. He's come to see that he's actually quite the farmer, and harvested a bountiful amount of space papayas.
Thanos wants to make himself a pot of papaya soup, but he's strictly on a perfectly balanced diet (as all things should be), and the sheer abundance of papayas is too much to digest. His last harvest produced papayas, but Thanos only wants an amount for his soup. He hires you, a computer scientist, to help him decide how he can get the optimal papaya value.
Unfortunately, being an almighty titan has its downsides, as Thanos can only reduce the number of papayas by half each time (the quotient is rounded down if it is a decimal number). Thanos is generally flexible when it comes to papaya consumption, but he much prefers an amount that is closer to . If there are two amounts that are the same difference from , Thanos prefers the higher amount.
Calculate the closest possible final number of papayas to to make a somewhat perfectly balanced diet for Thanos.
Line 1: 2 integers and
A single integer, representing the closest value possible to .
Let denote the largest integer less than or equal to .
We can compute what happens each time Thanos reduces the number of papayas by half:
We see that is the closest we can get to , thus the answer is .