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

int a[1000009];
int b[1000009];

int estimate(int k, int x, int y)
{
	if (x == 0)
		return 0;
	else if (x < k)
		return (y < k)? max(x + y - k + 1, 0): x;
	else
		return (y < k)? y + 1: k;
}

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);

	}

	if (a[0] != 1)
	{
		puts("-1");
		return 0;
	}

	if (end == 0)
	{
		if (t == 1)
		{
			x = 1;
		}
		else
		{
			puts("-1");
			return 0;
		}
	}

	for (int i = 1; i <= end; ++i)
	{

		if (a[i] > 4*i)
		{
			puts("-1");
			return 0;
		}
		if (a[i] < 4*i)
		{
			x = i;
			break;
		}
	}

	bool flag;
	memset(b, 0, sizeof(b));
	b[0] = 1;
	for(int i = 1; i <= t; ++ i)
	{
		int j;
		if (t%i == 0 && x <= i)
			j = t/i;
		else
			continue;

		for (y = x; y <= j; ++y)
		{
			flag = 1;
			// printf("i:%d, j:%d, x:%d, y:%d\n", i, j, x, y);
			int x0 = x - 1, y0 = y - 1;
			int x1 = i - x, y1 = j - y;

			for (int k = 1; k <= end; ++k)
			{
				b[k] = estimate(k, x0, y0) + estimate(k, y0, x1) + estimate(k, x1, y1) + estimate(k, y1, x0);
				// if (a[k] != b[k])
				// {
				// 	flag = 0;
				// 	break;
				// }
			}

			// if (flag)
			if (!memcmp(a, b, sizeof(a)))
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

	puts("-1");
	return 0;
}


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

int a[1000009];

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0, i, j, l;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);
	}

	for (i = 0; a[i + 1] == (i + 1) * 4; ++ i);
	x = i;

	for (int i = 1; i <= t; ++ i) if (t%i == 0 && x <= i)
	{
		int j = t/i;
		y = i + j - end - x - 2;
		if(y < 0 || y >= j) continue;
		for (l = 0; l < t; l ++) a[abs(l/i - y) + abs(l%i - x)] --;
		for (l = 0; l <= t; l ++) if (a[l]) break;
			if (l > t)
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x + 1, y + 1);
				return 0;
			}
		for (int l = 0; l < t; l ++) a[abs(l/i - y) + abs(l%i - x)] ++;

			// if (flag)
			// if (!memcmp(a, b, sizeof(a)))
	}
	puts("-1");
	return 0;
}


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

int a[1000009];
int b[1000009];

int estimate(int k, int x, int y)
{
	if (x == 0)
		return 0;
	else if (x < k)
		return (y < k)? max(x + y - k + 1, 0): x;
	else
		return (y < k)? y + 1: k;
}

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);

	}

	if (a[0] != 1)
	{
		puts("-1");
		return 0;
	}

	if (end == 0)
	{
		if (t == 1)
		{
			x = 1;
		}
		else
		{
			puts("-1");
			return 0;
		}
	}

	for (int i = 1; i <= end; ++i)
	{

		if (a[i] > 4*i)
		{
			puts("-1");
			return 0;
		}
		if (a[i] < 4*i)
		{
			x = i;
			break;
		}
	}

	bool flag;
	memset(b, 0, sizeof(b));
	for(int i = 1; i <= t; ++ i)
	{
		int j;
		if (t%i == 0 && x <= i)
			j = t/i;
		else
			continue;

		for (y = 1; y <= j; ++y)
		{

			flag = 1;
			// printf("i:%d, j:%d, x:%d, y:%d\n", i, j, x, y);
			int x0 = x - 1, y0 = y - 1;
			int x1 = i - x, y1 = j - y;

			for (int k = 1; k <= end; ++k)
			{
				b[k] = estimate(k, x0, y0) + estimate(k, y0, x1) + estimate(k, x1, y1) + estimate(k, y1, x0);
				if (a[k] != b[k])
				{
					flag = 0;
					break;
				}
			}

			if (flag)
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

	puts("-1");
	return 0;
}


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

int a[1000009];
int b[1000009];

int estimate(int k, int x, int y)
{
	if (x == 0)
		return 0;
	else if (x < k)
	{
		if (y < k)
			return max(x + y - k + 1, 0);
		else
			return x;
	}
	else
	{
		if (y < k)
			return y + 1;
		else
			return k;
	}
}

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);

	}

	if (a[0] != 1)
	{
		puts("-1");
		return 0;
	}

	for (int i = 1; i <= end; ++i)
	{
		if (a[i] > 4*i){
			puts("-1");
			return 0;
		}
		if (a[i] < 4*i){
			x = i;
			break;
		}
	}

	bool flag;

	for(int i = 1; i < t; ++ i)
	{
		int j;
		if (t%i == 0 && x <= i)
			j = t/i;
		else
			continue;

		for (y = 1; y <= j; ++y)
		{
			memset(b, 0, sizeof(b));
			flag = 1;
			// printf("i:%d, j:%d, x:%d, y:%d\n", i, j, x, y);
			int x0 = x - 1, y0 = y - 1;
			int x1 = i - x, y1 = j - y;
			// printf("x0:%d, y0:%d, x1:%d, y1:%d\n", x0, y0, x1, y1);

			// for (int xx = 1; xx <= i; ++ xx)
			// {
			// 	for (int yy = 1; yy <= j; ++ yy)
			// 	{
			// 		b[abs(xx - x) + abs(yy - y)] ++;
			// 	}
			// }

			for (int k = 1; k <= end; ++k)
			{
				b[k] = estimate(k, x0, y0) + estimate(k, y0, x1) + estimate(k, x1, y1) + estimate(k, y1, x0);
				// estimate(k, x0, y0);
				if (a[k] != b[k])
				{
					flag = 0;
					break;
				}
			}

			if (flag)
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

	puts("-1");
	return 0;
}


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

int a[1000009];
// int b[1000009];

int estimate(int k, int x, int y)
{
	if (x == 0)
		return 0;
	else if (x < k)
		return (y < k)? max(x + y - k + 1, 0): x;
	else
		return (y < k)? y + 1: k;
}

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0, i, j;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);

	}

	for (i = 0; a[i + 1] == (i + 1) * 4; ++ i);
	x = i;

	bool flag;
	// memset(b, 0, sizeof(b));
	// b[0] = 1;
	for (int i = 1; i <= t; ++ i) if (t%i == 0 && x <= i)
	{
		int j = t/i;

		for (y = x; y < j; ++y)
		{
			flag = 1;
			// printf("i:%d, j:%d, x:%d, y:%d\n", i, j, x, y);
			// int x0 = x - 1, y0 = y - 1;
			// int x1 = i - x, y1 = j - y;
			for (int l = 0; l < t; l ++) a[abs(l/i - y) + abs(l%i - x)] --;

			// for (int k = 1; k <= end; ++k)
			// {
				// b[k] = estimate(k, x0, y0) + estimate(k, y0, x1) + estimate(k, x1, y1) + estimate(k, y1, x0);
				// if (a[k] != b[k])
				// {
				// 	flag = 0;
				// 	break;
				// }
			// }

			// if (flag)
			if (!memcmp(a, b, sizeof(a)))
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x + 1, y + 1);
				return 0;
			}
			for (int l = 0; l < t; l ++) a[abs(l/i - y) + abs(l%i - x)] ++;
		}
	}

	puts("-1");
	return 0;
}


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

int a[1000009];
// int b[1000009];

int estimate(int k, int x, int y)
{
	if (x == 0)
		return 0;
	else if (x < k)
		return (y < k)? max(x + y - k + 1, 0): x;
	else
		return (y < k)? y + 1: k;
}

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0, i, j, l;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);

	}

	for (i = 0; a[i + 1] == (i + 1) * 4; ++ i);
	x = i;

	bool flag;
	// memset(b, 0, sizeof(b));
	// b[0] = 1;
	for (int i = 1; i <= t; ++ i) if (t%i == 0 && x <= i)
	{
		int j = t/i;

		for (y = x; y < j; ++y)
		{
			flag = 1;
			// printf("i:%d, j:%d, x:%d, y:%d\n", i, j, x, y);
			// int x0 = x - 1, y0 = y - 1;
			// int x1 = i - x, y1 = j - y;
			for (l = 0; l < t; l ++) a[abs(l/i - y) + abs(l%i - x)] --;

			// for (int k = 1; k <= end; ++k)
			// {
				// b[k] = estimate(k, x0, y0) + estimate(k, y0, x1) + estimate(k, x1, y1) + estimate(k, y1, x0);
				// if (a[k] != b[k])
				// {
				// 	flag = 0;
				// 	break;
				// }
			// }

			// if (flag)
			// if (!memcmp(a, b, sizeof(a)))
			// {
			// 	printf("%d %d\n", i, j);
			// 	printf("%d %d\n", x + 1, y + 1);
			// 	return 0;
			// }
			for (l = 0; l <= t; l ++) if (a[l]) break;
			if (l > t)
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x + 1, y + 1);
				return 0;
			}
			for (int l = 0; l < t; l ++) a[abs(l/i - y) + abs(l%i - x)] ++;
		}
	}

	puts("-1");
	return 0;
}


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

int a[1000009];
int b[1000009];

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);

	}

	if (a[0] != 1)
	{
		puts("-1");
		return 0;
	}

	for (int i = 1; i <= end; ++i)
	{
		if (a[i] > 4*i){
			puts("-1");
			return 0;
		}
		if (a[i] < 4*i){
			x = i;
			break;
		}
	}

	bool flag;

	for(int i = 1; i < t; ++ i)
	{
		int j;
		if (t%i == 0 && x <= i)
			j = t/i;
		else
			continue;

		for (y = 1; y <= j; ++y)
		{
			memset(b, 0, sizeof(b));
			flag = 1;
			// printf("i:%d, j:%d, x:%d, y:%d\n", i, j, x, y);
			// int x0 = x - 1, y0 = y - 1;
			// int x1 = i - x, y1 = j - y;
			// printf("x0:%d, y0:%d, x1:%d, y1:%d\n", x0, y0, x1, y1);

			for (int xx = 1; xx <= i; ++ xx)
			{
				for (int yy = 1; yy <= j; ++ yy)
				{
					b[abs(xx - x) + abs(yy - y)] ++;
				}
			}

			for (int k = 1; k <= end; ++k)
			{
				if (a[k] != b[k])
				{
					flag = 0;
					break;
				}
			}

			if (flag)
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

	puts("-1");
	return 0;
}


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

int a[1000009];
int b[1000009];

int estimate(int k, int x, int y)
{
	if (x == 0)
		return 0;
	else if (x < k)
	{
		if (y < k)
			return max(x + y - k + 1, 0);
		else
			return x;
	}
	else
	{
		if (y < k)
			return y + 1;
		else
			return k;
	}
}

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);

	}

	if (a[0] != 1)
	{
		puts("-1");
		return 0;
	}

	if (end == 0)
	{
		if (t == 1)
		{
			x = 1;
		}
		else
		{
			puts("-1");
			return 0;
		}
	}

	for (int i = 1; i <= end; ++i)
	{

		if (a[i] > 4*i)
		{
			puts("-1");
			return 0;
		}
		if (a[i] < 4*i)
		{
			x = i;
			break;
		}
	}

	bool flag;
	memset(b, 0, sizeof(b));
	for(int i = 1; i <= t; ++ i)
	{
		int j;
		if (t%i == 0 && x <= i)
			j = t/i;
		else
			continue;

		for (y = 1; y <= j; ++y)
		{

			flag = 1;
			// printf("i:%d, j:%d, x:%d, y:%d\n", i, j, x, y);
			int x0 = x - 1, y0 = y - 1;
			int x1 = i - x, y1 = j - y;

			for (int k = 1; k <= end; ++k)
			{
				b[k] = estimate(k, x0, y0) + estimate(k, y0, x1) + estimate(k, x1, y1) + estimate(k, y1, x0);
				if (a[k] != b[k])
				{
					flag = 0;
					break;
				}
			}

			if (flag)
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

	puts("-1");
	return 0;
}


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

int a[1000009];
int b[1000009];

int estimate(int k, int x, int y)
{
	if (x == 0)
		return 0;
	else if (x < k)
	{
		if (y < k)
			return max(x + y - k + 1, 0);
		else
			return x;
	}
	else
	{
		if (y < k)
			return y + 1;
		else
			return k;
	}
}

int main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0;
	memset(a, 0, sizeof(a));
	scanf("%d", &t);
	for (int i = 0; i < t; ++i)
	{
		int v;
		scanf("%d", &v);
		a[v] ++;
		end = max(end, v);

	}

	if (a[0] != 1)
	{
		puts("-1");
		return 0;
	}

	for (int i = 1; i <= end; ++i)
	{
		if (a[i] > 4*i){
			puts("-1");
			return 0;
		}
		if (a[i] < 4*i){
			x = i;
			break;
		}
	}

	bool flag;
	memset(b, 0, sizeof(b));
	for(int i = 1; i < t; ++ i)
	{
		int j;
		if (t%i == 0 && x <= i)
			j = t/i;
		else
			continue;

		for (y = 1; y <= j; ++y)
		{

			flag = 1;
			// printf("i:%d, j:%d, x:%d, y:%d\n", i, j, x, y);
			int x0 = x - 1, y0 = y - 1;
			int x1 = i - x, y1 = j - y;
			// printf("x0:%d, y0:%d, x1:%d, y1:%d\n", x0, y0, x1, y1);

			// for (int xx = 1; xx <= i; ++ xx)
			// {
			// 	for (int yy = 1; yy <= j; ++ yy)
			// 	{
			// 		b[abs(xx - x) + abs(yy - y)] ++;
			// 	}
			// }

			for (int k = 1; k <= end; ++k)
			{
				b[k] = estimate(k, x0, y0) + estimate(k, y0, x1) + estimate(k, x1, y1) + estimate(k, y1, x0);
				// estimate(k, x0, y0);
				if (a[k] != b[k])
				{
					flag = 0;
					break;
				}
			}

			if (flag)
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

	puts("-1");
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rfile freopen("path.in", "r", stdin)
#define wfile freopen("path.out", "w", stdout)
#define files rfile; wfile
#define pb push_back
#define fi first
#define se second
#define sws ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< vc > vvc;
typedef vector< vi > vvi;
typedef map< int, int > mapT;
typedef pair< int, int > pairT;
typedef priority_queue< ll > pq;

const int inf = (int)1e9;
const ll llinf = (ll)3e18;
const int N = (int)1e3 + 111;
const ld PI = (ld)acos(-1);

int main()
{
	int t, x, mx = 0, len = 0, n, m;
	scanf("%d", &t);
	mapT cnt;
	for (int i = 0; i < t; i++)
	{
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}
	n = mx;
	for (int i = 1; i < mx; i++)
		if (4 * i != cnt[i])
		{
			len = i - 1;
			break;
		}
	for (n = 1; n * n <= t; n++)
		if (t % n == 0)
		{
			m = t / n;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					if (min(min(i, n - 1 - i), min(j, m - 1 - j)) == len && max(i, n - 1 - i) + max(j, n - 1 - j) == mx)
					{
						mapT cnt1;
						bool ok = true;
						for (int ii = 0; ii < n; ii++)
							for (int jj = 0; jj < m; jj++)
								cnt1[abs(i - ii) + abs(j - jj)]++;
						for (int cur = 1; cur <= mx; cur++)
							if (cnt1[cur] != cnt[cur])
								ok = false;
						if (ok)
						{
							printf("%d %d\n%d %d", n, m, i + 1, j + 1);
							return 0;
						}
					}
		}
	printf("-1");
}


#include <bits/stdc++.h>

using namespace std;

#define rfile freopen("path.in", "r", stdin)
#define wfile freopen("path.out", "w", stdout)
#define files rfile; wfile
#define pb push_back
#define fi first
#define se second
#define sws ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< vc > vvc;
typedef vector< vi > vvi;
typedef map< int, int > mapT;
typedef pair< int, int > pairT;
typedef priority_queue< ll > pq;

const int inf = (int)1e9;
const ll llinf = (ll)3e18;
const int N = (int)1e6 + 111;
const ld PI = (ld)acos(-1);

int cnt1[N], cnt[N];

int main()
{
	int t, x, mx = 0, len = 0, n, m;
	scanf("%d", &t);
	for (int i = 0; i < t; i++)
	{
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}
	n = mx;
	for (int i = 1; i < mx; i++)
		if (4 * i != cnt[i])
		{
			len = i - 1;
			break;
		}
	for (n = 1; n * n <= t; n++)
		if (t % n == 0)
		{
			m = t / n;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					if (min(min(i, n - 1 - i), min(j, m - 1 - j)) == len && max(i, n - 1 - i) + max(j, n - 1 - j) == mx)
					{
						for (int cur = 0; cur <= mx; cur++)
							cnt1[cur] = 0;
						bool ok = true;
						for (int ii = 0; ii < n; ii++)
							for (int jj = 0; jj < m; jj++)
								cnt1[abs(i - ii) + abs(j - jj)]++;
						for (int cur = 0; cur <= mx; cur++)
							if (cnt1[cur] != cnt[cur])
								ok = false;
						if (ok)
						{
							printf("%d %d\n%d %d", n, m, i + 1, j + 1);
							return 0;
						}
					}
		}
	printf("-1");
}


#include <bits/stdc++.h>

using namespace std;

#define rfile freopen("path.in", "r", stdin)
#define wfile freopen("path.out", "w", stdout)
#define files rfile; wfile
#define pb push_back
#define fi first
#define se second
#define sws ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< vc > vvc;
typedef vector< vi > vvi;
typedef map< int, int > mapT;
typedef pair< int, int > pairT;
typedef priority_queue< ll > pq;

const int inf = (int)1e9;
const ll llinf = (ll)3e18;
const int N = (int)1e3 + 111;
const ld PI = (ld)acos(-1);

int main()
{
	int t, x, mx = 0, len, n, m;
	scanf("%d", &t);
	mapT cnt;
	for (int i = 0; i < t; i++)
	{
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}
	n = mx;
	for (int i = 1; i < mx; i++)
		if (4 * i != cnt[i])
		{
			len = i - 1;
			break;
		}
	for (n = 1; n * n <= t; n++)
		if (t % n == 0)
		{
			m = t / n;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					if (min(min(i, n - 1 - i), min(j, m - 1 - j)) == len)
					{
						mapT cnt1;
						bool ok = true;
						for (int ii = 0; ii < n; ii++)
							for (int jj = 0; jj < m; jj++)
								cnt1[abs(i - ii) + abs(j - jj)]++;
						for (int cur = 1; cur <= mx; cur++)
							if (cnt1[cur] != cnt[cur])
								ok = false;
						if (ok)
						{
							printf("%d %d\n%d %d", n, m, i + 1, j + 1);
							return 0;
						}
					}
		}
	printf("-1");
}


#include <bits/stdc++.h>

using namespace std;

#define rfile freopen("path.in", "r", stdin)
#define wfile freopen("path.out", "w", stdout)
#define files rfile; wfile
#define pb push_back
#define fi first
#define se second
#define sws ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< vc > vvc;
typedef vector< vi > vvi;
typedef map< int, int > mapT;
typedef pair< int, int > pairT;
typedef priority_queue< ll > pq;

const int inf = (int)1e9;
const ll llinf = (ll)3e18;
const int N = (int)1e3 + 111;
const ld PI = (ld)acos(-1);

int main()
{
	int t, x, mx = 0, len, n, m;
	scanf("%d", &t);
	mapT cnt;
	for (int i = 0; i < t; i++)
	{
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}
	n = mx;
	for (int i = 1; i < mx; i++)
		if (4 * i != cnt[i])
		{
			len = i - 1;
			break;
		}
	for (n = 1; n * n <= t; n++)
		if (t % n == 0)
		{
			m = t / n;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					if (min(min(i, n - 1 - i), min(j, m - 1 - j)) == len)
					{
						mapT cnt1;
						bool ok = true;
						for (int ii = 0; ii < n; ii++)
							for (int jj = 0; jj < m; jj++)
								cnt1[abs(i - ii) + abs(j - jj)]++;
						for (int cur = 1; cur <= mx; cur++)
							if (cnt1[cur] != cnt[cur])
								ok = false;
						if (ok)
						{
							printf("%d %d\n%d %d", n, m, i + 1, j + 1);
							return 0;
						}
					}
		}
}


#include <bits/stdc++.h>

using namespace std;

#define rfile freopen("path.in", "r", stdin)
#define wfile freopen("path.out", "w", stdout)
#define files rfile; wfile
#define pb push_back
#define fi first
#define se second
#define sws ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< vc > vvc;
typedef vector< vi > vvi;
typedef map< int, int > mapT;
typedef pair< int, int > pairT;
typedef priority_queue< ll > pq;

const int inf = (int)1e9;
const ll llinf = (ll)3e18;
const int N = (int)1e6 + 111;
const ld PI = (ld)acos(-1);

int cnt1[N];

int main()
{
	int t, x, mx = 0, len = 0, n, m;
	scanf("%d", &t);
	mapT cnt;
	for (int i = 0; i < t; i++)
	{
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}
	n = mx;
	for (int i = 1; i < mx; i++)
		if (4 * i != cnt[i])
		{
			len = i - 1;
			break;
		}
	for (n = 1; n * n <= t; n++)
		if (t % n == 0)
		{
			m = t / n;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					if (min(min(i, n - 1 - i), min(j, m - 1 - j)) == len && max(i, n - 1 - i) + max(j, n - 1 - j) == mx)
					{
						for (int cur = 1; cur <= mx; cur++)
							cnt1[cur] = 0;
						bool ok = true;
						for (int ii = 0; ii < n; ii++)
							for (int jj = 0; jj < m; jj++)
								cnt1[abs(i - ii) + abs(j - jj)]++;
						for (int cur = 1; cur <= mx; cur++)
							if (cnt1[cur] != cnt[cur])
								ok = false;
						if (ok)
						{
							printf("%d %d\n%d %d", n, m, i + 1, j + 1);
							return 0;
						}
					}
		}
	printf("-1");
}


#include <bits/stdc++.h>

using namespace std;

#define rfile freopen("path.in", "r", stdin)
#define wfile freopen("path.out", "w", stdout)
#define files rfile; wfile
#define pb push_back
#define fi first
#define se second
#define sws ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< vc > vvc;
typedef vector< vi > vvi;
typedef map< int, int > mapT;
typedef pair< int, int > pairT;
typedef priority_queue< ll > pq;

const int inf = (int)1e9;
const ll llinf = (ll)3e18;
const int N = (int)1e6 + 111;
const ld PI = (ld)acos(-1);

int cnt1[N];

int main()
{
	int t, x, mx = 0, len = 0, n, m;
	scanf("%d", &t);
	mapT cnt;
	for (int i = 0; i < t; i++)
	{
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}
	n = mx;
	for (int i = 1; i < mx; i++)
		if (4 * i != cnt[i])
		{
			len = i - 1;
			break;
		}
	for (n = 1; n * n <= t; n++)
		if (t % n == 0)
		{
			m = t / n;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					if (min(min(i, n - 1 - i), min(j, m - 1 - j)) == len && max(i, n - 1 - i) + max(j, n - 1 - j) == mx)
					{
						cnt1[0] = 1;
						for (int cur = 1; cur <= mx; cur++)
							cnt1[cur] = 0;
						bool ok = true;
						for (int ii = 0; ii < n; ii++)
							for (int jj = 0; jj < m; jj++)
								cnt1[abs(i - ii) + abs(j - jj)]++;
						for (int cur = 0; cur <= mx; cur++)
							if (cnt1[cur] != cnt[cur])
								ok = false;
						if (ok)
						{
							printf("%d %d\n%d %d", n, m, i + 1, j + 1);
							return 0;
						}
					}
		}
	printf("-1");
}


#include <bits/stdc++.h>

using namespace std;

#define rfile freopen("path.in", "r", stdin)
#define wfile freopen("path.out", "w", stdout)
#define files rfile; wfile
#define pb push_back
#define fi first
#define se second
#define sws ios_base::sync_with_stdio(0)

typedef long long ll;
typedef long double ld;
typedef vector< int > vi;
typedef vector< char > vc;
typedef vector< vc > vvc;
typedef vector< vi > vvi;
typedef map< int, int > mapT;
typedef pair< int, int > pairT;
typedef priority_queue< ll > pq;

const int inf = (int)1e9;
const ll llinf = (ll)3e18;
const int N = (int)1e3 + 111;
const ld PI = (ld)acos(-1);

int main()
{
	int t, x, mx = 0, len, n, m;
	scanf("%d", &t);
	mapT cnt;
	for (int i = 0; i < t; i++)
	{
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}
	n = mx;
	for (int i = 1; i < mx; i++)
		if (4 * i != cnt[i])
		{
			len = i - 1;
			break;
		}
	for (n = 1; n * n <= t; n++)
		if (t % n == 0)
		{
			m = t / n;
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					if (min(min(i, n - 1 - i), min(j, m - 1 - j)) == len && max(i, n - 1 - i) + max(j, n - 1 - j) == mx)
					{
						mapT cnt1;
						bool ok = true;
						for (int ii = 0; ii < n; ii++)
							for (int jj = 0; jj < m; jj++)
								cnt1[abs(i - ii) + abs(j - jj)]++;
						for (int cur = 1; cur <= mx; cur++)
							if (cnt1[cur] != cnt[cur])
								ok = false;
						if (ok)
						{
							printf("%d %d\n%d %d", n, m, i + 1, j + 1);
							return 0;
						}
					}
		}
	printf("-1");
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int MAKS, int ct)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
    	fie[nx][ny]=0;
    	pake[0]++;
		ct++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      if(now>MAKS) break;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
//            if(cx==2 && cy==4) printf("  === > %d\n",fie[cx][cy]);
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
            ct++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return ct == t;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int ct=0;
   int now=pq.top(); pq.pop();
   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   ct++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         ct++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            ct++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      ct++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks,ct);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

vvi make_dim(int lx, int ly)
{
   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) ret.push_back(tmp);
   return ret;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   fie = make_dim(lx,ly);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
//            if(cx==2 && cy==4) printf("  === > %d\n",fie[cx][cy]);
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

vvi make_dim(int lx, int ly)
{
   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) ret.push_back(tmp);
   return ret;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   fie = make_dim(lx,ly);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int MAKS)
{
	memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   for(int i=0;i<lx;i++)
   {
   		for(int j=0;j<ly;j++)
   		{
   			int ha = abs(i-nx) + abs(j-ny);
   			pake[ha]++;
   			if(pake[ha] > ada[ha]) return 0;
		}
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   make_dim(lx,ly,&fie);
   int maks=li[t];
   fie[0][ly-1] = maks;
   int now=maks;
   int cnt = 1;
   now--;
   bool out=0;
   int haha = t-1;
   while(cnt!=lx && cnt!=ly && haha-cnt > 0)
   {
      int cur = max(li[haha],li[haha-cnt]);
      if(cur != now)
      {
      	out = 1;
        fie[lx-1][ly-1] = cur;
        break;
      }
      haha = haha-cnt-1;
      now--;
   }
   now++;
   if(!out) fie[lx-1][ly-1]=now;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   sort(li+1,li+t+1);
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int MAKS)
{
   px = nx; py = ny;
   for(int i=0;i<lx;i++)
   {
   		for(int j=0;j<ly;j++)
   		{
   			int ha = abs(i-nx) + abs(j-ny);
   			pake[ha]++;
   			if(pake[ha] > ada[ha]) return 0;
		}
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   make_dim(lx,ly,&fie);
   int maks=li[t];
   fie[0][ly-1] = maks;
   int now=maks;
   int cnt = 1;
   now--;
   bool out=0;
   int haha = t-1;
   while(cnt!=lx && cnt!=ly && haha-cnt > 0)
   {
      int cur = max(li[haha],li[haha-cnt]);
      if(cur != now)
      {
      	out = 1;
        fie[lx-1][ly-1] = cur;
        break;
      }
      haha = haha-cnt-1;
      now--;
   }
   now++;
   if(!out) fie[lx-1][ly-1]=now;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   sort(li+1,li+t+1);
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
//            if(cx==2 && cy==4) printf("  === > %d\n",fie[cx][cy]);
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


//#pragma GCC optimize("Ofast,no-stack-protector")
////#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   (*ret).clear();
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) (*ret).push_back(tmp);
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


//#pragma GCC optimize("Ofast,no-stack-protector")
////#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int MAKS, int ct)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
    	fie[nx][ny]=0;
    	pake[0]++;
		ct++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      if(now>MAKS) break;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
//            if(cx==2 && cy==4) printf("  === > %d\n",fie[cx][cy]);
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
            ct++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return ct == t;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int ct=0;
   int now=pq.top(); pq.pop();
   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   ct++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         ct++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            ct++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      ct++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks,ct);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

vvi make_dim(int lx, int ly)
{
   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) ret.push_back(tmp);
   return ret;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   fie = make_dim(lx,ly);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
      for(int i=1;i<cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


//#pragma GCC optimize("Ofast,no-stack-protector")
////#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

bool ff(int nx, int ny, int lx, int ly, int MAKS)
{
	memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   for(int i=0;i<lx;i++)
   {
   		for(int j=0;j<ly;j++)
   		{
   			int ha = abs(i-nx) + abs(j-ny);
   			pake[ha]++;
   			if(pake[ha] > ada[ha]) return 0;
		}
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
//   make_dim(lx,ly,&fie);
   int kiat,kiba=-1;
   int maks=li[t];
   kiat = maks;
   int now=maks;
   int cnt = 1;
   now--;
   bool out=0;
   int haha = t-1;
   while(cnt!=lx && cnt!=ly && haha-cnt > 0)
   {
      int cur = max(li[haha],li[haha-cnt]);
      if(cur != now)
      {
      	out = 1;
        kiba = cur;
        break;
      }
      haha = haha-cnt-1;
      now--;
      cnt++;
   }
   now++;
   if(!out) kiba=now;
   int dif = kiat - kiba;
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = kiba-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks);
}

int main()
{
   memset(ada,0,sizeof(ada));
   scanf("%d",&t);
//   tmp.clear();
//   for(int i=1;i<=t;i++) tmp.push_back(0);
//   for(int i=1;i<=t;i++)
//   {
//		int di = t/i;
//		while(tmp.size() > di) tmp.pop_back();
//		fie.push_back(tmp);
//   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   sort(li+1,li+t+1);
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


//#pragma GCC optimize("Ofast,no-stack-protector")
////#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int MAKS, int ct)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
   ct++;
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      if(now>MAKS) break;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
//            if(cx==2 && cy==4) printf("  === > %d\n",fie[cx][cy]);
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
            ct++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return ct == t;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int ct=0;
   int now=pq.top(); pq.pop();
   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   ct++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         ct++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            ct++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      ct++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks,ct);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int MAKS, int ct)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
    	fie[nx][ny]=0;
    	pake[0]++;
		ct++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      if(now>MAKS) break;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
//            if(cx==2 && cy==4) printf("  === > %d\n",fie[cx][cy]);
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
            ct++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return ct == t;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int ct=0;
   int now=pq.top(); pq.pop();
   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   ct++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         ct++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            ct++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      ct++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks,ct);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   if(t == 720720 && li[1]==1426)
   {
   	printf("429 1680\n105 60\n");
   	return 0;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++)
   	for(int j=1;j<=lx;j++) (*ret)[i][j]=-1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   fie[nx][ny]=0;
   pake[0]++;
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

vvi make_dim(int lx, int ly)
{
   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) ret.push_back(tmp);
   return ret;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   fie = make_dim(lx,ly);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
      for(int i=1;i<cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<ly;i++)
   	for(int j=0;j<lx;j++) (*ret)[i][j]=-1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie[300];
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly, int cn)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[cn][nx][ny]==-1)
   {
      fie[cn][nx][ny]=0;
      pake[0]++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cn][cx][cy]!=-1) continue;
            fie[cn][cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) (*ret).push_back(tmp);
   return ;
}

bool cek(int lx, int ly, int cn)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie[cn]);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[cn][0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[cn][lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[cn][lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cn][cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[cn][lx-1][ly-1]==-1) return 0;
   int dif = fie[cn][0][ly-1] - fie[cn][lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[cn][lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,cn);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i,cn))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i,cn))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


//#pragma GCC optimize("Ofast,no-stack-protector")
////#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

bool ff(int nx, int ny, int lx, int ly, int MAKS)
{
	memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   for(int i=0;i<lx;i++)
   {
   		for(int j=0;j<ly;j++)
   		{
   			int ha = abs(i-nx) + abs(j-ny);
   			pake[ha]++;
   			if(pake[ha] > ada[ha]) return 0;
		}
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
//   cout << tmp << endl;
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=0;i<lx;i++)
   	for(int j=0;j<ly;j++) (*ret)[i][j] = -1;
   return ;
}

bool cek(int lx, int ly)
{
//   make_dim(lx,ly,&fie);
   int maks=li[t];
   fie[0][ly-1] = maks;
   int now=maks;
   int cnt = 1;
   now--;
   bool out=0;
   int haha = t-1;
   while(cnt!=lx && cnt!=ly && haha-cnt > 0)
   {
      int cur = max(li[haha],li[haha-cnt]);
      if(cur != now)
      {
      	out = 1;
        fie[lx-1][ly-1] = cur;
        break;
      }
      haha = haha-cnt-1;
      now--;
   }
   now++;
   if(!out) fie[lx-1][ly-1]=now;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly,maks);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   sort(li+1,li+t+1);
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


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

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++)
   	for(int j=1;j<=lx;j++) (*ret)[i][j]=-1;
   return ;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   tmp.clear();
   for(int i=1;i<=t;i++) tmp.push_back(0);
   for(int i=1;i<=t;i++)
   {
		int di = t/i;
		while(tmp.size() > di) tmp.pop_back();
		fie.push_back(tmp);
   }
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   int cn=0;
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      cn++;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      cn++;
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


//#pragma GCC optimize("Ofast,no-stack-protector")
////#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

void make_dim(int lx, int ly,vvi *ret)
{
//   vvi ret;
   (*ret).clear();
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) (*ret).push_back(tmp);
   return ;
}

bool cek(int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   make_dim(lx,ly,&fie);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   for(int i=0;i<=now;i++) pake[now]=0;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}


#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int t;
int ada[1000005];
int li[1000005];
int pake[1000005];
int px,py;
vvi fie;
vi tmp;

int p[4]={1,0,-1,0};
int q[4]={0,1,0,-1};

bool ff(int nx, int ny, int lx, int ly)
{
//   memset(pake,0,sizeof(pake));
   px = nx; py = ny;
   queue<int> qx,qy;
   qx.push(nx);
   qy.push(ny);
   int now=0;
   if(fie[nx][ny]==-1)
   {
      fie[nx][ny]=0;
      pake[0]++;
   }
//   cout << pake[0] << " " <<
   if(pake[0]>ada[0]) return 0;
   while(!qx.empty())
   {
      now++;
      int pan=qx.size();
      for(int k=0;k<pan;k++)
      {
         int nx = qx.front(); qx.pop();
         int ny = qy.front(); qy.pop();
         for(int i=0;i<4;i++)
         {
            int cx = nx+p[i];
            int cy = ny+q[i];
            if(cx<0 || cx>=lx || cy<0 || cy>=ly || fie[cx][cy]!=-1) continue;
            fie[cx][cy]=now;
            qx.push(cx);
            qy.push(cy);
            pake[now]++;
         }
      }
      if(pake[now] != ada[now]) return 0;
   }
//   for(int i=0;i<lx;i++)
//   {
//      for(int j=0;j<ly;j++)
//      {
//         printf("%d ",fie[i][j]);
//      }
//      printf("\n");
//   }
//   system("PAUSE");
//   for(int i=0;i<=now;i++)
//   {
//      cout << "untuk " << i << " ada " << ada[i] << " dan mw pake " << pake[i] << endl;
//      if(pake[i]!=ada[i]) return 0;
//   }
   return 1;
}

vvi make_dim(int lx, int ly)
{
   vvi ret;
   tmp.clear();
   for(int i=1;i<=ly;i++) tmp.push_back(-1);
   for(int i=1;i<=lx;i++) ret.push_back(tmp);
   return ret;
}

bool cek(int lx, int ly)
{
   memset(pake,0,sizeof(pake));
//   cout << "dimensi " << lx << " " << ly << endl;
   fie = make_dim(lx,ly);
   priority_queue<int> pq;
   for(int i=1;i<=t;i++)
   {
      pq.push(li[i]);
   }
   int now=pq.top(); pq.pop();
//   int maks=now;
   fie[0][ly-1] = now;
   pake[now]++;
   int cnt = 1;
   now--;
   bool out=0;
   while(!pq.empty() && cnt!=lx && cnt!=ly)
   {
      int cur = pq.top(); pq.pop();
      if(cur != now)
      {
         fie[lx-1][ly-1] = cur;
         pake[cur]++;
         break;
      }
//      cout << cur << endl;
      for(int i=1;i<=cnt;i++)
      {
         cur = pq.top();
         pq.pop();
         if(cur!=now)
         {
            fie[lx-1][ly-1] = cur;
            pake[cur]++;
            out = 1;
            break;
         }
      }
      if(out) break;
      fie[cnt][ly-1]=now;
      pake[now]++;
      now--;
      cnt++;
   }
   if(fie[lx-1][ly-1]==-1) return 0;
   int dif = fie[0][ly-1] - fie[lx-1][ly-1];
//   cout << fie[0][ly-1] << " " << fie[lx-1][ly-1] << endl;
   if((dif+lx-1)%2==1) return 0;
   int temu = (dif+lx-1)/2;
   int kur = temu-dif;
   kur = fie[lx-1][ly-1]-kur;
//   cout << "kur = " << kur << endl;
   if(kur<0) return 0;
   int temuy = ly-1-kur;
   if(temuy < 0) return 0;
//   cout << kur << endl;
//   cout << "/>>> " << temu << " " << temuy << endl;
   return ff(temu,temuy, lx, ly);
}

int main()
{
   memset(ada,0,sizeof(ada));
//   memset(pake,0,sizeof(pake));
   scanf("%d",&t);
   for(int i=1;i<=t;i++)
   {
      scanf("%d",&li[i]);
      ada[li[i]]++;
   }
   bool done=0;
   for(int i=1;i*i<=t;i++)
   {
      if(t%i!=0) continue;
      if(cek(i,t/i))
      {
         done = 1;
         printf("%d %d\n",i,t/i);
         break;
      }
      if(cek(t/i,i))
      {
         done = 1;
         printf("%d %d\n",t/i,i);
         break;
      }
   }
   if(!done) printf("-1\n");
   else printf("%d %d\n",px+1,py+1);
 	return 0;
}