12773 - GEC1506 N-gram Sum   

Description

Given a line of numbers, you need to calculate the sum of the numbers by n-gram of the line.

An example is demonstrated below.

 

Input

Several lines of text

  1. N for N-gram SUM
  2. Skip size for the N-gram
  3. Numerical text line 1
  4. Numerical text line 2
  5. Numerical text line ...

In the following example, there are four lines.

2

2

12345

1234

 

Note that there is no numerical text line start with the text digit "0."

Output

The sums of all the n-grams of the given numerical text lines.

 

As the N for n-gram is 2 and the skip size is 2, the result of the above example is calculated by

12+34 = 46  (for the line of 12345, 23 and 45 are skipped)

12+34 = 46 (for the line of 1234, 23 is skipped)

Here is an illustration,

Taking another example, if the skip size is 1, the result of the above example is calculated by

12+23+34+45 = 114  (for the line of 12345)

12+23+34 = 69 (for the line of 1234)

Here is another illustration,

Sample Input  Download

Sample Output  Download

Tags




Discuss