Password
Time limit4sMemory limit512 MB
Given a length-N string, collect all distinct substrings meeting four counts (length, digits, specials, uppercase), sort them lexicographically, and print the middle one.
- Level
Hard8 of 10
- Topics
- String, Sorting, String matching, Two pointers
- Solved
- No attempts yet
Problem
Jihun forgot the password of a site he rarely visits. The site keeps passwords as hashes, so it cannot tell him the old one and asks him to create a new password instead. The security policy is strict, so a password has to meet all four of these conditions.
- Its length is at least .
- It contains at least digits.
- It contains at least special characters. A special character is a character that is neither a digit nor a letter.
- It contains at least uppercase letters.
Jihun picks the new password this way.
- He writes one string of length , choosing each character freely from lowercase letters, uppercase letters, digits, and the special characters
!@#$%^&*()_-. - He inspects the contiguous substrings of that string one by one and puts into a candidate list only the ones that meet all four conditions. If the same string occurs more than once, it enters the list only once. For example, in
ababthe substringabenters the list exactly once. - He sorts the candidate list in lexicographic order. Characters compare by their ASCII values, and when one string equals the beginning of another, the shorter one comes first.
- If the sorted list holds candidates
candidate[1],candidate[2], ...,candidate[M], he adopts the -th one as the final password.
You are given the string of length that Jihun wrote. Find the password he finally adopts.
Input
The first line contains the integers , , , , in this order, separated by spaces.
The second line contains the string of length that Jihun wrote. It consists only of lowercase letters, uppercase letters, digits, and the special characters !@#$%^&*()_-.
Output
Print on the first line the password Jihun finally adopts. Every given input has at least one candidate.