Happy subsequences at increasing positions in a matrix

Given a matrix MM of n×mn\times{}m characters, a happy subsequence at increasing positions is a triple of positions (i1,j1),(i2,j2),(i3,j3)(i_1,j_1),(i_2,j_2),(i_3,j_3) such that M[i1][j1]M[i_1][j_1]=’:’, M[i2][j2]M[i_2][j_2]=’-’, M[i3][j3]M[i_3][j_3]=’)’ and 0i1<i2<i3<n0\leq{}i_1<i_2<i_3<n and 0j1<j2<j3<m0\leq{}j_1<j_2<j_3<m.

Implement a program that reads matrices of characters from the input, and prints the number of happy subsequences at increasing positions in each matrix.

Input

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

Output

For each case, the program prints in one line the number of happy subsequences at increasing positions in the input matrix.

Observation

Grading up to 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-25T13:34:46.785Z

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