def ascan; gets.split.map(&:to_i); end n,X = ascan A = ascan.sort cc = [] aa = [] A.each do |a| if aa.empty? || aa[-1] != a cc << 1 aa << a else cc[-1] += 1 end end N = aa.size left = 0 right = N-1 ans = 0 while left < right if aa[left] + aa[right] > X right -= 1 elsif aa[left] + aa[right] < X left += 1 else ans += cc[left]*cc[right] right -= 1 end end ans *= 2 aa.each_with_index do |a,i| if a*2 == X ans += cc[i]*cc[i] end end p ans