cho.sh
Notes
Loading...

IP Network Address

Time limit

2s

Memory limit

128 MB

Problem

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 2m2^m2m addresses, the first 32−m32-m32−m bits of the network address are fixed and the last mmm bits are 0. The network mask has 1 in the first 32−m32-m32−m bits and 0 in the last mmm bits. The network contains every IP address whose first 32−m32-m32−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.

Input

The first line contains an integer nnn (1≤n≤1,0001 \le n \le 1{,}0001≤n≤1,000). Each of the next nnn lines contains one computer's IPv4 address.

Output

Print the network address on the first line and the network mask on the second line.