improve file reading with less memory usage

"import fileinput" to read file without loading into memory.