Minimum Segment Cost#13042

Minimum Segment Cost

2 seconds
256 megabytes
Easy

You are given two integer arrays and of length , and an integer .

For each 1 \le i \le n, let

b_i=a_i-c_i.

You need to choose a segment [l,r] of length such that

2 \le l \le r \le n-1.

For each position , define d_i as follows:

The cost of the segment [l,r] is

\sum_{i=1}^{n} |b_i-b_l+d_i|.

Find the minimum possible cost over all valid segments [l,r].

Input

The first line contains two integers and (4 \le n \le 3000, 2 \le k \le n-2).

The second line contains integers a_1,a_2,\ldots,a_n (-10^9 \le a_i \le 10^9).

The third line contains integers c_1,c_2,\ldots,c_n (-10^9 \le c_i \le 10^9).

Output

Print one integer — the minimum possible cost.

Examples

Example 1

Loading
Loading

Note

In the example:

For l=3 and r=4, we have

b=[3,4,5,5,4,3].

The distances from the positions to the segment are

[2,1,0,0,1,2].

Since b_l=b_3=5, we get

[b_l-d_1,b_l-d_2,\ldots,b_l-d_n] = [3,4,5,5,4,3].

Therefore, the cost of this segment is

\sum_{i=1}^{n}|b_i-b_l+d_i|=0.

Since the cost cannot be negative, the answer is .

Scoring

  1. Subtask ( points): n \le 30 and k = n - 2.

  2. Subtask ( points): n \le 500.

  3. Subtask ( points): No additional constraints.