#include <bits/stdc++.h>   using namespace std;   int n, m;   char** mat;   short ***sparse, ***rem;   void build() {     sparse = new short**[n + 1];     rem = new short**[n + 1];     for (int i = 0; i <= n; ++i) {       sparse[i] = new short*[m + 1];       rem[i] = new short*[m + 1];     }     for (int i = 0; i <= n; ++i) {       for (int j = 0; j <= m; ++j) {         sparse[i][j] = new short[4];         memset(sparse[i][j], 0, sizeof(short) * 4);         rem[i][j] = new short[4];         memset(rem[i][j], 0, sizeof(short) * 4);       }     }     for (int i = 1; i <= n; ++i) {       int prev = 0;       for (int j = 1; j <= m; ++j) {         if (mat[i][j]) {           sparse[i][j][0] = prev;           prev = j;         }       }       prev = 0;       for (int j = m; j > 0; --j) {         if (mat[i][j]) {           sparse[i][j][1] = prev;           prev = j;         }       }     }     for (int j = 1; j <= m; ++j) {       int prev = 0;       for (int i = 1; i <= n; ++i) {         if (mat[i][j]) {           sparse[i][j][2] = prev;           prev = i;         }       }       prev = 0;       for (int i = n; i > 0; --i) {         if (mat[i][j]) {           sparse[i][j][3] = prev;           prev = i;         }       }     }   }   void remove(int p, int q) {     int prox, prev;     prox = sparse[p][q][0];     prev = sparse[p][q][1];     if (prev) sparse[p][prev][0] = prox;     if (prox) sparse[p][prox][1] = prev;     rem[p][q][0] = prox;     prox = sparse[p][q][1];     prev = sparse[p][q][0];     if (prev) sparse[p][prev][1] = prox;     if (prox) sparse[p][prox][0] = prev;     rem[p][q][1] = prox;     prox = sparse[p][q][2];     prev = sparse[p][q][3];     if (prev) sparse[prev][q][2] = prox;     if (prox) sparse[prox][q][3] = prev;     rem[p][q][2] = prox;     prox = sparse[p][q][3];     prev = sparse[p][q][2];     if (prev) sparse[prev][q][3] = prox;     if (prox) sparse[prox][q][2] = prev;     rem[p][q][3] = prox;   }   void insert(int p, int q) {     int x;     x = rem[p][q][0];     if (x) sparse[p][x][1] = q;     x = rem[p][q][1];     if (x) sparse[p][x][0] = q;     x = rem[p][q][2];     if (x) sparse[x][q][3] = p;     x = rem[p][q][3];     if (x) sparse[x][q][2] = p;     for (int i = 0; i < 4; ++i) rem[p][q][i] = 0;   }   int solve(int p, int q) {     int tot = 0;     stack<pair<int, int> > s;     while (p and q) {       int prox, prev;       if (mat[p][q] ==  L ) {         prox = sparse[p][q][0];         if (p and q) remove(p, q);         if (p and q) s.push(make_pair(p, q));         q = prox;       } else if (mat[p][q] ==  R ) {         prox = sparse[p][q][1];         if (p and q) remove(p, q);         if (p and q) s.push(make_pair(p, q));         q = prox;       } else if (mat[p][q] ==  U ) {         prox = sparse[p][q][2];         if (p and q) remove(p, q);         if (p and q) s.push(make_pair(p, q));         p = prox;       } else {         prox = sparse[p][q][3];         if (p and q) remove(p, q);         if (p and q) s.push(make_pair(p, q));         p = prox;       }       tot++;     }     while (s.size()) {       pair<int, int> p = s.top();       s.pop();       insert(p.first, p.second);     }     return tot;   }   int main(int argc, char* argv[]) {     cin >> n >> m;     mat = new char*[n + 1];     for (int i = 0; i <= n; ++i) mat[i] = new char[m + 1];     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         cin >> mat[i][j];         if (mat[i][j] ==  . ) mat[i][j] = 0;       }     }     build();     int ans = 0, freq = 0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j <= m; ++j) {         int x = mat[i][j] ? solve(i, j) : 0;         if (x > ans) {           ans = x;           freq = 1;         } else if (x == ans)           freq++;       }     }     cout << ans <<     << freq << endl;     return 0;   }   