[Question]
  [
There are more than 100 elements in the modern periodic table. You challenge is to output the rounded mass of an element with respect to the input given.
# Input
* Input will contain an abbreviation of an element.
* Input can be taken from any one of the following:
	+ `stdin`
	+ command-line arguments
	+ function arguments
* Input will contain a one or two letter abbreviation of an element. The first character is always an uppercase letter and the second character, if any, will be a lowercase letter.
# Output
* Output the mass of the element entered
* Output must be in the stdout or closest equivalent.
* Output may contain a trailing newline character
# Elements and their masses
Here is the list of abbreviation of elements and their masses:
```
Sl.No     Elements     Abbreviation     Mass     
1         Hydrogen     H                1        
2         Helium       He               4        
3         Lithium      Li               7        
4         Beryllium    Be               9        
5         Boron        B                11       
6         Carbon       C                12       
7         Nitrogen     N                14       
8         Oxygen       O                16       
9         Fluorine     F                19       
10        Neon         Ne               20       
11        Sodium       Na               23       
12        Magnesium    Mg               24       
13        Aluminium    Al               27       
14        Silicon      Si               28       
15        Phosphorus   P                31       
16        Sulfur       S                32       
17        Chlorine     Cl               35       
18        Argon        Ar               40       
19        Potassium    K                39       
20        Calcium      Ca               40       
21        Scandium     Sc               45       
22        Titanium     Ti               48       
23        Vanadium     V                51       
24        Chromium     Cr               52       
25        Manganese    Mn               55       
26        Iron         Fe               56       
27        Cobalt       Co               59       
28        Nickel       Ni               59       
29        Copper       Cu               64       
30        Zinc         Zn               65       
31        Gallium      Ga               70       
32        Germanium    Ge               73       
33        Arsenic      As               75       
34        Selenium     Se               79       
35        Bromine      Br               80       
36        Krypton      Kr               84       
37        Rubidium     Rb               85       
38        Strontium    Sr               88       
39        Yttrium      Y                89       
40        Zirconium    Zr               91       
41        Niobium      Nb               93       
42        Molybdenum   Mo               96       
43        Technetium   Tc               98       
44        Ruthenium    Ru               101      
45        Rhodium      Rh               103      
46        Palladium    Pd               106      
47        Silver       Ag               108      
48        Cadmium      Cd               112      
49        Indium       In               115      
50        Tin          Sn               119      
51        Antimony     Sb               122      
52        Tellurium    Te               128      
53        Iodine       I                127      
54        Xenon        Xe               131      
55        Cesium       Cs               133      
56        Barium       Ba               137      
57        Lanthanum    La               139      
58        Cerium       Ce               140      
59        Praseodymium Pr               141      
60        Neodymium    Nd               144      
61        Promethium   Pm               145      
62        Samarium     Sm               150      
63        Europium     Eu               152      
64        Gadolinium   Gd               157      
65        Terbium      Tb               159      
66        Dysprosium   Dy               163      
67        Holmium      Ho               165      
68        Erbium       Er               167      
69        Thulium      Tm               169      
70        Ytterbium    Yb               173      
71        Lutetium     Lu               175      
72        Hafnium      Hf               178      
73        Tantalum     Ta               181      
74        Tungsten     W                184      
75        Rhenium      Re               186      
76        Osmium       Os               190      
77        Iridium      Ir               192      
78        Platinum     Pt               195      
79        Gold         Au               197      
80        Mercury      Hg               201      
81        Thallium     Tl               204      
82        Lead         Pb               207      
83        Bismuth      Bi               209      
84        Polonium     Po               209      
85        Astatine     At               210      
86        Radon        Rn               222      
87        Francium     Fr               223      
88        Radium       Ra               226      
89        Actinium     Ac               227      
90        Thorium      Th               232      
91        Protactinium Pa               231      
92        Uranium      U                238      
93        Neptunium    Np               237      
94        Plutonium    Pu               244      
95        Americium    Am               243      
96        Curium       Cm               247      
97        Berkelium    Bk               247      
98        Californium  Cf               251      
99        Einsteinium  Es               252      
100       Fermium      Fm               257 
```
Yes. Your code only needs to deal with elements having atomic number 0-100 as seen in the table above.
# Rules
* [Standard loopholes are disallowed](http://meta.codegolf.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default), as is fetching the data from built-ins
* You may write a full program, or a function.
# Test Cases
```
O    --> 16
Sn   --> 119
H    --> 1
Fm   --> 257
```
# Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest submission (in bytes) wins.
  
[Answer]
# CJam, ~~219~~ ~~213~~ 211 bytes
```
"
b$2#ÐÇ°aë#ëG0ÚÛ;½_+â¨9¨%ôº¯ó¾Ù""ÏÑ¯ÀcKÌA6ïõÃVå%x²XßM³0øUà°ÅæM¨Ã([©bþÚðÐÔ×¼&Và«òð×øùÚ¼5·¹IõÉðÑ§é°i9õÛ[&i÷jÍ¶û_<-c-uîá¹¹»D+èF"]256fb~26b'Af+2/'Jf-reua#__.0042*2.2+*i4-@Ab@=+
```
[Try it online](http://cjam.aditsu.net/#code=%22%0Ab%242%C2%9F%23%C3%90%C3%87%C2%B0%18%C2%86a%0F%C3%AB%23%C3%ABG%070%C3%9A%11%C3%9B%3B%C2%BD_%2B%C3%A2%C2%A89%C2%A8%14%25%C3%B4%1D%C2%BA%C2%8E%C2%AF%C3%B3%C2%BE%C2%86%C2%8C%C3%99%22%22%04%C3%8F%C3%91%C2%AF%C3%80cK%C3%8CA6%C3%AF%C2%8C%C3%B5%C3%83%11V%C3%A5%13%25x%C2%B2X%C3%9FM%C2%B3%C2%930%14%C3%B8U%C3%A0%C2%B0%C3%85%C3%A6M%C2%A8%C3%83%08%C2%9A%28%C2%8F%5B%C2%A9%C2%81b%13%C3%BE%C3%9A%C3%B0%C3%90%C3%94%C3%97%C2%93%C2%BC%26%05V%C3%A0%C2%81%C2%AB%C3%B2%C3%B0%C3%97%C3%B8%C3%B9%1A%C3%9A%C2%89%C2%BC5%C2%B7%C2%B9I%C3%B5%C2%87%04%C3%89%C3%B0%C3%91%C2%A7%C2%9D%13%C3%A9%C2%B0i9%C3%B5%C3%9B%5B%C2%9F%26i%C3%B7j%C3%8D%C2%80%C2%B6%C3%BB_%3C%C2%84-%1Fc-u%C3%AE%C3%A1%C2%80%C2%B9%C2%B9%C2%BB%C2%92D%2B%C3%A8%08F%22%5D256fb~26b'Af%2B2%2F'Jf-reua%23__.0042*2.2%2B*i4-%40Ab%40%3D%2B&input=Th). Because of unprintables, the permalink might not work in all browsers. For the two long strings the code points are
```
[10 98 36 50 159 35 208 199 176 24 134 97 15 235 35 235 71 7 48 218 17 219 59 189 95 43 226 168 57 168 20 37 244 29 186 142 175 243 190 134 140 217]
[4 207 209 175 192 99 75 204 65 54 239 140 245 195 17 86 229 19 37 120 178 88 223 77 179 147 48 20 248 85 224 176 197 230 77 168 195 8 154 40 143 91 169 129 98 19 254 218 240 208 212 215 147 188 38 5 86 224 129 171 242 240 215 248 249 26 218 137 188 53 183 185 73 245 135 4 201 240 209 167 157 19 233 176 105 57 245 219 91 159 38 105 247 106 205 128 182 251 95 60 132 45 31 99 45 117 238 225 128 185 185 187 146 68 43 232 8 70]
```
respectively.
The program uses the quadratic regression `mass ~ floor(2.2(a-1) + 0.0042(a-1)^2)`, where `a` is atomic number. The reason for the `a-1` is because of 0-indexing. This regression gives an error range of `[-4, 5]`, which allows a base 10 encoding of the offsets.
Mathematica code for the regression:
```
data = {{0, 1}, {1, 4}, {2, 7}, {3, 9}, {4, 11}, {5, 12}, {6, 14}, {7, 16}, {8, 19}, {9, 20}, {10, 23}, {11, 24}, {12, 27}, {13, 28}, {14, 31}, {15, 32}, {16, 35}, {17, 40}, {18, 39}, {19, 40}, {20, 45}, {21, 48}, {22, 51}, {23, 52}, {24, 55}, {25, 56}, {26, 59}, {27, 59}, {28, 64}, {29, 65}, {30, 70}, {31, 73}, {32, 75}, {33, 79}, {34, 80}, {35, 84}, {36, 85}, {37, 88}, {38, 89}, {39, 91}, {40, 93}, {41, 96}, {42, 98}, {43, 101}, {44, 103}, {45, 106}, {46, 108}, {47, 112}, {48, 115}, {49, 119}, {50, 122}, {51, 128}, {52, 127}, {53, 131}, {54, 133}, {55, 137}, {56, 139}, {57, 140}, {58, 141}, {59, 144}, {60, 145}, {61, 150}, {62, 152}, {63, 157}, {64, 159}, {65, 163}, {66, 165}, {67, 167}, {68, 169}, {69, 173}, {70, 175}, {71, 178}, {72, 181}, {73, 184}, {74, 186}, {75, 190}, {76, 192}, {77, 195}, {78, 197}, {79, 201}, {80, 204}, {81, 207}, {82, 209}, {83, 209}, {84, 210}, {85, 222}, {86, 223}, {87, 226}, {88, 227}, {89, 232}, {90, 231}, {91, 238}, {92, 237}, {93, 244}, {94, 243}, {95, 247}, {96, 247}, {97, 251}, {98, 252}, {99, 257}};
parabola = Fit[data, {1, x, x^2}, x]
Show[ListPlot[data, PlotMarkers -> {Automatic, Tiny}], Plot[parabola, {x, 0, 100}], Frame -> True]
```
Which gives:
```
-0.019569 + 2.20617 x + 0.00417056 x^2
```
[![enter image description here](https://i.stack.imgur.com/GqDeA.png)](https://i.stack.imgur.com/GqDeA.png)
[Answer]
# CJam, ~~175~~ 174 bytes
```
0000000: 7232316222faaf6c3e227b693138302b257d2f296322  r21b"..l>"{i180+%}/)c"
0000016: 0221dce3cc4eb9561f953aaf640771c048ca3b9926c1  .!...N.V..:.d.q.H.;.&.
000002c: 4d033768588e2545069a202e128f0e238546134bdb31  M.7hX.%E.. ....#.F.K.1
0000042: c2e9e6924a7a8642dab33d6b789009112b5a8a652dd3  ....Jz.B..=kx...+Z.e-.
0000058: 7dbf0f0b27eb18e52808e857967bd7be4ce2545181b8  }...'...(..W.{..L.TQ..
000006e: 01101447504f4443c6392449222322f43a606ce335e0  ...GPODC.9$I"#".:`l.5.
0000084: 4356e76914357218e3942869eb8ab3f97e2e161ef061  CV.i.5r...(i....~....a
000009a: 59c310c6cbe922323538623762364365723e3a2b      Y....."258b7b6Cer>:+
```
The above is a reversible xxd dump. You can try the code online in the [CJam interpreter](http://cjam.aditsu.net/#code=r21b%22%C3%BA%C2%AFl%3E%22%7Bi180%2B%25%7D%2F)c%22%02!%C3%9C%C3%A3%C3%8CN%C2%B9V%1F%C2%95%3A%C2%AFd%07q%C3%80H%C3%8A%3B%C2%99%26%C3%81M%037hX%C2%8E%25E%06%C2%9A%20.%12%C2%8F%0E%23%C2%85F%13K%C3%9B1%C3%82%C3%A9%C3%A6%C2%92Jz%C2%86B%C3%9A%C2%B3%3Dkx%C2%90%09%11%2BZ%C2%8Ae-%C3%93%7D%C2%BF%0F%0B'%C3%AB%18%C3%A5(%08%C3%A8W%C2%96%7B%C3%97%C2%BEL%C3%A2TQ%C2%81%C2%B8%01%10%14GPODC%C3%869%24I%22%23%22%C3%B4%3A%60l%C3%A35%C3%A0CV%C3%A7i%145r%18%C3%A3%C2%94(i%C3%AB%C2%8A%C2%B3%C3%B9~.%16%1E%C3%B0aY%C3%83%10%C3%86%C3%8B%C3%A9%22258b7b6Cer%3E%3A%2B&input=Pt).
If the permalink doesn't work in your browser, you can copy the code from [this paste](http://pastebin.com/Y1pscnmg).
In supported browsers, you can [verify all test cases](http://cjam.aditsu.net/#code=qN%2F%7BS%25~21b%22%C3%BA%C2%AFl%3E%22%7Bi180%2B%25%7D%2F)c%22%02!%C3%9C%C3%A3%C3%8CN%C2%B9V%1F%C2%95%3A%C2%AFd%07q%C3%80H%C3%8A%3B%C2%99%26%C3%81M%037hX%C2%8E%25E%06%C2%9A%20.%12%C2%8F%0E%23%C2%85F%13K%C3%9B1%C3%82%C3%A9%C3%A6%C2%92Jz%C2%86B%C3%9A%C2%B3%3Dkx%C2%90%09%11%2BZ%C2%8Ae-%C3%93%7D%C2%BF%0F%0B'%C3%AB%18%C3%A5(%08%C3%A8W%C2%96%7B%C3%97%C2%BEL%C3%A2TQ%C2%81%C2%B8%01%10%14GPODC%C3%869%24I%22%23%22%C3%B4%3A%60l%C3%A35%C3%A0CV%C3%A7i%145r%18%C3%A3%C2%94(i%C3%AB%C2%8A%C2%B3%C3%B9~.%16%1E%C3%B0aY%C3%83%10%C3%86%C3%8B%C3%A9%22258b7b6Cer%3E%3A%2B%60%3D%7D%25&input=1%20H%0A4%20He%0A7%20Li%0A9%20Be%0A11%20B%0A12%20C%0A14%20N%0A16%20O%0A19%20F%0A20%20Ne%0A23%20Na%0A24%20Mg%0A27%20Al%0A28%20Si%0A31%20P%0A32%20S%0A35%20Cl%0A39%20K%0A40%20Ar%0A40%20Ca%0A45%20Sc%0A48%20Ti%0A51%20V%0A52%20Cr%0A55%20Mn%0A56%20Fe%0A59%20Co%0A59%20Ni%0A64%20Cu%0A65%20Zn%0A70%20Ga%0A73%20Ge%0A75%20As%0A79%20Se%0A80%20Br%0A84%20Kr%0A85%20Rb%0A88%20Sr%0A89%20Y%0A91%20Zr%0A93%20Nb%0A96%20Mo%0A98%20Tc%0A101%20Ru%0A103%20Rh%0A106%20Pd%0A108%20Ag%0A112%20Cd%0A115%20In%0A119%20Sn%0A122%20Sb%0A127%20I%0A128%20Te%0A131%20Xe%0A133%20Cs%0A137%20Ba%0A139%20La%0A140%20Ce%0A141%20Pr%0A144%20Nd%0A145%20Pm%0A150%20Sm%0A152%20Eu%0A157%20Gd%0A159%20Tb%0A163%20Dy%0A165%20Ho%0A167%20Er%0A169%20Tm%0A173%20Yb%0A175%20Lu%0A178%20Hf%0A181%20Ta%0A184%20W%0A186%20Re%0A190%20Os%0A192%20Ir%0A195%20Pt%0A197%20Au%0A201%20Hg%0A204%20Tl%0A207%20Pb%0A209%20Bi%0A209%20Po%0A210%20At%0A222%20Rn%0A223%20Fr%0A226%20Ra%0A227%20Ac%0A231%20Pa%0A232%20Th%0A237%20Np%0A238%20U%0A243%20Am%0A244%20Pu%0A247%20Bk%0A247%20Cm%0A251%20Cf%0A252%20Es%0A257%20Fm) at once.
### Idea
The actual weights are encoded in the same fashion as in [Martin Büttner's answer](https://codegolf.stackexchange.com/a/52265), with three minor modifications:
* 12's are replaced with 6's instead of 7's.
* The encoding is done in base 7 instead of base 8.
* The order of the elements is reversed.
The difference between our answers lies in how the element abbreviations are stored.
In this approach, we hash all 100 element abbreviations into 8-bit characters, by doing the following:
* Take the element name (treated as the array of its code points) and apply base 21 conversion.
Examples: `"H"21b` yields **72**, `"He"21b` yields **1613 = 21 × 72 + 101**.
* Successively compute the residue of the division by 430, 355, 288 and 242.
Example: `1613 430% 355% 288% 242%` yields **35**.
* Increment and cast to character.
Example: `35)c` yields **$**.
### Code
```
r         e# Read a whitespace-separated token from STDIN.
21b       e# Convert to intger, using base 21 conversion.
"ú¯l>"    e# Push that string.
{i180+%}/ e# Cast each char to integer, add 180 and apply modular division.
)c        e# Add 1 and cast to character.
"!ÜãÌN¹V:¯dqÀHÊ;&ÁM7hX%E .#FKÛ1ÂéæJzBÚ³=kx  +Ze-Ó}¿'ëå(èW{×¾LâTQ¸GPODCÆ9$I"
          e# Push that string.
          e# "He", e.g., is hashed to '$', which is the second char from the right.
#         e# Compute the index of the character hash in the string.
"ô:`lã5àCVçi5rã(ië³ù~.ðaYÃÆËé"
          e# Push that string.
 258b7b   e# Convert from base 258 to base 7.
 6Cer     e# Replace 6's with 12's.
 >        e# Keep only weight differences before the hashes occurrence.
 :+       e# Push the sum of the weight differences.
```
[Answer]
# CJam, ~~201~~ 195 bytes
```
"üæ1Îe3©ü^<ùÉkIxX¯þÄäj¤ý¨,N8jËäVªw{®Ö_<U
Zká++ØÙ/ªQÒ?»<yÙ>K_þÉ«2´EªÄ¡8ÕþÀ!-,ñ©ZÒàF"256b26b2/Gf-qeu'Af-a#)"#ØmÔwXÍÒA5(Wâ£ogg5ÂßòtwÆÚ^ØW¶°¥"258b8b7Cer<:+
```
I'm sure there are a bunch of unprintable characters in there, so use [this permalink for testing](http://cjam.aditsu.net/#code=%22%04%C3%BC%C3%A61%C3%8Ee3%C2%A9%C3%BC%5E%3C%C3%B9%C3%89kI%C2%93x%C2%9C%C2%9BX%C2%AF%0C%C3%BE%C3%84%C3%A4j%C2%A4%C3%BD%C2%A8%2C%C2%97N%C2%888%1Fj%C3%8B%02%C3%A4V%C2%AA%C2%86w%7B%C2%8B%C2%AE%C3%96_%3C%10U%0A%C2%99Zk%C3%A1%2B%2B%C2%93%C2%96%C2%87%C3%98%C3%99%2F%C2%AAQ%C3%92%C2%85%C2%82%3F%C2%8C%C2%BB%13%C2%92%3C%C2%80%C2%92%18%C2%90y%C3%99%3EK%C2%99_%0F%C3%BE%C2%86%C3%89%C2%AB2%C2%B4E%13%C2%AA%C3%84%C2%9A%C2%A1%1B8%C3%95%C3%BE%C3%80!%C2%9F%0F%16%C2%82-%2C%C3%B1%1D%C2%A9Z%C2%8D%C3%92%C3%A0F%22256b26b2%2FGf-qeu'Af-a%23)%22%02%23%C3%98%C2%9Fm%C3%94%06wX%C3%8D%C2%84%C3%92A%1E%C2%915(W%C3%A2%C2%A3ogg5%C3%82%C3%9F%C3%B2tw%C3%86%C3%9A%5E%C3%98W%C2%B6%1A%C2%B0%C2%A5%22258b8b7Cer%3C%3A%2B&input=Mn).
I used [this script](http://cjam.aditsu.net/#code=qN%2FSf%252f%3E%7B)~%2B(2'Qe%5Deua%5C%2B%7D%25%7BW%3D%7D%24z(s'Afm26bp%0A~0%5C%2B%7B_%40-%5C%7D*%3B%5DC7er8bp&input=1%20%20%20%20%20%20%20%20%20Hydrogen%20%20%20%20%20H%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%201%20%20%20%20%20%20%20%20%0A2%20%20%20%20%20%20%20%20%20Helium%20%20%20%20%20%20%20He%20%20%20%20%20%20%20%20%20%20%20%20%20%20%204%20%20%20%20%20%20%20%20%0A3%20%20%20%20%20%20%20%20%20Lithium%20%20%20%20%20%20Li%20%20%20%20%20%20%20%20%20%20%20%20%20%20%207%20%20%20%20%20%20%20%20%0A4%20%20%20%20%20%20%20%20%20Beryllium%20%20%20%20Be%20%20%20%20%20%20%20%20%20%20%20%20%20%20%209%20%20%20%20%20%20%20%20%0A5%20%20%20%20%20%20%20%20%20Boron%20%20%20%20%20%20%20%20B%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2011%20%20%20%20%20%20%20%0A6%20%20%20%20%20%20%20%20%20Carbon%20%20%20%20%20%20%20C%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2012%20%20%20%20%20%20%20%0A7%20%20%20%20%20%20%20%20%20Nitrogen%20%20%20%20%20N%20%20%20%20%20%20%20%20%20%20...%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20238%20%20%20%20%20%20%0A93%20%20%20%20%20%20%20%20Neptunium%20%20%20%20Np%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20237%20%20%20%20%20%20%0A94%20%20%20%20%20%20%20%20Plutonium%20%20%20%20Pu%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20244%20%20%20%20%20%20%0A95%20%20%20%20%20%20%20%20Americium%20%20%20%20Am%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20243%20%20%20%20%20%20%0A96%20%20%20%20%20%20%20%20Curium%20%20%20%20%20%20%20Cm%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20247%20%20%20%20%20%20%0A97%20%20%20%20%20%20%20%20Berkelium%20%20%20%20Bk%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20247%20%20%20%20%20%20%0A98%20%20%20%20%20%20%20%20Californium%20%20Cf%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20251%20%20%20%20%20%20%0A99%20%20%20%20%20%20%20%20Einsteinium%20%20Es%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20252%20%20%20%20%20%20%0A100%20%20%20%20%20%20%20Fermium%20%20%20%20%20%20Fm%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20257%20) to encode the abbreviations and masses as two numbers, and [this script](http://cjam.aditsu.net/#code=363180297747591790604930618402396129685962856524967156551691803198533587214560772335382797%20258b_%3Ae%3Ep_%2Cp%3Acp&input=Mn) to generate the base encoding. (These are mostly for myself if I need to change anything.)
## Explanation
Of course, the main compression comes from base encoding: to compress any array, interpret it as digits in some sufficiently large base to get a single number - then get the base-256 (or similar) digits of that number and turn them into characters. That process is reversible, such that we can recover the array from that string.
The above code contains two such base encodings: one for the abbreviations, and one for the masses. To make those two arrays more amenable to base encoding (i.e. to lower the base, as that makes the overall number and string significantly shorter), I did some preprocessing on the table.
First, I sorted the entire table by masses to get a non-decreasing sequence. Then I computed the successive differences between those, because the sequence is rising rather slowly. In fact, the steps are always less than 13. That allows me to use base 13 (and then recover the masses by truncating that array to the correct length and summing all elements). However, we can do better: there is only a single 12, and the next smaller step is 6. So we can replace that 12 by a 7 and use base 8, which saves quite a bit.
To encode the abbreviations, we pad the single-character elements with `Q` (which doesn't appear in any abbreviation), join them all together and take the difference with `A` or `a` (such that each letter becomes a number between `0` and `25` inclusive). This is then encoded in base 26. The abbreviations can be recovered by splitting the base-26 digits into pairs of 2 and removing all `16`s (which correspond to the `Q`s).
Here is the code:
```
e# Decode the abbreviations
"gibberish"256b26b
     e# Get the base-26 digits representing the letters.
2/   e# Split into pairs.
Gf-  e# Remove 16s (Qs).
e# Process the input
qeu  e# Read input and convert to upper case.
'Af- e# Subtract the characters from 'A' to get numbers.
a#)  e# Find the position in the decoded array.
e# Find the mass
"gibberish"258b8b
     e# Get the base-8 digits representing the mass increments.
7Cer e# Replace the 7 by a 12.
<    e# Truncate, based on the position of the input in the abbreviations.
:+   e# Sum all the increments.
```
[Answer]
# Bash + coreutils, 381
```
base64 -d<<<H4sICPGCjVUAA3B0LnR4dABNUMuShCAMvPcveQIEoUaQAtzdmf//kO2Ol7GKEJP0I2QAOTKcBfBMPALQgIu1hKZWc6gHb3dicgodkzGcDHjBjS04pZhEYmniB2Hwqg1JBOHaWrGRcOPTLDuEOdh107ARfhjhwPAqDLyBD2tNv5V+lvjHzZPlYif2MFJmKEY7Fac3hYIl8T+GYBqekqdDiOiSajt6fYzzivdji1zL8DvlM1UjZ5fNvVk/NZaTFtUCvzQjEVxUKGLti7aMK8vc0it1An3Z+gW38PUNvo8ww8FpN3SHla3VOh5DrqIrC3XzL9s2Ido6SBX/wOjUg78BAAA=|zcat|sed -n "/\b$1\b/I="
```
This is simply the elements represented in a file thus:
```
H
HE
LI
BE
...
```
Note the line number of the element corresponds with the mass. In cases where there are multiple elements with the same mass, the line looks like:
```
AR;CA
```
The file is gzipped and base64 encoded. Note the element names are all in upper case to improve compression. Interestingly gzip and bzip2 had identical compressed lengths, and xz was a little bit longer.
The `base64 -d` and `zcat` simply convert the base64 stream back to this original file. The `sed` then simply searches (case insensitively) for the input string and outputs its line number.
### Test output:
```
$ for e in O Sn H Fm Ni Co; do ./pt.sh $e; done
16
119
1
257
59
59
$ 
```
[Answer]
# [Marbelous](https://github.com/marbelous-lang/marbelous.py), 1426 bytes
```
}0}1
LNLn
=A
RLSS
=G=M=T=C=U=L=R=S
P1P2P2P2P1P2P4P7
P0P4P1P2P9P7P0P5
P8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P8P9//PN
PNPNPNPNPN
}0}1
LNLn
>X
RLSS
=B=R=N
P1P9P6
P7P1P5
P3PNPN
PN
}0
LN
=Y=X=W=V=U=D
P8P1P1P5P2P1
P9P3P8P1P3P6
..P1P4..P8P3
PNPNPNPNPNPN
:P0
}0
{030
:P1
}0
{031
:P2
}0
{032
:P3
}0
{033
:P4
}0
{034
:P5
}0
{035
:P6
}0
{036
:P7
}0
{037
:P8
}0
{038
:P9
}0
{039
:PN
}0
\/0A
:LN
}0
-Z
-K
{0
:Ln
}0
-W
-Z
-K
{0
:RLSS
}1}0
{0\/
```
Input is provided as two command line parameters. Marbelous does not currently have a way to handle variable length input and halt, so the second parameter is required. For one-letter symbols, just pass in any character as the second parameter, as long as it doesn't make a valid two-letter symbol. I hope to improve the language in the future to remove this limitation.
Also, a bug in the python interpreter currently requires the `-m 0` parameter, as stdout is not being memoized correctly for functions.
```
# marbelous.py -m 0 mass.mbl H e
4
# marbelous.py -m 0 mass.mbl T a
181
```
[Answer]
### Excel VBA, 1587 bytes
So it isn't really a good golf attempt, I used a standard CASE statement, which looks like:
```
n = InputBox("n")
Select Case n
Case "H"
m = 1
Case "He"
m = 4
Case "Li"
m = 7
......
End Select
```
For all 100 elements specified in the question, it will read in the abbreviation and then display its weight in a message box.   
But what was interesting is instead of spending ages typing it all out, I used another bit of VBA to generate the CASE statement:
```
FilePath = Application.DefaultFilePath & "\code.txt"
Open FilePath For Output As #2
For i = 3 To UsedRange.Rows.Count
sentence = sentence + "Case " & Chr(34) & Cells(i, 3) & Chr(34) & vbNewLine & "m = " & Cells(i, 4) & vbNewLine
Next i
Print #2, sentence
Close #2
```
I copy and pasted the helpful table used in the question, the macro then reads the needed columns and pieces together the entire CASE statement used above.
I used this guide to work out how to output to a text file: <http://www.homeandlearn.org/write_to_a_text_file.html>
[Answer]
# JavaScript ES6, 326
```
s=>eval(`/${s}(\\d+)/.exec(btoa\`QÞà¸»ïA×PµØÝx;^×Ó^ÛCZÛs Û%Û´¢ÛÃ÷Õ-ö
]ù¾4+BksSçP«çc'ç^ç ¨çÓbçÐ®ëgëïAïp,ïïÐkóB«ó[ó«óÆ<õýÔÖýÜÊ=é7=ñµÓTa×MÏw]:
tð'u×b'×^R]}I½vÙ7µÛÂ5ÛµÞ×}B³]÷­wì¶µßÐ×¯^55Ýxàùµã¦×»^vÝyí6õçÐò×­Ç£^¹½zí9µëÖ×½Ë»^ùý{ñ6µóUµó^×Î³_t"½}Øûu÷.×ÞÇm5N]´àööÓ°bÛOO£m=ÝµÑöÛakÛmÑkmºÍ¶í8vßcÚÛ}TÛ
§mû>í¸à ¶ãp¦ÛÁn;    ý¹ÔK6çafÛ\`)`)[1]
```
[JSFiddle](http://jsfiddle.net/hw5mjLon/), the special charecters keep having issues
~~I hate to use an object and then search through it but I'll try to golf this more when I get access to a computer~~. Updated
Template Strings are the same length as regular strings so it doesn't matter. `.exec` actually stores the capture groups starting in `[1]` which adds another unavoidable 3 bytes, JavaScript's RegEx also doesn't support lookbehind but that wouldn't matter because that would be longer
I'm using `atob` which is used to convert from Base64 but if you use it the other way, you can chop off about a hundred bytes
[Answer]
# Python 2, 405 401 bytes
Call `w(e)` to print the weight of element e:
```
def w(e):import re;print reduce(lambda c,(_,d):c+int(d)-1,re.findall(r"(\D+)(\d+)",re.match(".*%s\d"%e,"H2He4Li4Be3B3C2N3O3F4Ne2Na4Mg2Al4Si2P4S2Cl4Ar6K0Ca2Sc6Ti4V4Cr2Mn4Fe2Co4Ni1Cu6Zn2Ga6Ge4As3Se5Br2Kr5Rb2Sr4Y2Zr3Nb3Mo4Tc3Ru4Rh3Pd4Ag3Cd5In4Sn5Sb4Te7I0Xe5Cs3Ba5La3Ce2Pr2Nd4Pm2Sm6Eu3Gd6Tb3Dy5Ho3Er3Tm3Yb5Lu3Hf4Ta4W4Re3Os5Ir3Pt4Au3Hg5Tl4Pb4Bi3Po1At2Rn13Fr2Ra4Ac2Th6Pa0U8Np0Pu8Am0Cm5Bk1Cf5Es2Fm6").group()),0)
```
Tests:
```
w("O")
w("Sn")
w("H")
w("Fm")
```
Output:
```
16
119
1
257
```
**Updated** - now 401 bytes
I was sure those nested regexs were too wordy, so I've managed to drop one of them, and put in a beautifully convoluted lambda instead :-)
```
def w(e):import re;print reduce(lambda(r,m),(l,d):(r+m*(int(d)-1),m*(l!=e)),re.findall(r"(\D+)(\d+)","H2He4Li4Be3B3C2N3O3F4Ne2Na4Mg2Al4Si2P4S2Cl4Ar6K0Ca2Sc6Ti4V4Cr2Mn4Fe2Co4Ni1Cu6Zn2Ga6Ge4As3Se5Br2Kr5Rb2Sr4Y2Zr3Nb3Mo4Tc3Ru4Rh3Pd4Ag3Cd5In4Sn5Sb4Te7I0Xe5Cs3Ba5La3Ce2Pr2Nd4Pm2Sm6Eu3Gd6Tb3Dy5Ho3Er3Tm3Yb5Lu3Hf4Ta4W4Re3Os5Ir3Pt4Au3Hg5Tl4Pb4Bi3Po1At2Rn13Fr2Ra4Ac2Th6Pa0U8Np0Pu8Am0Cm5Bk1Cf5Es2Fm6"),(0,1))[0]
```
[Answer]
# Python 2 ~~364~~, ~~335~~, 324 bytes
## 3rd attempt
Last program, which beats all non cjam entries.
```
#coding:latin1
c="ôÜÅÌ¿ß*[hÌ¹IÊALu>-\ÏÃnay,ÃU[ŠáŠJðûC¢\rýÑÏR¬\0W¶°ò£w¿<M¹KŸ0I\fî1Ž[b¥!iÖœ­C>÷©€)rë>:öæö\nœèãbXñ0Èéà8J¯6sõ'ìA±+yï#»ÀÙ<Š=Ùï"
n=sum([ord(c[i])*256**i for i in range(145)])
w=raw_input()+'q'
s=1
while n and n%541!=ord(w[0])*21+ord(w[1])-1464:
    n/=541;s+=n%6;n/=6
print(s,s+7)[s>210]
```
## 2nd attempt
Here's a second tentative, but it's still not very statisfactory. I can get 335 bytes by first building a table 676 bits, then get the position of a pair of letters by counting the elements preceding it int the table, and finally get the mass using a 100 bytes table. Both tables are specified in latin1 in order to get values over 128.
```
#coding:latin1
w=raw_input()+'`'
o=ord
print(o("ájñ&IÐÃ    ÏõN\n&nù!õ92>¡¥ú6ÿÝDG°Ç£}qŸ%R­5^[9ëŒåÍhÏÁòàSžeÜcx+MuV³`~æ.Ê§ì1¶W«?Y"[''.join(['{:08b}'.format(o(k))for k in "îóÃçuûüÇË/ÿÿÿßÿüŸ÷÷¿ìÿÿûÇ÷ÿýßÿÿÿýÿÿßßýÿïÏþ'~ÿßÿûø¿Öÿÿÿóo¿}.çÅÿ÷ÿÿþÿÿÿßÿÿÿßÿÿ_ÿÿÿÿ»ÿ"])[:o(w[0])*27+o(w[1])-1851].count('0')])+2,1)[w=='H`']
```
## 1st attempt 364
I think Python is a pretty good challenge for this game. I've tried to encode the different strings, but my decoder is always too big. And since python is very verbose and all characters appearing in the file have to be printable, it's pretty hard to get a small program. Here's my best solution so far:
```
w=raw_input()
x='HqHeLiBeBqCqNqOqFqNeNaMgAlSiPqSqClKqCaArScTiVqCrMnFeNiCoCuZnGaGeAsSeBrKrRbSrYqZrNbMoTcRuRhPdAgCdInSnSbIqTeXeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaWqReOsIrPtAuHgTlPbBiPoAtRnFrRaAcPaThNpUqAmPuBkCmCfEsFm'.find((w,w+'q')[len(w)<2])/2
print (1,8)[x>84]+sum(map(int,str(int('2zbca9fh3fq7op0ta54q928z3xc5l7hp7yyu1in8al1iis2fkjt91pxi0kkgw94f',36)))[:x])
```
which does not use big ideas, just the differences are encoded in base 6, then base 36, the maximum of int build-in.
[Answer]
# Python3, ~~856~~ 660 bytes
```
print(dict(H=1,He=4,Li=7,Be=9,B=11,C=12,N=14,O=16,F=19,Ne=20,Na=23,Mg=24,Al=27,Si=28,P=31,S=32,Cl=35,Ar=40,K=30,Ca=40,Sc=45,Ti=48,V=51,Cr=52,Mn=55,Fe=56,Co=58,Ni=58,Cu=64,Zn=65,Ga=70,Ge=73,As=75,Se=79,Br=80,Kr=84,Rb=85,Sr=88,Y=89,Zr=91,Nb=93,Mo=96,Tc=98,Ru=101,Rh=103,Pd=106,Ag=108,Cd=112,In=115,Sn=119,Sb=122,Te=128,I=127,Xe=131,Cs=133,Ba=137,La=139,Ce=140,Pr=141,Nd=144,Pm=145,Sm=150,Eu=152,Gd=157,Tb=159,Dy=163,Ho=165,Er=167,Tm=169,Yb=173,Lu=175,Hf=178,Ta=181,W=184,Re=186,Os=190,Ir=192,Pt=195,Au=197,Hg=201,Tl=204,Pb=207,Bi=209,Po=209,At=210,Rn=222,Fr=223,Ra=226,Ac=227,Th=232,Pa=231,U=238,Np=237,Pu=244,Am=243,Cm=247,Bk=247,Cf=251,Es=252,Fm=257)[input()])
```
Thanks to [@Sp3000](https://codegolf.stackexchange.com/users/21487/sp3000), I could save a whopping 196 bytes!
Test it [here](http://rextester.com/YCXJ37171)
---
Old version (856 bytes):
```
print({"H":1,"He":4,"Li":7,"Be":9,"B":11,"C":12,"N":14,"O":16,"F":19,"Ne":20,"Na":23,"Mg":24,"Al":27,"Si":28,"P":31,"S":32,"Cl":35,"Ar":40,"K":39,"Ca":40,"Sc":45,"Ti":48,"V":51,"Cr":52,"Mn":55,"Fe":56,"Co":59,"Ni":59,"Cu":64,"Zn":65,"Ga":70,"Ge":73,"As":75,"Se":79,"Br":80,"Kr":84,"Rb":85,"Sr":88,"Y":89,"Zr":91,"Nb":93,"Mo":96,"Tc":98,"Ru":101,"Rh":103,"Pd":106,"Ag":108,"Cd":112,"In":115,"Sn":119,"Sb":122,"Te":128,"I":127,"Xe":131,"Cs":133,"Ba":137,"La":139,"Ce":140,"Pr":141,"Nd":144,"Pm":145,"Sm":150,"Eu":152,"Gd":157,"Tb":159,"Dy":163,"Ho":165,"Er":167,"Tm":169,"Yb":173,"Lu":175,"Hf":178,"Ta":181,"W":184,"Re":186,"Os":190,"Ir":192,"Pt":195,"Au":197,"Hg":201,"Tl":204,"Pb":207,"Bi":209,"Po":209,"At":210,"Rn":222,"Fr":223,"Ra":226,"Ac":227,"Th":232,"Pa":231,"U":238,"Np":237,"Pu":244,"Am":243,"Cm":247,"Bk":247,"Cf":251,"Es":252,"Fm":257}[input()])
```
[Answer]
## JavaScript 344 337 chars
Code:  
Since it has some special chars and will not work when adding to to SO as a snippet, here is a link: <https://jsfiddle.net/stefnotch/gz3hu8bq/2/>
Hexdump:
```
0000000: 733d 3e61 6c65 7274 2852 6567 4578 7028  s=>alert(RegExp(
0000010: 6024 7b73 7d28 5c5c 5729 6029 2e65 7865  `${s}(\\W)`).exe
0000020: 6328 2248 7b48 657e 4c69 c281 4265 c283  c("H{He~Li..Be..
0000030: 42c2 8543 c286 4ec2 884f c28a 46c2 8d4e  B..C..N..O..F..N
0000040: 65c2 8e4e 61c2 914d 67c2 9241 6cc2 9553  e..Na..Mg..Al..S
0000050: 69c2 9650 c299 53c2 9a43 6cc2 9d41 72c2  i..P..S..Cl..Ar.
0000060: a24b c2a1 4361 c2a2 5363 c2a7 5469 c2aa  .K..Ca..Sc..Ti..
0000070: 56c2 ad43 72c2 ae4d 6ec2 b146 65c2 b243  V..Cr..Mn..Fe..C
0000080: 6fc2 b54e 69c2 b543 75c2 ba5a 6ec2 bb47  o..Ni..Cu..Zn..G
0000090: 61c3 8047 65c3 8341 73c3 8553 65c3 8942  a..Ge..As..Se..B
00000a0: 72c3 8a4b 72c3 8e52 62c3 8f53 72c3 9259  r..Kr..Rb..Sr..Y
00000b0: c393 5a72 c395 4e62 c397 4d6f c39a 5463  ..Zr..Nb..Mo..Tc
00000c0: c39c 5275 c39f 5268 c3a1 5064 c3a4 4167  ..Ru..Rh..Pd..Ag
00000d0: c3a6 4364 c3aa 496e c3ad 536e c3b1 5362  ..Cd..In..Sn..Sb
00000e0: c3b4 5465 c3ba 49c3 b958 65c3 bd43 73c3  ..Te..I..Xe..Cs.
00000f0: bf42 61c4 834c 61c4 8543 65c4 8650 72c4  .Ba..La..Ce..Pr.
0000100: 874e 64c4 8a50 6dc4 8b53 6dc4 9045 75c4  .Nd..Pm..Sm..Eu.
0000110: 9247 64c4 9754 62c4 9944 79c4 9d48 6fc4  .Gd..Tb..Dy..Ho.
0000120: 9f45 72c4 a154 6dc4 a359 62c4 a74c 75c4  .Er..Tm..Yb..Lu.
0000130: a948 66c4 ac54 61c4 af57 c4b2 5265 c4b4  .Hf..Ta..W..Re..
0000140: 4f73 c4b8 4972 c4ba 5074 c4bd 4175 c4bf  Os..Ir..Pt..Au..
0000150: 4867 c583 546c c586 5062 c589 4269 c58b  Hg..Tl..Pb..Bi..
0000160: 506f c58b 4174 c58c 526e c598 4672 c599  Po..At..Rn..Fr..
0000170: 5261 c59c 4163 c59d 5468 c5a2 5061 c5a1  Ra..Ac..Th..Pa..
0000180: 55c5 a84e 70c5 a750 75c5 ae41 6dc5 ad43  U..Np..Pu..Am..C
0000190: 6dc5 b142 6bc5 b143 66c5 b545 73c5 b646  m..Bk..Cf..Es..F
00001a0: 6dc5 bb22 295b 315d 2e63 6861 7243 6f64  m..")[1].charCod
00001b0: 6541 7428 292d 3132 3229 0a              eAt()-122).
```
Even more golfed:
<https://jsfiddle.net/stefnotch/gz3hu8bq/4/>
Hexdump:
```
0000000: 733d 3e65 7661 6c28 602f 247b 737d 285c  s=>eval(`/${s}(\
0000010: 5c57 292f 2e65 7865 6328 2248 7b48 657e  \W)/.exec("H{He~
0000020: 4c69 c281 4265 c283 42c2 8543 c286 4ec2  Li..Be..B..C..N.
0000030: 884f c28a 46c2 8d4e 65c2 8e4e 61c2 914d  .O..F..Ne..Na..M
0000040: 67c2 9241 6cc2 9553 69c2 9650 c299 53c2  g..Al..Si..P..S.
0000050: 9a43 6cc2 9d41 72c2 a24b c2a1 4361 c2a2  .Cl..Ar..K..Ca..
0000060: 5363 c2a7 5469 c2aa 56c2 ad43 72c2 ae4d  Sc..Ti..V..Cr..M
0000070: 6ec2 b146 65c2 b243 6fc2 b54e 69c2 b543  n..Fe..Co..Ni..C
0000080: 75c2 ba5a 6ec2 bb47 61c3 8047 65c3 8341  u..Zn..Ga..Ge..A
0000090: 73c3 8553 65c3 8942 72c3 8a4b 72c3 8e52  s..Se..Br..Kr..R
00000a0: 62c3 8f53 72c3 9259 c393 5a72 c395 4e62  b..Sr..Y..Zr..Nb
00000b0: c397 4d6f c39a 5463 c39c 5275 c39f 5268  ..Mo..Tc..Ru..Rh
00000c0: c3a1 5064 c3a4 4167 c3a6 4364 c3aa 496e  ..Pd..Ag..Cd..In
00000d0: c3ad 536e c3b1 5362 c3b4 5465 c3ba 49c3  ..Sn..Sb..Te..I.
00000e0: b958 65c3 bd43 73c3 bf42 61c4 834c 61c4  .Xe..Cs..Ba..La.
00000f0: 8543 65c4 8650 72c4 874e 64c4 8a50 6dc4  .Ce..Pr..Nd..Pm.
0000100: 8b53 6dc4 9045 75c4 9247 64c4 9754 62c4  .Sm..Eu..Gd..Tb.
0000110: 9944 79c4 9d48 6fc4 9f45 72c4 a154 6dc4  .Dy..Ho..Er..Tm.
0000120: a359 62c4 a74c 75c4 a948 66c4 ac54 61c4  .Yb..Lu..Hf..Ta.
0000130: af57 c4b2 5265 c4b4 4f73 c4b8 4972 c4ba  .W..Re..Os..Ir..
0000140: 5074 c4bd 4175 c4bf 4867 c583 546c c586  Pt..Au..Hg..Tl..
0000150: 5062 c589 4269 c58b 506f c58b 4174 c58c  Pb..Bi..Po..At..
0000160: 526e c598 4672 c599 5261 c59c 4163 c59d  Rn..Fr..Ra..Ac..
0000170: 5468 c5a2 5061 c5a1 55c5 a84e 70c5 a750  Th..Pa..U..Np..P
0000180: 75c5 ae41 6dc5 ad43 6dc5 b142 6bc5 b143  u..Am..Cm..Bk..C
0000190: 66c5 b545 73c5 b646 6dc5 bb22 295b 315d  f..Es..Fm..")[1]
00001a0: 2e63 6861 7243 6f64 6541 7428 292d 3132  .charCodeAt()-12
00001b0: 3260 290a                                2`).
```
It uses RegExp to find the appropriate char from the string then it converts to it's Unicode value and subtracts something.  
I wonder if this can be shortened even further.  
Credits: manatwork, vihan1086 ([Mass of elements](https://codegolf.stackexchange.com/questions/52257/mass-of-elements/52260#52260))
[Answer]
# Rev 1, Ruby, 327
I'm fairly new to Ruby, so thanks to **ManAtWork** for refactoring and massively improving the code part of my program, for a saving of 42 bytes.
```
"1H3He3Li2Be2B1C2N2O3F1Ne3Na1Mg3Al1Si3P1S3Cl4K1Ar0Ca5Sc3Ti3V1Cr3Mn1Fe3Co0Ni5Cu1Zn5Ga3Ge2As4Se1Br4Kr1Rb3Sr1Y2Zr2Nb3Mo2Tc3Ru2Rh3Pd2Ag4Cd3In4Sn3Sb5I1Te3Xe2Cs4Ba2La1Ce1Pr3Nd1Pm5Sm2Eu5Gd2Tb4Dy2Ho2Er2Tm4Yb2Lu3Hf3Ta3W2Re4Os2Ir3Pt2Au4Hg3Tl3Pb2Bi0Po1At12Rn1Fr3Ra1Ac4Pa1Th5Np1U5Am1Pu3Cm0Bk4Cf1Es5Fm0"=~/#{gets}\d/
p eval($`.gsub /\D/,?+)
```
As far as I can tell, it works like this:
the `=~` ("match") operator searches the data for an incidence of a string of type `/#{gets}\d/` where `#{gets}` is an element input by the user and `\d` can be any number. This returns the position/index where the element occurs in the big string, but the return value is thrown away.
`$'` (not used here) is a special global variable which contains the part of the string to the right of the last match. `$``  is the complementary special global variable which contains the part of the string to the left of the last match. This is basically the truncated string from my rev 0.
The remaining code to subsitute all the letters for `+`symbols and evaluate the expression formed works in the same way as my original answer, except that ManAtWork has improved my original `.gsub(/[A-z]/,'+')` to `.gsub /\D/,?+`
# Rev 0, Ruby, 369
```
s="1H3He3Li2Be2B1C2N2O3F1Ne3Na1Mg3Al1Si3P1S3Cl4K1Ar0Ca5Sc3Ti3V1Cr3Mn1Fe3Co0Ni5Cu1Zn5Ga3Ge2As4Se1Br4Kr1Rb3Sr1Y2Zr2Nb3Mo2Tc3Ru2Rh3Pd2Ag4Cd3In4Sn3Sb5I1Te3Xe2Cs4Ba2La1Ce1Pr3Nd1Pm5Sm2Eu5Gd2Tb4Dy2Ho2Er2Tm4Yb2Lu3Hf3Ta3W2Re4Os2Ir3Pt2Au4Hg3Tl3Pb2Bi0Po1At12Rn1Fr3Ra1Ac4Pa1Th5Np1U5Am1Pu3Cm0Bk4Cf1Es5Fm0"
e=gets
puts eval(s[0..s.gsub(/[0-9]/,'*').index(e+'*')-1].gsub(/[A-z]/,'+'))
```
The numbers in the string correspond to the difference between an element and the previous one (elements are in atomic mass order, not atomic number order, so the difference is always positive.)
The first `gsub` replaces all numbers with `*`. Then we search for `<element name>+"*"` to find the index of the element (the appended `*` is necessary to avoid confusing for example, `Be` and `B` because one is a substring of the other.)
The second `gsub` replaces all letters with `+`. This produces an expression that gives the mass of the element: `1+3++3++2...` (Ruby does not care about the duplicate `+`, presumably it considers the second `+` to be a unary `+`.) All that remains is to truncate the expression at the index mentioned above, and evaluate it.
[Answer]
# [Python 3](https://docs.python.org/3/), 560 bytes
```
import functools as f
n="HᱨἬᨊBCNOFỆᶎỻ᭬∋PS᱄ᳲKᥣ’≴Vᷖ№ᮞᴍ῾ẟ⚬᫧ᰃᴳ₿ᵤⅦὤ⓶Y⠔ᷜⅣ⁼╺⅐ὀᨧᨬ὞⎪ῆℤI⊸ḙᤂ᳌ᩯ⎠Ṹ∐⍗ᾉᮼ
․ἸẺ⏄−⊼Ჰ῔W⁚⍽₂⑀ᶵ᳸⍰Ạᬒ⊰ᵴ⌼Ἤἒᤣ∠ṐU∠⒐ᮭᲇᮖ᪲ỿ᷎"
m="!$')+,.03478;<?@CHGHMPSTWX[[`afikoptuxy{}€‚…‡ŠŒ“—š Ÿ£¥©«¬­°±¶¸½¿ÃÅÇÉÍÏÒÕØÚÞàãåéìïññòþÿĂăĈćĎčĔēėėěĜġ"
i=lambda w:f.reduce(lambda l,c:l*ord(c),list(w),1)
print(str(ord(m[n.find(chr(i(input())))])-32))
```
[Try it online!](https://tio.run/##LU99a1JhHP3fT2ESdG/ZqBYUq1E0qEW0BqtWjCDTyS7pVfTKGhE4X6az6cy9NRvO0DW33Tnf5kyvXnie@0XO74vYHXTOHwfOORw4/iVlwSePDoeS1@8LKFZ3SHYqPp8naHUErW6LPG6bRL0CTUUl9WRi6tVT9FbQzqDXw6lKye/TM6jH0Gy8wEGJwru02nqLi22KbaNaQCsNfYDuPuVVnByiFkWrSREd52WK/0G/TBvt91TcxMUexUu0rNFWl@JZ9MOoHKKiol@gzDH0FYqVn1Oqg84uyhE013B0Rpki/nYomaX0DgarqGoUrlC4DK2DbpfWY5TMUUpDowZ9c5aW85TuUyRCP8Jon6PZoXQN3SJUs1TDeYvWtMuPWg7lEiXN6ewbUyiXRfUUjQSq2zhuoKfjImOzeMdtV65eE2/YR26N3r13/8HDR48nJp9NvpyeeT37bm7uo8Mtffb5ldCXpa/fWJhFWJwlWIqtsSzbYDssz4psn5XYATtiJ0xlp6zG6qzNOqzPdB7lcZ7gqzzN13mOb/GfPM8LvMhL/IAfcZWf8brJBh9w3YgYUSNpJIyMkTY2jQ1jx@QvY8/4bbNI4x6H95PLYV0cc48E5l0h57zw3/HYnWOe676AS3CKdo8UVIRF0X5btPgDkqwIQSUgXGbeOXnELclmaSEgSIIk@0OKIJr4IN4cvSOKw@GU4x8 "Python 3 – Try It Online")
Explanation: So 2 variables, `n` and `m` are used to hold the abbreviations (more described below) and the elements atomic mass as strings. The input is then encrypted into a character to match to some character in `n`, using the string.find, an index of where the character is can be used to find the respective atomic mass in `m`. Due to shifting the mass values by 32 previously, they must be unshifted, then this number is output.
Each character of `n` is the ascii of the product of the ascii values of the characters in the name
Each character of `m` is the ascii of mass + 32
Below is the setup code for `m` and `n`
```
obfNames=""
for name in names:
    prod=1
    for c in name:
        prod*=ord(c)
    obfNames+=chr(prod)
obfMass=""
for m in mass:
    obfMass+=chr(int(m)+32)
for c in obfNames:
    print(c,end="")
print()
for c in obfMass:
    print(c,end="")
```
[Try it online!](https://tio.run/##XZRLc9pAEITv/AqKE8Q@sCskJFdxEAoGKoApIA8n5QPmEaiERwE5@NcT5mthO/Ghd@np6XksZv9yWu22wfm8nW4Wx8aPUqd0Wyx1Foa9tWGTe9MgMxgYPBjc85HwYGrY/2mY/jYckzzkSi5sejD8BEHKeGY4QfwFGkV/SwG8sx0VkGR/DL8TbWPQRpMeMVOrqgGOnuG5P5LKdQDdx3hCByOMRyuanmPJMBn3LgXHQnInlOoafFOXdNCkpx6YwQ9VEJvhBgOwRcE2/ATLjy@snqZaZE1QPhLtoe8s4fH/SscUeaB4l6Thie4lZ4YJqx9i09SzUCRFOdKqtS6MU72JdgHzmRn2EBindJaBzV/c6axFI/eb0lNhMz3a98kZUTOoGyQGDtJ5kJiLQKK@CgYgUU@qjw0DcgNygxBz9EHydq@JRx@iD9GH8CG1wuQNI6pEROs41KleF4Mmho9RxvAx/jHRhCoJWQn@CVFX1ajVQIfGrCqWL8CFOrQaL1LDOk3uNLQL5BLkpBI0sqtJUtM6tQEXKqbpXag8zewimWlqFykWKabxneZ3dfUSq4JW4OL8xVQhUYVECYneS7P7qt6wmpPJ@8PprTW0z9/cRzqUoKf2WoEPYh2KaVpfy78r9feHHt5rdn@Z/amwe14O@JkrlQrL3aFov3nF9ZbzeFcoXv72h9284biaYnYNK3pVfGjsDvPyrAJ5db1pzFaHsoUrVqlv3/@80MZs7B/i7pphUSWst6fypnIT@ErhteLV8tqTaWa3i@38Ylgp6PO/8v6r@f/q8/kv)
[Answer]
# [R](https://www.r-project.org/), ~~301~~ ~~289~~ ~~287~~ 273 bytes
Explanation.
Look up the index of the mass sorted atomic number in a UTF8 encoded hash string `s`. The hash is taken by taking the element name, encoding it as ASCII, multiplying by a 2-vector encoded with UTF-8 and modding three times in succession. The operator `+` is used for the UTF8 to integer vector conversion.
Encode the masses of the elements as a UTF8 encoded string of differences, packing 2 differences into each byte as `9*d1 + d2` where `d1` is the difference of the nth element and `d2` is the successive mass difference of the n+50th element. Then to retrieve the mass, take the corresponding position at the cumulative sum of the differences. This is shorter than a quadratic formula.
```
function(x)sum(c(o%%9,o%/%9)[1:match(sum(+x*+"
")%%740%%623%%278,+'{ćWZ}èċæŸ+Ó>qÿƒ!2Eo&ē_
u½8`h›’Hb‰¹ĎŽ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5qraZ450jR3UZgcO5bpGtfFyiDK4j2decW7HxTVU@dUQ9P8kkV029E0m25ZXDj7xfyby9e@nD2ZH85@l78tzh6feuv1j8989dnsb/nwHfvltdH788c3335h@ob868Vgd08eyR/rt@R38tn8kXwkDz8ppr1w9nB2pM2enb@xIx@sbN650p/9uvpqW34vf5K/bF2Sfw5M@cO2/MPtzA4zL36z9pr/0ulX3pVPl@df3xeVBeOGUVCLanma9YLOaGOYFUblorp6sSkf1G8mSeOgsds46EfNswv/PAk/tQ6K8mhZ/vzh7jn57aJ63O2Vu1EWLfXG0SDRh2WxIizL/Pc/tnzyX2vuj5NuGmdJd4l/H@WdJM5G4/R@ovcM/YRkmFGcTaN@Tsl/R0ah23uvm07icbIfDeN75aXWOB2kWfp5opNpQ6fj/1SZFP6/FQscPwc "R – Try It Online") which *nearly* beats the R record by encoding three mass differences in mixed base 6,5.
[Answer]
# PHP 4.1, ~~645~~ ~~643~~ 641 bytes
This is not the best idea, it may be possible to minimize a little more.
```
<?$V=split(A,A1A4A7A9AbAcAeAgAjAkAnAoArAsAvAwAzA14A13A14A19A1cA1fA1gA1jA1kA1nA1nA1sA1tA1yA21A23A27A28A2cA2dA2gA2hA2jA2lA2oA2qA2tA2vA2yA30A34A37A3bA3eA3kA3jA3nA3pA3tA3vA3wA3xA40A41A46A48A4dA4fA4jA4lA4nA4pA4tA4vA4yA51A54A56A5aA5cA5fA5hA5lA5oA5rA5tA5tA5uA66A67A6aA6bA6gA6fA6mA6lA6sA6rA6vA6vA6zA70A75);echo base_convert($V[array_search($E,array(H,He,Li,Be,B,C,N,O,F,Ne,Na,Mg,Al,Si,P,S,Cl,Ar,K,Ca,Sc,Ti,V,Cr,Mn,Fe,Co,Ni,Cu,Zn,Ga,Ge,'As',Se,Br,Kr,Rb,Sr,Y,Zr,Nb,Mo,Tc,Ru,Rh,Pd,Ag,Cd,In,Sn,Sb,Te,I,Xe,Cs,Ba,La,Ce,Pr,Nd,Pm,Sm,Eu,Gd,Tb,Dy,Ho,Er,Tm,Yb,Lu,Hf,Ta,W,Re,Os,Ir,Pt,Au,Hg,Tl,Pb,Bi,Po,At,Rn,Fr,Ra,Ac,Th,Pa,U,Np,Pu,Am,Cm,Bk,Cf,Es,Fm))+1],36,10);
```
Sadly, I've seen myself forced to use Base36 instead of Base96.
To use it, simply set the key `E` in POST/GET/SESSION with the name of the element.
To emulate it in newer versions, simply add `$E=<element name>;` before `$V`.
You can test it on <http://rextester.com/OMAA85454>
[Answer]
# PHP, 893 695 bytes
```
function a($e,$m=[H,1,He,4,Li,7,Be,9,B,11,C,12,N,14,O,16,F,19,Ne,20,Na,23,Mg,24,Al,27,Si,28,P,31,S,32,Cl,35,Ar,40,K,39,Ca,40,Sc,45,Ti,48,V,51,Cr,52,Mn,55,Fe,56,Co,59,Ni,59,Cu,64,Zn,65,Ga,70,Ge,73,'As',75,Se,79,Br,80,Kr,84,Rb,85,Sr,88,Y,89,Zr,91,Nb,93,Mo,96,Tc,98,Ru,101,Rh,103,Pd,106,Ag,108,Cd,112,In,115,Sn,119,Sb,122,Te,128,I,127,Xe,131,Cs,133,Ba,137,La,139,Ce,140,Pr,141,Nd,144,Pm,145,Sm,150,Eu,152,Gd,157,Tb,159,Dy,163,Ho,165,Er,167,Tm,169,Yb,173,Lu,175,Hf,178,Ta,181,W,184,Re,186,Os,190,Ir,192,Pt,195,Au,197,Hg,201,Tl,204,Pb,207,Bi,209,Po,209,At,210,Rn,222,Fr,223,Ra,226,Ac,227,Th,232,Pa,231,U,238,Np,237,Pu,244,Am,243,Cm,247,Bk,247,Cf,251,Es,252,Fm,257]){return $m[array_search($e,$m)+1];}
```
The usage of the function is to omit the 2nd argument, eg
```
echo a('Ra'); // returns 226
```
Requires PHP >=5.4 to allow `[...]` for array declaration and suppressing errors (at least `error_reporting(~E_NOTICE)` is given or there is the same clause in the php.ini file).
The `As` needs to be in quotes because it is considered as a reserved keyword.
[Answer]
# Ruby: ~~474~~ 468 characters
```
f=->e{"H1He4Li7Be9B11C12N14O16F19Ne20Na23Mg24Al27Si28P31S32Cl35Ar40K39Ca40Sc45Ti48V51Cr52Mn55Fe56Co59Ni59Cu64Zn65Ga70Ge73As75Se79Br80Kr84Rb85Sr88Y89Zr91Nb93Mo96Tc98Ru101Rh103Pd106Ag108Cd112In115Sn119Sb122Te128I127Xe131Cs133Ba137La139Ce140Pr141Nd144Pm145Sm150Eu152Gd157Tb159Dy163Ho165Er167Tm169Yb173Lu175Hf178Ta181W184Re186Os190Ir192Pt195Au197Hg201Tl204Pb207Bi209Po209At210Rn222Fr223Ra226Ac227Th232Pa231U238Np237Pu244Am243Cm247Bk247Cf251Es252Fm257"=~/#{e}(\d+)/;$><<$1}
```
Sample run:
```
irb(main):001:0> f=->e{"H1He4Li7Be9B11C12N14O16F19Ne20Na23Mg24Al27Si28P31S32Cl35Ar40K39Ca40Sc45Ti48V51Cr52Mn55Fe56Co59Ni59Cu64Zn65Ga70Ge73As75Se79Br80Kr84Rb85Sr88Y89Zr91Nb93Mo96Tc98Ru101Rh103Pd106Ag108Cd112In115Sn119Sb122Te128I127Xe131Cs133Ba137La139Ce140Pr141Nd144Pm145Sm150Eu152Gd157Tb159Dy163Ho165Er167Tm169Yb173Lu175Hf178Ta181W184Re186Os190Ir192Pt195Au197Hg201Tl204Pb207Bi209Po209At210Rn222Fr223Ra226Ac227Th232Pa231U238Np237Pu244Am243Cm247Bk247Cf251Es252Fm257"=~/#{e}(\d+)/;$><<$1}
=> #<Proc:0x00000001e59d08@(irb):2 (lambda)>
irb(main):002:0> f["K"]
39=> #<IO:<STDOUT>>
```
Online run:
<http://rextester.com/edit/UMNY88866>
[Answer]
# SAS, 351 (chars) 791 (bytes) 454 bytes
Borrowing from the concept posted by Sp3000, using a quadratic regression to model the positional offsets mass = floor(o\*0.715+0.00031\*o\*o+1.7)+e where o represents the offset and e is the known error from actual.
```
%macro m(e);data;s='H-1He0Li1Be1B0C0N1O1F3Ne2Na3Mg2Al3Si01P1S01Cl2Ar5K01Ca0Sc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po-At19Rn-Fr1Ra-Ac2Pa-Th3Np-U4Am-Pu1Cm--Bk2Cf-Es1Fm"
  .split(RegExp(e+'[^a-z].*'))[0]
  .split('')
  .reduce(function(o,n) {
    return +n ? +n+o : n=='-' ? --o : ++o;
  })
}
```
The elements are stored in a string of numbers symbols and minus characters. The mass of any given element is the number of letter characters preceding it, plus the sum of digits subtracted by the occurrences of `-`.
## Tests:
```
var a = [
  'H', 1,
  'He', 4,
  'Li', 7,
  'Be', 9,
  'B', 11,
  'C', 12,
  'N', 14,
  'O', 16,
  'F', 19,
  'Ne', 20,
  'Na', 23,
  'Mg', 24,
  'Al', 27,
  'Si', 28,
  'P', 31,
  'S', 32,
  'Cl', 35,
  'Ar', 40,
  'K', 39,
  'Ca', 40,
  'Sc', 45,
  'Ti', 48,
  'V', 51,
  'Cr', 52,
  'Mn', 55,
  'Fe', 56,
  'Co', 59,
  'Ni', 59,
  'Cu', 64,
  'Zn', 65,
  'Ga', 70,
  'Ge', 73,
  'As', 75,
  'Se', 79,
  'Br', 80,
  'Kr', 84,
  'Rb', 85,
  'Sr', 88,
  'Y', 89,
  'Zr', 91,
  'Nb', 93,
  'Mo', 96,
  'Tc', 98,
  'Ru', 101,
  'Rh', 103,
  'Pd', 106,
  'Ag', 108,
  'Cd', 112,
  'In', 115,
  'Sn', 119,
  'Sb', 122,
  'I', 127,
  'Te', 128,
  'Xe', 131,
  'Cs', 133,
  'Ba', 137,
  'La', 139,
  'Ce', 140,
  'Pr', 141,
  'Nd', 144,
  'Pm', 145,
  'Sm', 150,
  'Eu', 152,
  'Gd', 157,
  'Tb', 159,
  'Dy', 163,
  'Ho', 165,
  'Er', 167,
  'Tm', 169,
  'Yb', 173,
  'Lu', 175,
  'Hf', 178,
  'Ta', 181,
  'W', 184,
  'Re', 186,
  'Os', 190,
  'Ir', 192,
  'Pt', 195,
  'Au', 197,
  'Hg', 201,
  'Tl', 204,
  'Pb', 207,
  'Bi', 209,
  'Po', 209,
  'At', 210,
  'Rn', 222,
  'Fr', 223,
  'Ra', 226,
  'Ac', 227,
  'Pa', 231,
  'Th', 232,
  'U', 238,
  'Np', 237,
  'Pu', 244,
  'Am', 243,
  'Cm', 247,
  'Bk', 247,
  'Cf', 251,
  'Es', 252,
  'Fm', 257
];
function p(e) {
  return "1H2He1LiBeBC1N1O2FNe1Na-Mg1Al-Si1PS2Cl2KAr--Ca3Sc1Ti1VCr1Mn-Fe1Co--Ni3Cu-Zn3Ga1GeAs2Se-Br2Kr-Rb1Sr-Y1ZrNb1MoTc1RuRh1PdAg2Cd1In2Sn1Sb3ITe1XeCs2BaLa-Ce-Pr1Nd-Pm3SmEu3GdTb2DyHoErTm2YbLu1Hf1Ta1W1Re2OsIr1PtAu2Hg1Tl1PbBi--Po-At19Rn-Fr1Ra-Ac2Pa-Th3Np-U4Am-Pu1Cm--Bk2Cf-Es1Fm"
    .split(RegExp(e + '[^a-z].*'))[0]
    .split('')
    .reduce(function(o, n) {
      return +n ? +n + o : n == '-' ? --o : ++o;
    })
}
var $elementList = $('#elements');
for (var i = 0; i < a.length; i++) {
  var symbol = a[i];
  var mass = a[++i];
  var result = p(symbol);
  var resultString = "<li><b>" + symbol + "</b>";
  if (symbol.length === 1) resultString += "&nbsp;";
  resultString += " expected <b>" + mass + "</b>";
  if (mass < 10) resultString += "&nbsp;";
  if (mass < 100) resultString += "&nbsp;";
  resultString += " got <b>" + result + "</b></li>";
  $elementList.append(resultString);
}
```
```
#elements li {
  font-family: "Consolas", monospace;
}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul id="elements">
</ul>
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~373~~ 371 bytes
-2 bytes thanks to [ceilingcat](https://codegolf.stackexchange.com/users/52904/ceilingcat)
One string containing the elements is used for lookup. When an index is found, this is used to traverse the second string, each character of which holds two mass deltas, one per nibble. (Each character has also been increased by 32 to bring them into printable territory.) In other words, we do not save the masses of the elements, only how much they differ from the previous one, in a list sorted by mass.
Adding all these deltas together gets us the mass for half of the elements (the ones that are in even slots). If we are in an odd slot, we remove the last delta again.
```
x,w,c,i;f(char*e){char*E="H HeLiBeB C N O F NeNaMgAlSiP S ClK ArCaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbI TeXeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcPaThNpU AmPuCmBkCfEsFm",a[3]={*e++,*e?:32};for(x=strstr(E,a)-E,w=i=0;i<=x/4;w+=c%16+c/16-2)c="3RABQQQQT0sQQPqsD432CCCDTU3DA35EDBDCSDCDS@<34553$5"[i++];c=x&2?w:w-c%16;}
```
[Try it online!](https://tio.run/##VZRrb9pKEIY/h1@xspojCKCCjUkItXLsxVwUYhzbaZuk@WCbBaxySddwoIry23M8A7NqI6TwsDsz7zs7u2l9nqYfH4favpbWsu6snC5ieSEqb/jftbQhG4px5giHceaxCeszT3jx3dxehpnPQsaXt8yWPA7TKPvKuLxb9wXfeBnfPa0H8UDYeSgceSuDJJSP7El6yd0mSoNdsPCn9pxPR@twHSYjFonvgudOPI658KU39Vfhyt0NplHS@z3cuDJaPSbj3XAWxd9YICb5SPpbezecR0s/cTJ/Y2@DdV8GsZ36cbTwXh@YvfJ3fOX85DM376@0WvxsvFhvF6JarV2Im2tDf@/ONrJ8sPKtLD5ltxZX6m5tb2VWo5t9sQ6fW9191UrPm@1q@rnZruuV1NKMwHbui7@okd/f@7/yXsvQOee96MHo2Ybp9pweD3u8F/77xWiZpvHJ1J6zavWlm1qHf/Sb/fW@Dhm77x//bbIpm2PD2UWcJLLGsvWWicOrSLdiWim9lc7gByny3XLLLDYrw65Kt3RWOnuVxdKsrD2z85y9sPO6nrPz6Y@1VlP7LZWK3TBtcquxa6YxVuw4FjvuK9K9l0pQZxVn6zJWnZe1YbGtCaXguyigdYJxVsDlCRxY6RBACMVwAP0EHgAlmAC0T9AHoAQeZNMbRDGQcaK7ORDlsJdApCIESfrVifwCDJIRApAMDlGGSTkkuKJqt7BEQnj851KYAlFYBMVaVOxrAabyDBlNqnYHZ2FSWB@8mWSbb4CU7@xP4ruC2uT0CbK0KcsAhF2SsAHkvKQO2TkQ7QxxTR0NKLtSXpGoQpAAqThcI3uPAJTkCZY6ZNaDsI46HjDUIXsRdKxDSQIw1GxQYLBApEh/ikih9hyRYjmuqkEarRGV2COSwDDBoaPNkUCkVCMkmpnvuKjmhOeIJMqJEWnz@IjqhDBWzYcvEVVjUHKL2uuvEJVkRJNiXeyNmpkBxppUN0JDajJ6v/HqkMjhBpEyuyijrWKxUJtiHzGVGpYx1lXTMpwhUqsi9HtFjr4hqXlB91d0YBPsXIcMjVBFhwz5W0R157BshzQO8VKryYjwVjdU5xJE9dbgLW@QIX/zF9pQSG@SjAAmQ1ej0JeI5D7Ap0VXM5ciqs4t8OFRFo7vEIl8QKJOea@IFOrv8JVSz9QKkcryIypDP/9CDmegq8fEzRGVA4zFyXj/@B8 "C (gcc) – Try It Online")
[Answer]
# Python 2, ~~860~~ ~~859~~ 858 bytes
Based on @Cool Guy's version -
```
def f(x):print {"H":1,"He":4,"Li":7,"Be":9,"B":11,"C":12,"N":14,"O":16,"F":19,"Ne":20,"Na":23,"Mg":24,"Al":27,"Si":28,"P":31,"S":32,"Cl":35,"Ar":40,"K":39,"Ca":40,"Sc":45,"Ti":48,"V":51,"Cr":52,"Mn":55,"Fe":56,"Co":59,"Ni":59,"Cu":64,"Zn":65,"Ga":70,"Ge":73,"As":75,"Se":79,"Br":80,"Kr":84,"Rb":85,"Sr":88,"Y":89,"Zr":91,"Nb":93,"Mo":96,"Tc":98,"Ru":101,"Rh":103,"Pd":106,"Ag":108,"Cd":112,"In":115,"Sn":119,"Sb":122,"Te":128,"I":127,"Xe":131,"Cs":133,"Ba":137,"La":139,"Ce":140,"Pr":141,"Nd":144,"Pm":145,"Sm":150,"Eu":152,"Gd":157,"Tb":159,"Dy":163,"Ho":165,"Er":167,"Tm":169,"Yb":173,"Lu":175,"Hf":178,"Ta":181,"W":184,"Re":186,"Os":190,"Ir":192,"Pt":195,"Au":197,"Hg":201,"Tl":204,"Pb":207,"Bi":209,"Po":209,"At":210,"Rn":222,"Fr":223,"Ra":226,"Ac":227,"Th":232,"Pa":231,"U":238,"Np":237,"Pu":244,"Am":243,"Cm":247,"Bk":247,"Cf":251,"Es":252,"Fm":257}[x]
```
Usage -
```
f("K")
```
Output -
```
39
```
Try it [here](http://ideone.com/vwNXxw)
[Answer]
# Python 2, 630 bytes
Based on @Cool Guy's code, just packed all the strings into one and then used regexp to get them back. It saved me few bytes.
**edit:** rewrote mass list, just to be sure it's correct this time.
```
import re;print dict(zip(map(str.strip,re.findall("..","H HeLiBeB C N O F NeNaMgAlSiP S ClArK CaScTiV CrMnFeCoNiCuZnGaGeAsSeBrKrRbSrY ZrNbMoTcRuRhPdAgCdInSnSbTeI XeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaW ReOsIrPtAuHgTlPbBiPoAtRnFrRaAcThPaU NpPuAmCmBkCfEsFm")),(1,4,7,9,11,12,14,16,19,20,23,24,27,28,31,32,35,40,39,40,45,48,51,52,55,56,59,59,64,65,70,73,75,79,80,84,85,88,89,91,93,96,98,101,103,106,108,112,115,119,122,128,127,131,133,137,139,140,141,144,145,150,152,157,159,163,165,167,169,173,175,178,181,184,186,190,192,195,197,201,204,207,209,209,210,222,223,226,227,232,231,238,237,244,243,247,247,251,252,257)))[raw_input()]
```
[Answer]
# Javascript ES6, 620 bytes
This is a pretty basic one, like my PHP answer.
It uses base36 to encode the values.
```
s=>parseInt("1|4|7|9|b|c|e|g|j|k|n|o|r|s|v|w|z|14|13|14|19|1c|1f|1g|1j|1k|1n|1n|1s|1t|1y|21|23|27|28|2c|2d|2g|2h|2j|2l|2o|2q|2t|2v|2y|30|34|37|3b|3e|3k|3j|3n|3p|3t|3v|3w|3x|40|41|46|48|4d|4f|4j|4l|4n|4p|4t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b0Lu0Hf0Ta0W0Re0Os0Ir0Pt0Au0Hg0Tl0Pb0Bi0Po0At0Rn0Fr0Ra0Ac0Th0Pa0U0Np0Pu0Am0Cm0Bk0Cf0Es0Fm".split(0).indexOf(s)],36)}
document.getElementById('e').onkeyup=function(){
  document.getElementById('o').innerHTML=this.value?f(this.value):'';
}
```
```
<input type="text" id="e" placeholder="Element"><br>
<span>Element mass: <b id="o"></b></span> 
```
[Answer]
## Java, 414 407 Bytes
```
void m(String e){String s="5.=\\>i6K<35)<?<@CB/L<Y0 ?M0ZCL59?OOA&z.8KI>qCR2v@./D@>)JP22%Jh=[::[[email protected]](/cdn-cgi/l/email-protection)=5?:95h@H6)B+7J=J6~DH@*G?<xS*&xDw:<CX5L/A3$=H1`N0:rKW5nJ198:$8oD*:y=v<_CS6[H^:(An:nE<?`<u7T+*3Icj2y<].jLm /_}$7^U#;Ft)rD|33N#",a=s;int i=0,n=0,c,b;while(!a.equals(e)){c=s.charAt(i++)*95+s.charAt(i++)-3072;a=""+(char)(65+c%26);b=97+c/26%26;if(b!=122)a+=(char)b;c/=676;n+=c==9?12:c-1;}System.out.print(n);}
```
Usage: `m("He")`
The tuple `(element code, delta from previous element)` is transformed into an integer varying from 0 to 6760 (=26x26x10), then encoded in base 95 into the string.
It can be tested here: <http://rextester.com/VFXLG54655>
[Answer]
# Python 3, ~~500~~ 495
Pretty self-explanatory. Just use a regex built from the input to find the number after the element's abbreviation.
[**Try it here**](http://ideone.com/Gq4o1y)
```
import re
print(re.findall(r"(?<=%s)\d+"%input(),"H1He4Li7Be9B11C12N14O16F19Ne20Na23Mg24Al27Si28P31S32Cl35Ar40K39Ca40Sc45Ti48V51Cr52Mn55Fe56Co59Ni59Cu64Zn65Ga70Ge73As75Se79Br80Kr84Rb85Sr88Y89Zr91Nb93Mo96Tc98Ru101Rh103Pd106Ag108Cd112In115Sn119Sb122Te128I127Xe131Cs133Ba137La139Ce140Pr141Nd144Pm145Sm150Eu152Gd157Tb159Dy163Ho165Er167Tm169Yb173Lu175Hf178Ta181W184Re186Os190Ir192Pt195Au197Hg201Tl204Pb207Bi209Po209At210Rn222Fr223Ra226Ac227Th232Pa231U238Np237Pu244Am243Cm247Bk247Cf251Es252Fm257")[0])
```
[Answer]
# PHP, ~~415~~ ~~414~~ 387 bytes
```
<?preg_match("/\d".$_GET[e]."\d/",$b="2H3He4Li4Be6B2C3N3O5F4Ne4Na3Mg3Al2Si2P6S3Cl6Ar2K1Ca4Sc4Ti5V4Cr5Mn3Fe4Co1Ni3Cu2Zn4Ga5Ge4As6Se4Br5Kr4Rb4Sr3Y3Zr2Nb3Mo2Tc2Ru2Rh2Pd1Ag3Cd3In4Sn5Sb8Te4I6Xe6Cs7Ba6La5Ce3Pr3Nd1Pm4Sm3Eu5Gd4Tb6Dy5Ho4Er3Tm5Yb4Lu4Hf4Ta4W5Re6Os5Ir5Pt4Au6Hg6Tl6Pb5Bi2Po0At9Rn8Fr8Ra6Ac8Th4Pa8U5Np9Pu5Am6Cm4Bk5Cf3Es5Fm0",$m,256);$s=$m[0][1];echo round(.0003*$s*$s+.81*$s-1)+$b{$s};
```
This answer works basically off the same principle as Sp3000's CJam answer; I did a quadratic regression with the element's position in the `$b` string as the independent variable and molar mass as the dependent, then found the difference between the actual value and regression value for each element, and put it all into the $b string. I actually originally did this in Java, but then discovered that it takes a lot of bytes to do regex in Java.
I've never done a code golf before so please let me know if I'm doing something wrong here.
~~Edit: try it out [here](http://uvkk79d27f2c.vijrox.koding.io/ElementGolf.php)~~ (Actually, that link probably doesn't work)
Edit 2: [Ismael Miguel](https://codegolf.stackexchange.com/users/14732/ismael-miguel) helped me knock a bunch of bytes off of this!
[Answer]
# Powershell, 324 bytes
```
('1H3He3Li2Be2B1C2N2O3F1Ne3Na1Mg3Al1Si3P1S3Cl4K1ArCa5Sc3Ti3V1Cr3Mn1Fe3CoNi5Cu1Zn5Ga3Ge2As4Se1Br4Kr1Rb3Sr1Y2Zr2Nb3Mo2Tc3Ru2Rh3Pd2Ag4Cd3In4Sn3Sb5I1Te3Xe2Cs4Ba2La1Ce1Pr3Nd1Pm5Sm2Eu5Gd2Tb4Dy2Ho2Er2Tm4Yb2Lu3Hf3Ta3W2Re4Os2Ir3Pt2Au4Hg3Tl3Pb2BiPo1At12Rn1Fr3Ra1Ac4Pa1Th5Np1U5Am1Pu3CmBk4Cf1Es5Fm'-split"$args")[0]-replace'\D+','+'|iex
```
Test script:
```
$f = {
('1H3He3Li2Be2B1C2N2O3F1Ne3Na1Mg3Al1Si3P1S3Cl4K1ArCa5Sc3Ti3V1Cr3Mn1Fe3CoNi5Cu1Zn5Ga3Ge2As4Se1Br4Kr1Rb3Sr1Y2Zr2Nb3Mo2Tc3Ru2Rh3Pd2Ag4Cd3In4Sn3Sb5I1Te3Xe2Cs4Ba2La1Ce1Pr3Nd1Pm5Sm2Eu5Gd2Tb4Dy2Ho2Er2Tm4Yb2Lu3Hf3Ta3W2Re4Os2Ir3Pt2Au4Hg3Tl3Pb2BiPo1At12Rn1Fr3Ra1Ac4Pa1Th5Np1U5Am1Pu3CmBk4Cf1Es5Fm'`
-split"$args")[0]-replace'\D+','+'|iex
}
@(
    ,(16,'O')
    ,(119,'Sn')
    ,(1,'H')
    ,(257,'Fm')
) | % {
    $e,$a = $_
    $r = &$f $a
    "$($e-eq$r): $r"
}
```
Output:
```
True: 16
True: 119
True: 1
True: 257
```
## Explanation
The datastring contains chemical element labels and differences of the masses of adjacent elements. Zero differences are removed.
The script:
1. splits the datastring by a target element label.
2. takes a first substring with elements and differences that precede the target
3. replaces nondigit symbols to `+` (result for Oxigen element is: `1+3+3+2+2+1+2+2`)
4. calculates the result string as powershell expression
[Answer]
# [C (clang)](http://clang.llvm.org/), ~~624~~ 623 bytes
```
*a=L"H效楌敂BCNOF敎慎杍汁楓PS汃牁K慃捓楔V牃湍敆潃楎畃湚慇敇獁敓牂牋扒牓Y牚扎潍捔畒桒摐杁摃湉湓打敔I敘獃慂慌敃牐摎浐浓畅摇扔祄潈牅浔扙界晈慔W敒獏牉瑐畁杈汔扐楂潐瑁湒牆慒捁桔慐U灎畐流浃歂晃獅浆";f(short*x){return L"敉敌敏救敓敔敖敘敛敜敟敠散敤敧敨敫数敯数敵數敻敼敿斀斃斃斈斉斎斑斓斗斘斜斝斠斡斣斥斨斪断斯斲斴斸斻斿旂旈旇旋旍旑旓旔旕旘旙旞无日旧旫旭旯旱旵旷旺旽昀昂昆昈昋昍昑昔昗昙昙昚昦昧昪昫昰是昶昵昼昻昿昿晃晄晉"[wcschr(a,*x)-a]-a[1];}
```
[Try it online!](https://tio.run/##dVVtTxNZGP2@v8I0MQEjH/xM9kPb5S0WaKC@4MuHWkWIWk3B6MaY2I4DvcGpnc48996iKEQrRkKQzXZXFhv@zbk/g51lv85JJpPOydNzz3Oec@@tjFQelqv3T08vlH8tZCYhTfTeQBq5/MzsOKQFv4WtAId19KLiPA49p@qX4XsIIvTiq055OAogaxh46LWcJJ@b8Nch6y6oQyKnGk5tQHWcihac2oRqYRAgiJ10sNNB2MZWHWHyN4WjCCqCxFMQ6wIPfgN@oiVZso2whX4b/ciJj3AdKna91xg0nfLRj6G6Tt6g24QfX4N0XPDWKeXCtpM6tpo4TCra6DUwaLuwjqNEzBr8DhKFOzH89hVXT6Qn9HX0Pew30PVckBCvZUYXh1aWHtdWLzwfflG7t/q0Vj1XyEAUkuXkLSRMWkwUQ3SiGfIO8h7yEbIN@QT5DNmFfIXsQb5DDs7efcgPyDHkJ@QE@hW0d/Y0oRV0CzqEjqANtIV@D70FvQ29A/0Jugf9Ffob9D70AfQf0H9C/4A@hj6BacA0YdZhNmACmBAmgolhBMbCdGE@wGzD9GB2YfZg9mEOYA5h@jB/w/wDM4B9BduAXYNtwm7ABrAhbAxrYLtnzybsF9hd2G@we7DfYQ9g/4Ltw/6EPYY9@e/peui@Rldlbj6rrFSWakPli4mHI@XbI@Wbl26Pvjxdrq6ee1Rerg4Nv/jlSS35WhzKnL97q5q5mPyYzAwPj6bA99LxwnI6niP1uXQ4nw7PpMOz6fA4ISFSZsrp@PT9dDz7MB2fJxYUSTlxgLBna@n4ZUJDmpqvpOMlIv4qoSdqpqtkJMT7/GMyEyIn/zQdv0HWnSA2TBA92RViG4sxmwrB5@4QflK/QNol5TOEfprYXCJpmCM2zy2RiN8ldpItlCf1U2SM8wwn/ZbIuKbS4essnSQNOZKqAsHzhL/IxkjsKT4iNhB8jIxxgvCXiJ2//U4uAxKrMdJXiehcIOsWiP7JRcJP/L9G0kzGMkvGPkXaKq6S9DP5ZFeUyNFfJPbk2IVDxpIlOufYoc0OMWJzlt0t7NQgPFfIrnhCaIjNWZK2PMFzD0g9SdsYicn4//wvT/8F "C (clang) – Try It Online")
Just a pair of table lookups. Little endian only.
[Answer]
# PowerShell , 655
```
$S="Ac227Ag108Al027Am243Ar040As075At210Au197B 011Ba137Be009Bi209Bk247Br080C 012Ca040Cd112Ce140Cf251Cl035Cm247Co059Cr052Cs133Cu064Dy163Er167Es252Eu152F 019Fe056Fm257Fr223Ga070Gd157Ge073H 001He004Hf178Hg201Ho165I 127In115Ir192K 039Kr084La139Li007Lu175Mg024Mn055Mo096N 014Na023Nb093Nd144Ne020Ni059Np237O 016Os190P 031Pa231Pb207Pd106Pm145Po209Pr141Pt195Pu244Ra226Rb085Re186Rh103Rn222Ru101S 032Sb122Sc045Se079Si028Sm150Sn119Sr088Ta181Tb159Tc098Te128Th232Ti048Tl204Tm169U 238V 051W 184Xe131Y 089Yb173Zn065Zr091"
$a=$args[0][0];$b=$args[0][1];if(!$b){$b=" "};
for($i=0;$i-lt500;$i+=5){if(($a-match$s[$i])-and$b-match$s[$i+1]){$s[$i+2]+$s[$i+3]+$s[$i+4];break}}
```
the string s was constructed with 
```
awk '{printf(\"%-2s %03d\n\",$3,$4)}' .\input.txt | sort | awk '{printf(\"%-2s%03d\",$1,$2)}' > .\output.txt
```
result as follows
![enter image description here](https://i.stack.imgur.com/9kszC.png)
[Answer]
# T-SQL, ~~627~~ 524 bytes
```
SELECT ISNULL((SELECT SUBSTRING(value,3,3)FROM
STRING_SPLIT('B 11-F 19-Na23-Al27-P 31-K 39-Ar40-V 51-Mn55-Co59-Cu64-Se79-Sr88-Nb93-I 127-La139-Pr141-Nd144-Bi209-Po209-Rn222-Pa231-Np237-Am243-Cm247-Cf251','-')m,t
WHERE s=LEFT(value,2)),
(SELECT CHARINDEX(s,'H .He.LiBe.C N O ..Ne..Mg..Si..S .Cl..KCa...Sc.Ti..Cr..Fe.Ni....Zn...Ga.GeAs...Br..KRb..Y Zr...MoTc.RuRh.PdAg..Cd.In..Sn.Sb....Te.XeCs..Ba.Ce...Pm...SmEu...GdTb..DyHoErTm..YbLu.Hf.Ta.W Re..OsIr.PtAu..Hg.Tl.Pb.At...........Fr.RAc...Th....U ....Pu.Bk...Es...Fm')
FROM t))
```
Significant redesign, here, saved over 100 bytes.
Here is how this one works, reading back to front:
* The main piece here is a string (inside the `CHARINDEX()`, the dots are just filler) that *returns the element mass based on the string position*, for example, the letters `Ga` start at string position 70, which is the mass of Gallium.
* That unfortunately doesn't work for elements that have the *same* mass (`Ar` and `Ca`, for example), or elements that differ with mass that differs only by one (`Al` and `Si`), so I have a more traditional lookup table (inside the `STRING_SPLIT()`) that covers the exceptions.
* The `ISNULL()` statement pieces it all together: first it looks in the exception table, if that returns `NULL`, it instead returns the position from `CHARINDEX`.
**Original version, 627 bytes**:
```
SELECT SUBSTRING(value,3,3)
FROM STRING_SPLIT('H 1-He4-Li7-Be9-B 11-C 12-N 14-O 16-F 19-Ne20-Na23-Mg24-Al27-Si28-P 31
    -S 32-Cl35-Ar40-K 39-Ca40-Sc45-Ti48-V 51-Cr52-Mn55-Fe56-Co59-Ni59-Cu64-Zn65-Ga70-Ge73
    -As75-Se79-Br80-Kr84-Rb85-Sr88-Y 89-Zr91-Nb93-Mo96-Tc98-Ru101-Rh103-Pd106-Ag108-Cd112
    -In115-Sn119-Sb122-Te128-I 127-Xe131-Cs133-Ba137-La139-Ce140-Pr141-Nd144-Pm145-Sm150
    -Eu152-Gd157-Tb159-Dy163-Ho165-Er167-Tm169-Yb173-Lu175-Hf178-Ta181-W 184-Re186-Os190
    -Ir192-Pt195-Au197-Hg201-Tl204-Pb207-Bi209-Po209-At210-Rn222-Fr223-Ra226-Ac227-Th232
    -Pa231-U238-Np237-Pu244-Am243-Cm247-Bk247-Cf251-Es252-Fm257','-')
,t WHERE LEFT(value,2)=s
```
Returns are for formatting only.
[Per our IO standards](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods/5341#5341), input is taken via pre-existing table **t** with chemical symbol **s**. Joins to in-memory table derived from a delimited string.
]