#include <bits/stdc++.h>   using namespace std;   const long long MX = 200005;   long long n, m;   vector<long long> adj[2][MX];   long long st[MX], fin[MX];   long long deg[2][MX];   long long ans, tim;   long long cur = 1;   pair<long long, long long> seg[4 * MX];   long long lazy[4 * MX];   pair<long long, long long> merge(pair<long long, long long> x,                                    pair<long long, long long> y) {     if (x.first == y.first) return {x.first, x.second + y.second};     return min(x, y);   }   void build(long long node, long long l, long long r) {     if (l == r) {       seg[node] = {0, 1};       return;     }     long long mid = (l + r) / 2;     build(2 * node, l, mid);     build(2 * node + 1, mid + 1, r);     seg[node] = merge(seg[2 * node], seg[2 * node + 1]);   }   void propagate(long long node, long long l, long long r) {     seg[node].first += lazy[node];     if (l != r) {       lazy[2 * node] += lazy[node];       lazy[2 * node + 1] += lazy[node];     }     lazy[node] = 0;   }   void update(long long node, long long l, long long r, long long x, long long y,               long long val) {     propagate(node, l, r);     if (l > y or r < x) return;     if (l >= x and r <= y) {       lazy[node] += val;       propagate(node, l, r);       return;     }     long long mid = (l + r) / 2;     update(2 * node, l, mid, x, y, val);     update(2 * node + 1, mid + 1, r, x, y, val);     seg[node] = merge(seg[2 * node], seg[2 * node + 1]);   }   void dfs(long long u) {     st[u] = tim++;     for (auto v : adj[1][u]) {       dfs(v);     }     fin[u] = tim;   }   void solve(long long u) {     update(1, 0, cur - 1, st[u], fin[u] - 1, 1);     if (!seg[1].first) ans -= seg[1].second;     for (auto v : adj[0][u]) {       solve(v);     }     update(1, 0, cur - 1, st[u], fin[u] - 1, -1);   }   signed main() {     cin >> n >> m;     vector<vector<long long> > index(n, vector<long long>(m, -1));     vector<vector<char> > a(n, vector<char>(m));     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         cin >> a[i][j];         if (a[i][j] ==  L ) {           index[i][j] = cur;           index[i][j + 1] = cur;           cur++;         } else if (a[i][j] ==  U ) {           index[i][j] = cur;           index[i + 1][j] = cur;           cur++;         }       }     }     cur--;     for (long long i = 0; i < n; i++) {       for (long long j = 0; j < m; j++) {         if (a[i][j] ==  L  and j + 2 < m) {           adj[(i + j) % 2][index[i][j + 2]].push_back(index[i][j]);           deg[(i + j) % 2][index[i][j]]++;         }         if (a[i][j] ==  R  and j - 2 >= 0) {           adj[(i + j) % 2][index[i][j - 2]].push_back(index[i][j]);           deg[(i + j) % 2][index[i][j]]++;         }         if (a[i][j] ==  U  and i + 2 < n) {           adj[(i + j) % 2][index[i + 2][j]].push_back(index[i][j]);           deg[(i + j) % 2][index[i][j]]++;         }         if (a[i][j] ==  D  and i - 2 >= 0) {           adj[(i + j) % 2][index[i - 2][j]].push_back(index[i][j]);           deg[(i + j) % 2][index[i][j]]++;         }       }     }     ans = (n * m * n * m) / 4;     tim = 0;     for (long long i = 1; i < cur + 1; i++) {       if (!deg[1][i]) dfs(i);     }     build(1, 0, cur - 1);     for (long long i = 1; i < cur + 1; i++) {       if (!deg[0][i]) solve(i);     }     cout << ans <<   n ;   }   