Problems solved in SPOJ. These are hard! arrgh!