
import java.util.regex.*;
import java.util.TreeSet;
import java.util.Scanner;
import java.io.File;
import java.io.IOException;

/**
 * This program reads its input, extracts all the words
 * from the input, converts them to lower case, and outputs
 * a list of all words found, in sorted order, with
 * duplicates removed.  If a command line argument is
 * specified when the program is run, the program attempts
 * to use that argument as a file name, and it reads its
 * input from that file.  If no command-line argument is
 * given, the program reads its input from standard input.
 * Output is always written to standard output.
 *     A "word" for this program is considered to be a sequence
 * of upper and lower case ASCII letters (A through Z), possibly
 * with apostrophes embedded; an apostrophe is considered
 * to be part of a word if it is surrounded by letters on
 * both sides.  (Using a regular expression and a TreeSet,
 * this program couldn't've been easier.)
 */
public class GetWords {

   public static void main(String[] args) throws IOException {

      Scanner in;
      if (args.length == 0)
         in = new Scanner(System.in);
      else
         in = new Scanner(new File(args[0]));

      TreeSet<String> words = new TreeSet<String>();
      Pattern wordPattern = Pattern.compile("\\b[a-zA-Z]+('[a-zA-Z]+)*\\b");

      while (in.hasNextLine()) {
         Matcher wordMatcher = wordPattern.matcher( in.nextLine() );
         while (wordMatcher.find()) {
            words.add(wordMatcher.group(0).toLowerCase());
         }
      }

      for (String word : words)
         System.out.println(word);

   }

}


