#!/usr/bin/ruby N, X = gets.split.map(&:to_i) a = gets.split.map(&:to_i) hash = {} a.each do |a| hash[a] ||= 0 hash[a] += 1 end count = 0 i = 0 while i < a.length do num1 = a[i] num2 = X - num1 if num1 == num2 if hash[num2] >= 2 count += hash[num]-1 elsif hash[num2] >= 1 count += hash[num2] end else if hash[num2] count += hash[num2] end end i += 1 end puts count