#1296. Problem C. 黑白立方格

Problem C. 黑白立方格

Given a cubic lattice of size N×M×LN \times M\times L such that each lattice point (i,j,k)(i,j,k) is either white or black. The coordinates of the lattice point are all positive integers. Let the cost of flipping the color of lattice point (i,j,k)(i,j,k) be ai,j,ka_{i,j,k}. Find the minimum cost to flip the colors of lattice points such that the bottom left corner (1,1,1)(1,1,1) is black, the top right corner (N,M,L)(N,M,L) is white, and any two different lattice points (i1,j1,k1)(i_1, j_1, k_1) and (i2,j2,k2)(i_2,j_2,k_2) satisfy at least one of the following conditions.

Input

The first line includes three integers N,M,LN, M, L (1N,M,L5×1031\le N, M, L\le 5\times 10^3, 2N×M×L5×1032 \leq N \times M \times L \leq 5\times 10^3), denoting the size of the lattice. Each of the next L×NL \times N lines contains a string of length MM that only consists of \t{B} and \t{W}. The initial color of lattice point (i,j,k)(i,j,k) is the jj-th character of the (k1)×N+i(k-1) \times N + i line. If the character is \t{B}, it means the color of the lattice point is black, otherwise it is white. Each of the next L×NL \times N lines contains MM non-negative integers not greater than 10510^5. The cost of flipping the color of lattice point (i,j,k)(i,j,k) is the jj-th integer of the (k1)×N+i(k-1) \times N + i line.

Output

Output the minimum cost.

Example

2 2 2
WW
WW
BB
BB
1 1
1 1
2 2
2 2
5