## C - ABC Tournament

players, labeled through , will compete against each other in a single-elimination programming tournament. The rating of Player is . Any two players have different ratings, and a match between two players always results in the victory of the player with the higher rating.

The tournament looks like a perfect binary tree.Formally, the tournament will proceed as follows:

• For each integer in this order, the following happens.
• For each integer , among the players who have never lost, the player with the -th smallest label and the player with the -th smallest label play a match against each other.

Find the label of the player who will take second place, that is, lose in the final match.

Constraints

• are pairwise different
• All values in input are integers.

Sample Input 1

Sample Output 1

## D - Snuke Prime

Snuke Inc. offers various kinds of services.

A payment plan called Snuke Prime is available.In this plan, by paying yen (the currency of Japan) per day, you can use all services offered by the company without additional fees.

You can start your subscription to this plan at the beginning of any day and cancel your subscription at the end of any day.

Takahashi is going to use of the services offered by the company.

He will use the -th of those services from the beginning of the -th day until the end of the -th day, where today is the first day. Without a subscription to Snuke Prime, he has to pay yen per day to use the -th service.

Find the minimum total amount of money Takahashi has to pay to use the services.

Constraints

• All values in input are integers.

Sample Input 1

Sample Output 1

## E - Peddler

In Takahashi Kingdom, there are towns, called Town through Town .
There are also roads in the kingdom, called Road through Road . By traversing Road , you can travel from Town to Town , but not vice versa. Here, it is guaranteed that .

Gold is actively traded in this kingdom. At Town , you can buy or sell kilogram of gold for yen (the currency of Japan).

Takahashi, a traveling salesman, plans to buy kilogram of gold at some town, traverse one or more roads, and sell kilogram of gold at another town.

Find the maximum possible profit (that is, the selling price minus the buying price) in this plan.

Constraints

• All values in input are integers.

Sample Input 1

Sample Output 1

We can achieve the profit of yen, as follows:

• At Town , buy one kilogram of gold for yen.
• Traverse Road to get to Town .
• Traverse Road to get to Town .
• At Town , sell one kilogram of gold for yen.

## F - +1-1x2

Takahashi has written an integer on a blackboard. He can do the following three kinds of operations any number of times in any order:

• increase the value written on the blackboard by ;
• decrease the value written on the blackboard by ;
• multiply the value written on the blackboard by .

Find the minimum number of operations required to have written on the blackboard.

Constraints

• and are integers.

Sample Input 1

Sample Output 1

### 解法一

1. 为偶数（只考虑 ，小于 差值就是答案），这时候 会增大 的差距，那么有没有可能是 然后再除二使得次数更少呢？也是不可能的， ， 转换到同一个值，前者需要 3 次变化，而后者只需要 2 次变化，所以直接除 2 是最优选择
2. 同理，但是我们也需要考虑 差距很小的时候， 直接一步步的减到 的情况