def func():
global s, n
def init():
if level == 1:
stack[level] = 0
else:
stack[level] = stack[level-1]-1
def succ():
global s
if stack[level] < (n - s):
stack[level] += 1
return True
else:
s = s - stack[level-1]
return False
def valid():
global s
if stack[level] <= n - s:
s = s + stack[level]
return True
return False
def printf():
global s
for i in range(1, level+1):
print(stack[i], end = " ")
s -= stack[level]
print()
def sol():
return s == n
def backtracking():
global level, s
s = 0
level = 1
init()
while level > 0:
h = True
v = False
while h is True and v is False:
h = succ()
if h is True:
v = valid()
if h is True:
if sol() is True:
printf()
else:
level+=1
init()
else:
level-=1
n = 4
stack = [0] * (n+1)
backtracking()
func()
ZGVmIGZ1bmMoKToKICAgIGdsb2JhbCBzLCBuCiAgICBkZWYgaW5pdCgpOgogICAgICAgIGlmIGxldmVsID09IDE6CiAgICAgICAgICAgIHN0YWNrW2xldmVsXSA9IDAKICAgICAgICBlbHNlOgogICAgICAgICAgICBzdGFja1tsZXZlbF0gPSBzdGFja1tsZXZlbC0xXS0xCgogICAgZGVmIHN1Y2MoKToKICAgICAgICBnbG9iYWwgcwogICAgICAgIGlmIHN0YWNrW2xldmVsXSA8IChuIC0gcyk6CiAgICAgICAgICAgIHN0YWNrW2xldmVsXSArPSAxCiAgICAgICAgICAgIHJldHVybiBUcnVlCiAgICAgICAgZWxzZToKICAgICAgICAgICAgcyA9IHMgLSBzdGFja1tsZXZlbC0xXQogICAgICAgICAgICByZXR1cm4gRmFsc2UKCiAgICBkZWYgdmFsaWQoKToKICAgICAgICBnbG9iYWwgcwogICAgICAgIGlmIHN0YWNrW2xldmVsXSA8PSBuIC0gczoKICAgICAgICAgICAgcyA9IHMgKyBzdGFja1tsZXZlbF0KICAgICAgICAgICAgcmV0dXJuIFRydWUKICAgICAgICByZXR1cm4gRmFsc2UKCiAgICBkZWYgcHJpbnRmKCk6CiAgICAgICAgZ2xvYmFsIHMKICAgICAgICBmb3IgaSBpbiByYW5nZSgxLCBsZXZlbCsxKToKICAgICAgICAgICAgcHJpbnQoc3RhY2tbaV0sIGVuZCA9ICIgIikKICAgICAgICBzIC09IHN0YWNrW2xldmVsXQogICAgICAgIHByaW50KCkKCiAgICBkZWYgc29sKCk6CiAgICAgICAgcmV0dXJuIHMgPT0gbgoKICAgIGRlZiBiYWNrdHJhY2tpbmcoKToKICAgICAgICBnbG9iYWwgbGV2ZWwsIHMKICAgICAgICBzID0gMAogICAgICAgIGxldmVsID0gMQogICAgICAgIGluaXQoKQogICAgICAgIHdoaWxlIGxldmVsID4gMDoKICAgICAgICAgICAgaCA9IFRydWUKICAgICAgICAgICAgdiA9IEZhbHNlCiAgICAgICAgICAgIHdoaWxlIGggaXMgVHJ1ZSBhbmQgdiBpcyBGYWxzZToKICAgICAgICAgICAgICAgIGggPSBzdWNjKCkKICAgICAgICAgICAgICAgIGlmIGggaXMgVHJ1ZToKICAgICAgICAgICAgICAgICAgICB2ID0gdmFsaWQoKQogICAgICAgICAgICBpZiBoIGlzIFRydWU6CiAgICAgICAgICAgICAgICBpZiBzb2woKSBpcyBUcnVlOgogICAgICAgICAgICAgICAgICAgIHByaW50ZigpCiAgICAgICAgICAgICAgICBlbHNlOgogICAgICAgICAgICAgICAgICAgIGxldmVsKz0xCiAgICAgICAgICAgICAgICAgICAgaW5pdCgpCiAgICAgICAgICAgIGVsc2U6CiAgICAgICAgICAgICAgICBsZXZlbC09MQoKICAgIG4gPSA0CiAgICBzdGFjayA9IFswXSAqIChuKzEpCiAgICBiYWNrdHJhY2tpbmcoKQoKZnVuYygpCg==