Add third version

Take into account invalid solutions