cswork / OAOpen practice workspace

Two SigmaOA #3

Replacing Val

Estimated EasyJudge-ready

Topics (AI-labelled)Grid Search

Change the start cell, and every position connected to it through up/down/left/right cells with the same original value, to the given value; cells that touch only diagonally are not connected.

Input

The first line contains the number of rows r, the number of columns c, the start row and column, and the replacement value, followed by r lines of the matrix. The original constraints are Unknown; this site specifies 1≤r,c≤1000, matrix and replacement values in −10^9..10^9, and a valid 0-based start. It does not pretend that the bounds added by the catalog are the original bounds.

Output

Output the replaced matrix as r lines of c integers each, without repeating the dimensions.

Example 1

Input:

2 3 1 1 2
0 1 0
1 1 0

Output:

0 2 0
2 2 0

Example 2

Input:

2 2 0 0 3
1 0
0 1

Output:

3 0
0 1

Example 3

Input:

1 1 0 0 -1
-1

Output:

-1

Example notes

The outputs of the three public examples are, in order: 0 2 0 / 2 2 0; 3 0 / 0 1; -1. They have been checked by independent enumeration or direct simulation.

Editorial

Loading solution…