404767: GYM101628 D Don't Lose The Droid

Memory Limit:1024 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Don't Lose The Droidtime limit per test1 secondmemory limit per test1024 megabytesinputstandard inputoutputstandard output

The Inter-space Navigation Center (CIN in portuguese) launched a probe in a distant planet. To know its precise location, the Center will need to maintain a satellite following its steps. That way, the satellite needs first to find the probe in the terrain of the unknown planet, which can be considered a matrix of N lines and M columns.

While operating, the probe emits a log with the taken actions at each instant of time. Let (Xi, Yi) be the position of the probe at instant i, these actions can be:

  • C: The probe moves upwards (Xi + 1 = Xi + 1)
  • D: The probe moves rightwards (Yi + 1 = Yi + 1)
  • B: The probe moves downwards (Xi + 1 = Xi - 1)
  • E: The probe moves leftwards (Yi + 1 = Yi - 1)

At instant T all the logs emited by the probe since instant 0 will be available. Your task is compute all positions that must be checked at instant T so that the probe is guaranteedly found.

The satellite is capable of analyzing as many positions as they're necessary, but you must not check any position for which there are enough data to determine that the probe can't be there.

Input

The first line contains 2 space separated integers, N and M (1 ≤ N, M ≤ 106, 1 ≤ N × M ≤ 106), the number of lines and the number of coulmns in the matrix.

The second line contains 1 integer T (1 ≤ T ≤ 106), the current instant. T lines follow. The (i + 2)-th line contains 1 character, li (), the probe's log at instant i.

Output

In the first line, print 1 integer, Q (1 ≤ Q ≤ N * M), the number of positions to be verified.

Then, print Q lines. In the (j + 1)-th line, print 2 space separated integers, Xj (1 ≤ Xj ≤ N) and Yj (1 ≤ Yj ≤ N), the j-th coordinates of the matrix to be verified.

ExamplesInput
3 3
3
D
D
B
Output
2
1 3
2 3
Input
1 3
1
E
Output
2
1 1
1 2

加入题单

算法标签: