#include <iostream>
#include <cmath>
using namespace std;

int main(){

	long n,m,c, *first, *second, shag = 0;
	long *summ, buf;
	cin >> n >> m >> c;
	first = new long [n];
	second = new long [m];
	summ = new long [m];

//	FILE *out = fopen("output2.txt","w");
	for ( int i = 0; i < n; i++){
		 cin >> first[i];
	//	first[i] = i;
	}
	for ( int i = 0; i < m; i ++){
		cin >> second [i];
	//	second[i] = m - i;
	}
/*
	buf = 0;
	for ( int i = 0;  i < m; i ++){
		summ[i] = (buf + second[i]);
		buf = summ[i];
	}
	if ( m != n ){
		for ( int i = 0; i < m - 1; i++){
			first [ i ] += summ[i];
		}
		for ( int i = 0; i < n - 2 * ( m - 1 ) && m != n; i++){
			first [ m - 1 + i ] += summ[m-1];
		}
		for ( int i = n - (m - 1) ; i < n; i++){
			first [ n - (m-1) + shag ] += summ[m-1] - summ[shag];
			shag++;
		}
	} else {
		for ( int i = 0; i < n; i++){
			first [i] += second[i];
		}
	}
	for ( int i = 0; i < n; i++){
		//cout << first[ i ] % c << ' ';
		fprintf(out,"%d ",first[ i ] % c);
	}
	cout << endl;
*/
	if ( n > 10 ) return 0;
	shag = 0;
	for ( int i = 0; i < n - m + 1; i++){
		for ( int j = 0; j < m; j++ ){
			first[i+j] += second[j];
			first[i+j] = first[i+j]%c;
		}

	}
	for ( int i = 0; i < n; i++){
		cout << first[ i ] << ' ';
	//	fprintf(out,"%d ",first[ i ]);
	}

//	fclose(out);
	return 0;
}


#include <iostream>
#include <cmath>
using namespace std;

int main(){

	long n,m,c, *first, *second, shag = 0;
	long *summ, buf;
	cin >> n >> m >> c;
	first = new long [n];
	second = new long [m];
	summ = new long [m];

//	FILE *out = fopen("output2.txt","w");
	for ( int i = 0; i < n; i++){
		 cin >> first[i];
	//	first[i] = i;
	}
	for ( int i = 0; i < m; i ++){
		cin >> second [i];
	//	second[i] = m - i;
	}
/*
	buf = 0;
	for ( int i = 0;  i < m; i ++){
		summ[i] = (buf + second[i]);
		buf = summ[i];
	}
	if ( m != n ){
		for ( int i = 0; i < m - 1; i++){
			first [ i ] += summ[i];
		}
		for ( int i = 0; i < n - 2 * ( m - 1 ) && m != n; i++){
			first [ m - 1 + i ] += summ[m-1];
		}
		for ( int i = n - (m - 1) ; i < n; i++){
			first [ n - (m-1) + shag ] += summ[m-1] - summ[shag];
			shag++;
		}
	} else {
		for ( int i = 0; i < n; i++){
			first [i] += second[i];
		}
	}
	for ( int i = 0; i < n; i++){
		//cout << first[ i ] % c << ' ';
		fprintf(out,"%d ",first[ i ] % c);
	}
	cout << endl;
*/
	if ( m > 800 ) return 0;
	shag = 0;
	for ( int i = 0; i < n - m + 1; i++){
		for ( int j = 0; j < m; j++ ){
			first[i+j] += second[j];
			first[i+j] = first[i+j]%c;
		}

	}
	for ( int i = 0; i < n; i++){
		cout << first[ i ] << ' ';
	//	fprintf(out,"%d ",first[ i ]);
	}

//	fclose(out);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <stack>
#include <list>
#include <cstdio>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <hash_map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <list>
#include <map>
#include <sstream>
#include <string>
#include <cstdlib>
#include <bitset>
#include <iomanip>
#include <ctime>
using namespace std;
#pragma comment(linker,"/STACK:1700000000")
const double eps = 1e-9; const double inf = 1e+9;
typedef long long ll;
typedef pair<int, int> P;
typedef double db;

int n, m, c;
int a[100009];
int b[100009];
int s[100009];
int l[100009];
int r[100009];
inline int f(int b, int e){
	int t = s[e] - ((b - 1 >= 0) ? s[b - 1] : 0);
	return t;
}
int main()
{
	int all = 0;
	scanf("%d%d%d", &n, &m, &c);
	for (int i = 0; i < n; i++)scanf("%d", a + i);
	for (int i = 0; i < m; i++){
		scanf("%d", b + i);
		if (i <= n - m)all += b[i];
	}
	s[0] = b[0];
	for (int i = 1; i < m; i++)
		s[i] = s[i - 1] + b[i];

	for (int i = 0; i < n; i++){
		l[i] = m - min(n - i, m);
		r[i] = min(m - 1, i);
	}

	for (int i = 0; i < n; i++){
		printf("%d ", (a[i] + f(l[i],r[i])) % c);
	}
}
/*
6 5 2
1 1 1 1 1 1
1 1 1 1 1

8 3 2
1 1 1 1 1 1 1 1
1 1 1

*/


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <stack>
#include <list>
#include <cstdio>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <hash_map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <list>
#include <map>
#include <sstream>
#include <string>
#include <cstdlib>
#include <bitset>
#include <iomanip>
#include <ctime>
using namespace std;
#pragma comment(linker,"/STACK:1700000000")
const double eps = 1e-9; const double inf = 1e+9;
typedef long long ll;
typedef pair<int, int> P;
typedef double db;

int n, m, c;
int a[100009];
int b[100009];
int s[100009];
int l[100009];
int r[100009];
inline int f(int b, int e){
    return s[e] - (b >= 0) ? s[b] : 0;
}
int main()
{
    int all = 0;
    scanf("%d%d%d", &n, &m, &c);
    for (int i = 0; i < n; i++)scanf("%d", a + i);
    for (int i = 0; i < m; i++){
        scanf("%d", b + i);
        if(i<=n-m)all += b[i];
    }
    s[0] = b[0];
    for (int i = 1; i < m; i++)
        s[i] = s[i - 1] + b[i];

    for (int i = 0; i < n; i++){
        l[i] = m - min(n - i,m);
        r[i] = min(m - 1, i);
    }

    for (int i = 0; i < n; i++){
        printf("%d ",(a[i]+f(r[i],l[i]-1))%c);
    }
}
/*
6 5 2
1 1 1 1 1 1
1 1 1 1 1

8 3 2
1 1 1 1 1 1 1 1
1 1 1

*/


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <stack>
#include <list>
#include <cstdio>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <hash_map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <list>
#include <map>
#include <sstream>
#include <string>
#include <cstdlib>
#include <bitset>
#include <iomanip>
#include <ctime>
using namespace std;
#pragma comment(linker,"/STACK:1700000000")
const double eps = 1e-9; const double inf = 1e+9;
typedef long long ll;
typedef pair<int, int> P;
typedef double db;

int n, m, c;
int a[100009];
int b[100009];
int main()
{
    int all = 0;
    scanf("%d%d%d", &n, &m, &c);
    for (int i = 0; i < n; i++)scanf("%d", a + i);
    for (int i = 0; i < m; i++){
        scanf("%d", b + i);
        if(i<=n-m)all += b[i];
    }

    int k1 = min(m - 2, n - m - 1);
    int k2 = max(m, n - m + 1);

    for (int i = 0; i <= k1; i++){
        for (int j = 0; i + j <= k1; j++){
            a[i + j] += b[j];
        }
    }

    for (int i = n-1; i >= k2; i--){
        for (int j = m - 1; i - (m - 1 - j) >= k2; j--){
            a[i - (m - 1 - j)] += b[j];
        }
    }

    for (int i = k1+1; i < k2; i++)
        a[i] += all;

    for (int i = 0; i < n; i++){
        printf("%d ",(a[i])%c);
    }
}
/*
6 5 2
1 1 1 1 1 1
1 1 1 1 1

8 3 2
1 1 1 1 1 1 1 1
1 1 1

*/


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstring>
#include <stack>
#include <list>
#include <cstdio>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <hash_map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <list>
#include <map>
#include <sstream>
#include <string>
#include <cstdlib>
#include <bitset>
#include <iomanip>
#include <ctime>
using namespace std;
#pragma comment(linker,"/STACK:1700000000")
const double eps = 1e-9; const double inf = 1e+9;
typedef long long ll;
typedef pair<int, int> P;
typedef double db;

int n, m, c;
int a[100009];
int b[100009];
int b2[100009];
int main()
{
    int all = 0;
    scanf("%d%d%d", &n, &m, &c);
    for (int i = 0; i < n; i++)scanf("%d", a + i);
    for (int i = 0; i < m; i++){
        scanf("%d", b + i);
        b2[i] = b[i];
        all += b[i];
    }

    for (int i = m - 1; i < n - m + 1; i++)
        a[i] += all;

    if (m - 1>0)a[0] += b[0];
    for (int i = 1; i < m-1; i++){
        b[i] += b[i - 1];
        a[i] += b[i];
    }

    if (n - 1> n - m)a[n - 1] += b2[m - 1];
    for (int i = n-2,j=m-2; i >= n - m + 1; i--,j--){
        b2[j] += b2[j + 1];
        a[i] += b2[j];
    }
    for (int i = 0; i < n; i++){
        printf("%d ",(a[i])%c);
    }
}
/*

*/


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <set>
#include <queue>
#include <string>
#include <map>
#include <list>
#include <deque>
#include <algorithm>
using namespace std;
#pragma warning(disable:4996)

const int nmax=100005;
int a[nmax],b[nmax],add[nmax];

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int n,m,i,j,k,c;
	cin >>n>>m>>c;
	for (i=0;i<n;i++)cin >>a[i];
	for (i=0;i<m;i++)cin >>b[i];
	for (i=0;i<m;i++)
	{
		add[i]=(add[i]+b[i]);add[i+n-m+1]=add[i+n-m+1]-b[i];
	}
	int s=0;
	for (i=0;i<n;i++)
	{
		s+=add[i];s=(s+c)%c;
		a[i]=(a[i]+s+c)%c;
		cout <<a[i]<<" ";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

const int N = 1000005;
int t, mx = -1;
int f[N], f2[N];

bool check(int n, int m, int x, int y){
	// printf("%d %d %d %d\n", n, m, x, y);
	if(x < 1 or x > n or y < 1 or y > m) return 0;

	memset(f2, 0, sizeof f2);

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			int dist = abs(x-i) + abs(y-j);
			f2[dist]++;
		}
	}

	for(int i = 0; i <= mx; i++){
		if(f[i] != f2[i]) return 0;
	}

	return 1;
}

int main(void){
	scanf("%d", &t);

	int val;
	for(int i = 0; i < t; i++){
		scanf("%d", &val);
		f[val]++;
		mx = max(mx, val);
	}

	if(t == 1){
		if(mx == 0){
			printf("1 1\n");
			printf("1 1\n");
		}
		else{
			printf("-1\n");
		}
		return 0;
	}

	for(int n = 1; n*n <= t; n++){
		if(t%n == 0){
			int m = t/n;

			int x = -1;
			for(int i = 1; i <= mx; i++){
				if(f[i] != 4*i){
					x = i;
					break;
				}
			}

			if(x == -1){
				printf("-1\n");
				return 0;
			}

			int y = n+m-mx-x;

			if(check(n, m, x, y)){
				printf("%d %d\n", n, m);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

	printf("-1\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

const int N = 1000005;
int t, mx = -1;
int f[N], f2[N];

bool check(int n, int m, int x, int y){
	// printf("%d %d %d %d\n", n, m, x, y);

	memset(f2, 0, sizeof f2);

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			int dist = abs(x-i) + abs(y-j);
			f2[dist]++;
		}
	}

	for(int i = 0; i <= mx; i++){
		if(f[i] != f2[i]) return 0;
	}

	return 1;
}

int main(void){
	scanf("%d", &t);

	int val;
	for(int i = 0; i < t; i++){
		scanf("%d", &val);
		f[val]++;
		mx = max(mx, val);
	}

	if(t == 1){
		if(mx == 0){
			printf("1 1\n");
			printf("1 1\n");
		}
		else{
			printf("-1\n");
		}
		return 0;
	}

	for(int n = 1; n*n <= t; n++){
		if(t%n == 0){
			int m = t/n;

			int x;
			for(int i = 1; i <= mx; i++){
				if(f[i] != 4*i){
					x = i;
					break;
				}
			}

			int y = n+m-mx-x;

			if(check(n, m, x, y)){
				printf("%d %d\n", n, m);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

	printf("-1\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

const int N = 1000005;
int t, mx = -1;
int f[N], f2[N];

bool check(int n, int m, int x, int y){
	// printf("%d %d %d %d\n", n, m, x, y);

	memset(f2, 0, sizeof f2);

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			int dist = abs(x-i) + abs(y-j);
			f2[dist]++;
		}
	}

	for(int i = 0; i <= mx; i++){
		if(f[i] != f2[i]) return 0;
	}

	return 1;
}

int main(void){
	scanf("%d", &t);

	int val;
	for(int i = 0; i < t; i++){
		scanf("%d", &val);
		f[val]++;
		mx = max(mx, val);
	}

	if(t == 1){
		if(mx == 0){
			printf("1 1\n");
			printf("1 1\n");
		}
		else{
			printf("-1\n");
		}
		return 0;
	}

	for(int n = 1; n*n <= t; n++){
		if(t%n == 0){
			int m = t/n;

			int x;
			for(int i = 1; i <= mx; i++){
				if(f[i] != 4*i){
					x = i;
					break;
				}
			}

			int y = n+m-mx-x;

			if(check(n, m, x, y)){
				printf("%d %d\n", n, m);
				printf("%d %d\n", x, y);
				return 0;
			}
			// if(check(n, m, y, x)){
			// 	printf("%d %d\n", n, m);
			// 	printf("%d %d\n", y, x);
			// 	return 0;
			// }
			// if(check(m, n, x, y)){
			// 	printf("%d %d\n", m, n);
			// 	printf("%d %d\n", x, y);
			// 	return 0;
			// }
			// if(check(m, n, y, x)){
			// 	printf("%d %d\n", m, n);
			// 	printf("%d %d\n", y, x);
			// 	return 0;
			// }
		}
	}

	printf("-1\n");

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

const int N = 1000005;
int t, n, m;
int cnt[N], cnt2[N];

int main(void){
	scanf("%d", &t);

	int x, mx = -1;
	for(int i = 0; i < t; i++){
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}

	int x0 = -1, y0 = -1;
	for(int i = 1; i*i <= t; i++){
		if(t%i == 0){
			n = i;
			m = t/i;

			int x = n;
			int y = mx-n+1;

			// printf("%d %d %d %d\n", n, m, x, y);

			if(y > m) continue;

			while(x >= 1){
				// testar os cantos
				int d1 = x+y-2;
				int d2 = x + m-y - 1;
				int d3 = n-x + y - 1;
				int d4 = n-x + m-y;

				int cnt_mx = 0;
				if(d1 == mx) cnt_mx++;
				if(d2 == mx) cnt_mx++;
				if(d3 == mx) cnt_mx++;
				if(d4 == mx) cnt_mx++;

				if(d1 <= mx and d2 <= mx and d3 <= mx and d4 <= mx and cnt_mx == cnt[mx]){
					// printf("testando para n = %d, m = %d, x = %d, y = %d\n", n, m, x, y);
					memset(cnt2, 0, sizeof cnt2);

					for(int ii = 1; ii <= n; ii++){
						for(int jj = 1; jj <= m; jj++){
							int dist = abs(ii-x) + abs(jj-y);
							cnt2[dist]++;
						}
					}

					bool ok = 1;
					for(int j = 0; j <= mx; j++){
						if(cnt[j] != cnt2[j]){
							// printf("deu ruim em %d %d\n", it.fi, it.se);
							ok = 0;
							break;
						}
					}

					if(ok){
						x0 = x;
						y0 = y;
						break;
					}
				}
				x--;
				y++;
			}

			if(x0 != -1) break;
		}
	}

	if(x0 != -1){
		printf("%d %d\n", n, m);
		printf("%d %d\n", x0, y0);
	}
	else{
		printf("-1\n");
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

const int N = 1000005;
int t, n, m;
int cnt[N], cnt2[N];

int main(void){
	scanf("%d", &t);

	int x, mx = -1;
	for(int i = 0; i < t; i++){
		scanf("%d", &x);
		cnt[x]++;
		mx = max(mx, x);
	}

	int x0 = -1, y0 = -1;
	for(int i = 1; i*i <= t; i++){
		if(t%i == 0){
			n = i;
			m = t/i;

			int x = n;
			int y = mx-n+1;

			// printf("%d %d %d %d\n", n, m, x, y);

			if(y > m) continue;

			while(x >= 1){
				// testar os cantos
				int d1 = x+y-2;
				int d2 = x + m-y - 1;
				int d3 = n-x + y - 1;
				int d4 = n-x + m-y;

				int cnt_mx = 0;
				if(d1 == mx) cnt_mx++;
				if(d2 == mx) cnt_mx++;
				if(d3 == mx) cnt_mx++;
				if(d4 == mx) cnt_mx++;

				if(d1 <= mx and d2 <= mx and d3 <= mx and d4 <= mx and cnt_mx == cnt[mx]){
					// printf("testando para n = %d, m = %d, x = %d, y = %d\n", n, m, x, y);
					memset(cnt2, 0, sizeof cnt2);

					for(int ii = 1; ii <= n; ii++){
						for(int jj = 1; jj <= m; jj++){
							int dist = abs(ii-x) + abs(jj-y);
							cnt2[dist]++;
						}
					}

					bool ok = 1;
					for(int j = 0; j < N; j++){
						if(cnt[j] != cnt2[j]){
							// printf("deu ruim em %d %d\n", it.fi, it.se);
							ok = 0;
							break;
						}
					}

					if(ok){
						x0 = x;
						y0 = y;
						break;
					}
				}
				x--;
				y++;
			}

			if(x0 != -1) break;
		}
	}

	if(x0 != -1){
		printf("%d %d\n", n, m);
		printf("%d %d\n", x0, y0);
	}
	else{
		printf("-1\n");
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define PI acos(-1)
#define fastcin ios_base::sync_with_stdio(false);
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> ii;
typedef complex<double> base;

const int N = 1000005;
int t, mx = -1;
int f[N], f2[N];

bool check(int n, int m, int x, int y){
	// printf("%d %d %d %d\n", n, m, x, y);
	if(x < 1 or x > n or y < 1 or y > m) return 0;

	memset(f2, 0, sizeof f2);

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			int dist = abs(x-i) + abs(y-j);
			f2[dist]++;
		}
	}

	for(int i = 0; i <= mx; i++){
		if(f[i] != f2[i]) return 0;
	}

	return 1;
}

int main(void){
	scanf("%d", &t);

	int val;
	for(int i = 0; i < t; i++){
		scanf("%d", &val);
		f[val]++;
		mx = max(mx, val);
	}

	if(t == 1){
		if(mx == 0){
			printf("1 1\n");
			printf("1 1\n");
		}
		else{
			printf("-1\n");
		}
		return 0;
	}

	for(int n = 1; n*n <= t; n++){
		if(t%n == 0){
			int m = t/n;

			int x = -1;
			for(int i = 1; i <= mx; i++){
				if(f[i] != 4*i){
					x = i;
					break;
				}
			}

			if(x == -1){
				continue;
			}

			int y = n+m-mx-x;

			if(check(n, m, x, y)){
				printf("%d %d\n", n, m);
				printf("%d %d\n", x, y);
				return 0;
			}
			if(check(n, m, y, x)){
				printf("%d %d\n", n, m);
				printf("%d %d\n", y, x);
				return 0;
			}
			if(check(m, n, x, y)){
				printf("%d %d\n", m, n);
				printf("%d %d\n", x, y);
				return 0;
			}
			if(check(m, n, y, x)){
				printf("%d %d\n", m, n);
				printf("%d %d\n", y, x);
				return 0;
			}
		}
	}

	printf("-1\n");

	return 0;
}


#include <bits/stdc++.h>

#define base 1000000007LL
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-10
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)
using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;
struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const ll M=1e6+7;
const ll MOD=1e9+7;
const ll MAX=1e9+9;

inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
ll inverse(ll n, ll p=MOD){return power(n,p-2);}

int c[M], c2[M], hx, hy, n, x, maxx;

void calc(int x, int y){
    hy = maxx+1-x+hx;
    if(hx>x || hx<1 || hy>y || hy<1) return ;
    memset(c2, 0, sizeof(c2));

    foru(i,1,x) foru(j,1,y) c2[abs(hx-i) + abs(hy-j)]++;
    foru(i,1,maxx) if(c2[i]!=c[i]) return ;
    cout<<x<<" "<<y<<endl<<hx<<" "<<hy;
    exit(0);
}

ll solve(){
    cin>>n;
    foru(i,1,n){
        cin>>x;
        c[x]++;
        maxx = max(maxx, x);
    }

    if(c[0]!=1) return 0;

    foru(i,1,maxx) if(i*4==c[i]) hx=i; else break;
    hx++;
    //hy=maxx+1-hx;
   // if(n == 1000000) cout<<hx<<" "<<hy<<endl;

    for(int i=1; i*i<=n; i++) if(n%i==0){
       // cout<<i<<" "<<n/i<<endl;
        calc(n/i, i);
        calc(i, n/i);
    }
    cout<<-1;
}

int main(){
    ios::sync_with_stdio(0);

   // freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define base 1000000007LL
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-10
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)
using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;
struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const ll M=1e6+7;
const ll MOD=1e9+7;
const ll MAX=1e9+9;

inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
ll inverse(ll n, ll p=MOD){return power(n,p-2);}

int del[M],maxx,c[M],h[10],n,x,huong=4,tmp;

void update(int l, int r, int val){
    del[l]+=val;
    del[r+1]-=val;
}

bool chuyenhuong(int id){
   switch(huong){
        case 4: foru(i,1,4) h[i]=id;
                update(id+1,id*2,-4);
                update(id+1,id*2-1,-4);
                break;
        case 3: foru(i,1,3) h[i]=id;
                update(id+1,id*2,-2);
                update(id+1,id*2-1,-2);
                update(id+1,h[4]+id,-2);
                break;
        case 2: foru(i,1,2) h[i]=id;
                update(id+1,id*2,-1);
                update(id+1,id*2-1,-1);
                update(id+1,h[4]+id,-1);
                update(id+1,h[3]+id,-1);
                break;
        case 1: foru(i,1,1) h[i]=id;
                update(id+1,h[2]+id,-1);
                update(id+1,h[3]+id,-1);
                break;
   }

  // foru(i,1,4) cout<<h[i]<<" ";
}

ll solve(){
    cin>>n;
    foru(i,1,n){
        cin>>x;
        c[x]++;
        maxx = max(maxx, x);
    }

    if(c[0]!=1){
        return 0;
    }

    foru(i,1,maxx){
        tmp += del[i];
        c[i] += tmp;

       // cout<<c[i];

        if(c[i]<0) return 0;
        c[i]-=huong;
        if(c[i]>0) return 0;

        if(huong==0) continue;
        huong += c[i];

       // cout<<" "<<huong<<" ";
        chuyenhuong(i);
       // cout<<endl;
    }

    cout<<h[2]+h[4]+1<<" "<<h[1]+h[3]+1<<endl;
 //    cout<<h[1]<<" "<<h[4]<<" "<<h[2]<<" "<<h[3]<<endl;
    cout<<h[4]+1<<" "<<h[1]+1;
    return 1;
}

int main(){
    ios::sync_with_stdio(0);

   // freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //int t;cin>>t;while(t--)
    if(!solve()) cout<<-1;
    return 0;
}


#include <bits/stdc++.h>

#define base 1000000007LL
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-10
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)
using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;
struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const ll M=1e6+7;
const ll MOD=1e9+7;
const ll MAX=1e9+9;

inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
ll inverse(ll n, ll p=MOD){return power(n,p-2);}

int c[M], c2[M], hx, hy, n, x, maxx;

void calc(int x, int y){
    if(hx>x || hx<1 || hy>y || hy<1) return ;
    memset(c2, 0, sizeof(c2));

    foru(i,1,x) foru(j,1,y) c2[abs(hx-i) + abs(hy-j)]++;
    foru(i,1,maxx) if(c2[i]!=c[i]) return ;
    cout<<x<<" "<<y<<endl<<hx<<" "<<hy;
    exit(0);
}

ll solve(){
    cin>>n;
    foru(i,1,n){
        cin>>x;
        c[x]++;
        maxx = max(maxx, x);
    }

    if(c[0]!=1) return 0;

    foru(i,1,maxx) if(i*4==c[i]) hx=i; else break;
    hx++;
    hy=maxx+1-hx;
    if(n == 1000000) cout<<hx<<" "<<hy<<endl;

    for(int i=1; i*i<=n; i++) if(n%i==0){
       // cout<<i<<" "<<n/i<<endl;
        calc(n/i, i);
        calc(i, n/i);
    }
    cout<<-1;
}

int main(){
    ios::sync_with_stdio(0);

//    freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define base 1000000007LL
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-10
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)
using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;
struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const ll M=1e6+7;
const ll MOD=1e9+7;
const ll MAX=1e9+9;

inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
ll inverse(ll n, ll p=MOD){return power(n,p-2);}

int del[M],maxx,c[M],h[10],n,x,huong=4,tmp;

void update(int l, int r, int val){
    del[l]+=val;
    del[r+1]-=val;
}

bool chuyenhuong(int id){
   switch(huong){
        case 4: foru(i,1,4) h[i]=id;
                update(id+1,id*2,-4);
                update(id+1,id*2-1,-4);
                break;
        case 3: foru(i,1,3) h[i]=id;
                update(id+1,id*2,-2);
                update(id+1,id*2-1,-2);
                update(id+1,h[4]+id,-2);
                break;
        case 2: foru(i,1,2) h[i]=id;
                update(id+1,id*2,-2);
                update(id+1,id*2-1,-1);
                update(id+1,h[4]+id,-1);
                update(id+1,h[3]+id,-1);
                break;
        case 1: foru(i,1,1) h[i]=id;
                update(id+1,h[2]+id,-1);
                update(id+1,h[3]+id,-1);
                break;
   }
}

ll solve(){
    cin>>n;
    foru(i,1,n){
        cin>>x;
        c[x]++;
        maxx = max(maxx, x);
    }

    if(c[0]!=1){
        return 0;
    }

    foru(i,1,maxx){
        tmp += del[i];
        c[i] += tmp;

        if(c[i]<0) return 0;
        c[i]-=huong;
        if(c[i]>0) return 0;

        if(huong==0) continue;
        huong -= c[i];
        if(chuyenhuong(i)) return 0;
    }

    cout<<h[1]+h[4]<<" "<<h[2]+h[3]<<endl;
    cout<<h[2]<<" "<<h[4];
    return 1;
}

int main(){
    ios::sync_with_stdio(0);

  //  freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //int t;cin>>t;while(t--)
    if(!solve()) cout<<-1;
    return 0;
}


#include <bits/stdc++.h>

#define base 1000000007LL
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-10
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)
using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;
struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const ll M=1e6+7;
const ll MOD=1e9+7;
const ll MAX=1e9+9;

inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
ll inverse(ll n, ll p=MOD){return power(n,p-2);}

int c[M], c2[M], hx, hy, n, x, maxx;

void calc(int x, int y){
    if(hx>x || hx<1 || hy>y || hy<1) return ;
    memset(c2, 0, sizeof(c2));

    foru(i,1,x) foru(j,1,y) c2[abs(hx-i) + abs(hy-j)]++;
    foru(i,1,maxx) if(c2[i]!=c[i]) return ;
    cout<<x<<" "<<y<<endl<<hx<<" "<<hy;
    exit(0);
}

ll solve(){
    cin>>n;
    foru(i,1,n){
        cin>>x;
        c[x]++;
        maxx = max(maxx, x);
    }

    if(c[0]!=1) return 0;

    foru(i,1,maxx) if(i*4==c[i]) hx=i; else break;
    hx++;
    hy=maxx+1-hx;
   // cout<<hx<<" "<<hy<<endl;

    for(int i=1; i*i<=n; i++) if(n%i==0){
       // cout<<i<<" "<<n/i<<endl;
        calc(n/i, i);
        calc(i, n/i);
    }
    cout<<-1;
}

int main(){
    ios::sync_with_stdio(0);

 //   freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


#include <bits/stdc++.h>

#define base 1000000007LL
#define ll long long
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-10
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)
using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;
struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const ll M=1e6+7;
const ll MOD=1e9+7;
const ll MAX=1e9+9;

inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
ll inverse(ll n, ll p=MOD){return power(n,p-2);}

int c[M], c2[M], hx, hy, n, x, maxx;

void calc(int x, int y){
    hy = maxx+1-x+hx;
    if(hx>x || hx<1 || hy>y || hy<1) return ;
    memset(c2, 0, sizeof(c2));

    foru(i,1,x) foru(j,1,y) c2[abs(hx-i) + abs(hy-j)]++;
    foru(i,1,maxx) if(c2[i]!=c[i]) return ;
    cout<<x<<" "<<y<<endl<<hx<<" "<<hy;
    exit(0);
}

ll solve(){
    cin>>n;
    foru(i,1,n){
        cin>>x;
        c[x]++;
        maxx = max(maxx, x);
    }

    if(c[0]!=1){
        cout<<-1;
        return 0;
    }

    foru(i,1,maxx) if(i*4==c[i]) hx=i; else break;
    hx++;
    //hy=maxx+1-hx;
   // if(n == 1000000) cout<<hx<<" "<<hy<<endl;

    for(int i=1; i*i<=n; i++) if(n%i==0){
       // cout<<i<<" "<<n/i<<endl;
        calc(n/i, i);
        calc(i, n/i);
    }
    cout<<-1;
}

int main(){
    ios::sync_with_stdio(0);

  //  freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //int t;cin>>t;while(t--)
    solve();
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int ss[1000001];
int n;
int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
//  cout << tot << endl;
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
//  cout << top_left << ' ' << top_right << ' ' << bottom_left << ' ' << bottom_right << endl;
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
bool can(int a, int b, int x, int y){
  for(int i = 1;i < n;i++){
    if(cnt[ss[i]] != coun(a, b, x, y, ss[i])){
      return false;
    }
  }
  return true;
}
void tr(int a, int b){
  for(int i = 0;i < (a + 1) / 2;i++){
    for(int j = 0;j < (b + 1) / 2;j++){
      if(can(a, b, i, j)){
        cout << a << ' ' << b << endl << 1 + i << ' ' << 1 + j;
        exit(0);
      }
    }
  }
}

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  srand(time(0));
  cin >> n;
  int arr[n];
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;

  for(int i = 1;i < n;i++)
    ss[i] = i;
  random_shuffle(ss + 1, ss + n);
  random_shuffle(ss + 1, ss + n);
//  for(int i = 1;i < n;i++)
//    cout << ss[i] << endl;
  if(cnt[0] != 1){
    cout << -1;
    return 0;
  }
  for(int i = 1;i * i <= n;i++){
    if(n % i == 0){
      tr(i, n / i);
    }
  }
  cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int n;
inline int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
int x = 1;
bool can(int a, int b, int xx, int y){
  for(int i = x + 1;i < n;i++){
    if(cnt[i] != coun(a, b, xx, y, i)){
      return false;
    }
  }
  return true;
}
void tr(int a, int b){
    for(int j = x;j < (b + 1) / 2 - x;j++){
      if(can(a, b, x, j)){
        cout << a << ' ' << b << endl << 1 + x << ' ' << 1 + j;
        exit(0);
      }
    }
}

int arr[1000001];
int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n;
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;
  if(cnt[0] != 1){
    cout << -1;
    return 0;
  }
  while(cnt[x] == 4 * x)
    x ++;
  x--;
  for(int i = 1;i * i <= n;i++){
    if(n % i == 0 && i >= 2 * x + 1 && n / i >= 2 * x + 1){
      tr(i, n / i);
      tr(n / i, i);
    }
  }
  cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int n;
int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
//  cout << tot << endl;
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
//  cout << top_left << ' ' << top_right << ' ' << bottom_left << ' ' << bottom_right << endl;
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
bool can(int a, int b, int x, int y){
  for(int i = 1;i < n;i++){
    if(cnt[i] != coun(a, b, x, y, i)){
      return false;
    }
  }
  return true;
}
void tr(int a, int b){
  for(int i = 0;i < (a + 1) / 2;i++){
    for(int j = 0;j < (b + 1) / 2;j++){
      if(can(a, b, i, j)){
//        cout << a << ' ' << b << endl << 1 + i << ' ' << 1 + j;
//        exit(0);
      }
    }
  }
}

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n;
  int arr[n];
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;
  if(cnt[0] != 1){
    cout << -1;
    return 0;
  }
  for(int i = 1;i * i <= n;i++){
    if(n % i == 0){
      tr(i, n / i);
    }
  }
  cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int n;
inline int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
int x = 1;
bool can(int a, int b, int xx, int y){
  for(int i = x + 1;i < n;i++){
    if(cnt[i] != coun(a, b, xx, y, i)){
      return false;
    }
  }
  return true;
}
  int mx = -1;
void tr(int a, int b){
      if(can(a, b, x, a - 1 + b - 1 - x - mx)){
        cout << a << ' ' << b << endl << 1 + x << ' ' << 1 + a - 1 + b - 1 - x - mx;
        exit(0);
      }
}

int arr[1000001];
int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n;
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i), mx = max(mx, arr[i]);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;
  if(cnt[0] != 1){
    cout << -1;
    return 0;
  }
  while(x < n && cnt[x] == 4 * x)
    x ++;
  x--;

  for(int i = 1;i * i <= n;i++){
    if(n % i == 0 && i >= 2 * x + 1 && n / i >= 2 * x + 1){
      tr(i, n / i);
      tr(n / i, i);
    }
  }
  cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int n;
int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
//  cout << tot << endl;
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
//  cout << top_left << ' ' << top_right << ' ' << bottom_left << ' ' << bottom_right << endl;
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
bool can(int a, int b, int x, int y){
  for(int i = n - 1;i >= 1;i--){
    if(cnt[i] != coun(a, b, x, y, i)){
      return false;
    }
  }
  return true;
}
void tr(int a, int b){
  for(int i = 0;i < (a + 1) / 2;i++){
    for(int j = 0;j < (b + 1) / 2;j++){
      if(can(a, b, i, j)){
        cout << a << ' ' << b << endl << 1 + i << ' ' << 1 + j;
        exit(0);
      }
    }
  }
}

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n;
  int arr[n];
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;
  for(int i = 1;i * i <= n;i++){
    if(n % i == 0)
      tr(i, n / i);
  }
  cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int ss[1000001];
int n;
int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
//  cout << tot << endl;
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
//  cout << top_left << ' ' << top_right << ' ' << bottom_left << ' ' << bottom_right << endl;
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
bool can(int a, int b, int x, int y){
  for(int i = 1;i < n;i++){
    if(cnt[ss[i]] != coun(a, b, x, y, ss[i])){
      return false;
    }
  }
  return true;
}
void tr(int a, int b){
  for(int i = 0;i < (a + 1) / 2;i++){
    for(int j = 0;j < (b + 1) / 2;j++){
      if(can(a, b, i, j)){
        cout << a << ' ' << b << endl << 1 + i << ' ' << 1 + j;
        exit(0);
      }
    }
  }
}

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n;
  int arr[n];
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;

  for(int i = 1;i < n;i++)
    ss[i] = i;
  random_shuffle(ss + 1, ss + n);
  if(cnt[0] != 1){
    cout << -1;
    return 0;
  }
  for(int i = 1;i * i <= n;i++){
    if(n % i == 0){
      tr(i, n / i);
    }
  }
  cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int n;
inline int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
int x = 1;
bool can(int a, int b, int xx, int y){
  for(int i = x + 1;i < n;i++){
    if(cnt[i] != coun(a, b, xx, y, i)){
      return false;
    }
  }
  return true;
}
void tr(int a, int b){
    for(int j = x;j < (b + 1) / 2;j++){
      if(can(a, b, x, j)){
        cout << a << ' ' << b << endl << 1 + x << ' ' << 1 + j;
        exit(0);
      }
    }
}

int arr[1000001];
int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n;
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;
  if(cnt[0] != 1){
    cout << -1;
    return 0;
  }
  while(cnt[x] == 4 * x)
    x ++;
  x--;
//  cout << x << endl;
  for(int i = 1;i * i <= n;i++){
    if(n % i == 0 && i >= 2 * x + 1 && n / i >= 2 * x + 1){
      tr(i, n / i);
      tr(n / i, i);
    }
  }
  cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int n;
int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
//  cout << tot << endl;
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
//  cout << top_left << ' ' << top_right << ' ' << bottom_left << ' ' << bottom_right << endl;
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
bool can(int a, int b, int x, int y){
  for(int i = 1;i < n;i++){
    if(cnt[i] != coun(a, b, x, y, i)){
      return false;
    }
  }
  return true;
}
void tr(int a, int b){
  for(int i = 0;i < (a + 1) / 2;i++){
    for(int j = 0;j < (b + 1) / 2;j++){
      if(can(a, b, i, j)){
        cout << a << ' ' << b << endl << 1 + i << ' ' << 1 + j;
        exit(0);
      }
    }
  }
}

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n;
  int arr[n];
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;
  if(cnt[0] != 1){
    cout << -1;
    return 0;
  }
  for(int i = 1;i * i <= n;i++){
    if(n % i == 0){
      tr(i, n / i);
    }
  }
  cout << -1;
}


#include <bits/stdc++.h>
#define ll long long
#define OO 10000000000000
using namespace std;
int cnt[1000001];
int n;
int coun(int a, int bb, int x, int y, int num){
  int tot = 4 * num;
  int r, l, t, b;
  t = num - x;
  l = num - y;
  r = num - (a - 1 - x);
  b = num - (bb - 1 - y);
  if(l > 0){
    tot -= 2 * l - 1;
  }
  if(r > 0){
    tot -= 2 * r - 1;
  }
  if(t > 0){
    tot -= 2 * t - 1;
  }
  if(b > 0){
    tot -= 2 * b - 1;
  }
//  cout << tot << endl;
  int top_left, top_right, bottom_left, bottom_right;
  top_left = x + y;
  top_right = x + (bb - 1 - y);
  bottom_left = (a - 1 - x) + y;
  bottom_right = (a - 1 - x) + (bb - 1 - y);
//  cout << top_left << ' ' << top_right << ' ' << bottom_left << ' ' << bottom_right << endl;
  if(top_left < num){
    tot += num - top_left - 1;
  }
  if(top_right < num){
    tot += num - top_right - 1;
  }
  if(bottom_left < num){
    tot += num - bottom_left - 1;
  }
  if(bottom_right < num){
    tot += num - bottom_right - 1;
  }
  return tot;

}
bool can(int a, int b, int x, int y){
  for(int i = 1;i < n;i++){
    if(cnt[i] != coun(a, b, x, y, i)){
      return false;
    }
  }
  return true;
}
int x = 1;
void tr(int a, int b){
//  for(int i = 0;i < (a + 1) / 2;i++){
    for(int j = 0;j < (b + 1) / 2;j++){
      if(can(a, b, x, j)){
        cout << a << ' ' << b << endl << 1 + x << ' ' << 1 + j;
        exit(0);
      }
    }
//  }
}

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  srand(time(0));
  cin >> n;
  int arr[n];
  for(int i = 0;i < n;i++)
    scanf("%d", arr + i);
  for(int i = 0;i < n;i++)
    cnt[arr[i]]++;
  if(cnt[0] != 1){
    cout << -1;
    return 0;
  }
  while(cnt[x] == 4 * x)
    x ++;
  x--;
  for(int i = 1;i * i <= n;i++){
    if(n % i == 0){
      tr(i, n / i);
    }
  }
  cout << -1;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005],ff[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i*i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		if(x>n)swap(n,m);
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<=n;i++){
			vector<int>tmp;
			for(int j=0;j<=m;j++)
				tmp.push_back(0);
			g.push_back(tmp);
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=abs(i-x)+abs(j-y);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]++;
	}
	int n=500,m=2000,y=51;
	x=184;
	vector<vector<int> >g;
                for(int i=0;i<=n;i++){
                        vector<int>tmp;
                        for(int j=0;j<=m;j++)
                                tmp.push_back(0);
                        g.push_back(tmp);
                }
	for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                        g[i][j]=abs(i-x)+abs(j-y);
	for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                ff[g[i][j]]++;
                bool fl=true;
                for(int i=0;i<=b;i++)
                if(f[i]!=ff[i]){
                        fl=false;
                        break;
                }
                if(fl){
                        cout<<n<<" "<<m<<endl;
                        cout<<x<<" "<<y<<endl;
                        return 0;
                }
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005],ff[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i*i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		if(x>n)swap(n,m);
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<=n;i++){
			vector<int>tmp;
			for(int j=0;j<=m;j++)
				tmp.push_back(0);
			g.push_back(tmp);
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=abs(i-x)+abs(j-y);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]++;
	}
	int n=500,m=2000;
	int y=n+m-b-x;
	vector<vector<int> >g;
                for(int i=0;i<=n;i++){
                        vector<int>tmp;
                        for(int j=0;j<=m;j++)
                                tmp.push_back(0);
                        g.push_back(tmp);
                }
	for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                        g[i][j]=abs(i-x)+abs(j-y);
	for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                ff[g[i][j]]++;
                bool fl=true;
                for(int i=0;i<=b;i++)
                if(f[i]!=ff[i]){
                        fl=false;
                        break;
                }
                if(fl){
                        cout<<n<<" "<<m<<endl;
                        cout<<x<<" "<<y<<endl;
                        return 0;
                }
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005],ff[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i*i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		if(x>n)swap(n,m);
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<=n;i++){
			vector<int>tmp;
			for(int j=0;j<=m;j++)
				tmp.push_back(0);
			g.push_back(tmp);
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=abs(i-x)+abs(j-y);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]++;
	}
	int n=500,m=2000,y=51;
	x=184;
	vector<vector<int> >g;
                for(int i=0;i<=n;i++){
                        vector<int>tmp;
                        for(int j=0;j<=m;j++)
                                tmp.push_back(0);
                        g.push_back(tmp);
                }
	for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                ff[g[i][j]]++;
                bool fl=true;
                for(int i=0;i<=b;i++)
                if(f[i]!=ff[i]){
                        fl=false;
                        break;
                }
                if(fl){
                        cout<<n<<" "<<m<<endl;
                        cout<<x<<" "<<y<<endl;
                        return 0;
                }
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i*i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		if(x>n)swap(n,m);
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<=n;i++){
			vector<int>tmp;
			for(int j=0;j<=m;j++)
				tmp.push_back(0);
			g.push_back(tmp);
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=abs(i-x)+abs(j-y);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]++;
	}
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005],ff[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	bool fff=false;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		if(t==1000000&&i==0&&x==802)fff=true;
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i*i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		if(x>n)swap(n,m);
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<=n;i++){
			vector<int>tmp;
			for(int j=0;j<=m;j++)
				tmp.push_back(0);
			g.push_back(tmp);
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=abs(i-x)+abs(j-y);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]++;
	}
	int n=500,m=2000;
	int y=n+m-b-x;
	if(fff)cout<<x<<" "<<y<<" "<<b<<endl;
	vector<vector<int> >g;
                for(int i=0;i<=n;i++){
                        vector<int>tmp;
                        for(int j=0;j<=m;j++)
                                tmp.push_back(0);
                        g.push_back(tmp);
                }
	for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                        g[i][j]=abs(i-x)+abs(j-y);
	for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                ff[g[i][j]]++;
                bool fl=true;
                for(int i=0;i<=b;i++)
                if(f[i]!=ff[i]){
                        fl=false;
                        break;
                }
                if(fl){
                        cout<<n<<" "<<m<<endl;
                        cout<<x<<" "<<y<<endl;
                        return 0;
                }
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005],ff[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	bool fff=false;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		if(t==1000000&&i==0&&x==802)fff=true;
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<=n;i++){
			vector<int>tmp;
			for(int j=0;j<=m;j++)
				tmp.push_back(0);
			g.push_back(tmp);
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=abs(i-x)+abs(j-y);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]++;
	}
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i*i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		if(x>n)swap(n,m);
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<n;i++){
			vector<int>tmp;
			for(int j=0;j<m;j++)
			tmp.push_back(-1);
			g.push_back(tmp);
		}
		int sx=x-1,sy=y-1;
		g[sx][sy]=0;
		queue<pair<int,int> >q;
		q.push(make_pair(sx,sy));
		while(!q.empty()){
			sx=q.front().first;
			sy=q.front().second;
			q.pop();
			for(int i=0;i<4;i++){
				int tx=sx+dir[i][0];
				int ty=sy+dir[i][1];
				if(tx<0||tx>=n||ty<0||ty>=m||g[tx][ty]>=0)continue;
				g[tx][ty]=g[sx][sy]+1;
				q.push(make_pair(tx,ty));
			}
		}
		for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		f[g[i][j]]++;
	}
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i*i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		if(x>n)swap(n,m);
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<=n;i++){
			vector<int>tmp;
			for(int j=0;j<=m;j++)
				tmp.push_back(0);
			g.push_back(tmp);
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=abs(i-x)+abs(j-y);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]++;
	}
	int n=500,m=2000,y=51;
	x=184;
	vector<vector<int> >g;
                for(int i=0;i<=n;i++){
                        vector<int>tmp;
                        for(int j=0;j<=m;j++)
                                tmp.push_back(0);
                        g.push_back(tmp);
                }
	for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                f[g[i][j]]--;
                bool fl=true;
                for(int i=0;i<=b;i++)
                if(f[i]!=0){
                        fl=false;
                        break;
                }
                if(fl){
                        cout<<n<<" "<<m<<endl;
                        cout<<x<<" "<<y<<endl;
                        return 0;
                }
                for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                f[g[i][j]]++;
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	for(int i=0;i<t;i++){
		int x;
		cin>>x;
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i*i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		if(x>n)swap(n,m);
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<n;i++){
			vector<int>tmp;
			for(int j=0;j<m;j++)
			tmp.push_back(-1);
			g.push_back(tmp);
		}
		int sx=x-1,sy=y-1;
		g[sx][sy]=0;
		queue<pair<int,int> >q;
		q.push(make_pair(sx,sy));
		while(!q.empty()){
			sx=q.front().first;
			sy=q.front().second;
			q.pop();
			for(int i=0;i<4;i++){
				int tx=sx+dir[i][0];
				int ty=sy+dir[i][1];
				if(tx<0||tx>=n||ty<0||ty>=m||g[tx][ty]>=0)continue;
				g[tx][ty]=g[sx][sy]+1;
				q.push(make_pair(tx,ty));
			}
		}
		for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
		f[g[i][j]]++;
	}
	cout<<-1<<endl;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
int f[1000005];
int dir[4][2]={{-1,0},{0,-1},{0,1},{1,0}};
int main(){
	int t;
	cin>>t;
	int b=0;
	for(int i=0;i<t;i++){
		int x;
		scanf("%d",&x);
		f[x]++;
		b=max(x,b);
	}
	int x=0;
	for(int i=1;i<=t;i++){
		if(f[i]==4*i)continue;
		x=i;
		break;
	}
	for(int i=1;i<=t;i++){
		if(t%i)continue;
		int n,m;
		n=i,m=t/i;
		int y=n+m-b-x;
		if(y<1||y>m||x<1||x>n)continue;
		vector<vector<int> >g;
		for(int i=0;i<=n;i++){
			vector<int>tmp;
			for(int j=0;j<=m;j++)
				tmp.push_back(0);
			g.push_back(tmp);
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			g[i][j]=abs(i-x)+abs(j-y);
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]--;
		bool fl=true;
		for(int i=0;i<=b;i++)
		if(f[i]!=0){
			fl=false;
			break;
		}
		if(fl){
			cout<<n<<" "<<m<<endl;
			cout<<x<<" "<<y<<endl;
			return 0;
		}
		for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		f[g[i][j]]++;
	}
	cout<<-1<<endl;
}


#include <iostream>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>

using namespace std ;

const int maxn = 1000010 ;

int t , am ;

map <int , int> mp , nmp ;

bool Solve(int n , int m){

    bool check1 = true ;
    bool check2 = true ;

    if(mp[0] != 1)
        return false ;
    if(am > n + m - 2)
        return false ;

    int x1 = 1 , y1 = 1  , x2 = 1 , y2 = 1;

    for(int i = 1 ; i <= am ; ++i){
        if(mp[i] < 4 * i){
            x1 = i ;
            y2 = i ;
            break ;
        }
    }

    y1 = (n + m - x1 - am) ;
    x2 = (n + m - y2 - am) ;
    if(((x1 < 1) || (x1 > n)) && ((x2 < 1) || (x2 > n)))
        return false ;
    if(((y1 < 1) || (y1 > m)) && ((y1 < 1) || (y2 > m)))
        return false ;

    nmp.clear() ;

    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            nmp[abs(x1 - i) + abs(y1 - j)]++ ;
        }
    }

    for(int i = 0 ; i <= am ; ++i){
        if(nmp[i] != mp[i]){
            check1 = false ;
            break ;
        }
    }

    nmp.clear() ;

    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            nmp[abs(x2 - i) + abs(y2 - j)]++ ;
        }
    }

    for(int i = 0 ; i <= am ; ++i){
        if(nmp[i] != mp[i]){
            check2 = false ;
            break ;
        }
    }

    if((check1 == false) && (check2 == false))
        return false ;

    printf("%d %d\n",n,m) ;

    if(check1){
        printf("%d %d\n",x1,y1) ;
    } else printf("%d %d\n",x2,y2) ;

    return true ;
}

int main(){

    scanf("%d",&t) ;

    for(int i = 1 ; i <= t ; ++i){
        int a ;
        scanf("%d",&a) ;
        mp[a]++ ;
        am = max(a , am) ;
    }

    for(int i = 1 ; i * i <= t ;++i){
        if(t % i == 0){
            if(Solve(i , t / i)){
                return 0 ;
            }
        }
    }

    printf("-1\n") ;

    return 0 ;

}


#include <iostream>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>

using namespace std ;

const int maxn = 1000010 ;

int t , am ;

int mp[maxn] , nmp[maxn] ;

bool Solve(int n , int m){

    bool check1 = true ;
    bool check2 = true ;

    if(mp[0] != 1)
        return false ;
    if(am > n + m - 2)
        return false ;

    int x1 = 1 , y1 = 1  , x2 = 1 , y2 = 1;

    for(int i = 1 ; i <= am ; ++i){
        if(mp[i] < 4 * i){
            x1 = i ;
            y2 = i ;
            break ;
        }
    }

    y1 = (n + m - x1 - am) ;
    x2 = (n + m - y2 - am) ;
    if(((x1 < 1) || (x1 > n)) && ((x2 < 1) || (x2 > n)))
        return false ;
    if(((y1 < 1) || (y1 > m)) && ((y1 < 1) || (y2 > m)))
        return false ;

    memset(nmp , 0 , sizeof(nmp)) ;

    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            nmp[abs(x1 - i) + abs(y1 - j)]++ ;
        }
    }

    for(int i = 0 ; i <= am ; ++i){
        if(nmp[i] != mp[i]){
            check1 = false ;
            break ;
        }
    }

    memset(nmp , 0 , sizeof(nmp)) ;

    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            nmp[abs(x2 - i) + abs(y2 - j)]++ ;
        }
    }

    for(int i = 0 ; i <= am ; ++i){
        if(nmp[i] != mp[i]){
            check2 = false ;
            break ;
        }
    }

    if((check1 == false) && (check2 == false))
        return false ;

    printf("%d %d\n",n,m) ;

    if(check1){
        printf("%d %d\n",x1,y1) ;
    } else printf("%d %d\n",x2,y2) ;

    return true ;
}

int main(){

    scanf("%d",&t) ;

    for(int i = 1 ; i <= t ; ++i){
        int a ;
        scanf("%d",&a) ;
        mp[a]++ ;
        am = max(a , am) ;
    }

    for(int i = 1 ; i * i <= t ;++i){
        if(t % i == 0){
            if(Solve(i , t / i)){
                return 0 ;
            }
        }
    }

    printf("-1\n") ;

    return 0 ;

}


#include <iostream>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>

using namespace std ;

const int maxn = 1000010 ;

int t , am ;

map <int , int> mp , nmp ;

bool Solve(int n , int m){

    if(mp[0] != 1)
        return false ;
    if(am > n + m - 2)
        return false ;

    int x = 1 , y = 1 ;

    for(int i = 1 ; i <= am ; ++i){
        if(mp[i] < 4 * i){
            x = i ; break ;
        }
    }

    y = (n + m - x - am) ;
    if(x < 1 || x > n)
        return false ;
    if(y < 1 || y > m)
        return false ;

    nmp.clear() ;

    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            nmp[abs(x - i) + abs(y - j)]++ ;
        }
    }

    for(int i = 0 ; i <= am ; ++i){
        if(nmp[i] != mp[i]){
            return false ;
        }
    }

    printf("%d %d\n",n,m) ;

    printf("%d %d\n",x,y) ;

    return true ;
}

int main(){

    scanf("%d",&t) ;

    for(int i = 1 ; i <= t ; ++i){
        int a ;
        scanf("%d",&a) ;
        mp[a]++ ;
        am = max(a , am) ;
    }

    for(int i = 1 ; i * i <= t ;++i){
        if(t % i == 0){
            if(Solve(i , t / i)){
                return 0 ;
            }
        }
    }

    printf("-1\n") ;

    return 0 ;

}


#include <iostream>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>

using namespace std ;

const int maxn = 1000010 ;

int t , am ;

map <int , int> mp , nmp ;

bool Solve(int n , int m){

    if(mp[0] != 1)
        return false ;
    if(am > n + m - 2)
        return false ;

    int x = 0 , y = 0 ;

    for(int i = 1 ; i <= am ; ++i){
        if(mp[i] < 4 * i){
            x = i ; break ;
        }
    }

    y = (n + m - x - am) ;
    if(x < 1 || x > n)
        return false ;
    if(y < 1 || y > m)
        return false ;

    nmp.clear() ;

    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            nmp[abs(x - i) + abs(y - j)]++ ;
        }
    }

    for(int i = 0 ; i <= am ; ++i){
        if(nmp[i] != mp[i]){
            return false ;
        }
    }

    printf("%d %d\n",n,m) ;

    printf("%d %d\n",x,y) ;

    return true ;
}

int main(){

    scanf("%d",&t) ;

    for(int i = 1 ; i <= t ; ++i){
        int a ;
        scanf("%d",&a) ;
        mp[a]++ ;
        am = max(a , am) ;
    }

    for(int i = 1 ; i * i <= t ;++i){
        if(t % i == 0){
            if(Solve(i , t / i)){
                return 0 ;
            }
        }
    }

    printf("-1\n") ;

    return 0 ;

}


#include <iostream>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>

using namespace std ;

const int maxn = 1000010 ;

int t , am ;

map <int , int> mp , nmp ;

bool Solve(int n , int m){

    if(mp[0] != 1)
        return false ;
    if(am > n + m - 2)
        return false ;

    int x = 0 , y = 0 ;

    for(int i = 1 ; i <= am ; ++i){
        if(mp[i] < 4 * i){
            x = i ; break ;
        }
    }

    y = (n + m - x - am) ;
    if(x < 1 || x > n)
        return false ;
    if(y < 1 || y > m)
        return false ;

    nmp.clear() ;

    for(int i = 1 ; i <= n ; ++i){
        for(int j = 1 ; j <= m ; ++j){
            nmp[abs(x - i) + abs(y - j)]++ ;
        }
    }

    for(int i = 0 ; i <= am ; ++i){
        if(nmp[i] != mp[i]){
            return false ;
        }
    }

    printf("%d %d\n",n,m) ;

    printf("%d %d\n",x,y) ;

    return true ;
}

int main(){

    scanf("%d",&t) ;

    for(int i = 1 ; i <= t ; ++i){
        int a ;
        scanf("%d",&a) ;
        mp[a]++ ;
        am = max(a , am) ;
    }

    for(int i = 1 ; i * i <= t ;++i){
        if(t % i == 0){
            if(Solve(i , t / i)){
                break ;
            }
        }
    }

    printf("-1\n") ;

    return 0 ;

}


#include <iostream>
#include <cstdio>
#include <queue>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>

using namespace std ;

const int maxn = 1000010 ;

int t , am ;

int mp[maxn] , nmp[maxn] ;

bool Solve(int n , int m){

    bool check1 = true ;
    bool check2 = true ;

    if(mp[0] != 1)
        return false ;
    if(am > n + m - 2)
        return false ;

    int x1 = 1 , y1 = 1  , x2 = 1 , y2 = 1;

    for(int i = 1 ; i <= am ; ++i){
        if(mp[i] < 4 * i){
            x1 = i ;
            y2 = i ;
            break ;
        }
    }

    y1 = (n + m - x1 - am) ;
    x2 = (n + m - y2 - am) ;
    if((x1 < 1) || (x1 > n))
        check1 = false ;
    if((y1 < 1) || (y1 > m))
        check1 = false ;
    if((x2 < 1) || (x2 > n))
        check2 = false ;
    if((y2 < 1) || (y2 > m))
        check2 = false ;

    if(check1){
        memset(nmp , 0 , sizeof(nmp)) ;

        for(int i = 1 ; i <= n ; ++i){
            for(int j = 1 ; j <= m ; ++j){
                nmp[abs(x1 - i) + abs(y1 - j)]++ ;
            }
        }

        for(int i = 0 ; i <= am ; ++i){
            if(nmp[i] != mp[i]){
                check1 = false ;
                break ;
            }
        }
    }

    if(check2){
        memset(nmp , 0 , sizeof(nmp)) ;
        for(int i = 1 ; i <= n ; ++i){
            for(int j = 1 ; j <= m ; ++j){
                nmp[abs(x2 - i) + abs(y2 - j)]++ ;
            }
        }

        for(int i = 0 ; i <= am ; ++i){
            if(nmp[i] != mp[i]){
                check2 = false ;
                break ;
            }
        }
    }

    if((check1 == false) && (check2 == false))
        return false ;

    printf("%d %d\n",n,m) ;

    if(check1){
        printf("%d %d\n",x1,y1) ;
    } else printf("%d %d\n",x2,y2) ;

    return true ;
}

int main(){

    scanf("%d",&t) ;

    for(int i = 1 ; i <= t ; ++i){
        int a ;
        scanf("%d",&a) ;
        mp[a]++ ;
        am = max(a , am) ;
    }

    for(int i = 1 ; i * i <= t ;++i){
        if(t % i == 0){
            if(Solve(i , t / i)){
                return 0 ;
            }
        }
    }

    printf("-1\n") ;

    return 0 ;

}


#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) int(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 1000010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	cerr<<a<<" "<<b<<"\n";
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}

int a[N],cnt[N];
int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
int main(){
    //cout<<setprecision(9)<<fixed;
    srand(time(NULL));
    int T,ca=0,m=0,k,i,j,K,n;
	scanf("%d",&K);
	int mx=0;
	rep(i,0,K)scanf("%d",&k),a[k]++,Max(mx,k);
	if(!a[0]){
		puts("-1");return 0;
	}
	rep(n,1,K+1){
		if(1LL*n*n>K)break;
		if(K%n)continue;
		m=K/n;
		if(mx>n+m-2)continue;
		rep(x,1,n+1){
			int y=mx-(x-2);
			if(y<=0||y>m)continue;
			if(dist(x,y,n,1)>mx||dist(x,y,n,m)>mx||dist(x,y,1,m)>mx)continue;
			rep(j,1,n+1){
				rep(k,1,m+1){
					cnt[dist(x,y,j,k)]++;
				}
			}
			int ok=1;
			rep(j,0,mx+1){
				if(a[j]!=cnt[j]){
					ok=0;
				}
				cnt[j]=0;
			}
			if(ok){
				printf("%d %d\n%d %d\n",n,m,x,y);
				return 0;
			}
		}
	}
	puts("-1");
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) int(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 1000010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	cerr<<a<<" "<<b<<"\n";
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}

int a[N],cnt[N];
int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
int main(){
    //cout<<setprecision(9)<<fixed;
    srand(time(NULL));
    int T,ca=0,m=0,k,i,j,K,n;
	scanf("%d",&K);
	int mx=0;
	rep(i,0,K)scanf("%d",&k),a[k]++,Max(mx,k);
	if(!a[0]){
		puts("-1");return 0;
	}
	rep(n,1,K+1){
		if(1LL*n*n>K)break;
		if(K%n)continue;
		m=K/n;
		if(mx>n+m-2)continue;
		set<pii>c;
		c.insert({1,1});
		c.insert({n,1});
		c.insert({1,m});
		c.insert({n,m});
		rep(x,1,n+1){
			int y=mx-(x-2);
			if(y<=0||y>m)continue;
			int ok=1,num=0;
			for(auto &o:c){
				k=dist(x,y,o.x,o.y);
				if(k>mx){ok=0;break;}
				if(k==mx)num++;
			}
			//cerr<<x<<" "<<y<<" "<<num<<"\n";
			if(!ok||num!=a[mx])continue;
			num=0;
			rep(i,0,4){
				int nx=x+dx[i],ny=y+dy[i];
				if(nx<=0||nx>n||ny<=0||ny>m)continue;
				num++;
			}
			if(num!=a[1])continue;
			rep(j,1,n+1){
				rep(k,1,m+1){
					cnt[dist(x,y,j,k)]++;
				}
			}
			rep(j,0,mx+1){
				if(a[j]!=cnt[j]){
					ok=0;
				}
				cnt[j]=0;
			}
			if(ok){
				printf("%d %d\n%d %d\n",n,m,x,y);
				return 0;
			}
		}
	}
	puts("-1");
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) int(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 1000010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	cerr<<a<<" "<<b<<"\n";
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}

int a[N],cnt[N];
int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
int main(){
    //cout<<setprecision(9)<<fixed;
    srand(time(NULL));
    int T,ca=0,m=0,k,i,j,K,n;
	scanf("%d",&K);
	int mx=0;
	rep(i,0,K)scanf("%d",&k),a[k]++,Max(mx,k);
	if(!a[0]){
		puts("-1");return 0;
	}
	rep(n,1,K+1){
		if(1LL*n*n>K)break;
		if(K%n)continue;
		m=K/n;
		if(mx>n+m-2)continue;
		pii c[4]={{1,1},{n,1},{1,m},{n,m}};
		rep(x,1,n+1){
			int y=mx-(x-2);
			if(y<=0||y>m)continue;
			int ok=1,num=0;
			rep(i,0,4){
				k=dist(x,y,c[i].x,c[i].y);
				if(k>mx){ok=0;break;}
				if(k==mx)num++;
			}
			if(!ok||num!=a[mx])continue;
			num=0;
			rep(i,0,4){
				int nx=x+dx[i],ny=y+dy[i];
				if(nx<=0||nx>n||ny<=0||ny>m)continue;
				num++;
			}
			if(num!=a[1])continue;
			rep(j,1,n+1){
				rep(k,1,m+1){
					cnt[dist(x,y,j,k)]++;
				}
			}
			rep(j,0,mx+1){
				if(a[j]!=cnt[j]){
					ok=0;
				}
				cnt[j]=0;
			}
			if(ok){
				printf("%d %d\n%d %d\n",n,m,x,y);
				return 0;
			}
		}
	}
	puts("-1");
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) int(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 1000010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	cerr<<a<<" "<<b<<"\n";
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}

int a[N],cnt[N];
int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
int main(){
    //cout<<setprecision(9)<<fixed;
    srand(time(NULL));
    int T,ca=0,m=0,k,i,j,K,n;
	scanf("%d",&K);
	int mx=0;
	rep(i,0,K)scanf("%d",&k),a[k]++,Max(mx,k);
	if(!a[0]){
		puts("-1");return 0;
	}
	rep(n,1,K+1){
		if(1LL*n*n>K)break;
		if(K%n)continue;
		m=K/n;
		if(mx>n+m-2)continue;
		pii c[4]={{1,1},{n,1},{1,m},{n,m}};
		rep(x,1,n+1){
			int y=mx-(x-2);
			if(y<=0||y>m)continue;
			int ok=1,num=0;
			rep(i,0,4){
				k=dist(x,y,c[i].x,c[i].y);
				if(k>mx){ok=0;break;}
				if(k==mx)num++;
			}
			if(!ok||num!=a[mx])continue;
			num=0;
			rep(i,0,4){
				int nx=x+dx[i],ny=y+dy[i];
				if(nx<=0||nx>n||ny<=0||ny>m)continue;
				num++;
			}
			if(num!=a[1])continue;
			rep(j,1,n+1){
				rep(k,1,m+1){
					cnt[dist(x,y,j,k)]++;
				}
			}
			rep(j,0,mx+1){
				if(a[j]!=cnt[j]){
					ok=0;
				}
				cnt[j]=0;
			}
			if(ok){
				printf("%d %d\n%d %d\n",n,m,x,y);
				return 0;
			}
			break;
		}
	}
	puts("-1");
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) int(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 1000010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	cerr<<a<<" "<<b<<"\n";
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}

int a[N],cnt[N];
int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
int dx[]={0,0,-1,1},dy[]={-1,1,0,0};
int main(){
    //cout<<setprecision(9)<<fixed;
    srand(time(NULL));
    int T,ca=0,m=0,k,i,j,K,n;
	scanf("%d",&K);
	int mx=0;
	rep(i,0,K)scanf("%d",&k),a[k]++,Max(mx,k);
	if(!a[0]){
		puts("-1");return 0;
	}
	rep(n,1,K+1){
		if(1LL*n*n>K)break;
		if(K%n)continue;
		m=K/n;
		if(mx>n+m-2)continue;
		set<pii>c;
		c.insert({1,1});
		c.insert({n,1});
		c.insert({1,m});
		c.insert({n,m});
		rep(x,1,n+1){
			int y=mx-(x-2);
			if(y<=0||y>m)continue;
			int ok=1,num=0;
			for(auto &o:c){
				k=dist(x,y,o.x,o.y);
				if(k>mx){ok=0;break;}
				if(k==mx)num++;
			}
			//cerr<<x<<" "<<y<<" "<<num<<"\n";
			if(!ok||num!=a[mx])continue;
			num=0;
			rep(i,0,4){
				int nx=x+dx[i],ny=y+dy[i];
				if(nx<=0||nx>n||ny<=0||ny>m)continue;
				num++;
			}
			if(num!=a[1])continue;
			rep(j,1,n+1){
				rep(k,1,m+1){
					cnt[dist(x,y,j,k)]++;
				}
			}
			rep(j,0,mx+1){
				if(a[j]!=cnt[j]){
					ok=0;
				}
				cnt[j]=0;
			}
			if(ok){
				printf("%d %d\n%d %d\n",n,m,x,y);
				return 0;
			}
			break;
		}
	}
	puts("-1");
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) int(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 1000010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	cerr<<a<<" "<<b<<"\n";
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}

int a[N],cnt[N];
int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
void Add(int w,int h){
	if(w<=0||h<=0)return;
	int len=1;
	rep(i,1,w+h){
		cnt[i]+=len;
		if(i<w)len++;
		if(i>=h)len--;
	}
}
int main(){
    //cout<<setprecision(9)<<fixed;
    srand(time(NULL));
    int T,ca=0,m=0,k,i,j,K,n;
	scanf("%d",&K);
	int mx=0;
	rep(i,0,K)scanf("%d",&k),a[k]++,Max(mx,k);
	if(!a[0]){
		puts("-1");return 0;
	}
	rep(n,1,K+1){
		if(1LL*n*n>K)break;
		if(K%n)continue;
		m=K/n;
		if(mx>n+m-2)continue;
		set<pii>c;
		c.insert({1,1});
		c.insert({n,1});
		c.insert({1,m});
		c.insert({n,m});
		rep(x,1,n+1){
			if(x>(n+1)/2+1)break;
			int y=mx-(x-2);
			if(y<=0||y>m)continue;
			int ok=1,num=0;
			for(auto &o:c){
				k=dist(x,y,o.x,o.y);
				if(k>mx){ok=0;break;}
				if(k==mx)num++;
			}
			//cerr<<x<<" "<<y<<" "<<num<<"\n";
			if(!ok||num!=a[mx])continue;
			Add(x-1,y);
			Add(n-x+1,y-1);
			Add(n-x,m-y+1);
			Add(x,m-y);
			cnt[0]++;
			rep(j,0,mx+1){
				if(a[j]!=cnt[j]){
					ok=0;
				}
				cnt[j]=0;
			}
			if(ok){
				printf("%d %d\n%d %d\n",n,m,x,y);
				return 0;
			}
		}
	}
	puts("-1");
}


#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <assert.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) int(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353 //1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 1000010

template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	cerr<<a<<" "<<b<<"\n";
    int ans=1;
    while(b){
        if(b&1)ans=1LL*ans*a%mod;
        a=1LL*a*a%mod;b>>=1;
    }
    return ans;
}

int a[N],cnt[N];
int dist(int x1,int y1,int x2,int y2){
	return abs(x1-x2)+abs(y1-y2);
}
void Add(int w,int h){
	if(w<=0||h<=0)return;
	int len=1;
	rep(i,1,w+h){
		cnt[i]+=len;
		if(i<w)len++;
		if(i>=h)len--;
	}
}
int main(){
    //cout<<setprecision(9)<<fixed;
    srand(time(NULL));
    int T,ca=0,m=0,k,i,j,K,n;
	scanf("%d",&K);
	int mx=0;
	rep(i,0,K)scanf("%d",&k),a[k]++,Max(mx,k);
	if(!a[0]){
		puts("-1");return 0;
	}
	rep(n,1,K+1){
		if(1LL*n*n>K)break;
		if(K%n)continue;
		m=K/n;
		if(mx>n+m-2)continue;
		set<pii>c;
		c.insert({1,1});
		c.insert({n,1});
		c.insert({1,m});
		c.insert({n,m});
		rep(x,1,n+1){
		    int y=mx-(x-2);
			if(y<=0||y>m)continue;
			int ok=1,num=0;
			for(auto &o:c){
				k=dist(x,y,o.x,o.y);
				if(k>mx){ok=0;break;}
				if(k==mx)num++;
			}
			//cerr<<x<<" "<<y<<" "<<num<<"\n";
			if(!ok||num!=a[mx])continue;
			Add(x-1,y);
			Add(n-x+1,y-1);
			Add(n-x,m-y+1);
			Add(x,m-y);
			cnt[0]++;
			rep(j,0,mx+1){
				if(a[j]!=cnt[j]){
					ok=0;
				}
				cnt[j]=0;
			}
			if(ok){
				printf("%d %d\n%d %d\n",n,m,x,y);
				return 0;
			}
		}
	}
	puts("-1");
}


#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 <= end; l ++) if (a[l]) break;
		if (l > end)
		{
			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;
	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 main(int argc, char const *argv[])
{
	int t, x = 0, y = 0, end = 0;
	int a[1000009];
	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;
		}
	}

	int b[end + 5];
	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)
		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);

	}

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

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

	for (i = 0; a[i] == i*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 ++) b[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;
			}
		}
	}

	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));
	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 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 = 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)
			if (!memcmp(a, b, sizeof(a)))
			{
				printf("%d %d\n", i, j);
				printf("%d %d\n", x, y);
				return 0;
			}
		}
	}

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