#K92767. Taco: IP Block Checker

    ID: 38271 Type: Default 1000ms 256MiB

Taco: IP Block Checker

Taco: IP Block Checker

You are given a list of blocked IP ranges in CIDR notation and a list of IP addresses. For each IP address, determine whether it is blocked or allowed. An IP is blocked if it falls into any of the CIDR ranges provided.

The CIDR (Classless Inter-Domain Routing) notation is of the form a.b.c.d/x where a, b, c, d are the octets of the IP address and x is the number of bits used for the network mask. The mask can be computed using the formula: $$mask = \left(2^{32} - 1\right) \ll (32 - x)$$ and an IP is in the network if:

$$\text{IP} \; \& \; mask = network \; \& \; mask$$

Your task is to implement a solution that reads input from stdin and writes the results to stdout, with each result on a new line.

inputFormat

The input is given via stdin in the following format:

 n
 cidr_1
 cidr_2
 ...
 cidr_n
 m
 ip_1
 ip_2
 ...
 ip_m

Where:

  • n is the number of CIDR notations.
  • Each cidr_i is a string representing a blocked IP range, e.g., 192.168.1.0/24.
  • m is the number of IP addresses to check.
  • Each ip_j is an IP address in dotted decimal notation.

outputFormat

The output must be printed to stdout with exactly m lines. Each line corresponds to the respective IP address from the input. For each IP, print blocked if the IP is within any of the CIDR ranges, otherwise print allowed.

## sample
1
192.168.1.0/24
1
192.168.1.100
blocked

</p>