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

#PS0000105. Tổng của các tổng đoạn (Sum of Sums)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tổng của các tổng đoạn (Sum of Sums)

Sum of Sums

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given nn integers a1,…,ana_1,\ldots,a_n and an integer kk, there are exactly n−k+1n-k+1 contiguous subarrays of length kk. Compute the sum of each such subarray, then add all these sums. An element contributes separately to each subarray containing it.

Input

The first line contains two integers n,kn,k.

The second line contains nn integers a1,…,ana_1,\ldots,a_n.

Output

Print one integer: the sum of the sums of all length-kk contiguous subarrays.

Subtasks

  • Subtask 1 (50 points): 1≤n≤10001\le n\le 1000; 1≤k≤n1\le k\le n; 0≤ai≤1000000000\le a_i\le 100000000 for all 1≤i≤n1\le i\le n.
  • Subtask 2 (50 points): 1≤n≤1000001\le n\le 100000; 1≤k≤n1\le k\le n; 0≤ai≤1000000000\le a_i\le 100000000 for all 1≤i≤n1\le i\le n.

Examples

Input

5 3
1 2 4 8 16

Output

49

Explanation

There are five elements and the required length is three. The three subarray sums are 1+2+4=71+2+4=7, 2+4+8=142+4+8=14, and 4+8+16=284+8+16=28. Their sum is 7+14+28=497+14+28=49.

Example 2

Input

20 10
100000000 100000000 98667799 100000000 100000000 100000000 100000000 99986657 100000000 100000000 100000000 100000000 100000000 98995577 100000000 100000000 99999876 100000000 100000000 99999999

Output

10988865195

Explanation

There are 11 windows of exactly 10 elements. The sums, in order of starting positions 1 through 11, are 998654456, 998654456, 998654456, 999986657, 998982234, 998982234, 998982234, 998982110, 998995453, 998995453, 998995452. Their total is 10988865195, exceeding the signed 32-bit range.