GX,GY,K=gets.split.map &:to_i a=K.times.map{ x,y,n=gets.split.map(&:to_i) (1..n).map{|i|[x*i,y*i,i,i]} } F=->a,i,v,r{ if i+1