Under construction

Still being built. Things may change

Gold Stimulation Also Needs a Meal First

Time limit2sMemory limit512 MB

Summary
Count the starting levels F_1 where the sums of exactly M ingredients inside the window [F_1, F_1 + D_K] match the plan exactly, shifted by F_1.
Level

Medium7 of 10

Topics
Dynamic programming, String matching, Bit manipulation, Math
Solved
No attempts yet

Problem

Bo-seon went to the Namgang Lantern Festival during a trip to Jinju. The festival has many colorful sculptures and fun shows, but Bo-seon, whose motto is 'Even Mount Geumgang needs a meal first,' went looking for the food truck zone with lots of food. Strangely, there was no food truck zone. It turned out the festival had a cooking zone instead.

The cooking zone sells NN kinds of ingredients. Each ingredient has a stimulation level T1,…,TNT_1, \dots, T_N, and every ingredient is plentiful enough to be used as much as needed. From these ingredients, you choose the kinds of ingredients and how many of each to cook a dish. The stimulation level of a finished dish is the sum of the stimulation levels of the ingredients used. Each cooking session costs a fixed amount of money, and the number of cooking sessions is not limited. However, each dish must use exactly MM ingredients. Too many ingredients take too long and ruin the taste, and too few make the taste bland.

Bo-seon plans to eat KK dishes. Bo-seon is a gourmet and cares about the stimulation levels of these KK dishes. Let FiF_i be the stimulation level of the ii-th dish eaten, and let Di=Fi−F1D_i = F_i - F_1. The meal plan is the increasing sequence D={D1,…,DK}D = \{D_1, \dots, D_K\}, where D1D_1 is always 00. Any dish whose stimulation level differs from F1F_1 by at least D1D_1 and at most DKD_K, and which is not in the plan DD, cannot be made, because similar dishes can be confused.

For example, let the plan DD be {0,2,3}\{0, 2, 3\}. If F1F_1 is chosen as 33, then F2F_2 must be 55 and F3F_3 must be 66. A dish with stimulation level 44 is not in the plan, and its difference from F1F_1 is between D1D_1 and DKD_K, so it must not be makeable. If a dish with stimulation level 44 can be made, F1F_1 cannot be 33.

Bo-seon makes every dish that can be made using exactly MM ingredients. Count the stimulation levels that can serve as F1F_1 while satisfying the conditions above.

Input

The first line contains the number of ingredient kinds NN, the number of ingredients per dish MM, and the number of dishes KK, separated by spaces. (1≤N,M≤1 000;1≤K≤1 000 000)(1 \le N, M \le 1\,000; 1 \le K \le 1\,000\,000)

The second line contains T1,…,TNT_1, \dots, T_N, separated by spaces. TiT_i is the stimulation level of the ii-th ingredient. (1≤Ti≤1 000)(1 \le T_i \le 1\,000)

The third line contains D1,…,DKD_1, \dots, D_K, separated by spaces. This is the increasing sequence DD that describes the meal plan. (0≤Di≤1 000 000;D1=0)(0 \le D_i \le 1\,000\,000; D_1 = 0)

All numbers in the input are integers.

Output

Print one line containing the number of stimulation levels that can be F1F_1 under the conditions.

Hint

Python 3 users are recommended to submit with PyPy3.

Examples2

  1. Example 1

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

    Input
    2 3 3
    1 3
    0 1 2
    
    Expected output
    0