Problem: Stewie the Rabbit explores a new parallel universe. This two dimensional universe has the shape of a rectangular grid, containing n lines and m columns. The universe is very small: one cell of the grid can only contain one particle. Each particle in this universe is either static or dynamic. Each static particle always remains in one and the same position. Due to unintelligible gravitation laws no two static particles in the parallel universe can be present in one column or row, and they also can't be present in the diagonally adjacent cells. A dynamic particle appears in a random empty cell, randomly chooses the destination cell (destination cell may coincide with the start cell, see the samples) and moves there along the shortest path through the cells, unoccupied by the static particles. All empty cells have the same probability of being selected as the beginning or end of the path. Having reached the destination cell, the particle disappears. Only one dynamic particle can exist at one moment of time. This particle can move from a cell to a cell if they have an adjacent side, and this transition takes exactly one galactic second. Stewie got interested in what is the average lifespan of one particle in the given universe.

Input

The first line contains two space-separated integers: n, m (2 ≤ n, m ≤ 1000) which represent the sizes of the universe. The next n lines containing m symbols each describe the universe without dynamic particles — the j-th symbol of the i-th line equals to 'X' if the cell is occupied by a static particle, and to '.' if it is empty. It is guaranteed that the described universe satisfies the properties described above, that is no two static particles can be in one column or in one row, besides, they can't be positioned in the diagonally adjacent cells.

Output

You have to print on a single line a single number which is the average life span of a particle with an accuracy of at least 6 decimal places.

The answer will be accepted if it is within 10 - 6 of absolute or relative error from the correct answer.

Examples

Input

2 2
..
.X


Output

0.888888888889


Input

3 3
...
.X.
...


Output

2.000000000000

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1100;
int n, m;
char s[maxN][maxN];
long long sumx[maxN][maxN];
long long sumy[maxN][maxN];
int cnt[maxN][maxN];
int get_cnt(int x1, int y1, int x2, int y2) {
  if (x1 > x2) return 0;
  if (y1 > y2) return 0;
  int ret = cnt[x2][y2];
  if (x1 > 0) ret -= cnt[x1 - 1][y2];
  if (y1 > 0) ret -= cnt[x2][y1 - 1];
  if (x1 > 0 && y1 > 0) ret += cnt[x1 - 1][y1 - 1];
  return ret;
}
long long get_sum(long long sum[maxN][maxN], int x1, int y1, int x2, int y2) {
  if (x1 > x2) return 0;
  if (y1 > y2) return 0;
  long long ret = sum[x2][y2];
  if (x1 > 0) ret -= sum[x1 - 1][y2];
  if (y1 > 0) ret -= sum[x2][y1 - 1];
  if (x1 > 0 && y1 > 0) ret += sum[x1 - 1][y1 - 1];
  return ret;
}
int r[maxN], c[maxN];
long long arithm(long long a, long long b) {
  if (a > b) return 0;
  return (a + b) * (b - a + 1) / 2;
}
int g[maxN][maxN];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
bool is_in(int x, int y) {
  return x >= 0 && x < n && y >= 0 && y < m && s[x][y] == '.';
}
void solve_brut() {
  for (int i = 0; i < maxN; ++i) {
    for (int j = 0; j < maxN; ++j) {
      g[i][j] = 1000000000;
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == '.') {
        int val = i * m + j;
        g[val][val] = 0;
        for (int k = 0; k < 4; ++k) {
          int nx = i + dx[k], ny = j + dy[k];
          if (is_in(nx, ny)) {
            g[val][nx * m + ny] = g[nx * m + ny][val] = 1;
          }
        }
      }
    }
  }
  int tot = n * m;
  for (int k = 0; k < tot; ++k) {
    for (int i = 0; i < tot; ++i) {
      for (int j = 0; j < tot; ++j) {
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
  double sum = 0;
  double cnt = 0;
  for (int i = 0; i < tot; ++i) {
    for (int j = 0; j < tot; ++j) {
      int x1 = i / m, y1 = i % m;
      int x2 = j / m, y2 = j % m;
      if (s[x1][y1] == '.' && s[x2][y2] == '.') {
        sum += g[i][j];
        ++cnt;
      }
    }
  }
  printf("%.10lf\n", sum / cnt);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  cnt[0][0] = 1;
  if (s[0][0] == 'X') cnt[0][0] = 0;
  for (int i = 1; i < n; ++i) {
    cnt[i][0] = cnt[i - 1][0] + (int)(s[i][0] == '.');
    sumx[i][0] = sumx[i - 1][0];
    sumy[i][0] = sumy[i - 1][0];
    if (s[i][0] == '.') {
      sumx[i][0] += i;
    }
  }
  for (int i = 1; i < m; ++i) {
    cnt[0][i] = cnt[0][i - 1] + (int)(s[0][i] == '.');
    sumx[0][i] = sumx[0][i - 1];
    sumy[0][i] = sumy[0][i - 1];
    if (s[0][i] == '.') {
      sumy[0][i] += i;
    }
  }
  for (int i = 1; i < n; ++i) {
    for (int j = 1; j < m; ++j) {
      cnt[i][j] = cnt[i - 1][j] + cnt[i][j - 1] - cnt[i - 1][j - 1] +
                  (int)(s[i][j] == '.');
      sumx[i][j] = sumx[i - 1][j] + sumx[i][j - 1] - sumx[i - 1][j - 1];
      sumy[i][j] = sumy[i - 1][j] + sumy[i][j - 1] - sumy[i - 1][j - 1];
      if (s[i][j] == '.') {
        sumx[i][j] += i;
        sumy[i][j] += j;
      }
    }
  }
  long long total = 0;
  long long cnt = 0;
  memset(r, -1, sizeof(r));
  memset(c, -1, sizeof(c));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'X') {
        r[i] = j;
        c[j] = i;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'X') continue;
      long long cnt1 = get_cnt(0, j + 1, i - 1, m - 1);
      long long sum1x = get_sum(sumx, 0, j + 1, i - 1, m - 1);
      long long sum1y = get_sum(sumy, 0, j + 1, i - 1, m - 1);
      total += cnt1 * i - sum1x;
      total += sum1y - cnt1 * j;
      cnt += cnt1;
      long long cnt2 = get_cnt(i + 1, j + 1, n - 1, m - 1);
      long long sum2x = get_sum(sumx, i + 1, j + 1, n - 1, m - 1);
      long long sum2y = get_sum(sumy, i + 1, j + 1, n - 1, m - 1);
      total += sum2x - cnt2 * i;
      total += sum2y - cnt2 * j;
      cnt += cnt2;
      if (r[i] > j) {
        long long ctotal = 0;
        int curi = i + 1;
        while (curi < n && r[curi] > r[curi - 1]) {
          ctotal += m - 1 - r[curi];
          ++curi;
        }
        curi = i - 1;
        while (curi >= 0 && r[curi] > r[curi + 1]) {
          ctotal += m - 1 - r[curi];
          --curi;
        }
        total += ctotal * 2;
      }
      if (c[j] > i) {
        long long ctotal = 0;
        int curj = j + 1;
        while (curj < m && c[curj] > c[curj - 1]) {
          ctotal += n - 1 - c[curj];
          ++curj;
        }
        curj = j - 1;
        while (curj >= 0 && c[curj] > c[curj + 1]) {
          ctotal += n - 1 - c[curj];
          --curj;
        }
        total += ctotal * 2;
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'X') continue;
      {
        if (c[j] > i) {
          cnt += n - 2 - i;
          total += arithm(1, c[j] - 1 - i);
          total += arithm(c[j] + 1 - i + 2, n - 1 - i + 2);
        } else {
          cnt += n - 1 - i;
          total += arithm(1, n - 1 - i);
        }
      }
      {
        if (r[i] > j) {
          cnt += m - 2 - j;
          total += arithm(1, r[i] - 1 - j);
          total += arithm(r[i] + 1 - j + 2, m - 1 - j + 2);
        } else {
          cnt += m - 1 - j;
          total += arithm(1, m - 1 - j);
        }
      }
    }
  }
  total *= 2, cnt *= 2;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'X') continue;
      ++cnt;
    }
  }
  printf("%.10lf\n", (double)total / (double)cnt);
  return 0;
}