## 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`.

Difficulty: introductory

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, {}                  # n: principal quantum number / l: secondary qunatum number (minus 1) / nl: n+l
    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
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'''
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(r'..', '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']
# Tuple of shell loading.
# (<orbit>, <final count>, <code>)
# Codes are:
#    -2 - Remove one electron at a time and ultimately remove the shell so we don't get something like 5d0 for this one.
#    -1 - Remove electrons in this shell one at a time.  Don't remove the shell.
#     0 - Add this shell with zero electrons so that it does show up as something like 5d0 in the sequence.
#     1 - Add 1 at a time
#     2 - Add but the first one is a double skip because of electrons dropped before.

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), # Cu
    ("3d", 10, 1), # Cu
    ("4s", 2, 1), # Zn
    ("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), # Ba
    ("4f", 0, 0), # La
    ("5d", 1, 1), # La
    ("4f", 1, 1), # Ce
    ("5d", 0, -2), #Pr
    ("4f", 7, 2), # Eu
    ("5d", 1, 1),
    ("5d", 0, -2),
    ("4f", 14, 1), # Yb
    ("5d", 7, 1), # IR
    ("6s", 1, -1), # Pt
    ("5d", 10, 1), # Au
    ("6s", 2, 1), # Hg
    ("6p", 6, 1), # Rn
    ("7s", 2, 1), # Ra
    ("5f", 0, 0), # Ac
    ("6d", 2, 1), # Th
    ("6d", 1, -1), # Pa
    ("5f", 4, 2), # Np
    ("6d", 0, -2), #Pu
    ("5f", 7, 2), # Am
    ("6d", 1, 1), # Cm
    ("6d", 0, -2), # Bk
    ("5f", 14, 2), # No
    ("6d", 1, 1), # Lr
#  These exceptions should exist per https://ptable.com/ but they don't in the tests.
#    ("7p", 1, 1), # Lr
#    ("7p", 0, -2), # Rf
#    ("6d", 7, 2), # Mt
#    ("7s", 1, -1), # Ds
    ("6d", 9, 2), # Ds
    ("7s", 2, 1), # Rg
    ("6d", 10, 1), # Cn
    ("7p", 6, 1)
    )
    
# Order of shells.    
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):
    # Create our electron shell dictionary
    e = {}
    # Get the atomic number
    a = ELEMENTS.index(element)+1
    # Keep track of the total number electrons.  This is easier/faster than summing up the numbers in the dict.
    t = 0
    # Loop through the shells
    for o, cnt, code in shells:
        # If we reached the atomic number, we stop.
        if t == a:
            break
        else:
            # If orbit isn't in the dict, add it.
            # Note:  Even if code=0 this portion will add the orbit so it will show up in "o in e" below when building the o_list.
            if o not in e: e[o] = 0
            # If the code is -2, count down and delete the orbit.
            if code == -2:
                while e[o] > cnt:
                    e[o] -= 1
                    t -= 1
                del(e[o])
            # If the code is -1, count down.
            elif code == -1:
                while e[o] > cnt:
                    e[o] -= 1
                    t -= 1
            # IF the code is positve, count up.  We just use the 2 for ease in building the table above.
            # Nothing special is required for code=2 vs code=1
            elif code > 0:
                while t != a and e[o] < cnt:
                    e[o] += 1
                    t += 1
    
    # Combine the orbits and counts.  Use the shell_seq to get the order correct and don't include shells that aren't in e.
    o_list = [f"{o}{e[o]}" for o in shell_seq if o in e]
    # Join the list and output.
    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']
order=['1s','2s','2p','3s','3p','4s','3d','4p','5s','4d','5p','6s',
       '4f','5d','6p','7s','5f','6d','7p']
hold={'s':2,'p':6,'d':10,'f':14}
special={
    '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']
}
def get_electron_configuration(element):
    e=ELEMENTS.index(element)+1
    r=[]
    for o in order:
        r.append(o+str(min(e,hold[o[1]])))
        e-=hold[o[1]]
        if e<=0:
            break
    if element in special:
        for o2 in special[element]:
            flag=False
            for i in range(len(r)):
                if r[i][:2]==o2[:2]:
                    r[i]=o2
                    flag=True
                    break
            if not flag:
                r.append(o2)
    return '{} -> {}'.format(element,' '.join(sorted(r,key=lambda x:(x[0],'spdf'.index(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']
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):
  '''
  Return the electron configuration of the supplied element.
  '''
  #ELEMENTS
  # array is an array of the element symbols in order by
  # atomic number. The atomic number is 1 plus the index in the array
  # For example:
  #  ELEMENTS = ['H', 'He', 'Li', ...]
  
  #exceptions array
  # Elements whose electron fill order are not normal.  Format is
  # <element>:[<the remaining orbitals/electrons>]
  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 array
  # Orbitals are listed in order they are normally filled.  Also listed
  # with their maximum fill
  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        #Index into the array of orbitals
  config = []             #List of the orbitals with electrons
  
  while numElectrons > 0: #If orbital is filled
    if numElectrons - int(orbitals[orbitalIndex][2:]) > 0:
      config.append(orbitals[orbitalIndex])
    else:                 # otherwise add the remaining e's to this orbital
      config.append(orbitals[orbitalIndex][:2] + str(numElectrons))
      
    numElectrons -= int(orbitals[orbitalIndex][2:])
    orbitalIndex += 1

  if element in list(exceptions.keys()):  #Abnormal electron fill
    end = exceptions[element]       #Retrieve the config of the last few e's
    e = 0                           #The number of abnormal e's
    for orb in end:                 # sum them
      e += int(orb[2:])
    while e > 0:                    #Remove the orbitals at end that have
      e -= int(config.pop()[2:])    # than number of electrons

    config.extend(end)              #Add back the abnormal electon fill

  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