ICPC 2020 · Problem L · Sweep Stakes

44th ICPC · Moscow, Russia

Statement

Time limit: 20 seconds

You may have already won! In fact, you did already win! You won your very own island, in the deepest reaches of the unexplored ocean! Well, mostly unexplored. As it happens, there was a small military base there before you, and when they packed up and flew out they left behind an assortment of scraps, munitions, tunnels, . . . and unexploded defensive ordnance. That’s right: You now possess your very own minefield.

The minefield consists of an m×nm\times n grid, with any square of the grid holding 0 or 1 mines. Fortunately, you were able to recover the engineers’ plans from when they deployed the mines. Unfortunately, the exact locations of the mines were never written down: the engineers had a preselected independent probability of deploying a mine in each square. However, you do know how many mines were placed in total.

You would like to estimate how safe various parts of your island are. Write a program to compute the probability of mine counts over various subsets of the minefield.

Input

The first line of input contains four integers mm, nn, tt, and qq, where mm and nn (1m,n5001 \le m, n \le 500) are the dimensions of the minefield, tt (0tmn0 \le t \le mn) is the total number of mines, and qq (0q5000 \le q \le 500) is the number of queries. The second line contains mm real numbers p1,p2,...,pmp_{1}, p_{2}, . . . , p_{m} (0pi0.10 \le pi \le 0.1 for all ii, with at most six digits after the decimal point specified), and the third line contains nn real numbers q1,q2,...,qnq_{1}, q_{2}, . . . , q_{n} (0qj0.10 \le qj \le 0.1 for all jj, with at most six digits after the decimal point specified). The preselected probability of the engineers placing a mine on square (i,j)(i, j) is pi+qjpi+qj. All choices of whether to place a mine on a given square were made independently, and the value of tt is chosen so that the probability of deploying exactly tt mines is at least 10510^{- 5}.

Each of the remaining qq lines describes a single query. Each of those lines begins with an integer ss (0s5000 \le s \le 500), followed by ss pairs of integers ii and jj (1im1 \le i \le m, 1jn1 \le j \le n), which are the coordinates of ss distinct squares in the grid.

Output

For each query with ss squares, output s+1s+ 1 real numbers, which are the probabilities of the ss given squares containing 0,1,...,s0,1, . . . , s mines. Your answer should have an absolute error of at most 10610^{- 6}.

Sample Input 1

2 2 1 2
0.05 0.05
0.05 0.05
1 1 1
2 2 1 1 2

Sample Output 1

0.75 0.25
0.5 0.5 0

ICPC World Finals 2020 Problem L: Sweep Stakes

Sample Input 2

3 4 3 4
0.02 0.04 0.06
0.005 0.07 0.035 0.09
1 3 2
3 1 4 2 4 3 4
4 1 2 2 3 3 1 1 4
8 1 1 1 2 1 3 2 1 2 3 3 1 3 2 3 3

Sample Output 2

0.649469772 0.350530228
0.219607636 0.527423751 0.237646792 0.015321822
0.267615440 0.516222318 0.201611812 0.014550429 0
0.054047935 0.364731941 0.461044157 0.120175967 0 0 0 0 0

ICPC World Finals 2020 Problem L: Sweep Stakes

No official solution in the source collection.