Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
E. Cutting the Line

time limit per test

2 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputYou are given a non-empty line *s* and an integer *k*. The following operation is performed with this line exactly once:

- A line is split into at most
*k*non-empty substrings, i.e. string*s*is represented as a concatenation of a set of strings*s*=*t*_{1}+*t*_{2}+ ... +*t*_{m}, 1 ≤*m*≤*k*. - Some of strings
*t*_{i}are replaced by strings*t*_{i}^{r}, that is, their record from right to left. - The lines are concatenated back in the same order, we get string
*s*' =*t*'_{1}*t*'_{2}...*t*'_{m}, where*t*'_{i}equals*t*_{i}or*t*_{i}^{r}.

Your task is to determine the lexicographically smallest string that could be the result of applying the given operation to the string *s*.

Input

The first line of the input contains string *s* (1 ≤ |*s*| ≤ 5 000 000), consisting of lowercase English letters. The second line contains integer *k* (1 ≤ *k* ≤ |*s*|) — the maximum number of parts in the partition.

Output

In the single line print the lexicographically minimum string *s*' which can be obtained as a result of performing the described operation.

Examples

Input

aba

2

Output

aab

Input

aaaabacaba

2

Output

aaaaabacab

Input

bababa

1

Output

ababab

Input

abacabadabacaba

4

Output

aababacabacabad

Codeforces (c) Copyright 2010-2022 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/26/2022 22:03:01 (h1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|