n, x = gets.split.map(&:to_i) a = gets.split.map(&:to_i) table = a.group_by(&:itself).map { |k,v| [k,v.size] }.to_h puts table.each_key.inject(0) { |acc,k| acc + table[k] * table[x - k] }