IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 N          PIC 9(10).
01 num        PIC 9(10).
01 qt         PIC 9(10).
01 rm         PIC 9(10).
01 ans        PIC 9(10).
01 zs         PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT N.
  DIVIDE N BY 1000 GIVING qt REMAINDER rm.
  COMPUTE num = 1000 - rm.
  DIVIDE num BY 1000 GIVING qt REMAINDER ans.
  MOVE ans TO zs.
  DISPLAY FUNCTION TRIM(zs).
  STOP RUN.
