# -----------------------------------------------------------------------------------------
# Oak Valley Coding Club 2019-2020
# Solution for 2020 ACSL Programming Problem #2 – Junior Division
# Author :  Jared Baza
# Language: Python 3.x
# -----------------------------------------------------------------------------------------


#Jared Baza
#ACSL 2


#-----------------------------------------------
# Main Functions to solve the problem

def remove_doubleconsonant_vowels_L_R_Justify(S1, S2):

    initS1 = []      # Create list initS1
    for s in str(S1):
        initS1.append(s)
        
    initS2 = []      # Create list initS2
    for s in str(S2):
        initS2.append(s)

    O_listS1 = list(S1)#Create Original List for 0th character reference
    O_listS2 = list(S2)
#*****************First Part: Remove Double Consonant*******************************************************************************#
    consonants = ['B', 'C', 'D', 'F', 'G', 'H', 'J', 'K', 'L,', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z']#List of consonants
 
    for i in range(0,len(initS1)-1):#For loop to remove any double consonants
        if initS1[i] == initS1[i+1] and initS1[i] in consonants:#check for any repeating charecters in initS1 and also found in consonants
            initS1[i] = ' '#Adds blank space to any repeating consonants
            
    while ' ' in initS1: #Removes the extra blank space
        initS1.remove(' ')
                    
    sS1 = ''.join(initS1)# New string created with no repeated consonants to check if step 1 was correctly executed
       
    for i in range(0,len(initS2)-1):#For loop to remove any double consonants
        if initS2[i] == initS2[i+1] and initS2[i] in consonants:
            initS2[i] = ' '

    while ' ' in initS2: #Removes the extra blank space
        initS2.remove(' ')

    sS2 = ''.join(initS2)# New string created with no repeated consonants to check if step 1 was correctly executed
             
  #********************************Second Part: Remove All Vowels***********************************************************************#
    listS1 = initS1 # New list with no repeated consonants
    listS2 = initS2

    vowels = ['A', 'E', 'I', 'O', 'U']#Defines all the vowels

    # Create a count when first character in the string is a vowel, and store in matches
    matches1 = 0
    for i in range(len(vowels)):#Counter to check if the first position in O_listS1 is a vowel
        if O_listS1[0] == vowels[i]: #If true, increment matches
            matches1 = matches1+1
    
    matches2 = 0
    for i in range(len(vowels)):
        if O_listS2[0] == vowels[i]: #Note use of 0th place is from Original string
            matches2 = matches2+1

        for i in listS1:#This for loop is removing the vowels in listS1
            if i in vowels:
                listS1.remove(i)

        for i in listS1:#This for loop is removing any repeated vowels left--
            if i in vowels:#in listS1
                listS1.remove(i)
            ns1 = (''.join(listS1))
            
        if matches1 > 0: #If first character in original string is a vowel (matches>0), add vowel back to string ns1
            ns1 = ''.join((str(O_listS1[0]), ns1))

    for i in listS2:#This for loop is removing the vowels in listS2
        if i in vowels:
            listS2.remove(i)

        for i in listS2:#This for loop is removing any repeated vowels left--
            if i in vowels:#in listS2
                listS2.remove(i)
            ns2 = (''.join(listS2))

        if matches2 > 0: #If first character in original string is a vowel (matches>0), add vowel back to string ns2
            ns2 = ''.join((str(O_listS2[0]), ns2))

    #*******************************Part 3: peform left justification after deleting Double Consonants and Vowels******************************

    both = [ns1, ns2]#Places both ns1 and ns2 into one list of strings
    Maxval = len (max(both, key = len))#Defines the max value within the list of strings
    Minval = len (min(both, key = len))#Defines the min value within the list of strings

    ls1 = list(ns1.ljust(Maxval, ' '))#left justifies ns1 by the max value of the either of the strings
    ls2 = list(ns2.ljust(Maxval, ' '))#left justifies ns2 by the max value of the either of the strings
    
    if len(ls1) == len(ls2): #Checking that both lists have the same lenght after left justifying
        for i in range (len(ls1)):#For loop that replaces any like characters in both lists with blank spaces
            if ls1[i] == ls2[i]:
                ls1[i] = ' '
                ls2[i] = ' '
    while ' ' in ls1: #While loop to remove blank spaces in ls1
        ls1.remove(' ')
        
    while ' ' in ls2:
        ls2.remove(' ')

    nls1 = "".join(ls1)  #Creates a new srting after removing like terms during left justification
    nls2 = "".join(ls2)

    #******************************Part 4: peform right justification and removing like terms******************************************************************
    both2 = [nls1, nls2]#Places both nls1 and nls2 into one list of strings
    Maxval2 = len (max(both, key = len))#Defines the max value within the list of strings
    Minval2 = len (min(both, key = len))#Defines the min value within the list of strings
    
    r_s1 = nls1.rjust(Maxval2)#Rigth justifies nls1 by the max value of the either of the strings
    r_s2 = nls2.rjust(Maxval2)#Rigth justifies nls2 by the max value of the either of the strings

    rs1 = list (r_s1) #Change string into list of strings
    rs2 = list (r_s2)

    if len(rs1) == len(rs2):#Checking that both lists have the same lenght after right justifying
        for i in range (len(rs1)):#For loop that replaces any like characters in both lists with blank spaces
            if rs1[i] == rs2[i]:
                rs1[i] = ' ' 
                rs2[i] = ' ' 
    while ' ' in rs1: #While loop to remove blank spaces in rs1       
        rs1.remove(' ')

    while ' ' in rs2:
        rs2.remove(' ')

    s_rs1 = "".join(rs1) #Creates a new srting after removing like terms during right justification
    s_rs2 = "".join(rs2)

    #*************************************Part 5: compare and select shorter string or first alphabetical*****************************************

    if len(s_rs1) < len(s_rs2):#If statements to select smallest string between s_rs1 and s_rs2
        s = s_rs1

    if len(s_rs1) > len(s_rs2):
        s = s_rs2

    if len(s_rs1) == len(s_rs2):#If the length of both rs1 and rs2 are th same, sort alphabetically--
        both = [s_rs1,s_rs2]    #the 2 strings and return the first string
        b = sorted(both)
        k = b[:1]
        s = (''.join(k))
    return s
               

#-----------------------------------------------
# Auxiliary code for reading input and writing output
input = 'input.txt'
output = 'output.txt'

def readinput():
  words=[]
  with open(input) as f:
    lines = f.readlines()
    for line in lines:
      if line.split()!=[]:
        words.append(line.split())

  for j in range (0,len(words)):
    for i in range(0,len(words[j])):
      words[j][i]=(words[j][i])

  return words


def writeoutput(line):
  with open(output,'a') as f:
     f.write(str(line)+'\n')

def clearoutput():
  f=open(output,'w')
  f.write('')

allinputs = readinput()

clearoutput()
for line in allinputs:
    S1 = line[0]
    S2 = line[1]
    writeoutput(remove_doubleconsonant_vowels_L_R_Justify(S1,S2))
    print(remove_doubleconsonant_vowels_L_R_Justify(S1,S2))