fork download
  1. # your code goes here
  2. n = int(input())
  3. tg = int(input())
  4. arr = list(map(int, input().split()))
  5. mp = {}
  6. ctr = 0
  7. for x in arr:
  8. r1 = tg - x
  9. r2 = -tg - x
  10. if tg == 0:
  11. ctr += mp.get(r1, 0)
  12. else:
  13. ctr += mp.get(r1, 0)
  14. ctr += mp.get(r2, 0)
  15. mp[x] = mp.get(x, 0) + 1
  16. print(ctr)
  17.  
Success #stdin #stdout 0.07s 14168KB
stdin
5
2
10 5 1 3 1
stdout
1