Printing 1,000,000 numbers in 1 sec. in Python
Nice solution, few suggestions:

Printing the numbers one by one might be the issue. Generate the list of numbers first and then call print only once.
The case n==1 is already handled, so the first elif can be removed.

Applying the suggestions:
n = int(input())
if n == 2 or n == 3:
    print(&quot;NO SOLUTION&quot;)
elif n == 4:
    print(&quot;3 1 4 2&quot;)
else:
    beautiful_perm = [*range(1, n + 1, 2), *range(2, n + 1, 2)]
    print(' '.join(map(str, beautiful_perm)))

By inverting the ranges we don't need to check for n==4:
n = int(input())
if n == 2 or n == 3:
    print(&quot;NO SOLUTION&quot;)
else:
    beautiful_perm = [*range(2, n + 1, 2), *range(1, n + 1, 2)]
    print(' '.join(map(str, beautiful_perm)))

Runtime on CSES:
n = 906819 (CPython3)
Original: 0.92 s
Improved: 0.26 s

n = 1000000 (CPython3)
Original: timeout
Improved: 0.28 s

n = 1000000 (PyPy3)
Original: 0.61 s
Improved: 0.15 s