My solution for 4 was quite efficient in design (and very simple). I was able to be very inefficient in the rough implementation (being lazy and copying arrays, reading the entire input file at once and breaking it up into lines in memory) and still, using JS, solve the large set in only a few milliseconds.
That should probably be a few orders of magnitude higher to realistically make the time constraint remotely difficult.
This was a fun problem to think about, though. Naomi is such a cheater.