Easy game? P60219


Statement
 

pdf   zip

Consider the following game. You start with an empty set of words SS. Afterwards, you will be given words one by one. For every given word ww, if ww is not in SS, insert ww in SS, and if ww is already in SS, remove ww from SS. At the end of the process, you must list

  • the words that belong to SS;

  • the words that have been in SS, but that finally are not in SS.

Input

Input consists of one or more cases. Every case consists of words made up of only lowercase letters. Each case ends with “END”, except the last case, which ends with “QUIT”.

Take into accout that the “big” private test cases have words repeated many times. If your program uses too much memory, you may receive a “WA” veredict.

Output

For every case, print its game number starting at 1. Then, print the words that are in SS, followed by a blank line, followed by the words that are not in SS but that at some moment were in SS. The first list must be sorted in alphabetical order. The second list must be sorted by the length of the words (first the shorter words), using alphabetical order to break ties. Separate the output of two consecutive games by a blank line.

Public test cases
  • Input

    abc  de  xy
    abc  de  xy  END
    de abc de de QUIT
    

    Output

    GAME #1
    HAS:
    
    HAD:
    de
    xy
    abc
    
    GAME #2
    HAS:
    abc
    de
    
    HAD:
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++ Python
    User solutions
    C++ Python