It's an interesting -- if irritating -- phenomenon. You're at a party, someone makes a witty joke at your expense, and it's only later that you think of the perfect comeback. "If only I had come up with it sooner!" you think, replaying the scene in your mind and creating an alternate reality of how the rest of the night would have turned out. (Remember George Costanza's "the jerk store called, and they're running out of you!")
Well, the French have a term for this: L'esprit de l'escalier or "staircase wit." The philosopher Denis Diderot came up with it after an unfortunate dinner. From Wikipedia:
"During a dinner at the home of statesman Jacques Necker, a remark was made to Diderot which left him speechless at the time, because, he explains, "l’homme sensible, comme moi, tout entier à ce qu’on lui objecte, perd la tête et ne se retrouve qu’au bas de l’escalier" ("a sensitive man, such as myself, overwhelmed by the argument levelled against him, becomes confused and can only think clearly again [when he reaches] the bottom of the stairs"). In this case, “the bottom of the stairs” refers to the architecture of the kind of hôtel particulier or mansion to which Diderot had been invited."