def func():
def ok(level):
return True
def print_sol():
max = stack[1]
for i in range(2, n + 1):
if max < stack[i]:
max = stack[i]
for i in range(1, max+1):
print("{", end = " ")
for j in range(1, n + 1):
if i == stack[j]:
print(j, end = " ")
print("}", end = "")
print()
def partition(level):
if level > n:
print_sol()
else:
for i in range(1, n + 1 ):
if stack[level] < stack[ level - 1 ] + 1:
stack[level] = i
if ok(level):
partition( level + 1 )
n = 5
stack = [0] * (n+1)
partition(1)
func()
ZGVmIGZ1bmMoKToKCiAgICBkZWYgb2sobGV2ZWwpOgoKICAgICAgICByZXR1cm4gVHJ1ZQoKICAgIGRlZiBwcmludF9zb2woKToKICAgICAgICAKICAgICAgICBtYXggPSBzdGFja1sxXQogICAgICAgIAogICAgICAgIGZvciBpIGluIHJhbmdlKDIsIG4gKyAxKToKICAgICAgICAgICAgCiAgICAgICAgICAgIGlmIG1heCA8IHN0YWNrW2ldOgogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgIG1heCA9IHN0YWNrW2ldCiAgICAgICAgICAgICAgIAogICAgICAgIGZvciBpIGluIHJhbmdlKDEsIG1heCsxKToKICAgICAgICAgICAgCiAgICAgICAgICAgIHByaW50KCJ7IiwgZW5kID0gIiAiKQogICAgICAgICAgICAKICAgICAgICAgICAgZm9yIGogaW4gcmFuZ2UoMSwgbiArIDEpOgogICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICBpZiBpID09IHN0YWNrW2pdOgogICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgIHByaW50KGosIGVuZCA9ICIgIikKICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgcHJpbnQoIn0iLCBlbmQgPSAiIikKICAgICAgICAgICAgCiAgICAgICAgcHJpbnQoKSAgICAKCiAgICBkZWYgcGFydGl0aW9uKGxldmVsKToKICAgICAgICBpZiBsZXZlbCA+IG46CiAgICAgICAgICAgcHJpbnRfc29sKCkKICAgICAgICBlbHNlOgogICAgICAgICAgZm9yIGkgaW4gcmFuZ2UoMSwgbiArIDEgKToKICAgICAgICAgICAgIGlmIHN0YWNrW2xldmVsXSA8IHN0YWNrWyBsZXZlbCAtIDEgXSArIDE6CiAgICAgICAgICAgICAgICBzdGFja1tsZXZlbF0gPSBpCiAgICAgICAgICAgICAgICBpZiBvayhsZXZlbCk6CiAgICAgICAgICAgICAgICAgICBwYXJ0aXRpb24oIGxldmVsICsgMSApCiAgICBuID0gNQogICAgc3RhY2sgPSBbMF0gKiAobisxKQogICAgcGFydGl0aW9uKDEpCgpmdW5jKCkK