#include <bits/stdc++.h>
using namespace std;
const int max_n = 510, inf = 1e9 + 100;
int m[max_n][max_n];
int h, w, r;
int cw[max_n];
int ch;
int cs[max_n][max_n];
int ps[max_n][max_n];
int sqr(int a) { return a * a; }
void calc_ps() {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ps[i][j] += m[i][j];
      if (j) {
        ps[i][j] += ps[i][j - 1];
      }
    }
  }
}
int get_ps(int i, int from, int to) {
  int res = ps[i][to];
  if (from) {
    res -= ps[i][from - 1];
  }
  return res;
}
void calc_cw() {
  char f[max_n][max_n];
  int ci = r + 2, cj = r;
  for (int i = 0; i < r * 2 + 6; ++i) {
    for (int j = 0; j < ch; ++j) {
      if (sqr(i - ci) + sqr(j - cj) <= sqr(r)) {
        f[i][j] = 'x';
      } else {
        f[i][j] = '.';
      }
    }
  }
  for (int j = 0; j < ch; ++j) {
    int len = 0;
    int i = ci - 1;
    while (f[i][j] == 'x') {
      ++len;
      --i;
    }
    cw[j] = len;
  }
}
bool check_cent(int ci, int cj) {
  return (ci - r) >= 0 && (ci + r) < h && (cj - r) >= 0 && (cj + r) < w;
}
int calc_sum(int ci, int cj) {
  int res = 0;
  for (int i = ci - r; i <= ci + r; ++i) {
    int curw = cw[i - (ci - r)];
    res += get_ps(i, cj - curw, cj + curw);
  }
  return res;
}
void calc_cs() {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (check_cent(i, j)) {
        cs[i][j] = calc_sum(i, j);
      } else {
        cs[i][j] = -inf;
      }
    }
  }
}
int min_dist[max_n];
int calc_md(int d) {
  int w1[max_n];
  int w2[max_n];
  for (int i = 0; i < max_n; ++i) {
    w1[i] = -inf;
  }
  for (int i = 0; i <= d; ++i) {
    if (r + i >= ch) break;
    w1[i] = cw[r + i];
  }
  int ans = 0;
  for (ans = 0;; ++ans) {
    for (int i = 0; i < max_n; ++i) {
      w2[i] = -inf;
    }
    for (int i = 0; i <= d; ++i) {
      if (r + i >= ch) break;
      w2[d - i] = ans - cw[r + i];
    }
    bool ok = true;
    for (int i = 0; i <= d; ++i) {
      if (w1[i] != -inf && w2[i] != -inf && w1[i] >= w2[i]) {
        ok = 0;
      }
    }
    if (ok) {
      return ans;
    }
  }
}
int sq_pm[max_n][max_n];
int sq_sm[max_n][max_n];
int sq_pc[max_n][max_n];
int sq_sc[max_n][max_n];
void calc_sq_p() {
  for (int i = 0; i < h; ++i) {
    int c = 1;
    for (int j = 0; j < w; ++j) {
      if (j) {
        sq_pm[i][j] = sq_pm[i][j - 1];
        if (cs[i][j] > sq_pm[i][j]) {
          c = 1;
          sq_pm[i][j] = cs[i][j];
        } else if (cs[i][j] == sq_pm[i][j]) {
          ++c;
        }
      } else {
        sq_pm[i][j] = cs[i][j];
      }
      sq_pc[i][j] = c;
    }
  }
  for (int i = 0; i < h; ++i) {
    int c = 1;
    for (int j = w - 1; j >= 0; --j) {
      if (j < w - 1) {
        sq_sm[i][j] = sq_sm[i][j + 1];
        if (cs[i][j] > sq_sm[i][j]) {
          c = 1;
          sq_sm[i][j] = cs[i][j];
        } else if (cs[i][j] == sq_sm[i][j]) {
          ++c;
        }
      } else {
        sq_sm[i][j] = cs[i][j];
      }
      sq_sc[i][j] = c;
    }
  }
}
int main() {
  cin >> h >> w >> r;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> m[i][j];
    }
  }
  ch = r * 2 + 1;
  calc_cw();
  calc_ps();
  calc_cs();
  for (int i = 0; i < h; ++i) {
    min_dist[i] = calc_md(i);
  }
  calc_sq_p();
  int ans = -1;
  long long c = 0;
  for (int si = 0; si < h; ++si) {
    for (int fi = si; fi < h; ++fi) {
      int curh = fi - si;
      int md = min_dist[curh];
      for (int j = 0; j < w; ++j) {
        if (!check_cent(si, j)) continue;
        if (fi > si && j - md >= 0) {
          int alt_ans = cs[si][j] + sq_pm[fi][j - md];
          if (alt_ans > ans) {
            ans = alt_ans;
            c = sq_pc[fi][j - md];
          } else if (alt_ans == ans) {
            c += sq_pc[fi][j - md];
          }
        }
        if (j + md < w) {
          int alt_ans = cs[si][j] + sq_sm[fi][j + md];
          if (alt_ans > ans) {
            ans = alt_ans;
            c = sq_sc[fi][j + md];
          } else if (alt_ans == ans) {
            c += sq_sc[fi][j + md];
          }
        }
        if (md == 0 && cs[si][j] + cs[fi][j] == ans) {
          --c;
        }
      }
    }
  }
  if (ans == -1) {
    cout << 0 << ' ' << 0 << endl;
    return 0;
  }
  cout << ans << ' ' << c << endl;
  return 0;
}

### Prompt

Construct a cpp code solution to the problem outlined:

Let's assume that we are given an n × m table filled by integers. We'll mark a cell in the i-th row and j-th column as (i, j). Thus, (1, 1) is the upper left cell of the table and (n, m) is the lower right cell. We'll assume that a circle of radius r with the center in cell (i0, j0) is a set of such cells (i, j) that <image>. We'll consider only the circles that do not go beyond the limits of the table, that is, for which r + 1 ≤ i0 ≤ n - r and r + 1 ≤ j0 ≤ m - r. 

<image> A circle of radius 3 with the center at (4, 5). 

Find two such non-intersecting circles of the given radius r that the sum of numbers in the cells that belong to these circles is maximum. Two circles intersect if there is a cell that belongs to both circles. As there can be more than one way to choose a pair of circles with the maximum sum, we will also be interested in the number of such pairs. Calculate the number of unordered pairs of circles, for instance, a pair of circles of radius 2 with centers at (3, 4) and (7, 7) is the same pair as the pair of circles of radius 2 with centers at (7, 7) and (3, 4). 

Input

The first line contains three integers n, m and r (2 ≤ n, m ≤ 500, r ≥ 0). Each of the following n lines contains m integers from 1 to 1000 each — the elements of the table. The rows of the table are listed from top to bottom at the elements in the rows are listed from left to right. It is guaranteed that there is at least one circle of radius r, not going beyond the table limits. 

Output

Print two integers — the maximum sum of numbers in the cells that are located into two non-intersecting circles and the number of pairs of non-intersecting circles with the maximum sum. If there isn't a single pair of non-intersecting circles, print 0 0.

Examples

Input

2 2 0
1 2
2 4


Output

6 2


Input

5 6 1
4 2 1 3 2 6
2 3 2 4 7 2
5 2 2 1 1 3
1 4 3 3 6 4
5 1 4 2 3 2


Output

34 3


Input

3 3 1
1 2 3
4 5 6
7 8 9


Output

0 0

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int max_n = 510, inf = 1e9 + 100;
int m[max_n][max_n];
int h, w, r;
int cw[max_n];
int ch;
int cs[max_n][max_n];
int ps[max_n][max_n];
int sqr(int a) { return a * a; }
void calc_ps() {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ps[i][j] += m[i][j];
      if (j) {
        ps[i][j] += ps[i][j - 1];
      }
    }
  }
}
int get_ps(int i, int from, int to) {
  int res = ps[i][to];
  if (from) {
    res -= ps[i][from - 1];
  }
  return res;
}
void calc_cw() {
  char f[max_n][max_n];
  int ci = r + 2, cj = r;
  for (int i = 0; i < r * 2 + 6; ++i) {
    for (int j = 0; j < ch; ++j) {
      if (sqr(i - ci) + sqr(j - cj) <= sqr(r)) {
        f[i][j] = 'x';
      } else {
        f[i][j] = '.';
      }
    }
  }
  for (int j = 0; j < ch; ++j) {
    int len = 0;
    int i = ci - 1;
    while (f[i][j] == 'x') {
      ++len;
      --i;
    }
    cw[j] = len;
  }
}
bool check_cent(int ci, int cj) {
  return (ci - r) >= 0 && (ci + r) < h && (cj - r) >= 0 && (cj + r) < w;
}
int calc_sum(int ci, int cj) {
  int res = 0;
  for (int i = ci - r; i <= ci + r; ++i) {
    int curw = cw[i - (ci - r)];
    res += get_ps(i, cj - curw, cj + curw);
  }
  return res;
}
void calc_cs() {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (check_cent(i, j)) {
        cs[i][j] = calc_sum(i, j);
      } else {
        cs[i][j] = -inf;
      }
    }
  }
}
int min_dist[max_n];
int calc_md(int d) {
  int w1[max_n];
  int w2[max_n];
  for (int i = 0; i < max_n; ++i) {
    w1[i] = -inf;
  }
  for (int i = 0; i <= d; ++i) {
    if (r + i >= ch) break;
    w1[i] = cw[r + i];
  }
  int ans = 0;
  for (ans = 0;; ++ans) {
    for (int i = 0; i < max_n; ++i) {
      w2[i] = -inf;
    }
    for (int i = 0; i <= d; ++i) {
      if (r + i >= ch) break;
      w2[d - i] = ans - cw[r + i];
    }
    bool ok = true;
    for (int i = 0; i <= d; ++i) {
      if (w1[i] != -inf && w2[i] != -inf && w1[i] >= w2[i]) {
        ok = 0;
      }
    }
    if (ok) {
      return ans;
    }
  }
}
int sq_pm[max_n][max_n];
int sq_sm[max_n][max_n];
int sq_pc[max_n][max_n];
int sq_sc[max_n][max_n];
void calc_sq_p() {
  for (int i = 0; i < h; ++i) {
    int c = 1;
    for (int j = 0; j < w; ++j) {
      if (j) {
        sq_pm[i][j] = sq_pm[i][j - 1];
        if (cs[i][j] > sq_pm[i][j]) {
          c = 1;
          sq_pm[i][j] = cs[i][j];
        } else if (cs[i][j] == sq_pm[i][j]) {
          ++c;
        }
      } else {
        sq_pm[i][j] = cs[i][j];
      }
      sq_pc[i][j] = c;
    }
  }
  for (int i = 0; i < h; ++i) {
    int c = 1;
    for (int j = w - 1; j >= 0; --j) {
      if (j < w - 1) {
        sq_sm[i][j] = sq_sm[i][j + 1];
        if (cs[i][j] > sq_sm[i][j]) {
          c = 1;
          sq_sm[i][j] = cs[i][j];
        } else if (cs[i][j] == sq_sm[i][j]) {
          ++c;
        }
      } else {
        sq_sm[i][j] = cs[i][j];
      }
      sq_sc[i][j] = c;
    }
  }
}
int main() {
  cin >> h >> w >> r;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> m[i][j];
    }
  }
  ch = r * 2 + 1;
  calc_cw();
  calc_ps();
  calc_cs();
  for (int i = 0; i < h; ++i) {
    min_dist[i] = calc_md(i);
  }
  calc_sq_p();
  int ans = -1;
  long long c = 0;
  for (int si = 0; si < h; ++si) {
    for (int fi = si; fi < h; ++fi) {
      int curh = fi - si;
      int md = min_dist[curh];
      for (int j = 0; j < w; ++j) {
        if (!check_cent(si, j)) continue;
        if (fi > si && j - md >= 0) {
          int alt_ans = cs[si][j] + sq_pm[fi][j - md];
          if (alt_ans > ans) {
            ans = alt_ans;
            c = sq_pc[fi][j - md];
          } else if (alt_ans == ans) {
            c += sq_pc[fi][j - md];
          }
        }
        if (j + md < w) {
          int alt_ans = cs[si][j] + sq_sm[fi][j + md];
          if (alt_ans > ans) {
            ans = alt_ans;
            c = sq_sc[fi][j + md];
          } else if (alt_ans == ans) {
            c += sq_sc[fi][j + md];
          }
        }
        if (md == 0 && cs[si][j] + cs[fi][j] == ans) {
          --c;
        }
      }
    }
  }
  if (ans == -1) {
    cout << 0 << ' ' << 0 << endl;
    return 0;
  }
  cout << ans << ' ' << c << endl;
  return 0;
}

```