#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()
#define SL(n) scanf("%d", &n)
#define PL(n) printf("%lld", n)
#define fill(a, x) memset(a, x, sizeof(a));
#define mod 1000000007

using namespace std;
typedef int LL;
typedef vector <LL> VL;
typedef map <LL, LL> ML;
typedef pair<LL, LL> PL;
typedef vector <pair <LL, LL> > VPL;

int main(){
    LL N, M, K, P;
    SL(N);
    SL(M);
    SL(K);
    SL(P);
    LL a[N+5][M+5];
    LL Col[M+5];
    LL Row[N+5];
    for(LL n=0;n<N;++n){
        for(LL m=0;m<M;++m){
            SL(a[n][m]);
        }
    }
    LL Ans = 0;
    LL x, b, c, d, y, i, j, n, m, Sum;
    for(n=0;n<N;++n){
        Sum = 0;
        for(m=0;m<M;++m){
            Sum += a[n][m];
        }
        Row[n] = Sum;
    }
    for(m=0;m<M;++m){
        Sum = 0;
        for(n=0;n<N;++n){
            Sum += a[n][m];
        }
        Col[m] = Sum;
    }
    pair<LL, LL> temp1;
    while(K--){
        b = (LL)-1e9;
        c = 0;
        d = 0;
        for(n=0;n<N;++n){
            if(b < Row[n]){
                b = Row[n];
                c = n;
                d = 0;
            }
        }
        for(m=0;m<M;++m){
            if(b < Col[m]){
                b = Col[m];
                c = m;
                d = 1;
            }
        }
        //cout << "   " << b << " " << c << " " << d << endl;
        if(d == 1){
            Ans += b;
            for(n=0;n<N;++n){
                Row[n] -= P;
            }
            Col[c] -= N*P;
        }
        else{
            Ans += b;
            for(m=0;m<M;++m){
                Col[m] -= P;
            }
            Row[c] -= M*P;
        }
    }
    cout << Ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, k, p, x;

// rowsum, colsum
LL rs[1001];
LL cs[1001];

// ar[i] -> value of pleasure after taking i largest rowsums; ac[i] is the same for columns
LL ar[1000001];
LL ac[1000001];

LQ que;

void solve1() {
  while (!que.empty()) que.pop();
  for (int i = 0; i < n; ++i) {
    que.push(rs[i]);
  }
  ar[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ar[i] = que.top() + ar[i - 1];
    LL nv = que.top() - p * m;
    que.pop();
    que.push(nv);
  }
}

void solve2() {
  while (!que.empty()) que.pop();
  for (int i = 0; i < m; ++i) {
    que.push(cs[i]);
  }
  ac[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ac[i] = que.top() + ac[i - 1];
    LL nv = que.top() - p * n;
    que.pop();
    que.push(nv);
  }
}

LL solve() {
  solve1();
  solve2();
  LL mx = -10000000000000000;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - (LL)i * j * p;
    if (mx < v) mx = v;
  }
  return mx;
}

int main() {
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      rs[i] += x;
      cs[j] += x;
    }
  }
  cout << solve() << endl;
  return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

LL n, m, p, k;
LL tbl[1001][1001];
LL r[1001];
LL c[1001];

LL ar[1000002];
LL ac[1000002];

int main() {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> tbl[i][j];
      r[i] += tbl[i][j];
      c[j] += tbl[i][j];
    }
  }

  LQ rq;
  for (int i = 0; i < n; ++i) {
    rq.push(r[i]);
  }

  LQ cq;
  for (int i = 0; i < m; ++i) {
    cq.push(c[i]);
  }

  ar[0] = ac[0] = 0;
  ar[1] = rq.top();
  ac[1] = cq.top();
  for (int i = 2; i <= k; ++i) {
    LL nr = rq.top() - 1LL * m * p;
    rq.pop();
    rq.push(nr);
    ar[i] = rq.top() + ar[i - 1];

    LL nc = cq.top() - 1LL * n * p;
    cq.pop();
    cq.push(nc);
    ac[i] = cq.top() + ac[i - 1];
  }

  LL mx = -1000000000000000000;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL sub = i * j * p;
    LL v = ar[i] + ac[j] - 1LL * sub;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, p, k;
int tbl[1001][1001];
int r[1001];
int c[1001];

LL ar[1000002];
LL ac[1000002];

int main() {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> tbl[i][j];
      r[i] += tbl[i][j];
      c[j] += tbl[i][j];
    }
  }

  LQ rq;
  for (int i = 0; i < n; ++i) {
    rq.push(r[i]);
  }

  LQ cq;
  for (int i = 0; i < m; ++i) {
    cq.push(c[i]);
  }

  ar[0] = ac[0] = 0;
  ar[1] = rq.top();
  ac[1] = cq.top();
  for (int i = 2; i <= k; ++i) {
    LL nr = rq.top() - m * p;
    rq.pop();
    rq.push(nr);
    ar[i] = rq.top() + ar[i - 1];

    LL nc = cq.top() - n * p;
    cq.pop();
    cq.push(nc);
    ac[i] = cq.top() + ac[i - 1];
  }

  LL mx = -10000000000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL sub = i * j * p;
    LL v = ar[i] + ac[j] - sub;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, k, p, x;

// rowsum, colsum
LL rs[1001];
LL cs[1001];

// ar[i] -> value of pleasure after taking i largest rowsums; ac[i] is the same for columns
LL ar[1000001];
LL ac[1000001];

LQ que;

void solve1() {
  while (!que.empty()) que.pop();
  for (int i = 0; i < n; ++i) {
    que.push(rs[i]);
  }
  ar[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ar[i] = que.top() + ar[i - 1];
    LL nv = que.top() - p * m;
    que.pop();
    que.push(nv);
  }
}

void solve2() {
  while (!que.empty()) que.pop();
  for (int i = 0; i < m; ++i) {
    que.push(cs[i]);
  }
  ac[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ac[i] = que.top() + ac[i - 1];
    LL nv = que.top() - p * n;
    que.pop();
    que.push(nv);
  }
}

LL solve() {
  solve1();
  solve2();
  LL mx = -10000000000000000;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - i * j * p;
    if (mx < v) mx = v;
  }
  return mx;
}

int main() {
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      rs[i] += x;
      cs[j] += x;
    }
  }
  cout << solve() << endl;
  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, k, p, x;

// rowsum, colsum
LL rs[1001];
LL cs[1001];

// ar[i] -> value of pleasure after taking i largest rowsums; ac[i] is the same for columns
LL ar[1000001];
LL ac[1000001];

int main() {
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      rs[i] += x;
      cs[j] += x;
    }
  }

  LQ rq, cq;
  for (int i = 0; i < n; ++i) rq.push(rs[i]);
  for (int i = 0; i < m; ++i) cq.push(cs[i]);

  ar[0] = ac[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ar[i] = rq.top() + ar[i - 1];
    LL nr = rq.top() - (LL)p * m;
    rq.pop();
    rq.push(nr);
    ac[i] = cq.top() + ac[i - 1];
    LL nc = cq.top() - (LL)p * n;
    cq.pop();
    cq.push(nc);
  }

  LL mx = -1000000000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - (LL)i * j * p;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, k, p, x;

// rowsum, colsum
LL rs[1001];
LL cs[1001];

// ar[i] -> value of pleasure after taking i largest rowsums; ac[i] is the same for columns
LL ar[1000001];
LL ac[1000001];

int main() {
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      rs[i] += x;
      cs[j] += x;
    }
  }

  LQ rq, cq;
  for (int i = 0; i < n; ++i) rq.push(rs[i]);
  for (int i = 0; i < m; ++i) cq.push(cs[i]);

  ar[0] = ac[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ar[i] = rq.top() + ar[i - 1];
    LL nr = rq.top() - (LL)p * m;
    rq.pop();
    rq.push(nr);
    ac[i] = cq.top() + ac[i - 1];
    LL nc = cq.top() - (LL)p * n;
    cq.pop();
    cq.push(nc);
  }

  LL mx = -1000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - (LL)i * j * p;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

LL n, m, p, k;
LL tbl[1001][1001];
LL r[1001];
LL c[1001];

LL ar[1000002];
LL ac[1000002];

int main() {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> tbl[i][j];
      r[i] += tbl[i][j];
      c[j] += tbl[i][j];
    }
  }

  LQ rq;
  for (int i = 0; i < n; ++i) {
    rq.push(r[i]);
  }

  LQ cq;
  for (int i = 0; i < m; ++i) {
    cq.push(c[i]);
  }

  ar[0] = ac[0] = 0;
  ar[1] = rq.top();
  ac[1] = cq.top();
  for (int i = 2; i <= k; ++i) {
    LL nr = rq.top() - m * p;
    rq.pop();
    rq.push(nr);
    ar[i] = rq.top() + ar[i - 1];

    LL nc = cq.top() - n * p;
    cq.pop();
    cq.push(nc);
    ac[i] = cq.top() + ac[i - 1];
  }

  LL mx = -1000000000000000000;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL sub = i * j * p;
    LL v = ar[i] + ac[j] - sub;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, p, k;
int tbl[1001][1001];
int r[1001];
int c[1001];

LL ar[1000002];
LL ac[1000002];

int main() {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> tbl[i][j];
      r[i] += tbl[i][j];
      c[j] += tbl[i][j];
    }
  }

  LQ rq;
  for (int i = 0; i < n; ++i) {
    rq.push(r[i]);
  }

  LQ cq;
  for (int i = 0; i < m; ++i) {
    cq.push(c[i]);
  }

  ar[0] = ac[0] = 0;
  ar[1] = rq.top();
  ac[1] = cq.top();
  for (int i = 2; i <= k; ++i) {
    LL nr = rq.top() - m * p;
    rq.pop();
    rq.push(nr);
    ar[i] = rq.top() + ar[i - 1];

    LL nc = cq.top() - n * p;
    cq.pop();
    cq.push(nc);
    ac[i] = cq.top() + ac[i - 1];
  }

  LL mx = -1000000000000000000;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL sub = i * j * p;
    LL v = ar[i] + ac[j] - sub;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, k, x;
LL p;

// rowsum, colsum
LL rs[1001];
LL cs[1001];

// ar[i] -> value of pleasure after taking i largest rowsums; ac[i] is the same for columns
LL ar[1000001];
LL ac[1000001];

int main() {
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      rs[i] += x;
      cs[j] += x;
    }
  }

  LQ rq, cq;
  for (int i = 0; i < n; ++i) rq.push(rs[i]);
  for (int i = 0; i < m; ++i) cq.push(cs[i]);

  ar[0] = ac[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ar[i] = rq.top() + ar[i - 1];
    LL nr = rq.top() - p * m;
    rq.pop();
    rq.push(nr);
    ac[i] = cq.top() + ac[i - 1];
    LL nc = cq.top() - p * n;
    cq.pop();
    cq.push(nc);
  }

  LL mx = -1000000000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - p * i * j;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, k, x;
LL p;

// rowsum, colsum
LL rs[1001];
LL cs[1001];

// ar[i] -> value of pleasure after taking i largest rowsums; ac[i] is the same for columns
LL ar[1000001];
LL ac[1000001];

int main() {
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      rs[i] += x;
      cs[j] += x;
    }
  }

  LQ rq, cq;
  for (int i = 0; i < n; ++i) rq.push(rs[i]);
  for (int i = 0; i < m; ++i) cq.push(cs[i]);

  ar[0] = ac[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ar[i] = rq.top() + ar[i - 1];
    LL nr = rq.top() - p * m;
    rq.pop();
    rq.push(nr);
    ac[i] = cq.top() + ac[i - 1];
    LL nc = cq.top() - p * n;
    cq.pop();
    cq.push(nc);
  }

  LL mx = -1000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - (LL)i * j * p;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, k, x;
LL p;

// rowsum, colsum
LL rs[1001];
LL cs[1001];

// ar[i] -> value of pleasure after taking i largest rowsums; ac[i] is the same for columns
LL ar[1000001];
LL ac[1000001];

int main() {
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      rs[i] += x;
      cs[j] += x;
    }
  }

  LQ rq, cq;
  for (int i = 0; i < n; ++i) rq.push(rs[i]);
  for (int i = 0; i < m; ++i) cq.push(cs[i]);

  ar[0] = ac[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ar[i] = rq.top() + ar[i - 1];
    LL nr = rq.top() - p * m;
    rq.pop();
    rq.push(nr);
    ac[i] = cq.top() + ac[i - 1];
    LL nc = cq.top() - p * n;
    cq.pop();
    cq.push(nc);
  }

  LL mx = -1000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - p * i * j;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

LL n, m, p, k;
int tbl[1001][1001];
int r[1001];
int c[1001];

LL ar[1000002];
LL ac[1000002];

int main() {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> tbl[i][j];
      r[i] += tbl[i][j];
      c[j] += tbl[i][j];
    }
  }

  LQ rq;
  for (int i = 0; i < n; ++i) {
    rq.push(r[i]);
  }

  LQ cq;
  for (int i = 0; i < m; ++i) {
    cq.push(c[i]);
  }

  ar[0] = ac[0] = 0;
  ar[1] = rq.top();
  ac[1] = cq.top();
  for (int i = 2; i <= k; ++i) {
    LL nr = rq.top() - m * p;
    rq.pop();
    rq.push(nr);
    ar[i] = rq.top() + ar[i - 1];

    LL nc = cq.top() - n * p;
    cq.pop();
    cq.push(nc);
    ac[i] = cq.top() + ac[i - 1];
  }

  LL mx = -100000000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - i * j * p;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, k, p, x;

// rowsum, colsum
LL rs[1001];
LL cs[1001];

// ar[i] -> value of pleasure after taking i largest rowsums; ac[i] is the same for columns
LL ar[1000001];
LL ac[1000001];

LQ que;

void solve1() {
  while (!que.empty()) que.pop();
  for (int i = 0; i < n; ++i) {
    que.push(rs[i]);
  }
  ar[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ar[i] = que.top() + ar[i - 1];
    LL nv = que.top() - p * m;
    que.pop();
    que.push(nv);
  }
}

void solve2() {
  while (!que.empty()) que.pop();
  for (int i = 0; i < m; ++i) {
    que.push(cs[i]);
  }
  ac[0] = 0;
  for (int i = 1; i <= k; ++i) {
    ac[i] = que.top() + ac[i - 1];
    LL nv = que.top() - p * n;
    que.pop();
    que.push(nv);
  }
}

LL solve() {
  solve1();
  solve2();
  LL mx = -10000000000000000;
    int i;
    for (i=0;i<=k;i++) {
        long long tmp=ar[i]+ac[k-i]-1LL*i*(k-i)*p;
        if (tmp>mx) mx=tmp;
    }
  return mx;
}

int main() {
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> x;
      rs[i] += x;
      cs[j] += x;
    }
  }
  cout << solve() << endl;
  return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

LL n, m, p, k;
LL tbl[1001][1001];
LL r[1001];
LL c[1001];

LL ar[1000002];
LL ac[1000002];

int main() {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> tbl[i][j];
      r[i] += tbl[i][j];
      c[j] += tbl[i][j];
    }
  }

  LQ rq;
  for (int i = 0; i < n; ++i) {
    rq.push(r[i]);
  }

  LQ cq;
  for (int i = 0; i < m; ++i) {
    cq.push(c[i]);
  }

  ar[0] = ac[0] = 0;
  ar[1] = rq.top();
  ac[1] = cq.top();
  for (int i = 2; i <= k; ++i) {
    LL nr = rq.top() - m * p;
    rq.pop();
    rq.push(nr);
    ar[i] = rq.top() + ar[i - 1];

    LL nc = cq.top() - n * p;
    cq.pop();
    cq.push(nc);
    ac[i] = cq.top() + ac[i - 1];
  }

  LL mx = -1000000000000000000LL;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL sub = i * j * p;
    LL v = ar[i] + ac[j] - sub;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, p, k;
int tbl[1001][1001];
int r[1001];
int c[1001];

LL ar[1000002];
LL ac[1000002];

int main() {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> tbl[i][j];
      r[i] += tbl[i][j];
      c[j] += tbl[i][j];
    }
  }

  LQ rq;
  for (int i = 0; i < n; ++i) {
    rq.push(r[i]);
  }

  LQ cq;
  for (int i = 0; i < m; ++i) {
    cq.push(c[i]);
  }

  ar[0] = ac[0] = 0;
  ar[1] = rq.top();
  ac[1] = cq.top();
  for (int i = 2; i <= k; ++i) {
    LL nr = rq.top() - m * p;
    rq.pop();
    rq.push(nr);
    ar[i] = rq.top() + ar[i - 1];

    LL nc = cq.top() - n * p;
    cq.pop();
    cq.push(nc);
    ac[i] = cq.top() + ac[i - 1];
  }

  LL mx = -1000000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL sub = i * j * p;
    LL v = ar[i] + ac[j] - sub;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <vector>
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef priority_queue<LL> LQ;

int n, m, p, k;
int tbl[1001][1001];
int r[1001];
int c[1001];

LL ar[1000002];
LL ac[1000002];

int main() {
  memset(r, 0, sizeof r);
  memset(c, 0, sizeof c);
  cin >> n >> m >> k >> p;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      cin >> tbl[i][j];
      r[i] += tbl[i][j];
      c[j] += tbl[i][j];
    }
  }

  LQ rq;
  for (int i = 0; i < n; ++i) {
    rq.push(r[i]);
  }

  LQ cq;
  for (int i = 0; i < m; ++i) {
    cq.push(c[i]);
  }

  ar[0] = ac[0] = 0;
  ar[1] = rq.top();
  ac[1] = cq.top();
  for (int i = 2; i <= k; ++i) {
    LL nr = rq.top() - m * p;
    rq.pop();
    rq.push(nr);
    ar[i] = rq.top() + ar[i - 1];

    LL nc = cq.top() - n * p;
    cq.pop();
    cq.push(nc);
    ac[i] = cq.top() + ac[i - 1];
  }

  LL mx = -100000000000001;
  for (int i = 0; i <= k; ++i) {
    int j = k - i;
    LL v = ar[i] + ac[j] - i * j * p;
    if (mx < v) mx = v;
  }
  cout << mx << endl;

  return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define forn(i,n) for (size_t i = 0; i < n; ++i)
#define forb(i,n) for (int i = n - 1; i >= 0; --i)
const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int INF = (1 << 31);

int n, m, k, p, tmp, mul = 0, cols[6666], rows[6666], dp[2][1234567];
priority_queue<int> q;
int ans = 0;

int main() {
#ifdef F0X
    freopen("input.in", "r", stdin);
#endif
    scanf("%d%d%d%d", &n, &m, &k, &p);
    forn(i, n)
        forn(j, m) {
        scanf("%d", &tmp);
        rows[i] += tmp;
        cols[j] += tmp;
    }

    while (q.size()) q.pop();
    forn(i, n) q.push(rows[i]);
    dp[0][0] = dp[1][0] = 0;

    for (int i = 1; i <= k; ++i) {
        int tmp = q.top();
        q.pop();
        dp[0][i] = tmp + dp[0][i - 1];
        tmp -= m * p;
        q.push(tmp);
    }

    while (q.size()) q.pop();
    forn(i, m) q.push(cols[i]);

    for (int i = 1; i <= k; ++i) {
        tmp = q.top();
        q.pop();
        dp[1][i] = tmp + dp[1][i - 1];
        tmp -= n * p;
        q.push(tmp);
    }

    for (int i = 0; i <= k; i++) {
        if (dp[0][i] + dp[1][k-i] - i * (k - i) * p > ans) {
            ans = dp[0][i] + dp[1][k-i] - i * (k - i) * p;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define forn(i,n) for (size_t i = 0; i < n; ++i)

const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int INF = (1 << 31);

int n, m, k, p, tmp, ans = 0, cols[6666], rows[6666];
priority_queue<pair<int, int> > q_cols, q_rows;

int main() {
#ifdef F0X
    freopen("input.in", "r", stdin);
#endif
    forn(i, 6666) rows[i] = cols[i] = 0;
    scanf("%d%d%d%d", &n, &m, &k, &p);
    forn(i, n)
        forn(j, m) {
        scanf("%d", &tmp);
        rows[i] += tmp;
        cols[j] += tmp;
    }
    forn(i, n) q_rows.push(mp(rows[i], 0));
    forn(i, m) q_cols.push(mp(cols[i], 0));
    int delCols = 0, delRows = 0;
    pair<int, int> valR = q_rows.top(), valC = q_cols.top();
    q_cols.pop();
    q_rows.pop();

    while (k--) {
        int R = valR.first - p * (delCols - valR.second),
            C = valC.first - p * (delRows - valC.second);
        if (R > C) {
            delRows++;
            ans += R;
            q_rows.push(mp(R - n * p, delCols));
            valR = q_rows.top();
            q_rows.pop();
        }
        else {
            delCols++;
            ans += C;
            q_cols.push(mp(C - m * p, delRows));
            valC = q_cols.top();
            q_cols.pop();
        }
    }
    cout << ans << endl;
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define forn(i,n) for (size_t i = 0; i < n; ++i)
#define forb(i,n) for (int i = n - 1; i >= 0; --i)
const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int INF = (1 << 31);

int n, m, k, p, tmp, mul = 0, cols[6666], rows[6666], dp[2][1234567];
priority_queue<int> q;
ll ans = -999999999999999999LL;

int main() {
#ifdef F0X
    freopen("input.in", "r", stdin);
#endif
    scanf("%d%d%d%d", &n, &m, &k, &p);
    forn(i, n)
        forn(j, m) {
        scanf("%d", &tmp);
        rows[i] += tmp;
        cols[j] += tmp;
    }

    while (q.size()) q.pop();
    forn(i, n) q.push(rows[i]);
    dp[0][0] = dp[1][0] = 0;

    for (int i = 1; i <= k; ++i) {
        int tmp = q.top();
        q.pop();
        dp[0][i] = tmp + dp[0][i - 1];
        tmp -= m * p;
        q.push(tmp);
    }

    while (q.size()) q.pop();
    forn(i, m) q.push(cols[i]);

    for (int i = 1; i <= k; ++i) {
        tmp = q.top();
        q.pop();
        dp[1][i] = tmp + dp[1][i - 1];
        tmp -= n * p;
        q.push(tmp);
    }

    for (int i = 0; i <= k; i++) {
        if (dp[0][i] + dp[1][k-i] - i * (k - i) * 1LL * p > ans) {
            ans = dp[0][i] + dp[1][k-i] - i * (k - i) * p;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

long long rs[1000010], cs[1000010];
int main()
{
    const int MAX = 1010;
    int w[MAX][MAX];
    int r[MAX], c[MAX];
    int k, p;
    int n, m;
    cin >> n >> m >> k >> p;
    for(int i = 0; i < MAX; ++i)
        r[i] = c[i] = 0;

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            cin >> w[i][j];
            r[i] += w[i][j];
            c[j] += w[i][j];
        }
    }
    priority_queue<long long> rr, cc;
    for(int i = 0; i < n; ++i)
        rr.push(r[i]);
    for(int i = 0; i < m; ++i)
        cc.push(c[i]);

    rs[0] = cs[0] = 0;

    for(int i = 1; i <= k; ++i)
    {
        rs[i] = rs[i - 1] + rr.top();
        int temp = rr.top() - p * n;
        rr.pop();
        rr.push(temp);

        cs[i] = cs[i - 1] + cc.top();
        temp = cc.top() - p * m;
        cc.pop();
        cc.push(temp);
    }

    long long out = -1000000000000;

    for(int i = 0; i <= k; ++i)
    {
        out = max(out, rs[i] + cs[k - i] - p * 1LL * i * (k - i));
    }

    cout << out << endl;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define forn(i,n) for (size_t i = 0; i < n; ++i)
#define forb(i,n) for (int i = n - 1; i >= 0; --i)
const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int INF = (1 << 31);

int n, m, k, p, tmp, mul = 0, cols[6666], rows[6666], dp[2][1234567];
priority_queue<int> q;
ll ans = -999999999999999999LL;

int main() {
#ifdef F0X
    freopen("input.in", "r", stdin);
#endif
    scanf("%d%d%d%d", &n, &m, &k, &p);
    forn(i, n)
        forn(j, m) {
        scanf("%d", &tmp);
        rows[i] += tmp;
        cols[j] += tmp;
    }

    while (q.size()) q.pop();
    forn(i, n) q.push(rows[i]);
    dp[0][0] = dp[1][0] = 0;

    for (int i = 1; i <= k; ++i) {
        int tmp = q.top();
        q.pop();
        dp[0][i] = tmp + dp[0][i - 1];
        tmp -= m * p;
        q.push(tmp);
    }

    while (q.size()) q.pop();
    forn(i, m) q.push(cols[i]);

    for (int i = 1; i <= k; ++i) {
        tmp = q.top();
        q.pop();
        dp[1][i] = tmp + dp[1][i - 1];
        tmp -= n * p;
        q.push(tmp);
    }

    for (int i = 0; i <= k; i++) {
        if (dp[0][i] + dp[1][k-i] - i * (k - i) * 1LL * p > ans) {
            ans = dp[0][i] + dp[1][k-i] - i * 1LL * (k - i) * p;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define forn(i,n) for (size_t i = 0; i < n; ++i)
#define forb(i,n) for (int i = n - 1; i >= 0; --i)
const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int INF = (1 << 31);

int n, m, k, p, tmp, mul = 0, cols[6666], rows[6666];
priority_queue<ll> q;
ll ans = -999999999999999999LL,  dp[2][1234567];;

int main() {
#ifdef F0X
    freopen("input.in", "r", stdin);
#endif
    scanf("%d%d%d%d", &n, &m, &k, &p);
    forn(i, n)
        forn(j, m) {
        scanf("%d", &tmp);
        rows[i] += tmp;
        cols[j] += tmp;
    }

    while (q.size()) q.pop();
    forn(i, n) q.push(rows[i]);
    dp[0][0] = dp[1][0] = 0;

    for (int i = 1; i <= k+3; ++i) {
        dp[0][i] = q.top() + dp[0][i - 1];
        q.push(q.top() - p * m);
        q.pop();
    }

    while (q.size()) q.pop();
    forn(i, m) q.push(cols[i]);

    for (int i = 1; i <= k+3; ++i) {
        dp[1][i] = q.top() + dp[1][i - 1];
        q.push(q.top() - p * n);
        q.pop();
    }

    for (int i = 0; i <= k; i++) {
            ans = max(ans, dp[0][i] + dp[1][k-i] - i * 1LL * (k - i) * p);
    }

    cout << ans << endl;
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define forn(i,n) for (size_t i = 0; i < n; ++i)
#define forb(i,n) for (int i = n - 1; i >= 0; --i)
const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int INF = (1 << 31);

int n, m, k, p, tmp, mul = 0, cols[6666], rows[6666], dp[2][1234567];
priority_queue<int> q;
ll ans = 0;

int main() {
#ifdef F0X
    freopen("input.in", "r", stdin);
#endif
    scanf("%d%d%d%d", &n, &m, &k, &p);
    forn(i, n)
        forn(j, m) {
        scanf("%d", &tmp);
        rows[i] += tmp;
        cols[j] += tmp;
    }

    while (q.size()) q.pop();
    forn(i, n) q.push(rows[i]);
    dp[0][0] = dp[1][0] = 0;

    for (int i = 1; i <= k; ++i) {
        int tmp = q.top();
        q.pop();
        dp[0][i] = tmp + dp[0][i - 1];
        tmp -= m * p;
        q.push(tmp);
    }

    while (q.size()) q.pop();
    forn(i, m) q.push(cols[i]);

    for (int i = 1; i <= k; ++i) {
        tmp = q.top();
        q.pop();
        dp[1][i] = tmp + dp[1][i - 1];
        tmp -= n * p;
        q.push(tmp);
    }

    for (int i = 0; i <= k; i++) {
        if (dp[0][i] + dp[1][k-i] - i * (k - i) * 1LL * p > ans) {
            ans = dp[0][i] + dp[1][k-i] - i * (k - i) * p;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define forn(i,n) for (size_t i = 0; i < n; ++i)
#define forb(i,n) for (int i = n - 1; i >= 0; --i)
const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int INF = (1 << 31);

int n, m, k, p, tmp, cols[6666], rows[6666];
priority_queue<ll> q;
ll ans = -999999999999999999LL,  dp[2][1000005];;

int main() {
#ifdef F0X
    freopen("input.in", "r", stdin);
#endif
    scanf("%d%d%d%d", &n, &m, &k, &p);
    forn(i, n)
        forn(j, m) {
        scanf("%d", &tmp);
        rows[i] += tmp;
        cols[j] += tmp;
    }

    while (q.size()) q.pop();
    forn(i, n) q.push(rows[i]);
    dp[0][0] = dp[1][0] = 0;

    for (int i = 1; i <= k; ++i) {
        dp[0][i] = q.top() + dp[0][i - 1];
        q.push(q.top() - p * m);
        q.pop();
    }

    while (q.size()) q.pop();
    forn(i, m) q.push(cols[i]);

    for (int i = 1; i <= k; ++i) {
        dp[1][i] = q.top() + dp[1][i - 1];
        q.push(q.top() - p * n);
        q.pop();
    }

    for (int i = 0; i <= k; i++) {
            ans = max(ans, dp[0][i] + dp[1][k-i] - i * 1LL * (k - i) * p);
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

long long rs[1000010], cs[1000010];
int main()
{
    const int MAX = 1010;
    int w[MAX][MAX];
    int r[MAX], c[MAX];
    int k, p;
    int n, m;
    cin >> n >> m >> k >> p;
    for(int i = 0; i < MAX; ++i)
        r[i] = c[i] = 0;

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            cin >> w[i][j];
            r[i] += w[i][j];
            c[j] += w[i][j];
        }
    }
    priority_queue<long long> rr, cc;
    for(int i = 0; i < n; ++i)
        rr.push(r[i]);
    for(int i = 0; i < m; ++i)
        cc.push(c[i]);

    rs[0] = cs[0] = 0;

    for(int i = 1; i <= k; ++i)
    {
        rs[i] = rs[i - 1] + rr.top();
        int temp = rr.top() - p * m;
        rr.pop();
        rr.push(temp);

        cs[i] = cs[i - 1] + cc.top();
        temp = cc.top() - p * n;
        cc.pop();
        cc.push(temp);
    }

    long long out = -1000000000000000000LL;

    for(int i = 0; i <= k; ++i)
    {
        out = max(out, rs[i] + cs[k - i] - p * 1LL * i * (k - i));
    }

    cout << out << endl;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;

long long rs[1000010], cs[1000010];
int main()
{
    const int MAX = 1010;
    int w[MAX][MAX];
    int r[MAX], c[MAX];
    int k, p;
    int n, m;
    cin >> n >> m >> k >> p;
    for(int i = 0; i < MAX; ++i)
        r[i] = c[i] = 0;

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j < m; ++j)
        {
            cin >> w[i][j];
            r[i] += w[i][j];
            c[j] += w[i][j];
        }
    }
    priority_queue<long long> rr, cc;
    for(int i = 0; i < n; ++i)
        rr.push(r[i]);
    for(int i = 0; i < m; ++i)
        cc.push(c[i]);

    rs[0] = cs[0] = 0;

    for(int i = 1; i <= k; ++i)
    {
        rs[i] = rs[i - 1] + rr.top();
        int temp = rr.top() - p * m;
        rr.pop();
        rr.push(temp);

        cs[i] = cs[i - 1] + cc.top();
        temp = cc.top() - p * n;
        cc.pop();
        cc.push(temp);
    }

    long long out = -1000000000000;

    for(int i = 0; i <= k; ++i)
    {
        out = max(out, rs[i] + cs[k - i] - p * 1LL * i * (k - i));
    }

    cout << out << endl;
}


#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;

#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define pb push_back
#define mp make_pair
#define forn(i,n) for (size_t i = 0; i < n; ++i)
#define forb(i,n) for (int i = n - 1; i >= 0; --i)
const double EPS = 1e-9;
const int MAXN = 666666;
const int MOD = 1e9 + 7;
const int INF = (1 << 31);

int n, m, k, p, tmp, mul = 0, cols[6666], rows[6666], dp[2][1234567];
priority_queue<int> q;
ll ans = -999999999999999999LL;

int main() {
#ifdef F0X
    freopen("input.in", "r", stdin);
#endif
    scanf("%d%d%d%d", &n, &m, &k, &p);
    forn(i, n)
        forn(j, m) {
        scanf("%d", &tmp);
        rows[i] += tmp;
        cols[j] += tmp;
    }

    while (q.size()) q.pop();
    forn(i, n) q.push(rows[i]);
    dp[0][0] = dp[1][0] = 0;

    for (int i = 1; i <= k+3; ++i) {
        dp[0][i] = q.top() + dp[0][i - 1];
        q.push(q.top() - p * m);
        q.pop();
    }

    while (q.size()) q.pop();
    forn(i, m) q.push(cols[i]);

    for (int i = 1; i <= k+3; ++i) {
        dp[1][i] = q.top() + dp[1][i - 1];
        q.push(q.top() - p * n);
        q.pop();
    }

    for (int i = 0; i <= k; i++) {
            ans = max(ans, dp[0][i] + dp[1][k-i] - i * 1LL * (k - i) * p);
    }

    cout << ans << endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define EPS 1e-8
#define MAXN 1005
#define MAXE 1005

typedef pair<int, int> pii;
typedef long long ll;

int n, m, k, p;
int a[MAXN][MAXN];

int hr[MAXN], hc[MAXN];

void heapify(int *a, int n, int i) {
	int l = 2 * i, r = l + 1;
	int ix = (l <= n && a[l] > a[i]) ? l : i;
	if (r <= n && a[r] > a[ix]) ix = r;
	if (ix != i) {
		swap(a[i], a[ix]);
		heapify(a, n, ix);
	}
}

void build_heap(int *a, int n) {
	for (int i = n / 2; i >= 1; --i) {
		heapify(a, n, i);
	}
}

int main() {
	scanf("%d %d %d %d", &n, &m, &k, &p);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			scanf("%d", &a[i][j]);
		}
	}

	// init heap
	for (int i = 0; i < n; ++i) {
		int sum = 0;
		for (int j = 0; j < m; ++j) {
			sum += a[i][j];
		}
		hr[i + 1] = sum;
	}
	for (int j = 0; j < m; ++j) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			sum += a[i][j];
		}
		hc[j + 1] = sum;
	}
	build_heap(hr, n);
	build_heap(hc, m);

	/*
	for (int i = 0; i < n; ++i) {
		printf("%d ", hr[i + 1]);
	}
	*/

	int nr = 0, nc = 0;
	ll ret = 0;
	for (int i = 0; i < k; ++i) {
		if (hr[1] > hc[1]) {
			ret += (hr[1] - nr * p);
			nc += 1;
			hr[1] -= m * p;
			heapify(hr, n, 1);
		} else {
			ret += (hc[1] - nc * p);
			nr += 1;
			hc[1] -= n * p;
			heapify(hc, m, 1);
		}
	}
	cout << ret << endl;

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define EPS 1e-8
#define MAXN 1005
#define MAXE 1005

typedef pair<int, int> pii;
typedef long long ll;

int n, m, k, p;
int a[MAXN][MAXN];

int hr[MAXN], hc[MAXN];

void heapify(int *a, int n, int i) {
	int l = 2 * i, r = l + 1;
	int ix = (l <= n && a[l] > a[i]) ? l : i;
	if (r <= n && a[r] > a[ix]) ix = r;
	if (ix != i) {
		swap(a[i], a[ix]);
		heapify(a, n, ix);
	}
}

void build_heap(int *a, int n) {
	for (int i = n / 2; i >= 1; --i) {
		heapify(a, n, i);
	}
}

int main() {
	scanf("%d %d %d %d", &n, &m, &k, &p);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			scanf("%d", &a[i][j]);
		}
	}

	// init heap
	for (int i = 0; i < n; ++i) {
		int sum = 0;
		for (int j = 0; j < m; ++j) {
			sum += a[i][j];
		}
		hr[i + 1] = sum;
	}
	for (int j = 0; j < m; ++j) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			sum += a[i][j];
		}
		hc[j + 1] = sum;
	}
	build_heap(hr, n);
	build_heap(hc, m);

	/*
	for (int i = 0; i < n; ++i) {
		printf("%d ", hr[i + 1]);
	}
	*/

	int nr = 0, nc = 0;
	int ret = 0;
	for (int i = 0; i < k; ++i) {
		if (hr[1] > hc[1]) {
			ret += (hr[1] - nr * p);
			nc += 1;
			hr[1] -= m * p;
			heapify(hr, n, 1);
		} else {
			ret += (hc[1] - nc * p);
			nr += 1;
			hc[1] -= n * p;
			heapify(hc, m, 1);
		}
	}
	printf("%d\n", ret);

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define EPS 1e-8
#define MAXN 1005
#define MAXK 1000005

typedef pair<int, int> pii;
typedef long long ll;

int n, m, k, p;
int a[MAXN][MAXN];

int hr[MAXN], hc[MAXN];
ll sr[MAXK], sc[MAXK];
ll ret;

void heapify(int *a, int n, int i) {
	int l = 2 * i, r = l + 1;
	int ix = (l <= n && a[l] > a[i]) ? l : i;
	if (r <= n && a[r] > a[ix]) ix = r;
	if (ix != i) {
		swap(a[i], a[ix]);
		heapify(a, n, ix);
	}
}

void build_heap(int *a, int n) {
	for (int i = n / 2; i >= 1; --i) {
		heapify(a, n, i);
	}
}

void gao() {
	ll now = 0;
	for (int i = 1; i <= k; ++i) {
		sr[i] = hr[1] + now;
		hr[1] -= p * m;
		heapify(hr, n, 1);
		now = sr[i];
	}

	now = 0;
	for (int i = 1; i <= k; ++i) {
		sc[i] = hc[1] + now;
		hc[1] -= p * n;
		heapify(hc, m, 1);
		now = sc[i];
	}

	ret = LLONG_MIN;
	for (int i = 0; i <= k; ++i) {
		ret = max(ret, sr[i] + sc[k - i] - (ll)i * (k - i) * p);
	}
}

int main() {
	scanf("%d %d %d %d", &n, &m, &k, &p);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			scanf("%d", &a[i][j]);
			hr[i + 1] += a[i][j];
			hc[j + 1] += a[i][j];
		}
	}

	build_heap(hr, n);
	build_heap(hc, m);

	gao();
	cout << ret << endl;

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define EPS 1e-8
#define MAXN 1005
#define MAXE 1005

typedef pair<int, int> pii;
typedef long long ll;

int n, m, k, p;
int a[MAXN][MAXN];

int hr[MAXN], hc[MAXN];
ll sr[MAXN], sc[MAXN];
ll ret;

void heapify(int *a, int n, int i) {
	int l = 2 * i, r = l + 1;
	int ix = (l <= n && a[l] > a[i]) ? l : i;
	if (r <= n && a[r] > a[ix]) ix = r;
	if (ix != i) {
		swap(a[i], a[ix]);
		heapify(a, n, ix);
	}
}

void build_heap(int *a, int n) {
	for (int i = n / 2; i >= 1; --i) {
		heapify(a, n, i);
	}
}

void gao() {
	ll now = 0;
	for (int i = 1; i <= k; ++i) {
		sr[i] = hr[1] + now;
		hr[1] -= p * m;
		heapify(hr, n, 1);
		now = sr[i];
	}

	now = 0;
	for (int i = 1; i <= k; ++i) {
		sc[i] = hc[1] + now;
		hc[1] -= p * n;
		heapify(hc, m, 1);
		now = sc[i];
	}

	ret = LLONG_MIN;
	for (int i = 0; i <= k; ++i) {
		ret = max(ret, sr[i] + sc[k - i] - (ll)i * (k - i) * p);
	}
}

int main() {
	scanf("%d %d %d %d", &n, &m, &k, &p);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			scanf("%d", &a[i][j]);
			hr[i + 1] += a[i][j];
			hc[j + 1] += a[i][j];
		}
	}

	build_heap(hr, n);
	build_heap(hc, m);

	gao();
	cout << ret << endl;

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define EPS 1e-8
#define MAXN 1005
#define MAXE 1005

typedef pair<int, int> pii;
typedef long long ll;

int n, m, k, p;
int a[MAXN][MAXN];

int hr[MAXN], hc[MAXN];

void heapify(int *a, int n, int i) {
	int l = 2 * i, r = l + 1;
	int ix = (l <= n && a[l] > a[i]) ? l : i;
	if (r <= n && a[r] > a[ix]) ix = r;
	if (ix != i) {
		swap(a[i], a[ix]);
		heapify(a, n, ix);
	}
}

void build_heap(int *a, int n) {
	for (int i = n / 2; i >= 1; --i) {
		heapify(a, n, i);
	}
}

int main() {
	scanf("%d %d %d %d", &n, &m, &k, &p);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			scanf("%d", &a[i][j]);
		}
	}

	// init heap
	for (int i = 0; i < n; ++i) {
		int sum = 0;
		for (int j = 0; j < m; ++j) {
			sum += a[i][j];
		}
		hr[i + 1] = sum;
	}
	for (int j = 0; j < m; ++j) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			sum += a[i][j];
		}
		hc[j + 1] = sum;
	}
	build_heap(hr, n);
	build_heap(hc, m);

	// gao
	int nr = 0, nc = 0;
	ll ret = 0;
	for (int i = 0; i < k; ++i) {
		if (hr[1] - nr * p > hc[1] - nc * p) {
			ret += (hr[1] - nr * p);
			nc += 1;
			hr[1] -= m * p;
			heapify(hr, n, 1);
		} else {
			ret += (hc[1] - nc * p);
			nr += 1;
			hc[1] -= n * p;
			heapify(hc, m, 1);
		}
	}
	cout << ret << endl;

	return 0;
}


#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

#define EPS 1e-8
#define MAXN 1005
#define MAXE 1005

typedef pair<int, int> pii;
typedef long long ll;

int n, m, k, p;
int a[MAXN][MAXN];

int hr[MAXN], hc[MAXN];

void heapify(int *a, int n, int i) {
	int l = 2 * i, r = l + 1;
	int ix = (l <= n && a[l] > a[i]) ? l : i;
	if (r <= n && a[r] > a[ix]) ix = r;
	if (ix != i) {
		swap(a[i], a[ix]);
		heapify(a, n, ix);
	}
}

void build_heap(int *a, int n) {
	for (int i = n / 2; i >= 1; --i) {
		heapify(a, n, i);
	}
}

int main() {
	scanf("%d %d %d %d", &n, &m, &k, &p);
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			scanf("%d", &a[i][j]);
		}
	}

	// init heap
	for (int i = 0; i < n; ++i) {
		int sum = 0;
		for (int j = 0; j < m; ++j) {
			sum += a[i][j];
		}
		hr[i + 1] = sum;
	}
	for (int j = 0; j < m; ++j) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			sum += a[i][j];
		}
		hc[j + 1] = sum;
	}
	build_heap(hr, n);
	build_heap(hc, m);

	// gao
	int nr = 0, nc = 0;
	ll ret = 0;
	while (k--) {
		if (hr[1] - nr * p > hc[1] - nc * p) {
			ret += (hr[1] - nr * p);
			nc += 1;
			hr[1] -= m * p;
			heapify(hr, n, 1);
		} else {
			ret += (hc[1] - nc * p);
			nr += 1;
			hc[1] -= n * p;
			heapify(hc, m, 1);
		}
		//printf("ret = %lld\n", ret);
	}
	//printf("nr = %d, nc = %d\n", nr, nc);
	cout << ret << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;
const int MAX = 1005;
const ll INF = 1e14 + 7;
int N, M, K, P;
int mar[MAX][MAX];
int sumr[MAX], sumc[MAX];
ll a[MAX], b[MAX];

void solve() {
        priority_queue <int> qr;
        priority_queue <int> ql;
        for (int i = 1; i <= N; ++i) {
                qr.push(sumr[i]);
        }

        for (int i = 1; i <= M; ++i) {
                ql.push(sumc[i]);
        }

        for (int i = 1; i <= K; ++i) {
                int x = qr.top(); qr.pop();
                a[i] = x + a[i - 1];
                qr.push(x - M * P);
        }

        for (int i = 1; i <= K; ++i) {
                int x = ql.top(); ql.pop();
                b[i] = x + b[i - 1];
                ql.push(x - N * P);
        }

        ll ans = -INF;
        for (int i = 0; i <= K; ++i) {
                //printf("%d %d %d\n", i, a[i], b[K - i]);
                ans = max(ans, a[i] + b[K - i] - (K - i) * (i * P));
        }

        cout << ans << endl;
}

int main()
{
    scanf("%d%d%d%d", &N, &M, &K, &P);
    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    scanf("%d", &mar[i][j]);
            }
    }

    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    sumr[i] += mar[i][j];
                    sumc[j] += mar[i][j];
            }
    }

    solve();

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

const int MAX = 1005;
const int INF = 1e9 + 7;
int N, M, K, P;
int mar[MAX][MAX];
int sumr[MAX], sumc[MAX];
int a[MAX], b[MAX];

void solve() {
        priority_queue <int> qr;
        priority_queue <int> ql;
        for (int i = 1; i <= N; ++i) {
                qr.push(sumr[i]);
        }

        for (int i = 1; i <= M; ++i) {
                ql.push(sumc[i]);
        }

        for (int i = 1; i <= K; ++i) {
                int x = qr.top(); qr.pop();
                a[i] = x + a[i - 1];
                qr.push(x - M * P);
        }

        for (int i = 1; i <= K; ++i) {
                int x = ql.top(); ql.pop();
                b[i] = x + b[i - 1];
                ql.push(x - N * P);
        }

        int ans = -INF;
        for (int i = 0; i <= K; ++i) {
                //printf("%d %d %d\n", i, a[i], b[K - i]);
                ans = max(ans, a[i] + b[K - i] - (K - i) * (i * P));
        }

        printf("%d\n", ans);
}

int main()
{
    scanf("%d%d%d%d", &N, &M, &K, &P);
    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    scanf("%d", &mar[i][j]);
            }
    }

    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    sumr[i] += mar[i][j];
                    sumc[j] += mar[i][j];
            }
    }

    solve();

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;
const int MAX = 1005;
const ll INF = 1e14 + 7;
int N, M, K, P;
int mar[MAX][MAX];
int sumr[MAX], sumc[MAX];
ll a[1000007], b[1000007];

void solve() {
        priority_queue <ll> qr;
        priority_queue <ll> ql;
        for (int i = 1; i <= N; ++i) {
                qr.push(sumr[i]);
        }

        for (int i = 1; i <= M; ++i) {
                ql.push(sumc[i]);
        }

        for (int i = 1; i <= K; ++i) {
                ll x = qr.top(); qr.pop();
                a[i] = x + a[i - 1];
                qr.push(x - M * P);
        }

        for (int i = 1; i <= K; ++i) {
                ll x = ql.top(); ql.pop();
                b[i] = x + b[i - 1];
                ql.push(x - N * P);
        }

        ll ans = min(a[K], b[K]);
        for (int i = 0; i <= K; ++i) {
                //printf("%d %d %d\n", i, a[i], b[K - i]);
                ans = max(ans, a[i] + b[K - i] - (K - i) * (i * P));
        }

        cout << ans << endl;
}

int main()
{
    scanf("%d%d%d%d", &N, &M, &K, &P);
    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    scanf("%d", &mar[i][j]);
            }
    }

    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    sumr[i] += mar[i][j];
                    sumc[j] += mar[i][j];
            }
    }

    solve();

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;
const int MAX = 1005;
const ll INF = 1e14 + 7;
int N, M, K, P;
int mar[MAX][MAX];
int sumr[MAX], sumc[MAX];
ll a[MAX], b[MAX];

void solve() {
        priority_queue <ll> qr;
        priority_queue <ll> ql;
        for (int i = 1; i <= N; ++i) {
                qr.push(sumr[i]);
        }

        for (int i = 1; i <= M; ++i) {
                ql.push(sumc[i]);
        }

        for (int i = 1; i <= K; ++i) {
                int x = qr.top(); qr.pop();
                a[i] = x + a[i - 1];
                qr.push(x - M * P);
        }

        for (int i = 1; i <= K; ++i) {
                int x = ql.top(); ql.pop();
                b[i] = x + b[i - 1];
                ql.push(x - N * P);
        }

        ll ans = -INF;
        for (int i = 0; i <= K; ++i) {
                //printf("%d %d %d\n", i, a[i], b[K - i]);
                ans = max(ans, a[i] + b[K - i] - (K - i) * (i * P));
        }

        cout << ans << endl;
}

int main()
{
    scanf("%d%d%d%d", &N, &M, &K, &P);
    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    scanf("%d", &mar[i][j]);
            }
    }

    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    sumr[i] += mar[i][j];
                    sumc[j] += mar[i][j];
            }
    }

    solve();

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;
const int MAX = 1005;
const ll INF = 1e14 + 7;
int N, M, K, P;
int mar[MAX][MAX];
int sumr[MAX], sumc[MAX];
ll a[MAX], b[MAX];

void solve() {
        priority_queue <ll> qr;
        priority_queue <ll> ql;
        for (int i = 1; i <= N; ++i) {
                qr.push(sumr[i]);
        }

        for (int i = 1; i <= M; ++i) {
                ql.push(sumc[i]);
        }

        for (int i = 1; i <= K; ++i) {
                ll x = qr.top(); qr.pop();
                a[i] = x + a[i - 1];
                qr.push(x - M * P);
        }

        for (int i = 1; i <= K; ++i) {
                ll x = ql.top(); ql.pop();
                b[i] = x + b[i - 1];
                ql.push(x - N * P);
        }

        ll ans = -INF;
        for (int i = 0; i <= K; ++i) {
                //printf("%d %d %d\n", i, a[i], b[K - i]);
                ans = max(ans, a[i] + b[K - i] - (K - i) * (i * P));
        }

        cout << ans << endl;
}

int main()
{
    scanf("%d%d%d%d", &N, &M, &K, &P);
    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    scanf("%d", &mar[i][j]);
            }
    }

    for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= M; ++j) {
                    sumr[i] += mar[i][j];
                    sumc[j] += mar[i][j];
            }
    }

    solve();

    return 0;
}


a=int(input())
if a==1:print(-1)
else:print(a,a+1,a*(a+1))


n = int(input());

print(n),
print(n+1),
print(n*(n+1));


n = int(input());

if n==1 :
    print(-1);
else :
    print(n),
    print(n+1),
    print(n*(n+1));


n=int(input(""))
if n==1:  #如果n==1，无解，输出-1
    print(-1)
else:  #反之，输出x，y，z
    print(n," ",n+1," ",n*(n+1))


n=int(input())
if n<=1:
    print(-1)
else:
    print("%d %d %d"%(n,n*(n+1),n+1))


n=int(input())
if n>1:
	print(n, n+1, n*(n+1))
else:
	print(-1)


n=int(input())
for x in range(1,100):
    for y in range(x+1,100):
        for z in range(y+1,1000):
            if (z*y+y*x+z*x)*n==2*x*y*z:
                print(x,y,z)
                exit()
print(-1)


n=int(input())
for x in range(1,1000):
    for y in range(1,1000):
        for z in range(1,1000):
            if (z*y+y*x+z*x)*n==2*x*y*z:
                print(x,y,z)
                exit()
print(-1)


n=int(input())
for x in range(1,1000):
    for y in range(x+1,1000):
        for z in range(y+1,1000):
            if (z*y+y*x+z*x)*n==2*x*y*z:
                print(x,y,z)
                exit()
print(-1)


n = int(input())
if n==1:
    print(-1)
else:
    print(n,n+1,n*(n+1))


n = int(input())
if(n==1):
    print(-1)
else:
    print(n, n+1, n*(n+1))


n = int(input())
print(n, n + 1, (n + 1) * n)


n = int(input())
if n == 1:
    print(-1)
else:
    print(n, n + 1, (n + 1) * n)


n = int(input())
if n == 1:
    print("-1")
else:
    print(*[n, n+1, n*(n+1)])


n=int(input())
if(n==1):
	print("-1")
else:
	print(n,n+1,n*(n+1))


x=int(input())
if x==1:
    print(-1)
else:
    print(x,x+1,x*(x+1))


import string
import math

n=int(input())

if n==1:
    print(-1)
    exit(0)

if n&1==0:
    print(str(n)+" "+str(n//2*3)+" "+str(n//2*6))
    exit(0)

for a in range(1,10001):
    for y in range(1,a+1):
        for z in range(1,a*n//y+1):
            x=a*n
            if ((2*a-1)*y*z==x*(y+z)):
                ans=1
                print(str(x)+" "+str(y)+" "+str(z))
                exit(0)

print(-1)


import string
import math

n=int(input())

if n&1==0:
    print(str(n)+" "+str(n//2*3)+" "+str(n//2*6))
    exit(0)

for a in range(1,10001):
    for y in range(1,a+1):
        for z in range(1,a*n//y+1):
            x=a*n
            if ((2*a-1)*y*z==x*(y+z)):
                ans=1
                print(str(x)+" "+str(y)+" "+str(z))
                exit(0)

print(-1)


import string
import math

n=int(input())

if n==1:
    print(-1)
    exit(0)

if n&1==0:
    print(str(n)+" "+str(n//2*3)+" "+str(n//2*6))
    exit(0)

print(str(n)+" "+str(n+1)+" "+str(n*n+n))


def solve(n):
    if n == 1:
        return None
    return (n, n + 1, n * (n + 1))

def test(n, x, y, z):
    import math
    assert x != y
    assert y != z
    assert x <= 10**9
    assert y <= 10**9
    assert z <= 10**9
    assert math.isclose(2/n, 1/x + 1/y + 1/z, abs_tol=1e-10)

def testAll():
    for i in range(1, 10000 + 1):
        r = solve(i)
        if i == 1:
            assert r is None
        else:
            test(i, *r)

if __name__ == '__main__':
    n = int(input())
    r = solve(n)
    if r is None:
        print(-1)
    else:
        print('{} {} {}'.format(*r))

    #testAll()


def solve(n):
    return (n, n + 1, n * (n + 1))

def test(n, x, y, z):
    import math
    assert math.isclose(2/n, 1/x + 1/y + 1/z)

if __name__ == '__main__':
    n = int(input())
    print('{} {} {}'.format(*solve(n)))

    #for i in range(1, 1000):
    #    test(i, *solve(i))


"Codeforces Round #384 (Div. 2)"
"C. Vladik and fractions"
y=int(input())
a=y
b=a+1
c=y*b
if y==1:
    print(-1)
else:
    print(a,b,c)


"Codeforces Round #384 (Div. 2)"
"C. Vladik and fractions"
y=int(input())
a=y
b=a+1
c=y*b
print(a,b,c)


n=int(input())
if n>1:
    print(n,n+1,n*(n+1))
else:
    print(-1)


def ratios(n):
    if n * (n + 1) <= 1000000000 and n != 1:
        return n, n + 1, n * (n + 1)
    return [-1]

print(*ratios(int(input())))


def yolo(n):
	denom = 0
	k = 0

	if n % 2 == 1:
		k = (n+1)/2
		denom = n*k

	if denom > 0:
		a,b,c = [int(x) for x in [k, denom+1, denom*(denom+1)]]

		if a==k and b == denom+1 and c == denom*(denom+1) and (a < 10**9 and b < 10**9 and c < 10**9)and (not duplicates([a,b,c])):
			print(str(a) + " " + str(b) + " " + str(c))
			return

	k = n
	denom = n
	a,b,c = [int(x) for x in [k, denom+1, denom*(denom+1)]]
	if a==k and b == denom+1 and c == denom*(denom+1) and (a < 10**9 and b < 10**9 and c < 10**9) and (not duplicates([a,b,c])):
		print(str(a) + " " + str(b) + " " + str(c))
		return

	print(-1)

def duplicates(arr):
	for i in range(len(arr)):
		for x in range(i+1, len(arr)):
			if arr[i] == arr[x]:
				return True
	return False

yolo(int(input()))


def yolo(n):
	denom = 0
	k = 0

	if n % 2 == 1:
		k = (n+1)/2
		denom = n*k

	if denom > 0:
		a,b,c = [int(x) for x in [k, denom+1, denom*(denom+1)]]

		if a==k and b == denom+1 and c == denom*(denom+1) and (a < 10**9 and b < 10**9 and c < 10**9):
			print(str(a) + " " + str(b) + " " + str(c))
			return

	k = n
	denom = n
	a,b,c = [int(x) for x in [k, denom+1, denom*(denom+1)]]
	if a==k and b == denom+1 and c == denom*(denom+1) and (a < 10**9 and b < 10**9 and c < 10**9):
		print(str(a) + " " + str(b) + " " + str(c))
		return

	print(-1)

yolo(int(input()))


from collections import Counter,defaultdict,deque
#import heapq as hq
#from itertools import count, islice
#from functools import reduce
alph = 'abcdefghijklmnopqrstuvwxyz'
#from math import factorial as fact
#a,b = [int(x) for x in input().split()]
import math
import sys

input=sys.stdin.readline
n = int(input())
if n==1:
    print(-1)
    exit()
x = n+1
y = x*n
print(n,x,y)


n=int(input())
if n == 1: print( -1 )
else: print(n, n + 1,n * (n + 1))


n = int(input())
if n == 1:
    print(-1)
else:
    print(n, n+1, n*(n+1))


n = int(input())

if n == 1:
    print(-1)
else:
    print(n, n + 1, n * (n + 1))


n = int(input())

print(n, n + 1, n * (n + 1))


import math

n = int(input())

x = math.ceil(n/2)
rest_num, rest_den = -n % 2, n * math.ceil(n/2)
#print(x, rest_num, rest_den)
if rest_num:
    x, y, z = n, n + 1, n * (n + 1)
else:
    x, y, z = n, n + 1, n * (n + 1)
print(x, y, z)


n = int(input())
x, y, z = n, n + 1, n * (n + 1)
if n != 1:
    print(x, y, z)
else:
    print(-1)


n=int(input())
if n==1:
    print (-1)
else:
    print (n,n+1,n*(n+1))


n = int(input())
if n==1:
    print("-1")
else:
    print(n,n+1,n*(n+1))


n=int(input())
z=n
y=n+1
x=n*(n+1)
print(x,y,z)


n=int(input())
z=n
y=n+1
x=n*(n+1)
if(n==1):
    print(0)
else:
    print(x,y,z)


n=int(input())
z=n
y=n+1
x=n*(n+1)
if(n==1):
    print(-1)
else:
    print(x,y,z)


n = int(input())
if n==1:
    print(-1)
else:
    s = str(n) + ' ' + str(n+1) + ' ' + str(n*(n+1))
    print(s)


n = int(input())
if n==1:
    print(-1)
else:
    s = str(n) + ' ' + str(n+1) + ' ' + str(n*n+1)
    print(s)


n = int(input())
if n == 1:
    print("-1")
else:
    print(n, n+1, n*(n+1))


n = int(input())
if n == 1:
    exit(print(-1))
print(n, n + 1, n * (n + 1))


a = input()
if (a==1)
    print("-1\n")
else
    print(n,n+1,n*(n+1))


n = int(input())
if (n==1):
    print("-1\n")
else:
    print(n,n+1,n*(n+1))


n = int(input())
if (n==1)
    print("-1\n")
else
    print(n,n+1,n*(n+1))


n=int(input())
if n==1:
    print(-1)
else:
    print(n,n+1,n*(n+1))


#EGYPTIAN FRACTION
n=int(input())
if(n==1):
	print("-1")
else:
	print(n,n+1,n*(n+1))


n = int(input())
if n==1:
	print(-1)
else:
	print(n,n+1,n*(n+1))


n=int(input())
if n==1:
    print(-1)
else:
    print(n,n+1,n*n+n)


from math import ceil, floor

MAXINT = 10 ** 9 + 1

if __name__ == '__main__':
	n, = map(int, input().split())
	print(n, n+1, n*(n+1))


from math import ceil, floor

MAXINT = 10 ** 9 + 1

if __name__ == '__main__':
	n, = map(int, input().split())
	calc = False
	res = -1,
	for x in range(ceil(n / 2), (3*n+1) // 2):
		a, b = 2*x - n, n * x
		for y in range(ceil((b+1) / a), ceil((2*b) / a)):
			z, r = divmod(b*y, a*y-b)
			if r == 0 and x < y and y < z:
				calc = True
				res = x, y, z
				break
		if calc:
			break
	print(' '.join(map(str, res)))


from math import ceil, floor

MAXINT = 10 ** 9 + 1

if __name__ == '__main__':
	n, = map(int, input().split())
	calc = False
	res = -1,
	for x in range(ceil((n+1) / 2), (3*n+1) // 2):
		if calc:
			break
		a, b = 2*x - n, n * x
		for y in range(ceil((b+1) / a), min(MAXINT, ceil((2*b) / a)):
			z, r = divmod(b*y, a*y-b)
			if r == 0 and x < y and y < z and z < MAXINT and (2*x*y*z == n*(x*y+y*z+z*x)):
				calc = True
				res = x, y, z
				break
	print(' '.join(map(str, res)))


from math import ceil, floor

MAXINT = 10 ** 9 + 1

if __name__ == '__main__':
	n, = map(int, input().split())
	calc = False
	res = -1,
	for x in range(ceil((n+1) / 2), (3*n+1) // 2):
		if calc:
			break
		a, b = 2*x - n, n * x
		for y in range(ceil((b+1) / a), min(MAXINT, ceil((2*b) / a))):
			z, r = divmod(b*y, a*y-b)
			if r == 0 and x < y and y < z and z < MAXINT and (2*x*y*z == n*(x*y+y*z+z*x)):
				calc = True
				res = x, y, z
				break
	print(' '.join(map(str, res)))


from math import ceil, floor

MAXINT = 10 ** 9 + 1

if __name__ == '__main__':
	n, = map(int, input().split())
	calc = False
	res = -1,
	for x in range(ceil((n+1) / 2), (3*n+1) // 2):
		if calc:
			break
		a, b = 2*x - n, n * x
		for y in range(ceil((b+1) / a), ceil((2*b) / a)):
			z, r = divmod(b*y, a*y-b)
			if r == 0 and x < y and y < z:
				calc = True
				res = x, y, z
				break
	print(' '.join(map(str, res)))


from math import ceil, floor

MAXINT = 10 ** 9 + 1

if __name__ == '__main__':
	n, = map(int, input().split())
	if n == 1:
		print(-1)
	else:
		print(n, n+1, n*(n+1))


import math
n=int(input())
if n==1:
    print(-1)
if n!=1:
    print(f'{n} {n+1} {n*(n+1)}')


import math
n=int(input())
print(f'{n} {n+1} {n*(n+1)}')


#http://codeforces.com/problemset/problem/743/C
#solved

n = int(input())
wrong = [1,2]

if n in wrong:
    print("-1")
    exit()

else:
    b = n + 1
    c = b * n

    if max(n, b, c) >= 10**9:
        print("-1")

    else:
        print(n, b, c)


#http://codeforces.com/problemset/problem/743/C
#solved

n = int(input())

if n == 1:
    print("-1")
    exit()

else:
    b = n + 1
    c = b * n

    if max(n, b, c) >= 10**9:
        print("-1")

    else:
        print(n, b, c)


a=int(input())
if(a==1):
    print("-1")
else:
    print(a,a+1,a*(a+1),sep=' ')


n = int(input())

print(n, n+1, n*(n+1))


n = int(input())

if n == 1:
    print(-1)
else:
    print(n, n+1, n*(n+1))


n = (int) (input ());
if (n == 1) print (-1);
else print (n, n + 1, n * (n + 1));


n = (int) (input ())
if n == 1: print (-1)
else: print (n, n + 1, n * (n + 1))


n = int(input())
if n == 1:
    print(-1)
else:
    print(n*(n+1), n, n+1)


n = int(input())
if n*(n+1) <= 10**9:
    if n == 1:
        print(-1)
    else:
        print(n, n+1, n*(n+1))
else:
    print(-1)


n=int(input())
if n==1:
    print("-1")
else:
    print(n,(n+1),n*(n+1),end=" ")


n=int(input())

if(n==1):print(-1)

else:print(n,n+1,n*(n+1))

# Made By Mostafa_Khaled


n=int(input())
if (n>1):
    print(n,n+1,n*(n+1))
else:
    print("-1")


n = int(input())
if n == 1:
    print(-1)
else:
    print(n, n + 1, n * (n + 1))


n = int(input())
print(n, n + 1, n * (n + 1))


n = int(input())

print(n, n+1, n*(n+1) if n > 1 else -1)


n = int(input())

if n > 1:
    print(n, n+1, n*(n+1))
else:
    print(1)


n = int(input())

if n > 1:
    print(n, n+1, n*(n+1))
else:
    print(-1)


n = int(input())

if n == 1:
    print (-1)
else:
    print(n, n + 1, n * (n + 1))


n = int(input())
if n < 1:
    print(-1)
else:
    print(n, n + 1, n * (n + 1)


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char matrix[501][501];
    int r,c;
    cin >> r >> c;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cin >> matrix[i][j];
        }
    }
    for(int i=0;i<r;i++)
    {

        for(int j=0;j<c-1;j++)
        {
            if(matrix[i][j]=='S' && matrix[i][j+1]=='W' ||  matrix[i][j]=='W' && matrix[i][j+1]=='S')
            {
                cout<<"No";
                return 0;

            }
        }

    }
    cout<<"Yes"<<endl;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(matrix[i][j]=='.')
            {
                matrix[i][j]='D';
            }
        }
    }
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cout<<matrix[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char matrix[501][501];
    int r,c;
    cin >> r >> c;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cin >> matrix[i][j];
        }
    }
    for(int i=0;i<r;i++)
    {

        for(int j=0;j<c-1;j++)
        {
            if(matrix[i][j]=='S' && matrix[i][j+1]=='W' ||  matrix[i][j]=='W' && matrix[i][j+1]=='S' ||
            (matrix[i][j-1]=='.' && matrix[i][j]=='W' && matrix[i][j+1]=='.'))
            {
                cout<<"No";
                return 0;

            }
        }

    }
    cout<<"Yes"<<endl;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(matrix[i][j]=='.')
            {
                matrix[i][j]='D';
            }
        }
    }
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cout<<matrix[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char matrix[501][501];
    int r,c;
    cin >> r >> c;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cin >> matrix[i][j];
        }
    }
    for(int i=0;i<r;i++)
    {

        for(int j=0;j<c-1;j++)
        {
            if(matrix[i][j]=='S' && matrix[i][j+1]=='W' ||  matrix[i][j]=='W' && matrix[i][j+1]=='S')
            {
                cout<<"No";
                return 0;

            }
        }

    }
    cout<<"Yes"<<endl;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(matrix[i][j]=='S' && matrix[i][j+1]=='.')
            {
                matrix[i][j+1]='D';
            }
            if(matrix[i][j]=='W' && matrix[i][j-1]=='.')
            {
                matrix[i][j-1]='D';
            }
        }
    }
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cout<<matrix[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char matrix[501][501];
    int r,c;
    cin >> r >> c;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cin >> matrix[i][j];
        }
    }
    for(int i=0;i<r;i++)
    {

        for(int j=0;j<c-1;j++)
        {
            if(matrix[i][j]=='S' && matrix[i][j+1]=='W' ||  matrix[i][j]=='W' && matrix[i][j+1]=='S' ||
            (matrix[i][j-1]=='.' && matrix[i][j]=='W' && matrix[i][j+1]=='.' && j>0))
            {
                cout<<"No";
                return 0;

            }
        }

    }
    cout<<"Yes"<<endl;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(matrix[i][j]=='.')
            {
                matrix[i][j]='D';
            }
        }
    }
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cout<<matrix[i][j];
        }
        cout<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    char matrix[501][501];
    int r,c;
    cin >> r >> c;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cin >> matrix[i][j];
        }
    }
    for(int i=0;i<r;i++)
    {

        for(int j=0;j<c-1;j++)
        {
            if(matrix[i][j]=='S' && matrix[i][j+1]=='W' ||  matrix[i][j]=='W' && matrix[i][j+1]=='S')
            {
                cout<<"No";
                return 0;

            }
        }

    }
    cout<<"Yes"<<endl;
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            if(matrix[i][j]=='S' && matrix[i][j+1]=='.')
            {
                matrix[i][j+1]='D';
            }
            if(matrix[i][j]=='W' && matrix[i][j-1]=='.')
            {
                matrix[i][j-1]='D';
            }
        }
    }
    for(int i=0;i<r;i++)
    {
        for(int j=0;j<c;j++)
        {
            cout<<matrix[i][j]<<" ";
        }
        cout<<endl;
    }

    return 0;
}


#include <cstdio>
#include <cstring>
using namespace std;

const int maxn = 510;
bool flag;
int n,m;
char a[maxn][maxn];
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};
int x,y;

bool judge(int r, int c) {
   for (int i=0; i<4; i++) {
      x = dx[i] + r;
      y = dy[i] + c;
      if (x<1 || x>n || y<1 || y>m) continue;
      if (a[x][y]=='W') return 0;
   }
   return 1;
}

int main(){
    scanf("%d%d",&n,&m);
    for (int i=1; i<=n; i++) scanf("%s",a[i]+1);
    flag = 1;
    for (int i=1; i<=n; i++) {
       for (int j=1; j<=m; j++) if (a[i][j] == 'S') {
           if (!judge(i,j)) {flag = 0; break; }
       }
       if (!flag) break;
    }

    if (!flag) printf("No\n");
    else {
        printf("Yes\n");
        for (int i=1; i<=n; i++) {
            for (int j=1; j<=m; j++) if (a[i][j]=='.') printf("D"); else printf("%c",a[i][j]);
            printf("\n");
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
// #define mp          make_pair
#define MAX 200005
#define CHAR_SIZE 26
using namespace std;

#define N  1500001

void solve(ll cno)
{
	ll n,i,j,k,l,r,m,q,h;
	cin>>n>>m;
	string arr[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			{if(arr[i][j]=='.')
					arr[i][j]='D';}

	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(arr[i][j]=='S')
				{
					if((i>0 && arr[i-1][j]=='W') || (j>0 && arr[i][j-1]=='W') || (j<m-1 && arr[i][j+1]=='W') || (i<n-1 && arr[1+1][j]=='W'))
					{
						cout<<"No";
						return;
					}
				}
		}
	}
	cout<<"Yes"<<endl;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		cout<<arr[i][j];
		cout<<endl;
	}

}
// cout<<mn<<endl;
/*

*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	ll i=1;
	while(TESTS--)
	{
		solve(i);
		i++;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
// #define mp          make_pair
#define MAX 200005
#define CHAR_SIZE 26
using namespace std;

#define N  1500001

void solve(ll cno)
{
	ll n,i,j,k,l,r,m,q,h;
	cin>>n>>m;
	string arr[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{if(arr[i][j]=='.')
					arr[i][j]='D';
				if(arr[i][j]=='S')
				{
					if((i>0 && arr[i-1][j]=='W') || (j>0 && arr[i][j-1]=='W') || (j<m-1 && arr[i][j+1]=='W') || (i<n-1 && arr[1+1][j]=='W'))
					{
						cout<<"No";
						return;
					}
				}}
	}
	cout<<"Yes"<<endl;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		cout<<arr[i][j];
		cout<<endl;
	}

}
// cout<<mn<<endl;
/*

*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	ll i=1;
	while(TESTS--)
	{
		solve(i);
		i++;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define _USE_MATH_DEFINES
// #define mp         make_pair
#define MAX 200005
#define CHAR_SIZE 26
#define N 1000001
using namespace std;
ll n,m;
string arr[501];
ll check(ll i,ll j)
{
	if(i>0 && arr[i-1][j]=='S')
		return -1;
	if(j>0 && arr[i][j-1]=='S')
		return -1;
	if(i<n-1 && arr[i+1][j]=='S')
		return -1;
	if(j<m-1 && arr[i][j+1]=='S')
		return -1;
	return 1;
}

void solve(int cno)
{

	ll i,j,k,l;
	cin>>n>>m;

	for(i=0;i<n;i++)
		cin>>arr[i];
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(arr[i][j]=='.')
				arr[i][j]='D';
			if(arr[i][j]=='W')
			{
				ll temp=check(i,j);
				if(temp==-1)
				{
					cout<<"No"<<endl;
					return;
				}
			}
		}
	}

	cout<<"Yes"<<endl;
	for(i=0;i<n;i++)
		cout<<arr[i]<<endl;

}
// cout<<mn<<endl;
/*

*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int TESTS=1;
	// cin>>TESTS;
	ll  i=1;
	while(TESTS--)
	{
		solve(i);
		i++;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
// #define mp          make_pair
#define MAX 200005
#define CHAR_SIZE 26
using namespace std;

#define N  1500001

void solve(ll cno)
{
	ll n,i,j,k,l,r,m,q,h;
	cin>>n>>m;
	string arr[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			{if(arr[i][j]=='.')
					arr[i][j]='D';}

	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(arr[i][j]=='W')
				{
					if((i>0 && arr[i-1][j]=='S') || (j>0 && arr[i][j-1]=='S') || (j<m-1 && arr[i][j+1]=='S') || (i<n-1 && arr[1+1][j]=='S'))
					{
						cout<<"No";
						return;
					}
				}
		}
	}
	cout<<"Yes"<<endl;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		cout<<arr[i][j];
		cout<<endl;
	}

}
// cout<<mn<<endl;
/*

*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	ll i=1;
	while(TESTS--)
	{
		solve(i);
		i++;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000000000000000
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
// #define mp          make_pair
#define MAX 200005
#define CHAR_SIZE 26
using namespace std;

#define N  1500001

void solve(ll cno)
{
	ll n,i,j,k,l,r,m,q,h;
	cin>>n>>m;
	string arr[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
			{if(arr[i][j]=='.')
					arr[i][j]='D';}

	}
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(arr[i][j]=='W')
				{
					if((i>0 && arr[i-1][j]=='D') || (j>0 && arr[i][j-1]=='D') || (j<m-1 && arr[i][j+1]=='D') || (i<n-1 && arr[1+1][j]=='D') || (i>0 && arr[i-1][j]=='W') || (j>0 && arr[i][j-1]=='W') || (j<m-1 && arr[i][j+1]=='W') || (i<n-1 && arr[1+1][j]=='W'))
					{
						continue;
					}
					else
					{
						// cout<<i<<" "<<j<<endl;
						// cout<<arr[i-1][j]<<" "<<arr[i+1][j]<<" "<<arr[i][j+1]<<" "<<arr[i][j-1]<<endl;
						cout<<"No";
						return;
					}
				}
		}
	}
	cout<<"Yes"<<endl;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		cout<<arr[i][j];
		cout<<endl;
	}

}
// cout<<mn<<endl;
/*

*/

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	ll i=1;
	while(TESTS--)
	{
		solve(i);
		i++;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r, c;
    char buf;
    bool flag = true;
    cin >> r >> c;
    int a[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> buf;
            if(buf == 'S')
                a[i][j] = 1;
            else if(buf == 'W')
                a[i][j] = 2;
            else
                a[i][j] = 0;
        }
    }

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 1){
                if(a[abs(i-1)][j] == 2 || a[i+1][j] == 2 || a[i][abs(j-1)] == 2 || a[i][j+1] == 2){
                    flag = false;
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << '\n';
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 0)
                cout << 'D';
            else if(a[i][j] == 1)
                cout << 'S';
            else if(a[i][j] == 2)
                cout << 'W';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r, c;
    char buf;
    bool flag = true;
    cin >> r >> c;
    int a[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> buf;
            if(buf == 'S')
                a[i][j] = 1;
            else if(buf == 'W')
                a[i][j] = 2;
            else
                a[i][j] = 0;
        }
    }

    for(int i = 0; i < r - 1; i++){
        for(int j = 0; j < c - 1; j++){
            if(a[i][j] == 1){
                if(a[abs(i-1)][j] == 2 || a[i+1][j] == 2 || a[i][abs(j-1)] == 2 || a[i][j+1] == 2){
                    flag = false;
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << '\n';
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 0)
                cout << 'D';
            else if(a[i][j] == 1)
                cout << 'S';
            else if(a[i][j] == 2)
                cout << 'W';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r, c;
    char buf;
    bool flag = true;
    cin >> r >> c;
    int a[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> buf;
            if(buf == 'S')
                a[i][j] = 1;
            else if(buf == 'W')
                a[i][j] = 2;
            else
                a[i][j] = 0;
        }
    }

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 1){
                if(a[abs(i-1)][j] == 2 || a[(i+1)%r][j] == 2 || a[i][abs(j-1)] == 2 || a[i][(j+1)%c] == 2){
                    flag = false;
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << '\n';
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 0)
                cout << 'D';
            else if(a[i][j] == 1)
                cout << 'S';
            else if(a[i][j] == 2)
                cout << 'W';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r, c;
    char buf;
    bool flag = true;
    cin >> r >> c;
    int a[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> buf;
            if(buf == 'S')
                a[i][j] = 1;
            else if(buf == 'W')
                a[i][j] = 2;
            else
                a[i][j] = 0;
        }
    }

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 1){
                if(a[i-1][j] == 2 || a[i+1][j] == 2 || a[i][j-1] == 2 || a[i][j+1] == 2){
                    flag = false;
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << '\n';
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 0)
                cout << 'D';
            else if(a[i][j] == 1)
                cout << 'S';
            else if(a[i][j] == 2)
                cout << 'W';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r, c;
    char buf;
    bool flag = true;
    cin >> r >> c;
    int a[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> buf;
            if(buf == 'S')
                a[i][j] = 1;
            else if(buf == 'W')
                a[i][j] = 2;
            else
                a[i][j] = 0;
        }
    }

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 1){
                if(i == r - 1)
                    if(j == c - 1)
                        continue;
                    else{
                        if(a[i][j+1] == 2){
                            flag = false;
                            cout << "No";
                            return 0;
                        }
                    }
                if(j == c - 1){
                    if(a[i + 1][j] == 2){
                            flag = false;
                            cout << "No";
                            return 0;
                        }
                }
                if(a[abs(i-1)][j] == 2 || a[i][abs(j-1)] == 2){
                    flag = false;
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << '\n';
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 0)
                cout << 'D';
            else if(a[i][j] == 1)
                cout << 'S';
            else if(a[i][j] == 2)
                cout << 'W';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r, c;
    char buf;
    bool flag = true;
    cin >> r >> c;
    int a[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> buf;
            if(buf == 'S')
                a[i][j] = 1;
            else if(buf == 'W')
                a[i][j] = 2;
            else
                a[i][j] = 0;
        }
    }

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 1){
                if(i == r - 1 && j == c - 1)
                        continue;
                else{
                    if(j == c - 1){
                        if(a[i + 1][j] == 2){
                            flag = false;
                            cout << "No";
                            return 0;
                        }
                    }
                    else if(i == r -1){
                        if(a[i][j + 1] == 2){
                            flag = false;
                            cout << "No";
                            return 0;
                        }
                    }
                }
                if(a[abs(i-1)][j] == 2 || a[i][abs(j-1)] == 2){
                    flag = false;
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << '\n';
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 0)
                cout << 'D';
            else if(a[i][j] == 1)
                cout << 'S';
            else if(a[i][j] == 2)
                cout << 'W';
        }
        cout << '\n';
    }
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r, c;
    char buf;
    bool flag = true;
    cin >> r >> c;
    int a[r][c];
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> buf;
            if(buf == 'S')
                a[i][j] = 1;
            else if(buf == 'W')
                a[i][j] = 2;
            else
                a[i][j] = 0;
        }
    }

    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            if(a[i][j] == 1){
                if(a[i-1][j] == 2 || a[i+1][j] == 2 || a[i][j-1] == 2 || a[i][j+1] == 2)
                    flag = false;
            }
        }
    }
    if(flag == false)
        cout << "No";
    else{
        cout << "Yes" << '\n';
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                if(a[i][j] == 0)
                    cout << 'D';
                else if(a[i][j] == 1)
                    cout << 'S';
                else if(a[i][j] == 2)
                    cout << 'W';
            }
            cout << '\n';
        }
    }

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define mod 1000000007
#define pb push_back
#define pop pop_back
#define mp make_pair
#define ALL(v)  v.begin(), v.end()

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r, c;
    char mat[500][500] = {0};
    cin >> r >> c;
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            if(mat[i][j] == 'W') {
                if(mat[(i==0)?i:(i-1)][j] != 'S' && mat[(i==r-1)?i:(i+1)][j] != 'S' && mat[i][(j==0)?j:(j-1)] != 'S' && mat[i][(j==c-1)?j:(j+1)] != 'S') {
                    mat[(i==0)?i:(i-1)][j] = 'D';
                    mat[(i==r-1)?i:(i+1)][j] = 'D';
                    mat[i][(j==0)?j:(j-1)] = 'D';
                    mat[i][(j==c-1)?j:(j+1)] = 'D';
                }
                else {
                    cout << "NO";
                    return 0;
                }
            }
        }
    }
    cout << "YES\n";
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++){
            cout << mat[i][j] << " ";
        }
        cout << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define mod 1000000007
#define pb push_back
#define pop pop_back
#define mp make_pair
#define ALL(v)  v.begin(), v.end()

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r, c;
    char mat[500][500];
    cin >> r >> c;
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            if(mat[i][j] == 'W') {
                if(mat[(i==0)?i:(i-1)][j] == 'S' && mat[(i==r-1)?i:(i+1)][j] == 'S' && mat[i][(j==0)?j:(j-1)] == 'S' && mat[i][(j==c-1)?j:(j+1)] == 'S') {
                    cout << "NO";
                    break;
                }
            }
        }
    }
    cout << "YES\n";
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++){
            if(mat[i][j] == '.')
                cout << 'D';
            else
                cout << mat[i][j];
        }
        cout << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define mod 1000000007
#define pb push_back
#define pop pop_back
#define mp make_pair
#define ALL(v)  v.begin(), v.end()

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r, c;
    char mat[500][500];
    cin >> r >> c;
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            if(mat[i][j] == 'W') {
                if(mat[(i==0)?i:(i-1)][j] != 'S' && mat[(i==r-1)?i:(i+1)][j] != 'S' && mat[i][(j==0)?j:(j-1)] != 'S' && mat[i][(j==c-1)?j:(j+1)] != 'S') {
                    if(i != 0 && mat[i-1][j] == '.')  mat[i-1][j] = 'D';
                    if(i != r-1 && mat[i+1][j] == '.')    mat[i+1][j] = 'D';
                    if(j != 0 && mat[i][j-1] == '.')  mat[i][j-1] = 'D';
                    if(j != c-1 && mat[i][j+1] == '.')    mat[i][j+1] = 'D';
                }
                else {
                    cout << "NO";
                    return 0;
                }
            }
        }
    }
    cout << "YES\n";
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++){
            cout << mat[i][j];
        }
        cout << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define mod 1000000007
#define pb push_back
#define pop pop_back
#define mp make_pair
#define ALL(v)  v.begin(), v.end()

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r, c;
    char mat[500][500] = {0};
    cin >> r >> c;
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            if(mat[i][j] == 'W') {
                if(mat[(i==0)?i:(i-1)][j] != 'S' && mat[(i==r-1)?i:(i+1)][j] != 'S' && mat[i][(j==0)?j:(j-1)] != 'S' && mat[i][(j==c-1)?j:(j+1)] != 'S') {
                    if(i != 0)  mat[i-1][j] = 'D';
                    if(i != r-1)    mat[i+1][j] = 'D';
                    if(j != 0)  mat[i][j-1] = 'D';
                    if(j != c-1)    mat[i][j+1] = 'D';
                }
                else {
                    cout << "NO";
                    return 0;
                }
            }
        }
    }
    cout << "YES\n";
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++){
            cout << mat[i][j];
        }
        cout << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define mod 1000000007
#define pb push_back
#define pop pop_back
#define mp make_pair
#define ALL(v)  v.begin(), v.end()

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r, c;
    char mat[500][500];
    cin >> r >> c;
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            if(mat[i][j] == 'W') {
                if(mat[(i==0)?i:(i-1)][j] == 'S' || mat[(i==r-1)?i:(i+1)][j] == 'S' || mat[i][(j==0)?j:(j-1)] == 'S' || mat[i][(j==c-1)?j:(j+1)] == 'S') {
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes\n";
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++){
            if(mat[i][j] == '.')
                cout << 'D';
            else
                cout << mat[i][j];
        }
        cout << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define mod 1000000007
#define pb push_back
#define pop pop_back
#define mp make_pair
#define ALL(v)  v.begin(), v.end()

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r, c;
    char mat[500][500] = {0};
    cin >> r >> c;
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            cin >> mat[i][j];
        }
    }
    for(int i = 0; i < r; i++) {
        for(int j = 0; j < c; j++) {
            if(mat[i][j] == 'W') {
                if(mat[(i==0)?i:(i-1)][j] != 'S' && mat[(i==r-1)?i:(i+1)][j] != 'S' && mat[i][(j==0)?j:(j-1)] != 'S' && mat[i][(j==c-1)?j:(j+1)] != 'S') {
                    mat[(i==0)?i:(i-1)][j] = 'D';
                    mat[(i==r-1)?i:(i+1)][j] = 'D';
                    mat[i][(j==0)?j:(j-1)] = 'D';
                    mat[i][(j==c-1)?j:(j+1)] = 'D';
                }
                else {
                    cout << "NO";
                    return 0;
                }
            }
        }
    }
    cout << "YES\n";
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++){
            cout << mat[i][j];
        }
        cout << "\n";
    }

    return 0;
}


/*
	Description : Graph sheep , wolf and dog
	Date :	13-10-19 11:58
*/

#include<bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
#define INF (1<<29)
#define LINF (1ll<<60)

typedef long long int lli;
using namespace std;

void desperate_optimization(bool submitting=true,int precision=10)
{
  if(!submitting) return;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}

int main()
{
    desperate_optimization(false);
	int n,i,j,count=0,temp,flag1=0,flag2=0;

	int m;
	cin>>n>>m;

	char grid[505][505];

	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			cin>>grid[i][j];

	for(i=0;i<=n;i++)
		for(j=0;j<=m;j++)
		{
			if(grid[i][j]=='S')
			{
				if(grid[i-1][j]=='W'||grid[i+1][j]=='W' ||grid[i][j+1]=='W' ||grid[i][j-1]=='W')
				{
					flag1=1;
					break;
				}
			}
		}

	if(flag1)
		return cout<<"NO",0;

	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			if(grid[i][j]=='.')
				grid[i][j]='D';

	cout<<"YES\n";

	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			cout<<grid[i][j];
		}
		cout<<"\n";
	}

	int do_not_hack;

	return 0;
}


/*
	Description : Graph sheep , wolf and dog
	Date :	13-10-19 11:58
*/

#include<bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
#define INF (1<<29)
#define LINF (1ll<<60)

typedef long long int lli;
using namespace std;

void desperate_optimization(bool submitting=true,int precision=10)
{
  if(!submitting) return;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}

int main()
{
    desperate_optimization(false);
	int n,i,j,count=0,temp,flag1=0,flag2=0;

	int m;
	cin>>n>>m;

	char grid[505][505];

	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
			cin>>grid[i][j];

	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
		{
			if(grid[i][j]=='S')
			{
				if(grid[i-1][j]=='W'||grid[i+1][j]=='W' ||grid[i][j+1]=='W' ||grid[i][j-1]=='W')
				{
					flag1=1;
					break;
				}
			}
		}

	if(flag1)
		return cout<<"NO",0;

	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			if(grid[i][j]=='.')
				grid[i][j]='D';

	cout<<"YES\n";

	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			cout<<grid[i][j];
		}
		cout<<"\n";
	}

	int do_not_hack;

	return 0;
}


/*
	Description : Graph sheep , wolf and dog
	Date :	13-10-19 11:58
*/

#include<bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
#define INF (1<<29)
#define LINF (1ll<<60)

typedef long long int lli;
using namespace std;

void desperate_optimization(bool submitting=true,int precision=10)
{
  if(!submitting) return;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}

int main()
{
    desperate_optimization(false);
	int n,i,j,count=0,temp,flag1=0,flag2=0;

	int m;
	cin>>n>>m;

	char grid[505][505];

	for(i=1;i<n;i++)
		for(j=1;j<m;j++)
			cin>>grid[i][j];

	for(i=1;i<=n;i++)
		for(j=1;j<=m;j++)
		{
			if(grid[i][j]=='S')
			{
				if(grid[i-1][j]=='W'||grid[i+1][j]=='W' ||grid[i][j+1]=='W' ||grid[i][j-1]=='W')
				{
					flag1=1;
					break;
				}
			}
		}

	if(flag1)
		return cout<<"NO",0;

	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			if(grid[i][j]=='.')
				grid[i][j]='D';

	cout<<"YES\n";

	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			cout<<grid[i][j];
		}
		cout<<"\n";
	}

	int do_not_hack;

	return 0;
}


/*
	Description : Graph sheep , wolf and dog
	Date :	13-10-19 11:58
*/

#include<bits/stdc++.h>

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

typedef long long ll;
#define INF (1<<29)
#define LINF (1ll<<60)

typedef long long int lli;
using namespace std;

void desperate_optimization(bool submitting=true,int precision=10)
{
  if(!submitting) return;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}

int main()
{
    desperate_optimization(false);
	int n,i,j,count=0,temp,flag1=0,flag2=0;

	int m;
	cin>>n>>m;

	char grid[505][505];

	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			cin>>grid[i][j];

	for(i=0;i<=n;i++)
		for(j=0;j<=m;j++)
		{
			if(grid[i][j]=='S')
			{
				if(grid[i-1][j]=='W'||grid[i+1][j]=='W' ||grid[i][j+1]=='W' )
				{
					flag1=1;
					break;
				}
			}
		}

	if(flag1)
		return cout<<"NO",0;

	for(i=0;i<n;i++)
		for(j=0;j<m;j++)
			if(grid[i][j]=='.')
				grid[i][j]='D';

	cout<<"YES\n";

	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			cout<<grid[i][j];
		}
		cout<<"\n";
	}

	int do_not_hack;

	return 0;
}