# Here your code ! MAX = 20000 CELL = 40 SEG = MAX.div(CELL) + 3 ZONE = SEG.times.map { SEG.times.map { [] } } n = gets.to_i coins = n.times.map { gets.split.map(&:to_i) } puts coins.inject(0) {|s,c| cx, cy = c.map {|v| v / CELL + 1} nears = [cx - 1, cx, cx + 1].product([cy - 1, cy, cy + 1]) intersect = nears.all? do |dx,dy| begin ZONE[dx][dy].empty? || ZONE[dx][dy].all? { |v| 2.times.inject(0) {|q,i| q + (c[i] - v[i]) ** 2} >= 400 } rescue p [dx,dy] end end unless intersect s else ZONE[cx][cy].push(c) s+1 end }