An English text needs to be encrypted using the following encryption scheme. 

First, the spaces are removed from the text. Let $L$ be the length of this text. 

Then, characters are written into a grid, whose rows and columns have the following constraints:

$\lfloor\sqrt{L}\rfloor\leq row\leq column\leq\lceil\sqrt{L}\rceil,\text{where}\lfloor x\rfloor\text{is floor function and}\lceil x\rceil\text{is cell function}$ 

Example  

$s=\textbf{if man was meant to stay on the ground good would have given us roots}$  

After removing spaces, the string is $54$ characters long.  $\sqrt{54}$ is between $7$ and $8$, so it is written in the form of a grid with 7 rows and 8 columns. 

ifmanwas  
meanttos          
tayonthe  
groundgo  
dwouldha  
vegivenu  
sroots

Ensure that $rows\times columns\geq L$   
If multiple grids satisfy the above conditions, choose the one with the minimum area, i.e. $rows\times columns$.  

The encoded message is obtained by displaying the characters of each column, with a space between column texts. The encoded message for the grid above is:  

imtgdvs fearwer mayoogo anouuio ntnnlvt wttddes aohghn sseoau  

Create a function to encode a message.

Function Description  

Complete the encryption function in the editor below.  

encryption has the following parameter(s):  

string s: a string to encrypt  

Returns  

string: the encrypted string  

Input Format

One line of text, the string $\boldsymbol{\mathrm{~S~}}$

Constraints

$1\leq\ \text{length of}\ s\leq81$ 

$\boldsymbol{\mathrm{~S~}}$ contains characters in the range ascii[a-z] and space, ascii(32).

Sample Input
haveaniceday

Sample Output 0

hae and via ecy

Explanation 0  

$L=12$, $\sqrt{12}$ is between $3$ and $4$. 

Rewritten with $3$ rows and $4$ columns:

have
anic
eday

Sample Input 1

feedthedog    

Sample Output 1

fto ehg ee dd

Explanation 1  

$L=\textbf{10}$, $\sqrt{10}$ is between $3$ and $4$. 

Rewritten with $3$ rows and $4$ columns:  

feed
thed
og

Sample Input 2

chillout

Sample Output 2

clu hlt io

Explanation 2  

$L=8$, $\sqrt{8}$ is between $2$ and $3$. 

Rewritten with $3$ columns and $3$ rows ($2*3=6<8$ so we have to use $3X3$.)

chi
llo
ut

Source: hackerrank | Difficulty: MEDIUM
Tags: Implementation


Solutions:
from math import sqrt
st = input()
size = len(st)
sq = int(sqrt(size))
minArea = 2 * size
minRows = 0
minCols = 2 * size
for i in range(1, 3 * sq):
	for j in range(i, 3 * sq):
		if i * j < size:
			continue
		else:
			if j - i < minCols - minRows:
				minArea = i * j
				minRows = i
				minCols = j
			break
output = ''
for j in range(minCols):
	for i in range(minRows):
		val = minCols * i + j
		if val < len(st):
			output += st[val]
	output += ' '
print(output)


txt = input()
size = len(txt)
w = size ** 0.5
if w != round(w):
	w = round(w + 0.5)
w = int(w)
ar = []
col = 0
add = []
for c in txt:
	if col >= w:
		ar.append(add)
		add = []
		col = 0
	add.append(c)
	col += 1
if len(add) > 0:
	ar.append(add)
out = ''
for i in range(0, w):
	for e in ar:
		if i < len(e):
			out += e[i]
	out += ' '
print(out)


from math import *

def main():
	str = input()
	Len = len(str)
	i = int(sqrt(Len))
	j = i
	if Len == 43:
		i = 7
		j = 7
	while Len > i * j:
		case = 0
		case2 = 0
		min = 100
		if abs(Len - (j + 1) * (i + 1)) < min:
			min = abs(Len - (j + 1) * (i + 1))
			case = 1
			case2 = 1
		if abs(Len - (j + 1) * i) < min:
			min = abs(Len - (j + 1) * i)
			case = 0
			case2 = 1
		if abs(Len - (i + 1) * j) < min:
			min = abs(Len - (i + 1) * j)
			case = 1
			case2 = 0
		i = i + case
		j = j + case2
	arr = []
	for n in range(i):
		row = []
		for m in range(j):
			if m + n * j == Len:
				break
			row.append(str[m + n * j])
		arr.append(row)
	final = ''
	for n in range(j):
		word = ''
		for m in range(i):
			try:
				word += arr[m][n]
			except IndexError:
				word += ''
		final = final + word + ' '
	print(final)
main()


import itertools, sys
s = sys.stdin.readline().strip()
dim = int(len(s) ** 0.5)
if dim * dim == len(s):
	(x, y) = (dim, dim)
else:
	(x, y) = (dim, dim + 1)
array = [s[i:i + y] for i in range(0, len(s), y)]
transpose = itertools.zip_longest(*array, fillvalue='')
print(' '.join((''.join(s) for s in transpose)))


msg = input().strip()
from math import ceil, floor, sqrt

def enc(msg):
	sr = sqrt(len(msg))
	(row, col) = (floor(sr), ceil(sr))
	rt = []
	for i in range(col):
		tmp = []
		ind = i
		while ind < len(msg):
			tmp.append(msg[ind])
			ind += col
		tmp = ''.join(tmp)
		rt.append(tmp)
	return ' '.join(rt)
print(enc(msg))


import sys, math
message = sys.stdin.read().strip()
boxheight = math.ceil(math.sqrt(len(message)))
box = [[] for _ in range(boxheight)]
for (index, char) in enumerate(message):
	boxindex = index % boxheight
	box[boxindex].append(char)
print(' '.join((''.join((c for c in q)) for q in box)))


import math

def main():
	string = input()
	char = list(string)
	size = math.ceil(math.sqrt(len(string)))
	out = [''] * size
	count = 0
	for i in char:
		if count >= size:
			count = 0
		out[count] += i
		count = count + 1
	for j in range(len(out)):
		if j == len(out) - 1:
			print(out[j])
		else:
			print(out[j], end=' ')
main()


import sys
from itertools import islice
text = ''.join(sys.stdin.readline().strip())
n = len(text)
q = int(pow(n, 0.5))
(a, b) = (n, n)
for i in range(q, q + 2):
	for j in range(q, q + 2):
		if i <= j and i * j >= n and (i * j < a * b):
			(a, b) = (i, j)
ans = []
for i in range(b):
	ans.append(''.join(islice(text, i, None, b)))
print(' '.join(ans))


s = input()
l = len(s)
x = l ** 0.5
x = x // 1
y = 0
if x * x >= l:
	x = x
	y = x
elif x * (x + 1) >= l:
	y = x
	x = x + 1
else:
	x = x + 1
	y = x
x = int(x)
y = int(y)
a = [['' for i in range(0, 15)] for j in range(0, 15)]
t = 0
for i in range(0, y):
	for j in range(0, x):
		if t < l:
			a[j][i] = s[t]
			t += 1
for i in range(0, x):
	ans = ''
	for j in range(0, y):
		ans = ans + a[i][j]
	if i < x - 1:
		print(ans, end=' ')
	else:
		print(ans)


import sys, math, string
plaintext = sys.stdin.readline().strip()
cols = math.ceil(math.sqrt(len(plaintext)))
rows = math.ceil(math.sqrt(len(plaintext)))
result = []
for n in range(0, rows):
	result.append('')
for j in range(0, cols):
	for i in range(0, rows):
		index = j * rows + i
		try:
			result[i] += plaintext[index]
		except IndexError:
			pass
print(' '.join(result))


import math

class Encryption:

	def getInput(self, line):
		self.line = line.strip('\n')
		self.rows = math.ceil(math.sqrt(len(self.line)))

	def encrypt(self):
		self.out = ''
		for i in range(self.rows):
			j = i
			while j < len(self.line):
				self.out = self.out + self.line[j]
				j = j + self.rows
			self.out = self.out + ' '
		return self.out.strip(' ')
enc = Encryption()
enc.getInput(input())
print(enc.encrypt())


import math

def main():
	txt = str(input())
	l = len(txt)
	h = math.floor(math.sqrt(l))
	w = math.ceil(math.sqrt(l))
	while w * h > l:
		h -= 1
	if w * h < l:
		h += 1
	beg = 0
	end = w
	lst = []
	while beg <= l:
		lst.append(txt[beg:end])
		beg = end
		end += w
	l = len(lst)
	txt = ''
	for j in range(0, w):
		for i in range(0, l):
			if len(lst[i]) - 1 >= j:
				txt += lst[i][j]
		txt += ' '
	txt = txt[0:len(txt) - 1]
	print(txt)
main()


import math
strng = input()
Width = math.floor(math.sqrt(len(strng)))
Height = math.ceil(math.sqrt(len(strng)))
OUT = []
for i in range(0, Height):
	s = ''
	j = i
	while j < len(strng):
		s += strng[j]
		j = j + Height
	OUT.append(s)
for o in OUT:
	print(o, end=' ')


from math import sqrt, floor, ceil
from itertools import zip_longest

def main():
	line = input().strip()
	length = len(line)
	sroot = sqrt(length)
	(low, high) = (floor(sroot), ceil(sroot))
	l = []
	for i in range(0, length, high):
		l.append(line[i:i + high])
	print(' '.join(list(map(lambda x: ''.join(x), zip_longest(*l, fillvalue='')))))
main()


s = input()
n = 1
while n * n < len(s):
	n += 1
a = s + ' ' * (n * n - len(s))
a = [a[i:i + n] for i in range(0, n * n, n)]
print(' '.join([''.join([a[j][i] for j in range(n)]).strip() for i in range(n)]))


import math
strin = input()
nrow = math.floor(math.sqrt(len(strin)))
ncol = math.ceil(math.sqrt(len(strin)))
length = len(strin)
for i in range(ncol):
	n = i
	for j in range(nrow):
		while n < length:
			print(strin[n], end='')
			n = n + ncol
	print(' ', end='')


import math
a = input()
l = len(a)
i = 0
c = 0
h = 1
t = math.floor(math.sqrt(l))
r = math.ceil(math.sqrt(l))
while c < l:
	print(a[i], end='')
	i = i + r
	c = c + 1
	if i >= l:
		i = h
		h += 1
		print(' ', end='')


import math
in_text = input().strip()
len_sqrt = math.sqrt(len(in_text))
columns = int(math.ceil(len_sqrt))
rows = int(math.ceil(len_sqrt))
if int(len(in_text) / columns) < rows - 1:
	rows -= 1
encoded = ''
for c in range(columns):
	for r in range(rows):
		if r * columns + c < len(in_text):
			encoded += in_text[r * columns + c]
	if c < columns:
		encoded += ' '
print(encoded)


s = input()
ls = len(s)
f = int(ls ** 0.5)
if f ** 2 == ls:
	r = c = f
elif f * (f + 1) >= ls:
	(r, c) = (f, f + 1)
else:
	r = c = f + 1
for i in range(c):
	w = ''
	for j in range(r):
		ind = i + j * c
		if ind > len(s) - 1:
			break
		w += s[ind]
	print(w, end=' ')


import math
s = input()
x = len(s)
h = math.floor(x ** 0.5)
w = math.ceil(x ** 0.5)
if h * w > x:
	e = h * w - x
	for i in range(0, e):
		s += ' '
elif h * w < x:
	h += 1
l = [''] * w
for i in range(0, x):
	l[i % w] += s[i]
for x in l:
	print(x, end=' ')


from math import floor
from math import sqrt
from math import ceil

def rect_height(l):
	root = sqrt(l)
	(_min, _max) = (int(floor(root)), int(ceil(root)))
	if _min ** 2 >= l:
		return _min
	else:
		return _max

def encode(s):
	l = len(s)
	height = rect_height(l)
	rect = []
	for i in range(height):
		word = []
		for j in range(i, l, height):
			word.append(s[j])
		rect.append(''.join(word))
	return ' '.join(rect)
s = input().strip()
print(encode(s))


from math import sqrt, floor, ceil
x = input()
le = len(x)
l = sqrt(le)
rows = floor(l)
cols = ceil(l)
if rows * cols < le:
	rows += 1
encrypt = [['' for i in range(cols)] for i in range(rows)]
for (i, char) in enumerate(x):
	encrypt[i // cols][i % cols] = char
words = [[encrypt[i][j] for i in range(rows)] for j in range(cols)]
print(' '.join([''.join(a) for a in words]))


import math

def main():
	inp = str(input())
	n = len(inp)
	row = int(math.floor(math.sqrt(n)))
	col = int(math.ceil(math.sqrt(n)))
	for i in range(0, col):
		j = i
		while j < n:
			print(inp[j], end='')
			j += col
		print('', end=' ')
main()


import math

def encryption(l):
	encrypted = ''
	width = math.ceil(math.sqrt(len(l)))
	height = int(math.sqrt(len(l)))
	for start in range(0, width):
		for letter in range(start, len(l), width):
			encrypted += l[letter]
		encrypted += ' '
	return encrypted[:-1]
l = input()
print(encryption(l))


import math
word = input().strip()
word.replace(' ', '')
height = math.floor(math.sqrt(len(word)))
width = math.ceil(math.sqrt(len(word)))
while height * width < len(word):
	height = height + 1
word = word + '                                '
for i in range(0, width):
	for j in range(0, height):
		print(word[i + width * j].replace(' ', ''), end='')
	print(' ', end='')
print('')


from math import *
str = input()
w = int(sqrt(len(str)))
h = int(sqrt(len(str)))
while w * h < len(str):
	if w == h:
		h += 1
	else:
		w += 1
for r in range(h):
	for c in range(w):
		tmp = c * h + r
		if tmp < len(str):
			print(str[tmp], end='')
		if c == w - 1:
			print(' ', end='')


from math import *
P = [x for x in input().strip()]
L = len(P)
H = W = int(L ** 0.5)
if H * W < len(P):
	W += 1
if H * W < len(P):
	H += 1
P += [''] * (H * W - len(P))
s = ''
for w in range(0, W):
	for h in range(0, H):
		s += P[h * W + w]
	s += ' '
s = s[:-1]
print(s)


from math import floor, ceil, sqrt

def is_square(apositiveint):
	if apositiveint == 0 or apositiveint == 1:
		return True
	x = apositiveint // 2
	seen = set([x])
	while x * x != apositiveint:
		x = (x + apositiveint // x) // 2
		if x in seen:
			return False
		seen.add(x)
	return True
sentence = input().replace(' ', '')
height = floor(sqrt(len(sentence)))
width = ceil(sqrt(len(sentence)))
if not is_square(len(sentence)):
	height += 1
new_sentence = []
for i in range(height):
	for j in range(width + 1):
		if i + j * width < len(sentence):
			new_sentence.append(sentence[i + j * width])
	new_sentence.append(' ')
print(''.join(new_sentence))


from math import floor, ceil, sqrt
original = input()
width = ceil(sqrt(len(original)))
height = floor(sqrt(len(original)))
print(' '.join((original[i:81:width] for i in range(height + (width != height)))))


import math
intext = input()
n = len(intext)
minW = math.floor(math.sqrt(n))
maxW = math.ceil(math.sqrt(n))
maxi = 9999999
pair = (99999, 99999)
for i in range(minW, maxW + 1):
	for j in range(i, maxW + 1):
		if i * j >= n:
			if i * j < maxi:
				maxi = i * j
				pair = (i, j)
intext = intext.ljust(pair[0] * pair[1])
cube = []
for i in range(pair[0]):
	cube.append(intext[i * pair[1]:i * pair[1] + pair[1]])
coded = ''
for i in range(pair[1]):
	tmp = ''
	for j in range(pair[0]):
		tmp += cube[j][i]
	tmp = tmp.strip()
	coded += tmp + ' '
print(coded)


import math
raw = input()
colh = math.floor(math.sqrt(len(raw)))
rowh = math.ceil(math.sqrt(len(raw)))
rows = [''] * rowh
for i in range(len(raw)):
	rows[i % rowh] += raw[i]
pprint = ''
for row in rows:
	pprint += row + ' '
print(pprint.strip())


s = input()
l = len(s)
for i in range(l + 1):
	if i * i >= l:
		c = i
		break
print(' '.join((s[i::c] for i in range(c))))


import math
sentence = input()
numberOfRows = math.floor(math.sqrt(len(sentence)))
numberOfCols = math.ceil(math.sqrt(len(sentence)))
if numberOfRows * numberOfCols < len(sentence):
	numberOfRows += 1
table = [[]]
for (index, char) in enumerate(sentence):
	if index // numberOfCols > len(table) - 1:
		table.append([])
	table[index // numberOfCols].append(char)
for index in range(numberOfRows * numberOfCols):
	try:
		print(table[index % numberOfRows][index // numberOfRows], end='')
	except IndexError:
		pass
	if index % numberOfRows == numberOfRows - 1:
		print(' ', end='')


import sys
import math
for line in sys.stdin:
	string = line.strip()
	width = length = 1
	while width * length < len(string):
		width += 1
		if width * length < len(string):
			length += 1
	print(' '.join((string[i::width] for i in range(width))))


import math
message = input()
l = len(message)
rows = int(math.sqrt(l))
cols = rows
if cols * rows < l:
	cols += 1
if cols * rows < l:
	rows += 1
result = ''
for c in range(cols):
	for r in range(rows):
		pos = r * cols + c
		if pos < l:
			result += message[pos]
	if c != cols - 1:
		result += ' '
print(result)


from math import sqrt, ceil, floor
from itertools import zip_longest
message = input()
s = sqrt(len(message))
(row_count, col_count) = (floor(s), ceil(s))
print(' '.join([message[i::col_count] for i in range(col_count)]))


import math
x = input().strip()
l = len(x)
a = math.floor(math.sqrt(l))
b = math.ceil(math.sqrt(l))
if a != math.sqrt(l):
	a += 1
for i in range(a):
	j = 0
	while i + j < l:
		print(x[i + j], end='')
		j += b
	print(' ', end='')


import sys
from math import ceil, floor, sqrt

def decode(string):
	l = sqrt(len(string))
	possibles = [(floor(l), floor(l)), (floor(l), ceil(l)), (ceil(l), ceil(l))]
	(rows, cols) = min([(row, ceil) for (row, ceil) in possibles if row * ceil >= len(string)])
	answer = [string[i::cols] for i in range(cols)]
	return ' '.join(answer)

def main():
	print(decode(sys.stdin.readline().strip()))
main()


import sys
from math import floor, ceil, sqrt
word = sys.stdin.readline().strip()
width = height = floor(sqrt(len(word)))
maxheight = ceil(sqrt(len(word)))
while width * height < len(word) and width <= height and (height <= maxheight):
	if width == height:
		height += 1
	elif (width + 1) * height > width * (height + 1):
		width += 1
	else:
		height += 1
encrypted = ''
enc = []
if width != height:
	width += 1
for j in range(width):
	for i in range(height):
		if height * i + j < len(word):
			encrypted += word[height * i + j]
	enc.append(encrypted)
	encrypted = ''
print(' '.join(enc))


from math import ceil, sqrt
plaintext = str(input()).strip()
width = ceil(sqrt(len(plaintext)))
ciphertext = ''
for i in range(width):
	if len(ciphertext) > 0:
		ciphertext += ' '
	for j in range(i, len(plaintext), width):
		ciphertext += plaintext[j]
print(ciphertext)


import sys, collections, math, itertools
n = input()

def encryption(n):
	n = n.replace(' ', '')
	height = math.ceil(len(n) ** (1 / 2))
	width = math.floor(len(n) ** (1 / 2))
	minarea = sys.maxsize
	(h, w) = (0, 0)
	for i in range(width, height + 1):
		for j in range(1, height + 1):
			if i * j >= len(n) and i * j < minarea:
				minarea = i * j
				(w, h) = (i, j)
	p = list(n)
	matrix = [p[i:i + h] for i in range(0, len(p), h)]
	res = ''
	almost = list(itertools.zip_longest(*matrix, fillvalue=''))
	for i in almost:
		res += ''.join(i)
		res += ' '
	return res[:-1]
print(encryption(n))


import math
message = input()
length = len(message)
assert 1 <= length <= 81
floorz = int(math.sqrt(length))
ceilz = int(math.ceil(math.sqrt(length)))
if floorz is not ceilz:
	if floorz < ceilz and floorz * ceilz >= length:
		(rows, cols) = (floorz, ceilz)
	else:
		(rows, cols) = (ceilz, ceilz)
else:
	(rows, cols) = (floorz, floorz)
encode = []
answer = dict.fromkeys(range(cols), '')
for x in range(rows):
	encode = message[x * cols:x * cols + cols]
	for y in range(len(encode)):
		answer[y] += encode[y]
print(' '.join(answer.values()))


from itertools import zip_longest
from math import sqrt
m = input()
m_len = len(m)
min_dim = int(sqrt(m_len))
(w, h) = (min_dim, min_dim)
if w * h < m_len:
	w += 1
enc = zip_longest(*[m[i:i + w] for i in range(0, m_len, w)], fillvalue='')
print(' '.join((''.join(w) for w in enc)))


import sys
import math
text = sys.stdin.readline().strip()
sqrt = math.sqrt(len(text))
num_rows = math.floor(sqrt)
num_columns = math.ceil(sqrt)
for i in range(num_columns):
	for j in range(i, len(text), num_columns):
		print(text[j], end='')
	print(' ', end='')


from math import sqrt, ceil, floor
s = input().strip()
res = ''
rows = floor(sqrt(len(s)))
cols = ceil(sqrt(len(s)))
if rows * cols < len(s):
	rows += 1
for col in range(cols):
	for row in range(rows):
		idx = col + row * cols
		if idx < len(s):
			res += s[idx]
	res += ' '
print(res)


import math
input_string = str(input())
length = len(input_string)
(best_w, best_h, best_surface) = (-1, -1, 100000)
for height in range(1, math.ceil(math.sqrt(length)) + 1):
	width = length // height
	surface = width * height
	if surface != length:
		width += 1
		surface += height
	if math.floor(math.sqrt(length)) > width:
		continue
	if surface < best_surface:
		surface = best_surface
		best_w = width
		best_h = height
if best_w < best_h:
	(best_w, best_h) = (best_h, best_w)
output = ''
for i in range(height):
	for j in range(width):
		idx = j * height + i
		if idx < length:
			output += input_string[idx]
		else:
			break
	output += ' '
print(output)


from math import sqrt, ceil
word = str(input().strip())
n = len(word)
width = ceil(sqrt(n))
height = ceil(n / width)
s = ''
for j in range(width):
	for i in range(height):
		if i * width + j < len(word):
			s += word[i * width + j]
	s += ' '
print(s)


import math
text = input()
cols = math.ceil(math.sqrt(len(text)))
words = [text[i::cols] for i in range(cols)]
print(' '.join(words))


import sys
import math

def opt_size(x):
	rows_min = math.floor(math.sqrt(x))
	collumns_min = math.floor(math.sqrt(x))
	rows_max = math.ceil(math.sqrt(x))
	collumns_max = math.ceil(math.sqrt(x))
	smallest = [rows_max * collumns_max, rows_max, collumns_max]
	for rows in range(rows_min, rows_max + 1):
		for collumns in range(rows_min, rows_max + 1):
			if rows * collumns < smallest[0] and rows * collumns >= x:
				smallest = [rows * collumns, rows, collumns]
	(rows, collumns) = smallest[1:]
	return (rows, collumns)

def make_rectangle(s):
	(height, width) = opt_size(len(s))
	rect = []
	for a in range(height):
		row = []
		for b in range(width):
			row.append('')
		rect.append(row)
	for a in range(height):
		for b in range(width):
			if a * width + b < len(s):
				rect[a][b] = s[a * width + b]
			else:
				rect[a][b] = ''
	return rect

def transponse(matrix):
	y = len(matrix)
	x = len(matrix[0])
	tr = []
	for a in range(x):
		row = []
		for b in range(y):
			row.append('')
		tr.append(row)
	for a in range(x):
		for b in range(y):
			tr[a][b] = matrix[b][a]
	return tr

def tests():
	t = opt_size
	assert t(9) == (3, 3)

def main():
	text = sys.stdin.readline().strip()
	text_rect = make_rectangle(text)
	text_rect = transponse(text_rect)
	print(' '.join([''.join([str(i) for i in row]) for row in text_rect]))
main()


import math

def prog():
	string = str(input())
	width = math.floor(math.sqrt(len(string)))
	height = math.ceil(math.sqrt(len(string)))
	output = [''] * height
	for i in range(len(string)):
		output[i % height] += string[i]
	print(' '.join(output))
prog()


import math as m
s = list(input())
sl = len(s)
mn = m.floor(sl ** 0.5)
mx = m.ceil(sl ** 0.5)
minarea = 100
for r in range(mn, mx + 1):
	for c in range(mn, mx + 1):
		area = r * c
		if area >= sl and area < minarea:
			(minr, minc) = (r, c)
for _ in range(r * c - len(s)):
	s.append('')
print(' '.join((''.join((s[i * minc + j] for i in range(minr))) for j in range(minc))))


import math
word = input()
wordSize = len(word)
width = math.floor(math.sqrt(wordSize))
height = math.ceil(math.sqrt(wordSize))
words = ['' for x in range(height)]
for i in range(wordSize):
	xIndex = i % height
	words[xIndex] += word[i]
print(' '.join(words))


import itertools, sys
s = sys.stdin.readline().strip()
dim = int(len(s) ** 0.5)
if dim * dim == len(s):
	(x, y) = (dim, dim)
else:
	(x, y) = (dim, dim + 1)
array = [s[i:i + y] for i in range(0, len(s), y)]
transpose = itertools.zip_longest(*array, fillvalue='')
print(' '.join((''.join(s) for s in transpose)))


from math import sqrt, floor, ceil
line = input()
lower = floor(sqrt(len(line)))
upper = ceil(sqrt(len(line)))
for width in range(lower, upper + 1):
	for height in range(lower, upper + 1):
		if width * height >= len(line):
			break
row = []
matrix = []
for char in line:
	if len(row) == width:
		matrix.append(row)
		row = []
	row.append(char)
if len(row) != 0:
	matrix.append(row)
sentence = ''
for i in range(width):
	word = ''
	for j in range(height):
		row = matrix[j]
		if i < len(row):
			word += row[i]
	sentence += word + ' '
print(sentence)


from math import *
s = input()
col = ceil(sqrt(len(s)))
row = int(sqrt(len(s)))
a = []
for i in range(row + 1):
	r = ''
	for j in range(i, len(s), col):
		r += s[j]
	a.append(r)
if a[0] == a[0][0] + a[len(a) - 1]:
	a = a[:len(a) - 1]
print(*a)


import math
ls = [x for x in input()]
N = len(ls)
w = int(math.sqrt(N))
h = int(math.sqrt(N))
if w * h < N:
	w = w + 1
res = []
for i in range(0, w):
	res.append('')
for i in range(0, N):
	res[i % w] = res[i % w] + ls[i]
print(' '.join(res))


word = input()
import math
(low_dim, high_dim) = (int(math.floor(len(word) ** 0.5)), int(math.ceil(len(word) ** 0.5)))
width = height = low_dim
if low_dim != high_dim:
	width = high_dim
if width * height < len(word):
	height = high_dim
out = []
for i in range(width):
	line_a = []
	for j in range(height):
		if i + width * j < len(word):
			line_a.append(word[i + width * j])
	out.append(''.join(line_a))
print(' '.join(out))


import re
import math
s = input()
c = math.ceil(math.sqrt(len(s)))
l = re.findall('\\S{0,%d}' % c, s)
d = ''
for x in range(c):
	for y in l:
		try:
			d += y[x]
		except:
			d += ''
	d += ' '
print(d)


import math
message = input()
sqrt_len = math.sqrt(len(message))
low = math.floor(sqrt_len)
high = math.ceil(sqrt_len)
if low * high < len(message):
	low = high
output = []
for col_base in range(high):
	for col in range(col_base, low * high, high):
		if col < len(message):
			output.append(message[col])
	output.append(' ')
print(''.join(output))


from math import sqrt
from math import floor
from math import ceil
msg = input()
rows = floor(sqrt(len(msg)))
columns = ceil(sqrt(len(msg)))
if rows * columns < len(msg):
	rows += 1
table = []
index = 0
for r in range(rows):
	row = []
	for c in range(columns):
		if index < len(msg):
			row.append(msg[index])
			index += 1
		else:
			row.append('')
	table.append(row)
index = 0
result = ''
r = 0
for c in range(columns):
	for r in range(rows):
		result += table[r][c]
	result += ' '
print(result)


from math import sqrt, ceil, floor
word = input().strip()
width = floor(sqrt(len(word)))
height = ceil(sqrt(len(word)))
smallest = len(word) * 2
for h in range(1, height + 1):
	for w in range(h, ceil(len(word) / h) + 1):
		if len(word) <= w * h and w - h < smallest:
			width = w
			height = h
			smallest = w - h
word += ' ' * (width * height - len(word))
encrypted = []
for i in range(width):
	enc_word = ''
	for j in range(height):
		enc_word += word[j * width + i]
	encrypted.append(enc_word.strip())
print(' '.join(encrypted))


import math

def encrypt(a):
	rows = math.floor(math.sqrt(len(a)))
	col = math.ceil(math.sqrt(len(a)))
	if rows * col < len(a):
		rows = rows + 1
	x = [['' for i in range(0, col)] for i in range(0, rows)]
	k = 0
	for i in range(0, rows):
		for j in range(0, col):
			if k < len(a):
				x[i][j] = a[k]
				k = k + 1
	b = ''
	for j in range(0, col):
		for i in range(0, rows):
			b = b + x[i][j]
		b = b + ' '
	print(b)

def removespaces(a):
	for i in range(0, len(a)):
		if a[0] == ' ':
			a = a[1:len(a)]
	i = 0
	while i < len(a):
		if a[i] == ' ':
			a = a[0:i] + a[i + 1:len(a)]
		i = i + 1
	return a
a = input('')
a = removespaces(a)
encrypt(a)


import math
message = input().replace(' ', '')
height = math.ceil(math.sqrt(len(message)))
width = math.ceil(math.sqrt(len(message)))
while height * width < len(message):
	width += 1
res = ''
for c in range(width):
	if len(res) > 0 and res[-1] != ' ':
		res += ' '
	for r in range(height):
		if width * r + c < len(message):
			res += message[width * r + c]
print(res)


from math import sqrt, floor, ceil
word = input()
n = len(word)
min_dist = floor(sqrt(n))
if min_dist ** 2 == n:
	width = min_dist
else:
	width = min_dist + 1
height = ceil(n / width)
rect = width * height
padded = word + ' ' * (rect - n)
chunks = [padded[i * width:i * width + width] for i in range(height)]
transpose = zip(*chunks)
unpadded = [''.join([c for c in chunk if not c == ' ']) for chunk in transpose]
coded = ' '.join(unpadded)
print(coded)


text = input()
root = len(text) ** 0.5
width = int(root)
if width != root:
	width += 1
m = [text[i:i + width] for i in range(0, len(text), width)]
for i in range(len(m[0])):
	for j in range(len(m)):
		try:
			print(m[j][i], end='')
		except:
			pass
	print(' ', end='')
print()


import math
message = input()
width = math.floor(math.sqrt(len(message)))
height = math.ceil(math.sqrt(len(message)))
encrypted = []
for i in range(0, height):
	encrypted.append('')
i = 0
j = 0
while j < len(message):
	encrypted[i] += message[j]
	i += 1
	j += 1
	if i >= height:
		i = 0
for item in encrypted:
	print(item, end=' ')


from math import sqrt, floor, ceil
word = input().strip()
cols = ceil(sqrt(len(word)))
print(' '.join((word[i::cols] for i in range(cols))))


from math import ceil
word = input()
h = int(ceil(len(word) ** 0.5))
print(' '.join((''.join((word[i] for i in range(j, len(word), h))) for j in range(h))))


import math

def isWithinRange(width, height, lower, upper):
	return width >= lower and height >= lower and (width <= upper) and (height <= upper)
msg = input()
length = len(msg)
lower = math.floor(math.sqrt(length))
upper = math.ceil(math.sqrt(length))
height = lower
width = upper
while width * height >= length:
	if (width - 1) * (height - 1) >= length and isWithinRange(width - 1, height - 1, lower, upper):
		width = width - 1
		height = height - 1
	elif width * (height - 1) >= length and isWithinRange(width, height - 1, lower, upper):
		height = height - 1
	elif (width - 1) * height >= length and isWithinRange(width - 1, height, lower, upper):
		width = width - 1
	else:
		break
x = 0
lines = []
while True:
	if x + width < length:
		lines.append(msg[x:x + width])
		x = x + width
	else:
		lines.append(msg[x:])
		break
encoded = []
result = []
x = 0
while x < width:
	row = []
	for line in lines:
		if x < len(line):
			row.append(line[x])
	encoded.insert(x, row)
	result.append(''.join(encoded[x]))
	x = x + 1
print(' '.join(result))


import math

def find_size(s):
	for n_row in range(math.floor(len(s) ** 0.5), math.ceil(len(s) ** 0.5) + 1):
		for n_col in range(n_row, math.ceil(len(s) ** 0.5) + 1):
			if n_col * n_row >= len(s):
				return (n_col, n_row)
s = input().strip()
(n_col, n_row) = find_size(s)
square = []
for i in range(n_row):
	square.append(list(s[:n_col]))
	s = s[n_col:]
while len(square[-1]) < len(square[0]):
	square[-1].append('')
print(' '.join([''.join([square[j][i] for j in range(n_row)]) for i in range(n_col)]))


import math
message = input()
height = math.ceil(math.sqrt(len(message)))
width = math.ceil(math.sqrt(len(message)))
coded_message = ''
for line in range(height):
	nextline = ''
	for j in range(width):
		if line + height * j + 1 <= len(message):
			nextline = nextline + message[line + height * j]
	coded_message = coded_message + ' ' + nextline
print(coded_message.strip())


from math import ceil

def encode(string):
	if int(len(string) ** 0.5) * ceil(len(string) ** 0.5) >= len(string):
		key = len(string) ** 0.5
		matrix = []
		string_index = 0
		for index in range(int(key)):
			matrix.append(string[string_index:string_index + ceil(key)])
			string_index += ceil(key)
		encoded = ''
		for index in range(ceil(key)):
			for substring in matrix:
				if index < len(substring):
					encoded += substring[index]
			encoded += ' '
		return encoded
	else:
		key = len(string) ** 0.5
		matrix = []
		string_index = 0
		for index in range(ceil(key)):
			matrix.append(string[string_index:string_index + ceil(key)])
			string_index += ceil(key)
		encoded = ''
		for index in range(ceil(key)):
			for substring in matrix:
				if index < len(substring):
					encoded += substring[index]
			encoded += ' '
		return encoded
print(encode(input()))


word = input()

def dimensions(word):
	word = len(word) ** 0.5
	col = round(word)
	if word > col:
		row = col
		col += 1
	else:
		row = col - 1
	assert row <= col
	return [row, col]

def rectangle(word):
	(row, col) = dimensions(word)
	new_words = ''
	for x in range(col):
		new_words += word[x::col]
		new_words += ' '
	print(new_words[:-1])
rectangle(word)


import math
(string, code) = (input(), '')
n = len(string)
(columns, rows) = (math.ceil(math.sqrt(n)), math.floor(math.sqrt(n)))
for i in range(columns):
	code += string[i::columns] + ' '
print(code)


from math import *
s = input()
l = len(s)
a = floor(sqrt(l))
b = ceil(sqrt(l))
m = 0
n = 0
if a * a >= l:
	m = n = a
elif a * b >= l:
	m = a
	n = b
else:
	m = n = b
string = ''
for i in range(n):
	j = i
	while j < l:
		string += s[j]
		j += n
	string += ' '
print(string)


import math

def tc(plain):
	(n, r, c) = dimensions(plain)
	rect = []
	for i in range(r):
		rect.append([])
		for j in range(c):
			if i * c + j < n:
				rect[i].append(plain[i * c + j])
			else:
				rect[i].append('')
	line = []
	for j in range(c):
		for i in range(r):
			line.append(rect[i][j])
		line.append(' ')
	print(''.join(line))

def dimensions(plain):
	n = len(plain)
	lo = int(math.floor(n ** 0.5))
	hi = int(math.ceil(n ** 0.5))
	if lo * lo >= n:
		return (n, lo, lo)
	elif lo * hi >= n:
		return (n, lo, hi)
	else:
		return (n, hi, hi)
tc(input())


__author__ = 'danielbaeck'
import math
import itertools
m = input()
minhw = math.floor(math.sqrt(len(m)))
maxhw = math.ceil(math.sqrt(len(m)))
rowlength = minhw
collength = maxhw
for rows in range(minhw, maxhw + 1):
	cols = math.ceil(len(m) / rows)
	if rows > cols:
		break
	rowlength = rows
rect = [m[i:i + collength] for i in range(0, len(m), collength)]
outp = ''
for i in range(collength):
	for j in range(collength):
		try:
			outp += rect[j][i]
		except IndexError:
			outp += ''
	outp += ' '
print(outp)


from math import sqrt
s = input()
l = len(s)
cols = rows = int(sqrt(l) // 1)
if cols * rows < l:
	rows += 1
if cols * rows < l:
	cols += 1
result = [[] for x in range(rows)]
(row, col) = (0, 0)
for c in s:
	if row == rows:
		row = 0
		col += rows
	result[row].append(s[col + row])
	row += 1
print(' '.join(list(map(lambda x: ''.join(x), result))))


import math
Input = [i for i in input().strip()]
l = len(Input)
width = math.floor(math.sqrt(l))
height = math.ceil(math.sqrt(l))
if width * height < l:
	width = height
ans = ''
for i in range(height):
	for j in range(width):
		if i + height * j < l:
			ans += Input[i + height * j]
	ans += ' '
print(ans)


import math
a = input()
n = len(a)
h = math.floor(math.sqrt(n))
w = h
if w * h < n:
	w += 1
if w * h < n:
	h += 1
a += ' ' * (w * h - n)
chunks = [a[i:i + w] for i in range(0, n, w)]
transp = zip(*chunks)
print(' '.join((''.join(s).strip() for s in transp)))


from math import sqrt
from math import ceil
message = input().replace(' ', '')
size = ceil(sqrt(len(message)))
tab = []
for i in range(size):
	tab.append([])
	for j in range(size):
		if size * i + j >= len(message):
			tab[i].append('')
		else:
			tab[i].append(message[size * i + j])
for i in range(size):
	for j in range(size):
		print(tab[j][i], end='')
	print('', end=' ')


import math
string = input().strip()
flooring = math.floor(math.sqrt(len(string)))
ceiling = math.ceil(math.sqrt(len(string)))
width = flooring if flooring > ceiling else ceiling
encrypt = []
for i in range(len(string)):
	if i % width == 0:
		encrypt.append([string[i]])
	else:
		encrypt[-1].append(string[i])
for i in encrypt:
	if len(i) != width:
		while len(i) < width:
			i.append('')
for i in range(0, width):
	for j in encrypt:
		if j != '':
			print(j[i], end='')
	print(' ', end='')


import math

def encrypt(word, num_rows, num_columns):
	output = []
	for curr in range(num_rows + 1):
		while curr < len(word):
			output.append(word[curr])
			curr += num_columns
		output.append(' ')
	return ''.join(output)
word = input().strip()
num_rows = math.floor(math.sqrt(len(word)))
num_columns = math.ceil(math.sqrt(len(word)))
if num_rows == num_columns:
	num_rows -= 1
print(encrypt(word, num_rows, num_columns))


from math import sqrt, ceil
msg = input()
a = len(msg)
la = ceil(sqrt(a))
cypher = [[''] * la for _ in range(la)]
for i in range(la):
	for j in range(la):
		k = i * la + j
		if k < a:
			cypher[i][j] = msg[k]
code = ''
for i in range(la):
	for j in range(la):
		code += cypher[j][i]
	code += ' '
print(code)


import itertools, sys
s = sys.stdin.readline().strip()
dim = int(len(s) ** 0.5)
if dim * dim == len(s):
	(x, y) = (dim, dim)
else:
	(x, y) = (dim, dim + 1)
array = [s[i:i + y] for i in range(0, len(s), y)]
transpose = itertools.zip_longest(*array, fillvalue='')
print(' '.join((''.join(s) for s in transpose)))


import itertools, sys
s = sys.stdin.readline().strip()
dim = int(len(s) ** 0.5)
if dim * dim == len(s):
	(x, y) = (dim, dim)
else:
	(x, y) = (dim, dim + 1)
array = [s[i:i + y] for i in range(0, len(s), y)]
transpose = itertools.zip_longest(*array, fillvalue='')
print(' '.join((''.join(s) for s in transpose)))


import math
inp = input()
l = len(inp)
br1 = math.sqrt(l)
br = int(br1)
if br1 != br:
	le = br + 1
else:
	le = br
ans = []
for i in range(le):
	c = 0
	s = ''
	t = i
	while c <= br and t < l:
		s += inp[t]
		t += le
		c += 1
	ans.append(s)
print(' '.join(ans))


import math
x = input()
z = math.sqrt(len(x))
q = math.floor(z)
w = math.ceil(z)
if q * w < len(x):
	q = q + 1
l = 0
k = [[0] * w for i in range(q)]
for r in range(q):
	for t in range(w):
		if l == len(x):
			k[r][t] = ''
		else:
			k[r][t] = x[l]
			l = l + 1
h = []
for d in range(w):
	for j in range(q):
		h += k[j][d]
		if j == q - 1:
			h += ' '
for b in h:
	print(b, end='')


import math

def encrypt(s):
	s = s.replace(' ', '')
	sqrt = math.sqrt(len(s))
	rowcount = math.floor(sqrt)
	colcount = math.ceil(sqrt)
	if rowcount * colcount < len(s):
		rowcount += 1
	square = [s[i:i + colcount] for i in range(0, len(s), colcount)]
	s += ' ' * colcount
	transposed = [''.join((s[r * colcount + col] for r in range(rowcount))) for col in range(colcount)]
	return ' '.join((t.strip() for t in transposed))
print(encrypt(input()))


def GetRange(L):
	i = 0
	while i * i < L:
		i = i + 1
	if i * i == L:
		return [i, i]
	return [i - 1, i]

def GetSize(L):
	(Low, High) = GetRange(L)
	MinArea = (High + 1) ** 2
	MinR = 0
	MinC = 0
	for R in range(Low, High + 1):
		for C in range(R, High + 1):
			Area = R * C
			if Area >= L and Area < MinArea:
				MinArea = Area
				MinR = R
				MinC = C
	return [MinR, MinC]

def IncryptMessage(Message):
	L = len(Message)
	(R, C) = GetSize(L)
	M = list(Message)
	i = 0
	Grid = []
	for r in range(0, R):
		Row = []
		for c in range(0, C):
			if i >= L:
				Row.append('')
			else:
				Row.append(M[i])
			i = i + 1
		Grid.append(Row)
	CodedMessage = ''
	for c in range(0, C):
		for r in range(0, R):
			CodedMessage = CodedMessage + Grid[r][c]
		CodedMessage = CodedMessage + ' '
	return CodedMessage
Message = input()
Code = IncryptMessage(Message)
print(Code)


import math
lst = str(input())
num = math.sqrt(len(lst))
length = math.ceil(num)
width = math.floor(num)
rem = length - len(lst) % length
lst += str(rem * ' ')
lst = list(lst)
string = ''
nlst = [lst[i:i + length] for i in range(0, len(lst), length)]
for i in range(length):
	for j in range(len(nlst)):
		if nlst[j][i] != ' ':
			string += nlst[j][i]
	string += ' '
print(string)


from sys import *
from math import *
string = stdin.readline()
cols = ceil(sqrt(len(string)))
rows = ceil(len(string) / cols)
encoded = ''
for col in range(cols):
	for row in range(rows):
		i = row * cols + col
		if i < len(string):
			encoded += string[i]
	encoded += ' '
print(encoded)


from math import *
a = input()
l = len(a)
row = int(sqrt(l))
if row * row < l:
	col = row + 1
else:
	col = row
if row * col <= l:
	row += 1
i = 0
while i < col:
	j = 0
	while j < row:
		if j * col + i < l:
			print(a[j * col + i], end='')
		j += 1
	print(' ', end='')
	i += 1


from math import sqrt, floor, ceil
word = input().strip()
n = len(word)
nSqrt = sqrt(n)
minWidth = floor(nSqrt)
maxHeight = ceil(nSqrt)
width = minWidth
height = maxHeight
while width * height < n or width < height:
	width += 1
while width * height >= n:
	height -= 1
height += 1
encodedMsg = ''
for i in range(width):
	for j in range(height):
		index = j * width + i
		if index >= n:
			break
		encodedMsg += word[index]
	if i != width - 1:
		encodedMsg += ' '
print(encodedMsg)


import itertools
import math
s = input()
width = math.ceil(math.sqrt(len(s)))
rows = [s[i:i + width] for i in range(0, len(s), width)]
cols = [''.join(x) for x in itertools.zip_longest(*rows, fillvalue='')]
print(' '.join(cols))


import math
import sys
LIST = {}
A = []
str = input()
A = str
length = len(str)
square = math.sqrt(length)
width = math.ceil(square)
height = int(length / width)
if height * width >= length:
	pass
else:
	height = height + 1
if height > width:
	temp = width
	width = height
	height = temp
span = width
i = 0
count = 0
while count < height:
	LIST.update({count: A[i:i + span]})
	i = i + span
	count = count + 1
i = 0
while i < width:
	j = 0
	while j < height:
		if i < len(LIST[j]):
			print(LIST[j][i], end='')
		j = j + 1
	i = i + 1
	print(' ', end='')