fork download
  1. # your code goes here
  2. n=int(input())
  3. arr=list(map(int, input().split()))
  4. tg=int(input())
  5. mp={}
  6. ctr=0
  7. for x in arr:
  8. r1=x+tg
  9. r2=x-tg
  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)
Success #stdin #stdout 0.08s 14104KB
stdin
5
10 5 7 3 8
2 
stdout
3