IDENTIFICATION DIVISION.
PROGRAM-ID. 143B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP   PIC X(2000).
01 N     PIC 9(2).
01 D-TBL.
   03 D  PIC 9(3) OCCURS 50. 
01 I     PIC 9(2).
01 J     PIC 9(2).
01 P1    PIC 9(4).
01 P2    PIC 9(4).
01 GK    PIC 9(6).
01 OUT   PIC ZZZZZ9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
*>
  ACCEPT INP.
  MOVE 1 TO P1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
    PERFORM VARYING P2 FROM P1 BY 1 UNTIL INP(P2:1) = ' '
    END-PERFORM
*> 
    MOVE INP(P1:P2 - P1) TO D(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  MOVE 0 TO GK.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I >= N
    COMPUTE J = I + 1
    PERFORM VARYING J FROM J BY 1 UNTIL J > N
      COMPUTE GK = GK + D(I) * D(J)
    END-PERFORM
  END-PERFORM.
*>
  MOVE GK TO OUT.
  DISPLAY OUT.
  STOP RUN.
