Before Jessica Lee graduated high school in 2014, she went out with more street cred than anybody else who has ever made a chemistry joke in school with her yearbook quote. While her peers were probably quoting Ferris Bueller, Ralph Waldo Emerson or Mahatma Ghandi, the piece of advice she wanted to pass along to her classmates came from the song Get Money1 of Christopher George Latore Wallace — better known to the world as The Notorious B.I.G. For those of you who don't have a periodic table handy, this is the translation taken from Biggie's song.

Jessica Lee
Yearbook photograph of Jessica Lee with quote (2014).

While it hasn't been made public what, if any, repercussions Lee faced because of her brilliant joke, it appears that Paris Gray's similar-style joke caused more of an uproar with her school's administration. As she and her fellow classmates get ready to embark on adulthood and the ups and downs associated with post-high school life, she had this to say to keep her peers motivated.

Paris Gray
Yearbook photograph of Paris Gray with quote (2014).

Once the school board had decoded her message (of course without making the link with Juvenile's hit single Back That Azz Up2), she was given in-school suspension and prohibited from attending her school's senior walk. When she was also threatened with not being able to attend the graduation ceremony, that took things too far. Missing out on graduation would be more than just missing out on walking across the stage to receive her diploma, Gray was also slated to give the inspirational speech during the ceremony. Only after Gray and her mother sat down with the principal and the superintendent of the district, it was decided that she would be allowed to participate in the ceremony and could give her commencement address.

Assignment

In the periodic table of the elements, each chemical element is assigned an official name and a symbolic representation. Both the name and the symbol start with an uppercase letter, followed by zero or more lowercase letters. Symbols have at most three letters. All names and symbols are unique. Your task:

Example

The following interactive session assumes that the text file chemical_elements.txt3 to be located in the current directory.

>>> table = mendeleev('chemical_elements.txt4')
>>> table['I']
'Iodine'
>>> table['K']
'Potassium'
>>> table['Be']
'Beryllium'

>>> symbols('IKBeNHeTbEu')
['I', 'K', 'Be', 'N', 'He', 'Tb', 'Eu']
>>> symbols('FIReISFUN')
['F', 'I', 'Re', 'I', 'S', 'F', 'U', 'N']
>>> symbols('IPLaYWIThDyNAmITe')
['I', 'P', 'La', 'Y', 'W', 'I', 'Th', 'Dy', 'N', 'Am', 'I', 'Te']

>>> encode('IKBeNHeTbEu', table)
'Iodine Potassium Beryllium Nitrogen Helium Terbium Europium'
>>> encode('FIReISFUN', table)
'Fluorine Iodine Rhenium Iodine Sulfur Fluorine Uranium Nitrogen'
>>> encode('IPLaYWIThDyNAmITe', table)
'Iodine Phosphorus Lanthanum Yttrium Tungsten Iodine Thorium Dysprosium Nitrogen Americium Iodine Tellurium'
>>> encode('HeLiUm', table)
Traceback (most recent call last):
AssertionError: invalid symbol

>>> decode('Iodine Potassium Beryllium Nitrogen Helium Terbium Europium', table)
'IKBeNHeTbEu'
>>> decode('Fluorine Iodine Rhenium Iodine Sulfur Fluorine Uranium Nitrogen', table)
'FIReISFUN'
>>> decode('Iodine Phosphorus Lanthanum Yttrium Tungsten Iodine Thorium Dysprosium Nitrogen Americium Iodine Tellurium', table)
'IPLaYWIThDyNAmITe'
>>> decode('Mithril Oxygen Nitrogen Titanium Phosphorus Yttrium Thorium Oxygen Nitrogen', table)
Traceback (most recent call last):
AssertionError: invalid name

Epilogue

Ghent University students should not fear to be expelled, since the following tweet of one of its students was used in the university's community magazine Durf Denken. The phrase "ik ben het beu" means "I'm sick of it", referring to the feeling most students have during examination periods.

IKBeNHeTbEu

Epilogue

Did you know there are 12 chemical elements whose name can be spelled using element symbols?

ArSeNiC
AsTaTiNe
BiSmUTh
CArBON
CoPPEr
IrON
KrYPtON
NeON
PHOsPHORuS
SiLiCoN
TiN
XeNoN