Inspired by this post.

Answers are here.