http://www.cs.helsinki.fi/courses/582362/2013/k/k/1