Const IM = 139968
Const IA =   3877
Const IC =  29573

LAST = 42

Function gen_random(n)
    LAST = (LAST * IA + IC) Mod IM
    gen_random = n * LAST / IM
End Function


Sub heapsort(n, ra)
    rra = 0
    i = 0
    j = 0
    l = CLng((n / 2) + 1)
    ir = n
    
    While 1
        If l > 1 Then
            l = l - 1
            rra = ra(l)
        Else
            rra = ra(ir)
            ra(ir) = ra(1)
            ir = ir - 1
            If ir = 1 Then
                ra(1) = rra
                Exit Sub
            End If
        End If
        
        i = l
        j = l * 2

        While  CLng(j) <= CLng(ir)
            If CLng(j) < CLng(ir) Then
                If ra(j) < ra(j+1) Then j = j + 1
            End If
            
            If rra < ra(j) Then
                ra(i) = ra(j)
                i = j
                j = j + i
            Else
                j = ir + 1
            End If
        Wend
        ra(i) = rra
    Wend    

End Sub

n = WScript.Arguments(0)
If n < 1 Then n = 1

Redim ary(N+1)

For i = 1 To N
    ary(i) = gen_random(1)
Next

heapsort N, ary

WScript.Echo FormatNumber(ary(N), 10)