{"raw_statement":[{"iden":"statement","content":"Let's consider the following game. We have a rectangular field _n_ × _m_ in size. Some squares of the field contain chips.\n\nEach chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right.\n\nThe player may choose a chip and make a move with it.\n\nThe move is the following sequence of actions. The chosen chip is marked as the current one. After that the player checks whether there are more chips in the same row (or in the same column) with the current one that are pointed by the arrow on the current chip. If there is at least one chip then the closest of them is marked as the new current chip and the former current chip is removed from the field. After that the check is repeated. This process can be repeated several times. If a new chip is not found, then the current chip is removed from the field and the player's move ends.\n\nBy the end of a move the player receives several points equal to the number of the deleted chips.\n\nBy the given initial chip arrangement determine the maximum number of points that a player can receive during one move. Also determine the number of such moves."},{"iden":"input","content":"The first line contains two integers _n_ and _m_ (1 ≤ _n_, _m_, _n_ × _m_ ≤ 5000). Then follow _n_ lines containing _m_ characters each — that is the game field description. \"_._\" means that this square is empty. \"_L_\", \"_R_\", \"_U_\", \"_D_\" mean that this square contains a chip and an arrow on it says left, right, up or down correspondingly.\n\nIt is guaranteed that a field has at least one chip."},{"iden":"output","content":"Print two numbers — the maximal number of points a player can get after a move and the number of moves that allow receiving this maximum number of points."},{"iden":"examples","content":"Input\n\n4 4\nDRLD\nU.UL\n.UUR\nRDDL\n\nOutput\n\n10 1\n\nInput\n\n3 5\n.D...\nRRRLL\n.U...\n\nOutput\n\n6 2"},{"iden":"note","content":"In the first sample the maximum number of points is earned by the chip in the position (3, 3). You can see its progress at the following picture:\n\n<center>![image](https://espresso.codeforces.com/84ee56080a3b653a0ae6d3933850dbfadd95e63b.png)</center>All other chips earn fewer points."}],"translated_statement":[{"iden":"statement","content":"考虑以下游戏。我们有一个大小为 #cf_span[n × m] 的矩形棋盘，某些格子上放置了棋子。\n\n每个棋子上都画有一个箭头，指向以下四个方向之一：上、下、左或右。\n\n玩家可以选择一个棋子并执行一次移动。\n\n移动的流程如下：选定的棋子被标记为当前棋子。接着，玩家检查在当前棋子所在的行或列中，是否存在至少一个被当前棋子箭头所指向的其他棋子。如果存在，则将其中最近的一个标记为新的当前棋子，并将原当前棋子从棋盘上移除。然后重复此检查过程。该过程可以多次进行。若未找到新的棋子，则移除当前棋子，玩家的移动结束。\n\n在移动结束时，玩家获得的分数等于被移除的棋子数量。\n\n给定初始的棋子布局，请确定玩家在一次移动中能获得的最大分数，以及能获得该最大分数的移动方式的数量。\n\n第一行包含两个整数 #cf_span[n] 和 #cf_span[m]（#cf_span[1 ≤ n, m, n × m ≤ 5000]）。接下来 #cf_span[n] 行，每行包含 #cf_span[m] 个字符，表示游戏棋盘。\"_._\" 表示该格子为空；\"_L_\"、\"_R_\"、\"_U_\"、\"_D_\" 分别表示该格子包含一个箭头指向左、右、上或下的棋子。\n\n保证棋盘上至少有一个棋子。\n\n请输出两个数字：玩家在一次移动中能获得的最大分数，以及能获得该最大分数的移动方式的数量。\n\n在第一个样例中，最大分数由位置 #cf_span[(3, 3)] 的棋子获得。其移动过程如下图所示：\n\n其他所有棋子获得的分数均较少。"},{"iden":"input","content":"第一行包含两个整数 #cf_span[n] 和 #cf_span[m]（#cf_span[1 ≤ n, m, n × m ≤ 5000]）。接下来 #cf_span[n] 行，每行包含 #cf_span[m] 个字符，表示游戏棋盘。\"_._\" 表示该格子为空；\"_L_\"、\"_R_\"、\"_U_\"、\"_D_\" 分别表示该格子包含一个箭头指向左、右、上或下的棋子。保证棋盘上至少有一个棋子。"},{"iden":"output","content":"请输出两个数字：玩家在一次移动中能获得的最大分数，以及能获得该最大分数的移动方式的数量。"},{"iden":"examples","content":"输入\n4 4\nDRLD\nU.UL\n.UUR\nRDDO\n\n输出\n10 1\n\n输入\n3 5\n.D...\nRRRLL\n.U...\n\n输出\n6 2"},{"iden":"note","content":"在第一个样例中，最大分数由位置 #cf_span[(3, 3)] 的棋子获得。其移动过程如下图所示：   其他所有棋子获得的分数均较少。"}],"sample_group":[],"show_order":[],"formal_statement":"Let $ G = (V, E) $ be a directed graph defined on a grid of size $ n \\times m $, where:\n\n- $ V $ is the set of positions $ (i, j) $ containing a chip (i.e., non-empty cells with directions $ \\{L, R, U, D\\} $).\n- For each chip at position $ (i, j) $ with direction $ d \\in \\{L, R, U, D\\} $, define its **target** as the closest chip in the direction $ d $ along row $ i $ (if $ d \\in \\{L, R\\} $) or column $ j $ (if $ d \\in \\{U, D\\} $). If no such chip exists, no outgoing edge is defined.\n- An edge $ (u, v) \\in E $ exists if and only if $ v $ is the closest chip to $ u $ in the direction of $ u $’s arrow.\n\nEach move corresponds to starting at a vertex $ v_0 \\in V $ and following the unique directed path $ v_0 \\to v_1 \\to \\cdots \\to v_k $ until no outgoing edge exists (i.e., the path terminates). The score of the move is $ k+1 $, the number of vertices visited (including the start).\n\nDefine:\n\n- $ \\text{score}(v) $: the length of the path starting at vertex $ v $ under the above transition rule.\n- $ M = \\max_{v \\in V} \\text{score}(v) $\n- $ C = |\\{ v \\in V \\mid \\text{score}(v) = M \\}| $\n\n**Objective:**\n\nCompute $ M $ and $ C $.\n\n---\n\n**Formal Constraints:**\n\n- Grid dimensions: $ 1 \\leq n, m \\leq 5000 $, $ n \\times m \\leq 5000 $\n- Each cell is either empty or contains one chip with direction in $ \\{L, R, U, D\\} $\n- For each chip at $ (i, j) $:\n  - If direction = $ L $: find $ \\min\\{ j' < j \\mid (i, j') \\in V \\} $, if exists → edge to $ (i, j') $\n  - If direction = $ R $: find $ \\max\\{ j' > j \\mid (i, j') \\in V \\} $, if exists → edge to $ (i, j') $\n  - If direction = $ U $: find $ \\min\\{ i' < i \\mid (i', j) \\in V \\} $, if exists → edge to $ (i', j) $\n  - If direction = $ D $: find $ \\max\\{ i' > i \\mid (i', j) \\in V \\} $, if exists → edge to $ (i', j) $\n\nThe graph $ G $ is a functional graph (each node has out-degree ≤ 1), hence each connected component is a tree of chains directed toward a cycle or a sink.\n\nSince transitions are deterministic and each node has at most one outgoing edge, the path from any starting node is unique and finite (no cycles possible in practice due to strict directionality and grid monotonicity — e.g., moving left always decreases column index, etc.), so all paths terminate.\n\nThus, $ \\text{score}(v) $ is the number of nodes in the unique path starting at $ v $ until no next node exists.\n\nCompute $ M = \\max_{v \\in V} \\text{score}(v) $, $ C = \\#\\{ v \\in V : \\text{score}(v) = M \\} $\n\nOutput: $ M $ and $ C $","simple_statement":null,"has_page_source":false}