Problems > The winner takes it all

Problem Statement

We are holding a strange tennis competition, we will arrange all the players in an orderly list from the highest ranked to the lowest ranked.

 

The competition is held according to the following rules:

Generally speaking, whoever is ranked higher will always beat whoever is ranked lower than him.

But - if there can be a huge surprise, and the last seed plays the first seed, the last seeded player will win.

 

The competition is held in a series of rounds:

In each round, the player who is currently ranked first will play against the player who is currently ranked second.

The third versus the fourth and so on.

If there is an odd number of players, the last player will play against the first and beat him.

 

Any player who loses in the competition no longer takes a part in it.

 

We will re-rank the players again. And we will start a new round.

 

We get a single number n, up to 2,000,000,000 which represents the number of participants.

 

Our question is, who will win at the end of the competition? That is, what was his ranking at the beginning of the competition.

 

In the first example, four players play:

In the first round - the first beats the second, and the third beats the fourth.

In the second round - the first ranked beats the third and is now the winner of the competition.

 

In the second example, three players play:

In the first round - the first beats the second, and since the number of players is odd the third plays the first who is tired from the previous game and wins. Therefore the winner is the third player.

Sample input #1

3

Sample output #1

3

Sample input #2

4

Sample output #2

1
You must be logged in to submit