You are given n integers. You need to choose a subset and put the chosen numbers in a beautiful rectangle (rectangular matrix). Each chosen number should occupy one of its rectangle cells, each cell must be filled with exactly one chosen number. Some of the n numbers may not be chosen.

A rectangle (rectangular matrix) is called beautiful if in each row and in each column all values are different.

What is the largest (by the total number of cells) beautiful rectangle you can construct? Print the rectangle itself.

Input

The first line contains n (1 ≤ n ≤ 4⋅10^5). The second line contains n integers (1 ≤ a_i ≤ 10^9).

Output

In the first line print x (1 ≤ x ≤ n) — the total number of cells of the required maximum beautiful rectangle. In the second line print p and q (p ⋅ q=x): its sizes. In the next p lines print the required rectangle itself. If there are several answers, print any.

Examples

Input


12
3 1 4 1 5 9 2 6 5 3 5 8


Output


12
3 4
1 2 3 5
3 1 5 4
5 6 8 9


Input


5
1 1 1 1 1


Output


1
1 1
1

Difficulty: HARD
Tags: Constructive algorithms

Combinatorics

Complete search

Greedy algorithms

Mathematics

Data structures
Skill types: Complete search

Data structures

Greedy algorithms

Starter code:

Solutions:
def play(arr):
	n = len(arr)
	number2Count = {}
	for p in arr:
		number2Count[p] = number2Count.get(p, 0) + 1
	count2Numbers = {}
	maxCnt = 0
	for num in number2Count:
		cnt = number2Count[num]
		if not cnt in count2Numbers:
			count2Numbers[cnt] = []
		count2Numbers[cnt].append(num)
		maxCnt = max(maxCnt, cnt)
	numRepeats = [0] * (n + 1)
	numRepeats[n] = len(count2Numbers.get(n, []))
	for i in range(n - 1, 0, -1):
		numRepeats[i] = numRepeats[i + 1] + len(count2Numbers.get(i, []))
	a_ideal = 0
	b_ideal = 0
	square = 0
	square_ideal = 0
	for a in range(1, n + 1):
		square += numRepeats[a]
		b = int(square / a)
		if a <= b:
			if square_ideal < a * b:
				square_ideal = a * b
				a_ideal = a
				b_ideal = b
	print(a_ideal * b_ideal)
	print(str(a_ideal) + ' ' + str(b_ideal))
	matrix = [[0] * b_ideal for p in range(0, a_ideal)]
	x = 0
	y = 0
	for cnt in range(maxCnt, 0, -1):
		for num in count2Numbers.get(cnt, []):
			for i in range(0, min(cnt, a_ideal)):
				if matrix[x][y] > 0:
					x = (x + 1) % a_ideal
				if matrix[x][y] == 0:
					matrix[x][y] = num
				x = (x + 1) % a_ideal
				y = (y + 1) % b_ideal
	for i in range(0, a_ideal):
		print(*matrix[i])

def main():
	input()
	arr = list(map(int, input().split()))
	play(arr)
main()


n = int(input())
l = list(map(int, input().split()))
if n == 1:
	print(1)
	print(1, 1)
	print(l[0])
else:
	d = {}
	for i in l:
		d[i] = 0
	for i in l:
		d[i] += 1
	equal = [0] * (n + 1)
	for i in d:
		equal[d[i]] += 1
	atmost = [0] * (n + 1)
	atmost[0] = equal[0]
	for i in range(1, n + 1):
		atmost[i] = atmost[i - 1] + equal[i]
	sumka = 0
	best_iloczyn = 0
	best_a = 0
	best_b = 0
	for a in range(1, n):
		if a ** 2 > n:
			break
		sumka += len(d) - atmost[a - 1]
		b_cand = sumka // a
		if b_cand < a:
			continue
		if a * b_cand > best_iloczyn:
			best_iloczyn = a * b_cand
			best_a = a
			best_b = b_cand
	print(best_iloczyn)
	print(best_a, best_b)
	li = []
	for i in d:
		if d[i] >= best_a:
			li += [i] * min(best_a, d[i])
	for i in d:
		if d[i] < best_a:
			li += [i] * min(best_a, d[i])
	mat = [[0] * best_b for i in range(best_a)]
	for dd in range(1, best_a + 1):
		if best_a % dd == 0 and best_b % dd == 0:
			du = dd
	i = 0
	for st in range(du):
		for j in range(best_iloczyn // du):
			mat[i % best_a][(st + i) % best_b] = li[i]
			i += 1
	for i in range(best_a):
		print(*mat[i])


from collections import Counter
from itertools import accumulate
from math import sqrt
from operator import itemgetter
import sys
n = int(input())
cnt = Counter(map(int, input().split()))
(nums, counts) = zip(*sorted(cnt.items(), key=itemgetter(1)))
acc = [0] + list(accumulate(counts))
area = 1
(h, w) = (1, 1)
i = len(counts)
for y in range(int(sqrt(n)), 0, -1):
	while i and counts[i - 1] > y:
		i -= 1
	total = acc[i] + (len(counts) - i) * y
	x = total // y
	if y <= x and area < x * y:
		(h, w, area) = (y, x, x * y)
ans = [[0] * w for _ in range(h)]
i = len(counts) - 1
(num, count) = (nums[i], min(h, counts[i]))
for x in range(w):
	for y in range(h):
		ans[y][(x + y) % w] = num
		count -= 1
		if count == 0:
			i -= 1
			(num, count) = (nums[i], h if h < counts[i] else counts[i])
print(area)
print(h, w)
for y in range(h):
	sys.stdout.write(' '.join(map(str, ans[y])) + '\n')


from collections import Counter
from sys import stdin

def input():
	return next(stdin)[:-1]

def main():
	n = int(input())
	aa = input().split()
	cc = list(Counter(aa).most_common())
	if n % cc[0][1] == 0 and cc[0][1] * cc[0][1] <= n:
		h = cc[0][1]
		w = n // cc[0][1]
		best = n
	else:
		count_count = [0] * (n + 1)
		for (v, c) in cc:
			count_count[c] += 1
		geq = [count_count[n]]
		for v in reversed(count_count[:n]):
			geq.append(geq[-1] + v)
		geq.reverse()
		tot = 0
		best = 0
		for a in range(1, n + 1):
			tot += geq[a]
			b = tot // a
			if a <= b and best < a * b:
				best = a * b
				h = a
				w = b
	print(best)
	print(h, w)
	x = 0
	y = 0
	mat = [[''] * w for _ in range(h)]
	for (v, c) in cc:
		for j in range(min(c, h)):
			if mat[x][y] != '':
				x = (x + 1) % h
			if mat[x][y] == '':
				mat[x][y] = v
			x = (x + 1) % h
			y = (y + 1) % w
	for i in range(h):
		print(' '.join(mat[i]))
main()


n = int(input())
arr = list(map(int, input().split()))
d = {}
for i in arr:
	d[i] = d.get(i, 0) + 1
d2 = {}
for (k, v) in d.items():
	d2.setdefault(v, []).append(k)
s = n
prev = 0
ansp = ansq = anss = 0
for p in range(n, 0, -1):
	q = s // p
	if p <= q and q * p > anss:
		anss = q * p
		ansq = q
		ansp = p
	prev += len(d2.get(p, []))
	s -= prev

def get_ans():
	cur_i = 0
	cur_j = 0
	cur = 0
	for (k, v) in d3:
		for val in v:
			f = min(k, anss - cur, ansp)
			cur += f
			for i in range(f):
				cur_i = (cur_i + 1) % ansp
				cur_j = (cur_j + 1) % ansq
				if ans[cur_i][cur_j]:
					cur_i = (cur_i + 1) % ansp
				ans[cur_i][cur_j] = val
print(anss)
print(ansp, ansq)
d3 = sorted(d2.items(), reverse=True)
ans = [[0] * ansq for i in range(ansp)]
get_ans()
for i in range(ansp):
	print(*ans[i])