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;
int N, M;
char c[1010][1010];
long long lux[1010][1010], luy[1010][1010], lus[1010][1010];
long long rux[1010][1010], ruy[1010][1010], rus[1010][1010];
long long ldx[1010][1010], ldy[1010][1010], lds[1010][1010];
long long rdx[1010][1010], rdy[1010][1010], rds[1010][1010];
long long hh[1010], ll[1010];
long long ans, s;
int main() {
  scanf("%d%d\n", &N, &M);
  for (long long i = 1; i <= N; i++) {
    for (long long j = 1; j <= M; j++) scanf("%c", &c[i][j]);
    scanf("\n");
  }
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++)
      if (c[i][j] == 'X') {
        hh[i] = j;
        ll[j] = i;
      }
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++) {
      lux[i][j] = lux[i][j - 1] + lux[i - 1][j] - lux[i - 1][j - 1];
      luy[i][j] = luy[i][j - 1] + luy[i - 1][j] - luy[i - 1][j - 1];
      lus[i][j] = lus[i][j - 1] + lus[i - 1][j] - lus[i - 1][j - 1];
      if (c[i][j] == '.') lux[i][j] += i, luy[i][j] += j, lus[i][j]++;
    }
  for (long long i = 1; i <= N; i++)
    for (long long j = M; j; j--) {
      rux[i][j] = rux[i][j + 1] + rux[i - 1][j] - rux[i - 1][j + 1];
      ruy[i][j] = ruy[i][j + 1] + ruy[i - 1][j] - ruy[i - 1][j + 1];
      rus[i][j] = rus[i][j + 1] + rus[i - 1][j] - rus[i - 1][j + 1];
      if (c[i][j] == '.') rux[i][j] += i, ruy[i][j] += j, rus[i][j]++;
    }
  for (long long i = N; i; i--)
    for (long long j = 1; j <= M; j++) {
      ldx[i][j] = ldx[i][j - 1] + ldx[i + 1][j] - ldx[i + 1][j - 1];
      ldy[i][j] = ldy[i][j - 1] + ldy[i + 1][j] - ldy[i + 1][j - 1];
      lds[i][j] = lds[i][j - 1] + lds[i + 1][j] - lds[i + 1][j - 1];
      if (c[i][j] == '.') ldx[i][j] += i, ldy[i][j] += j, lds[i][j]++;
    }
  for (long long i = N; i; i--)
    for (long long j = M; j; j--) {
      rdx[i][j] = rdx[i][j + 1] + rdx[i + 1][j] - rdx[i + 1][j + 1];
      rdy[i][j] = rdy[i][j + 1] + rdy[i + 1][j] - rdy[i + 1][j + 1];
      rds[i][j] = rds[i][j + 1] + rds[i + 1][j] - rds[i + 1][j + 1];
      if (c[i][j] == '.') rdx[i][j] += i, rdy[i][j] += j, rds[i][j]++;
    }
  ans = 0;
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++)
      if (c[i][j] != 'X') {
        ans += abs(i * lus[i - 1][j - 1] - lux[i - 1][j - 1]) +
               abs(j * lus[i - 1][j - 1] - luy[i - 1][j - 1]);
        ans += abs(i * rus[i - 1][j + 1] - rux[i - 1][j + 1]) +
               abs(j * rus[i - 1][j + 1] - ruy[i - 1][j + 1]);
        ans += abs(i * lds[i + 1][j - 1] - ldx[i + 1][j - 1]) +
               abs(j * lds[i + 1][j - 1] - ldy[i + 1][j - 1]);
        ans += abs(i * rds[i + 1][j + 1] - rdx[i + 1][j + 1]) +
               abs(j * rds[i + 1][j + 1] - rdy[i + 1][j + 1]);
        if (hh[i]) {
          if (hh[i] > j) {
            ans += (j - 1) * j / 2;
            ans += (hh[i] - j - 1) * (hh[i] - j) / 2;
            ans += (M - hh[i]) * (M - j + 2 + hh[i] + 1 - j + 2) / 2;
          } else {
            ans += (M - j) * (M - j + 1) / 2;
            ans += (j - hh[i] - 1) * (j - hh[i]) / 2;
            ans += (hh[i] - 1) * (j - 1 + 2 + j - (hh[i] - 1) + 2) / 2;
          }
        } else {
          ans += (j - 1) * j / 2;
          ans += (M - j) * (M - j + 1) / 2;
        }
        if (ll[j]) {
          if (ll[j] > i) {
            ans += (i - 1) * i / 2;
            ans += (ll[j] - i - 1) * (ll[j] - i) / 2;
            ans += (N - ll[j]) * (N - i + 2 + ll[j] + 1 - i + 2) / 2;
          } else {
            ans += (N - i) * (N - i + 1) / 2;
            ans += (i - ll[j] - 1) * (i - ll[j]) / 2;
            ans += (ll[j] - 1) * (i - 1 + 2 + i - (ll[j] - 1) + 2) / 2;
          }
        } else {
          ans += (i - 1) * i / 2;
          ans += (N - i) * (N - i + 1) / 2;
        }
      }
  for (int i = 1; i < N; i++) {
    int j = i;
    while (hh[j] && hh[j + 1] && (hh[j + 1] > hh[j])) j++;
    for (int x = i; x < j; x++)
      for (int y = x + 1; y <= j; y++) {
        if (hh[x] < hh[y])
          ans += 4 * (hh[x] - 1) * (M - hh[y]);
        else
          ans += 4 * (hh[y] - 1) * (M - hh[x]);
      }
    i = j;
  }
  for (int i = 1; i < N; i++) {
    int j = i;
    while (hh[j] && hh[j + 1] && (hh[j + 1] < hh[j])) j++;
    for (int x = i; x < j; x++)
      for (int y = x + 1; y <= j; y++) {
        if (hh[x] < hh[y])
          ans += 4 * (hh[x] - 1) * (M - hh[y]);
        else
          ans += 4 * (hh[y] - 1) * (M - hh[x]);
      }
    i = j;
  }
  for (int i = 1; i < M; i++) {
    int j = i;
    while (ll[j] && ll[j + 1] && (ll[j + 1] > ll[j])) j++;
    for (int x = i; x < j; x++)
      for (int y = x + 1; y <= j; y++) {
        if (ll[x] < ll[y])
          ans += 4 * (ll[x] - 1) * (N - ll[y]);
        else
          ans += 4 * (ll[y] - 1) * (N - ll[x]);
      }
    i = j;
  }
  for (int i = 1; i < M; i++) {
    int j = i;
    while (ll[j] && ll[j + 1] && (ll[j + 1] < ll[j])) j++;
    for (int x = i; x < j; x++)
      for (int y = x + 1; y <= j; y++) {
        if (ll[x] < ll[y])
          ans += 4 * (ll[x] - 1) * (N - ll[y]);
        else
          ans += 4 * (ll[y] - 1) * (N - ll[x]);
      }
    i = j;
  }
  for (long long i = 1; i <= N; i++)
    for (long long j = 1; j <= M; j++)
      if (c[i][j] == '.')
        s += lus[i][j] + rus[i][j + 1] + lds[i + 1][j] + rds[i + 1][j + 1];
  printf("%0.8lf", double(ans) / double(s));
}