This page is still under construction.

Parts of this page are still being built. What you see may change.

Bali Sculptures

Time limit1sMemory limit64 MB

Summary
Split N sculptures in order into between A and B consecutive groups to minimize the bitwise OR of the group age sums.
Level

Hard8 of 10

Topics
Dynamic programming, Greedy, Bit manipulation
Solved
No attempts yet

Problem

A main street in Bali has NN sculptures on it, numbered 1 to NN in order along the street. Sculpture ii is YiY_i years old, that is, it was made YiY_i years ago. To make the street prettier, the government wants to split the sculptures into groups and plant trees between neighbouring groups.

The rules for splitting the sculptures are:

  • The sculptures are split into exactly XX groups, where A≤X≤BA \le X \le B. Every group holds at least one sculpture, and every sculpture belongs to exactly one group. The sculptures of one group must be consecutive along the street.
  • For each group, add up the ages of the sculptures in that group.
  • Take the bitwise OR of all the group sums. That value is the beauty of the split.

Find the smallest beauty that a valid split can reach.

The bitwise OR of two non-negative integers PP and QQ is computed like this. Write both numbers in binary and pad the shorter one with leading zeros so that the two lengths match. Each bit of the result is decided by the two bits in the same position:

  • 0 OR 0 = 0
  • 0 OR 1 = 1
  • 1 OR 0 = 1
  • 1 OR 1 = 1

Input

The first line contains the integers NN, AA and BB, separated by spaces. The second line contains the ages Y1,Y2,…,YNY_1, Y_2, \dots, Y_N, separated by spaces.

  • 1≤N≤20001 \le N \le 2000
  • 1≤A≤B≤N1 \le A \le B \le N
  • 0≤Yi≤10000000000 \le Y_i \le 1000000000
  • If NN is greater than 100, then A=1A = 1.

Output

Print the minimum possible beauty on a single line.

Hint

In the first example the sculptures are split into (8 1 2) and (1 5 4). The group sums are 11 and 10, and their bitwise OR is 11.

Examples8

  1. Example 1

    Input
    6 1 3
    8 1 2 1 5 4
    
    Expected output
    11
    
  2. Example 2

    Input
    1 1 1
    0
    
    Expected output
    0
    
  3. Example 3

    Input
    5 2 3
    0 0 0 0 0
    
    Expected output
    0
    
  4. Example 4

    Input
    4 4 4
    1 2 4 8
    
    Expected output
    15
    
  5. Example 5

    Input
    5 1 1
    1 2 3 4 5
    
    Expected output
    15
    
  6. Example 6

    Input
    3 1 1
    1000000000 1000000000 1000000000
    
    Expected output
    3000000000
    
  7. Example 7

    Input
    8 2 4
    7 9 6 3 12 5 10 4
    
    Expected output
    23
    
  8. Example 8

    Input
    6 3 3
    1 1 1 1 1 1
    
    Expected output
    2