program Check;

{$APPTYPE CONSOLE}

uses
  TestLib, SysUtils;

const
  MAXN = 10000;

var
  n, i, x, last, y: integer;
  a, b: array [1..MAXN] of integer;

begin
	n := inf.ReadLongInt;
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),0);
  
  last := 0;
  for i := 1 to n do begin
  	x := ouf.ReadLongInt;
  	if (x < 1) or (x > n) then quit(_WA,Format('Invalid number %d found',[x]));
  	
  	inc(b[x]);
  	if (b[x] > 1) then quit(_WA,Format('Number %d found twice',[x]));
  	  	
  	if (i > 1) then begin
  		y := abs(x-last);
  		if (y < 1) or (y >= n) then quit(_WA,Format('Invalid difference %d found',[y]));
  	  inc(a[y]);
  	  if (a[y] > 1) then quit(_WA,Format('Difference %d found twice',[y]));
  	end;
  	
  	last := x;
  end;
  
  if not ouf.SeekEof then quit(_PE,'Extra characters in output file.');

  quit(_OK,Format('N = %d',[n]));
end.
