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