IN A
IN B
MOV G 0
MOV H 1

; --- QUERY LOOP ---
CMP B G
JNZ 130
SUB B H
IN C
IN D
IN E
CMP C H
JZ 79

; --- QUERY TYPE 1 ---
IN F
MOV C 175
CMP D E
JZ 7

; --- CHECK FOR FAST BLOCK STEP ---
MOV A D
SUB A H
DIV A C
MUL A C
ADD A H
CMP D A
JZ 62
ADD A C
SUB A H
CMP A E
JZ 62

; --- FAST BLOCK STEP ---
MOV A D
SUB A H
DIV A C
MOV C 200000
ADD C A
LOAD C A
ADD A F
STORE C A
MOV A D
SUB A H
MOV C 175
DIV A C
MOV C 100000
ADD C A
LOAD C G
MOV A 175
MUL A F
ADD A G
STORE C A
MOV G 0
MOV C 175
ADD D C
CMP H G
JZ 21

; --- SINGLE ELEMENT STEP ---
LOAD D A
ADD A F
STORE D A
MOV A D
SUB A H
MOV C 175
DIV A C
MOV C 100000
ADD C A
LOAD C A
ADD A F
STORE C A
ADD D H
CMP H G
JZ 19

; --- QUERY TYPE 2 ---
MOV F 0
MOV C 175
CMP D E
JZ 126

; --- CHECK FOR FAST BLOCK STEP ---
MOV A D
SUB A H
DIV A C
MUL A C
ADD A H
CMP D A
JZ 111
ADD A C
SUB A H
CMP A E
JZ 111

; --- FAST BLOCK STEP ---
MOV A D
SUB A H
DIV A C
MOV C 100000
ADD C A
LOAD C A
ADD F A
MOV C 175
ADD D C
CMP H G
JZ 81

; --- SINGLE ELEMENT STEP ---
LOAD D A
ADD F A
MOV A D
SUB A H
MOV C 175
DIV A C
MOV C 200000
ADD C A
LOAD C A
ADD F A
ADD D H
CMP H G
JZ 81

; --- OUTPUT RESULT ---
OUT F
CMP H G
JZ 7

RETURN