(in-package #:cl-user) ;;------------------------------Preferences------------------------------ (eval-when (:compile-toplevel :load-toplevel :execute) #+swank (declaim (optimize (speed 3) (safety 2))) #-swank (declaim (optimize (speed 3) (safety 0) (debug 0))) #+swank (load "~/ghq/github.com/motoshira/atcoder-submission/ac-tools/act.lisp") #+swank (ql:quickload :prove) #-swank (declaim (sb-ext:muffle-conditions sb-ext:compiler-note)) #-swank (sb-ext:disable-debugger) (pushnew :inline-generic-funcion *features*)) ;;---------------------------------Body--------------------------------- (in-package #:cl-user) (declaim (inline println)) (defun println (obj &optional (stream *standard-output*)) (let ((*read-default-float-format* 'double-float)) (prog1 obj (princ obj stream) (terpri stream)))) (defun read-into (count &optional (result-type 'list) (reader #'read)) (coerce (loop :repeat count :collect (funcall reader)) result-type)) (defun main () (let* ((n (read)) (as (read-into n 'vector)) (movable (make-array n :initial-element nil)) (next (make-array n :initial-element (1- n)))) (dotimes (i (1- n)) (when (and (plusp i) (= 1 (logxor (aref as i) (aref as (1- i))))) (setf (aref movable i) t))) (loop :for i :from (- n 2) :downto 0 :do (setf (aref next i) (if (aref movable i) (aref next (1+ i)) i))) (let ((res 0)) (dotimes (i (1- n)) (when (= 1 (aref as i)) (let ((dist (aref next (1+ i)))) (incf res (- dist i))))) (println res)))) #-swank (main) #+swank (defun run () (let ((*standard-input* (make-string-input-stream (with-output-to-string (*standard-output*) (run-program (merge-pathnames "copy-or-paste" (truename "~/bin/")) '() :output *standard-output*))))) (main)))