IDENTIFICATION DIVISION.
PROGRAM-ID. HEILTOLUSUMMA. *> Virkar ekki

DATA DIVISION.
    WORKING-STORAGE SECTION.
    01 N           PIC S9(16).
    01 ANS         PIC S9(26).
    01 A           PIC S9(16).
    01 B           PIC S9(26).
    01 REM1        PIC S9(16).
    01 RES1        PIC S9(16).
    01 W           PIC X(26).

PROCEDURE DIVISION.
    ACCEPT N
    
    IF N = -1
       DISPLAY 0
       STOP RUN
    END-IF
    
    IF N > 1
       ADD 1 TO N GIVING A
       MULTIPLY N BY A GIVING B
       DIVIDE B BY 2 GIVING ANS REMAINDER REM1
    ELSE
       MULTIPLY N BY -1 GIVING RES1
       ADD 1 TO RES1 GIVING A   
       MULTIPLY RES1 BY A GIVING B
       DIVIDE B BY 2 GIVING ANS REMAINDER REM1
       MULTIPLY ANS BY -1 GIVING ANS
       ADD 1 TO ANS GIVING ANS
       *> COMPUTE ANS = (-(-N*(-N+1)/2)+1)
    END-IF
    
    
    DISPLAY FUNCTION TRIM(ANS)
STOP RUN.
