m@main=id%1>>m f%n=getLine>>=r where r""=putStrLn$g$f[0..n];r s=(>>= \x->f[x|s#2==x`mod`s#4])%lcm(s#4)n;g(a:_)=shows a" + "++shows n"k";g[]="no solutions" a#b=read$words(init a)!!b
Note that non-ascii characters in the above source code will be escaped (such as \x9f).