IDENTIFICATION DIVISION.
PROGRAM-ID. 133B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC  X(40).
01 N          PIC  9(2).
01 D          PIC  9(2).
01 TBL-AREA.
   03 X1      OCCURS 10.
      05 Y1   OCCURS 10.    
        07 X  PIC S9(02). 
01 I          PIC  9(02).
01 J          PIC  9(02).
01 K          PIC  9(02).
01 P1         PIC  9(02).
01 P2         PIC  9(02).
01 CNT        PIC  9(02).
01 DST        PIC  9(05).
01 RT1        PIC  9(03)V9(03).
01 RT2        REDEFINES RT1.
   03 RT2-1   PIC  9(03).
   03 RT2-2   PIC  9(03).
01 OUT-CNT    PIC  Z9.
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO N D.
*>      
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    ACCEPT INP
    MOVE 1 TO P1
    PERFORM VARYING J FROM 1 BY 1 UNTIL J > D
      PERFORM VARYING P2 FROM P1 BY 1 
                UNTIL INP(P2:1) = ' '
      END-PERFORM   
      MOVE INP(P1:P2 - P1) TO X(I J)
      COMPUTE P1 = P2 + 1
    END-PERFORM
  END-PERFORM.
*>
  MOVE 0 TO CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I >= N
    COMPUTE K = I + 1
    PERFORM VARYING K FROM K BY 1 UNTIL K > N
      MOVE 0 TO DST
      PERFORM VARYING J FROM 1 BY 1 UNTIL J > D
        COMPUTE DST = DST + (X(I, J) - X(K, J)) ** 2
      END-PERFORM 
      COMPUTE RT1 = DST ** 0.5
      IF (RT2-2 = 0)
        ADD 1 TO CNT
      END-IF
    END-PERFORM  
  END-PERFORM.
*>
  MOVE CNT TO OUT-CNT.
  DISPLAY OUT-CNT.
*>
  STOP RUN.
