; Memory mappings:
; reg A - Q
; reg E - answer





IN A                                    ; cin >> N

IN A                                    ; cin >> Q

MOV RES A
JZ 45                                   ; if(Q==0) return 0
MOV C 1
SUB A C                                 ; Q--
MOV C 0

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

MOV C 1
SUB B C
MOV RES B
JZ 34                                   ; if(t==1) jmp

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

IN D
ADD E D

; unconditional jump
MOV RES 0
JZ 13





RETURN                                  ; return 0