#P5109. Unlocking the Doors in ION8102

    ID: 18347 Type: Default 1000ms 256MiB

Unlocking the Doors in ION8102

Unlocking the Doors in ION8102

dkw is playing a game called ION8102. In the first chapter, level "归程", she must reach a designated point by sequentially opening m magical doors. Each door is guarded by a special keyhole that controls k rotating locks. Each lock has marks from 0 to v (i.e. there are v+1 positions) and initially displays 0. To open a door, every lock must be rotated to its target position, given by $$a_i$$ for the i-th lock.

dkw possesses n keys. Each key has k rotation amounts, denoted by $$b_{ij}$$, where using the key for one full circle will rotate the j-th lock by $$b_{ij}$$ positions (rotations are performed in the forward direction and taken modulo v+1). Moreover, each door enforces a circle limit of c, meaning that you can use keys for at most c circles in total.

A scheme is defined as a sequence of key usages (one key per circle) so that after a total of t circles (where $$0\le t\le c$$) the state of every dial satisfies $$\sum_{r=1}^{t} b_{i_r j} \equiv a_j \pmod{v+1}$$ for all j (with the convention that when t=0 the state remains 0). Two schemes are considered different if they differ in the total number of circles used or if at least one circle employs a different key.

Your task is to calculate, for each door, the total number of distinct schemes that will successfully unlock it.

inputFormat

The input begins with a line containing five integers: m n k v c, where

  • m is the number of doors,
  • n is the number of keys,
  • k is the number of rotating locks on each door,
  • v determines the maximum mark on each dial (the dials have marks from 0 to v),
  • c is the maximum number of circles you can use on any door.

The second line contains k integers, representing the target positions a1, a2, …, ak for the locks of each door.

Then follow n lines. Each of these lines contains k integers. The i-th of these lines describes the key i with its rotation amounts: bi1, bi2, …, bik.

outputFormat

Output exactly m lines. Each line should contain a single integer representing the number of distinct schemes to unlock one door.

sample

1 1 1 4 3
3
2
0

</p>