# your code goes here
from random import randint
def swap( A, i, j) :
temp = A[ i]
A[ i] = A[ j]
A[ j] = temp
def Partition( A, lb, ub) :
Pivot = A[ lb]
start = lb
end = ub
while ( start < end) :
while ( A[ start] <= Pivot) :
start+= 1
while ( A[ end] > Pivot) :
end-= 1
if ( start < end) :
swap( A, start, end)
swap( A, lb, end)
return end
def QuickSort( A, lb, ub) :
if ( lb < ub) :
loc = Partition( A, lb, ub)
QuickSort( A, lb, loc - 1 )
QuickSort( A, loc+1 , ub)
n= int ( input ( ) )
m= int ( input ( ) )
A = [ ] ;
for k in range ( n) :
A.append ( randint( 0 , m) )
print ( A)
QuickSort( A, 0 , len ( A) -1 )
print ( A)
while A:
A.pop ( )
IyB5b3VyIGNvZGUgZ29lcyBoZXJlCmZyb20gcmFuZG9tIGltcG9ydCByYW5kaW50CgpkZWYgc3dhcChBLGksaik6CiAgICB0ZW1wID0gQVtpXQogICAgQVtpXSA9IEFbal0KICAgIEFbal0gPSB0ZW1wCgpkZWYgUGFydGl0aW9uKEEsbGIsdWIpOgogICAgUGl2b3QgPSBBW2xiXQogICAgc3RhcnQgPSBsYgogICAgZW5kID0gdWIKICAgIHdoaWxlKHN0YXJ0IDwgZW5kKToKICAgICAgICB3aGlsZShBW3N0YXJ0XSA8PSBQaXZvdCk6CiAgICAgICAgICAgIHN0YXJ0Kz0xCiAgICAgICAgd2hpbGUoQVtlbmRdID4gUGl2b3QpOgogICAgICAgICAgICBlbmQtPTEKICAgICAgICBpZihzdGFydCA8IGVuZCk6CiAgICAgICAgICAgIHN3YXAoQSxzdGFydCxlbmQpCiAgICBzd2FwKEEsbGIsZW5kKQogICAgcmV0dXJuIGVuZAoKZGVmIFF1aWNrU29ydChBLGxiLHViKToKICAgIGlmKGxiIDwgdWIpOgogICAgICAgIGxvYyA9IFBhcnRpdGlvbihBLGxiLHViKQogICAgICAgIFF1aWNrU29ydChBLGxiLGxvYyAtIDEpCiAgICAgICAgUXVpY2tTb3J0KEEsbG9jKzEsdWIpCgpuPWludChpbnB1dCgpKQptPWludChpbnB1dCgpKQoKQSA9IFtdOwoKZm9yIGsgaW4gcmFuZ2Uobik6CiAgICBBLmFwcGVuZChyYW5kaW50KDAsbSkpCgpwcmludChBKQoKUXVpY2tTb3J0KEEsMCxsZW4oQSktMSkKCnByaW50KEEpCgoKd2hpbGUgQToKICAgIEEucG9wKCk=
stdout
[50, 480, 628, 225, 312, 474, 830, 412, 888, 406, 1000, 597, 54, 686, 446, 508, 19, 487, 519, 419]
stderr
Traceback (most recent call last):
File "./prog.py", line 39, in <module>
File "./prog.py", line 27, in QuickSort
File "./prog.py", line 27, in QuickSort
File "./prog.py", line 27, in QuickSort
File "./prog.py", line 25, in QuickSort
File "./prog.py", line 14, in Partition
IndexError: list index out of range