This page is still under construction.

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

Race for the Galaxy

Time limit4sMemory limit1024 MB

Summary
Count non-intersecting monotone grid paths for N runners with puddles and mud rows, grouped by how many runners cross the mud row S to S+1.
Level

Hard9 of 10

Topics
Dynamic programming, Combinatorics, Graph
Solved
No attempts yet

Problem

A school playground has a large grid with RR horizontal lines and CC vertical lines. The intersection of the rr-th horizontal line from the top and the cc-th vertical line from the left is called (r,c)(r, c).

Heavy rain yesterday created several obstacles on the playground.

  • Between the SS-th and (S+1)(S+1)-th horizontal lines there is a muddy area covering the segments of NN vertical lines. That is, for each vertical line number t1,t2,⋯ ,tNt_1, t_2, \cdots, t_N, the vertical segment connecting (S,ti)(S, t_i) and (S+1,ti)(S+1, t_i) is covered in mud.
  • There are MM puddles. The jj-th puddle is at (xj,yj)(x_j, y_j).

Hyea plans to draw NN running tracks on the playground, one for each of NN runners, for a race at the sports day. The event is meant to build harmony more than to record times, so the race has several rules.

  • The goal of each track is to start at the starting point on the first horizontal line and finish at the ending point on the last horizontal line. Each runner has a fixed start and end. The ii-th runner starts at (1,ai)(1, a_i) and must finish at (R,bi)(R, b_i). Here a1<a2<⋯<aNa_1 < a_2 < \cdots < a_N and b1<b2<⋯<bNb_1 < b_2 < \cdots < b_N.
  • Runners must run along the horizontal and vertical lines of the grid. They cannot leave the grid, move in a direction that is neither horizontal nor vertical, or change direction anywhere except at an intersection.
  • When moving along a vertical line, a runner must move downward.
  • When moving along a horizontal line, a runner must move left on an odd-numbered horizontal line and must move right on an even-numbered horizontal line.
  • Puddles are dangerous because the ground is dug out there, so no track may pass through an intersection with a puddle.
  • Two runners colliding is also dangerous, so no two tracks may share an intersection.

The rules stated more precisely:

  • The track of the ii-th runner is a sequence of intersections that starts at (1,ai)(1, a_i), ends at (R,bi)(R, b_i), and in which consecutive intersections are adjacent. (1≤i≤N1 \le i \le N) Two intersections (r1,c1)(r_1, c_1) and (r2,c2)(r_2, c_2) are adjacent when ∣r1−r2∣+∣c1−c2∣=1|r_1-r_2|+|c_1-c_2|=1.
  • Every intersection (r,c)(r, c) in a sequence must satisfy 1≤r≤R1 \le r \le R and 1≤c≤C1 \le c \le C.
  • (xj,yj)(x_j, y_j) cannot appear in any sequence. (1≤j≤M1 \le j \le M)
  • For (r,c)(r, c) with 1<r≤R1 < r \le R and 1≤c≤C1 \le c \le C, the element after (r,c)(r, c) cannot be (r−1,c)(r-1, c).
  • For rr and cc with 1≤r≤R1 \le r \le R and 1≤c<C1 \le c < C: if rr is odd, the element after (r,c)(r, c) cannot be (r,c+1)(r, c+1). If rr is even, the element after (r,c+1)(r, c+1) cannot be (r,c)(r, c).
  • Each intersection belongs to at most one sequence.

Among all ways to draw the tracks under these rules, count the number of ways in which exactly kk runners pass through a muddy area, for each k=0,1,⋯ ,Nk = 0, 1, \cdots, N. The numbers can be very large, so print each count modulo the prime 1 000 000 0071\,000\,000\,007 (=109+7=10^9+7).

  • The ii-th runner passes through a muddy area if there is some 1≤j≤N1 \le j \le N such that (S,tj)(S, t_j) and (S+1,tj)(S+1, t_j) appear consecutively in the sequence.

Input

The first line contains RR, CC, NN, MM, and SS, separated by spaces. (3≤R,C≤3003 \le R, C \le 300; 3≤N≤C3 \le N \le C; 0≤M≤3000 \le M \le 300; 1≤S<R1 \le S < R)

The second line contains a1,a2,⋯ ,aNa_1, a_2, \cdots, a_N, separated by spaces. (1≤a1<a2<⋯<aN≤C1 \le a_1 < a_2 < \cdots < a_N \le C)

The third line contains b1,b2,⋯ ,bNb_1, b_2, \cdots, b_N, separated by spaces. (1≤b1<b2<⋯<bN≤C1 \le b_1 < b_2 < \cdots < b_N \le C)

The fourth line contains t1,t2,⋯ ,tNt_1, t_2, \cdots, t_N, separated by spaces. (1≤t1<t2<⋯<tN≤C1 \le t_1 < t_2 < \cdots < t_N \le C)

If M>0M > 0, each of the next MM lines contains xjx_j and yjy_j, separated by a space. (1<xj<R1 < x_j < R; 1≤yj≤C1 \le y_j \le C)

All puddle positions are distinct.

Output

Print N+1N+1 integers on the first line, separated by spaces. The (k+1)(k+1)-th integer is the number of ways in which exactly kk runners pass through a muddy area, modulo 1 000 000 0071\,000\,000\,007 (=109+7=10^9+7). (0≤k≤N0 \le k \le N)

Examples2

  1. Example 1

    Input
    7 5 3 3 4
    1 3 5
    1 3 5
    1 3 4
    2 2
    2 5
    6 4
    
    Expected output
    0 4 6 0
    
  2. Example 2

    Input
    14 6 3 0 7
    1 2 3
    1 2 3
    4 5 6
    
    Expected output
    108900 1439077 95378 1