you can use std::set instead of deque to store codes and check if there is a good password on the fly.