IDENTIFICATION DIVISION.
PROGRAM-ID. 175B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC  X(1100).
01 N          PIC  9(03).
01 P1         PIC  9(04) COMP.
01 P2         PIC  9(04) COMP.
01 I          PIC  9(04) COMP.
01 J          PIC  9(04) COMP.
01 K          PIC  9(04) COMP.
01 TBL1.
   03 L1      PIC  9(10) OCCURS 101.
01 TBL2.
   03 L2      PIC  9(10) OCCURS 100.
   03 K2      PIC  9(03) OCCURS 100.
01 L-C        PIC  9(03) COMP.
01 CNT        PIC  9(06) COMP.
01 OUT        PIC  Z(5)9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
  ACCEPT INP.
*>       
  MOVE ZERO TO TBL1 TBL2.
  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 L1(I)
    COMPUTE P1 = P2 + 1
  END-PERFORM.
*>
  SORT L1 DESCENDING KEY L1.
*>
  MOVE 1     TO L-C.
  MOVE L1(1) TO L2(L-C)
  MOVE 1     TO K2(L-C)
  PERFORM VARYING I FROM 1 BY 1 UNTIL I >= N
    IF (L1(I + 1) < L1(I)) AND (L1(I + 1) > 0)
      ADD  1         TO L-C
      MOVE L1(I + 1) TO L2(L-C)
      MOVE 1         TO K2(L-C)
    ELSE
      ADD  1         TO K2(L-C)
    END-IF
  END-PERFORM.
*>
  MOVE 0 TO CNT.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > L-C + 2
    COMPUTE J = I + 1
    PERFORM VARYING J FROM J BY 1 UNTIL J > L-C + 1
      COMPUTE K = J + 1                        
      PERFORM VARYING K FROM K BY 1 UNTIL K > L-C
        IF (L2(I) + L2(J) > L2(K)) AND
           (L2(J) + L2(K) > L2(I)) AND
           (L2(K) + L2(I) > L2(J)) 
          COMPUTE CNT = CNT + K2(I) * K2(J) * K2(K)
        END-IF
      END-PERFORM
    END-PERFORM
  END-PERFORM.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
