C      PROGRAM SELECT(INPUT,OUTPUT,TAPE10,TAPE18,TAPE6=OUTPUT)
      DIMENSION LM(500),Y(75,500),A(500,500)
      IXF=0
      REWIND 18
      READ(18,*)MEMAX
      DO 10 I=1,MEMAX
      DO 10 J=1,MEMAX
  10  A(I,J)=0.
      DO 1 I=1,1000
      READ(18,*)L,J
      IF(L.EQ.0)GO TO 2
      IF(J.EQ.0)GO TO 1
      A(L,J)=-1.
      A(J,L)=-1.
  1   CONTINUE
  2   IE=1
  11  CONTINUE
      LUM=0
      DO 3 I=1,50
      DO 3 J=1,MEMAX
  3   Y(I,J)=0.
      DO 4 I=1,10000
      READ(18,*)LU,INDX,IEXP,AL
      IF(IEXP.NE.IE)GO TO 5
      LUM=MAX0(LUM,LU)
  4   Y(LU,INDX)=AL
  5   BACKSPACE 18
      IE=IEXP
      IF(IE.EQ.0)IXF=1
      DO 6 I=1,MEMAX
      DO 6 J=I,MEMAX
      IF(A(I,J).EQ.-1.)GO TO 6
      DO 7 L=1,LUM
  7   A(I,J)=A(I,J)+Y(L,I)*Y(L,J)
      A(J,I)=A(I,J)
  6   CONTINUE
      IF(IXF.EQ.1)GO TO 99
      GO TO 11
  99  CONTINUE
      DO 8 I=1,MEMAX
      AM=0.
      DO 9 J=1,MEMAX
      AM=AMAX1(A(I,J),AM)
  9   CONTINUE
      IF(AM.EQ.0.)AM=1.
      DO 20 J=1,MEMAX
      IF(A(I,J).EQ.-1.)GO TO 19
      A(I,J)=A(I,J)/AM
      IF(A(I,J).LT..1)GO TO 21
  19  A(I,J)=1.
      GO TO 20
  21  A(I,J)=0.
  20  CONTINUE
      WRITE(10,*)(IFIX(A(I,J)),J=1,MEMAX)
  8   CONTINUE
      DO 333 I=1,MEMAX
      WRITE(6,334)I
      LX=0
      DO 336 J=1,MEMAX
      IF(A(I,J).EQ.0.)GO TO 336
      LX=LX+1
      LM(LX)=J
  336 CONTINUE
      WRITE(6,*)(LM(J),J=1,LX)
 333  CONTINUE
 334  FORMAT(10X,3HME=,1I3,3X,21HPREDICTED CORRELATION/)
      STOP
      END
