## LCC '18 Contest 1 J2 - Subnetting

View as PDF

Points: 7 (partial)
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

In computer networking, IPs allow you to reach another computer by an address.

Currently, the main standard for IP addresses is called IPv4. IPv4 addresses are formatted with four blocks in form a.b.c.d, each block can only contain values between $$0$$ and $$255$$, inclusive.

Ranges of IP addresses can be formatted in the form $$x-y$$, where $$x$$ and $$y$$ are IP addresses. IP ranges are inclusive.

An IP address $$x$$ is less than an IP address $$y$$ only when:

• $$x.a < y.a$$ OR
• $$x.a = y.a$$ and $$x.b < y.b$$ OR
• $$x.a = y.a$$ and $$x.b = y.b$$ and $$x.c < y.c$$ OR
• $$x.a = y.a$$ and $$x.b = y.b$$ and $$x.c = y.x$$ and $$x.d < y.d$$

in this order.

Evan notices that certain IP ranges often cause trouble on his servers, so he wants to block them.

Can you write a program for Evan that checks if a given IP is in a list of ranges?

#### Input Specification

The first line of input provides the number of IP ranges, $$N\ (1 \le N \le 100)$$. $$N$$ IP ranges follow. All IP ranges will be valid IP ranges, and will end with an IP larger than the start IP, as defined in the problem statement.

The final line is the IP address that Evan wants to test.

##### Output Specification

The output will be bad ip if the IP is in any of the ranges or good ip if it is not in any range.

#### Sample Input

3
1.0.0.0-1.1.1.1
1.2.3.4-31.31.31.31
5.5.2.4-44.42.55.255
3.3.3.3

#### Sample Output

bad ip