#K95152. Unique Substring Transformation

    ID: 38800 Type: Default 1000ms 256MiB

Unique Substring Transformation

Unique Substring Transformation

Given a string \( s \) and an integer \( k \), partition \( s \) into consecutive substrings (segments) of length \( k \) (except possibly the last segment, which may be shorter). For each segment, remove duplicate characters while preserving their first occurrence order and print the resulting substring on a new line.

Example:

Input:  aabbbccccd
        3
Output: ab
        bc
        c
        d

More examples are provided in the input/output description below.

inputFormat

The input is read from stdin and consists of two lines:

  1. The first line contains the string \( s \), which may consist of lowercase or uppercase letters.
  2. The second line contains an integer \( k \) which specifies the size of each segment.

outputFormat

For each segment obtained by dividing the string \( s \) into consecutive chunks of size \( k \) (the final chunk may be shorter), output a line with the transformed substring. The transformation is performed by retaining only the first occurrence of each character in the segment.

## sample
aabbbccccd
3
ab

bc c d

</p>