Source: https://theory.stanford.edu/~trevisan/cs172-07/solutions/sol1.pdf