Under construction

Still being built. Things may change

Lexicographical Challenge

Interview

Time limit0.5sMemory limit1024 MB

Summary
Given a string S and an integer K, find the lexicographically smallest string reachable by swapping S_i with S_(i+K) any number of times.
Level

Easy3 of 10

Topics
String, Sorting, Implementation
Solved
No attempts yet

Problem

In the village of Lexicoville, Lily and Ethan received a mysterious letter containing a riddle. The riddle gives an integer KK and a string SS made only of lowercase letters. At any moment, the villagers may choose an index ii and swap the characters SiS_i and Si+KS_{i+K}. Using only this operation, find the lexicographically smallest string that can be obtained.

Input

The first line contains the string SS (1≤∣S∣≤1051 \le |S| \le 10^5). The second line contains the integer KK (1≤K<∣S∣1 \le K < |S|).

Output

Output a single line with the lexicographically smallest string that can be obtained.

Examples2

  1. Example 1

    Input
    zaaab
    4
    
    Expected output
    baaaz
    
  2. Example 2

    Input
    njoab
    2
    
    Expected output
    banjo