Sorting and eliminating duplicates
Why make it so complicated? Just use basic java 8 streaming operations and the new-ish BufferedReader.lines() method:

public static void main (String[] args) {
    Set&lt;String&gt; uniqueOrderedNames = new TreeSet&lt;&gt;();
    try(BufferedReader br = new BufferedReader(new InputStreamReader (System.in))){
        br.lines().forEach(uniqueOrderedNames::add);
    } catch (Exception e) {
        // don't do this, use the most specific exception type and handle it
    }
    System.out.println(uniqueOrderedNames.size());
    uniqueOrderedNames.forEach(System.out::println);
}


That much for your approach. Before you now copy paste that, I have some more things to say:


Indent correctly: Methods are indented by one level, blocks are indented 1 level. Levels add up. Your method is missing one level of indentation and your created Scanner should be indented 2 more spaces
Add spaces around binary operators: for(int i=0;i&lt;n;i++){ becomes for (int i = 0; i &lt; n; i++) {, which is significantly easier on the eyes.
Use clear names Set set is nonsensical, it doesn't shed any light whatsoever on what the thing does. Give it a proper name so you can understand what happens.