The speed seems to be unchanged from what I can see compared to the one used on the site now but it is shorter and simpler I think. import sys def main(): nl = nw = nc = 0 for line in sys.stdin: nl += 1 nc += len(line) nw += len(line.split()) print "%d %d %d" % (nl, nw, nc) main()