IDENTIFICATION DIVISION.
PROGRAM-ID. A-BEGINNER.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP     PIC X(401).
01 IN-DATA.
   03 DT-X1 PIC X(10).
   03 DT-X2 PIC X(10).
01 IN-LEN.
   03 DT-L1 PIC 9(2).
   03 DT-L2 PIC 9(2).
01 IN-N     PIC 9(3).
01 IN-X-ALL.
   03 IN-X     PIC 9(3) OCCURS 100.
01 I        PIC 9(3).
01 P1       PIC 9(3).
01 P2       PIC 9(3).
01 XP       PIC 9(5).
01 AVG      PIC 9(3).
01 X-P2     PIC 9(7).
01 OUT-P    PIC ZZZZZZ9.

PROCEDURE DIVISION.
MAIN-001.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO DT-X1 COUNT IN DT-L1.
  MOVE DT-X1(1:DT-L1) TO IN-N.

  ACCEPT INP.
  MOVE 0 TO I XP.
  MOVE 1 TO P1.
  PERFORM UNTIL I >= IN-N
    MOVE P1 TO P2
    PERFORM UNTIL INP(P1:1) < '0' OR INP(P1:1) > '9'
      ADD 1 TO P1
    END-PERFORM

    ADD 1 TO I
    MOVE INP(P2:P1 - P2) TO IN-X(I)
    ADD  IN-X(I)         TO XP
    ADD 1 TO P1
  END-PERFORM.

  COMPUTE AVG = XP / IN-N + 0.5.

  MOVE 0 TO X-P2.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > IN-N
    COMPUTE X-P2 = X-P2 + (IN-X(I) - AVG) ** 2
  END-PERFORM.
  MOVE X-P2 TO OUT-P
  DISPLAY OUT-P.

MAIN-EXIT.
  STOP RUN.
