cswork / OAOpen practice workspace

AmazonOA #85

Get Max Rating (Bitwise AND Subset)

Estimated HardJudge-ready

Topics (AI-labelled)Bits & MathGreedy

Perform at most k operations, each adding 1 to any rating. After the changes, choose exactly m items and maximize their bitwise AND.

Input

The first line contains n k m (1≤m≤n≤100000, 1≤k≤10⁹); the second line contains n rating values (1..10⁹).

Output

Output a single integer answer.

Example 1

Input:

2 2 2
1 2

Output:

2

Example 2

Input:

1 3 1
5

Output:

8

Example 3

Input:

3 2 3
1 1 1

Output:

1

Example notes

Example 1: raise 1 to 2 and choose two items, giving an AND of 2; bringing both items to 3 takes 3 operations, which exceeds the budget. Example 2: the only value goes from 5 to 8, so the answer is 8. Example 3: bringing all three items to 2 takes 3 operations but the budget is only 2, so the maximum AND stays 1.

Editorial

Loading solution…