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

#GD0000025. Bàn phím nhắn tin (Text Messaging Outrage)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Bàn phím nhắn tin (Text Messaging Outrage)

Text Messaging Outrage

Source: Kattis

Version: Phuoc Hung OJ Extended

Problem Statement

A keypad has KK keys and each key can contain at most PP characters. Typing the jj-th character on a key requires jj presses. There are LL characters with frequencies fif_i. Assign them to keys to minimize the total number of presses.

Input

The first line contains P,K,LP,K,L. The second line contains LL frequencies fif_i. It is guaranteed that L≤PKL\le PK.

Output

Print the minimum total number of key presses.

Constraints

  • 1≤P,K,L≤10001\le P,K,L\le 1000.
  • L≤P⋅KL\le P\cdot K.
  • 0≤fi≤1060\le f_i\le 10^6 for 1≤i≤L1\le i\le L.

Subtasks

  • Subtask 1 (20 points): P,K≤8P,K\le 8, L≤64L\le 64.
  • Subtask 2 (30 points): P,K≤20P,K\le 20, L≤400L\le 400.
  • Subtask 3 (50 points): Full constraints.

Examples

Input

3 2 5
8 2 5 2 4

Output

31

Explanation

The sample follows the ordering rule described in the Vietnamese explanation and produces the shown optimum.