Company: jane street
Difficulty: easy
Cancelling Letters You are given a string S consisting only of the letters 'A' , 'B' , 'C' and 'D' . The string can be transformed in one of two ways: remove a letter 'A' together with an adjacent letter 'B' (that is, delete an occurrence of "AB" or of "BA" ), or remove a letter 'C' together with an adjacent letter 'D' (that is, delete an occurrence of "CD" or of "DC" ). After a removal the two remaining parts of the string are joined, so letters that were not adjacent before may become adjacent and may then be removed as well. Apply the transformation repeatedly, for as long as at least one removal is possible. Print the string that is left when no further removal can be made. If at some point there is more than one possible way to transform the string, any of the valid transformations may be chosen; the final string is the same whichever choices are made. Input Format A single line containing the string S . Output Format Print the resulting string, the one that cannot be transformed