from random import randrange
def qsort(list):
if list == []:
return []
else:
pivot = list[0]
lesser = qsort([x for x in list[1:] if x < pivot])
greater = qsort([x for x in list[1:] if x >= pivot])
return lesser + [pivot] + greater
def qsortline(list):
return [] if list==[] else qsortline([x for x in list[1:] if x < list[0]]) + [list[0]] + qsortline([x for x in list[1:] if x >= list[0]])
def qsortrand(list):
if list == []:
return []
else:
pivot = list.pop(randrange(len(list)))
lesser = qsortrand([l for l in list if l < pivot])
greater = qsortrand([l for l in list if l >= pivot])
return lesser + [pivot] + greater
ZnJvbSByYW5kb20gaW1wb3J0IHJhbmRyYW5nZSAKCmRlZiBxc29ydChsaXN0KToKICAgIGlmIGxpc3QgPT0gW106IAogICAgICAgIHJldHVybiBbXQogICAgZWxzZToKICAgICAgICBwaXZvdCA9IGxpc3RbMF0KICAgICAgICBsZXNzZXIgPSBxc29ydChbeCBmb3IgeCBpbiBsaXN0WzE6XSBpZiB4IDwgcGl2b3RdKQogICAgICAgIGdyZWF0ZXIgPSBxc29ydChbeCBmb3IgeCBpbiBsaXN0WzE6XSBpZiB4ID49IHBpdm90XSkKICAgICAgICByZXR1cm4gbGVzc2VyICsgW3Bpdm90XSArIGdyZWF0ZXIKCmRlZiBxc29ydGxpbmUobGlzdCk6CiAgICByZXR1cm4gW10gaWYgbGlzdD09W10gIGVsc2UgcXNvcnRsaW5lKFt4IGZvciB4IGluIGxpc3RbMTpdIGlmIHggPCBsaXN0WzBdXSkgKyBbbGlzdFswXV0gKyBxc29ydGxpbmUoW3ggZm9yIHggaW4gbGlzdFsxOl0gaWYgeCA+PSBsaXN0WzBdXSkKCiAgICAgIAoKZGVmIHFzb3J0cmFuZChsaXN0KToKICAgIGlmIGxpc3QgPT0gW106IAogICAgICAgIHJldHVybiBbXQogICAgZWxzZToKICAgICAgICBwaXZvdCA9IGxpc3QucG9wKHJhbmRyYW5nZShsZW4obGlzdCkpKQogICAgICAgIGxlc3NlciA9IHFzb3J0cmFuZChbbCBmb3IgbCBpbiBsaXN0IGlmIGwgPCBwaXZvdF0pCiAgICAgICAgZ3JlYXRlciA9IHFzb3J0cmFuZChbbCBmb3IgbCBpbiBsaXN0IGlmIGwgPj0gcGl2b3RdKQogICAgICAgIHJldHVybiBsZXNzZXIgKyBbcGl2b3RdICsgZ3JlYXRlcg==