#include <bits/stdc++.h>
const int N = 4e3 + 3;
int n, m, q[N], lst[N];
char a[N][N];
long long f[N][N];
void solve() {
  memset(lst, 0, sizeof lst);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '1') lst[j] = i;
    int l = 1, r = 0;
    for (int j = 1; j <= m; j++) {
      if (lst[j]) {
        while (l < r &&
               (((long long)(q[r]) * (q[r]) +
                 (long long)(lst[q[r]] - i) * (lst[q[r]] - i)) -
                ((long long)(q[r - 1]) * (q[r - 1]) +
                 (long long)(lst[q[r - 1]] - i) * (lst[q[r - 1]] - i))) *
                       ((long long)(j) - (long long)(q[r])) >=
                   (((long long)(j) * (j) +
                     (long long)(lst[j] - i) * (lst[j] - i)) -
                    ((long long)(q[r]) * (q[r]) +
                     (long long)(lst[q[r]] - i) * (lst[q[r]] - i))) *
                       ((long long)(q[r]) - (long long)(q[r - 1])))
          r--;
        q[++r] = j;
      }
      while (l < r && (((long long)(q[l + 1]) * (q[l + 1]) +
                        (long long)(lst[q[l + 1]] - i) * (lst[q[l + 1]] - i)) -
                       ((long long)(q[l]) * (q[l]) +
                        (long long)(lst[q[l]] - i) * (lst[q[l]] - i))) <=
                          ((long long)(q[l + 1]) - (long long)(q[l])) *
                              ((long long)(j)*2))
        l++;
      if (l <= r)
        f[i][j] = std::min(f[i][j],
                           (long long)j * j +
                               ((long long)(q[l]) * (q[l]) +
                                (long long)(lst[q[l]] - i) * (lst[q[l]] - i)) -
                               ((long long)(j)*2) * (long long)(q[l]));
    }
  }
}
int main() {
  scanf("%d%d", &n, &m), n++, m++;
  for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  memset(f, 0x3f, sizeof f);
  solve();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m / 2; j++)
      std::swap(f[i][j], f[i][m - j + 1]), std::swap(a[i][j], a[i][m - j + 1]);
  solve();
  for (int i = 1; i <= n / 2; i++)
    for (int j = 1; j <= m; j++)
      std::swap(f[i][j], f[n - i + 1][j]), std::swap(a[i][j], a[n - i + 1][j]);
  solve();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m / 2; j++)
      std::swap(f[i][j], f[i][m - j + 1]), std::swap(a[i][j], a[i][m - j + 1]);
  solve();
  long long sum = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) sum += f[i][j];
  printf("%lld\n", sum);
  return 0;
}

### Prompt

Your task is to create a CPP solution to the following problem:

Mr. Chanek's city can be represented as a plane. He wants to build a housing complex in the city.

There are some telephone poles on the plane, which is represented by a grid a of size (n + 1) × (m + 1). There is a telephone pole at (x, y) if a_{x, y} = 1.

For each point (x, y), define S(x, y) as the square of the Euclidean distance between the nearest pole and (x, y). Formally, the square of the Euclidean distance between two points (x_1, y_1) and (x_2, y_2) is (x_2 - x_1)^2 + (y_2 - y_1)^2.

To optimize the building plan, the project supervisor asks you the sum of all S(x, y) for each 0 ≤ x ≤ n and 0 ≤ y ≤ m. Help him by finding the value of ∑_{x=0}^{n} {∑_{y=0}^{m} {S(x, y)}}.

Input

The first line contains two integers n and m (0 ≤ n, m < 2000) — the size of the grid.

Then (n + 1) lines follow, each containing (m + 1) integers a_{i, j} (0 ≤ a_{i, j} ≤ 1) — the grid denoting the positions of telephone poles in the plane. There is at least one telephone pole in the given grid.

Output

Output an integer denoting the value of ∑_{x=0}^{n} {∑_{y=0}^{m} {S(x, y)}}.

Examples

Input


2 2
101
000
000


Output


18


Input


5 4
10010
00000
01000
00001
00100
00010


Output


36

Note

<image>

In the first example, the nearest telephone pole for the points (0,0), (1,0), (2,0), (0,1), (1,1), and (2,1) is at (0, 0). While the nearest telephone pole for the points (0, 2), (1,2), and (2,2) is at (0, 2). Thus, ∑_{x=0}^{n} {∑_{y=0}^{m} {S(x, y)}} = (0 + 1 + 4) + (1 + 2 + 5) + (0 + 1 + 4) = 18.

### Response

```cpp
#include <bits/stdc++.h>
const int N = 4e3 + 3;
int n, m, q[N], lst[N];
char a[N][N];
long long f[N][N];
void solve() {
  memset(lst, 0, sizeof lst);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++)
      if (a[i][j] == '1') lst[j] = i;
    int l = 1, r = 0;
    for (int j = 1; j <= m; j++) {
      if (lst[j]) {
        while (l < r &&
               (((long long)(q[r]) * (q[r]) +
                 (long long)(lst[q[r]] - i) * (lst[q[r]] - i)) -
                ((long long)(q[r - 1]) * (q[r - 1]) +
                 (long long)(lst[q[r - 1]] - i) * (lst[q[r - 1]] - i))) *
                       ((long long)(j) - (long long)(q[r])) >=
                   (((long long)(j) * (j) +
                     (long long)(lst[j] - i) * (lst[j] - i)) -
                    ((long long)(q[r]) * (q[r]) +
                     (long long)(lst[q[r]] - i) * (lst[q[r]] - i))) *
                       ((long long)(q[r]) - (long long)(q[r - 1])))
          r--;
        q[++r] = j;
      }
      while (l < r && (((long long)(q[l + 1]) * (q[l + 1]) +
                        (long long)(lst[q[l + 1]] - i) * (lst[q[l + 1]] - i)) -
                       ((long long)(q[l]) * (q[l]) +
                        (long long)(lst[q[l]] - i) * (lst[q[l]] - i))) <=
                          ((long long)(q[l + 1]) - (long long)(q[l])) *
                              ((long long)(j)*2))
        l++;
      if (l <= r)
        f[i][j] = std::min(f[i][j],
                           (long long)j * j +
                               ((long long)(q[l]) * (q[l]) +
                                (long long)(lst[q[l]] - i) * (lst[q[l]] - i)) -
                               ((long long)(j)*2) * (long long)(q[l]));
    }
  }
}
int main() {
  scanf("%d%d", &n, &m), n++, m++;
  for (int i = 1; i <= n; i++) scanf("%s", a[i] + 1);
  memset(f, 0x3f, sizeof f);
  solve();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m / 2; j++)
      std::swap(f[i][j], f[i][m - j + 1]), std::swap(a[i][j], a[i][m - j + 1]);
  solve();
  for (int i = 1; i <= n / 2; i++)
    for (int j = 1; j <= m; j++)
      std::swap(f[i][j], f[n - i + 1][j]), std::swap(a[i][j], a[n - i + 1][j]);
  solve();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m / 2; j++)
      std::swap(f[i][j], f[i][m - j + 1]), std::swap(a[i][j], a[i][m - j + 1]);
  solve();
  long long sum = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) sum += f[i][j];
  printf("%lld\n", sum);
  return 0;
}

```