fork download
  1. #n = int(input())
  2. #a = list(map(int, input().split()))
  3. #m = int(input())
  4. #b = list(map(int, input().split()))
  5. #for i in range(m):
  6. # print(a.count(b[i]))
  7.  
  8. def binSearch(arr,v):
  9. n=len(arr)
  10. left=0
  11. right=n-1
  12. count=0
  13. if v > arr[n-1]:
  14. return 0
  15. if v < arr[0]:
  16. return 0
  17. while(True):
  18. middle=(left+right)//2
  19. if arr[middle]==v:
  20. count+=1
  21. i=middle-1
  22. while (i >= 0) and (arr[i]==v):
  23. count+=1
  24. i-=1
  25. i=middle+1
  26. while (i < n) and (arr[i]==v):
  27. count+=1
  28. i+=1
  29. return count
  30. elif middle==left | middle==right:
  31. return count
  32. elif arr[middle] > v:
  33. right=middle
  34. else:
  35. left=middle
  36.  
  37. x=binSearch([1,2,2,2,3,3,4,5,6,6,6,6],6)
  38. print(x)
  39.  
Success #stdin #stdout 0.02s 9108KB
stdin
Standard input is empty
stdout
4