QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 1024 MB Total points: 100

#15227. Subnet

Statistics

Iris has just learned about IPv4 subnets.

Given a subnet and several IP addresses, please help Iris determine whether each address belongs to this subnet.

Input

The first line contains a subnet in CIDR format.

The second line contains an integer $n$ ($1 \le n \le 1000$), the number of IP addresses to check.

The next $n$ lines each contain an IP address in dotted-decimal notation.

Output

For each of the $n$ lines, output "YES" or "NO" (excluding the quotes) to indicate whether the address belongs to the given subnet.

Examples

Input 1

192.168.88.0/24
5
10.1.1.1
10.2.3.4
192.168.88.0
192.168.88.88
182.168.0.0

Output 1

NO
NO
YES
YES
NO

Input 2

10.0.0.0/16
5
10.0.0.0
10.1.2.3
10.88.88.88
10.0.6.6
172.255.255.255

Output 2

YES
NO
NO
YES
NO

Note

An IPv4 address is a 32-bit binary number, usually composed of four octets. The maximum value that can be represented by an octet is 255 (binary 11111111). Dotted-decimal notation is a format for representing IP addresses, where the four octets of the IP address are separated by dots (.). Each octet is a decimal number between 0 and 255, hence the name dotted-decimal.

An IP address can be divided into a network portion and a host portion by a subnet mask. IP addresses with the same network portion belong to the same subnet. A subnet mask is a 32-bit binary number consisting of a sequence of $1$s followed by a sequence of $0$s, where $1$ represents the network bits and $0$ represents the host bits. For example, 255.255.255.0 (11111111 11111111 11111111 00000000) indicates that the first 24 bits are the network portion and the last 8 bits are the host portion.

CIDR (Classless Inter-Domain Routing) is a simplified and extended way of representing IP addresses, allowing for more flexible definition and allocation of IP addresses and their subnets. CIDR notation is represented by adding a slash '/' followed by a number between 0 and 32 (inclusive) after the IP address to indicate the length of the network portion. This number represents the number of consecutive leading $1$s in the subnet mask.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.