Amino Acids
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
Special Judge, 64bit IO Format: %lld

题目描述

There are 20 kinds of common amino acids in the natural world. In this problem, we only consider 10 of them: Alanine, Asparagine, Aspartate, Cysteine, Glutamine, Glutamate, Glycine, Methionine, Serine and Threonine.
By condensation reaction, n () amino acids can be linked by n-1 peptide bonds into a peptide chain and produce n-1 water molecules at the same time. Recall that each water molecule has a molecular mass of 18.


Figure: Idealized scheme showing condensation of two amino acids to give a peptide bond.
Given a set of different amino acids and a number N, you are asked to print the structural formula of all possible peptide chains, with a molecular mass not greater than N, which can be formed by the given amino acids. Chains are considered different if the permutations of amino acids of the chain is different.
Here are the structural formula of the 10 amino acids and the peptide bond.
Ala:           Asp:           Asn:           Cys:           Gly:                              
  H H O          H H O          H H O          H H O          H H O                           
  | | ||         | | ||         | | ||         | | ||         | | ||                          
H-N-C-C-O-H    H-N-C-C-O-H    H-N-C-C-O-H    H-N-C-C-O-H    H-N-C-C-O-H                       
    |              |              |              |              |                             
  H-C-H          H-C-H          H-C-H          H-C-S-H          H                             
    |              |              |              |                                            
    H            O=C-O-H        O=C-N-H          H                                            
                                    |                                                         
                                    H                                                         
                                                                                              
Ser:           Met:           Thr:           Gln:           Glu:           Peptide bond:     
  H H O          H H O          H H O          H H O          H H O         O   H            
  | | ||         | | ||         | | ||         | | ||         | | ||        ||  |            
H-N-C-C-O-H    H-N-C-C-O-H    H-N-C-C-O-H    H-N-C-C-O-H    H-N-C-C-O-H    -C---N-           
    |              |              |              |              |                            
  H-C-O-H        H-C-H          H-C-O-H        H-C-H          H-C-H                          
    |              |              |              |              |                            
    H            H-C-H          H-C-H          H-C-H          H-C-H                          
                   |              |              |              |                            
                   S              H            O=C-N-H        O=C-O-H                        
                   |                               |                                         
                 H-C-H                             H                                         
                   |                                                                         
                   H                                                                                                                                                                                    

See below for molecular mass of amino acids.

Amino acid 3-letter symbol Molecular mass
Alanine Ala 89
Asparagine Asn 132
Aspartate Asp 133
Cysteine Cys 121
Glutamine Gln 146
Glutamate Glu 147
Glycine Gly 75
Methionine Met 149
Serine Ser 105
Threonine Thr 119

输入描述:

The first line contains two integers M and N (, ), denoting the number of amino acids and the molecular mass upper bound.

The second line contains M strings, each consisting of 3 letters denoting a kind of amino acid.

输出描述:

In the first line, print a single integer denoting the number of possible peptide chains.

Then print the structural formula of every possible peptide chain by the lexicographical order of their 3-letter sequences, separated by a blank line in between.
示例1

输入

复制
2 150
Ala Gly

输出

复制
3
  H H O   H H O
  | | ||  | | ||
H-N-C-C---N-C-C-O-H
    |       |
  H-C-H     H
    |
    H

  H H O   H H O
  | | ||  | | ||
H-N-C-C---N-C-C-O-H
    |       |
    H     H-C-H
            |
            H

  H H O   H H O
  | | ||  | | ||
H-N-C-C---N-C-C-O-H
    |       |
    H       H