AlgoUniversity
  • Go Back
Discussion
Student Sequence :

Author

Akash

Difficulty Level : Hard

Submissions : 59

Asked In : Jio

Marks :10

: 1 | : 1

Before the prayer assembly begins, the students of different classes stand randomly in a single line. Often they become noisy. To maintain silence during the prayer assembly, the teacher tells them to stand in a particular sequence. The sequence is such that there are at least D students of other classes standing between students of the same class.

Write an algorithm to output the final sequence in which the students will stand. If no such sequence is possible, then output $$$-1$$$. If more than one sequence is possible, then output the lexicographically smallest string.

Input

The first line of the input consists of a string $$$S$$$ $$$( 1 \le |S| \le 10^{5})$$$, representing the initial sequence in which the students stand.

The second line consists of an integer count $$$( 1 \le D \le 1000)$$$, representing the minimum number of students that stand between students of the same class.

Output

Print the string representing the final sequence in which at least D students of other classes stand between students of the same class. Print $$$'-1'$$$ if it is impossible. If more than one sequence is possible, then output the lexicographically smallest string.

Examples

Input
ddgdghghh
2
Output
dghdghdgh
Input
aaaaa
1
Output
aaaaa

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.