#C8919. Merge the Tools

    ID: 52954 Type: Default 1000ms 256MiB

Merge the Tools

Merge the Tools

You are given a string s and an integer k. Your task is to split the string s into substrings of size k (the last substring may be shorter than k if s's length is not a multiple of k). For each substring, remove any duplicate characters while maintaining the order of their first occurrence. Print each resulting substring on a new line.

Note:

  • If the character appears multiple times in the substring, only its first occurrence should be kept.

Example:

Input: s = "AABCAAADA", k = 3
Output:
AB
CA
AD

Input: s = "AAABBBCCC", k = 3 Output: A B C

</p>

inputFormat

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

  • The first line contains a non-empty string s, comprising uppercase letters.
  • The second line contains an integer k, representing the length of each substring to process.

outputFormat

The output should be written to standard output (stdout). For each substring of length k (or the last substring which might be shorter), print the substring after removing duplicate characters, each on a new line.

## sample
AABCAAADA
3
AB

CA AD

</p>