Happy words in a matrix

Implement a program that reads matrices of characters from the input,
and prints the number of happy subwords contained in each of those
matrices.

A happy subword is an occurrence (inside the matrix) of one of these
submatrices:

    :-)

    (-:

    "
    |
    v

    ^
    |
    "

Input

The input has several cases. Each case begins with a line with two
positive naturals n, m. Next, there are n lines with m characters each,
chosen from {’:’,’-’,’(’,’)’,’"’,’v’,'|','^'}. Consecutive cases are
separated by a blank line.

Output

For each case, the program prints in one line the number of happy
subwords contained in the input matrix.

Observation

Grading up to 10 points:

- Slow solution: 5 points.

- Fast solution: 10 points.

We understand as a fast solution one which is correct, with linear cost
and which passes the public and private tests. We understand as slow
solution one which is not fast, but it is correct and passes the public
tests.

Problem information

Author: PRO1

Generation: 2026-01-25T14:42:42.998Z

© Jutge.org, 2006–2026.
https://jutge.org
