#K55252. Repeated DNA Sequences

    ID: 29934 Type: Default 1000ms 256MiB

Repeated DNA Sequences

Repeated DNA Sequences

You are given a list of DNA sequences and two integers ( n ) and ( k ). The integer ( n ) denotes the total number of sequences, and ( k ) is the target frequency. Your task is to find and output all the sequences that appear exactly ( k ) times in the list, sorted in lexicographical order. If no sequence meets the condition, output an empty line.

Example: For instance, if the input is:

5 2
ATCG
GCTA
ATCG
CGTA
GCTA

The sequences "ATCG" and "GCTA" both appear exactly 2 times and, when sorted lexicographically, the output should be:

ATCG GCTA

inputFormat

The input is received from standard input (stdin) and consists of multiple lines. The first line contains two space-separated integers ( n ) (the number of sequences) and ( k ) (the frequency to look for). The next ( n ) lines each contain a DNA sequence made up of uppercase letters.

outputFormat

Output to standard output (stdout) a single line with all the sequences that appear exactly ( k ) times, sorted in lexicographical order and separated by a single space. If there are no such sequences, output an empty line.## sample

5 2
ATCG
GCTA
ATCG
CGTA
GCTA
ATCG GCTA