stdin read is now done using scanf; this improved the performance