Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!

The only thing Mrs. Smith remembered was that any permutation of $n$ can be a secret phone number. Only those permutations that minimize secret value might be the phone of her husband.

The sequence of $n$ integers is called a permutation if it contains all integers from $1$ to $n$ exactly once.

The secret value of a phone number is defined as the sum of the length of the longest increasing subsequence (LIS) and length of the longest decreasing subsequence (LDS). 

A subsequence $a_{i_1}, a_{i_2}, \ldots, a_{i_k}$ where $1\leq i_1 < i_2 < \ldots < i_k\leq n$ is called increasing if $a_{i_1} < a_{i_2} < a_{i_3} < \ldots < a_{i_k}$. If $a_{i_1} > a_{i_2} > a_{i_3} > \ldots > a_{i_k}$, a subsequence is called decreasing. An increasing/decreasing subsequence is called longest if it has maximum length among all increasing/decreasing subsequences.

For example, if there is a permutation $[6, 4, 1, 7, 2, 3, 5]$, LIS of this permutation will be $[1, 2, 3, 5]$, so the length of LIS is equal to $4$. LDS can be $[6, 4, 1]$, $[6, 4, 2]$, or $[6, 4, 3]$, so the length of LDS is $3$.

Note, the lengths of LIS and LDS can be different.

So please help Mrs. Smith to find a permutation that gives a minimum sum of lengths of LIS and LDS.


-----Input-----

The only line contains one integer $n$ ($1 \le n \le 10^5$) — the length of permutation that you need to build.


-----Output-----

Print a permutation that gives a minimum sum of lengths of LIS and LDS. 

If there are multiple answers, print any.


-----Examples-----
Input
4

Output
3 4 1 2

Input
2

Output
2 1



-----Note-----

In the first sample, you can build a permutation $[3, 4, 1, 2]$. LIS is $[3, 4]$ (or $[1, 2]$), so the length of LIS is equal to $2$. LDS can be ony of $[3, 1]$, $[4, 2]$, $[3, 2]$, or $[4, 1]$. The length of LDS is also equal to $2$. The sum is equal to $4$. Note that $[3, 4, 1, 2]$ is not the only permutation that is valid.

In the second sample, you can build a permutation $[2, 1]$. LIS is $[1]$ (or $[2]$), so the length of LIS is equal to $1$. LDS is $[2, 1]$, so the length of LDS is equal to $2$. The sum is equal to $3$. Note that permutation $[1, 2]$ is also valid.

Difficulty: MEDIUM_HARD
Tags: Greedy algorithms

Constructive algorithms
Skill types: Greedy algorithms
Expected Time Complexity: O(N)

Starter code:

Solutions:
import math
n = int(input())
width = int(math.sqrt(n))
start = n - width + 1
ans = list()
while True:
	stop = False
	for v in range(start, start + width):
		if v > 0:
			ans.append(v)
		if v < 1:
			stop = True
	start -= width
	if stop:
		break
print(*ans)


import math

def solved(n):
	ceil = int(math.ceil(math.sqrt(n)))
	f = int(math.sqrt(n))
	for i in range(1, ceil + 1):
		for j in range(1, ceil + 1):
			if n - i * ceil + j > 0:
				print(n - i * ceil + j, end=' ')
n = int(input())
solved(n)


n = int(input())
m = int(n ** 0.5)
arr = [list() for i in range((n + m - 1) // m)]
ind = -1
for i in range(n):
	if i % m == 0:
		ind += 1
	arr[ind].append(i + 1)
for i in arr[::-1]:
	for j in i:
		print(j)


3
import itertools

def main():
	N = int(input())
	bestv = 4 * N
	besti = -1
	for i in range(1, N + 1):
		v = i + (N + i - 1) // i
		if v < bestv:
			bestv = v
			besti = i
	A = []
	cur = N
	if N % besti > 0:
		a = [cur - j for j in range(N % besti)]
		a.reverse()
		A.append(a)
		cur -= N % besti
	while cur > 0:
		a = [cur - j for j in range(besti)]
		a.reverse()
		A.append(a)
		cur -= besti
	print(*list(itertools.chain.from_iterable(A)))

def __starting_point():
	main()
__starting_point()


import math
n = int(input())
k = math.sqrt(n)
k1 = int(k)
if k1 == k:
	y = k1
else:
	y = k1 + 1
i = n - y + 1
p = 0
ii = True
for c in range(y):
	if ii == True:
		for x in range(y):
			if p >= n:
				ii = False
				break
			print(i, end=' ')
			i += 1
			p += 1
	i = n - y * (c + 2) + 1
	if i < 1:
		i = 1


import math
n = int(input())
m = int(math.sqrt(n))
for i in range(n):
	print(max(0, n - m * (i // m + 1)) + i % m + 1, end=' ')


def ii():
	return int(input())

def mi():
	return list(map(int, input().split()))

def li():
	return list(mi())
n = ii()
m = int(n ** 0.5)
a = [0] * n
c = 0
for i in range(10 ** 7):
	s = min(n, m * (i + 1))
	for j in range(m):
		a[c] = s
		s -= 1
		c += 1
		if c >= n:
			break
	if c >= n:
		break
print(*a)


from math import sqrt
n = int(input())
step = int(sqrt(n))
assert step ** 2 <= n and (step + 1) ** 2 > n
ans = []
for start in range(0, n, step):
	ans.extend(range(start, min(n, start + step))[::-1])
print(' '.join((str(v + 1) for v in ans)))


from math import sqrt
n = int(input())
s = int(sqrt(n))
v = []
for i in range(0, n, s):
	v.append(list(range(i + 1, min(i + s, n) + 1)))
v.reverse()
for i in v:
	for j in i:
		print(j, end=' ')


import math
n = int(input())
k = int(math.sqrt(n))
if k * k != n:
	k += 1
for i in range(1, k + 1):
	for j in range(i * k, k * (i - 1), -1):
		if j > n:
			continue
		print(j, end=' ')


n = int(input())
L = int(n ** 0.5)
s = []
for i in range(0, n, L):
	s += range(min(i + L, n), i, -1)
print(' '.join(map(str, s)))


n = int(input())
m = int(n ** 0.5)
L = []
for i in range(0, n, m):
	L += range(min(i + m, n), i, -1)
print(*L)


import math
n = int(input())
ceil = int(math.ceil(math.sqrt(n)))
floor = int(math.sqrt(n))
for i in range(1, ceil + 1):
	for j in range(1, ceil + 1):
		if n - i * ceil + j > 0:
			print(n - i * ceil + j, end=' ')


n = int(input())
sqr = n ** 0.5
sqr = int(sqr)
ind = []
rem = 0
while n > sqr:
	ind.extend([int(x) for x in range(n + 1 - sqr, n + 1)])
	n = n - sqr
ind.extend([int(x) for x in range(1, n + 1)])
print(*ind, sep=' ')


import math
n = int(input())
t = range(1, n + 1)
size = math.floor(math.sqrt(n))
ans = [list(t[i:i + size])[::-1] for i in range(0, n, size)]
for i in ans:
	for j in i:
		print(j, end=' ')
print(end='\n')


n = int(input())
b = int(n ** 0.5)
ans = []
for i in range(0, n, b):
	ans = [j for j in range(i + 1, min(i + 1 + b, n + 1))] + ans
print(*ans)


import math
n = int(input())
a = math.sqrt(n)
b = math.ceil(a)
a = math.floor(a)
if n - a * a <= a:
	for i in range(a):
		for j in range(a):
			print(a * (i + 1) - j, end=' ')
	if b > a:
		k = n
		while k >= a * a + 1:
			print(k, end=' ')
			k -= 1
else:
	for i in range(a):
		for j in range(b):
			print(b * (i + 1) - j, end=' ')
	if b > a:
		k = n
		while k >= a * b + 1:
			print(k, end=' ')
			k -= 1


from collections import defaultdict
import sys, heapq, bisect, math, itertools, string, queue, datetime
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
mod = 10 ** 9 + 7
eps = 10 ** (-7)
AtoZ = [chr(i) for i in range(65, 65 + 26)]
atoz = [chr(i) for i in range(97, 97 + 26)]

def inpl():
	return list(map(int, input().split()))

def inpl_s():
	return list(input().split())
N = int(input())
k = int(math.sqrt(N - 1)) + 1
ans = []
if N == 1:
	ans = [1]
elif N == 2:
	ans = [2, 1]
elif N == 3:
	ans = [2, 3, 1]
else:
	while N > 0:
		li = []
		for i in range(k):
			if N > 0:
				li.append(N)
			N -= 1
		li.reverse()
		ans = ans + li
print(' '.join(map(str, ans)))


from math import ceil, sqrt

def main():
	n = int(input())
	m = int(ceil(sqrt(n)))
	l = [i for j in range(n - m + 1, 0, -m) for i in range(j, j + m)]
	l += range(1, n % m + 1)
	print(' '.join(map(str, l)))
main()


import math
n = int(input())
x = int(math.sqrt(n))
tmp = x
tmp1 = 0
tmp2 = 1
cnt = 0
while cnt < n:
	if tmp1 == tmp:
		tmp1 = 0
		tmp2 += 1
	print(min(tmp * tmp2, n) - tmp1, end=' ')
	tmp1 += 1
	cnt += 1


from math import sqrt, ceil
n = int(input())
n_sqrt = int(ceil(sqrt(n)))
ans = []
i = 1
while i <= n:
	ans = ans + list(range(i, min(i + n_sqrt, n + 1)))[::-1]
	i += n_sqrt
print(' '.join(map(str, ans)))


import math
n = int(input())
c = int(math.sqrt(n))
if n == 3:
	print('2 3 1')
else:
	my = []
	while n > 0:
		last = n - c + 1
		if last < 1:
			last = 1
		my = my + list(range(last, n + 1))
		n = last - 1
	print(' '.join(map(str, my)))


import sys
import math as mt
I = lambda : list(map(int, input().split()))
(n,) = I()
x = int(n ** 0.5)
ans = []
t = mt.ceil(n / x)
st = 1
for i in range(t):
	if st + x <= n:
		ans.append(list(range(st, st + x)))
	else:
		ans.append(list(range(st, n + 1)))
	st += x
ans = ans[::-1]
for i in ans:
	print(*i, end=' ')


from math import sqrt
n = int(input())
r = int(sqrt(n))
ans = []
if n == 1:
	print('1')
elif n == 2:
	print('1 2')
elif n == 3:
	print('1 3 2')
elif r ** 2 == n:
	for i in range(r):
		ans += [str((r - i - 1) * r + j) for j in range(1, r + 1)]
	print(' '.join(ans))
else:
	if n <= r * (r + 1):
		segment = r
		element = r + 1
	else:
		segment = r + 1
		element = r + 1
	for i in range(segment - 1):
		ans += [str(n - element * i - j) for j in range(element - 1, -1, -1)]
	ans += [str(j) for j in range(1, n - element * (segment - 1) + 1)]
	print(' '.join(ans))


from __future__ import print_function
from collections import *
from sys import stdin
from heapq import *
from math import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
rr = lambda x: reversed(range(x))
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
(ans, sp) = (inf, inf)
if n < 3:
	for i in range(1, n + 1):
		print(i, end=' ')
	exit()
for i in range(1, n + 1):
	if i + int(ceil(n / i)) < ans:
		ans = i + int(ceil(n / i))
		sp = i
ans = []
i = 1
while i <= n:
	for _ in reversed(range(sp)):
		if i + _ <= n:
			ans.append(str(i + _))
	i += sp
print(' '.join(ans))


from math import sqrt, ceil
n = int(input())
(k, t) = (0, ceil(sqrt(n)))
answer = []
while k < n:
	if k + t > n:
		k = n
	else:
		k += t
	for j in range(k, k - t, -1):
		answer.append(j)
		if len(answer) == n:
			break
print(*answer)


from math import *
N = int(input())
Min = [1, N + 1]
for i in range(1, ceil(N / 2) + 1):
	if ceil(N / i) + i < Min[1]:
		Min[1] = ceil(N / i) + i
		Min[0] = i
min = Min[0]
i = N - min + 1
while True:
	if i > 0:
		for j in range(min):
			print(i + j, end=' ')
		i -= min
	else:
		break
if N % min:
	for j in range(1, i + min):
		print(j, end=' ')
print()


from math import sqrt
n = int(input())
k = int(sqrt(n))
b = []
last = 0
while last < n:
	b.append([last + j for j in range(k)])
	last = b[-1][-1] + 1
k = len(b)
for i in range(k - 1, -1, -1):
	for j in b[i]:
		if j < n:
			print(1 + j, end=' ')
print()


USE_STDIO = False
if not USE_STDIO:
	try:
		import mypc
	except:
		pass

def main():
	(n,) = list(map(int, input().split(' ')))
	q = int(n ** 0.5)
	ans = [i for i in range(1, n + 1)]
	for i in range(0, n, q):
		ans[i:i + q] = ans[i:i + q][::-1]
	print(*ans)

def __starting_point():
	main()
__starting_point()


from math import sqrt
n = int(input())
t = int(sqrt(n))
while n > 0:
	n = n - t
	for i in range(1, t + 1):
		if n + i > 0:
			print(n + i, end=' ')


import math
n = int(input())
A = [i + 1 for i in range(n)]
x = int(math.sqrt(n))
X = [A[i:i + x] for i in range(0, len(A), x)]
X = X[::-1]
f = [item for sublist in X for item in sublist]
print(*f)


import math
n = int(input())
k = math.ceil(n ** 0.5)
a = []
i = 1
while n - i * k > 0:
	for j in range(1, k + 1):
		a.append(str(n - i * k + j))
	i += 1
for l in range(1, n - (i - 1) * k + 1):
	a.append(str(l))
print(' '.join(a))


import functools
import time
from collections import Counter

def timer(func):

	@functools.wraps(func)
	def wrapper(*args, **kwargs):
		stime = time.perf_counter()
		res = func(*args, **kwargs)
		elapsed = time.perf_counter() - stime
		print(f'{func.__name__} in {elapsed:.4f} secs')
		return res
	return wrapper

class solver:

	def __init__(self):
		pass

	def __call__(self):
		n = int(input())
		minv = n + 1
		mini = n
		for l in range(1, n + 1):
			v = l + (n + l - 1) // l
			if v < minv:
				minv = v
				mini = l
		ref = [i + 1 for i in range(n)]
		l = mini
		res = list()
		p = n - 1
		while p >= 0:
			pp = max(0, p - l + 1)
			res.extend(ref[pp:p + 1])
			p = pp - 1
		print(' '.join(map(str, res)))
solver()()


from math import sqrt
n = int(input())
ans = [0 for i in range(n)]
m = int(sqrt(n))
for i in range(n // m):
	for j in range(m):
		ans[m * i + j] = m * (i + 1) - j
for i in range(n % m):
	ans[i - n % m] = n - i
print(' '.join(map(str, ans)))


import itertools
import math

def solution():
	up_b = int(input())
	n = int(math.ceil(math.sqrt(up_b)))
	for _ in range(n):
		for x in range(up_b - n + 1, up_b + 1):
			if x <= 0:
				continue
			print(x, end=' ')
		up_b -= n
		if up_b <= 0:
			break
	print()
solution()


import math
n = int(input())
l = math.sqrt(n)
l = int(l)
a = []
for i in range(n):
	if n % l >= n - i:
		a.append(i + 1 - n // l * l)
	else:
		a.append(n - (i // l + 1) * l + i % l + 1)
a = map(str, a)
print(' '.join(a))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		n = ri()
		ans = []
		i = 1
		k = 1
		t = 0
		while True:
			k = i * i
			if k <= n:
				t = i
			else:
				break
			i += 1
		a = []
		z = []
		for i in range(n):
			z += [i + 1]
			if len(z) == t:
				a = z + a
				z = []
		a = z + a
		wia(a)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import math
n = int(input())
arr = []
for i in range(1, n + 1):
	arr.append(i)
l = 0
r = n - 1
ans = []
if n == 1:
	print(1)
	exit()
if n == 2:
	print('2 1')
	exit()
k = int(math.sqrt(n))
for i in range(0, n, k):
	ans = [j for j in range(i + 1, min(i + 1 + k, n + 1))] + ans
for i in ans:
	print(i, end=' ')
print()


n = int(input())
a = [n - i for i in range(n)]
L = int(n ** 0.5)
a[:L] = a[L - 1::-1]
for i in range(L, n + L, L):
	a[i:i + L] = a[i + L - 1:i - 1:-1]
print(*a)


import math

def getx(n):
	return math.floor(math.sqrt(n))

def getans(n, x):
	l1 = [i for i in range(n, 0, -1)]
	l2 = []
	i = 0
	while i < n:
		l2 = l2 + sorted(l1[i:i + x])
		i += x
	return l2
n = int(input())
a = getx(n)
ans = getans(n, a)
ans1 = [str(i) for i in ans]
print(' '.join(ans1))


from math import sqrt, floor
n = int(input())
b = [i for i in range(1, n + 1)]
a = int(floor(sqrt(n)))
seq = a
if n == 3:
	print(2, 1, 3, sep=' ')
	exit()
if not n % a:
	tmp = b[-seq:]
	for v in tmp:
		print(v, end=' ')
	for i in range(1, n // a + 1):
		tmp = b[-seq * i:-seq * (i - 1)]
		for v in tmp:
			print(v, end=' ')
else:
	tmp = b[-seq:]
	for v in tmp:
		print(v, end=' ')
	for i in range(1, n // a + 1):
		tmp = b[-seq * i:-seq * (i - 1)]
		for v in tmp:
			print(v, end=' ')
	re = n % a
	for i in range(1, re + 1):
		print(i, end=' ')


n = int(input())
ans = 10 ** 9 + 7
num = -1
for i in range(1, n + 1):
	tmp = i - -n // i
	if tmp < ans:
		ans = tmp
		num = i
res = [0] * n
i = 1
ans = []
while i <= n:
	tmp = []
	while len(tmp) < num and i <= n:
		tmp.append(i)
		i += 1
	ans.append(tmp)
ans.sort(reverse=True)
for i in ans:
	for j in i:
		print(j, end=' ')


from math import sqrt
n = int(input())
k = int(sqrt(n))
ind = 0
curr = n
j = 0
while ind < n:
	ind += 1
	j += 1
	print(max(0, curr - k) + j, end=' ')
	if j == k:
		j = 0
		curr -= k


n = int(input())
if n == 1:
	print(1)
else:
	chunkn = 2
	ans = (n + 1) // 2 + 2
	for curChunkn in range(3, n + 1):
		chunk = n // curChunkn
		curAns = chunk + curChunkn
		if n % curChunkn > 0:
			curAns += 1
		if curAns > ans:
			break
		ans = curAns
		chunkn = curChunkn
	lim = n
	left = n % chunkn
	for i in range(chunkn):
		start = lim - n // chunkn + 1
		if left > 0:
			left -= 1
			start -= 1
		for j in range(start, lim + 1):
			print(j, end=' ')
		lim = start - 1


def isqrt(n):
	x = n
	y = (x + 1) // 2
	while y < x:
		x = y
		y = (x + n // x) // 2
	return x
k = int(input())
arr = list(range(1, k + 1))
sqrt_k = isqrt(k)
print(' '.join(map(str, sum([arr[i:i + sqrt_k][::-1] for i in range(0, k, sqrt_k)], []))))


import math
n = int(input())
l = math.floor(math.sqrt(n))
d = l
if l * l < n:
	d = l + 1
b = n
ans = []
while b > 0:
	a = max(b - d, 0)
	for i in range(a, b):
		ans.append(str(i + 1))
	b -= d
print(' '.join(ans))


import sys
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(n,) = I()
l = [0] * n
x = n + 1
p = 1
for i in range(2, int(n ** 0.5) + 1):
	a = i + (n + i - 1) // i
	if a < x:
		p = i
		x = a
for i in range(n // p * p):
	l[i] = (i // p + 1) * p - i % p
x = n
for j in range(i + 1, n):
	l[j] = x
	x -= 1
print(*l)


import math
n = int(input())
x = math.ceil(math.sqrt(n))
y = n // x
for i in range(y):
	for j in range(x, 0, -1):
		print(j + i * x, end=' ')
for i in range(n, x * y, -1):
	print(i, end=' ')


import math
n = int(input())
if n <= 3:
	for i in range(1, n + 1):
		print(i, end=' ')
	exit(0)
start = int(math.sqrt(n))
sqrtVal = start
already = [False] * 100005
if True:
	while start <= n:
		for i in range(sqrtVal):
			if already[start - i]:
				exit(0)
			print(start - i, end=' ')
			already[start - i] = True
		start += sqrtVal
		start = min(start, n)


n = int(input())
L = int(n ** 0.5)
i = 1
k = n
a = [0] * 100005
while i <= n:
	j = min(i + L - 1, n)
	while j >= i:
		a[j] = k
		j -= 1
		k -= 1
	i += L
print(' '.join(map(str, a[1:n + 1])))


import math as ma
n = int(input())
b = int(ma.sqrt(n))
a = [i + 1 for i in range(n)]
c = []
for i in range(0, n, b):
	c.extend(a[i:min(i + b, n)][::-1])
print(*c)


n = int(input())
m = 10 ** 18
for i in range(1, n + 1):
	if m > i + (n + i - 1) // i:
		m = i + (n + i - 1) // i
		lis = i
ans = []
for i in range(n - n % lis + 1, n + 1):
	ans.append(i)
for i in range(n // lis, 0, -1):
	for j in range(lis * i - lis + 1, lis * i + 1):
		ans.append(j)
print(*ans)


n = int(input())
m = int(n ** 0.5)
a = []
for i in range(0, n, m):
	for j in range(i, min(i + m, n)):
		a.append(min(i + m, n) - j + i)
print(' '.join((str(_) for _ in a)))


n = int(input())
import math
x = int(math.sqrt(n))
for i in range(n, 0, -x):
	for j in range(i - x + 1, i + 1):
		if j > 0:
			print(j, end=' ')


import math
t = int(input(''))
a = []
if t < 4:
	for i in range(t):
		a.append(i + 1)
elif t == 4:
	a = [3, 4, 1, 2]
else:
	b = []
	for i in range(1, t):
		b.append(math.ceil(t / i) + i)
	k = b.index(min(b))
	k = k + 1
	for i in range(t // k):
		tmp = (i + 1) * k
		while tmp != i * k:
			a.append(tmp)
			tmp -= 1
	tt = t - t // k * k
	for i in range(tt):
		a.append(t)
		t -= 1
for i in range(len(a)):
	print(a[i], end=' ')


import math
n = int(input())
k = math.ceil(math.sqrt(n))
a = [[j for j in range(min(i + k - 1, n), i - 1, -1)] for i in range(1, n + 1, k)]
for i in a[::-1]:
	print(*i[::-1], end=' ')


n = int(input())
a = []
rootn = int(n ** 0.5)
for i in range(n // rootn):
	for j in range(rootn, 0, -1):
		a.append(rootn * i + j)
for i in range(n % rootn):
	a.append(n - i)
print(*a)


n = int(input())
L = int(n ** 0.5)
T = n // L
s = []
for cur in range(0, n, T):
	s += list(range(min(cur + T, n), cur, -1))
print(' '.join(map(str, s)))


import math
n = int(input())
wk1 = math.floor(math.sqrt(n))
wk2 = n // wk1
for i in range(wk2 * wk1, n):
	print(i + 1, end=' ')
for i in reversed(range(wk1)):
	for j in range(wk2 * i, wk2 * (i + 1)):
		print(j + 1, end=' ')
print()


import math
n = int(input())
step = math.ceil(n ** (1 / 2))
k = n
i = 1
ans = []
while k > 0:
	tt = list(range(i, min(i + step, n + 1)))[::-1]
	ans += tt
	k -= step
	i += step
print(*ans)


import sys

def input():
	return sys.stdin.readline().strip()
n = int(input())
k = int(n ** 0.5)
ret = sum((list(range(i, i - k, -1)) for i in range(k, n + 1, k)), [])
if n % k > 0:
	ret += range(n, n - n % k, -1)
print(*ret)


import math
n = int(input())
m = math.ceil(math.sqrt(n))
ans = []
for k in range(m):
	s = min((k + 1) * m, n)
	t = k * m
	ans.extend(list(range(s, t, -1)))
print(*ans)


n = int(input())
ans = []
m = n + 1
mi = 1
for i in range(2, n):
	if n // i + i + int(bool(n % i)) < m:
		m = n // i + i + int(bool(n % i))
		mi = i
k = n
for i in range(n % mi):
	for j in range(mi + 1):
		ans.append(k - mi + j)
	k -= mi + 1
while k > 0:
	for j in range(mi):
		ans.append(k - mi + 1 + j)
	k -= mi
print(*ans)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, **kwargs, file=sys.stderr)
	dprint('debug mode')
except ModuleNotFoundError:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
for i in range(N + 20):
	if i * i > N:
		break
x = i - 1
if x * x != N:
	x += 1
dprint(x)
t = N // x
res = []
for i in range(N - t * x):
	res.append(t * x + i + 1)
for i in range(t - 1, -1, -1):
	for j in range(x):
		res.append(i * x + j + 1)
for x in res:
	print(x, end=' ')


from sys import stdin
from math import *
line = stdin.readline().rstrip().split()
n = int(line[0])
sizeG = int(floor(sqrt(n)))
cantG = int(ceil(n / sizeG))
for i in range(cantG - 1):
	for j in range(sizeG, 0, -1):
		print(j + i * sizeG, end=' ')
for j in range(n, (cantG - 1) * sizeG, -1):
	print(j, end=' ')


import math

def listsum(l):
	a = []
	for i in l:
		a = a + i
	return a
n = int(input())
m = math.ceil(math.sqrt(n))
a = [' '.join([str(m - i + x * m) for x in range(int((n - m + i) / m) + 1)]) for i in range(m)]
print(' '.join(a))


n = int(input())
f = int(n ** (1 / 2))
for i in range(f, n + f, f):
	for j in range(min(n, i), i - f, -1):
		print(j, end=' ')


import math
n = int(input())
sqr = int(math.sqrt(n))
dev = n // sqr
remain = n % sqr
for i in range(sqr - 1, -1, -1):
	print(' '.join((str(j + i * dev + remain) for j in range(1, dev + 1))), end=' ')
print(' '.join((str(j + 1) for j in range(remain))))


from math import *
n = int(input())
if n < 4:
	arr = []
	for i in range(1, n + 1):
		arr.append(i)
	print(*arr)
else:
	arr = []
	if ceil(sqrt(n)) == floor(sqrt(n)):
		x = floor(sqrt(n))
		y = floor(sqrt(n))
	else:
		x = floor(sqrt(n))
		y = ceil(sqrt(n))
		if x * y > n:
			y -= 1
	if x * y < n:
		a = x * y + 1
		for i in range(a, n + 1):
			arr.append(i)
	for i in range(x):
		a = (x - i - 1) * y + 1
		for j in range(a, a + y):
			arr.append(j)
	print(*arr)


import math
a = int(input())
c = a
i = 0
ls = []
ts = []
s = math.floor(math.sqrt(a))
for j in range(a, 0, -1):
	i += 1
	ts = [j] + ts
	if not i % s:
		ls += ts
		ts = []
ls += ts
print(*ls)


import math
n = int(input())
un = int(math.sqrt(n))
ans = []
for i in range(n):
	ans.append(n - i)
b = []
for i in range(n):
	if i % un == 0:
		b.reverse()
		for j in b:
			print(j, end=' ')
		b = []
	b.append(ans[i])
b.reverse()
for i in b:
	print(i, end=' ')
print()


n = int(input())
min1 = 1000000009
id = 0
s = ''
for i in range(1, n + 1):
	m = (n + i - 1) // i
	if m + i < min1:
		min1 = m + i
		id = i
a = []
for i in range(n, 0, -1):
	a.append(i)
	if len(a) == id:
		a.reverse()
		for j in range(len(a)):
			s += str(a[j]) + ' '
		a.clear()
if len(a) != 0:
	a.reverse()
	for j in range(len(a)):
		s += str(a[j]) + ' '
	a.clear()
print(s)


n = int(input())
s = int(n ** 0.5)
i = 0
cur = n
while i < n:
	if n - i < s:
		for j in range(1, n - i + 1):
			print(j)
		break
	cur -= s
	i += s
	for j in range(cur + 1, cur + s + 1):
		print(j, end=' ')


n = int(input())
t = n + 10
for i in range(1, n + 1):
	p = n // i
	if p != n / i:
		p = p + 1
	if t > i + p:
		t = i + p
		j = i
t = t - j
p = []
for i in range(j):
	z = n - t * (i + 1)
	for k in range(t):
		z = z + 1
		if z > 0:
			p.append(z)
print(*p)


def inp1():
	return int(input())

def inp2():
	return list(map(int, input().split()))

def inp3():
	return map(int, input().split())
if 1:
	n = inp1()
	x = int(n ** 0.5)
	i = 0
	y = n
	ans = []
	while i < n:
		arr = []
		for j in range(x):
			if y == 0:
				break
			arr.append(y)
			y -= 1
			i += 1
			if y == 0:
				break
		arr = arr[::-1]
		for j in arr:
			ans.append(j)
	print(*ans)


import math
n = int(input())
tmp = int(math.sqrt(n))
(l, r) = (max(1, n - tmp + 1), n)
while True:
	for i in range(l, r + 1):
		print(i, end=' ')
	if l == 1:
		break
	(l, r) = (max(1, l - tmp), l - 1)


n = int(input())
if n == 1:
	print(1)
	exit()
if n == 2:
	print(2, 1)
	exit()
if n == 3:
	print(2, 1, 3)
	exit()
l = []
mai = 1
act = n
for i in range(2, n):
	v = n // i
	if n % i != 0:
		v += i + 1
	else:
		v += i
	if act >= v:
		act = v
		mai = i
ans = []
for i in range(n // mai):
	w = [j for j in range((i + 1) * mai, i * mai, -1)]
	ans += w
for i in range(n, n // mai * mai, -1):
	ans.append(i)
print(*ans)


from math import sqrt
n = int(input())
sq = int(sqrt(n))
k = n % sq
ans = []
shft = 1
for i in range(k):
	ans.append(list(range(shft + (sq + 1) * i, shft + (sq + 1) * (i + 1))))
shft = k * (sq + 1) + 1
for i in range(n // sq - k):
	ans.append(list(range(shft + sq * i, shft + sq * (i + 1))))
ans.reverse()
for i in range(n // sq):
	print(*ans[i], end=' ')


n = int(input())
parts = 0
min_diff = 10000000000
for i in range(1, n + 1):
	if abs(n // i - i) < min_diff:
		min_diff = abs(n // i - i)
		parts = i
i = 0
res = []
while i + parts <= n:
	res += list(range(i + parts, i, -1))
	i += parts
res += list(range(n, i, -1))
print(*res)


n = int(input())
import math
key = n
arr = []
for i in range(1, math.ceil(pow(n, 0.5)) + 1):
	key = key - math.floor(pow(n, 0.5))
	for j in range(1, math.floor(pow(n, 0.5)) + 1):
		if key + j > 0:
			arr.append(key + j)
for i in range(1, min(arr)):
	arr.append(i)
print(*arr)


n = int(input())
import math
d = int(math.sqrt(n))
for i in range(n // d):
	b = n - d * (i + 1) + 1
	for i in range(d):
		print(b, end=' ')
		b += 1
a = 1
for i in range(n - d * (n // d)):
	print(a, end=' ')
	a += 1


n = int(input())
t = int(n ** (1 / 2))
ans = []
for i in range(1, n + 1, t):
	ans.append([])
	for j in range(i, i + t):
		if j <= n:
			ans[-1].append(j)
ans = ans[::-1]
res = []
for i in ans:
	res.extend(i)
print(*res)


from math import ceil, floor
n = int(input())
k = floor(n ** 0.5)
tmp = [[j for j in range(i, min(k + i, n + 1))] for i in range(k * (n // k) + 1, 0, -k)]
answer = []
for item in tmp:
	answer += item
print(' '.join((str(item) for item in answer)))


n = int(input())
k = int(n ** 0.5)
j = 0
s = []
for j in range(0, k + 2):
	s += [i + j * k for i in range(k, 0, -1)]
s = list(filter(lambda x: x <= n, s))
for i in s:
	print(i, end=' ')


import math
n = int(input())
c = int(math.ceil(math.sqrt(n)))
for i in range(0, n, c):
	for j in range(min(i + c, n), i, -1):
		print(j, end=' ')


import math
n = int(input())
a = []
b = math.ceil(math.sqrt(n))
c = n % b
d = n // b
for i in range(n - c + 1, n + 1):
	a.append(i)
for k in range(d):
	i = d - 1 - k
	for j in range(i * b + 1, i * b + 1 + b):
		a.append(j)
print(*a)


n = int(input())
i = 0
minn = 10000000000
index = -1
for i in range(1, n + 1):
	summ = i + n // i
	if n % i != 0:
		summ += 1
	if summ < minn:
		minn = summ
		index = i
p = n - n % index
s = ''
for i in range(1, n % index + 1):
	s += str(p + i) + ' '
p = p - index
while p >= 0:
	for j in range(1, index + 1):
		s += str(p + j) + ' '
	p -= index
print(s)


from math import sqrt
n = int(input())
i = 0
index = int(sqrt(n))
p = n - n % index
s = ''
for i in range(1, n % index + 1):
	s += str(p + i) + ' '
p = p - index
while p >= 0:
	for j in range(1, index + 1):
		s += str(p + j) + ' '
	p -= index
print(s)


n = int(input())
s = []
val = int(pow(n, 0.5))
while n > 0:
	count = 0
	ar = []
	while n > 0 and count < val:
		count += 1
		ar.insert(0, str(n))
		n -= 1
	s.extend(ar)
print(' '.join(s))


n = int(input())
ans = []
m = int(n ** 0.5)
x = n
while x - m > 0:
	for i in range(1, m + 1):
		ans.append(x - m + i)
	x -= m
for i in range(1, x + 1):
	ans.append(i)
print(*ans)


n = int(input())
t = int(n ** 0.5)
temp = []
while n >= t:
	temp += list(range(n - t + 1, n + 1))
	n -= t
temp += list(range(1, n + 1))
print(' '.join([str(i) for i in temp]))


from math import *
n = int(input())
res = n + 2
k = -1
for i in range(1, n + 1):
	if ceil(n / i) + i < res:
		res = ceil(n / i) + i
		k = i
i = n + 1
while i > 0:
	for j in range(max(1, i - k), i):
		print(j, end=' ')
	i -= k


import math
n = int(input())
sl = int(math.sqrt(n))
meomeo = int(n / sl)
if n % sl > 0:
	meomeo += 1
result = []
for i in range(1, meomeo + 1):
	for j in range(max(1, n - i * sl + 1), n - (i - 1) * sl + 1):
		result.append(j)
for k in result:
	print(k, end=' ')
print()


n = int(input())
ma = 99999999999999999
ans = [1, n, 0]
for i in range(2, int(n ** 0.5) + 1):
	j = i
	k = n // i
	t = 0
	if n % i != 0:
		t = 1
	if j + k + t <= ma:
		ans = [j, k, t]
		ma = j + k + t
fi = [[0 for j in range(ans[1])] for i in range(ans[0])]
cou = n
j = ans[0]
k = ans[1]
t = n % j
for i in range(j):
	r = 0
	if t > 0:
		r = 1
		t -= 1
	for jw in range(k + r):
		print(cou - k - r + jw + 1, end=' ')
	cou -= k + r