Walks on groups, counting reducible matrices, polynomials, and surface and free group automorphisms