I've noticed an influx of C# coders around here. I don't use the language much anymore for the more difficult problems because the I/O was so slow. The most difficult part to get around was that the input wasn't always laid out 100% as the problem description said. I wrote this input method to ease the pain of users going through this.

P.nextToken() will return the next contiguous string from the input. One thing that I will note, if you must read until EOF, then the refresh method is going to be the one generating an IOException.

To get faster times, I leave that to you, but this method is not what I have used for my faster times.

Good luck and have fun.

using System;
using System.IO;
class SimpleIOTemplate
{
        class TokenParser
        {
                private int mx, idx; 
                private string[] s;
                private TextReader din;
                public TokenParser(TextReader inp)
                {
                        din = inp;
                        idx = 0;
                        mx = 0;
                }
                private void refresh()
                {
                        s = din.ReadLine().Split(' ');
                        idx = 0;
                        mx = s.Length;
                }
                private void cueUp()
                {
                        while(idx == mx)
                                refresh();
                        while(s[idx]=="")
                        {
                                idx++;
                                while(idx==mx)
                                        refresh();
                        }       
                }
                public string nextToken()
                {
                        cueUp();
                        return s[idx++];
                }
        }
        static void Main()
        {
                TokenParser P = new TokenParser(Console.In);
        }
}