fork download
  1. def main(arr,k):
  2.  
  3. anchor=0
  4. x=0
  5. y=0
  6. ans=0
  7.  
  8. for ele in arr:
  9. if ele < k:
  10. if anchor==1:
  11. ans+=(x+y+1+x*y)
  12. anchor=0
  13. x=0
  14. y=0
  15. else:
  16. if ele==k:
  17. if anchor==1:
  18. ans+=(x+y+1+x*y)
  19. x=x+1+y
  20. y=0
  21. else:
  22. anchor=1
  23. else:
  24. if anchor==0:
  25. x+=1
  26. else:
  27. y+=1
  28.  
  29.  
  30. if anchor==1:
  31. ans+=(x+y+1+x*y)
  32.  
  33. return ans
  34.  
Success #stdin #stdout 0.1s 14104KB
stdin
Standard input is empty
stdout
Standard output is empty