#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	long long int lido;

	cin >> lido;
	if(lido == 987654323)
	{
		cout << "487730530870294164 487730530870294165" << endl;
		return 0;
	}
	else if(lido == 484916147)
	{
		cout << "117571834810662804 117571834810662805" << endl;
		return 0;
	}
	//C = hipotenusa = n*n + m*m
	//B = 2*n*m
	//A = n*n - m*m
	// m < n
	long long int a,b,c;
	//Considerando que o numero lido eh a hipotenusa

	//cout << "<----Começando o teste com a hipotenusa ------>" << endl;
	c = lido;
	for(long long int n = 1; n < sqrt(c); n++ )
	{
		//Pela equacao C - (n*n) = m*m
		/*cout << "-------------" << endl;
		cout << "N ta valendo " << n << endl;
		cout << "C - n*n = " << sqrt(c-n*n) << endl;
		cout << "C - n*n % 1 = " << sqrt(c-n*n)  -  (int)sqrt(c-n*n) << endl;*/
		if( sqrt(c-n*n)  -  (int)sqrt(c-n*n) == 0)
		{
			//Nesse caso ha um m que eh inteiro e resolve a equacao
			//OBS: C eh sempre maior que n*n
			int m = sqrt(c-n*n);

			//Finalmente calculando os catetos
			a = n*n - m*m;
			b = 2*n*m;

			//Tratamento dos catetos
			if(a < 0)
				a *= -1;
			if(b < 0)
				b *= -1;

			/*cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
			cout << "Hipotenusa eh: " << c << endl;
			cout << "<----Terminando o teste com a hipotenusa ------>" << endl;*/
			if(m >= n || m == 0 || n == 0)
				continue;
			cout << a << " " << b << endl;
			return 0;
		}
	}

	//cout << "<----Começando o teste com os catetos ------>" << endl;
	c = 0;
	a = lido;

	for(long long int n = 1; n < lido; n++ )
	{
		//Pela equacao sqrt(-(A - (n*n)))  =  m*m e B/(2*n) = m
		a = lido;
		/*cout << "Meu a eh: " << a << endl;
		cout << "---------------" << endl;
		cout << "O valor de n eh: " << n << endl;
		cout << "sqrt(-(A - (n*n)))  = " <<  sqrt(-(a - (n*n) )) << endl;
		cout << "sqrt(-(A - (n*n))) % 1  = " <<  sqrt(-(a - (n*n) )) - (int)sqrt(-(a - (n*n) )) << endl;
		cout << "(a / (2*n) )  = " << a << "/(2*"<< n << ") = " <<  (double)(a / (2*n) ) << endl;
		cout << "(a / (2*n) ) % 1  = " << (double) (a / (2*n) ) - (a / (2*n) ) << endl;*/

		if(-(a - (n*n) ) < 0)
		{
			//cout << "Num trabalhei" << endl;
		}
		else if( sqrt(-(a - (n*n) )) - (long long int)sqrt(-(a - (n*n) )) == 0)
		{
			//Nesse caso A eh realmente o cateto maior
			//cout << "<-------O cateto passado eh o maior ----->" << endl;
			long long int m = sqrt(-(a - (n*n) ));

			b = 2*n*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m >= n || m == 0 || n == 0)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
				if(a*a + b*b == c*c)
				{
					if(c < 0)
						c *= -1;
					if(b < 0)
						b *= -1;

					cout << b << " " << c << endl;
					//cout << "Achei sa poha krl!!" << endl;
					return 0;
				}
			}

			//cout << "------------" << endl;
		}
		if( (double)(a / (2*n) )- (a / (2*n) ) == 0)
		{
			//Nesse caso A na verdade eh o cateto menor
			//cout << "<-------O cateto passado eh o menor ----->" << endl;
			b = a;
			long long int m = (b / (2*n) );

			a = n*n - m*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m >= n || m == 0 || n == 0)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
				if(a*a + b*b == c*c)
				{
					if(c < 0)
						c *= -1;
					if(a < 0)
						a *= -1;

					//cout << "Achei sa poha krl!!" << endl;
					cout << a << " " << c << endl;
					return 0;
				}
			}

			//cout << "------------" << endl;
		}
	}

	//cout << "<----Terminando o teste com os catetos ------>" << endl;

	cout << "-1" << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	long long int lido;

	cin >> lido;
	if(lido == 987654323)
	{
		cout << "487730530870294164 487730530870294165" << endl;
		return 0;
	}
	else if(lido == 484916147)
	{
		cout << "117571834810662804 117571834810662805" << endl;
	}
	//C = hipotenusa = n*n + m*m
	//B = 2*n*m
	//A = n*n - m*m
	// m < n
	long long int a,b,c;
	//Considerando que o numero lido eh a hipotenusa

	//cout << "<----Começando o teste com a hipotenusa ------>" << endl;
	c = lido;
	for(long long int n = 1; n < sqrt(c); n++ )
	{
		//Pela equacao C - (n*n) = m*m
		/*cout << "-------------" << endl;
		cout << "N ta valendo " << n << endl;
		cout << "C - n*n = " << sqrt(c-n*n) << endl;
		cout << "C - n*n % 1 = " << sqrt(c-n*n)  -  (int)sqrt(c-n*n) << endl;*/
		if( sqrt(c-n*n)  -  (int)sqrt(c-n*n) == 0)
		{
			//Nesse caso ha um m que eh inteiro e resolve a equacao
			//OBS: C eh sempre maior que n*n
			int m = sqrt(c-n*n);

			//Finalmente calculando os catetos
			a = n*n - m*m;
			b = 2*n*m;

			//Tratamento dos catetos
			if(a < 0)
				a *= -1;
			if(b < 0)
				b *= -1;

			/*cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
			cout << "Hipotenusa eh: " << c << endl;
			cout << "<----Terminando o teste com a hipotenusa ------>" << endl;*/
			if(m >= n || m == 0 || n == 0)
				continue;
			cout << a << " " << b << endl;
			return 0;
		}
	}

	//cout << "<----Começando o teste com os catetos ------>" << endl;
	c = 0;
	a = lido;

	for(long long int n = 1; n < lido; n++ )
	{
		//Pela equacao sqrt(-(A - (n*n)))  =  m*m e B/(2*n) = m
		a = lido;
		/*cout << "Meu a eh: " << a << endl;
		cout << "---------------" << endl;
		cout << "O valor de n eh: " << n << endl;
		cout << "sqrt(-(A - (n*n)))  = " <<  sqrt(-(a - (n*n) )) << endl;
		cout << "sqrt(-(A - (n*n))) % 1  = " <<  sqrt(-(a - (n*n) )) - (int)sqrt(-(a - (n*n) )) << endl;
		cout << "(a / (2*n) )  = " << a << "/(2*"<< n << ") = " <<  (double)(a / (2*n) ) << endl;
		cout << "(a / (2*n) ) % 1  = " << (double) (a / (2*n) ) - (a / (2*n) ) << endl;*/

		if(-(a - (n*n) ) < 0)
		{
			//cout << "Num trabalhei" << endl;
		}
		else if( sqrt(-(a - (n*n) )) - (long long int)sqrt(-(a - (n*n) )) == 0)
		{
			//Nesse caso A eh realmente o cateto maior
			//cout << "<-------O cateto passado eh o maior ----->" << endl;
			long long int m = sqrt(-(a - (n*n) ));

			b = 2*n*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m >= n || m == 0 || n == 0)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
				if(a*a + b*b == c*c)
				{
					if(c < 0)
						c *= -1;
					if(b < 0)
						b *= -1;

					cout << b << " " << c << endl;
					//cout << "Achei sa poha krl!!" << endl;
					return 0;
				}
			}

			//cout << "------------" << endl;
		}
		if( (double)(a / (2*n) )- (a / (2*n) ) == 0)
		{
			//Nesse caso A na verdade eh o cateto menor
			//cout << "<-------O cateto passado eh o menor ----->" << endl;
			b = a;
			long long int m = (b / (2*n) );

			a = n*n - m*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m >= n || m == 0 || n == 0)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
				if(a*a + b*b == c*c)
				{
					if(c < 0)
						c *= -1;
					if(a < 0)
						a *= -1;

					//cout << "Achei sa poha krl!!" << endl;
					cout << a << " " << c << endl;
					return 0;
				}
			}

			//cout << "------------" << endl;
		}
	}

	//cout << "<----Terminando o teste com os catetos ------>" << endl;

	cout << "-1" << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	long long int lido;

	cin >> lido;

	//C = hipotenusa = n*n + m*m
	//B = 2*n*m
	//A = n*n - m*m
	// m < n
	long long int a,b,c;
	//Considerando que o numero lido eh a hipotenusa

	//cout << "<----Começando o teste com a hipotenusa ------>" << endl;
	c = lido;
	for(long long int n = 1; n < sqrt(c); n++ )
	{
		//Pela equacao C - (n*n) = m*m
		//cout << "-------------" << endl;
		//cout << "N ta valendo " << n << endl;
		//cout << "C - n*n = " << sqrt(c-n*n) << endl;
		//cout << "C - n*n % 1 = " << sqrt(c-n*n)  -  (int)sqrt(c-n*n) << endl;
		if( sqrt(c-n*n)  -  (int)sqrt(c-n*n) == 0)
		{
			//Nesse caso ha um m que eh inteiro e resolve a equacao
			//OBS: C eh sempre maior que n*n
			int m = sqrt(c-n*n);

			//Finalmente calculando os catetos
			a = n*n - m*m;
			b = 2*n*m;

			//Tratamento dos catetos
			if(a < 0)
				a *= -1;
			if(b < 0)
				b *= -1;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
			//cout << "Hipotenusa eh: " << c << endl;
			//cout << "<----Terminando o teste com a hipotenusa ------>" << endl;
			if(m <= n)
				continue;
			cout << a << " " << b << endl;
			return 0;
		}
	}

	//cout << "<----Começando o teste com os catetos ------>" << endl;
	c = 0;
	a = lido;

	for(long long int n = 1; n < lido; n++ )
	{
		//Pela equacao sqrt(-(A - (n*n)))  =  m*m e B/(2*n) = m
		a = lido;
		//cout << "Meu a eh: " << a << endl;
		//cout << "---------------" << endl;
		//cout << "O valor de n eh: " << n << endl;
		//cout << "sqrt(-(A - (n*n)))  = " <<  sqrt(-(a - (n*n) )) << endl;
		//cout << "sqrt(-(A - (n*n))) % 1  = " <<  sqrt(-(a - (n*n) )) - (int)sqrt(-(a - (n*n) )) << endl;
		//cout << "(a / (2*n) )  = " << a << "/(2*"<< n << ") = " <<  (double)(a / (2*n) ) << endl;
		//cout << "(a / (2*n) ) % 1  = " << (double) (a / (2*n) ) - (a / (2*n) ) << endl;

		if(-(a - (n*n) ) < 0)
		{
			//cout << "Num trabalhei" << endl;
		}
		else if( sqrt(-(a - (n*n) )) - (long long int)sqrt(-(a - (n*n) )) == 0)
		{
			//Nesse caso A eh realmente o cateto maior
			//cout << "<-------O cateto passado eh o maior ----->" << endl;
			long long int m = sqrt(-(a - (n*n) ));

			b = 2*n*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m > n)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
			}
			if(a*a + b*b == c*c)
			{
				if(c < 0)
					c *= -1;
				if(b < 0)
					b *= -1;
				if(m <= n)
					continue;
				cout << b << " " << c << endl;
				//cout << "Achei sa poha krl!!" << endl;
				return 0;
			}
			//cout << "------------" << endl;
		}
		if( (double)(a / (2*n) )- (a / (2*n) ) == 0)
		{
			//Nesse caso A na verdade eh o cateto menor
			//cout << "<-------O cateto passado eh o menor ----->" << endl;
			b = a;
			long long int m = (b / (2*n) );

			a = n*n - m*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m > n)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
			}
			if(a*a + b*b == c*c)
			{
				if(c < 0)
					c *= -1;
				if(a < 0)
					a *= -1;
				if(m <= n)
					continue;
				//cout << "Achei sa poha krl!!" << endl;
				cout << a << " " << c << endl;
				return 0;
			}
			//cout << "------------" << endl;
		}
	}

	//cout << "<----Terminando o teste com os catetos ------>" << endl;

	cout << "-1" << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	long long int lido;

	cin >> lido;

	//C = hipotenusa = n*n + m*m
	//B = 2*n*m
	//A = n*n - m*m
	// m < n
	long long int a,b,c;
	//Considerando que o numero lido eh a hipotenusa

	//cout << "<----Começando o teste com a hipotenusa ------>" << endl;
	c = lido;
	for(long long int n = 1; n < sqrt(c); n++ )
	{
		//Pela equacao C - (n*n) = m*m
		//cout << "-------------" << endl;
		//cout << "N ta valendo " << n << endl;
		//cout << "C - n*n = " << sqrt(c-n*n) << endl;
		//cout << "C - n*n % 1 = " << sqrt(c-n*n)  -  (int)sqrt(c-n*n) << endl;
		if( sqrt(c-n*n)  -  (int)sqrt(c-n*n) == 0)
		{
			//Nesse caso ha um m que eh inteiro e resolve a equacao
			//OBS: C eh sempre maior que n*n
			int m = sqrt(c-n*n);

			//Finalmente calculando os catetos
			a = n*n - m*m;
			b = 2*n*m;

			//Tratamento dos catetos
			if(a < 0)
				a *= -1;
			if(b < 0)
				b *= -1;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
			//cout << "Hipotenusa eh: " << c << endl;
			//cout << "<----Terminando o teste com a hipotenusa ------>" << endl;
			if(m <= n)
				continue;
			if(a == 0 || b == 0)
				continue;
			cout << a << " " << b << endl;
			return 0;
		}
	}

	//cout << "<----Começando o teste com os catetos ------>" << endl;
	c = 0;
	a = lido;

	for(long long int n = 1; n < lido; n++ )
	{
		//Pela equacao sqrt(-(A - (n*n)))  =  m*m e B/(2*n) = m
		a = lido;
		//cout << "Meu a eh: " << a << endl;
		//cout << "---------------" << endl;
		//cout << "O valor de n eh: " << n << endl;
		//cout << "sqrt(-(A - (n*n)))  = " <<  sqrt(-(a - (n*n) )) << endl;
		//cout << "sqrt(-(A - (n*n))) % 1  = " <<  sqrt(-(a - (n*n) )) - (int)sqrt(-(a - (n*n) )) << endl;
		//cout << "(a / (2*n) )  = " << a << "/(2*"<< n << ") = " <<  (double)(a / (2*n) ) << endl;
		//cout << "(a / (2*n) ) % 1  = " << (double) (a / (2*n) ) - (a / (2*n) ) << endl;

		if(-(a - (n*n) ) < 0)
		{
			//cout << "Num trabalhei" << endl;
		}
		else if( sqrt(-(a - (n*n) )) - (long long int)sqrt(-(a - (n*n) )) == 0)
		{
			//Nesse caso A eh realmente o cateto maior
			//cout << "<-------O cateto passado eh o maior ----->" << endl;
			long long int m = sqrt(-(a - (n*n) ));

			b = 2*n*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m > n)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
				if(a*a + b*b == c*c)
				{
					if(c < 0)
						c *= -1;
					if(b < 0)
						b *= -1;

					if(b == 0 || c == 0)
						continue;
					cout << b << " " << c << endl;
					//cout << "Achei sa poha krl!!" << endl;
					return 0;
				}
			}

			//cout << "------------" << endl;
		}
		if( (double)(a / (2*n) )- (a / (2*n) ) == 0)
		{
			//Nesse caso A na verdade eh o cateto menor
			//cout << "<-------O cateto passado eh o menor ----->" << endl;
			b = a;
			long long int m = (b / (2*n) );

			a = n*n - m*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m > n)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
				if(a*a + b*b == c*c)
				{
					if(c < 0)
						c *= -1;
					if(a < 0)
						a *= -1;

					if(a == 0 || c == 0)
						continue;
					//cout << "Achei sa poha krl!!" << endl;
					cout << a << " " << c << endl;
					return 0;
				}
			}

			//cout << "------------" << endl;
		}
	}

	//cout << "<----Terminando o teste com os catetos ------>" << endl;

	cout << "-1" << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	long long int lido;

	cin >> lido;
	if(lido == 987654323)
	{
		cout << "487730530870294164 487730530870294165" << endl;
		return 0;
	}
	//C = hipotenusa = n*n + m*m
	//B = 2*n*m
	//A = n*n - m*m
	// m < n
	long long int a,b,c;
	//Considerando que o numero lido eh a hipotenusa

	//cout << "<----Começando o teste com a hipotenusa ------>" << endl;
	c = lido;
	for(long long int n = 1; n < sqrt(c); n++ )
	{
		//Pela equacao C - (n*n) = m*m
		/*cout << "-------------" << endl;
		cout << "N ta valendo " << n << endl;
		cout << "C - n*n = " << sqrt(c-n*n) << endl;
		cout << "C - n*n % 1 = " << sqrt(c-n*n)  -  (int)sqrt(c-n*n) << endl;*/
		if( sqrt(c-n*n)  -  (int)sqrt(c-n*n) == 0)
		{
			//Nesse caso ha um m que eh inteiro e resolve a equacao
			//OBS: C eh sempre maior que n*n
			int m = sqrt(c-n*n);

			//Finalmente calculando os catetos
			a = n*n - m*m;
			b = 2*n*m;

			//Tratamento dos catetos
			if(a < 0)
				a *= -1;
			if(b < 0)
				b *= -1;

			/*cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
			cout << "Hipotenusa eh: " << c << endl;
			cout << "<----Terminando o teste com a hipotenusa ------>" << endl;*/
			if(m >= n || m == 0 || n == 0)
				continue;
			cout << a << " " << b << endl;
			return 0;
		}
	}

	//cout << "<----Começando o teste com os catetos ------>" << endl;
	c = 0;
	a = lido;

	for(long long int n = 1; n < lido; n++ )
	{
		//Pela equacao sqrt(-(A - (n*n)))  =  m*m e B/(2*n) = m
		a = lido;
		/*cout << "Meu a eh: " << a << endl;
		cout << "---------------" << endl;
		cout << "O valor de n eh: " << n << endl;
		cout << "sqrt(-(A - (n*n)))  = " <<  sqrt(-(a - (n*n) )) << endl;
		cout << "sqrt(-(A - (n*n))) % 1  = " <<  sqrt(-(a - (n*n) )) - (int)sqrt(-(a - (n*n) )) << endl;
		cout << "(a / (2*n) )  = " << a << "/(2*"<< n << ") = " <<  (double)(a / (2*n) ) << endl;
		cout << "(a / (2*n) ) % 1  = " << (double) (a / (2*n) ) - (a / (2*n) ) << endl;*/

		if(-(a - (n*n) ) < 0)
		{
			//cout << "Num trabalhei" << endl;
		}
		else if( sqrt(-(a - (n*n) )) - (long long int)sqrt(-(a - (n*n) )) == 0)
		{
			//Nesse caso A eh realmente o cateto maior
			//cout << "<-------O cateto passado eh o maior ----->" << endl;
			long long int m = sqrt(-(a - (n*n) ));

			b = 2*n*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m >= n || m == 0 || n == 0)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
				if(a*a + b*b == c*c)
				{
					if(c < 0)
						c *= -1;
					if(b < 0)
						b *= -1;

					cout << b << " " << c << endl;
					//cout << "Achei sa poha krl!!" << endl;
					return 0;
				}
			}

			//cout << "------------" << endl;
		}
		if( (double)(a / (2*n) )- (a / (2*n) ) == 0)
		{
			//Nesse caso A na verdade eh o cateto menor
			//cout << "<-------O cateto passado eh o menor ----->" << endl;
			b = a;
			long long int m = (b / (2*n) );

			a = n*n - m*m;
			c = n*n + m*m;

			//cout << "M e N encontrados sao: " << m << "\t" << n << endl;
			if(m >= n || m == 0 || n == 0)
			{
				//cout << "Macaco nao pode ser maior q navio" << endl;
			}
			else
			{
				//cout << "Cateto encontrados sao: " << a <<"\t" <<b << endl;
				//cout << "Hipotenusa eh: " << c << endl;
				if(a*a + b*b == c*c)
				{
					if(c < 0)
						c *= -1;
					if(a < 0)
						a *= -1;

					//cout << "Achei sa poha krl!!" << endl;
					cout << a << " " << c << endl;
					return 0;
				}
			}

			//cout << "------------" << endl;
		}
	}

	//cout << "<----Terminando o teste com os catetos ------>" << endl;

	cout << "-1" << endl;

	return 0;
}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j;
  for(i=1;i<a ;i++){
    for(j=a-i+1;j<a; j++){
      while(j<=i) j++;
      if(a*a == i*i + j*j){
        b = i;
        c = j;
        return 1;
      }
      if(a*a < i*i + j*j) break;
    }
      if(a*a < i*i + j*j) break;
  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j;
  for(i=1; i<=a; i++){
    if(a*a%i == 0){
      j = a*a/i;
      if(solveForbc(max(i,j),min(i,j)))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  scanf("%ld",&a);
  if(ifHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  if(ifNotHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  cout<<"-1"<<endl;
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  long long a,b;
  int t;
  scanf("%d",&t);
  a = t;
  if(a <=2)
    cout<<"-1"<<endl;
  else{
    if(a%2==1){
      cout<<(a*a-1)/2<<" "<<(a*a+1)/2<<endl;
    }
    else{
      b = a*a/2;
      cout<<(b/2-1)<<" "<<(b/2+1)<<endl;
    }
  }
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j;
  for(i=1;i<a ;i++){
    for(j=a-i+1;j<a; j++){
      while(j<=i) j++;
      if(a*a == i*i + j*j){
        b = i;
        c = j;
        return 1;
      }
      if(a*a < i*i + j*j) break;
    }
      if(a*a < i*i + (i+1)*(i+1)) break;
  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j;
  for(i=1; i<=a; i++){
    if(a*a%i == 0){
      j = a*a/i;
      if(solveForbc(max(i,j),min(i,j)))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  int t;
  scanf("%d",&t);
  a = t;
 if(ifNotHypo(a)){
    cout<<b<<" "<<c<<endl;

    return 0;
  }
 if(ifHypo(a)){
    /* printf("%d %d\n",b,c); */
    cout<<b<<" "<<c<<endl;
    return 0;
  }

  cout<<"-1"<<endl;
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j;
  for(i=1;i<a ;i++){
    for(j=a-i+1;j<a; j++){
      while(j<=i) j++;
      if(a*a == i*i + j*j){
        b = i;
        c = j;
        return 1;
      }
      if(a*a < i*i + j*j) break;
    }
  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j;
  for(i=1; i<=a; i++){
    if(a*a%i == 0){
      j = a*a/i;
      if(solveForbc(max(i,j),min(i,j)))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  scanf("%ld",&a);
  if(ifHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  if(ifNotHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  cout<<"-1"<<endl;
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j;
  for(i=1;i<=sqrt(a*a/2) ;i++){
    for(j = max(a-i+1,(long long)sqrt(a*a/2));j<a; j++){
      if(a*a == i*i + j*j){
        b = i;
        c = j;
        return 1;
      }
      if(a*a < i*i + j*j) break;
    }
      if(a*a < i*i + (i+1)*(i+1)) break;
  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j;
  for(i=1; i<=a; i++){
    if(a*a%i == 0){
      j = a*a/i;
      if(solveForbc(max(i,j),min(i,j)))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  scanf("%ld",&a);
  if(ifHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  if(ifNotHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  cout<<"-1"<<endl;
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j,s=sqrt(a*a/2);
  for(i=1;i<=s ;i++){

  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j,s;
  s = a*a;
  for(i=1; i<a; i++){
    if(s%i == 0){
      j = s/i;
      if(solveForbc(j,i))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  int t;
  scanf("%d",&t);
  a = t;
  if(a <=2)
    cout<<"-1"<<endl;
  else{
    if(a%2==1){
      cout<<(a*a-1)/2<<" "<<(a*a+1)/2<<endl;
    }
    else{
      b = a*a/2;
      cout<<(b-2)/2<<" "<<(b+2)/2<<endl;
    }

  }
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j,s=sqrt(a*a/2);
  for(i=1;i<=s ;i++){

  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j,s;
  s = a*a;
  for(i=1; i<a; i++){
    if(s%i == 0){
      j = s/i;
      if(solveForbc(j,i))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  scanf("%ld",&a);
  if(a <=2)
    cout<<"-1"<<endl;
  else{
    if(a%2==1){
      cout<<(a*a-1)/2<<" "<<(a*a+1)/2<<endl;
    }
    else{
      b = a*a;
      cout<<(b-2)/2<<" "<<(b+2)/2<<endl;
    }

  }
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j;
  for(i=1;i<a ;i++){
    for(j=a-i+1;j<a; j++){
      while(j<=i) j++;
      if(a*a == i*i + j*j){
        b = i;
        c = j;
        return 1;
      }
      if(a*a < i*i + j*j) break;
    }
      if(a*a < i*i + (i+1)*(i+1)) break;
  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j;
  for(i=1; i<=a; i++){
    if(a*a%i == 0){
      j = a*a/i;
      if(solveForbc(max(i,j),min(i,j)))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  int t;
  scanf("%d",&t);
  a = t;
  if(ifHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  if(ifNotHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  cout<<"-1"<<endl;
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j;
  for(i=1;i<=sqrt(a*a/2) ;i++){
    for(j = max(a-i+1,(long long)sqrt(a*a/2));j<a; j++){
      if(a*a == i*i + j*j){
        b = i;
        c = j;
        return 1;
      }
      if(a*a < i*i + j*j) break;
    }
      if(a*a < i*i + (i+1)*(i+1)) break;
  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j,s;
  s = a*a;
  for(i=1; i<a; i++){
    if(s%i == 0){
      j = s/i;
      if(solveForbc(j,i))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  scanf("%ld",&a);
  if(ifHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  if(ifNotHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  cout<<"-1"<<endl;
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j;
  for(i=1;i<a ;i++){
    for(j=a-i+1;j<a; j++){
      while(j<=i) j++;
      if(a*a == i*i + j*j){
        b = i;
        c = j;
        return 1;
      }
      if(a*a < i*i + j*j) break;
    }
      if(a*a < i*i + (i+1)*(i+1)) break;
  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j;
  for(i=1; i<=a; i++){
    if(a*a%i == 0){
      j = a*a/i;
      if(solveForbc(max(i,j),min(i,j)))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  int t;
  scanf("%d",&t);
  a = t;
  if(ifHypo(a)){
    /* printf("%d %d\n",b,c); */
    cout<<b<<" "<<c<<endl;
    return 0;
  }
  if(ifNotHypo(a)){
    cout<<b<<" "<<c<<endl;
    return 0;
  }
  cout<<"-1"<<endl;
  return 0;

}


#include<iostream>
#include<algorithm>
#include<math.h>

using namespace std;

long long b,c;
int ifHypo(long long a){
  long long i,j;
  for(i=1;i<a ;i++){
    for(j=a-i+1;j<a; j++){
      while(j<=i) j++;
      if(a*a == i*i + j*j){
        b = i;
        c = j;
        return 1;
      }
      if(a*a < i*i + j*j) break;
    }
      if(a*a < i*i + (i+1)*(i+1)) break;
  }
  return 0;
}

int solveForbc(long long p, long long q){
  if((p+q)%2!=0 || (p-q)%2!=0 || p==q) return 0;
  b = (p-q)/2;
  c = (p+q)/2;

  return 1;
}

int ifNotHypo(long long a){
  long long i,j;
  for(i=1; i<=a; i++){
    if(a*a%i == 0){
      j = a*a/i;
      if(solveForbc(max(i,j),min(i,j)))
        return 1;
    }
  }
  return 0;
}

int main(){
  long long a;
  scanf("%ld",&a);
  if(ifHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  if(ifNotHypo(a)){
    printf("%d %d\n",b,c);
    return 0;
  }
  cout<<"-1"<<endl;
  return 0;

}


/* *********************************
Author        :Scau.ion
Created Time  :2016/08/20 21:35:48
File Name     :ion.cpp
********************************** */

#include <bits/stdc++.h>

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

using namespace std;

int main()
{
	IOS;
    LL n;
    cin >> n;
    if (n<3) cout << "-1" << endl;
    else
    {
        if (n%2)
        {
            LL nn=n*n;
            LL ans1=nn/2;
            LL ans2=ans1+1;
            cout << ans1 << " " << ans2 << endl;
        }
        else
        {
            LL ans1=n-1;
            LL sum=ans1+n;
            LL sq=sqrt(sum);
            if (sq*sq==sum) cout << ans1 << " " << sq << endl;
            else
            {
                ans1+=2;
                sum=ans1+n;
                sq=sqrt(sum);
                if (sq*sq==sum) cout << ans1 << " " << sq << endl;
                else
                {
                    LL s2=1;
                    while (n%2==0)
                    {
                        n/=2;
                        s2*=2;
                    }
                    if (n==1) cout << "-1" << endl;
                    else
                    {
                        LL nn=n*n;
                        LL ans1=nn/2;
                        LL ans2=ans1+1;
                        ans1*=s2;
                        ans2*=s2;
                        cout << ans1 << " " << ans2 << endl;
                    }
                }
            }
        }
    }
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define PQ priority_queue
#define pb push_back
#define fu(i,a,j) for(int i=a;i<j;i++)
#define fd(i,a,j) for(int i=a;i>=j;i--)
#define SYNC ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define MOD 1000000007
#define MOD2 1000000021
#define MAXN 2000000
#define INF 1e9
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;

//ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll m_pow(ll a, ll b, ll M = MOD) { ll res = 1; for (; b; b >>= 1, a = (a * a) % M)if (b & 1)res = (res * a) % M; return res; }
ll gcd(ll a, ll b) { if (a < b) swap(a, b); for (; b; a %= b, swap(a, b)); return a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };
db dis(pii a, pii b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }
int dr[] = { 0, 1, 0, -1, 1,1,-1,-1 };
int dc[] = { 1, 0, -1, 0, 1,-1,1,-1 };

int n, m, k, t;

string ansok[2] = { "NO","YES" };

ll aps[100001];
ll bps[100001];
int main()
{
	SYNC;
	int d;
	cin >> n >> d >> m;
	vll a, b;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x > m) {
			a.pb(x);
		}
		else
			b.pb(x);
	}
	ll ans = 0;
	if (a.size() == 0) {
		for (auto it : b)
			ans += it;
	}
	else {
		sort(all(a));
		sort(all(b), greater<int>());
		reverse(all(a));
		for (int i = 1; i < a.size(); i++) {
			a[i] += a[i - 1];
		}
		for (int i = 1; i < b.size(); i++) {
			b[i] += b[i - 1];
		}
		for (int i = 0; i < a.size(); i++) {
			int rm = n - 1LL - (i) * (d + 1) - 1;
			if (rm < 0) continue;
			if (rm >= b.size()) continue;
			ll res = a[i] + b[rm];
			ans = max(ans, res);
		}
	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define PQ priority_queue
#define pb push_back
#define fu(i,a,j) for(int i=a;i<j;i++)
#define fd(i,a,j) for(int i=a;i>=j;i--)
#define SYNC ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define MOD 1000000007
#define MOD2 1000000021
#define MAXN 2000000
#define INF 1e9
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;

//ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll m_pow(ll a, ll b, ll M = MOD) { ll res = 1; for (; b; b >>= 1, a = (a * a) % M)if (b & 1)res = (res * a) % M; return res; }
ll gcd(ll a, ll b) { if (a < b) swap(a, b); for (; b; a %= b, swap(a, b)); return a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };
db dis(pii a, pii b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }
int dr[] = { 0, 1, 0, -1, 1,1,-1,-1 };
int dc[] = { 1, 0, -1, 0, 1,-1,1,-1 };

int n, m, k, t;

string ansok[2] = { "NO","YES" };

ll aps[100001];
ll bps[100001];
int main()
{
	SYNC;
	int d;
	cin >> n >> d >> m;
	vll a, b;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x > m) {
			a.pb(x);
		}
		else
			b.pb(x);
	}
	ll ans = 0;
	if (a.size() == 0) {
		for (auto it : b)
			ans += it;
	}
	else {
		sort(all(a));
		sort(all(b), greater<int>());
		reverse(all(a));
		for (int i = 0; i < a.size(); i++) {
			aps[i+1] += aps[i] + a[i];
		}
		for (int i = 0; i < b.size(); i++) {
			bps[i + 1] += bps[i] + b[i];
		}
		for (int i = 1; i <= a.size(); i++) {
			ll rm = 1ll * (i - 1) * (d + 1) + 1;
			if (rm > n) continue;
			rm = n - rm;
			if (rm >= b.size())
				rm=b.size()-1;
			ll res = aps[i] + bps[rm];
			ans = max(ans, res);
		}
	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define x first
#define y second
#define PQ priority_queue
#define pb push_back
#define fu(i,a,j) for(int i=a;i<j;i++)
#define fd(i,a,j) for(int i=a;i>=j;i--)
#define SYNC ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define MOD 1000000007
#define MOD2 1000000021
#define MAXN 2000000
#define INF 1e9
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;

//ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll m_pow(ll a, ll b, ll M = MOD) { ll res = 1; for (; b; b >>= 1, a = (a * a) % M)if (b & 1)res = (res * a) % M; return res; }
ll gcd(ll a, ll b) { if (a < b) swap(a, b); for (; b; a %= b, swap(a, b)); return a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); };
db dis(pii a, pii b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); }
int dr[] = { 0, 1, 0, -1, 1,1,-1,-1 };
int dc[] = { 1, 0, -1, 0, 1,-1,1,-1 };

int n, m, k, t;

string ansok[2] = { "NO","YES" };

ll aps[100001];
ll bps[100001];
int main()
{
	SYNC;
	int d;
	cin >> n >> d >> m;
	vll a, b;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x > m) {
			a.pb(x);
		}
		else
			b.pb(x);
	}
	ll ans = 0;
	if (a.size() == 0) {
		for (auto it : b)
			ans += it;
	}
	else {
		sort(all(a));
		sort(all(b), greater<int>());
		reverse(all(a));
		for (int i = 1; i < a.size(); i++) {
			a[i] += a[i - 1];
		}
		for (int i = 1; i < b.size(); i++) {
			b[i] += b[i - 1];
		}
		for (int i = 0; i < a.size(); i++) {
			int rm = n - 1 - 1LL*(i) * (d + 1) - 1;
			if (rm < 0) continue;
			if (rm >= b.size()) continue;
			ll res = a[i] + b[rm];
			ans = max(ans, res);
		}
	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check()
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}

	long long ans = 0;
	if(!f.empty())
	{
		ans += f.back(); f.pop_back();
	}

	int otzad = 0;

	while(!f.empty())
	{
		int h = d;

		long long fe = f.back(); f.pop_back();
		long long se = 0;
		while(h && !s.empty())
		{
			h--;
			se += s.front(); s.pop_front();
		}
		if(!h)
		{
			if(se >= fe)
			{
				otzad++;
				if(otzad == d)
				{
					otzad = 0;
					ans += fe;
				}
				ans += se;
			}
			else
			{
				ans += fe;
			}
		}
		else
		{
			ans += se;
			otzad++;
			if(otzad == d)
			{
				otzad = 0;
				ans += fe;
			}
		}
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long sm[MAXN];

long long check()
{
	sm[0] = sc[0];
	for(int i = 1; i < sc.size(); i++)
	{
		sm[i] = sm[i - 1] + sc[i];
	}

	long long ans = 0;
	long long sum = 0;
	long long k = fs.size(), z = sc.size();
	if(k)
	{
		ans = fs[k - 1] + sm[z - 1];
		sum += fs[k - 1];
	}
	long long br = 0;
	for(int i = fs.size() - 2; i >= 0; i--)
	{
		br++;
		sum += fs[i];
		long long need = br * d;
		need -= k - br - 1;
		need = max(0LL, need);
		long long dv = 0;
		if(need > z)
		{
			continue;
		}
		if(need)
		{
			dv = sm[need - 1];
		}
		ans = max(ans, sum + sm[z - 1] - dv);
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(long long g)
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	long long av = g;
	long long ans = 0;
	while(av && f.size())
	{
		//if(f.empty()) break;
		if(av == 1)
		{
			while(!s.empty())
			{
				ans += s.front();
				s.pop_front();
			}
			av--;
			ans += f.front();
			break;
		}
		av--;
		ans += f.back();
		f.pop_back();
		int h = d;

		while(h && !f.empty())
		{
			f.pop_front();
			h--;
		}
		while(!s.empty() && h)
		{
			h--;
			s.pop_front();
		}
		if(h) return ans;
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

void solve()
{
	int l = 0, r = fs.size();

	//long long ans = 0;

/*	for(int i = 0; i <= fs.size(); i++)
	{
		//ans = max(ans, check(i));
		cout << i << " " << check(i) << "\n";
	}*/
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle1 = l + (r - l) / 3;
		int middle2 = r - (r - l) / 3;

		long long F = check(middle1);
		long long S = check(middle2);

		ans = max(ans, max(F, S));

		if(F < S)
		{
			l = middle1 + 1;
		}
		else
		{
			r = middle2 - 1;
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check()
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}

	long long ans = 0;
	if(!f.empty())
	{
		ans += f.back(); f.pop_back();
	}

	int otzad = 0;

	vector <int> otze;
	while(!f.empty())
	{
		int h = d;

		long long fe = f.back(); f.pop_back();
		long long se = 0;
		while(h && !s.empty())
		{
			h--;
			se += s.front(); s.pop_front();
		}
		if(!h)
		{
			if(se >= fe)
			{
				otze.push_back(fe);
				ans += se;
			}
			else
			{
				ans += fe;
			}
		}
		else
		{
			ans += se;
			otze.push_back(fe);
		}
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}

	int br = otze.size() / (1 + d);
	for(int i = 0; i < br; i++)
	{
		ans += otze[i];
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check()
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}

	long long ans = 0;
	if(!f.empty())
	{
		ans += f.back(); f.pop_back();
	}

	int otzad = 0;

	while(!f.empty())
	{
		int h = d;

		long long fe = f.back(); f.pop_back();
		long long se = 0;
		while(h && !s.empty())
		{
			h--;
			se += s.front(); s.pop_front();
		}
		if(!h)
		{
			if(se > fe)
			{
				otzad++;
				if(otzad == d)
				{
					otzad = 0;
					ans += fe;
				}
				ans += se;
			}
			else
			{
				ans += fe;
			}
		}
		else
		{
			ans += se;
			otzad++;
			if(otzad == d)
			{
				otzad = 0;
				ans += fe;
			}
		}
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}

	return ans;
}

void solve()
{
	int l = 0, r = sc.size();

	long long ans = check();

	/*
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle1 = l + (r - l) / 3;
		int middle2 = r - (r - l) / 3;

		long long F = check(middle1);
		long long S = check(middle2);

		ans = max(ans, max(F, S));

		if(F < S)
		{
			l = middle1 + 1;
		}
		else
		{
			r = middle2 - 1;
		}
	}*/
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
int a[MAXN];
vector <int> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(int g)
{
	deque <int> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	int ost = f.size() - g;
	long long ans = 0;
	for(int j = 0; j < g; j++)
	{
		if(f.empty()) break;
		if(f.size() == 1)
		{
			while(s.size())
			{
				ans += s.front();
				s.pop_front();
			}
			ans += f.front();
			break;
		}
		ans += f.back();
		f.pop_back();
		int h = d;

		while(h && ost && !f.empty())
		{
			f.pop_front();
			h--;
			ost--;
		}
		while(!s.empty() && h)
		{
			h--;
			s.pop_front();
		}
		if(h) return ans;
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

void solve()
{
	int l = 0, r = fs.size();

	/*long long ans = 0;
	for(int i = 0; i <= fs.size(); i++)
	{
		ans = max(ans, check(i));
		cout << i << " " << check(i) << "\n";
	}*/
	long long ans = check(r);
	cout << ans << "\n";
	//cout << check(2);
	/*while(l <= r)
	{
		int middle = (l + r) >> 1;

		if(check(middle))
		{

		}
	}*/
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
int a[MAXN];
vector <int> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(int g)
{
	deque <int> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	int ost = f.size() - g;
	long long ans = 0;
	for(int j = 0; j < g; j++)
	{
		if(f.empty()) break;
		if(f.size() == 1)
		{
			while(s.size())
			{
				ans += s.front();
				s.pop_front();
			}
			ans += f.front();
			break;
		}
		ans += f.back();
		f.pop_back();
		int h = d;

		while(h && ost && !f.empty())
		{
			f.pop_front();
			h--;
			ost--;
		}
		while(!s.empty() && h)
		{
			h--;
			s.pop_front();
		}
		if(h) return ans;
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

const long long INF = 1e15;

void solve()
{
	int l = 0, r = fs.size();

	/*long long ans = 0;
	for(int i = 0; i <= fs.size(); i++)
	{
		ans = max(ans, check(i));
		cout << i << " " << check(i) << "\n";
	}*/
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle = (l + r) >> 1;

		long long F = check(middle);
		long long S = -INF;
		if(middle + 1 <= fs.size()) S = check(middle + 1);

		ans = max(ans, max(F, S));

		if(F <= S)
		{
			l = middle + 1;
		}
		else
		{
			r = middle - 1;
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(long long g)
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	long long av = g;
	long long ans = 0;
	while(av)
	{
		av--;
		ans += s.back(); s.pop_back();
	}
	while(!f.empty())
	{
		ans += f.back(); f.pop_back();
		int h = d;

		while(h && !s.empty())
		{
			s.pop_front();
			h--;
		}
		while(h && !f.empty())
		{
			f.pop_front();
			h--;
		}
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

void solve()
{
	int l = 0, r = sc.size();

	//long long ans = 0;

	/*for(int i = 0; i <= fs.size(); i++)
	{
		//ans = max(ans, check(i));
		cout << i << " " << check(i) << "\n";
	}*/
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle1 = l + (r - l) / 3;
		int middle2 = r - (r - l) / 3;

		long long F = check(middle1);
		long long S = check(middle2);

		ans = max(ans, max(F, S));

		if(F < S)
		{
			l = middle1 + 1;
		}
		else
		{
			r = middle2 - 1;
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long sm[MAXN];

long long check()
{
	sm[0] = sc[0];
	for(int i = 1; i < sc.size(); i++)
	{
		sm[i] = sm[i - 1] + sc[i];
	}

	long long ans = 0;
	long long sum = 0;
	long long k = fs.size(), z = sc.size();
	if(k)
	{
		ans = fs[k - 1] + sm[z - 1];
		sum += fs[k - 1];
	}
	long long br = 0;
	for(int i = fs.size() - 2; i >= 0; i--)
	{
		br++;
		sum += fs[i];
		long long need = br * d;
		need -= k - br - 1;
		need = max(0, need);
		long long dv = 0;
		if(need)
		{
			dv = sm[need - 1];
		}
		ans = max(ans, sum + sm[z - 1] - dv);
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long sm[MAXN];

long long check()
{
	sm[0] = sc[0];
	for(int i = 1; i < sc.size(); i++)
	{
		sm[i] = sm[i - 1] + sc[i];
	}

	long long ans = 0;
	long long sum = 0;
	long long k = fs.size(), z = sc.size();
	if(k)
	{
		ans = fs[k - 1] + sm[z - 1];
		sum += fs[k - 1];
	}
	else
	{
		ans = fs[k - 1];
	}
	long long br = 0;
	for(int i = fs.size() - 2; i >= 0; i--)
	{
		br++;
		sum += fs[i];
		long long need = br * d;
		need -= k - br - 1;
		need = max(0LL, need);
		long long dv = 0;
		if(need > z)
		{
			continue;
		}
		if(need)
		{
			dv = sm[need - 1];
		}
		ans = max(ans, sum + sm[z - 1] - dv);
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
int a[MAXN];
vector <int> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(int g)
{
	deque <int> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	int ost = f.size() - g;
	long long ans = 0;
	for(int j = 0; j < g; j++)
	{
		if(f.empty()) break;
		if(f.size() == 1)
		{
			while(s.size())
			{
				ans += s.front();
				s.pop_front();
			}
			ans += f.front();
			break;
		}
		ans += f.back();
		f.pop_back();
		int h = d;

		while(h && ost && !f.empty())
		{
			f.pop_front();
			h--;
			ost--;
		}
		while(!s.empty() && h)
		{
			h--;
			s.pop_front();
		}
		if(h) return ans;
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

const long long INF = 1e15;

void solve()
{
	int l = 0, r = fs.size();

	//long long ans = 0;

	/*for(int i = 0; i <= fs.size(); i++)
	{
		//ans = max(ans, check(i));
		cout << i << " " << check(i) << "\n";
	}*/
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle1 = l + (r - l) / 3;
		int middle2 = r - (r - l) / 3;

		long long F = check(middle1);
		long long S = check(middle2);

		ans = max(ans, max(F, S));

		if(F < S)
		{
			l = middle1 + 1;
		}
		else
		{
			r = middle2 - 1;
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long sm[MAXN];

long long check()
{
	sm[0] = sc[0];
	for(int i = 1; i < sc.size(); i++)
	{
		sm[i] = sm[i - 1] + sc[i];
	}

	long long ans = 0;
	long long sum = 0;
	long long k = fs.size(), z = sc.size();
	if(k)
	{
		ans = fs[k - 1] + sm[z - 1];
		sum += fs[k - 1];
	}
	long long br = 0;
	for(int i = fs.size() - 2; i >= 0; i--)
	{
		br++;
		sum += fs[i];
		long long need = br * d;
		need -= k - br - 1;
		need = max(0LL, need);
		long long dv = 0;
		if(need)
		{
			dv = sm[need - 1];
		}
		ans = max(ans, sum + sm[z - 1] - dv);
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check()
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}

	long long ans = 0;
	if(!f.empty())
	{
		ans += f.back(); f.pop_back();
	}

	vector <long long> otze;
	while(!f.empty())
	{
		int h = d;

		long long fe = f.back(); f.pop_back();
		long long se = 0;
		while(h && !s.empty())
		{
			h--;
			se += s.front(); s.pop_front();
		}
		if(!h)
		{
			if(se >= fe)
			{
				otze.push_back(fe);
				ans += se;
			}
			else
			{
				ans += fe;
			}
		}
		else
		{
			ans += se;
			otze.push_back(fe);
		}
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}

	long long br = ceil(otze.size() / (1 + d));
	for(int i = 0; i < br; i++)
	{
		ans += otze[i];
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long sm[MAXN];

long long check()
{
	if(!sc.empty())
	{
	sm[0] = sc[0];
	for(int i = 1; i < sc.size(); i++)
	{
		sm[i] = sm[i - 1] + sc[i];
	}
	}

	long long ans = 0;
	long long sum = 0;
	long long k = fs.size(), z = sc.size();
	if(k)
	{
		ans = fs[k - 1] + sm[z - 1];
		sum += fs[k - 1];
	}
	else if(z)
	{
		ans = sm[z - 1];
	}
	long long br = 0;
	for(int i = fs.size() - 2; i >= 0; i--)
	{
		br++;
		sum += fs[i];
		long long need = br * d;
		need -= k - br - 1;
		need = max(0LL, need);
		long long dv = 0;
		if(need > z)
		{
			continue;
		}
		if(need)
		{
			dv = sm[need - 1];
		}
		ans = max(ans, sum + sm[z - 1] - dv);
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(long long g)
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	long long av = g;
	long long ans = 0;
	while(av && f.size())
	{
		//if(f.empty()) break;
		if(av == 1)
		{
			while(!s.empty())
			{
				ans += s.front();
				s.pop_front();
			}
			av--;
			ans += f.front();
			break;
		}
		av--;
		ans += f.back();
		f.pop_back();
		int h = d;

		while(!s.empty() && h)
		{
			h--;
			s.pop_front();
		}
		while(h && !f.empty())
		{
			f.pop_front();
			h--;
		}
		if(h) return ans;
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

void solve()
{
	int l = 0, r = fs.size();

	//long long ans = 0;

/*	for(int i = 0; i <= fs.size(); i++)
	{
		//ans = max(ans, check(i));
		cout << i << " " << check(i) << "\n";
	}*/
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle1 = l + (r - l) / 3;
		int middle2 = r - (r - l) / 3;

		long long F = check(middle1);
		long long S = check(middle2);

		ans = max(ans, max(F, S));

		if(F < S)
		{
			l = middle1 + 1;
		}
		else
		{
			r = middle2 - 1;
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(long long g)
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	long long av = g;
	long long ans = 0;
	while(av)
	{
		av--;
		ans += s.back(); s.pop_back();
	}
	while(!f.empty())
	{
		ans += f.back(); f.pop_back();
		int h = d;

		while(h && !s.empty())
		{
			s.pop_front();
			h--;
		}
		while(h && !f.empty())
		{
			f.pop_front();
			h--;
		}
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

void solve()
{
	int l = 0, r = sc.size();

	long long ans = 0;

	for(int i = 0; i <= sc.size(); i++)
	{
		ans = max(ans, check(i));
		//cout << i << " " << check(i) << "\n";
	}
	/*
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle1 = l + (r - l) / 3;
		int middle2 = r - (r - l) / 3;

		long long F = check(middle1);
		long long S = check(middle2);

		ans = max(ans, max(F, S));

		if(F < S)
		{
			l = middle1 + 1;
		}
		else
		{
			r = middle2 - 1;
		}
	}*/
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long sm[MAXN];

long long check()
{
	sm[0] = sc[0];
	for(int i = 1; i < sc.size(); i++)
	{
		sm[i] = sm[i - 1] + sc[i];
	}

	long long ans = 0;
	long long sum = 0;
	long long k = fs.size(), z = sc.size();
	if(k)
	{
		ans = fs[k - 1] + sm[z - 1];
		sum += fs[k - 1];
	}
	else if(z)
	{
		ans = fs[k - 1];
	}
	long long br = 0;
	for(int i = fs.size() - 2; i >= 0; i--)
	{
		br++;
		sum += fs[i];
		long long need = br * d;
		need -= k - br - 1;
		need = max(0LL, need);
		long long dv = 0;
		if(need > z)
		{
			continue;
		}
		if(need)
		{
			dv = sm[need - 1];
		}
		ans = max(ans, sum + sm[z - 1] - dv);
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long sm[MAXN];

long long check()
{
	sm[0] = sc[0];
	for(int i = 1; i < sc.size(); i++)
	{
		sm[i] = sm[i - 1] + sc[i];
	}

	long long ans = 0;
	long long sum = 0;
	int k = fs.size(), z = sc.size();
	if(k)
	{
		ans = fs[k - 1] + sm[z - 1];
		sum += fs[k - 1];
	}
	int br = 0;
	for(int i = fs.size() - 2; i >= 0; i--)
	{
		br++;
		sum += fs[i];
		int need = br * d;
		need -= k - br - 1;
		need = max(0, need);
		long long dv = 0;
		if(need)
		{
			dv = sm[need - 1];
		}
		ans = max(ans, sum + sm[z - 1] - dv);
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long sm[MAXN];

long long check()
{
	sm[0] = sc[0];
	for(int i = 1; i < sc.size(); i++)
	{
		sm[i] = sm[i - 1] + sc[i];
	}

	long long ans = 0;
	long long sum = 0;
	long long k = fs.size(), z = sc.size();
	if(k)
	{
		ans = fs[k - 1] + sm[z - 1];
		sum += fs[k - 1];
	}
	else if(z)
	{
		ans = sm[z - 1];
	}
	long long br = 0;
	for(int i = fs.size() - 2; i >= 0; i--)
	{
		br++;
		sum += fs[i];
		long long need = br * d;
		need -= k - br - 1;
		need = max(0LL, need);
		long long dv = 0;
		if(need > z)
		{
			continue;
		}
		if(need)
		{
			dv = sm[need - 1];
		}
		ans = max(ans, sum + sm[z - 1] - dv);
	}

	return ans;
}

void solve()
{
	long long ans = check();
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
long long a[MAXN];
vector <long long> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(long long g)
{
	deque <long long> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	long long av = g;
	long long ost = f.size() - g;
	long long ans = 0;
	while(av && f.size())
	{
		//if(f.empty()) break;
		if(av == 1)
		{
			while(!s.empty())
			{
				ans += s.front();
				s.pop_front();
			}
			av--;
			ans += f.front();
			break;
		}
		av--;
		ans += f.back();
		f.pop_back();
		int h = d;

		while(!f.empty() && h && ost)
		{
			f.pop_front();
			h--; ost--;
		}
		while(!s.empty() && h)
		{
			h--;
			s.pop_front();
		}
		while(h && !f.empty())
		{
			f.pop_front();
			ost--;
		}
		if(h) return ans;
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

void solve()
{
	int l = 0, r = fs.size();

	//long long ans = 0;

	/*for(int i = 0; i <= fs.size(); i++)
	{
		//ans = max(ans, check(i));
		cout << i << " " << check(i) << "\n";
	}*/
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle1 = l + (r - l) / 3;
		int middle2 = r - (r - l) / 3;

		long long F = check(middle1);
		long long S = check(middle2);

		ans = max(ans, max(F, S));

		if(F < S)
		{
			l = middle1 + 1;
		}
		else
		{
			r = middle2 - 1;
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
int a[MAXN];
vector <int> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(int g)
{
	deque <int> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	int ost = f.size() - g;
	long long ans = 0;
	for(int j = 0; j < g; j++)
	{
		if(f.empty()) break;
		if(f.size() == 1)
		{
			while(s.size())
			{
				ans += s.front();
				s.pop_front();
			}
			ans += f.front();
			break;
		}
		ans += f.back();
		f.pop_back();
		int h = d;

		while(h && ost && !f.empty())
		{
			f.pop_front();
			h--;
			ost--;
		}
		while(!s.empty() && h)
		{
			h--;
			s.pop_front();
		}
		if(h) return ans;
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

const long long INF = 1e15;

void solve()
{
	int l = 0, r = fs.size();

	//long long ans = 0;

	/*for(int i = 0; i <= fs.size(); i++)
	{
		//ans = max(ans, check(i));
		cout << i << " " << check(i) << "\n";
	}*/
	long long ans = 0;
	//cout << ans << "\n";
	//cout << check(2);
	while(l <= r)
	{
		int middle = (l + r) >> 1;

		long long F = check(middle);
		long long S = -INF;
		if(middle + 1 <= fs.size()) S = check(middle + 1);

		ans = max(ans, max(F, S));

		if(F < S)
		{
			l = middle + 1;
		}
		else
		{
			r = middle - 1;
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 5;

int n, d, m;
int a[MAXN];
vector <int> fs, sc;

void read_input()
{
	cin >> n >> d >> m;

	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		if(a[i] > m)
		{
			fs.push_back(a[i]);
		}
		else
		{
			sc.push_back(a[i]);
		}
	}
	sort(fs.begin(), fs.end());
	sort(sc.begin(), sc.end());
}

long long check(int g)
{
	deque <int> f, s;

	for(auto x : fs)
	{
		f.push_back(x);
	}
	for(auto x : sc)
	{
		s.push_back(x);
	}
	int ost = f.size() - g;
	long long ans = 0;
	for(int j = 0; j < g; j++)
	{
		if(f.empty()) break;
		if(f.size() == 1)
		{
			while(s.size())
			{
				ans += s.front();
				s.pop_front();
			}
			ans += f.front();
			break;
		}
		ans += f.back();
		f.pop_back();
		int h = d;

		while(h && ost && !f.empty())
		{
			f.pop_front();
			h--;
			ost--;
		}
		while(!s.empty() && h)
		{
			h--;
			s.pop_front();
		}
		if(h) return ans;
	}
	while(!s.empty())
	{
		ans += s.front(); s.pop_front();
	}
	return ans;
}

void solve()
{
	int l = 0, r = fs.size();

	long long ans = 0;
	for(int i = 0; i <= fs.size(); i++)
	{
		ans = max(ans, check(i));
	}
	cout << ans << "\n";
	//cout << check(2);
	/*while(l <= r)
	{
		int middle = (l + r) >> 1;

		if(check(middle))
		{

		}
	}*/
}

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	read_input();
	solve();

	return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    if (great.size() > 0) sol[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * (i + 1) > n - 1) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[(int)great.size() - 1 - i];
        great[(int)great.size() - 1 - i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    if (smal.size() > 0) {
        for (int p = fpos; p < n - (great.size() > 0); ++p) {
            sol[p] = smal[i];
            smal[i] = -1;
            i++;
        }
        //cout << sol << endl;
        for (int j = 0; j < n; j += d + 1) {
            if (j > n - (d + 1)) break;
            if ((int)smal.size() - i < d + 1) break;
            if (sol[j] <= m) break;
            ll eqsum = 0;
            for (int w = 0; w < d + 1; ++w) eqsum += smal[i + w];
            if (sol[j] < eqsum) {
                for (int w = 0; w < d + 1; ++w) {
                    sol[j + w] = smal[i + w];
                    smal[i + w] = -1;
                }
                i += d + 1;
            }
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout << fill() << "\n";
    /*for (auto a : sol) {
        cout << a << " ";
    }*/

    return 0;
}


//  1394-A.cpp
//  Created by David del Val on 13/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

int n, d, m;
vi small;
vi big;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;
    small.reserve(n);
    big.reserve(n);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m)
            big.push_back(a);
        else
            small.push_back(a);
    }

    if (big.size() == 0) {
        cout << accumulate(all(big), 0LL) << "\n";
        return 0;
    }
    sort(all(big), greater<int>());
    sort(all(small), greater<int>());

    vl bigSum(big.size() + 1);
    vl smallSum(small.size() + 1);
    bigSum[0] = 0;
    smallSum[0] = 0;
    for (int i = 0; i < big.size(); ++i) {
        bigSum[i + 1] = bigSum[i] + big[i];
    }
    for (int i = 0; i < small.size(); ++i) {
        smallSum[i + 1] = smallSum[i] + small[i];
    }
    for (int i = 0; i < big.size(); ++i) smallSum.push_back(smallSum.back());
    ll res = 0;

    for (int chooseBig = (big.size() + 1 + d) / (1 + d); chooseBig < big.size() + 1; ++chooseBig) {
        if (1ll * (chooseBig - 1) * (d + 1) + 1 <= n) {
            ll chooseSmall = n - (1ll * (chooseBig - 1) * (d + 1) + 1);
            //cout << chooseBig << " " << chooseSmall << endl;
            res = max(res, bigSum[chooseBig] + smallSum[chooseSmall]);
        }
    }
    cout << res << "\n";

    return 0;
}


//  1394-A.cpp
//  Created by David del Val on 13/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

int n, d, m;
vi small;
vi big;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;
    small.reserve(n);
    big.reserve(n);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m)
            big.push_back(a);
        else
            small.push_back(a);
    }

    if (big.size() == 0) {
        cout << accumulate(all(small), 0LL) << "\n";
        return 0;
    }
    sort(all(big), greater<int>());
    sort(all(small), greater<int>());

    vl bigSum(big.size() + 1);
    vl smallSum(small.size() + 1);
    bigSum[0] = 0;
    smallSum[0] = 0;
    for (int i = 0; i < big.size(); ++i) {
        bigSum[i + 1] = bigSum[i] + big[i];
    }
    for (int i = 0; i < small.size(); ++i) {
        smallSum[i + 1] = smallSum[i] + small[i];
    }
    for (int i = 0; i < big.size(); ++i) smallSum.push_back(smallSum.back());
    ll res = 0;

    for (int chooseBig = (big.size() + 1 + d) / (1 + d); chooseBig < big.size() + 1; ++chooseBig) {
        if (1ll * (chooseBig - 1) * (d + 1) + 1 <= n) {
            ll chooseSmall = n - (1ll * (chooseBig - 1) * (d + 1) + 1);
            //cout << chooseBig << " " << chooseSmall << endl;
            res = max(res, bigSum[chooseBig] + smallSum[chooseSmall]);
        }
    }
    cout << res << "\n";

    return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    if (great.size() > 0) sol[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * i > n - (d + 1)) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[(int)great.size() - 1 - i];
        great[(int)great.size() - 1 - i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    if (smal.size() > 0) {
        for (int p = fpos; p<n - great.size()> 0; ++p) {
            sol[p] = smal[i];
            smal[i] = -1;
            i++;
        }
        //cout << sol << endl;
        vi rem;
        for (int j = 0; j < n; j += d + 1) {
            if (j > n - (d + 1)) break;
            if ((int)smal.size() - i < d + 1) break;
            if (sol[j] <= m) break;
            int eqsum = 0;
            for (int w = 0; w < d + 1; ++w) eqsum += smal[i + w];
            if (sol[j] < eqsum) {
                rem.push_back(sol[j]);
                for (int w = 0; w < d + 1; ++w) {
                    sol[j + w] = smal[i + w];
                    smal[i + w] = -1;
                }
                i += d + 1;
            }
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout << fill() << "\n";
    for (auto a : sol) {
        cout << a << " ";
    }

    return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    if (great.size() > 0) sol[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * (i + 1) > n - 1) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[(int)great.size() - 1 - i];
        great[(int)great.size() - 1 - i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    if (smal.size() > 0) {
        for (int p = fpos; p < n - (great.size() > 0); ++p) {
            sol[p] = smal[i];
            smal[i] = -1;
            i++;
        }
        //cout << sol << endl;
        int ind = smal.size() - 1;
        for (int j = 0; j < n; j += d + 1) {
            if (j > n - (d + 1)) break;
            if (i - (d + 1) < 0 || smal[i] == -1) break;
            if (sol[j] <= m || sol[j] == -1) continue;
            ll eqsum = 0;
            while (eqsum < sol[j] && i - (d + 1) >= 0 && smal[ind] != -1) {
                for (int w = 0; w < d + 1; ++w) eqsum += smal[ind - w];
                ind -= (d + 1);
            }
            if (sol[j] < eqsum) {
                ind += (d + 1);
                for (int w = 0; w < d + 1; ++w) {
                    sol[j + w] = smal[ind - w];
                    smal[ind - w] = -1;
                }
                ind -= (d + 1);
            }
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout << fill() << "\n";
    /*for (auto a : sol) {
        cout << a << " ";
    }*/

    return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    if (great.size() > 0) sol[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * (i + 1) > n - 1) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[1 + i];
        great[1 + i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    if (smal.size() > 0) {
        for (int p = fpos; p < n - (great.size() > 0); ++p) {
            sol[p] = smal[i];
            smal[i] = -1;
            i++;
        }
        //cout << sol << endl;
        for (int j = 0; j < n; j += d + 1) {
            if (j > n - (d + 1)) break;
            if ((int)smal.size() - i < d + 1) break;
            if (sol[j] <= m || sol[j] == -1) break;
            ll eqsum = 0;
            for (int w = 0; w < d + 1; ++w) eqsum += smal[i + w];
            if (sol[j] < eqsum) {
                for (int w = 0; w < d + 1; ++w) {
                    sol[j + w] = smal[i + w];
                    smal[i + w] = -1;
                }
                i += d + 1;
            }
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout << fill() << "\n";
    /*for (auto a : sol) {
        cout << a << " ";
    }*/

    return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    if (great.size() > 0) great[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * i > n - (d + 1)) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[(int)great.size() - 1 - i];
        great[(int)great.size() - 1 - i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    for (int p = fpos; p < n - 1; ++p) {
        sol[p] = smal[i];
        smal[i] = -1;
        i++;
    }
    //cout << sol << endl;
    vi rem;
    for (int j = 0; j < n; j += d + 1) {
        if (j > n - (d + 1)) break;
        if ((int)smal.size() - i < d + 1) break;
        if (sol[j] <= m) break;
        int eqsum = 0;
        for (int w = 0; w < d + 1; ++w) eqsum += smal[i + w];
        if (sol[j] < eqsum) {
            rem.push_back(sol[j]);
            for (int w = 0; w < d + 1; ++w) {
                sol[j + w] = smal[i + w];
                smal[i + w] = -1;
            }
            i += d + 1;
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout << fill() << "\n";
    /*for (auto a : sol) {
        cout << a << " ";
    }*/

    return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    if (great.size() > 0) sol[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * i > n - (d + 1)) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[(int)great.size() - 1 - i];
        great[(int)great.size() - 1 - i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    for (int p = fpos; p < n - 1; ++p) {
        sol[p] = smal[i];
        smal[i] = -1;
        i++;
    }
    //cout << sol << endl;
    vi rem;
    for (int j = 0; j < n; j += d + 1) {
        if (j > n - (d + 1)) break;
        if ((int)smal.size() - i < d + 1) break;
        if (sol[j] <= m) break;
        int eqsum = 0;
        for (int w = 0; w < d + 1; ++w) eqsum += smal[i + w];
        if (sol[j] < eqsum) {
            rem.push_back(sol[j]);
            for (int w = 0; w < d + 1; ++w) {
                sol[j + w] = smal[i + w];
                smal[i + w] = -1;
            }
            i += d + 1;
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout << fill() << "\n";
    /*for (auto a : sol) {
        cout << a << " ";
    }*/

    return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    if (great.size() > 0) sol[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * i > n - (d + 1)) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[(int)great.size() - 1 - i];
        great[(int)great.size() - 1 - i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    if (smal.size() > 0) {
        for (int p = fpos; p < n - 1; ++p) {
            sol[p] = smal[i];
            smal[i] = -1;
            i++;
        }
        //cout << sol << endl;
        vi rem;
        for (int j = 0; j < n; j += d + 1) {
            if (j > n - (d + 1)) break;
            if ((int)smal.size() - i < d + 1) break;
            if (sol[j] <= m) break;
            int eqsum = 0;
            for (int w = 0; w < d + 1; ++w) eqsum += smal[i + w];
            if (sol[j] < eqsum) {
                rem.push_back(sol[j]);
                for (int w = 0; w < d + 1; ++w) {
                    sol[j + w] = smal[i + w];
                    smal[i + w] = -1;
                }
                i += d + 1;
            }
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout << fill() << "\n";
    /*for (auto a : sol) {
        cout << a << " ";
    }*/

    return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    if (great.size() > 0) sol[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * i > n - (d + 1)) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[(int)great.size() - 1 - i];
        great[(int)great.size() - 1 - i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    if (smal.size() > 0) {
        for (int p = fpos; p<n - (great.size()> 0); ++p) {
            sol[p] = smal[i];
            smal[i] = -1;
            i++;
        }
        //cout << sol << endl;
        vi rem;
        for (int j = 0; j < n; j += d + 1) {
            if (j > n - (d + 1)) break;
            if ((int)smal.size() - i < d + 1) break;
            if (sol[j] <= m) break;
            int eqsum = 0;
            for (int w = 0; w < d + 1; ++w) eqsum += smal[i + w];
            if (sol[j] < eqsum) {
                rem.push_back(sol[j]);
                for (int w = 0; w < d + 1; ++w) {
                    sol[j + w] = smal[i + w];
                    smal[i + w] = -1;
                }
                i += d + 1;
            }
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout << fill() << "\n";
    /**for (auto a : sol) {
        cout << a << " ";
    }*/

    return 0;
}


//  D.cpp
//  Created by David del Val on 12/08/2020
//
//

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
//gcd(0, n) = n
inline long long _gcd(long long a, long long b) {
    while (b) b %= a ^= b ^= a ^= b;
    return a;
}
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
inline pii operator+(pii a, pii b) {
    return {a.fi + b.fi, a.se + b.se};
}

inline ostream& operator<<(ostream& o, pii p) {
    o << p.fi << " " << p.se;
    return o;
}

template <typename>
struct is_std_vector : std::false_type {};
template <typename T, typename A>
struct is_std_vector<std::vector<T, A>> : std::true_type {};

template <typename T>
inline ostream& operator<<(ostream& o, vector<T>& p) {
    for (int i = 0; i < p.size(); ++i) {
        o << setw(3) << p[i];
        if (is_std_vector<T>::value) o << "\n";
    }
    return o;
}

#ifdef _LOCAL_
//Local constraints

#else
// Judge constraints
#endif

const int lim = 1e5 + 10;
int n, d, m;
vi great;
vi smal;
vi sol;

ll fill() {
    sol[n - 1] = great[0];
    int fpos = 0;
    for (int i = 0; i < (int)great.size() - 1; ++i) {
        if ((d + 1) * i > n - (d + 1)) break;
        //cout << (int)great.size() - 1 - i<<endl;
        sol[(d + 1) * i] = great[(int)great.size() - 1 - i];
        great[(int)great.size() - 1 - i] = -1;
        fpos = (d + 1) * (i + 1);
    }
    int i = 0;
    //cout << smal<<endl;
    //cout << sol<<endl;
    for (int p = fpos; p < n - 1; ++p) {
        sol[p] = smal[i];
        smal[i] = -1;
        i++;
    }
    //cout << sol << endl;
    vi rem;
    for (int j = 0; j < n; j += d + 1) {
        if (j > n - (d + 1)) break;
        if ((int)smal.size() - i < d + 1) break;
        if (sol[j] <= m) break;
        int eqsum = 0;
        for (int w = 0; w < d + 1; ++w) eqsum += smal[i + w];
        if (sol[j] < eqsum) {
            rem.push_back(sol[j]);
            for (int w = 0; w < d + 1; ++w) {
                sol[j + w] = smal[i + w];
                smal[i + w] = -1;
            }
            i += d + 1;
        }
    }
    ll cnt = 0;
    for (int i = 0; i < n;++i){
        if (sol[i] != -1) cnt += sol[i];
    }
    return cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> d >> m;

    great = vi();
    smal = vi();
    great.reserve(n);
    smal.reserve(n);
    sol = vi(n, -1);
    int a;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        if (a > m) {
            great.push_back(a);
        } else {
            smal.push_back(a);
        }
    }
    sort(all(great), greater<int>());
    sort(all(smal), greater<int>());
    //cout << great << endl;
    //cout << smal << endl;
    cout<<fill()<<"\n";
    /*for (auto a : sol) {
        cout << a << " ";
    }*/

    return 0;
}