#include "look.h"
#include <stdio.h>
#include <stdlib.h>

#define MaxN            1000000L
#define true 1
#define false 0 

static int Init = true;
static long N;
static long S[MaxN+1];

static void ReadIn()
{
  FILE *inFile = NULL;
  long x, i;
  
  inFile = fopen("sticks.in","r");
  fscanf(inFile, "%ld%*[^\n]", &N);
  getc(inFile);

  for (i = 1; i <= N; i++) {
    fscanf(inFile, "%ld", &x);
    S[i] = x;
  }  /*for i*/
  if (inFile != NULL)
    fclose(inFile);
  inFile = NULL;
  Init = false;
}  /*Readin*/

int Compare(long x, long y)
{
  if (Init) {
    printf("ERROR: You must call GetN first\n");
    exit(1);
  }
  if (x < 1 || x > N || y < 1 || y > N) {
    printf("ERROR: Illegal argument of Compare\n");
    exit(1);
  }
  if (S[x] < S[y])
    return -1;
  else if (S[x] > S[y])
    return 1;
  else
    return 0;
}

long GetN()
{
  if (Init) {
    ReadIn();
    Init = false;
  }
  return N;
}

void Answer(long x)
{
  FILE *outFile = NULL;

  if (Init) {
    printf("ERROR: You must call GetN first\n");
    exit(1);
  }

  outFile = fopen("sticks.out","w");
  fprintf(outFile, "%ld\n", x);
  fclose(outFile);
  outFile = NULL;
  exit(0);
}


