#K77507. Sum of Frequencies in Substrings

    ID: 34879 Type: Default 1000ms 256MiB

Sum of Frequencies in Substrings

Sum of Frequencies in Substrings

Given a string \(S\) of length \(N\) and an integer \(K\), your task is to compute, for every contiguous substring of \(S\) with length \(K\), the sum of the frequencies of its characters.

For a substring \(T\) of length \(K\), let \(f(c)\) be the frequency of character \(c\) in \(T\). Then the answer for \(T\) is defined as:

\[ \sum_{c \in T} f(c)\,. \]

Note that since every character in the substring contributes its count, the result for any substring is always \(K\). However, you must implement the procedure as described.

inputFormat

The input is provided via standard input (stdin) in two lines:

  • The first line contains two space-separated integers \(N\) and \(K\), where \(N\) is the length of the string \(S\) and \(K\) is the length of each substring.
  • The second line contains the string \(S\) consisting of lowercase or uppercase letters.

outputFormat

Output the answer as a single line of space-separated integers to standard output (stdout). Each integer is the sum of frequencies of characters for the corresponding substring of length \(K\).

## sample
6 3
abcabc
3 3 3 3