Mathematica solution using $PreRead input preprocessing