#CCC24J5. Harvest Waterloo

Harvest Waterloo

In the farming simulation Harvest Waterloo, pumpkins and hay bales are arranged in a rectangular field. The farmer starts on a pumpkin and can move up, down, left, or right, but cannot move diagonally, through hay bales, or outside the field.

Pumpkin values:

  • S: $1
  • M: $5
  • L: $10

Input Format

  1. Integer R: number of rows
  2. Integer C: number of columns
  3. R lines: field description using S, M, L, *
  4. Integer A: starting row (0-indexed)
  5. Integer B: starting column (0-indexed)

Output Format Output the total pumpkin value the farmer can collect.

Sample Input

6
6
**LMLS
S*LMMS
S*SMSM
******
LLM*MS
SSL*SS
5
1

Sample Output

37

Explanation: reachable pumpkins → 2 small, 1 medium, 3 large = 37.