IDENTIFICATION DIVISION.
PROGRAM-ID. 136B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 N    PIC 9(6).
01 I    PIC 9(1).
01 KSU  PIC 9(6).
01 OUT  PIC ZZZZ9.
*>
PROCEDURE DIVISION.
  ACCEPT N.
  MOVE 0 TO KSU.
  PERFORM VARYING I FROM 1 BY 2 UNTIL (10 ** (I - 1) > N)
    IF (N >= 10 ** I) 
      COMPUTE KSU = KSU + (10 ** I) - (10 ** (I - 1))
    ELSE
      COMPUTE KSU = KSU + N - (10 ** (I - 1))  + 1
    END-IF
  END-PERFORM.
*>
  MOVE KSU TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
*>
  STOP RUN.
