# ACSL Senior 5 Division

    # Lexington High School

    # 2012-2013 Contest #2

    # Jonathan Tidor

 

def alph(cell):

    import re

    letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']

    string = ''

    for letter in letters:

        for i in re.findall(letter,cell):

            string = string + letter

    return string

 

while 0==0:

    cmd = input('Enter a valid operation name: ')

    if cmd == 'DIVIDE':

        cell = input('Enter the string: ')

        cell1 = alph(cell[0:4])

        cell2 = alph(cell[4:8])

        print(cell1+cell1+' and '+cell2+cell2+'\n')

    if cmd[0:-1] == 'ADD':

        cell = input('Enter the string: ')

        n = int(cmd[-1])

        cell1 = cell[0:n]

        cell2 = cell[n:8-n]

        print(cell1+alph(cell1)+cell2+'\n')

    if cmd[0:-1] == 'SUBTRACT':

        cell = input('Enter the string: ')

        n = int(cmd[-1])

        cell1 = cell[n:]

        cell2=''

        if n!=0:

            cell2 = alph(cell[-n:])

        print(cell1+cell2+'\n')

    if cmd == 'UNION':

        cell1 = input('Enter the first string: ')

        cell2 = input('Enter the second string: ')

        print(alph(cell1[4:])+alph(cell2[:4])+'\n')

    if cmd == 'INTERSECT':

        cell1 = input('Enter the first string: ')

        cell2 = input('Enter the second string: ')

        cell1 = cell1[:2]+cell1[6:]

        cell2 = cell2[:2]+cell2[6:]

        print(alph(cell1)+alph(cell2)+'\n')