/* The Great Win32 Language Shootout http://dada.perl.it/shootout/ 
   contributed by Isaac Gouy (Nice novice)

   Transliterated from the Java implementation

To compile:	
   nicec --sourcepath=.. -d=. -a heapsort.jar heapsort

To run:
   java -jar heapsort.jar 80000
*/


import random; // reuse gen_random & floatFormat & toSingleInt


void main(String[] args){
   let n = toSingleInt(args);

   let numbers = new double[n+1];
   for (var i = 1; i <= n; i++) numbers[i] = gen_random(1);

   heapsort(n, numbers);

   println(floatFormat(10).format(numbers[n]));
}


void heapsort(int n, double[] ra) {
   int l, j, ir, i;
   double rra;

   if (n < 2) return;
   l = (n >> 1) + 1;
   ir = n;
   for (;;) {
      if (l > 1) rra = ra[--l];
      else {
         rra = ra[ir];
         ra[ir] = ra[1];
         if (--ir == 1) {
            ra[1] = rra;
            return;
         }
      }
      i = l;
      j = l << 1;
      while (j <= ir) {
         if (j < ir && ra[j] < ra[j+1]) { ++j; }
         if (rra < ra[j]) {
            ra[i] = ra[j];
            j += (i = j);
         } 
         else j = ir + 1;
      }
      ra[i] = rra;
   }
}