#include <bits/stdc++.h>
const int MN = 2e5 + 10;
using ll = long long;
int N, M, pre[MN], post[MN], p[MN], ctr, id[MN], map[MN / 2];
bool col[MN];
char s[MN];
std::vector<int> a[MN];
ll f;
char get(int i, int j) { return s[j + i * M]; }
int loc(int i, int j) { return j + i * M; }
int c[1 << 18], v[1 << 18], z[1 << 18];
void build(int n, int l, int r) {
  c[n] = r - l;
  if (r - l > 1) {
    int m = l + (r - l) / 2;
    build(n << 1, l, m);
    build(n << 1 | 1, m, r);
  }
}
void down(int n, int l, int r) {
  if (!z[n]) return;
  if (r - l > 1) {
    v[n << 1] += z[n], z[n << 1] += z[n];
    v[n << 1 | 1] += z[n], z[n << 1 | 1] += z[n];
  }
  z[n] = 0;
}
void upd(int n, int l, int r, int ql, int qr, int d) {
  if (ql <= l && r <= qr)
    z[n] += d, v[n] += d;
  else {
    int m = l + (r - l) / 2;
    down(n, l, r);
    if (ql < m) upd(n << 1, l, m, ql, qr, d);
    if (m < qr) upd(n << 1 | 1, m, r, ql, qr, d);
    if (v[n << 1] == v[n << 1 | 1])
      v[n] = v[n << 1], c[n] = c[n << 1] + c[n << 1 | 1];
    else {
      int x = n << 1 | (v[n << 1] > v[n << 1 | 1]);
      v[n] = v[x], c[n] = c[x];
    }
  }
}
void dfs(int n) {
  pre[n] = ctr++;
  map[id[n]] = n;
  for (auto x : a[n])
    if (x != p[n]) dfs(x);
  post[n] = ctr;
}
void dfs2(int n) {
  int k = map[id[n]];
  assert(k != n && id[k] == id[n]);
  if (id[k]) {
    upd(1, 1, ctr, pre[k], post[k], 1);
    if (!v[1]) f += c[1];
  }
  for (auto x : a[n])
    if (x != p[n]) dfs2(x);
  if (id[k]) upd(1, 1, ctr, pre[k], post[k], -1);
}
int main(void) {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; ++i) scanf(" %s", s + i * M);
  memset(p, -1, sizeof p);
  for (int i = 0, k = 0, x, y = 0; i < N; ++i)
    for (int j = 0; j < M; ++j, ++k) {
      x = -1;
      if (s[k] == 'U') id[k] = id[k + M] = ++y;
      if (s[k] == 'L') id[k] = id[k + 1] = ++y;
      if (s[k] == 'U' && i + 2 < N) x = loc(i + 2, j);
      if (s[k] == 'D' && i >= 2) x = loc(i - 2, j);
      if (s[k] == 'L' && j + 2 < M) x = loc(i, j + 2);
      if (s[k] == 'R' && j >= 2) x = loc(i, j - 2);
      if (~x) {
        a[x].push_back(k);
        p[k] = x;
      }
      col[k] = i + j & 1;
    }
  for (int i = 0, x; i < N * M; ++i)
    if (!~p[i]) {
      x = N * M | col[i];
      a[x].push_back(i);
      p[i] = x;
    }
  dfs(N * M);
  assert(ctr == N * M / 2 + 1);
  build(1, 1, ctr);
  f = 0;
  dfs2(N * M + 1);
  printf("%lld\n", (ll)N * M * N * M / 4 - f);
  return 0;
}

### Prompt

Please create a solution in Cpp to the following problem:

Bill likes to play with dominoes. He took an n × m board divided into equal square cells, and covered it with dominoes. Each domino covers two adjacent cells of the board either horizontally or vertically, and each cell is covered exactly once with a half of one domino (that is, there are no uncovered cells, and no two dominoes cover the same cell twice).

After that Bill decided to play with the covered board and share some photos of it on social media. First, he removes exactly one domino from the board, freeing two of the cells. Next, he moves dominoes around. A domino can only be moved along the line parallel to its longer side. A move in the chosen direction is possible if the next cell in this direction is currently free. Bill doesn't want to lose track of what the original tiling looks like, so he makes sure that at any point each domino shares at least one cell with its original position.

After removing a domino and making several (possibly, zero) moves Bill takes a photo of the board and posts it. However, with the amount of filters Bill is using, domino borders are not visible, so only the two free cells of the board can be identified. When the photo is posted, Bill reverts the board to its original state and starts the process again.

Bill wants to post as many photos as possible, but he will not post any photo twice. How many distinct photos can he take? Recall that photos are different if the pairs of free cells in the photos are different.

Input

The first line contains two positive integers n and m (nm ≤ 2 ⋅ 10^5) — height and width of the board respectively.

The next n lines describe the tiling of the board, row by row from top to bottom. Each of these lines contains m characters, describing the cells in the corresponding row left to right. Each character is one of U, D, L, or R, meaning that the cell is covered with a top, bottom, left, or right half of a domino respectively.

It is guaranteed that the described tiling is valid, that is, each half-domino has a counterpart in the relevant location. In particular, since tiling is possible, the number of cells in the board is even.

Output

Print a single integer — the number of distinct photos Bill can take.

Examples

Input


2 4
UUUU
DDDD


Output


4


Input


2 3
ULR
DLR


Output


6


Input


6 6
ULRUUU
DUUDDD
UDDLRU
DLRLRD
ULRULR
DLRDLR


Output


133

Note

In the first sample case, no moves are possible after removing any domino, thus there are four distinct photos.

In the second sample case, four photos are possible after removing the leftmost domino by independently moving/not moving the remaining two dominoes. Two more different photos are obtained by removing one of the dominoes on the right.

### Response

```cpp
#include <bits/stdc++.h>
const int MN = 2e5 + 10;
using ll = long long;
int N, M, pre[MN], post[MN], p[MN], ctr, id[MN], map[MN / 2];
bool col[MN];
char s[MN];
std::vector<int> a[MN];
ll f;
char get(int i, int j) { return s[j + i * M]; }
int loc(int i, int j) { return j + i * M; }
int c[1 << 18], v[1 << 18], z[1 << 18];
void build(int n, int l, int r) {
  c[n] = r - l;
  if (r - l > 1) {
    int m = l + (r - l) / 2;
    build(n << 1, l, m);
    build(n << 1 | 1, m, r);
  }
}
void down(int n, int l, int r) {
  if (!z[n]) return;
  if (r - l > 1) {
    v[n << 1] += z[n], z[n << 1] += z[n];
    v[n << 1 | 1] += z[n], z[n << 1 | 1] += z[n];
  }
  z[n] = 0;
}
void upd(int n, int l, int r, int ql, int qr, int d) {
  if (ql <= l && r <= qr)
    z[n] += d, v[n] += d;
  else {
    int m = l + (r - l) / 2;
    down(n, l, r);
    if (ql < m) upd(n << 1, l, m, ql, qr, d);
    if (m < qr) upd(n << 1 | 1, m, r, ql, qr, d);
    if (v[n << 1] == v[n << 1 | 1])
      v[n] = v[n << 1], c[n] = c[n << 1] + c[n << 1 | 1];
    else {
      int x = n << 1 | (v[n << 1] > v[n << 1 | 1]);
      v[n] = v[x], c[n] = c[x];
    }
  }
}
void dfs(int n) {
  pre[n] = ctr++;
  map[id[n]] = n;
  for (auto x : a[n])
    if (x != p[n]) dfs(x);
  post[n] = ctr;
}
void dfs2(int n) {
  int k = map[id[n]];
  assert(k != n && id[k] == id[n]);
  if (id[k]) {
    upd(1, 1, ctr, pre[k], post[k], 1);
    if (!v[1]) f += c[1];
  }
  for (auto x : a[n])
    if (x != p[n]) dfs2(x);
  if (id[k]) upd(1, 1, ctr, pre[k], post[k], -1);
}
int main(void) {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; ++i) scanf(" %s", s + i * M);
  memset(p, -1, sizeof p);
  for (int i = 0, k = 0, x, y = 0; i < N; ++i)
    for (int j = 0; j < M; ++j, ++k) {
      x = -1;
      if (s[k] == 'U') id[k] = id[k + M] = ++y;
      if (s[k] == 'L') id[k] = id[k + 1] = ++y;
      if (s[k] == 'U' && i + 2 < N) x = loc(i + 2, j);
      if (s[k] == 'D' && i >= 2) x = loc(i - 2, j);
      if (s[k] == 'L' && j + 2 < M) x = loc(i, j + 2);
      if (s[k] == 'R' && j >= 2) x = loc(i, j - 2);
      if (~x) {
        a[x].push_back(k);
        p[k] = x;
      }
      col[k] = i + j & 1;
    }
  for (int i = 0, x; i < N * M; ++i)
    if (!~p[i]) {
      x = N * M | col[i];
      a[x].push_back(i);
      p[i] = x;
    }
  dfs(N * M);
  assert(ctr == N * M / 2 + 1);
  build(1, 1, ctr);
  f = 0;
  dfs2(N * M + 1);
  printf("%lld\n", (ll)N * M * N * M / 4 - f);
  return 0;
}

```