; alchemical reduction

(define (chem str)
  (let loop ((cs (string->list str)) (zs (list)))
    (cond ((null? cs) (reverse zs))
          ((null? zs) (loop (cdr cs) (cons (car cs) zs)))
          ((and (char-ci=? (car cs) (car zs))
                (not (char=? (car cs) (car zs))))
            (loop (cdr cs) (cdr zs)))
          (else (loop (cdr cs) (cons (car cs) zs))))))

(do ((str (read) (read))) ((eof-object? str))
  (display (length (chem str))) (newline))