MOV A 0
MOV B 0

MOV C 0
MOV D 0
MOV E 0
MOV F 0
MOV G 0

MOV H 0
MOV RES 0

IN A
IN B

CMP B H
JNZ 55
MOV H 1
SUB B H

  IN C
  IN D
  IN E
  CMP C H
  JZ 37
  JNZ 28

  IN F
  CMP D E
  JZ 50
  LOAD D G
  ADD G F
  STORE D G
  CMP C H
  JNZ 45
  
  MOV F 0
  CMP D E
  JZ 50
  LOAD D G
  ADD F G
  CMP C H
  JZ 45

  MOV H 1
  ADD D H
  JNZ 29
  JZ 37

CMP C H
JNZ 16
OUT F
JZ 16

RETURN