Under construction

Still being built. Things may change

INK

Time limit1sMemory limit1024 MB

Summary
Simulate a square on an N by N grid that moves, stores ink, and jumps to dye obstacles within Manhattan distance, then print the final grid.
Level

Easy3 of 10

Topics
Simulation, Implementation
Solved
No attempts yet

Problem

INK is a platformer puzzle game where you steer a white square past various hazards to reach the goal. Each time the white square jumps, it scatters ink of a color. When the ink hits a transparent obstacle, the obstacle is dyed. After that, the player can see the dyed obstacle.

A stage is an N×NN \times N grid. (y,x)(y, x) is the cell in row yy and column xx. Each cell is either empty or an obstacle. The player enters KK commands in total to steer the square. The commands are:

  • Move commands: the uppercase letters U, D, L, R, which move the square one cell up, down, left, or right. If the move takes the square outside the stage or onto an obstacle, the command is ignored.
  • Ink command: the lowercase letter j. It increases the square's ink amount by 1. The ink amount is 0 at the start.
  • Jump command: the uppercase letter J. The square jumps in place and scatters ink. The amount of scattered ink equals the square's current ink amount. Right after the jump, the square's ink amount becomes 0.

When ink of color cic_i and amount mim_i is scattered at (yi,xi)(y_i, x_i), every obstacle cell (a,b)(a, b) with ∣yi−a∣+∣xi−b∣≤mi|y_i-a|+|x_i-b| \le m_i is painted cic_i. If an obstacle is already painted a different color, it is repainted with the color of the later ink that reaches it.

The ink color depends on the jump count and the ink string. The ink string is an uppercase string of length II. The color of the (t×I+d)(t \times I + d)-th jump is the dd-th character of the ink string, where tt is a non-negative integer and 1≤d≤I1 \le d \le I. For example, the 1st jump uses the 1st character, the 2nd jump uses the 2nd character, the II-th jump uses the II-th character, the (I+1)(I+1)-th jump uses the 1st character, and the (I+2)(I+2)-th jump uses the 2nd character.

Input

The first line has three integers II, NN, and KK, separated by spaces. (1≤I,N,K≤1001 \le I, N, K \le 100)

The second line is the ink string.

The next NN lines give the N×NN \times N stage. @ is the square, . is an empty cell, and # is an obstacle. There is exactly one square.

The last line contains the KK commands with no spaces between them.

Output

Print the final stage as NN lines of NN characters each.

Print @ for the square, . for an empty cell, # for an undyed obstacle, and the uppercase letter of the ink color for a dyed obstacle.

Examples3

  1. Example 1

    Input
    3 4 12
    RGB
    .@..
    .##.
    .##.
    ....
    jJRRJjjDDjDJ
    
    Expected output
    ....
    .RB.
    .BB.
    ...@
    
  2. Example 2

    Input
    7 5 17
    UTILCUP
    .@...
    .#.#.
    ...#.
    ##.##
    ##...
    JjjUUJRJLLJJjjjjJ
    
    Expected output
    @....
    .U.U.
    ...#.
    UU.##
    U#...
    
  3. Example 3

    Input
    4 2 10
    ABCD
    @#
    ##
    JJJJDJjjjJ
    
    Expected output
    @B
    BB