PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000111. Những thùng gỗ của Liebig (Liebig's Barrels)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những thùng gỗ của Liebig (Liebig's Barrels)

Liebig's Barrels

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are n⋅kn\cdot k wooden staves of lengths aia_i. Partition all staves into exactly nn barrels, each containing kk staves. Barrel volume equals the shortest stave in that barrel. All barrel volumes must differ by at most ll. Maximize their total or output 00 if impossible.

Input

Line 1 contains n,k,ln,k,l. Line 2 contains n⋅kn\cdot k integers aia_i.

Output

Print the maximum total barrel volume, or 00 if no valid partition exists.

Subtasks

  • Subtask 1 (20 points): 1≤n,k1\le n,k; 1≤n⋅k≤121\le n\cdot k\le 12; 0≤l≤1090\le l\le10^9; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 2 (30 points): 1≤n,k1\le n,k; 1≤n⋅k≤30001\le n\cdot k\le 3000; 0≤l≤1090\le l\le10^9; 1≤ai≤1091\le a_i\le10^9.
  • Subtask 3 (50 points): 1≤n,k1\le n,k; 1≤n⋅k≤1000001\le n\cdot k\le 100000; 0≤l≤1090\le l\le10^9; 1≤ai≤1091\le a_i\le10^9.

Examples

Input

4 2 1
2 2 1 2 3 2 2 3

Output

7

Explanation

Sort lengths to 1,2,2,2,2,2,3,31,2,2,2,2,2,3,3. Four barrels can have minimum staves 1,2,2,21,2,2,2, giving volume 77; all differ by at most 11, and no higher total is possible.