Experience is Worth It

아직 제출이 없습니다시간 제한5초메모리 제한256 MB

문제

Pasha is playing the video game "DiaBro III". He is fighting against nmn \cdot m monsters in this game. The monsters are arranged into nn rows of mm columns each. Rows are numbered with sequential integers from 11 to nn and columns --- with sequential integers from 11 to mm.

Each monster has one of kk types. The ii-th monster type is described by two integers q_iq\_{i} and g_ig\_{i}: Pasha can kill a monster of ii-th type only if amount of his experience is at least q_iq\_{i}, and after killing each monster of this type --- Pasha will gain g_ig\_{i} units of experience.

Pasha wants to choose a rectangle by fixing four integers r_1r\_{1}, r_2r\_{2}, c_1c\_{1} and c_2c\_{2} such that 1r_1r_2n1 \leq r\_{1} \leq r\_{2} \leq n and 1c_1c_2m1 \leq c\_{1} \leq c\_{2} \leq m. Then Pasha starts to kill monsters in the chosen rectangle --- at cells (r,c)(r, c) such that r_1rr_2r\_{1} \leq r \leq r\_{2} and c_1cc_2c\_{1} \leq c \leq c\_{2}. Initially, he has no experience at all. The rectangle is good if it is possible to kill all monsters inside the rectangle in some order without killing any monster which is not in the rectangle.

You are to write a program that will find the number of different good rectangles.

입력

The first line of input contains two integers nn and mm (1n,m2001 \leq n, m \leq 200) --- the number of rows and columns of monsters respectively.

Each of the following nn lines contains exactly mm lowercase Latin letters. The jj-th character of ii-th line denotes the type of monster with row number ii and column number jj. Monsters of the same type are denoted with the same lowercase Latin letter. 

The next line contain the only integer kk (1k261 \leq k \leq 26) --- the number of monster types.

Each of the following kk lines contains the description of some monster type. The description of ii-th monster type consists of character l_il\_{i} --- the lowercase Latin letter corresponding to this monster type --- and two integers q_iq\_{i} and g_ig\_{i} (0q_i109,1g_i1090 \leq q\_{i} \leq 10^{9}, 1 \leq g\_{i} \leq 10^{9}) --- the amount of experience required to kill a monster of this type and the amount of experience obtained after killing each monster of this type respectively. The values of l_il\_{i}, q_iq\_{i} and g_ig\_{i} are separated by single spaces.

It is guaranteed that there is no monster of type that is not described in the input.

출력

The only line of output should contain one integer --- the number of ways to choose values r_1r\_{1}, r_2r\_{2}, c_1c\_{1} and c_2c\_{2} to satisfy all the conditions given above.

힌트

There are 1111 possible values of r_1r\_{1}, r_2r\_{2}, c_1c\_{1} and c_2c\_{2} in the first sample:

  1. r\_{1} = 1,\~\~\~r\_{2} = 1,\~\~\~c\_{1} = 1,\~\~\~c\_{2} = 1;
  2. r\_{1} = 1,\~\~\~r\_{2} = 1,\~\~\~c\_{1} = 1,\~\~\~c\_{2} = 3;
  3. r\_{1} = 1,\~\~\~r\_{2} = 1,\~\~\~c\_{1} = 3,\~\~\~c\_{2} = 3;
  4. r\_{1} = 1,\~\~\~r\_{2} = 2,\~\~\~c\_{1} = 1,\~\~\~c\_{2} = 2;
  5. r\_{1} = 1,\~\~\~r\_{2} = 2,\~\~\~c\_{1} = 1,\~\~\~c\_{2} = 3;
  6. r\_{1} = 1,\~\~\~r\_{2} = 2,\~\~\~c\_{1} = 2,\~\~\~c\_{2} = 3;
  7. r\_{1} = 1,\~\~\~r\_{2} = 2,\~\~\~c\_{1} = 3,\~\~\~c\_{2} = 3;
  8. r\_{1} = 2,\~\~\~r\_{2} = 2,\~\~\~c\_{1} = 1,\~\~\~c\_{2} = 3;
  9. r\_{1} = 2,\~\~\~r\_{2} = 2,\~\~\~c\_{1} = 2,\~\~\~c\_{2} = 2;
  10. r\_{1} = 2,\~\~\~r\_{2} = 2,\~\~\~c\_{1} = 2,\~\~\~c\_{2} = 3;
  11. r\_{1} = 2,\~\~\~r\_{2} = 2,\~\~\~c\_{1} = 3,\~\~\~c\_{2} = 3.