; Memory mappings:
; 1..N - array
; reg A - Q





IN A                                    ; cin >> N

IN A                                    ; cin >> Q

MOV RES A
JZ 64                                   ; if(Q==0) return 0
MOV E 1
SUB A E                                 ; Q--
MOV E 0

IN B                                    ; cin >> t
IN C                                    ; cin >> l
IN D                                    ; cin >> r

MOV E 1
SUB B E
MOV E 0                                 ; E will store our result
MOV RES B
JZ 46                                   ; if(t==1) jmp

; start for
CMP C D
JZ 39                                   ; if l>r print and continue
LOAD C B                                ; t = m[l]
ADD E B
MOV RES 1                               ; res is temporary here
ADD C RES
; unconditional jump - back to for
JNZ 29

; print answer
OUT E
; unconditional jump
MOV RES 0
JZ 13


; add query
IN E                                    ; cin >> x

; start for
CMP C D
JZ 13                                   ; if l>r go to next query
LOAD C B                                ; t = m[l]
ADD B E                                 ; t += x
STORE C B                               ; m[l] = t
MOV RES 1                               ; res is temporary here
ADD C RES
; unconditional jump - back to for
JNZ 49





RETURN                                  ; return 0