PROGRAM Palindrome
   IMPLICIT NONE
    
   INTEGER, PARAMETER :: Length = 30
   INTEGER, DIMENSION(1:Length) :: X
   INTEGER            :: Size, Head, Tail, I
  
   READ (*,*) Size, (X(I), I=1, Size)

   WRITE(*,*) 'Input array:'
   WRITE(*,*) ( X(I), I=1, Size )

   Head = 1
   Tail = Size
   DO
      IF ( Head >= Tail ) EXIT
      IF ( X(Head) /= X(Tail) ) EXIT
      Head = Head + 1
      Tail = Tail - 1
   END Do 

   WRITE(*,*)
   IF ( Head >= Tail ) THEN
      WRITE(*,*) 'The input array is a palindorme'
   ELSE 
      WRITE(*,*) 'The input array is NOT a palindrome'
   END IF
END PROGRAM Palindrome
