Gene Combination
InterviewTime limit1sMemory limit512 MB
Given N genes made of two uppercase letters, find which letters can be the phenotype (the larger letter) of a gene formed by combining two different genes, and list them in order.
- Level
Medium4 of 10
- Topics
- Implementation, Math
- Solved
- No attempts yet
Problem
Students at Seoul National University of Science and Technology found a gene from an unfamiliar organism during an experiment. The gene is described by two traits, and each trait is written as an uppercase letter. Genes can be combined with other genes. When two genes are combined, the first trait of the first gene and the second trait of the second gene are joined to form a second-generation gene. Among the letters in a gene's two traits, the letters that are alphabetically equal to or greater than the others are called the gene's phenotype.
Given first-generation genes, each one can be combined with every other distinct first-generation gene. Find how many letters can appear as phenotypes of the second-generation genes produced by these combinations, and find those letters.
Input
The first line contains the number of genes . ()
The second line contains the first-generation genes, separated by spaces.
Output
On the first line, print the number of letters that can be phenotypes of the second-generation genes.
On the second line, print those phenotype letters in alphabetical order, separated by spaces.