## [Khẩu trang](https://lqdoj.edu.vn/problem/mask)
```py=
# tìm kiếp nhị phân
def tknp(arr, x):
t, p = 0, len(arr)
while t < p:
g = (t + p) // 2
if arr[g] < x:
t = g + 1
else:
p = g
return t
n = int(input())
a = list(map(int,input().split()))
c = sorted(a) # sắp xếp bé -> lớn
q = int(input())
for i in range(q):
m = int(input())
print(tknp(c, m))
```
- đếm trong a xem có bao nhiêu hộp khẩu trang có giá bé hơn m
## [Tìm số trong mảng](https://lqdoj.edu.vn/problem/tknp01)
```py=
# tìm kiếp nhị phân
def tknp(a, x):
t, p = 0, len(a)
while t <= p:
g = (t + p) // 2
if a[g] == x:
return "YES"
elif a[g] < x:
t = g + 1
else :
p = g - 1
return "NO"
n , k = map(int,input().split())
a = list(map(int,input().split()))
x = list(map(int,input().split()))
for i in x :
print(tknp(a,i))
```
- Kiểm tra x có trong mảng a hay không
## [Nhỏ hơn](https://lqdoj.edu.vn/problem/lessthan)
```py=
def tknp(arr,x):
t,p = 0,len(arr)
while t < p :
g = (t+p)//2
if arr[g] < x :
t = g + 1
else :
p = g
return t
n = int(input())
a = list(map(int,input().split()))
c = sorted(a)
for i in a :
print(tknp(c,i),end=" ")
```
- đếm trong mảng a có bao nhiêu phần tử bé hơn a[i]