wit

Wit is brainpower or mental ability, or the person who possesses such ability, especially when it's used humorously.

When we are scared out of our wits, we — figuratively, anyway — lose for a moment our mental faculties. When we are at our wits' end, we have run out of ideas or possible solutions to a frustrating situation. When we outwit someone, we make the smarter decision. Historical figures known for their wit include Voltaire, Oscar Wilde, and Mark Twain.