Time limit
2s
Memory limit
128 MB
Computers in an IP network each have one IPv4 address. An IP network is represented by a network address and a network mask.
An IPv4 address, a network address, and a network mask are written as four decimal bytes separated by dots. Each byte is between 0 and 255, and no byte has leading zeros.
If each byte is written as 8 binary bits and the four bytes are concatenated, an address can be viewed as a 32-bit value. If a network contains 2m addresses, the first 32−m bits of the network address are fixed and the last m bits are 0. The network mask has 1 in the first 32−m bits and 0 in the last m bits. The network contains every IP address whose first 32−m bits equal the network address.
You are given IP addresses that all belong to the same network. Print the network address and network mask for the smallest network that contains all given addresses.
The first line contains an integer n (1≤n≤1,000). Each of the next n lines contains one computer's IPv4 address.
Print the network address on the first line and the network mask on the second line.