Hard! use deque and map.