cswork / OAOpen practice workspace

UberOA #28

Count Routes

Estimated HardJudge-ready

Topics (AI-labelled)Grid DPPrefix & Ranges

Climb from the bottom row to the top row, using at least 1 and at most 2 distinct holds X in every row; # cannot be held. You cannot move down, and the Euclidean distance between consecutively used holds is at most w. Routes are distinguished by their sequence of holds; count the routes modulo 998244353.

This site's standard input/output is stated explicitly.

Input

The first line contains n m w, followed by n strings of length m over X/#, from top to bottom. 2≤n≤2000, 1≤m,w≤2000.

Output

Output one integer answer.

Example 1

Input:

3 4 1
XX#X
#XX#
#X#X

Output:

2

Example 2

Input:

2 1 1
X
X

Output:

1

Example 3

Input:

2 2 2
##
XX

Output:

0

Example notes

Example 1: from the bottom row you can only continue from column 2, pass through column 2 of the middle row, and reach column 2 of the top row; on the top row you can stop or move on to column 1, for 2 routes in total. Example 2: each of the two rows has one hold, so there is only 1 route. Example 3: the top row has no holds, so it cannot be reached, and the output is 0.

Editorial

Loading solution…