#include<iostream>
#include<algorithm>
using namespace std;
int N;
long M,V,P;
long A[1<<17];
long po[1<<17];
main()
{
	cin>>N>>M>>V>>P;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	int Li=-1,Ri=N-1;
	long okv=A[N-P];
	while(Ri>=0&&A[Ri]>=okv)Ri--;
	Ri++;
	while(Ri-Li>1)
	{
		int Mi=(Li+Ri)/2;
		long dist=A[Mi]+M;
		long ret=M*(V-1);
		int okid=Mi;
		for(int i=0;i<N;i++)
		{
			if(i==Mi)po[i]=-1;
			else
			{
				if(A[i]<=dist)
				{
					po[i]=min(dist-A[i],M);
					okid=i;
				}
				else po[i]=0;
				ret-=po[i];
			}
		}
		if(N-okid-1>=P)
		{
			Li=Mi;
			continue;
		}
		if(ret<=0)
		{
			Ri=Mi;
			continue;
		}
		int id=N-1;
		for(int i=0;i<P-1;i++)
		{
			if(id==Mi)id--;
			if(id<0)break;
			ret-=M-po[id];
			id--;
		}
		if(ret<=0)
		{
			Ri=Mi;
		}
		else Li=Mi;
	}
	cout<<N-Ri<<endl;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') {x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar();}
	return x * f;
}
const int N  = 5100;
int n,tot; ll a[N][N];
int vis[N * 20],pri[N];
void init()
{
	vis[1] = 1;
	for(int i = 2;i <= 10000;i ++)
	{
		if(!vis[i]) pri[++ tot] = i;
		for(int j = 1;j <= tot && pri[j] * i <= 10000;j ++)
		{
			vis[i * pri[j]] = 1;
			if(i % pri[j] == 0) break;
		}
	}
}
ll gcd(ll x,ll y){return y ? gcd(y,x % y) : x;}
ll lcm(ll x,ll y){if(!x || !y) return x | y; return x / gcd(x,y) * y;}
int main()
{
	n = read(); init();
	if(n == 2) {puts("4 7\n23 10"); return 0;}
	for(int i = 1;i <= n;i ++) 
		for(int j = (i + 1 & 1) + 1;j <= n;j += 2) 
			a[i][j] = pri[(i + j) / 2] * pri[n + (i - j) / 2 + (n + 1) / 2];
	for(int i = 1;i <= n;i ++) 
		for(int j = (i & 1) + 1;j <= n;j += 2) 
			a[i][j] = lcm(lcm(a[i - 1][j],a[i][j - 1]),lcm(a[i][j + 1],a[i + 1][j])) + 1; 
	
	for(int i = 1;i <= n;i ++,cout << "\n") for(int j = 1;j <= n;j ++) cout << a[i][j] << " ";
	return 0;
}
