Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # author: ThePonyCoder
- # created: 01.07.2019, 12:41
- # filename: 1_1.py
- # path: F:/Projects/CodeForces/resp_2019/1_1.py
- import os
- import sys
- import itertools
- from math import factorial
- sys.stdin = open('input.txt', 'r')
- sys.stdout = open('output.txt', 'w')
- def rI():
- return [int(i) for i in input().split()]
- def print(*args, sep=' ', end='\n'):
- s = ''
- for i in args:
- s += str(i) + sep
- s += end
- sys.stdout.write(s)
- def main(n):
- ans1 = []
- ans2 = []
- if n % 2 == 0:
- ans1.append(n // 2)
- for i in range(n, 0, -1):
- if i == n // 2:
- continue
- ans1.append(i)
- # print()
- ans2.append(n // 2 + 1)
- for i in range(1, n + 1):
- if i == n // 2 + 1:
- continue
- ans2.append(i)
- else:
- ans1.append(n // 2 + 1)
- ans1.append(n // 2)
- for i in range(n, 0, -1):
- if i == n // 2 or i == n // 2 + 1:
- continue
- ans1.append(i)
- # print()
- ans2.append(n // 2 + 1)
- ans2.append(n // 2 + 2)
- for i in range(1, n + 1):
- if i == n // 2 + 1 or i == n // 2 + 2:
- continue
- ans2.append(i)
- return ans1, ans2
- # print(itertools.permutations(list(range(1, 10)))
- n = rI()[0]
- ans1,ans2 = main(n)
- print(*ans1)
- print(*ans2)
- def brut(n):
- perms = itertools.permutations(list(range(1, n + 1)))
- pos1 = factorial(n) // 2 - 1
- pos2 = pos1 + 1
- ans1 = None
- ans2 = None
- for idx,it in enumerate(perms):
- if idx == pos1:
- ans1 = it
- if idx == pos2:
- return ans1, it
- # return perms[pos1], perms[pos2]
- # print(*perms[pos1], sep=' ')
- # print(*perms[pos2], sep=' ')
- # brut(3)
- def test_main():
- for i in range(2, 20):
- print(i)
- assert brut(i) == main(i), (brut(i), main(i))
- # test_main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement