## Introduction


Each chemical element in its neutral state has a specific number of electrons associated with it. This is represented by the **atomic number** which is noted by an integer number next to or above each element of the periodic table (as highlighted in the image above).

As we move from left to right, starting from the top row of the periodic table, each element differs from its predecessor by 1 unit (electron). Electrons fill in different orbitals sets according to a specific order. Each set of orbitals, when full, contains an even number of electrons.

The orbital sets are:
* The _**s** orbital_ - a single orbital that can hold a maximum of 2 electrons.
* The _**p** orbital set_ - can hold 6 electrons.
* The _**d** orbital set_ - can hold 10 electrons.
* The _**f** orbital set_ - can hold 14 electrons.


The order in which electrons are filling the different set of orbitals is shown in the picture above. First electrons will occupy the **1s** orbital, then the **2s**, then the **2p** set, **3s** and so on.

Electron configurations show how the number of electrons of an element is distributed across each orbital set. Each orbital is written as a sequence that follows the order in the picture, joined by the number of electrons contained in that orbital set. The final electron configuration is a single string of orbital names and number of electrons per orbital set where the first 2 digits of each substring represent the orbital name followed by a number that states the number of electrons that the orbital set contains.

For example, a string that demonstrates an electron configuration of a chemical element that contains 10 electrons is: `1s2 2s2 2p6`. This configuration shows that there are two electrons in the `1s` orbital set, two electrons in the `2s` orbital set, and six electrons in the `2p` orbital set. `2 + 2 + 6 = 10` electrons total.

___

# Task

Your task is to write a function that displays the electron configuration built according to the Madelung rule of all chemical elements of the periodic table. The argument will be the symbol of a chemical element, as displayed in the periodic table.

**Note**: There will be a preloaded array called `ELEMENTS` with chemical elements sorted by their atomic number.

For example, when the element "O" is fed into the function the output should look like: 

`"O -> 1s2 2s2 2p4"`

However, there are some exceptions! The electron configurations of the elements below should end as:

```
Cr -> ...3d5 4s1
Cu -> ...3d10 4s1
Nb -> ...4d4 5s1
Mo -> ...4d5 5s1
Ru -> ...4d7 5s1
Rh -> ...4d8 5s1
Pd -> ...4d10 5s0
Ag -> ...4d10 5s1
La -> ...4f0 5d1
Ce -> ...4f1 5d1
Gd -> ...4f7 5d1 6s2
Pt -> ...4f14 5d9 6s1
Au -> ...4f14 5d10 6s1
Ac -> ...5f0 6d1 7s2
Th -> ...5f0 6d2 7s2
Pa -> ...5f2 6d1 7s2
U  -> ...5f3 6d1 7s2
Np -> ...5f4 6d1 7s2
Cm -> ...5f7 6d1 7s2
```

**Note**: for `Ni` the electron configuration should be `3d8 4s2` instead of `3d9 4s1`.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Starter code: ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']
def get_electron_configuration(element):
	

Solutions:
ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']
EXCEPTIONS = {'Cr': ['Ar', '4s1 3d5'], 'Cu': ['Ar', '4s1 3d10'], 'Nb': ['Kr', '5s1 4d4'], 'Mo': ['Kr', '5s1 4d5'], 'Ru': ['Kr', '5s1 4d7'], 'Rh': ['Kr', '5s1 4d8'], 'Pd': ['Kr', '5s0 4d10'], 'Ag': ['Kr', '5s1 4d10'], 'La': ['Xe', '6s2 4f0 5d1'], 'Ce': ['Xe', '6s2 4f1 5d1'], 'Gd': ['Xe', '6s2 4f7 5d1'], 'Pt': ['Xe', '6s1 4f14 5d9'], 'Au': ['Xe', '6s1 4f14 5d10'], 'Ac': ['Rn', '7s2 5f0 6d1'], 'Th': ['Rn', '7s2 5f0 6d2'], 'Pa': ['Rn', '7s2 5f2 6d1'], 'U': ['Rn', '7s2 5f3 6d1'], 'Np': ['Rn', '7s2 5f4 6d1'], 'Cm': ['Rn', '7s2 5f7 6d1']}
ORBITALS = 'spdfg'
ELT_TO_Z = {elt: i for (i, elt) in enumerate(ELEMENTS, 1)}
for arr in list(EXCEPTIONS.values()):
	arr[1] = [(int(s[0]), ORBITALS.find(s[1]), s[2:]) for s in arr[1].split(' ')]

def get_electron_configuration(element):
	(elt, repl) = EXCEPTIONS.get(element, (element, []))
	(z, nl, config) = (ELT_TO_Z[elt], 0, {})
	while z:
		nl += 1
		for l in range(nl - 1 >> 1, -1, -1):
			nE = min(z, 2 + l * 4)
			config[nl - l, l] = nE
			z -= nE
			if not z:
				break
	for (a, b, n) in repl:
		config[a, b] = n
	s = ' '.join((f'{k[0]}{ORBITALS[k[1]]}{n}' for (k, n) in sorted(config.items())))
	return f'{element} -> {s}'


ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']
import re
exc = 'Cr -> ...3d5 4s1\nCu -> ...3d10 4s1\nNb -> ...4d4 5s1\nMo -> ...4d5 5s1\nRu -> ...4d7 5s1\nRh -> ...4d8 5s1\nPd -> ...4d10 5s0\nAg -> ...4d10 5s1\nLa -> ...4f0 5d1\nCe -> ...4f1 5d1\nGd -> ...4f7 5d1 6s2\nPt -> ...4f14 5d9 6s1\nAu -> ...4f14 5d10 6s1\nAc -> ...5f0 6d1 7s2\nTh -> ...5f0 6d2 7s2\nPa -> ...5f2 6d1 7s2\nU  -> ...5f3 6d1 7s2\nNp -> ...5f4 6d1 7s2\nCm -> ...5f7 6d1 7s2'
exceptions = {i.split()[0]: {j[:2]: j[2:] for j in i.split('...')[1].split()} for i in exc.split('\n')}

def get_electron_configuration(element):
	names = re.findall('..', '1s2s2p3s3p4s3d4p5s4d5p6s4f5d6p7s5f6d7p8s')
	values = [2, 2, 6, 2, 6, 2, 10, 6, 2, 10, 6, 2, 14, 10, 6, 2, 14, 10, 6, 2]
	N = ELEMENTS.index(element) + 1
	res = {}
	while N > 0:
		v = min(values.pop(0), N)
		res[names.pop(0)] = str(v)
		N -= v
	if element in exceptions:
		res.update(exceptions[element])
	res = [i + j for (i, j) in zip(res.keys(), res.values())]
	res.sort(key=lambda x: (x[0], ['s', 'p', 'd', 'f'].index(x[1])))
	return '{} -> {}'.format(element, ' '.join(res))


ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']

def get_electron_configuration(a):
	d = {'s': 2, 'p': 6, 'd': 10, 'f': 14}
	o = [[x, d[x[1]]] for x in ['1s', '2s', '2p', '3s', '3p', '4s', '3d', '4p', '5s', '4d', '5p', '6s', '4f', '5d', '6p', '7s', '5f', '6d', '7p']][::-1]
	exceptions = {'Cr': [2, '4s1 3d5'], 'Cu': [2, '4s1 3d10'], 'Nb': [2, '5s1 4d4'], 'Mo': [2, '5s1 4d5'], 'Ru': [2, '5s1 4d7'], 'Rh': [2, '5s1 4d8'], 'Pd': [2, '5s0 4d10'], 'Ag': [2, '5s1 4d10'], 'La': [1, '4f0 5d1'], 'Ce': [1, '4f1 5d1'], 'Gd': [1, '4f7 5d1'], 'Pt': [3, '6s1 4f14 5d9'], 'Au': [3, '6s1 4f14 5d10'], 'Ac': [1, '5f0 6d1'], 'Th': [1, '5f0 6d2'], 'Pa': [1, '5f2 6d1'], 'U': [1, '5f3 6d1'], 'Np': [1, '5f4 6d1'], 'Cm': [1, '5f7 6d1']}
	(r, n) = ([], ELEMENTS.index(a) + 1)
	while n > 0:
		(s, m) = o.pop()
		x = min(n, m)
		n -= x
		r.append('{}{}'.format(s, x))
	if a in exceptions:
		(m, s) = exceptions[a]
		r = r[:-m] + s.split()
	return '{} -> {}'.format(a, ' '.join(sorted(r, key=lambda x: (x[0], d[x[1]]))))


ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']
shells = (('1s', 2, 1), ('2s', 2, 1), ('2p', 6, 1), ('3s', 2, 1), ('3p', 6, 1), ('4s', 2, 1), ('3d', 3, 1), ('4s', 1, -1), ('3d', 5, 2), ('4s', 2, 1), ('3d', 8, 1), ('4s', 1, -1), ('3d', 10, 1), ('4s', 2, 1), ('4p', 6, 1), ('5s', 2, 1), ('4d', 2, 1), ('5s', 1, -1), ('4d', 5, 2), ('5s', 2, 1), ('5s', 1, -1), ('4d', 8, 2), ('5s', 0, -1), ('4d', 10, 2), ('5s', 2, 1), ('5p', 6, 1), ('6s', 2, 2), ('4f', 0, 0), ('5d', 1, 1), ('4f', 1, 1), ('5d', 0, -2), ('4f', 7, 2), ('5d', 1, 1), ('5d', 0, -2), ('4f', 14, 1), ('5d', 7, 1), ('6s', 1, -1), ('5d', 10, 1), ('6s', 2, 1), ('6p', 6, 1), ('7s', 2, 1), ('5f', 0, 0), ('6d', 2, 1), ('6d', 1, -1), ('5f', 4, 2), ('6d', 0, -2), ('5f', 7, 2), ('6d', 1, 1), ('6d', 0, -2), ('5f', 14, 2), ('6d', 1, 1), ('6d', 9, 2), ('7s', 2, 1), ('6d', 10, 1), ('7p', 6, 1))
shell_seq = ['1s', '2s', '2p', '3s', '3p', '3d', '4s', '4p', '4d', '4f', '5s', '5p', '5d', '5f', '6s', '6p', '6d', '7s', '7p']

def get_electron_configuration(element):
	e = {}
	a = ELEMENTS.index(element) + 1
	t = 0
	for (o, cnt, code) in shells:
		if t == a:
			break
		else:
			if o not in e:
				e[o] = 0
			if code == -2:
				while e[o] > cnt:
					e[o] -= 1
					t -= 1
				del e[o]
			elif code == -1:
				while e[o] > cnt:
					e[o] -= 1
					t -= 1
			elif code > 0:
				while t != a and e[o] < cnt:
					e[o] += 1
					t += 1
	o_list = [f'{o}{e[o]}' for o in shell_seq if o in e]
	return f"{element} -> {' '.join(o_list)}"


ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']

def get_electron_configuration(element):
	elems = {'Cr': '3d5 4s1', 'Cu': '3d10 4s1', 'Nb': '4d4 5s1', 'Mo': '4d5 5s1', 'Ru': '4d7 5s1', 'Rh': '4d8 5s1', 'Pd': '4d10 5s0', 'Ag': '4d10 5s1', 'La': '4f0 5d1', 'Ce': '4f1 5d1', 'Gd': '4f7 5d1 6s2', 'Pt': '4f14 5d9 6s1', 'Au': '4f14 5d10 6s1', 'Ac': '5f0 6d1 7s2', 'Th': '5f0 6d2 7s2', 'Pa': '5f2 6d1 7s2', 'U': '5f3 6d1 7s2', 'Np': '5f4 6d1 7s2', 'Cm': '5f7 6d1 7s2'}
	elem_config = elems.get(element)
	list = ['Cr', 'Cu', 'Nb', 'Mo', 'Ru', 'Rh', 'Pd', 'Ag', 'La', 'Ce', 'Gd', 'Pt', 'Au', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Cm']
	s = []
	c = 0
	a = 0
	for x in range(len(ELEMENTS)):
		if element == ELEMENTS[x]:
			v = x + 1
	if element in list:
		s = elem_config.split(' ')
		for b in s:
			v -= int(b[2:])
	while v > 0:
		c += 1
		if v >= 2:
			s.append(str(c) + 's2')
			v -= 2
		elif 0 < v < 2:
			s.append(str(c) + 's' + str(v))
			v -= v
		if v >= 6 and c > 1:
			s.append(str(c) + 'p6')
			v -= 6
		elif 0 < v < 6 and c > 1:
			s.append(str(c) + 'p' + str(v))
			v -= v
		if v >= 12 and c > 2:
			s.append(str(c) + 'd10')
			v -= 10
		elif 2 < v <= 12 and c > 2:
			s.append(str(c) + 'd' + str(v - 2))
			v -= v - 2
		if v >= 24 and c > 3:
			s.append(str(c) + 'f14')
			v -= 14
		elif 10 < v < 24 and c > 3:
			s.append(str(c) + 'f' + str(v - 10))
			v -= v - 10
	s.sort(key=lambda p: p[0] + {'s': '0', 'p': '1', 'd': '2', 'f': '3'}[p[1]])
	s = ' '.join(s)
	return element + ' -> ' + s


ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']

def get_electron_configuration(element):
	(atomic_no, n) = (ELEMENTS.index(element) + 1, 0)
	orbitals = {'1s': 0, '2s': 0, '2p': 0, '3s': 0, '3p': 0, '3d': 0, '4s': 0, '4p': 0, '4d': 0, '4f': 0, '5s': 0, '5p': 0, '5d': 0, '5f': 0, '6s': 0, '6p': 0, '6d': 0, '6f': 0, '7s': 0, '7p': 0, '7d': 0, '7f': 0}
	exceptions = {'Cr': 'Cr -> 1s2 2s2 2p6 3s2 3p6 3d5 4s1', 'Cu': 'Cu -> 1s2 2s2 2p6 3s2 3p6 3d10 4s1', 'Nb': 'Nb -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d4 5s1', 'Mo': 'Mo -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d5 5s1', 'Ru': 'Ru -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d7 5s1', 'Rh': 'Rh -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d8 5s1', 'Pd': 'Pd -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 5s0', 'Ag': 'Ag -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 5s1', 'La': 'La -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f0 5s2 5p6 5d1 6s2', 'Ce': 'Ce -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f1 5s2 5p6 5d1 6s2', 'Gd': 'Gd -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f7 5s2 5p6 5d1 6s2', 'Pt': 'Pt -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f14 5s2 5p6 5d9 6s1', 'Au': 'Au -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f14 5s2 5p6 5d10 6s1', 'Ac': 'Ac -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f14 5s2 5p6 5d10 5f0 6s2 6p6 6d1 7s2', 'Th': 'Th -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f14 5s2 5p6 5d10 5f0 6s2 6p6 6d2 7s2', 'Pa': 'Pa -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f14 5s2 5p6 5d10 5f2 6s2 6p6 6d1 7s2', 'U': 'U -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f14 5s2 5p6 5d10 5f3 6s2 6p6 6d1 7s2', 'Np': 'Np -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f14 5s2 5p6 5d10 5f4 6s2 6p6 6d1 7s2', 'Cm': 'Cm -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p6 4d10 4f14 5s2 5p6 5d10 5f7 6s2 6p6 6d1 7s2'}
	if element in exceptions:
		return exceptions[element]
	while n < atomic_no:
		if n < 2:
			orbitals['1s'] += 1
		elif n < 4:
			orbitals['2s'] += 1
		elif n < 10:
			orbitals['2p'] += 1
		elif n < 12:
			orbitals['3s'] += 1
		elif n < 18:
			orbitals['3p'] += 1
		elif n < 20:
			orbitals['4s'] += 1
		elif n < 30:
			orbitals['3d'] += 1
		elif n < 36:
			orbitals['4p'] += 1
		elif n < 38:
			orbitals['5s'] += 1
		elif n < 48:
			orbitals['4d'] += 1
		elif n < 54:
			orbitals['5p'] += 1
		elif n < 56:
			orbitals['6s'] += 1
		elif n < 70:
			orbitals['4f'] += 1
		elif n < 80:
			orbitals['5d'] += 1
		elif n < 86:
			orbitals['6p'] += 1
		elif n < 88:
			orbitals['7s'] += 1
		elif n < 102:
			orbitals['5f'] += 1
		elif n < 112:
			orbitals['6d'] += 1
		elif n < 118:
			orbitals['7p'] += 1
		n += 1
	st = ''
	orbs = ['1s', '2s', '2p', '3s', '3p', '3d', '4s', '4p', '4d', '4f', '5s', '5p', '5d', '5f', '6s', '6p', '6d', '6f', '7s', '7p', '7d', '7f']
	for x in orbs:
		if orbitals[x] != 0:
			st += x + str(orbitals[x]) + ' '
	return element + ' -> ' + st.rstrip()


ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']

def orbital_sort(s):
	return s.replace('s', '1').replace('p', '2').replace('d', '3').replace('f', '4')

def get_electron_configuration(element):
	atomic = ELEMENTS.index(element) + 1
	filling = ['1s', '2s', '2p', '3s', '3p', '4s', '3d', '4p', '5s', '4d', '5p', '6s', '4f', '5d', '6p', '7s', '5f', '6d', '7p', '8s']
	replace_d = {'Cr': '3d5 4s1', 'Cu': '3d10 4s1', 'Nb': '4d4 5s1', 'Mo': '4d5 5s1', 'Ru': '4d7 5s1', 'Rh': '4d8 5s1', 'Pd': '4d10 5s0', 'Ag': '4d10 5s1', 'La': '4f0 5s2 5p6 5d1 6s2', 'Ce': '4f1 5s2 5p6 5d1 6s2', 'Gd': '4f7 5s2 5p6 5d1 6s2', 'Pt': '4f14 5s2 5p6 5d9 6s1', 'Au': '4f14 5s2 5p6 5d10 6s1', 'Ac': '5f0 6s2 6p6 6d1 7s2', 'Th': '5f0 6s2 6p6 6d2 7s2', 'Pa': '5f2 6s2 6p6 6d1 7s2', 'U': '5f3 6s2 6p6 6d1 7s2', 'Np': '5f4 6s2 6p6 6d1 7s2', 'Cm': '5f7 6s2 6p6 6d1 7s2'}
	result = []
	while atomic > 0:
		orbital = filling.pop(0)
		if orbital[-1] == 's':
			if atomic > 1:
				result.append(orbital + '2')
				atomic -= 2
			else:
				result.append(orbital + '1')
				atomic -= 1
		elif orbital[-1] == 'p':
			if atomic > 5:
				result.append(orbital + '6')
				atomic -= 6
			else:
				result.append(orbital + str(atomic))
				atomic -= atomic
		elif orbital[-1] == 'd':
			if atomic > 9:
				result.append(orbital + '10')
				atomic -= 10
			else:
				result.append(orbital + str(atomic))
				atomic -= atomic
		elif orbital[-1] == 'f':
			if atomic > 13:
				result.append(orbital + '14')
				atomic -= 14
			else:
				result.append(orbital + str(atomic))
				atomic -= atomic
	result.sort(key=orbital_sort)
	result = f"{element} -> {' '.join(result)}"
	print(element)
	if element in replace_d:
		i = result.index(replace_d[element][:2])
		print((i, result[:i], replace_d[element]))
		result = result[:i] + replace_d[element]
	return result


ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']

def get_electron_configuration(element):
	exceptions = {'Cr': ['3d5', '4s1'], 'Cu': ['3d10', '4s1'], 'Nb': ['4d4', '5s1'], 'Mo': ['4d5', '5s1'], 'Ru': ['4d7', '5s1'], 'Rh': ['4d8', '5s1'], 'Pd': ['4d10', '5s0'], 'Ag': ['4d10', '5s1'], 'La': ['4f0', '5d1'], 'Ce': ['4f1', '5d1'], 'Gd': ['4f7', '5d1', '6s2'], 'Pt': ['4f14', '5d9', '6s1'], 'Au': ['4f14', '5d10', '6s1'], 'Ac': ['5f0', '6d1', '7s2'], 'Th': ['5f0', '6d2', '7s2'], 'Pa': ['5f2', '6d1', '7s2'], 'U': ['5f3', '6d1', '7s2'], 'Np': ['5f4', '6d1', '7s2'], 'Cm': ['5f7', '6d1', '7s2']}
	orbitals = ['1s2', '2s2', '2p6', '3s2', '3p6', '4s2', '3d10', '4p6', '5s2', '4d10', '5p6', '6s2', '4f14', '5d10', '6p6', '7s2', '5f14', '6d10', '7p6', '8s2']
	atomicNumber = ELEMENTS.index(element) + 1
	numElectrons = atomicNumber
	orbitalIndex = 0
	config = []
	while numElectrons > 0:
		if numElectrons - int(orbitals[orbitalIndex][2:]) > 0:
			config.append(orbitals[orbitalIndex])
		else:
			config.append(orbitals[orbitalIndex][:2] + str(numElectrons))
		numElectrons -= int(orbitals[orbitalIndex][2:])
		orbitalIndex += 1
	if element in list(exceptions.keys()):
		end = exceptions[element]
		e = 0
		for orb in end:
			e += int(orb[2:])
		while e > 0:
			e -= int(config.pop()[2:])
		config.extend(end)
	return element + ' -> ' + ' '.join(sorted(config, key=lambda x: x[0]))


ELEMENTS = ['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', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds', 'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']

def get_electron_configuration(element):
	n = ELEMENTS.index(element) + 1
	import re
	a = 'Cr -> ...3d5 4s1 Cu -> ...3d10 4s1 Nb -> ...4d4 5s1 Mo -> ...4d5 5s1 Ru -> ...4d7 5s1 Rh -> ...4d8 5s1 Pd -> ...4d10 5s0 Ag -> ...4d10 5s1 La -> ...4f0 5d1 Ce -> ...4f1 5d1 Gd -> ...4f7 5d1 6s2 Pt -> ...4f14 5d9 6s1 Au -> ...4f14 5d10 6s1 Ac -> ...5f0 6d1 7s2 Th -> ...5f0 6d2 7s2 Pa -> ...5f2 6d1 7s2 U  -> ...5f3 6d1 7s2 Np -> ...5f4 6d1 7s2 Cm -> ...5f7 6d1 7s2'
	a = 'Ni 3d8 4s2 Cr 3d5 4s1 Cu 3d10 4s1 Nb 4d4 5s1 Mo 4d5 5s1 Ru 4d7 5s1 Rh 4d8 5s1 Pd 4d10 5s0 Ag 4d10 5s1 La 4f0 5d1 Ce 4f1 5d1 Gd 4f7 5d1 6s2 Pt 4f14 5d9 6s1 Au 4f14 5d10 6s1 Ac 5f0 6d1 7s2 Th 5f0 6d2 7s2 Pa 5f2 6d1 7s2 U  5f3 6d1 7s2 Np 5f4 6d1 7s2 Cm 5f7 6d1 7s2'
	a = {'Ni': ['Ni', '3d8', '4s2'], 'Ac': ['Ac', '5f0', '6d1', '7s2'], 'Pa': ['Pa', '5f2', '6d1', '7s2'], 'Pt': ['Pt', '4f14', '5d9', '6s1'], 'Ag': ['Ag', '4d10', '5s1'], 'Ru': ['Ru', '4d7', '5s1'], 'Nb': ['Nb', '4d4', '5s1'], 'La': ['La', '4f0', '5d1'], 'U': ['U', '5f3', '6d1', '7s2'], 'Ce': ['Ce', '4f1', '5d1'], 'Th': ['Th', '5f0', '6d2', '7s2'], 'Gd': ['Gd', '4f7', '5d1', '6s2'], 'Au': ['Au', '4f14', '5d10', '6s1'], 'Cm': ['Cm', '5f7', '6d1', '7s2'], 'Pd': ['Pd', '4d10', '5s0'], 'Np': ['Np', '5f4', '6d1', '7s2'], 'Cr': ['Cr', '3d5', '4s1'], 'Rh': ['Rh', '4d8', '5s1'], 'Mo': ['Mo', '4d5', '5s1'], 'Cu': ['Cu', '3d10', '4s1']}
	a = {'Ni': ['3d8', '4s2'], 'Ac': ['5f0', '6d1', '7s2'], 'Gd': ['4f7', '5d1', '6s2'], 'Ag': ['4d10', '5s1'], 'Pt': ['4f14', '5d9', '6s1'], 'Ru': ['4d7', '5s1'], 'Nb': ['4d4', '5s1'], 'La': ['4f0', '5d1'], 'Ce': ['4f1', '5d1'], 'Cm': ['5f7', '6d1', '7s2'], 'Pa': ['5f2', '6d1', '7s2'], 'U': ['5f3', '6d1', '7s2'], 'Cu': ['3d10', '4s1'], 'Th': ['5f0', '6d2', '7s2'], 'Cr': ['3d5', '4s1'], 'Np': ['5f4', '6d1', '7s2'], 'Au': ['4f14', '5d10', '6s1'], 'Rh': ['4d8', '5s1'], 'Mo': ['4d5', '5s1'], 'Pd': ['4d10', '5s0']}
	a = {'Ni': [['3d', '8'], ['4s', '2']], 'Ac': [['5f', '0'], ['6d', '1'], ['7s', '2']], 'Gd': [['4f', '7'], ['5d', '1'], ['6s', '2']], 'Pt': [['4f', '14'], ['5d', '9'], ['6s', '1']], 'Ag': [['4d', '10'], ['5s', '1']], 'Ru': [['4d', '7'], ['5s', '1']], 'Nb': [['4d', '4'], ['5s', '1']], 'La': [['4f', '0'], ['5d', '1']], 'Ce': [['4f', '1'], ['5d', '1']], 'Cm': [['5f', '7'], ['6d', '1'], ['7s', '2']], 'Pa': [['5f', '2'], ['6d', '1'], ['7s', '2']], 'U': [['5f', '3'], ['6d', '1'], ['7s', '2']], 'Cu': [['3d', '10'], ['4s', '1']], 'Th': [['5f', '0'], ['6d', '2'], ['7s', '2']], 'Np': [['5f', '4'], ['6d', '1'], ['7s', '2']], 'Cr': [['3d', '5'], ['4s', '1']], 'Rh': [['4d', '8'], ['5s', '1']], 'Mo': [['4d', '5'], ['5s', '1']], 'Pd': [['4d', '10'], ['5s', '0']], 'Au': [['4f', '14'], ['5d', '10'], ['6s', '1']]}
	o = ['1s', '2s', '2p', '3s', '3p', '4s', '3d', '4p', '5s', '4d', '5p', '6s', '4f', '5d', '6p', '7s', '5f', '6d', '7p', '8s']
	y = {}
	d = {}
	if element in a:
		a = a[element]
		for i in a:
			d[i[0]] = i[1]
	for i in o:
		if i[1] == 's':
			lim = 2
		if i[1] == 'p':
			lim = 6
		if i[1] == 'd':
			lim = 10
		if i[1] == 'f':
			lim = 14
		if n > lim:
			y[i] = str(lim)
			n = n - lim
			continue
		else:
			y[i] = str(n)
			break
	z = dict(list(y.items()) + list(d.items()))
	l = ['1s', '2s', '2p', '3s', '3p', '3d', '4s', '4p', '4d', '4f', '5s', '5p', '5d', '5f', '6s', '6p', '6d', '7s', '7p', '8s']
	r = ''
	for i in l:
		if i in z.keys():
			r += i + z[i] + ' '
	r = element + ' -> ' + r[::-1][1:][::-1]
	return r