#K49877. Concatenate K Consecutive Strings

    ID: 28740 Type: Default 1000ms 256MiB

Concatenate K Consecutive Strings

Concatenate K Consecutive Strings

Given a list of strings and a positive integer k, your task is to divide the list into non-overlapping groups of k consecutive strings and then concatenate the strings in each group. If there are fewer than k strings remaining, that group is discarded.

In other words, if the list has n strings and n ≥ k, then for each valid index i (stepping by k), you will compute \(s = s_i + s_{i+1} + \cdots + s_{i+k-1}\) and print s on its own line.

Note: If k is less than or equal to 0, or if n is less than k, the output should be empty.

inputFormat

The input is read from standard input (stdin) and has the following format:

  1. An integer n representing the number of strings.
  2. A line containing n space-separated strings.
  3. An integer k representing the number of consecutive strings to concatenate.

If n is 0, the second line will be empty.

outputFormat

For each valid group of k consecutive strings, print the concatenated result on a new line on standard output (stdout). If no valid group exists, do not print anything.

## sample
4
 a b c d
2
ab

cd

</p>