This page is still under construction.

Parts of this page are still being built. What you see may change.

Filter

Time limit1sMemory limit256 MB

Summary
The program checks each Bloom filter against every queried user id and lists the files that may hold at least one of them.
Level

Easy2 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

A database engine named ICPC (Instant Compression and Processing Codec) stores user activity records. Every record carries one integer user identifier. The records live in compressed data files, and one file can hold records of many users. Decompressing a file costs a lot of CPU time, so before it reads a file the engine needs a cheap check that decides whether the file might hold a record of a given user.

The engine runs that check with a Bloom filter. Each database fixes these integer parameters:

  • mm: the number of bits in a filter,
  • ff: the number of hash functions,
  • aia_i for 0≤i<f0 \le i < f: the multiplier of hash function ii.

Every data file has one filter value, a vector of mm bits. Bit jj of that vector (0≤j<m0 \le j < m) is one if and only if the file holds a record of some user identifier uku_k for which

j=(uk×ai) mod mj = (u_k \times a_i) \bmod m

holds for some hash function ii (0≤i<f0 \le i < f).

The file may hold a record of user identifier uku_k if and only if bit (uk×ai) mod m(u_k \times a_i) \bmod m of its filter value is one for every ii (0≤i<f0 \le i < f).

You are given the filter parameters, the filter value of each data file, and a query set of user identifiers. Report every data file that may hold a record of at least one identifier in the query set.

Input

The first line contains the filter parameters mm, ff, and aia_i for 0≤i<f0 \le i < f (1≤m≤10001 \le m \le 1000, 1≤f≤1001 \le f \le 100, 1≤ai<2311 \le a_i < 2^{31}).

The second line contains an integer nn, the number of data files (1≤n≤10001 \le n \le 1000). Each of the next nn lines contains the filter value of one data file in hexadecimal, a string of exactly ⌈m/4⌉\lceil m/4 \rceil characters taken from 0123456789abcdef. The first character carries bits 0 to 3 of the value, ordered from the least significant bit of the hexadecimal digit to its most significant bit. The second character carries bits 4 to 7, the third carries bits 8 to 11, and so on. When m mod 4≠0m \bmod 4 \ne 0, the last character carries the remaining m mod 4m \bmod 4 bits in its least significant bits and its other bits are zero.

The next line contains an integer qq, the number of user identifiers in the query (1≤q≤10001 \le q \le 1000), followed by the qq distinct identifiers uku_k of the query (1≤uk<2311 \le u_k < 2^{31}).

Output

Print on one line the integer ss, the number of data files that may hold a record of at least one identifier of the query, followed by the zero-based numbers dtd_t (0≤dt<n0 \le d_t < n) of those files in increasing order. Separate every number on the line with a single space. When s=0s = 0, print only 00.

Examples3

  1. Example 1

    Input
    23 4 3 5 7 11
    3
    effde7
    c07902
    0800c1
    3 2 4 6
    
    Expected output
    2 0 2
    
  2. Example 2

    Input
    1 2 1 7
    3
    0
    1
    1
    2 5 9
    
    Expected output
    2 1 2
    
  3. Example 3

    Input
    12 3 2 3 5
    4
    000
    000
    000
    000
    3 1 4 11
    
    Expected output
    0