require"prime" m,n,*c=$<.read.split.map &:to_i s=m/c[-1] a=[] f=->x{a[x]||=c.map{|e|x==e ?1:(x>e&&0