Getting a Jump on Crime

Given building heights on a grid, find the minimum number of jumps to reach each roof, where a jump is valid only if its parabola clears every building between the two roofs.

Hard8GraphBFSGeometryImplementationNo attempts yetTime limit2sMemory limit1024 MB

Problem

Your friend Robin is a superhero. When you first found out, you figured that everybody needs a hobby and that this one is more exciting than stamp collecting. Now you are simply glad that somebody is doing something about the crime in your hometown.

Every night Robin patrols the city by jumping from roof to roof and watching what goes on below. A superhero has to respond to a crisis immediately, so Robin asked you for help in working out how to get around town quickly.

Your hometown is built on a square grid. Each block is w×ww \times w meters and holds a single building. The buildings may have different heights. To get from one building to another building, not necessarily an adjacent one, Robin makes a single jump from the center of the roof of the first building to the center of the roof of the second building. Robin cannot change direction while in the air, but can choose the angle of takeoff.

Cross-section of the buildings in the first example. The buildings are drawn in black, and the jump from the roof at (1,1)(1, 1) to the roof at (4,1)(4, 1) is the green line.

Robin only wants to perform jumps without colliding with any building. Such a collision does little damage to a superhero, but building owners get irritated when somebody crashes through their windows. So you explain the physics. Every jump starts with the same initial speed vv, which splits into a horizontal component vdv_d toward the destination and a vertical component vhv_h upward, so vd2+vh2=v2v_d^2 + v_h^2 = v^2. The horizontal speed stays constant, vd(t)=vdv_d(t) = v_d, while gravity pulls on the vertical speed, vh(t)=vhtgv_h(t) = v_h - t g, where g=9.80665 m/s2g = 9.80665\ \mathrm{m/s^2} in your hometown. Robin's cape cancels air resistance. Somewhere in the middle of the derivation you notice that Robin has dozed off. Less math, more super-heroing.

So it falls to you. Given the layout of the city and the location of Robin's secret hideout, work out which roofs Robin can reach and the minimum number of jumps it takes to get to each roof.

If a jump passes over a corner where four buildings meet, the jump has to be higher than all four of those buildings.

Input

The first line has six integers dxd_x, dyd_y, ww, vv, x\ell_x, y\ell_y. They give the size dx×dyd_x \times d_y of the city grid in blocks (1dx,dy201 \le d_x, d_y \le 20), the width ww of each building in meters (1w1031 \le w \le 10^3), Robin's takeoff speed vv in meters per second (1v1031 \le v \le 10^3), and the coordinates (x,y)(\ell_x, \ell_y) of Robin's secret hideout (1xdx1 \le \ell_x \le d_x, 1ydy1 \le \ell_y \le d_y).

The first line is followed by a description of the heights of the buildings in the city grid. The description has dyd_y lines, each with dxd_x non-negative integers. The jj-th line holds the heights of buildings (1,j),(2,j),,(dx,j)(1, j), (2, j), \ldots, (d_x, j). All heights are given in meters and are at most 10310^3.

Output

Display the minimum number of jumps Robin needs to get from the secret hideout to the roof of each building. If there is no way to reach a building's roof, display X instead of the number of jumps. Display the buildings in the same order as the input, split into dyd_y lines of dxd_x values, and separate the values on a line with a single space.

You may assume that changing the height of any building by up to 10610^{-6} would not change the answers.