use deque.remove() instead of deque.poll()
use HashMap instead of slow LinkedHashMap