This page is still under construction.

Parts of this page are still being built. What you see may change.

IP Addresses

Time limit1sMemory limit1024 MB

Summary
Given a sequence of IP addresses added one by one, report which distinct addresses grep wrongly skipped because dots act as regex wildcards.
Level

Medium6 of 10

Topics
String, Hash map, Implementation, Brute force
Solved
No attempts yet

Problem

Mati has a website and wants to know exactly who visits it. To track visitors, Mati wrote a script that works as follows:

  • the IP addresses of all visitors seen so far are kept in a single text file;
  • whenever a new request (visitor) arrives, the program grep is used to check whether that IP address occurs in the text file (grep <newIP> <file>);
  • if no match is found, the new address is appended to the end of the file and a notification is sent to Mati;
  • otherwise, nothing is done.

An IP address is a string made of four integers, each in the range 0…2550 \ldots 255, separated by dots (.).

grep is a common tool for searching text files for patterns described by regular expressions. Here Mati uses grep incorrectly, because:

  • grep searches for substrings: the pattern need not start at the beginning of a line nor end at the end of a line;
  • the pattern is interpreted as a regular expression, so a dot (.) in the searched IP address can match any character in the text file (but not the other way around: a digit in the pattern does not match a dot in the file).

You are given the list of all IP addresses processed by Mati's script, in processing order. Determine which addresses Mati's script erroneously failed to add to the file.

Input

The first line contains one integer, the number of IP addresses NN (1≤N≤1 000 0001 \le N \le 1\,000\,000). Each of the next NN lines contains one IP address. The input may contain repeated addresses; in any test, the total number of distinct addresses does not exceed 2 0002\,000.

Output

On the first line, print the number VV of distinct addresses that were not added. On each of the next VV lines, print one of the not-added addresses, in the order of their first appearance in the input.

Examples1

  1. Example 1

    Input
    5
    112.112.112.112
    3.4.5.6
    2.112.112.1
    2.1.2.1
    1.2.1.2
    
    Expected output
    3
    2.112.112.1
    2.1.2.1
    1.2.1.2