#!ruby -pa k=->i{z=$F.map{|e|e.to_i%i};z.sort[1]!=z[1]&&z|[]==z} $_=k[1e4]?:INF:(1..1e3).count(&k)