Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to x_{i} coins.

Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent m_{i} coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".


-----Input-----

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink.

The second line contains n integers x_{i} (1 ≤ x_{i} ≤ 100 000) — prices of the bottles of the drink in the i-th shop.

The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink.

Then follow q lines each containing one integer m_{i} (1 ≤ m_{i} ≤ 10^9) — the number of coins Vasiliy can spent on the i-th day.


-----Output-----

Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day.


-----Example-----
Input
5
3 10 8 6 11
4
1
10
3
11

Output
0
4
1
5



-----Note-----

On the first day, Vasiliy won't be able to buy a drink in any of the shops.

On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.

On the third day, Vasiliy can buy a drink only in the shop number 1.

Finally, on the last day Vasiliy can buy a drink in any shop.

Source: codeforces | Difficulty: EASY
Tags: Dynamic programming

Sorting

Implementation


Solutions:
from bisect import bisect
n = int(input())
prices = list(map(int, input().split()))
prices.sort()
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
for i in range(q):
	print(bisect(prices, m[i]))


n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	qi = int(input())
	l = -1
	r = n
	while r - l > 1:
		m = (r + l) // 2
		if x[m] <= qi:
			l = m
		else:
			r = m
	print(l + 1)


def search_bin(A, n, key):
	left = -1
	right = n
	while right > left + 1:
		middle = (left + right) // 2
		if A[middle] > key:
			right = middle
		else:
			left = middle
	return left
n = int(input())
mas = input().split()
for i in range(n):
	mas[i] = int(mas[i])
mas.sort()
d = int(input())
res = []
for i in range(d):
	value = int(input())
	summ = search_bin(mas, n, value) + 1
	res.append(summ)
for i in range(d):
	print(res[i])


from sys import stdin

def main():
	n = int(stdin.readline().strip())
	x = stdin_get_ints_list_from_line()
	q = int(stdin.readline().strip())
	x.sort()
	for _ in range(q):
		m = int(stdin.readline().strip())
		print(find_nearest_left(x, m))

def find_nearest_left(array, value):
	left = 0
	right = len(array) - 1
	if value < array[0]:
		return 0
	elif value >= array[len(array) - 1]:
		return len(array)
	middle = int((left + right) / 2)
	i = 0
	while True:
		if array[middle] <= value < array[middle + 1]:
			break
		if array[middle] > value:
			right = middle
		elif array[middle] <= value:
			left = middle
		middle = int((left + right) / 2)
		i += 1
	return middle + 1

def stdin_get_ints_from_line():
	return (int(x) for x in stdin.readline().strip().split(' '))

def stdin_get_ints_list_from_line():
	return list((int(x) for x in stdin.readline().strip().split(' ')))

def stdin_get_string_from_line():
	return stdin.readline().strip()
main()


n = int(input())
data = list(map(int, input().split()))
M = max(data)
count = [0] * (M + 1)
for i in data:
	count[i] += 1
nc = [0] * (M + 1)
for k in range(1, M + 1):
	nc[k] = nc[k - 1] + count[k]
for j in range(int(input())):
	m = int(input())
	if m >= M:
		print(nc[-1])
	else:
		print(nc[m])


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest, nsmallest, _heapify_max, _heapreplace_max
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as c
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
arr.sort()
for _ in range(int(data())):
	n = int(data())
	out(br(arr, n))


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l = szzz()
for _ in range(int(z())):
	print(bs(l, int(z())))


def get_ind(a, k):
	l = -1
	r = len(a)
	while l + 1 < r:
		m = (l + r) // 2
		if k < a[m]:
			r = m
		else:
			l = m
	if a[l] <= k:
		return r
	return 0
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
for _ in range(q):
	k = int(input())
	print(get_ind(a, k))


import bisect
f = lambda : map(int, input().split())
n = int(input())
x = list(f())
x.sort()
m = int(input())
print('\n'.join((str(bisect.bisect(x, int(input()))) for _ in range(m))))


n = int(input())
x = [int(i) for i in input().split()]
q = int(input())
x.sort()
for i in range(q):
	k = int(input())
	l = -1
	r = n
	while r - l > 1:
		middle = l + (r - l) // 2
		if x[middle] <= k:
			l = middle
		else:
			r = middle
	print(l + 1)


import sys
import bisect

def main():
	n = int(sys.stdin.readline())
	shops_list = []
	shops = [bisect.insort_left(shops_list, int(x)) for x in sys.stdin.readline().split()]
	q = int(sys.stdin.readline())
	for _ in range(q):
		money = int(sys.stdin.readline())
		sys.stdout.write(f'{bisect.bisect_right(shops_list, money)}\n')
main()


from bisect import *
input()
shops = list(map(int, input().split()))
shops.sort()
q = int(input())

def bs(a, v):
	l = 0
	h = len(a) - 1
	while l <= h:
		mid = (l + h) // 2
		if a[mid] > v:
			h = mid - 1
		else:
			l = mid + 1
	if l > len(a) or h < 0:
		return -1
	return h
for i in range(q):
	v = int(input())
	c = bisect_right(shops, v)
	print(c)


import bisect
n = int(input())
prices = list(map(int, input().split()))
day = int(input())
prices.sort()
for _ in range(day):
	afford = int(input())
	print(bisect.bisect_right(prices, afford))


def lower_bound(a, n):
	lo = 0
	hi = len(a) - 1
	while hi > lo:
		mid = (lo + hi) // 2
		if a[mid] > n:
			hi = mid
		else:
			lo = mid + 1
	if a[lo] == n:
		return lo
	return lo - 1
n = int(input())
a = list(map(int, input().split()))
m = int(input())
b = []
a.sort()
for i in range(m):
	b.append(int(input()))
for i in range(len(b)):
	if a[len(a) - 1] <= b[i]:
		print(len(a))
	elif a[0] > b[i]:
		print(0)
	else:
		print(1 + lower_bound(a, b[i]))


from bisect import bisect_left, bisect_right
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = int(input())
for i in range(m):
	x = int(input())
	print(bisect_right(a, x))


import bisect
shopsVal = int(input())
price = list(map(int, input().split()))
price.sort()
days = int(input())
for k in range(0, days):
	res = 0
	money = int(input())
	print(bisect.bisect_right(price, money))


def findnum(x, value):
	first = 0
	last = len(x)
	while first < last:
		mid = (first + last) // 2
		if x[mid] > value:
			last = mid
		else:
			first = mid + 1
	return first
n = int(input())
x = sorted(map(int, input().split()))
k = int(input())
for i in range(k):
	a = int(input())
	t = findnum(x, a)
	print(t)


import bisect
numShops = input()
bottlesArray = list(map(int, input().split()))
bottlesArray.sort()
numDays = int(input())
for i in range(0, numDays):
	temp = int(input())
	print(bisect.bisect_right(bottlesArray, temp))


from itertools import accumulate
n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for _ in range(q):
	m.append(int(input()))
mx = max(x)
arr = [0 for _ in range(mx + 1)]
for e in x:
	arr[e] += 1
arr = list(accumulate(arr))
for a in m:
	if a > mx:
		print(n)
	else:
		print(arr[a])


n = int(input())
X = tuple(sorted(map(int, input().split())))
Qty = []
current_qty = 0
index_x = 0
for i in range(100001):
	if index_x < n and i == X[index_x]:
		number = 0
		while index_x + number < n and X[index_x + number] == i:
			number += 1
		current_qty += number
		index_x += number
	Qty.append(current_qty)
result = ''
for i in range(int(input())):
	m = int(input())
	if m > 100000:
		result += str(Qty[100000])
	else:
		result += str(Qty[m])
	result += '\n'
print(result)


import math

def binarySearchLastIndex(arr, key, left, right):
	checking_index = 0
	while left < right:
		checking_index = (right + left) // 2
		if arr[checking_index] == key:
			while checking_index + 1 < right and arr[checking_index + 1] == key:
				checking_index += 1
			break
		elif arr[checking_index] > key:
			right = checking_index
		else:
			left = checking_index + 1
	while checking_index > -1 and arr[checking_index] > key:
		checking_index -= 1
	return checking_index

def binarySearchCounts(prices, available_coins):
	results = {}
	last_index = len(prices) - 1
	start_index = 0
	remember = 0
	for i in range(len(available_coins)):
		available = available_coins[i]
		if available < prices[start_index]:
			results[available_coins[i]] = remember
			continue
		elif available >= prices[last_index]:
			while i < len(available_coins):
				results[available_coins[i]] = last_index + 1
				i += 1
			return results
		index = binarySearchLastIndex(prices, available, start_index, last_index)
		results[available] = index + 1
		remember = index + 1
		start_index = index
	return results

def main():
	number_of_shops = int(input())
	str_prices = input().strip().split(' ')
	prices = [int(i) for i in str_prices]
	number_of_days = int(input())
	available_coins = []
	for d in range(number_of_days):
		available_coins.append(int(input()))
	prices = sorted(prices)
	check_coins = sorted(set(available_coins))
	results_map = binarySearchCounts(prices, check_coins)
	answer = []
	for available_coin in available_coins:
		answer.append(str(results_map[available_coin]))
	print('\n'.join(answer))
main()


n = int(input())
prices = list(map(int, input().strip().split()))
prices.sort()
q = int(input())
for i in range(q):
	num = int(input())
	l = -1
	r = n
	while r - l > 1:
		mid = (r + l) // 2
		if prices[mid] > num:
			r = mid
		else:
			l = mid
	print(r)


n = int(input())
x = list(map(int, input().split()))
q = int(input())
qi = [int(input()) for _ in range(q)]
x.sort()
dp = dict()
for i in qi:
	if i in dp:
		print(dp[i])
		continue
	l = 0
	r = len(x) - 1
	while l <= r:
		m = l + (r - l) // 2
		if x[m] == i:
			while m < len(x) and x[m] == i:
				m += 1
			break
		elif i < x[m]:
			r = m - 1
		else:
			l = m + 1
	else:
		m = l
	dp[i] = m
	print(m)


def buying_drink(price, money):
	maxi = price[-1]
	mini = price[0]
	if money >= maxi:
		return len(price)
	elif money < mini:
		return 0
	else:
		start = 0
		end = len(price) - 1
		while start <= end:
			midpoint = (start + end) // 2
			if price[midpoint] == money:
				if price[midpoint + 1] == money:
					start = midpoint + 1
				else:
					return midpoint + 1
			elif price[midpoint] < money:
				start = midpoint + 1
			else:
				end = midpoint - 1
		if price[midpoint] > money:
			return midpoint
		else:
			return midpoint + 1
n = int(input())
price = list(map(int, input().split()))
price = sorted(price)
q = int(input())
ans = []
for x in range(q):
	money = int(input())
	ans.append(buying_drink(price, money))
for u in ans:
	print(u)


nShops = int(input())
shops = input().split(' ')
shops = [int(i) for i in shops]
nDays = int(input())
shops.sort()
for _ in range(nDays):
	curDay = int(input())
	piv1 = 0
	piv2 = nShops - 1
	while piv1 + 1 < piv2:
		midPoint = (piv1 + piv2) // 2
		if int(shops[midPoint]) > curDay:
			piv2 = midPoint
		else:
			piv1 = midPoint
	if int(shops[piv2]) <= curDay:
		print(piv2 + 1)
	elif int(shops[piv1]) <= curDay:
		print(piv1 + 1)
	else:
		print(0)


def binarySearch(arr, x, length):
	start = 0
	end = length - 1
	while start <= end:
		mid = start + (end - start) // 2
		if x > arr[mid]:
			start = mid + 1
		elif x < arr[mid]:
			end = mid - 1
		else:
			if mid + 1 >= len(arr):
				return mid
			if arr[mid] != arr[mid + 1]:
				return mid
			start = mid + 1
	if arr[mid] > x:
		if mid == 0:
			return -1
		return mid - 1
	return mid
n = int(input())
x = sorted(map(int, input().split()))
q = int(input())
for i in range(q):
	a = int(input())
	b = binarySearch(x, a, n)
	print(b + 1)


n = int(input())
x = input().split()
for i in range(n):
	x[i] = int(x[i])
x.sort()
b = []
count = 0
for i in range(n):
	if i == 0:
		count += 1
		if i == n - 1:
			b.append([x[i], count])
	elif x[i] == x[i - 1]:
		count += 1
		if i == n - 1:
			b.append([x[i], count])
	else:
		b.append([x[i - 1], count])
		count = 1
		if i == n - 1:
			b.append([x[i], count])
a = []
count = 0
for i in range(10 ** 5 + 1):
	if len(b) > 0:
		if i == b[0][0]:
			count += b[0][1]
			b.pop(0)
	a.append(count)
q = int(input())
while q:
	m = int(input())
	if m > 10 ** 5:
		print(n)
	else:
		print(a[m])
	q -= 1


from sys import stdin
input = stdin.readline
n = int(input())
a = sorted(list(map(int, input().split())))
a = [a[0] - 1] + a + [a[-1] + 1]
q = int(input())
for _ in range(q):
	money = int(input())
	l = 0
	r = n + 2
	m = l + (r - l) // 2
	while r - l > 1:
		if a[m] > money:
			r = m
		elif a[m] <= money:
			l = m
		m = l + (r - l) // 2
	if l == 0:
		print(0)
	elif r == n + 2:
		print(n)
	else:
		print(l)


from bisect import bisect_right
isDebug = False
n = int(input())
x = [int(x) for x in input().split()]
q = int(input())
x = sorted(x)
xl = x[0]
xr = x[len(x) - 1]
print(f'x={x}') if isDebug else ''
for i in range(0, q):
	m = int(input())
	if m < xl:
		print('0')
		continue
	elif m >= xr:
		print(n)
		continue
	v = bisect_right(x, m)
	print(v)


def bs(arr, x, shops):
	l = 0
	r = shops - 1
	if x >= arr[-1]:
		return shops
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] <= x and mid < shops and (arr[mid + 1] > x):
			return mid + 1
		elif x >= arr[mid]:
			l = mid + 1
		elif x <= arr[mid]:
			r = mid - 1
	return 0
n = int(input())
shops = list(map(int, input().split()))
days = int(input())
shops.sort()
while days:
	coins = int(input())
	print(bs(shops, coins, n))
	days -= 1


n = int(input())
max_limit = 100000
prices = list(map(int, input().split()))
(price_occur, prefix) = ([0] * (max_limit + 1), [0] * (max_limit + 1))
for p in prices:
	price_occur[p] += 1
for i in range(max_limit + 1):
	prefix[i] = (0 if i == 0 else prefix[i - 1]) + price_occur[i]
q = int(input())
ans = []
for i in range(q):
	money = int(input())
	if money > max_limit:
		ans.append(n)
	else:
		ans.append(prefix[money])
print(*ans, sep='\n')


n = int(input())
a = list(map(int, input().split()))
q = int(input())
a.sort()
ans = 0

def bsl(beg, end, x, upper):
	global a
	while beg <= end:
		mid = (beg + end) // 2
		if a[mid] <= x:
			upper = mid
			beg = mid + 1
		else:
			end = mid - 1
	return upper + 1
for _ in range(q):
	qq = int(input())
	ans = bsl(0, n - 1, qq, 0) if qq >= a[0] else 0
	print(ans)


from collections import Counter, defaultdict, deque
import math
import sys
input = sys.stdin.readline
n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
q = int(input())
for i in range(q):
	m = int(input())
	left = 0
	right = n - 1
	while left <= right:
		mid = (left + right) // 2
		if arr[mid] > m:
			right = mid - 1
		else:
			left = mid + 1
	print(left)


def bs(l, r, x):
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if a[m] <= x:
			l = m + 1
		else:
			ans = m
			r = m - 1
	return ans
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
q = int(input())
for w in range(q):
	x = int(input())
	ans = bs(0, n - 1, x)
	if ans == -1:
		print(n)
	else:
		print(ans)


import os, sys, math
from _thread import start_new_thread
from bisect import bisect_right

def child(item):
	print('hello from thread number', item)

def parent(i=0):
	while input() != 'exit':
		i += 1
		start_new_thread(child, (i,))
	print('bye')

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a = sorted(a)
	q = int(input())
	for i in range(q):
		print(bisect_right(a, int(input())))
sys.exit(int(main() or 0))


def bin_poisk(a, x, n):
	l = 0
	r = n - 1
	while l + 1 < r:
		m = (l + r) // 2
		if a[m] > x:
			r = m
		else:
			l = m
	if a[r] <= x:
		return n
	elif a[l] > x:
		return 0
	else:
		return l + 1
n = int(input())
a = list(map(int, input().split()))
q = int(input())
a.sort()
for i in range(q):
	b = int(input())
	print(bin_poisk(a, b, n))


import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
for x in range(int(input())):
	print(bisect.bisect(l, int(input()), 0, n))


from bisect import bisect
x = int(input())
l = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	z = int(input())
	print(bisect(l, z))


def find_upb(data, frm, to, value):
	if frm == to:
		return frm
	if frm + 1 == to:
		if data[frm] <= value:
			return to
		else:
			return frm
	mi = (frm + to) // 2
	if data[mi] <= value:
		return find_upb(data, mi, to, value)
	else:
		return find_upb(data, frm, mi, value)
input()
data = sorted(map(int, input().split()))
for _ in range(int(input())):
	print(find_upb(data, 0, len(data), int(input())))


from bisect import bisect_right
n = int(input())
s = sorted(list(map(int, input().split())))
x = int(input())
for _ in range(x):
	a = int(input())
	print(bisect_right(s, a))


n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
ms = [int(input()) for i in range(q)]
dp = [0] * 100001
j = 0
for i in range(1, 100001):
	dp[i] = dp[i - 1]
	while j < len(x) and x[j] <= i:
		dp[i] += 1
		j += 1
for i in ms:
	print(dp[i] if i <= 100000 else dp[-1])


shops = int(input())
prices = list(map(int, input().split()))
prices.sort()
days = int(input())
print_this = []
for i in range(days):
	right = len(prices)
	left = 0
	mid = (right - left) // 2
	money = int(input())
	while left + 1 < right:
		if prices[mid] <= money:
			left = mid
		else:
			right = mid
		mid = left + (right - left) // 2
	if prices[0] <= money:
		mid = mid + 1
	print_this.append(mid)
for k in print_this:
	print(k)


from bisect import bisect_right
n = int(input())
x = list(map(int, input().split()))
x.sort()
for _ in range(int(input())):
	m = int(input())
	print(bisect_right(x, m))


def search(a, n):
	l = 0
	r = len(a) - 1
	ans = -1
	while l <= r:
		mid = l + (r - l) // 2
		if a[mid] == n:
			ans = mid
			l = mid + 1
		elif a[mid] < n:
			l = mid + 1
			ans = mid
		else:
			r = mid - 1
	return ans
n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	m = int(input())
	if m < x[0]:
		print(0)
	elif m >= x[-1]:
		print(len(x))
	else:
		print(search(x, m) + 1)


from collections import defaultdict
from bisect import bisect_left

def BinarySearch(a, x):
	i = bisect_left(a, x)
	return i
shops = int(input())
prices = [int(i) for i in input().split()[:shops]]
prices.sort()
pricesCount = {}
pricesCount = defaultdict(int)
for (index, price) in enumerate(prices):
	pricesCount[int(price)] = index
prices = list(pricesCount.keys())
days = int(input())
for day in range(days):
	money = int(input())
	index = BinarySearch(prices, money)
	if index >= len(prices):
		print(pricesCount[prices[-1]] + 1)
	elif prices[index] > money:
		while index > 0 and prices[index] > money:
			index -= 1
		if index == 0 and prices[index] > money:
			print(0)
		else:
			print(pricesCount[prices[index]] + 1)
	else:
		print(pricesCount[prices[index]] + 1)


import bisect
n = int(input())
x = sorted(map(int, input().split()))
q = int(input())
for i in range(q):
	print(bisect.bisect(x, int(input())))


from bisect import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
q = int(input())
for i in range(q):
	e = int(input())
	print(bisect(l, e))


import sys
import math

def canBuyFromDisShop(shopIndex, coinsAvailable, shops):
	if coinsAvailable >= int(shops[shopIndex]):
		return True
	else:
		return False

def binarySearch(coinsAvailable, shops):
	lo = 0
	hi = len(shops) - 1
	if not canBuyFromDisShop(lo, coinsAvailable, shops):
		return 0
	if canBuyFromDisShop(hi, coinsAvailable, shops):
		return len(shops)
	while lo + 1 < hi:
		mid = math.floor((lo + hi) / 2)
		if canBuyFromDisShop(mid, coinsAvailable, shops):
			lo = mid
		else:
			hi = mid
	return hi
n = int(sys.stdin.readline().rstrip())
shopsString = sys.stdin.readline().rstrip()
shops = shopsString.split(' ')
shops.sort(key=int)
q = int(sys.stdin.readline().rstrip())
for i in range(0, q):
	todaysNumCoins = int(sys.stdin.readline().rstrip())
	print(binarySearch(todaysNumCoins, shops))


def single():
	return input()

def multiple():
	return list(map(int, input().split()))
n = int(single())
arr = multiple()
arr.sort()
days = int(single())
d = []
res = [0] * days
for i in range(days):
	d.append([int(single()), i])
d.sort()
x = 0
for i in d:
	while 1:
		if x < n and i[0] >= arr[x]:
			x += 1
		else:
			res[i[1]] = x
			break
for i in res:
	print(i, end=' ')


n = int(input())
price = [int(i) for i in input().split()]
q = int(input())
has = [int(input()) for i in range(q)]
from bisect import bisect_right as br
from bisect import bisect_left as bl
price.sort()
for i in has:
	print(br(price, i))


def bin_search(a):
	global prices
	global n
	(l, r) = (0, n - 1)
	while l < r:
		m = (l + r + 1) // 2
		if prices[m] <= a:
			l = m
		else:
			r = m - 1
	return l
n = int(input())
prices = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	money = int(input())
	ans = bin_search(money)
	print(ans + 1 if money >= prices[0] else 0)


import bisect
n = int(input())
L = sorted(map(int, input().split()))
for i in range(int(input())):
	num = bisect.bisect(L, int(input()))
	print(num)


import sys
import bisect

def main():
	n = int(sys.stdin.readline())
	shops = list(map(int, sys.stdin.readline().split()))
	q = int(sys.stdin.readline())
	shops.sort()
	for _ in range(q):
		money = int(sys.stdin.readline())
		sys.stdout.write(f'{bisect.bisect_right(shops, money)}\n')
main()


def my_bisect_right(x, a):
	for i in range(len(x)):
		if a < x[i]:
			return i
	return len(x)

def my_bisect_right_enhanced(x, a):
	result_left = 0
	result_right = len(x)
	while result_left + 1 < result_right:
		mid = (result_right + result_left) // 2
		if a < x[mid]:
			result_right = mid
		else:
			result_left = mid
	if a < x[result_left]:
		return result_left
	else:
		return result_right
from bisect import bisect_right
str1 = '5'
str2 = '3 10 8 6 11'
str3 = '4'
str1 = input()
str2 = input()
str3 = input()
n = int(str1)
x = sorted(list(map(int, str2.split())))
q = int(str3)
y = list(map(int, '1 10 3 11'.split()))
y = list(range(q))
for i in range(q):
	y[i] = int(input())
q = 4
for m in y:
	print(my_bisect_right_enhanced(x, m))


n = int(input())
L = list(map(int, input().split()))
a = [0] * 100002
for i in L:
	a[i] += 1
for i in range(100002):
	a[i] = a[i - 1] + a[i]
m = int(input())
for i in range(m):
	tmp = int(input())
	if tmp > 100000:
		print(n)
	else:
		print(a[tmp])


from collections import deque
from math import ceil, floor, sqrt, gcd

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def si():
	return input()
n = ii()
a = li()
x = [0] * 1000005
for i in range(n):
	x[a[i]] += 1
for i in range(1, 1000005):
	x[i] += x[i - 1]
for i in range(ii()):
	n1 = ii()
	if n1 > 100000:
		print(n)
	else:
		print(x[n1])


import bisect
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
q = int(input())
for i in range(q):
	a = int(input())
	print(bisect.bisect_right(arr, a))


import bisect
line = input()
n = int(line)
line = input()
numbers = []
for word in line.split():
	numbers.append(int(word))
numbers.sort()
line = input()
questions = int(line)
answer = []
for i in range(questions):
	line = input()
	money = int(line)
	index = bisect.bisect_right(numbers, money)
	answer.append(index)
for a in answer:
	print(a)


def solve(n, d, coin):
	big = float('inf')
	small = float('-inf')
	d.sort()
	for i in coin:
		if i < d[0]:
			print(0)
		elif i >= d[-1]:
			print(len(d))
		else:
			ans = -1
			lb = 0
			hb = len(d)
			while lb < hb:
				mid = (lb + hb) // 2
				if d[mid] <= i:
					lb = mid + 1
				else:
					ans = mid
					hb = mid
			print(ans)

def main():
	n = int(input())
	d = input()
	d = [int(i) for i in d.split()]
	n2 = int(input())
	coin = []
	for i in range(n2):
		cs = int(input())
		coin.append(cs)
	ans = solve(n, d, coin)
main()


import sys
from bisect import bisect_right
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	m = int(input())
	print(bisect_right(x, m))


import math

def main():
	n_shops = int(input())
	shops = [int(item) for item in input().split(' ')]
	shops.sort()
	op = ''
	for i in range(int(input())):
		n = int(input())
		if n < shops[0]:
			op += '0' + '\n'
		elif n >= shops[len(shops) - 1]:
			op += str(len(shops)) + '\n'
		else:
			op += str(search_greater(shops, n)) + '\n'
	print(op)

def search_greater(shops, n):
	l = 0
	r = len(shops) - 1
	answer = 0
	while l <= r:
		mid = math.floor((l + r) / 2)
		if shops[mid] > n:
			answer = mid
			r = mid - 1
		else:
			l = mid + 1
	return answer
main()


def bs(rd, ele, l, r):
	if r >= l:
		mid = l + (r - l) // 2
		if rd[mid] == ele:
			return mid
		elif rd[mid] > ele:
			return bs(rd, ele, l, mid - 1)
		else:
			return bs(rd, ele, mid + 1, r)

def solve():
	x = int(input())
	lx = list(map(int, input().strip().split()))
	d = int(input())
	ld = []
	for i in range(d):
		ld.append(int(input()))
	lx.sort()
	lds = ld[:]
	lds.sort()
	rd = []
	rc = []
	j = 0
	c = 0
	for i in range(d):
		while j < x:
			if lds[i] >= lx[j]:
				c += 1
				j += 1
				continue
			else:
				break
		rc.append(c)
		rd.append(lds[i])
	for i in range(d):
		f = bs(rd, ld[i], 0, d - 1)
		print(rc[f])
solve()


import sys
n = int(input())
p = [int(n) for n in input().split()]
p.sort()

def find(p, q):
	first = 0
	last = len(p)
	while first != last:
		mid = (first + last) // 2
		if p[mid] > q:
			last = mid
		else:
			first = mid + 1
	return first
m = int(input())
for i in range(m):
	q = int(input())
	print(find(p, q))


n = int(input())
bars = sorted([int(i) for i in input().split(' ')])
currentshop = 0
days = int(input())
money = [int(input()) for i in range(days)]
dp = []
currentshop = 0
sweet = min(max(bars) + 1, max(money) + 1)
for i in range(sweet):
	while currentshop < n and i >= bars[currentshop]:
		currentshop += 1
	dp.append(currentshop)
for i in money:
	if i < sweet:
		print(dp[i])
	else:
		print(dp[sweet - 1])


def BinarySearch(arr, ele, lft, r, index):
	a = arr
	toSearch = ele
	left = lft
	right = r
	ans = 0
	while left <= right:
		mid = int(left + (right - left) / 2)
		if a[mid] < toSearch:
			left = mid + 1
		else:
			ans = a[mid]
			index = mid
			right = mid - 1
	print(index)
n = int(input())
l = sorted(list(map(int, input().strip().split(' '))))
q = int(input())
for i in range(q):
	x = int(input())
	if x >= l[-1]:
		print(n)
	else:
		BinarySearch(l, x + 1, 0, n, 0)


n = int(input())
prices = sorted(list(map(int, input().split())))
max_price = prices[-1]
bottles = [0] * (max_price + 1)
current_idx = 0
val = 0
for i in range(1, max_price):
	if i == prices[current_idx]:
		while current_idx < n and prices[current_idx] == prices[current_idx + 1]:
			current_idx += 1
			val += 1
		current_idx += 1
		val += 1
	bottles[i] = val
bottles[-1] = n
q = int(input())
for i in range(q):
	m = min(max_price, int(input()))
	print(bottles[m])


from bisect import bisect_right
from collections import Counter
maxn = int(100000.0) + 1
n = int(input())
x = [int(x) for x in input().split()]
x.sort()
c = Counter(x)
ans = [0] * maxn
for i in range(1, maxn):
	ans[i] = ans[i - 1] + (c[i] if i in c else 0)
q = int(input())
for _ in range(q):
	e = int(input())
	print(ans[e] if e < maxn else n)


import bisect
count = int(input())
prices = sorted(map(int, input().split()))
daysbuy = int(input())
for x in range(daysbuy):
	coins = int(input())
	print(bisect.bisect_right(prices, coins))


n = int(input())
a = [int(i) for i in input().split()]
a.sort()
p = [0] * 100001
for i in range(n):
	p[a[i]] += 1
for i in range(1, len(p)):
	p[i] += p[i - 1]
q = int(input())
for i in range(q):
	q1 = int(input())
	if q1 > len(p):
		print(n)
	else:
		print(p[q1])


def binarySearch(arr, l, r, x):
	while l < r:
		mid = l + (r - l) // 2
		if arr[mid] <= x:
			l = mid + 1
		else:
			r = mid
	return l
num = int(input())
shops = [int(x) for x in input().split()]
num_days = int(input())
days = []
for i in range(num_days):
	days.append(int(input()))
shops = sorted(shops)
results = []
for day in days:
	if day < shops[0]:
		results.append(0)
	else:
		results.append(binarySearch(shops, 0, len(shops), day))
for res in results:
	print(res)


I = lambda : int(input())
In = lambda : list(map(int, input().split()))
n = I()
x = sorted(In())
q = I()
m = []
for i in range(q):
	m.append(I())
x.insert(0, 0)

def query(m):
	(lo, hi) = (0, n)
	while lo < hi:
		mi = lo + hi + 1 >> 1
		if x[mi] <= m:
			lo = mi
		else:
			hi = mi - 1
	return lo
res = list(map(query, m))
print(*res)


import bisect
x = int(input())
prices = list(map(int, input().split()))
z = int(input())
score = []
prices = sorted(prices)
for i in range(z):
	day = int(input())
	score.append(bisect.bisect(prices, day))
for c in score:
	print(c)


n = int(input())
x = [int(x) for x in input().split()]
x.sort()
dp = [0] * 100005
for i in x:
	dp[i] += 1
for j in range(1, x[-1] + 1):
	dp[j] += dp[j - 1]
q = int(input())
ans = ''
for i in range(q):
	m = int(input())
	if m >= x[-1]:
		ans += str(n) + '\n'
	else:
		ans += str(dp[m]) + '\n'
print(ans)


n = int(input())
a = list(map(int, input().split()))
m = max(a)
c = 0
b = [0] * (m + 1)
for i in a:
	b[i] += 1
for i in range(1, m + 1):
	if b[i] == 0:
		b[i] = c
	else:
		c += b[i]
		b[i] = c
q = int(input())
for i in range(q):
	try:
		print(b[int(input())])
	except:
		print(b[-1])


def search(cost, shop):
	if cost >= shop[-1]:
		return len(shop)
	elif cost < shop[0]:
		return 0
	(l, r) = (0, len(shop) - 1)
	while l < r:
		mid = l + (r - l) // 2
		if shop[mid] <= cost:
			l = mid + 1
		else:
			r = mid
	return l
n = int(input())
shop = list(map(int, input().strip().split()))
days = int(input())
shop.sort()
output = []
for i in range(days):
	output.append(search(int(input()), shop))
for o in output:
	print(o)


import bisect
n = int(input())
price = list(map(int, input().split()))
price.sort()
q = int(input())
for i in range(q):
	money = int(input())
	ans = bisect.bisect_right(price, money)
	print(ans)


n = int(input())
x = list(map(int, input().split()))
x.sort()
for _ in range(int(input())):
	m = int(input())
	lo = 0
	hi = n - 1
	mid = 0
	while lo < hi:
		mid = (lo + hi) // 2
		if x[mid] > m:
			hi = mid - 1
		else:
			lo = mid + 1
	if hi < 0:
		print(0)
	else:
		print(hi + 1 if m >= x[hi] else hi)


from bisect import bisect
I = lambda : map(int, input().split())
n = int(input())
x = sorted(list(I()))
q = int(input())
for _ in range(q):
	m = int(input())
	print(bisect(x, m))


import bisect
n = int(input())
nums = list(map(int, input().split(' ')))
nums.sort()
q = int(input())
arr = []
for _ in range(q):
	arr.append(int(input()))
for x in arr:
	i = bisect.bisect_right(nums, x)
	print(i)


input()
t = sorted(map(int, input().split()))
for _ in range(int(input())):
	k = int(input())
	(l, r) = (0, len(t) - 1)
	while l + 1 < r:
		b = (l + r) // 2
		if t[b] <= k:
			l = b
		else:
			r = b
	if t[r] <= k:
		print(r + 1)
	elif t[l] <= k:
		print(l + 1)
	else:
		print(0)


from bisect import bisect_right
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
q = int(input())
for i in range(q):
	m = int(input())
	pos = bisect_right(arr, m)
	print(pos)


from bisect import bisect_right as bl
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
for _ in range(q):
	m = int(input())
	i = bl(a, m)
	print(i)


n = int(input())
x = []
x = list(map(int, input().split()))
x.sort()
q = int(input())
m = []
for i in range(q):
	p = int(input())
	m.append(p)

def binarySearch(arr, n, x):
	mid = 0
	low = 0
	high = n - 1
	nb = 0
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] > x:
			high = mid - 1
		elif arr[mid] == x:
			nb += mid - low + 1
			low = mid + 1
		else:
			low = mid + 1
			nb = mid + 1
	return nb
for i in m:
	print(binarySearch(x, n, i))


import bisect
n = int(input())
prices = list(map(int, input().rstrip().split()))
prices.sort()
days = int(input())
for _ in range(days):
	coin = int(input())
	print(bisect.bisect_right(prices, coin))


from bisect import bisect
from functools import lru_cache
from array import array
n = int(input())
a = tuple(sorted(map(int, input().split())))
q = int(input())
dp = array('L')

def solve(v):
	if v >= len(dp):
		return dp[-1]
	else:
		return dp[v]
p = 0
for (i, e) in enumerate(a):
	for j in range(p, e):
		dp.append(i)
	p = e
dp.append(len(a))
for i in range(q):
	v = int(input())
	print(solve(v))


n = int(input())
s = sorted(list(map(int, input().split())))
q = int(input())
h = []
from bisect import bisect
for j in range(q):
	x = int(input())
	print(bisect(s, x))


n = int(input())
s = [int(n) for n in input().split()]
q = int(input())
ma = max(s)
prefixSum = [0 for i in range(ma + 1)]
for num in s:
	prefixSum[num] += 1
for i in range(1, ma + 1):
	prefixSum[i] += prefixSum[i - 1]
for i in range(q):
	m = int(input())
	if m > ma:
		print(prefixSum[ma])
	else:
		print(prefixSum[m])


n = input()
arr = list(map(int, input().split()))
mx = max(arr)
dp = [0] * (mx + 1)
for i in arr:
	dp[i] += 1
for i in range(1, mx + 1):
	dp[i] += dp[i - 1]
for i in range(int(input())):
	print(dp[min(mx, int(input()))])


trash = input()
prices = [int(x) for x in input().split()]
queryCount = int(input())
queries = [0 for i in range(queryCount)]
for i in range(queryCount):
	queries[i] = int(input())
sortedPrices = sorted(prices)
dp = sortedPrices
dp.insert(0, 0)
output = ''
for query in queries:
	if query >= dp[-1]:
		output += str(len(dp) - 1) + '\n'
		continue
	left = 0
	right = len(dp) - 1
	center = (left + right) // 2
	while not (dp[center] <= query and dp[center + 1] > query):
		if dp[center] > query:
			right = center
		else:
			left = center
		center = (left + right) // 2
	output += str(center) + '\n'
print(output)


import heapq as hp
import collections
import bisect

def unpack(func=int):
	return map(func, input().split())

def l_unpack(func=int):
	return list(map(func, input().split()))

def s_unpack(func=int):
	return sorted(map(func, input().split()))

def range_n():
	return range(int(input()))

def getint():
	return int(input())

def main():
	n = getint()
	shop = s_unpack()
	for i in range_n():
		print(bisect.bisect(shop, getint()))
main()


import math
import sys, collections
MAXN = 10000001

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def get_array():
	l = list(map(int, input().split()))
	return l

def get_2_ints():
	(a, b) = map(int, input().split())
	return (a, b)

def get_3_ints():
	(a, b, c) = map(int, input().split())
	return (a, b, c)

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = list()
	while x != 1:
		ret.append(spf[x])
		x = x // spf[x]
	return ret

def getFloor(A, x):
	(left, right) = (0, len(A) - 1)
	(ind, floor) = (-1, -1)
	while left <= right:
		mid = (left + right) // 2
		if x < A[mid]:
			right = mid - 1
		else:
			floor = A[mid]
			ind = mid
			left = mid + 1
	return ind
mod = 10 ** 9 + 7

def main():
	n = int(input())
	l = get_array()
	l.sort()
	q = int(input())
	for que in range(q):
		ans = getFloor(l, int(input()))
		if ans == -1:
			print(0)
		else:
			print(ans + 1)
main()


def find_index(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if x < a[mid]:
			right = mid
		else:
			left = mid + 1
	return left
no_of_shops = int(input())
prices = [int(x) for x in input().split()]
no_of_days = int(input())
money = []
for i in range(no_of_days):
	money.append(int(input()))
prices.sort()
for i in range(no_of_days):
	print(find_index(prices, money[i]))


from bisect import bisect_right
input()
costs = sorted(map(int, input().split()))
for _ in range(int(input())):
	print(bisect_right(costs, int(input())))


n = int(input())
a = list(map(int, input().split()))
a.sort()
f = int(input())

def findpos(q):
	if q < a[0]:
		return 0
	if q >= a[-1]:
		return n
	b = 0
	e = n - 1
	while b <= e:
		mid = (b + e) // 2
		if a[mid] <= q and a[mid + 1] > q:
			return mid + 1
		elif a[mid] > q:
			e = mid - 1
		else:
			b = mid + 1
for i in range(f):
	q = int(input())
	print(findpos(q))


import bisect
n = int(input())
arr = sorted([int(x) for x in input().split()])
days = int(input())
for d in range(days):
	money = int(input())
	pos = bisect.bisect_right(arr, money)
	print(pos)


import bisect
input()
a = sorted(list(map(int, input().split())), key=int)
for i in range(int(input())):
	print(bisect.bisect(a, int(input())))


import bisect
input()
p = sorted(map(int, input().split()))
print(*(bisect.bisect_right(p, int(input())) for _ in range(int(input()))), sep='\n')


def main():
	n = int(input())
	shop = [int(i) for i in input().split()]
	days_count = int(input())
	shop.sort()
	counts = []
	for i in range(days_count):
		day_cost = int(input())
		left_bound = -1
		right_bound = n
		while right_bound > left_bound + 1:
			separator = (right_bound + left_bound) // 2
			if day_cost < shop[separator]:
				right_bound = separator
			else:
				left_bound = separator
		counts.append(str(left_bound + 1))
	print('\n'.join(counts))
main()


import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
q = int(input())
for j in range(q):
	m = int(input())
	print(bisect.bisect_right(l, m))


import bisect
n = int(input())
x = list(map(int, input().split()))
q = int(input())
x.sort()
for i in range(q):
	f = int(input())
	print(bisect.bisect(x, f))


import bisect
n = int(input())
m = sorted(list(map(int, input().split())))
a = int(input())
b = []
count = 0
for i in range(a):
	i = int(input())
	b.append(i)
for j in b:
	print(bisect.bisect(m, j))


n = input()
x = str(input())
x = x.split()
for i in range(0, len(x)):
	x[i] = int(x[i])
x.append(0)
x.sort()
q = int(input())
for i in range(0, q):
	m = int(input())
	low = 0
	high = len(x)
	while low + 1 < high:
		mid = (low + high) // 2
		if m < x[mid]:
			high = mid
		else:
			low = mid
	print(low)


def find(target):
	if target < prices[0]:
		return 0
	if target >= prices[-1]:
		return n
	(low, high) = (0, n)
	while low < high:
		mid = (low + high) // 2
		if prices[mid] > target:
			high = mid
		else:
			low = mid + 1
	return low
n = int(input())
prices = list(map(int, input().split()))
prices.sort()
q = int(input())
for i in range(q):
	x = int(input())
	print(find(x))


from bisect import bisect_right
import sys

def get_drinks():
	data = [line.rstrip().split() for line in sys.stdin.readlines()]
	data = [[int(x) for x in row] for row in data]
	num_shops = data[0]
	shop_costs = data[1]
	sorted_costs = sorted(shop_costs)
	num_days = data[2][0]
	for i in range(num_days):
		coins = data[i + 3][0]
		print(bisect_right(sorted_costs, coins))
get_drinks()


shops = int(input())
prices = sorted(list(map(int, input().split(' '))))
days = int(input())
money_each_day = []
for day in range(days):
	money_each_day.append(int(input()))

def binary_search(item_list, item):
	first = 0
	last = len(item_list) - 1
	found = False
	if item >= item_list[-1]:
		return print(len(item_list))
	if item < item_list[0]:
		return print(0)
	while first <= last and (not found):
		mid = (first + last) // 2
		if item_list[mid + 1] > item >= item_list[mid]:
			found = True
		elif item < item_list[mid]:
			last = mid - 1
		else:
			first = mid + 1
	return print(mid + 1)
for item in money_each_day:
	binary_search(prices, item)


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_left
from bisect import bisect_right

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	a.sort()
	m = int(input())
	for _ in range(m):
		print(bisect_right(a, int(input())))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from bisect import bisect_right
n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
ans = list()
for i in range(q):
	m = int(input())
	ans.append(bisect_right(x, m))
print('\n'.join(map(str, ans)))


from itertools import accumulate
n = int(input())
x = [int(i) for i in input().split()]
cost_count = [0] * 100001
for i in x:
	cost_count[i] += 1
cost_count_prefix_sum = list(accumulate(cost_count))
for _ in range(int(input())):
	mi = int(input())
	if mi > 10 ** 5:
		print(n)
	else:
		print(cost_count_prefix_sum[mi])


def binarySearch(start, end, arr, x):
	mid = (start + end) // 2
	if mid >= len(arr):
		return len(arr) - 1
	elif start > end or arr[mid] == x:
		return mid
	elif arr[mid] > x:
		return binarySearch(start, mid - 1, arr, x)
	else:
		return binarySearch(mid + 1, end, arr, x)
n = int(input())
shops = [0]
shops.extend([int(x) for x in input().split()])
shops.sort()
prices = []
(prev, i) = (-1, 0)
while i < len(shops):
	if shops[i] > prev:
		prices.append(shops[i])
		prev = shops[i]
	i += 1
possible = []
prev = 0
for i in range(1, len(shops) + 1):
	if i == len(shops):
		possible.append(i - 1)
	elif shops[i] > prev:
		possible.append(i - 1)
		prev = shops[i]
days = int(input())
h_i = 0
for d in range(days):
	money = int(input())
	if money > prices[h_i]:
		h_i = binarySearch(h_i, len(prices), prices, money)
	elif money < prices[h_i]:
		h_i = binarySearch(0, h_i, prices, money)
	print(possible[h_i])


n = int(input())
price = input()
price = price.split()
price = list(map(int, price))
price.sort()
table = []
index = 0
count = 0
while 1:
	if index < n and price[index] == count:
		index += 1
		continue
	count += 1
	table.append(index)
	if index == n:
		break
q = int(input())
for i in range(q):
	m = int(input())
	if m > price[n - 1]:
		print(n)
	else:
		print(table[m])


from sys import stdin
from bisect import bisect_right

def ler():
	for line in stdin:
		yield line

def solve(s):
	n = int(next(s))
	lista = [int(x) for x in next(s).split(' ')]
	lista.sort()
	q = int(next(s))
	for i in range(q):
		m = int(next(s))
		print(bisect_right(lista, m))
s = ler()
solve(s)


import sys
input = lambda : sys.stdin.readline().strip()
inp = lambda : list(map(int, input().split()))
n = int(input())
a = inp()
a.sort()
for _ in range(int(input())):
	b = int(input())
	low = 0
	high = n - 1
	while low <= high:
		mid = (low + high) // 2
		if a[mid] <= b:
			low = mid + 1
		else:
			high = mid - 1
	print(low)


import bisect
n = int(input())
x = [int(s) for s in input().split(' ')]
x.sort()
q = int(input())
for i in range(q):
	mi = int(input())
	print(bisect.bisect_right(x, mi))


import bisect
import sys
from collections import deque
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
array = [0] * 1001

class BinarySearch:

	def __init__(self, array, sort_key=None):
		self.array = sorted(array, key=sort_key)

	def upper_bound(self, key):
		(l, r) = (0, len(self.array) - 1)
		while l < r:
			mid = r - (r - l) // 2
			if self.array[mid] <= key:
				l = mid
			else:
				r = mid - 1
		return l if self.array[l] == key else -1
a = input()
shops = list(map(int, sys.stdin.readline().split()))
drinks = []
q = int(input())
for i in range(q):
	value = int(input())
	drinks.append(value)
	shops.append(value)
binary_search_shops = BinarySearch(shops)
binary_search_drinks = BinarySearch(drinks)
for key in drinks:
	pos1 = binary_search_shops.upper_bound(key)
	pos2 = binary_search_drinks.upper_bound(key)
	print(pos1 - pos2)


n = int(input())
X = [int(x) for x in input().split()]
X.sort()
for _ in range(int(input())):
	coins = int(input())
	(l, r) = (0, n - 1)
	ans = 0
	while l <= r:
		m = (l + r) // 2
		if X[m] > coins:
			r = m - 1
		elif X[m] < coins:
			if m == n - 1:
				ans = n
				break
			else:
				if X[m + 1] > coins:
					ans = m + 1
					break
				l = m + 1
		elif m == n - 1:
			ans = n
			break
		else:
			if X[m + 1] > coins:
				ans = m + 1
				break
			l = m + 1
	print(ans)


def binarySearch(arr, l, r, x):
	while l <= r:
		mid = int(l + (r - l) / 2)
		if arr[mid] > x:
			r = mid - 1
		elif arr[mid] <= x:
			l = mid + 1
	return r
n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
a = list()
n = int(input())
for i in range(n):
	x = int(input())
	a.append(x)
for i in range(n):
	print(binarySearch(arr, 0, len(arr) - 1, a[i]) + 1)


from bisect import bisect
n = int(input())
a = sorted(map(int, input().split()))
q = int(input())
for i in range(q):
	p = int(input())
	print(bisect(a, p))


num_shops = int(input())
shop_costs = sorted(map(int, input().split()))
num_days = int(input())
sol = list()
for d in range(num_days):
	today_money = int(input())
	lo = -1
	hi = len(shop_costs)
	while lo + 1 < hi:
		mid = int((lo + hi) / 2)
		if shop_costs[mid] <= today_money:
			lo = mid
		else:
			hi = mid
	sol += f'{lo + 1}\n'
sol[-1] = sol[-1][:-1]
print(''.join(sol))


import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
arr = [0] * 10 ** 5
for i in range(n):
	arr[l[i] - 1] += 1
prefix = [arr[0]]
for i in range(1, 10 ** 5):
	prefix.append(prefix[-1] + arr[i])
q = int(sys.stdin.readline())
for _ in range(q):
	m = int(sys.stdin.readline())
	if m >= 10 ** 5:
		print(n)
	else:
		print(prefix[m - 1])


def binary_search_rightmost(A, n, T):
	L = 0
	R = n
	while L < R:
		m = (L + R) // 2
		if A[m] > T:
			R = m
		else:
			L = m + 1
	return R - 1
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for _ in range(q):
	m = int(input())
	print(binary_search_rightmost(x, n, m) + 1)


n = int(input())
xlist = list(map(int, input().split()))
xlist.sort()
q = int(input())
res = []
for i in range(q):
	k = len(xlist) // 2
	gap = k
	m = int(input())
	if m < xlist[0]:
		res.append(0)
		continue
	if m >= xlist[len(xlist) - 1]:
		res.append(len(xlist))
		continue
	while True:
		gap = gap // 2
		if gap == 0:
			gap = 1
		if k > len(xlist) - 1 or k < 1:
			res.append(0)
			break
		if m >= xlist[k - 1] and m < xlist[k]:
			res.append(k)
			break
		if m < xlist[k - 1]:
			k -= gap
			continue
		if m >= xlist[k]:
			k += gap
			continue
for i in res:
	print(i)


nc = int(input())
cf = input().split()
for i in range(len(cf)):
	cf[i] = int(cf[i])
cf.sort()
nq = int(input())

def b_sch(q, vals):
	if vals[-1] <= q:
		return len(vals)
	if vals[0] > q:
		return 0
	lo = 0
	hi = len(vals) - 1
	md = int((lo + hi) / 2)
	while lo + 1 < hi:
		md = int((lo + hi) / 2)
		if vals[md] <= q:
			lo = md
		elif vals[md] > q:
			hi = md
	return hi
for x in range(nq):
	print(b_sch(int(input()), cf))


import bisect
n = int(input())
x = sorted(map(int, input().split()))
t = int(input())
for tt in range(t):
	a = int(input())
	print(bisect.bisect(x, a))


n = int(input())
store = []
prices = [int(x) for x in input().split()]
maxPrice = max(prices)
for i in range(0, maxPrice + 1):
	store.append(0)
for x in prices:
	store[x] += 1
for i in range(1, maxPrice + 1):
	store[i] += store[i - 1]
q = int(input())
for i in range(0, q):
	m = int(input())
	if m >= maxPrice:
		print(n)
	else:
		print(store[m])


def pro():
	n = int(input())
	x = list(map(int, input().split()))
	q = int(input())

	def bs(x, t):
		l = -1
		r = n
		while r - l > 1:
			m = (l + r) // 2
			if t < x[m]:
				r = m
			else:
				l = m
		print(l + 1)
	x.sort()
	for i in range(q):
		t = int(input())
		bs(x, t)
pro()


from collections import Counter
n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for _ in range(q):
	m.append(int(input()))
counter_x = Counter(x)
unique_x = sorted(list(set(counter_x)))
dp = [0] * (unique_x[-1] + 1)
x_idx = 0
for i in range(1, unique_x[-1] + 1):
	if i >= unique_x[x_idx]:
		dp[i] = dp[i - 1] + counter_x[unique_x[x_idx]]
		x_idx += 1
	else:
		dp[i] = dp[i - 1]
res = []
for el in m:
	if el > unique_x[-1]:
		res.append(n)
	else:
		res.append(dp[el])
print(' '.join(map(str, res)))


def bp(n, t):
	l = 0
	r = n
	while r - l > 1:
		m = l + (r - l) // 2
		if x[m] <= t:
			l = m
		else:
			r = m
	if x[l] > t:
		l = -1
	return l + 1
n = int(input())
x = [int(i) for i in input().split()]
x.sort()
q = int(input())
for k in range(q):
	tmp = int(input())
	print(bp(n, tmp))


from bisect import *
from sys import *

def input():
	return stdin.readline()
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
for _ in range(int(input())):
	x = int(input())
	print(bisect_right(l, x))


def binsearch(ls, key):
	(first, last) = (0, len(ls) - 1)
	while first <= last:
		mid = (first + last) // 2
		if key < ls[mid]:
			last = mid - 1
		else:
			first = mid + 1
	return last + 1
n = int(input())
price = list(map(int, input().split()))
q = int(input())
budget = []
for i in range(0, q):
	budget.append(int(input()))
price.sort()
ls = []
for i in range(len(budget)):
	ls.append(binsearch(price, budget[i]))
for i in ls:
	print(i)


import bisect
n = int(input())
li = [int(k) for k in input().split()]
k = int(input())
que = []
for i in range(k):
	que.append(int(input()))
li.sort()
t = 0
for j in range(k):
	t = bisect.bisect(li, que[j])
	print(t)


n = int(input())
a = sorted([int(x) for x in input().split()])
q = int(input())
for i in range(q):
	key = int(input())
	l = 0
	r = n
	while l < r:
		m = (l + r) // 2
		if a[m] <= key:
			l = m + 1
		else:
			r = m
	print(l)


import math

def main():
	numShops = int(input())
	s = input().split()
	shops = []
	for i in range(len(s)):
		shops.append(int(s[i]))
	shops.sort()
	queries = int(input())
	inp = []
	for q in range(queries):
		inp.append(int(input()))
	for a in range(len(inp)):
		print(binarySearch(shops, inp[a]))

def binarySearch(shops, c):
	lo = 0
	hi = len(shops) - 1
	if c < shops[0]:
		return 0
	if c >= shops[len(shops) - 1]:
		return len(shops)
	while lo != hi:
		mid = int((lo + hi) / 2)
		if shops[mid] == c and shops[mid + 1] > c or (c > shops[mid] and c < shops[mid + 1]):
			return mid + 1
		if shops[mid] <= c:
			lo = mid
		else:
			hi = mid
	return lo
main()


from bisect import bisect
n = input()
coins = []
canBuy = []
shops = list(map(int, input().split()))
days = int(input())
for i in range(0, days, 1):
	coins.append(int(input()))
shops.sort()
for k in range(len(coins)):
	print(bisect(shops, coins[k]))
for z in canBuy:
	print(z)


import bisect
n = int(input())
listt = list(map(int, input().rstrip().split()))
listt = sorted(listt)
for _ in range(int(input())):
	m = int(input())
	print(bisect.bisect(listt, m))


def solve(arr, key, lo, hi):
	while lo <= hi:
		mid = lo + hi >> 1
		if arr[mid] <= key:
			lo = mid + 1
		else:
			hi = mid - 1
	return lo
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
for i in range(int(input())):
	x = int(input())
	ans = solve(arr, x, 0, len(arr) - 1)
	print(ans)


import bisect as b
(i, c) = (input, int)
i()
a = sorted(map(c, i().split()))
for _ in ' ' * c(i()):
	print(b.bisect_right(a, c(i())))


import bisect
n = int(input())
y = sorted(map(int, input().split()))
q = int(input())
for i in range(q):
	print(bisect.bisect_right(y, int(input())))


def dicho(t, n, x):
	debut = 0
	fin = n - 1
	nb = 0
	while debut <= fin:
		mil = (debut + fin) // 2
		if t[mil] == x:
			nb += mil - debut + 1
			debut = mil + 1
		elif t[mil] > x:
			fin = mil - 1
		else:
			debut = mil + 1
			nb = mil + 1
	return nb

def fonct():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	q = int(input())
	l1 = list()
	for i in range(q):
		x = int(input())
		l1.append(x)
	for i in l1:
		nb = dicho(l, n, i)
		print(nb)
fonct()


n = int(input())
a = [int(k) for k in input().split()]
a.sort()
q = int(input())

def f(a, b):
	(l, r) = (0, len(a) - 1)
	while r - l > 1:
		mid = (l + r) // 2
		if a[mid] > b:
			r = mid
		else:
			l = mid
	return r
for i in range(q):
	r = int(input())
	if r < a[0]:
		print(0)
	elif r >= a[n - 1]:
		print(n)
	else:
		print(f(a, r))


from bisect import bisect
n = int(input())
l = sorted(map(int, input().split()))
for i in range(int(input())):
	print(bisect(l, int(input())))


from bisect import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(int(input())):
	b = int(input())
	print(bisect(a, b))


import bisect
n = int(input())
prices = [int(t) for t in input().split()]
q = int(input())
prices.sort()
for _ in range(q):
	m = int(input())
	if m >= prices[-1]:
		print(n)
		continue
	if m < prices[0]:
		print(0)
		continue
	result = bisect.bisect_right(prices, m)
	print(result)


n = int(input())
pric = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	m = int(input())
	e = len(pric)
	s = 0
	if m < pric[0]:
		print(0)
		continue
	while s != e and e - s != 1:
		g = (s + e) // 2
		if m >= pric[g]:
			s = g
		else:
			e = g
	print(s + 1)


n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	m = int(input())
	left = 0
	right = n - 1
	while left < right:
		mid = (left + right + 1) // 2
		if m >= x[mid]:
			left = mid
		elif m < x[mid]:
			right = mid - 1
	if x[left] > m:
		print(0)
	else:
		print(left + 1)


n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for _ in range(q):
	m.append(int(input()))
x.sort()
y = [0 for _ in range(100001)]
j = 0
for i in range(1, 100001):
	z = y[i - 1]
	while j < n and x[j] <= i:
		z += 1
		j += 1
	y[i] = z
for i in range(q):
	if m[i] > 100000:
		print(n)
	else:
		print(y[m[i]])


from bisect import bisect
n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for i in range(q):
	s = int(input())
	m.append(s)
x = sorted(x)
for i in m:
	count = bisect(x, i)
	print(count)


from bisect import bisect_right
n = int(input())
lista = list(map(int, input().split()))
x = int(input())
lista.sort()
for i in range(x):
	ans = bisect_right(lista, int(input()))
	print(ans)


n = int(input())
shops = sorted(list(map(int, input().split())))
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
for i in m:
	l = 0
	r = n - 1
	while l <= r:
		md = (l + r) // 2
		if shops[md] > i:
			r = md - 1
		else:
			l = md + 1
	print(r + 1)


def last(arr, low, high, x, n):
	if high >= low:
		mid = low + (high - low) // 2
		if (mid == n - 1 or x < arr[mid + 1]) and arr[mid] == x:
			return [mid, 1]
		elif x < arr[mid]:
			return last(arr, low, mid - 1, x, n)
		else:
			return last(arr, mid + 1, high, x, n)
	return [low, 0]
n = int(input(''))
cnt = []
cnt.append(list(map(int, input().split())))
cnt1 = cnt[0]
cnt1.sort()
q = int(input(''))
day = []
for i in range(q):
	day.append(int(input('')))
for i in range(q):
	x = day[i]
	if x < cnt1[0]:
		print(0)
	else:
		y = len(cnt1)
		[num, flag] = last(cnt1, 0, y - 1, x, y)
		if flag:
			print(num + 1)
		else:
			print(num)


from sys import stdin
n = int(stdin.readline().strip())
x = list((int(x) for x in stdin.readline().strip().split(' ')))
q = int(stdin.readline().strip())
x.sort()
y = []
for i in range(0, n):
	y += [i] * (x[i] - len(y))
y.append(n)
for _ in range(q):
	m = int(stdin.readline().strip())
	if m > len(y) - 1:
		print(n)
	else:
		print(y[m])


def get_ints():
	return list(map(int, input().split()))

def main():
	import bisect
	input()
	x = sorted(get_ints())
	print('\n'.join((str(bisect.bisect_right(x, int(input()))) for _ in range(int(input())))))
main()


def counter(l, h, x, m):
	count = 0
	while l <= h:
		mid = (l + h) // 2
		if m >= x[mid]:
			count = mid + 1
			l = mid + 1
		else:
			h = mid - 1
	return count
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	m = int(input())
	count = counter(0, n - 1, x, m)
	print(count)


def binSearch(M, n, x):
	first = 0
	last = n - 1
	pos = -1
	if M[first] > x:
		return 0
	elif M[last] <= x:
		return last + 1
	while first <= last:
		if M[last] <= x:
			i = last
			while M[i] <= x and i < n:
				i += 1
			return i
		if M[first] == x:
			i = first
			while M[i] == x and i < n:
				i += 1
			return i
		mid = (first + last) // 2
		if M[mid] > x:
			last = mid - 1
		elif M[mid] < x:
			first = mid + 1
		else:
			i = mid
			while M[i] == x:
				i += 1
			return i
	if last > x:
		i = last
		while M[i] > x:
			i -= 1
		return i + 1
	else:
		i = last
		while M[i] <= x:
			i += 1
		return i
n = int(input())
M = input().split()
for i in range(n):
	M[i] = int(M[i])
M.sort()
q = int(input())
RES = {}
for i in range(q):
	x = int(input())
	if x not in RES:
		if x < M[0]:
			RES[x] = '0'
		else:
			j = 0
			j = binSearch(M, n, x)
			RES[x] = str(j)
	print(RES[x])


import time
time0 = time.time()
clock0 = time.clock()

def find(m, lst, start, end):
	length = end - start + 1
	if length == 1:
		if m >= lst[start]:
			return start + 1
		return start
	z = start + length // 2
	if lst[z - 1] <= m < lst[z]:
		return z
	elif m >= lst[z]:
		return find(m, lst, z + 1, end)
	elif m < lst[z]:
		return find(m, lst, start, z - 1)

def task(m, n, X):
	if m >= X[n - 1]:
		return n
	elif m < X[0]:
		return 0
	else:
		return find(m, X, 0, n - 1)

def main():
	cache = {}
	n = int(input())
	X = sorted(map(int, input().split()))
	q = int(input())
	results = ''
	for i in range(q):
		m = int(input())
		if m in cache:
			results += str(cache[m]) + '\n'
		else:
			answer = task(m, n, X)
			cache[m] = answer
			results += str(answer) + '\n'
	print(results)
main()


cnt = lambda s, x: s.count(i)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
n = ii()
ls = sorted(il())
t = ii()
l = -1
for i in range(t):
	mn = ii()
	l = -1
	r = n
	while r > l + 1:
		m = (r + l) // 2
		if mn < ls[m]:
			r = m
		else:
			l = m
	print(l + 1)


a = int(input())
li = list(map(int, input().split()))
li.sort()
dp = [0] * (li[-1] + 1)
for i in li:
	dp[i] += 1
for i in range(1, li[-1] + 1):
	dp[i] += dp[i - 1]
st = ''
b = int(input())
for _ in range(b):
	x = int(input())
	if li[-1] <= x:
		st += str(a) + '\n'
		continue
	else:
		st += str(dp[x]) + '\n'
print(st)


import bisect
input()
x = sorted(map(int, input().split()))
print('\n'.join((str(bisect.bisect(x, int(input()))) for i in range(int(input())))))


import bisect
int(input())
A = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	print(bisect.bisect(A, int(input())))


import bisect
n_shops = int(input())
prices = [int(x) for x in input().split(' ')]
prices.sort()
n_days = int(input())
for day in range(n_days):
	coins = int(input())
	N = bisect.bisect(prices, coins)
	print(N)


def main():
	import bisect
	n = int(input())
	x = sorted(map(int, input().split()))
	q = int(input())
	for i in range(q):
		m = int(input())
		print(bisect.bisect_right(x, m))
main()


def bisect_right(a, x, lo=0, hi=None):
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x < a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo
n = int(input())
x = sorted([int(i) for i in input().split()])
q = int(input())
d = []
for i in range(q):
	m = int(input())
	d.append(bisect_right(x, m))
print(*d, sep='\n')


n = int(input())
prices = list(map(int, input().split()))
prices.sort()
q = int(input())
mon = []
for _ in range(q):
	mon.append(int(input()))
for i in range(q):
	l = 0
	r = n - 1
	while l < r:
		mid = (l + r) // 2 + 1
		if mon[i] < prices[mid]:
			r = mid - 1
		else:
			l = mid
	if mon[i] < prices[0]:
		print(0)
	else:
		print(l + 1)


def floor(a, k, l, h):
	ans = -1
	while l <= h:
		m = (l + h) // 2
		if a[m] <= k:
			ans = m
			l = m + 1
		else:
			h = m - 1
	return ans
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
for _ in range(int(input())):
	k = int(input())
	l = 0
	h = n - 1
	x = floor(a, k, l, h)
	print(x + 1)


from bisect import bisect_right
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
q = int(input())
for _ in range(q):
	num = int(input())
	pos = bisect_right(a, num)
	print(pos)


n = int(input())
a = sorted([int(s) for s in input().split()])
for _ in range(int(input())):
	m = int(input())
	(L, M, R) = (0, 0, n - 1)
	while L <= R:
		M = (L + R) // 2
		if a[M] > m:
			R = M - 1
		else:
			L = M + 1
	print(L)


from bisect import bisect_right
n = int(input())
X = list(map(int, input().split()))
X.sort()
for _ in range(int(input())):
	print(bisect_right(X, int(input())))


def main():
	from bisect import bisect
	(n, xx, res) = (int(input()), sorted(map(int, input().split())), [])
	for _ in range(int(input())):
		res.append(bisect(xx, int(input())))
	print('\n'.join(map(str, res)))
main()


n = int(input())
l = [*map(int, input().split())]
r = int(input())
l.sort()
dp = [-1] * (l[n - 1] + 1)
dp[0] = 0
k = 0
for i in range(1, l[n - 1] + 1):
	if i < l[k]:
		dp[i] = dp[i - 1]
	else:
		dp[i] = dp[i - 1]
		while k < n and i >= l[k]:
			dp[i] += 1
			k += 1
for i in range(r):
	q = int(input())
	if q >= l[n - 1]:
		print(dp[l[n - 1]])
	else:
		print(dp[q])


def Search(tab, n, x):
	moi = 0
	deb = 0
	fin = n - 1
	nb = 0
	while deb <= fin:
		moi = (deb + fin) // 2
		if tab[moi] > x:
			fin = moi - 1
		elif tab[moi] == x:
			nb += moi - deb + 1
			deb = moi + 1
		else:
			deb = moi + 1
			nb = moi + 1
	return nb
n = int(input())
L = list(map(int, input().split()))
L.sort()
q = int(input())
for i in range(q):
	m = int(input())
	ans = Search(L, len(L), m)
	print(ans)


import bisect
t = int(input())
s = sorted(list(map(int, input().split())))
n = int(input())
while n > 0:
	n -= 1
	a = int(input())
	print(bisect.bisect(s, a))


import sys
import bisect

def read_data():
	m = int(next(sys.stdin))
	prices = list(map(int, next(sys.stdin).split()))
	n = int(next(sys.stdin))
	return (n, prices)

def solve_and_print(n, prices):
	prices.sort()
	for i in range(n):
		s = int(next(sys.stdin))
		n = bisect.bisect_right(prices, s)
		print(n)
(n, prices) = read_data()
solve_and_print(n, prices)


n = int(input())
a = list(sorted(map(int, input().split())))
q = int(input())
for i in range(q):
	beg = 0
	end = n - 1
	mid = (end - beg) // 2
	s = int(input())
	while mid != beg:
		if a[mid] > s:
			end = mid
		else:
			beg = mid
		mid = beg + (end - beg) // 2
	if n > 1 and a[end] <= s:
		print(mid + 2)
	elif a[mid] <= s:
		print(mid + 1)
	else:
		print(0)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
q = int(input())
for i in range(q):
	num = int(input())
	if num < arr[0]:
		print(0)
	elif num >= arr[n - 1]:
		print(n)
	else:
		start = 0
		end = n - 1
		while end - start != 1:
			mid = (end + start) // 2
			if num >= arr[mid]:
				start = mid
			else:
				end = mid
		print(end)


import sys
n = int(sys.stdin.readline())
prices = list((int(x) for x in sys.stdin.readline().split()))
c = [0] * 100001
for price in prices:
	c[price] += 1
prefix_sums = [0] * 100001
s = 0
for (i, stores) in enumerate(c):
	s += stores
	prefix_sums[i] = s
q = int(sys.stdin.readline())
for _ in range(q):
	amount = int(sys.stdin.readline())
	if amount >= 100001:
		print(n)
	else:
		print(prefix_sums[amount])


n = int(input())
arr = list(map(int, input().split()))
q = int(input())
arr.sort()
import bisect as b
for i in range(q):
	cost = int(input())
	print(b.bisect_right(arr, cost))


UPPER = 100000
(n,) = map(int, input().split())
price = [0 for _ in range(UPPER + 1)]
for x in map(int, input().split()):
	price[x] += 1
for i in range(1, UPPER + 1):
	price[i] += price[i - 1]
(q,) = map(int, input().split())
for _ in range(q):
	m = min(int(input()), UPPER)
	print(price[m])


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	a = sorted(LI())
	q = I()
	t = [I() for _ in range(q)]
	r = []
	for c in t:
		r.append(bisect.bisect_right(a, c))
	return '\n'.join(map(str, r))
print(main())


from bisect import bisect_right
n = int(input())
x = sorted(list(map(int, input().split())))
m = int(input())
for i in range(1, m + 1):
	count = 0
	budget = int(input())
	print(bisect_right(x, budget, 0, len(x)))


def binarySearch(ar, l, r, x):
	while l + 1 < r:
		mid = (l + r) // 2
		if ar[mid - 1] > x:
			r = mid
		else:
			l = mid
	return l
x = int(input())
ar = list(map(int, input().split()))
ar.sort()
for _ in range(int(input())):
	p = int(input())
	if p < ar[0]:
		print(0)
	elif p >= ar[len(ar) - 1]:
		print(len(ar))
	else:
		print(binarySearch(ar, 0, len(ar), p))


import sys
from bisect import bisect_right

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
Arr.sort()
q = int(input())
while q > 0:
	x = int(input())
	print(bisect_right(Arr, x))
	q -= 1


import math
n = int(input())
pri = list(map(int, input().split()))
m = max(pri)
a = [0] * (m + 1)
for x in pri:
	a[x] += 1
cum = [0] * len(a)
cum[0] = a[0]
for i in range(1, len(cum)):
	cum[i] = a[i] + cum[i - 1]
ans = ''
nq = int(input())
while nq:
	mo = int(input())
	mo = min(mo, len(cum) - 1)
	amt = cum[mo]
	ans += str(amt) + '\n'
	nq -= 1
print(ans)


(n, aa) = (int(input()), sorted(map(int, input().split())))
import bisect
for _ in range(int(input())):
	x = int(input())
	print(bisect.bisect(aa, x))


from sys import stdin, stdout

def solve(shop_count, prices, days, budget_day):
	shops_available = {}
	result = []
	sorted_prices = sorted(prices, reverse=True)
	highest_price = sorted_prices[0]
	lowest_price = sorted_prices[-1]
	shops_not_available = 0
	current_count = shop_count
	for budget in range(highest_price, lowest_price - 1, -1):
		while budget < sorted_prices[shops_not_available]:
			shops_not_available += 1
		shops_available[budget] = shop_count - shops_not_available
	for day in budget_day:
		if day in shops_available:
			result.append(shops_available[day])
		elif day >= highest_price:
			result.append(shop_count)
		else:
			result.append(0)
	return result
shop_count = int(stdin.readline())
prices = [int(x) for x in stdin.readline().rstrip('\r\n').split()]
budget_day = []
days = int(stdin.readline())
for i in range(days):
	day = int(stdin.readline().rstrip('\r\n'))
	budget_day.append(day)
result = solve(shop_count, prices, days, budget_day)
for data in result:
	stdout.write(str(data))
	stdout.write('\n')


from sys import stdin, stdout
from collections import Counter
from collections import defaultdict
from math import ceil
from bisect import bisect_left
from bisect import bisect_right
import math
ai = lambda : list(map(int, stdin.readline().split()))
ei = lambda : map(int, stdin.readline().split())
ip = lambda : int(stdin.readline().strip())

def myBinary(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i + 1
	else:
		return -1

def lessThanX(a, x):
	i = bisect_left(a, x)
	if i:
		return i
	else:
		return -1

def BinarySearch_rightmsot(a, x):
	i = bisect_right(a, x)
	if i != len(a) + 1 and a[i - 1] == x:
		return i
	else:
		return -1
n = ip()
li = ai()
li.sort()
for _ in range(ip()):
	p = ip()
	ans = BinarySearch_rightmsot(li, p)
	if ans != -1:
		print(ans)
	else:
		ans = lessThanX(li, p)
		if ans != -1:
			print(ans)
		else:
			print(0)


from bisect import bisect_right

def main():
	n = int(input())
	prices = [int(i) for i in input().split()]
	prices.sort()
	q = int(input())
	for i in range(q):
		mi = int(input())
		print(bisect_right(prices, mi))
main()


def NumberofShops(x, m):

	def Binarysearch(x, item):
		first = 0
		last = len(x)
		while last > first:
			mid = (first + last) // 2
			if item < x[mid]:
				last = mid
			else:
				first = mid + 1
		return first
	for i in range(len(m)):
		print(Binarysearch(x, m[i]))
n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
x.sort()
NumberofShops(x, m)


from sys import stdin, stdout, setrecursionlimit
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm, accumulate
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
setrecursionlimit(10 ** 9)
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return input()

def num():
	return int(input())

def L():
	return list(sp())

def LF():
	return list(spf())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def spf():
	return map(int, input.readline().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def pmat2(A):
	for ele in A:
		for j in ele:
			print(j, end='')
		print()

def iseven(n):
	return n % 2 == 0

def seive(r):
	prime = [1 for i in range(r + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(r + 1):
		if prime[i]:
			for j in range(2 * i, r + 1, i):
				prime[j] = 0
	return prime

def generate_all_sets(n, a):
	big_ans = []
	for i in range(1 << n):
		ans = []
		for j in range(n):
			if i & 1 << j:
				ans.append(a[j])
		big_ans.append(ans)
	return big_ans
n = int(input())
a = sorted(L())
for _ in range(int(input())):
	i = int(input())
	print(br(a, i))
endtime = time.time()


n = int(input())
arr = list(map(int, input().split()))
dp = int(100000.0 + 5) * [0]
for i in arr:
	dp[i] += 1
for i in range(1, len(dp)):
	dp[i] += dp[i - 1]
m = int(input())
for i in range(m):
	k = int(input())
	print(dp[min(int(100000.0), k)])


def binary_search(l, r, a, value):
	while l < r:
		middle = (l + r) // 2
		if a[middle] > value:
			r = middle
		else:
			l = middle + 1
	return l
n = int(input())
a = list(map(int, input().split()))
a.sort()
m = int(input())
for i in range(m):
	t = int(input())
	print(binary_search(0, len(a), a, t))


input()
li = [int(x) for x in input().split()]
li.sort()
for _ in range(int(input())):
	key = int(input())
	l = 0
	h = len(li) - 1
	while l <= h:
		mid = (l + h) // 2
		if li[mid] == key or li[mid] < key:
			l = mid + 1
		else:
			h = mid - 1
	print(l)


import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	print(bisect.bisect_right(a, int(input()), 0, n))


n = int(input())
cost = list(map(int, input().split(' ')))
m = int(input())
moneys = [0] * m
for i in range(m):
	money = int(input())
	moneys[i] = money
q = max(cost)
dp = [0] * (q + 1)
prefix_sum = [0] * (q + 1)
for i in range(n):
	dp[cost[i]] += 1
for i in range(1, q + 1):
	prefix_sum[i] = prefix_sum[i - 1] + dp[i]
for i in range(m):
	if moneys[i] > q:
		print(n)
	else:
		print(prefix_sum[moneys[i]])


from bisect import *
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
for _ in range(int(input())):
	m = int(input())
	print(bisect_right(a, m))


n = int(input())
x = map(int, input().split())
q = int(input())
maxi = 0
count = 0
m = [0] * 100004
for y in x:
	m[y] += 1
	maxi = max(maxi, y)
for i in range(0, maxi + 1):
	count += m[i]
	m[i] = count
for _ in range(0, q):
	a = int(input())
	if a > maxi:
		print(m[maxi])
	else:
		print(m[a])


n = int(input())
price = sorted(list(map(int, input().split())))
shop = len(price)
day = int(input())
buy = [shop] * (price[-1] + 1)
low = price[0]
number = 0
for i in range(price[-1]):
	if i < low:
		buy[i] = number
	else:
		while price[number] == low:
			number += 1
		low = price[number]
		buy[i] = number
for i in range(day):
	x = int(input())
	if x >= price[-1]:
		print(shop)
	else:
		print(buy[x])


import bisect
n = int(input())
x = list(map(int, input().split()))
q = int(input())
x.sort()
dd = {}
for _ in range(q):
	m = int(input())
	if m not in dd:
		dd[m] = bisect.bisect_right(x, m)
	print(dd[m])


def main():
	n = int(input())
	arr = [0] + sorted(list(map(int, input().split())))
	for i in range(int(input())):
		L = 0
		R = n + 1
		m = int(input())
		while R - L > 1:
			M = (R + L) // 2
			if arr[M] <= m:
				L = M
			else:
				R = M
		print(L)
main()


n = 100005
L = [0] * n
input()
for x in map(int, input().split()):
	L[x] += 1
for i in range(1, n):
	L[i] = L[i - 1] + L[i]
for j in range(int(input())):
	print(L[min(int(input()), n - 1)])


from bisect import *
(n, a, m) = (int(input()), sorted(list(map(int, input().split()))), int(input()))
for _ in ' ' * m:
	print(bisect_right(a, int(input())))


import bisect
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
q = int(input())
while q:
	q -= 1
	m = int(input())
	if m < a[0]:
		print(0)
		continue
	if m >= a[n - 1]:
		print(n)
		continue
	res = bisect.bisect_right(a, m)
	print(res)


def binSearch(a, item):
	if item > a[-1]:
		return len(a)
	if item < a[0]:
		return 0
	left = 0
	right = len(a) - 1
	while True:
		mid = (left + right) // 2
		if a[mid] <= item and (mid + 1 == len(a) or a[mid + 1] > item):
			return mid + 1
		elif a[mid] <= item:
			left = mid + 1
		else:
			right = mid - 1
n = int(input())
sortedprices = sorted(list((int(x) for x in input().split())))
q = int(input())
builderlist = []
for i in range(q):
	m = int(input())
	builderlist.append(binSearch(sortedprices, m))
print('\n'.join((str(data) for data in builderlist)))


def NewBinarySearch(alist, item):
	first = 0
	last = len(alist)
	while first < last:
		mid = (first + last) // 2
		if alist[mid] > item:
			last = mid
		else:
			first = mid + 1
	return first
input()
a = sorted([int(x) for x in input().split()])
q = int(input())
for i in range(q):
	m = int(input())
	res = NewBinarySearch(a, m)
	print(res)


n = int(input())
x = [0] + list(map(int, input().strip().split(' '))) + [100001]
q = int(input())
x.sort()
ans = ''
for i in range(q):
	l = 0
	r = n + 1
	m = int(input())
	while r - l > 1:
		j = l + (r - l) // 2
		if x[j] <= m:
			l = j
		else:
			r = j
	ans += str(r - 1) + '\n'
print(ans)


import sys
n = int(input())
n1 = []
n1 = input().split()
n1 = list(map(int, n1))
n1.sort()

def binary_search(n1, d1):
	l = 0
	h = len(n1)
	while l != h:
		mid = (l + h) // 2
		if n1[mid] > d1:
			h = mid
		else:
			l = mid + 1
	return l
d = int(input())
for i in range(d):
	d1 = int(input())
	x = binary_search(n1, d1)
	print(x)


n = int(input())
xs = [int(i) for i in input().strip().split(' ')]
xs.sort()
q = int(input())

def bs(m):
	low = 0
	high = n - 1
	while low < high:
		mid = low + (high - low) // 2
		if xs[mid] > m:
			high = mid
		else:
			low = mid + 1
	if xs[low] <= m:
		return n
	return low
for t in range(q):
	mi = int(input())
	print(bs(mi))


n = int(input())
costs = [int(x) for x in input().split()]
costs = list(sorted(costs))
q = int(input())
ans = []
for _ in range(q):
	m = int(input())
	(lo, hi) = (-1, n)
	while hi - lo > 1:
		mid = (hi + lo) // 2
		if costs[mid] > m:
			hi = mid
		else:
			lo = mid
	ans.append(lo + 1)
for v in ans:
	print(v)


n = int(input())
x = sorted(list(map(int, input().split())))
k = x[n - 1]
q = int(input())
r = [0]
j = 0
for i in range(1, k + 1):
	while j < n and x[j] <= i:
		j += 1
	r.append(j)
for i in range(q):
	w = int(input())
	if w > k:
		print(r[k])
	else:
		print(r[w])


import bisect
n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
t = int(input())
for _ in range(t):
	print(bisect.bisect_right(arr, int(input())))


input()
store = [int(i) for i in input().split()]
store.sort()
import bisect
for _ in [0] * int(input()):
	print(bisect.bisect(store, int(input())))


I = input
R = range
n = 100010
a = [0] * n
I()
for i in map(int, I().split()):
	a[i] += 1
for i in R(1, n):
	a[i] += a[i - 1]
for _ in R(int(I())):
	print(a[min(int(I()), n - 1)])


import bisect
n = int(input())
s = input()
s = s.split()
t = [int(s[i]) for i in range(len(s))]
t = sorted(t)
q = int(input())
for i in range(q):
	a = int(input())
	print(bisect.bisect(t, a))


from sys import *
n = int(stdin.readline())
pr = [int(z) for z in stdin.readline().split()]
pr.sort()
q = int(stdin.readline())
for i in range(q):
	m = int(stdin.readline())
	(l, r) = (0, n + 1)
	while r - l > 1:
		mid = l + r >> 1
		if pr[mid - 1] > m:
			r = mid
		else:
			l = mid
	print(l)


n = int(input())
X = list(map(int, input().split()))
q = int(input())
Q = []
for i in range(q):
	m = int(input())
	Q.append(m)
cnt = (10 ** 5 + 1) * [0]
for i in range(n):
	cnt[X[i]] += 1
ans = (10 ** 5 + 1) * [0]
for i in range(1, 10 ** 5 + 1):
	ans[i] = ans[i - 1] + cnt[i]
for i in range(q):
	print(ans[min(Q[i], 10 ** 5)])


def rech(elt, l):
	a = 0
	b = len(l) - 1
	minn = 0
	while a <= b:
		m = (a + b) // 2
		if l[m] == elt:
			minn += m - a + 1
			a = m + 1
		elif l[m] > elt:
			b = m - 1
		else:
			minn = m + 1
			a = m + 1
	return minn
x = int(input())
l = list(map(int, input().split()))
day = int(input())
l.sort()
for i in range(day):
	var = int(input())
	k = rech(var, l)
	print(k)


from bisect import bisect
n = int(input())
shops = [int(i) for i in input().split()]
shops.sort()
q = int(input())
for _ in range(q):
	m = int(input())
	print(bisect(shops, m))


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
from bisect import bisect
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	_ = int(input())
	prices_s = sorted(map(int, input().split()))
	days = int(input())
	for day in range(days):
		money = int(input())
		print(bisect(prices_s, money))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from bisect import bisect as bs
n = int(input())
l = list(map(int, input().split()))
l.sort()
q = int(input())
for i in range(q):
	m = int(input())
	print(bs(l, m))


def b_search(arr, target):
	start = 0
	end = len(arr) - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= target:
			start = mid + 1
		else:
			ans = mid
			end = mid - 1
	return ans
shops = int(input())
price = input()
price = price.split()
prices = []
result = []
for i in price:
	prices.append(int(i))
prices.sort()
days = int(input())
for i in range(0, days):
	coins = int(input())
	if coins >= prices[-1]:
		result.append(len(prices))
	elif coins < prices[0]:
		result.append(0)
	else:
		ans = b_search(prices, coins)
		if ans == -1:
			result.append(0)
		else:
			result.append(ans)
for i in result:
	print(i)


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

def gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def isPrime(n):
	if n <= 1:
		return False
	i = 2
	while i ** 2 <= n:
		if n % i == 0:
			return False
		i += 1
	return True

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def vars():
	return map(int, input().split())

def array():
	return list(map(int, input().split()))

def can(m, s):
	if 0 <= s <= m * 9:
		return True
	return False

def main():
	n = int(input())
	arr = array()
	arr.sort()
	m = int(input())
	p = []
	for i in range(m):
		mo = int(input())
		l = 0
		r = n - 1
		while l <= r:
			m = (l + r) // 2
			if arr[m] <= mo:
				l = m + 1
			else:
				r = m - 1
		print(l)
t = 1
for _ in range(t):
	main()


n = int(input())
l = [0] * 100001
t = 0
for i in input().split():
	l[int(i)] += 1
for i in range(100001):
	t += l[i]
	l[i] = t
q = int(input())
for i in range(q):
	c = int(input())
	if c > 100000:
		print(n)
	else:
		print(l[c])


n = int(input())
arr = sorted(map(int, input().split()))
q = int(input())
from bisect import bisect
for i in range(q):
	key = int(input())
	print(bisect(arr, key))


import sys
EPS = sys.float_info.epsilon
LENGTH = 10
matrix = [[] for i in range(LENGTH)]
array = [0] * 1001

class BinarySearch:
	__slots__ = ['__array']

	def __init__(self, array, sort_key=None):
		self.__array = sorted(array, key=sort_key)

	def upper_bound(self, key):
		(l, r) = (0, len(self.__array) - 1)
		while l < r:
			mid = r - (r - l) // 2
			if self.__array[mid] <= key:
				l = mid
			else:
				r = mid - 1
		return l if self.__array[l] == key else -1
n = input()
shops = list(map(int, input().split()))
drinks = []
q = int(input())
for i in range(q):
	value = int(input())
	drinks.append(value)
	shops.append(value)
binary_search_shops = BinarySearch(shops)
binary_search_drinks = BinarySearch(drinks)
for key in drinks:
	pos1 = binary_search_shops.upper_bound(key)
	pos2 = binary_search_drinks.upper_bound(key)
	print(pos1 - pos2)


n = int(input())
a = list(map(int, input().split()))
q = []
for _ in range(int(input())):
	q.append([int(input()), _, -1])
a.sort()
q.sort()
sq = 0
sa = 0
while sa < len(a) and sq < len(q):
	if q[sq][0] >= a[sa]:
		q[sq][2] = sa
		sa += 1
	else:
		if sq + 1 != len(q):
			q[sq + 1][2] = q[sq][2]
		sq += 1
while sq + 1 < len(q):
	q[sq + 1][2] = q[sq][2]
	sq += 1
q.sort(key=lambda x: x[1])
for sb in q:
	print(sb[2] + 1)


from bisect import bisect_right

def binary_search(l_p, m, l, h):
	if l >= h:
		return l + 1 if l_p[l] <= m else l
	mid = (h + l) // 2
	if l_p[mid] >= m:
		return binary_search(l_p, m, l, mid)
	elif l_p[mid] < m:
		return binary_search(l_p, m, mid + 1, h)
_ = input()
l_p = list(map(int, input().split()))
l_p.sort()
for _ in range(int(input())):
	t = 0
	m = int(input())
	print(bisect_right(l_p, m))


from bisect import bisect
n = int(input())
arr = sorted(list(map(int, input().split())))
q = int(input())
for _ in range(q):
	m = int(input())
	print(bisect(arr, m))


n = int(input())
x = list(map(int, input().split(' ')))
q = int(input())
max_price = 100000
n_per_price = [0] * (max_price + 1)
for x_i in x:
	n_per_price[x_i] += 1
cum_n_per_price = [0] * (max_price + 1)
cum = 0
for p in range(max_price + 1):
	cum += n_per_price[p]
	cum_n_per_price[p] = cum
for i in range(q):
	m_i = int(input())
	if m_i > max_price:
		print(n)
	else:
		print(cum_n_per_price[m_i])


def bins(l, k):
	(i, m) = (0, 0)
	j = len(l) - 1
	while i <= j:
		m = (i + j) // 2
		if l[m] > k:
			j = m - 1
		elif l[m] <= k:
			i = m + 1
	n = i
	for h in range(i + 1, len(l)):
		if l[h] <= k:
			n += 1
		else:
			break
	return n
n = int(input())
l = list(map(int, input().split()))
l.sort()
for _ in int(input()) * '9':
	m = int(input())
	print(bins(l, m))


from operator import itemgetter
n = int(input())
prices = list(map(int, input().split()))
prices.sort()
q = int(input())
l2 = []
for i in range(q):
	x = int(input())
	l2.append((i, x))
l2 = sorted(l2, key=itemgetter(1))
l3 = []
p = 0
for i in l2:
	if p == n:
		l3.append((i[0], n))
	else:
		while i[1] >= prices[p]:
			p += 1
			if p == n:
				break
		l3.append((i[0], p))
l3 = sorted(l3, key=itemgetter(0))
for i in l3:
	print(i[1])


n = int(input())
x = [int(i) for i in input().split()]
x = sorted(x)
q = int(input())
import bisect

def upperbound(m):
	ind = bisect.bisect(x, m)
	return ind
for i in range(q):
	m = int(input())
	print(upperbound(m))


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]

def number_of_bottles(current_money, prices):
	bad = -1
	good = len(prices)
	while good - bad > 1:
		m = (bad + good) // 2
		if prices[m] > current_money:
			good = m
		else:
			bad = m
	return good
n = input()
prices = read_ints()
prices = sorted(prices)
q = int(input())
for _ in range(q):
	current_money = int(input())
	print(number_of_bottles(current_money, prices))


from bisect import bisect
n = int(input())
shops = [int(c) for c in input().rstrip().split(' ')]
shops.sort()
q = int(input())
for _ in range(q):
	m = int(input())
	print(bisect(shops, m))


import bisect
t = int(input())
l = list(map(int, input().split()))
l.sort()
q = int(input())
for _ in range(q):
	m = int(input())
	ind = bisect.bisect_right(l, m)
	print(ind)


import bisect
n = int(input())
x = list(map(int, input().split()))
q = int(input())
x.sort()
for _ in range(q):
	m = int(input())
	ans = bisect.bisect(x, m)
	print(ans)


n = int(input())
a = list(map(int, input().split()))
dp = 100001 * [0]
for i in a:
	dp[i] += 1
for i in range(1, len(dp)):
	dp[i] += dp[i - 1]
d = int(input())
for i in range(d):
	print(dp[min(100000, int(input()))])


def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count
n = int(input())
list1 = list(map(int, input().split()))[:n]
list1.sort()
for _ in range(int(input())):
	p = int(input())
	ans = binarySearchCount(list1, n, p)
	print(ans)


from bisect import bisect
n = int(input())
prices = sorted((int(c) for c in input().split()))
m = int(input())
queries = [int(input()) for _ in range(m)]
for q in queries:
	print(bisect(prices, q))


n = int(input())
x = list(map(int, input().split()))
q = int(input())
dp = [0] + [0] * max(x)
for v in x:
	dp[v] += 1
for i in range(1, len(dp)):
	dp[i] = dp[i - 1] + dp[i]
for _ in range(q):
	d = int(input())
	if len(dp) <= d:
		print(dp[-1])
	else:
		print(dp[d])


import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
for i in range(int(input())):
	m = int(input())
	print(bisect.bisect_right(a, m))


import math
n = int(input())
l = list(map(int, input().split()))
q = int(input())
p = max(l)
k = [0] * (p + 1)
for i in l:
	k[i] += 1
for i in range(1, p + 1):
	k[i] = k[i - 1] + k[i]
for i in range(q):
	a = int(input())
	try:
		print(k[a])
	except:
		print(n)


import bisect
n = int(input())
x = [int(elt) for elt in input().split(' ')]
x.sort()
d = int(input())
ans = []
for i in range(d):
	m = int(input())
	ans.append(bisect.bisect_right(x, m, hi=n))
for elt in ans:
	print(elt)


nShops = int(input())
shopPrices = list(map(int, input().split()))
shopPrices.sort()
times = int(input())
answers = []

def iterativeBinary(array, target):
	low = 0
	high = len(array) - 1
	while low <= high:
		mid = low + (high - low) // 2
		print(mid)
		if array[mid] > target:
			high = mid - 1
		else:
			low = mid + 1
	return low

def theOther(shops, coins):
	leftIndex = 0
	rightIndex = len(shops) - 1
	cache = []
	while leftIndex <= rightIndex:
		center = leftIndex + (rightIndex - leftIndex) // 2
		if shops[center] > coins:
			rightIndex = center - 1
		else:
			leftIndex = center + 1
	return leftIndex
for time in range(times):
	money = int(input())
	others = theOther(shopPrices, money)
	answers.append(others)
for answer in answers:
	print(answer)


a = int(input())
b = list(map(int, input().split()))
b.sort()
c = int(input())
for k in range(c):
	d = int(input())
	l = 0
	r = a - 1
	while l <= r:
		mid = (l + r) // 2
		if d < b[0]:
			mid = -1
			break
		if d >= b[-1]:
			mid = a - 1
			break
		if d >= b[mid] and d < b[mid + 1]:
			break
		elif d == b[mid] and d == b[mid + 1]:
			l = mid + 1
		elif d > b[mid]:
			l = mid + 1
		else:
			r = mid - 1
	print(mid + 1)


n = int(input())
arr = [int(i) for i in input().split()]
mx = max(arr) + 1
sums = [0] * mx
for a in arr:
	sums[a] += 1
for i in range(1, mx):
	sums[i] += sums[i - 1]
q = int(input())
for i in range(q):
	idx = min(mx - 1, int(input()))
	print(sums[idx])


n = int(input())
s = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	d = int(input())
	l = 0
	r = n
	while r - l > 1:
		m = (r + l) // 2
		if s[m] > d:
			r = m
		else:
			l = m
	if s[0] <= d:
		print(r)
	else:
		print(0)


def sh(k, A):
	l = 0
	h = len(A) - 1
	while l < h:
		mid = (l + h) // 2
		if A[mid] < k:
			l = mid + 1
		else:
			h = mid - 1
	if A[l] > q:
		return l - 1
	else:
		return l
from sys import stdin
n = input()
A = sorted([int(x) for x in input().split()])
n = input()
for line in stdin:
	q = int(line)
	if A[0] > q:
		print(0)
	elif A[-1] <= q:
		print(len(A))
	else:
		print(sh(q + 0.5, A) + 1)


import bisect
input()
x = sorted(map(int, input().split()))
for i in range(int(input())):
	print(bisect.bisect_right(x, int(input())))


from bisect import bisect_right, bisect_left
n = int(input())
l = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	x = int(input())
	print(bisect_right(l, x))


import bisect
i = int(input())
l = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	print(bisect.bisect(l, int(input())))


def bin_srch(val, x):
	(l, r) = (0, len(val) - 1)
	while l <= r:
		mid = (l + r) // 2
		if val[(l + r) // 2] > x:
			r = mid - 1
		else:
			l = mid + 1
	return l
input()
val = list(map(int, input().split()))
val.sort()
for _ in range(int(input())):
	print(bin_srch(val, int(input())))


import bisect
n = int(input())
list1 = sorted(list(map(int, input().split())))
q = int(input())
m_list = [int(input()) for _ in range(q)]
ans = ''
for i in m_list:
	ans += str(bisect.bisect(list1, i)) + '\n'
print(ans)


(q, g) = ([0 for _ in range(100007)], [0 for _ in range(100007)])
n = int(input())
mxx = 0
tmp = [int(i) for i in input().split()]
for i in tmp:
	mxx = max(mxx, i)
	q[i] += 1
for i in range(1, 100007):
	g[i] = g[i - 1] + q[i - 1]
for _ in range(int(input())):
	k = int(input())
	if k >= 100000:
		print(g[100001])
	else:
		print(g[k + 1])


import bisect
n = input()
prices = sorted([int(x) for x in input().split(' ')])
num_days = int(input())
coins = []
for day in range(num_days):
	coins.append(int(input()))
for coin in coins:
	print(bisect.bisect_right(prices, coin))


import bisect
input()
lt = sorted([int(i) for i in input().split()])
for i in range(int(input())):
	print(bisect.bisect(lt, int(input())))


n = int(input())
f = list(map(int, input().split()))
f.sort()
q = int(input())
for i in range(q):
	m = int(input())
	start = 0
	end = len(f)
	while start < end:
		k = (start + end) // 2
		if m < f[k]:
			end = k - 1
		else:
			start = k + 1
	k = (start + end) // 2
	flag = True
	for j in range(max(0, k - 2), n):
		if f[j] > m:
			print(j)
			flag = False
			break
	if flag:
		print(n)


n = int(input().strip())
bars = sorted([int(x) for x in input().strip().split()])
days = int(input().strip())
d = {}

def binsearch(arr, num):
	if not arr:
		return 0
	if arr[0] > num:
		return 0
	if arr[-1] < num:
		return len(arr)
	(start, end, answer) = (0, len(arr) - 1, 0)
	while start <= end:
		middle = (start + end) // 2
		if arr[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer + 1
for i in range(days):
	cost = int(input().strip())
	if not cost in d:
		d[cost] = binsearch(bars, cost)
	print(d[cost])


import bisect
x = int(input())
a = sorted(map(int, input().split()))
b = int(input())
for _ in range(b):
	print(bisect.bisect(a, int(input())))


cnt = lambda s, i: s.count(i)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
import bisect
n = ii()
l = sorted(il())
t = ii()
for i in range(t):
	print(bisect.bisect_right(l, ii()))


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())
number_of_shops = int(input())
prices_bottle_shop = [int(x) for x in input().split()]
prices_bottle_shop.sort()
number_of_days = int(input())
number_shops_coins = [0] * 100001
nbShop = 0
for t in range(1, 100001):
	while nbShop < number_of_shops and t >= prices_bottle_shop[nbShop]:
		nbShop += 1
	number_shops_coins[t] = nbShop
for day in range(number_of_days):
	number_of_coins = int(input())
	if number_of_coins >= prices_bottle_shop[-1]:
		print(number_of_shops)
		continue
	print(number_shops_coins[number_of_coins])


n = int(input())
x = [int(i) for i in input().split()]
x.sort()

def binSrch(lo, hi, m):
	mid = (lo + hi) // 2
	if x[mid] <= m:
		if x[mid + 1] > m:
			return mid + 1
		else:
			return binSrch(mid + 1, hi, m)
	else:
		return binSrch(lo, mid - 1, m)
q = int(input())
for i in range(q):
	m = int(input())
	if m < x[0]:
		print(0)
	elif m >= x[n - 1]:
		print(n)
	else:
		print(binSrch(0, n - 1, m))


def main_function():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	special_hash = [0 for i in range(max(a) + 1)]
	for i in range(len(a)):
		special_hash[a[i]] += 1
	for i in range(1, len(special_hash)):
		special_hash[i] += special_hash[i - 1]
	q = int(input())
	m = [int(input()) for i in range(q)]
	for i in range(len(m)):
		if m[i] >= len(special_hash):
			print(special_hash[-1])
		else:
			print(special_hash[m[i]])
main_function()


n = int(input())
li = list(map(int, input().split()))
li.sort()
freq = {}
for i in range(1, 100001):
	freq[i] = 0
for i in li:
	if i in freq:
		freq[i] += 1
dp = [0] * 100001
i = 0
j = 0
while i <= 100000:
	if j > n - 1:
		dp[i] += dp[i - 1]
	elif i >= li[j]:
		dp[i] += dp[i - 1] + freq[i]
		j += 1
	else:
		dp[i] += dp[i - 1]
	i += 1
q = int(input())
query = []
for i in range(q):
	a = int(input())
	if a > 100000:
		print(n)
	else:
		print(dp[a])


from bisect import bisect
(n, x, m) = (int(input()), sorted(list(map(int, input().split()))), [])
for i in range(int(input())):
	m.append(bisect(x, int(input())))
print(*m, sep='\n')


N = int(input())
prices = [int(i) for i in input().split()]
q = int(input())
prices = sorted(prices)
Q = []
for _ in range(q):
	Q.append(int(input()))
A = []
for M in Q:
	answer = 0
	(L, R) = (0, N - 1)
	while L <= R:
		m = L + (R - L) // 2
		if prices[m] <= M:
			L = m + 1
			answer = m + 1
		else:
			R = m - 1
	A.append(answer)
print('\n'.join(map(str, A)))


n = int(input())
a = sorted(list(map(int, input().rstrip().split())))
r = 1
l = [0] * a[0]
for i in range(1, len(a)):
	l += [r] * (a[i] - a[i - 1])
	r += 1
l.append(n)
for j in range(int(input())):
	e = int(input())
	print(l[e] if e <= a[-1] else l[-1])


I = input
n = I()
l = [0] * (10 ** 5 + 1)
for i in map(int, I().split()):
	l[i] += 1
for i in range(1, 10 ** 5 + 1):
	l[i] += l[i - 1]
for i in range(int(I())):
	q = int(I())
	print(n if q > 10 ** 5 else l[q])


import sys
import itertools
import math
import collections
from collections import Counter

def getdict(n):
	d = {}
	if type(n) is list:
		for i in n:
			if i in d:
				d[i] += 1
			else:
				d[i] = 1
	else:
		for i in range(n):
			t = ii()
			if t in d:
				d[t] += 1
			else:
				d[t] = 1
	return d

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)

def upper_bound(a, p, l, r):
	ans = -1
	while l <= r:
		mid = l + (r - l) // 2
		if a[mid] > p:
			ans = mid
			r = mid - 1
		else:
			l = mid + 1
	return ans
n = ii()
d = sorted(li())
q = ii()
for _ in range(q):
	t = ii()
	ans = upper_bound(d, t, 0, n - 1)
	print(ans if ans != -1 else n)


numberOfShops = int(input())
precios = [int(n) for n in input().split()]
numberOfDias = int(input())
plata = []
for i in range(numberOfDias):
	plata.append(int(input()))
precios.sort()
maxPrecios = max(precios) + 1
cantDeShopsDandoPrecio = [0] * maxPrecios
prefijoAux = 0
for i in range(1, len(cantDeShopsDandoPrecio)):
	diferencia = 0
	while prefijoAux < len(precios) and i >= precios[prefijoAux]:
		diferencia += 1
		prefijoAux += 1
	cantDeShopsDandoPrecio[i] += cantDeShopsDandoPrecio[i - 1] + diferencia
for i in range(len(plata)):
	if plata[i] >= maxPrecios:
		print(cantDeShopsDandoPrecio[maxPrecios - 1])
	else:
		print(cantDeShopsDandoPrecio[plata[i]])


import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
for _ in range(int(input())):
	x = int(input())
	print(bisect.bisect(a, x, 0, len(a)))


import bisect
n = int(input())
p = [int(i) for i in input().split()]
q = int(input())
p.sort()
x = []
for i in range(q):
	x.append(int(input()))
for i in x:
	print(bisect.bisect_right(p, i))


import bisect
n = int(input())
a = list(map(int, input().split()))
a.sort()
m = int(input())
while m:
	x = int(input())
	x = bisect.bisect_right(a, x)
	print(x)
	m -= 1


def _binsearch(el, a, left, right):
	mid = left + (right - left) // 2
	if right - left <= 1:
		return left
	if a[mid] <= el:
		return _binsearch(el, a, mid, right)
	elif el < a[mid]:
		return _binsearch(el, a, left, mid)

def bs(el, a):
	if el < a[0]:
		return -1
	return _binsearch(el, a, 0, len(a))
n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
for _ in range(q):
	m = int(input())
	print(bs(m, x) + 1)


n = int(input())
p = list(map(int, input().split()))
p.sort()
q = int(input())
c = [int(input()) for _ in range(q)]
l = [0] * 100001
j = 0
for i in range(1, 100001):
	l[i] = l[i - 1]
	while j < len(p) and p[j] <= i:
		l[i] += 1
		j += 1
for x in c:
	print(l[x] if x <= 100000 else l[-1])


def main():
	(shops, q, budgets) = read_input()
	shops.sort()
	for budget in budgets:
		print(eligible_shops(budget, shops))

def eligible_shops(budget, shops):
	low = -1
	high = len(shops)
	while low + 1 < high:
		mid = (low + high) // 2
		if shops[mid] <= budget:
			low = mid
		elif shops[mid] > budget:
			high = mid
	return low + 1

def read_input():
	input()
	shops = [int(x) for x in input().split(' ')]
	q = int(input())
	budgets = []
	for _ in range(q):
		budgets.append(int(input()))
	return (shops, q, budgets)
main()


from bisect import bisect

def vasiliy(ls, lis):
	ls.sort()
	for i in lis:
		print(bisect(ls, i))
n = int(input())
ls = [int(i) for i in input().split()]
n1 = int(input())
n2 = n1
lis = []
while n2 > 0:
	k = int(input())
	lis.append(k)
	n2 = n2 - 1
vasiliy(ls, lis)


from bisect import bisect_right
from sys import stdin
stdin.readline()
prices = sorted((int(x) for x in stdin.readline().split()))
q = int(stdin.readline())
print(*(bisect_right(prices, int(stdin.readline())) for _ in range(q)), sep='\n')


n = int(input())
arr = [int(i) for i in input().split()]
arr = sorted(arr)
temp = [0]
curr = 0
count = 0
for i in range(len(arr)):
	if curr == arr[i]:
		temp[len(temp) - 1] += 1
		count += 1
		continue
	temp += (arr[i] - curr - 1) * [count]
	curr = arr[i]
	count = count + 1
	temp += [count]
for _ in range(int(input())):
	q = int(input())
	if q >= len(temp):
		print(temp[len(temp) - 1])
	else:
		print(temp[q])
	continue


from sys import stdin, stdout
inFile = stdin
tokens = []
tokens_next = 0

def next_str():
	global tokens, tokens_next
	while tokens_next >= len(tokens):
		tokens = inFile.readline().split()
		tokens_next = 0
	tokens_next += 1
	return tokens[tokens_next - 1]

def nextInt():
	return int(next_str())
n = nextInt()
a = sorted([nextInt() for i in range(n)])
q = nextInt()
from bisect import bisect_right
for _ in range(q):
	x = nextInt()
	i = bisect_right(a, x)
	stdout.write(str(i))
	stdout.write('\n')


def binary(x, n):
	start = 0
	end = n
	while end >= start:
		mid = (start + end) // 2
		if z[mid] > x and z[mid - 1] <= x:
			return mid
		if mid == 0 and z[0] > x:
			return 0
		if mid == n:
			return mid + 1
		if z[mid] > x:
			end = mid
		elif z[mid] <= x:
			start = mid + 1
n = int(input())
z = sorted(map(int, input().split()))
d = dict()
for i in range(int(input())):
	x = int(input())
	if d.get(x) == None:
		d[x] = binary(x, n - 1)
	print(d[x])


import bisect
t = int
u = input
shop = t(u())
prices2 = [t(x) for x in u().split(' ')]
prices2.sort()
for i in range(t(u())):
	print(bisect.bisect(prices2, t(u())))


import bisect
n = int(input())
x = list(map(int, input().split()))
q = int(input())
x.sort()
x0 = min(x)
x1 = max(x)
for i in range(q):
	m = int(input())
	if m < x0:
		print(0)
	elif m > x1:
		print(n)
	else:
		print(bisect.bisect_left(x, m + 1))


n = int(input())
shops = list(map(int, input().split()))
shops.sort()
d = int(input())
res = []
for j in range(d):
	a = int(input())
	hight = n
	low = 0
	while hight > low:
		mid = low + (hight - low) // 2
		if shops[mid] > a:
			hight = mid
		else:
			low = mid + 1
	res.append(low)
for i in res:
	print(i)


def binary_search(array, y, low, high):
	if y >= array[high]:
		return high + 1
	elif y < array[low]:
		return low
	else:
		mid = (low + high) // 2
		if y >= array[mid]:
			return binary_search(array, y, mid + 1, high)
		else:
			return binary_search(array, y, low, mid - 1)
n = int(input())
price = sorted(list(map(int, input().split())))
k = int(input())
money = []
for _ in range(k):
	money.append(int(input()))
for i in money:
	print(binary_search(price, i, 0, n - 1))


a = int(input())
b = sorted(list(map(int, input().split())))
from bisect import bisect as ba
for j in range(int(input())):
	print(ba(b, int(input())))


n = int(input())
x = sorted(list(map(int, input().split()))) + [10 ** 18]
m = int(input())
for j in range(m):
	q = int(input())
	(l, r) = (0, n - 1)
	for i in range(300):
		mid = (l + r) // 2
		if x[mid] <= q:
			l = mid + 1
		else:
			r = mid
	print(l)


import sys
from random import choice, randint
inp = sys.stdin.readline
out = sys.stdout.write
flsh = sys.stdout.flush
sys.setrecursionlimit(10 ** 9)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def MI():
	return map(int, inp().strip().split())

def LI():
	return list(map(int, inp().strip().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]

def LI_():
	return [int(x) - 1 for x in inp().strip().split()]

def LF():
	return [float(x) for x in inp().strip().split()]

def LS():
	return inp().strip().split()

def I():
	return int(inp().strip())

def F():
	return float(inp().strip())

def S():
	return inp().strip()

def pf(s):
	return out(s + '\n')

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def main():
	n = I()
	x = LI()
	x.sort()
	mx = x[-1]
	dp = [0] * (mx + 1)
	for i in range(n):
		dp[x[i]] = i + 1
	for i in range(1, mx + 1):
		if dp[i] == 0:
			dp[i] = dp[i - 1]
	q = I()
	for i in range(q):
		m = I()
		if m >= mx:
			pf(str(dp[-1]))
		else:
			pf(str(dp[m]))
main()


n = int(input())
price = [int(x) for x in input().split()]
q = int(input())
day = []
for i in range(q):
	day.append(int(input()))
price.sort()

def bin_search(li, t):
	l = 0
	r = len(li)
	while r - l > 1:
		m = (l + r) // 2
		if t < li[m]:
			r = m
		else:
			l = m
	return l
for i in range(q):
	if day[i] >= price[0]:
		print(bin_search(price, day[i]) + 1)
	else:
		print('0')


import bisect
input()
x = sorted(map(int, input().split()))
q = int(input())
ans = ''
for i in range(q):
	m = int(input())
	ans += str(bisect.bisect_right(x, m)) + '\n'
print(ans)


def arr_inp():
	return [int(x) for x in input().split()]
from collections import *
(n, x, q) = (int(input()), arr_inp(), int(input()))
x.sort()
c = Counter(x)
(memo, count) = (defaultdict(lambda : 0), 0)
for i in range(1, x[-1] + 1):
	if c[i] != 0:
		count += c[i]
	memo[i] = count
for j in range(q):
	m = int(input())
	if m > x[-1]:
		m = x[-1]
	print(memo[m])


n = int(input())
pri = sorted(list(map(int, input().split()))) + [10 ** 19]
q = int(input())
ans = [0] * q
from bisect import bisect_right
for i in range(q):
	num = int(input())
	ans[i] = bisect_right(pri, num)
print('\n'.join(map(str, ans)))


n = int(input())
c = list(map(int, input().split()))
q = int(input())
c.sort()
l = len(c)
for i in range(q):
	m = int(input())
	first = 0
	last = n - 1
	while first <= last:
		mid = (first + last) // 2
		if m >= c[mid]:
			first = mid + 1
		else:
			last = mid - 1
	if c[mid] <= m:
		print(mid + 1)
	else:
		print(mid)


def bs(p, maxinput, target):
	lo = 0
	hi = maxinput
	while lo + 1 < hi:
		mid = (lo + hi) // 2
		if p[mid] <= target:
			lo = mid
		else:
			hi = mid
	if p[lo] > target:
		return lo
	return hi

def linear(p, target):
	count = 0
	for x in p:
		if x > target:
			break
		count += 1
	return count
n = int(input())
prices = list(map(int, input().split()))
q = int(input())
prices = sorted(prices)
for a0 in range(q):
	current = int(input())
	print(bs(prices, n, current))


z = [0] * 100001
a = int(input())
for i in map(int, input().split()):
	z[i] += 1
for i in range(1, 100001):
	z[i] = z[i] + z[i - 1]
for i in ' ' * int(input()):
	print(z[min(int(input()), 100000)])


import bisect
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	z = int(input())
	idx = bisect.bisect_right(x, z)
	print(idx)


import bisect
n = int(input())
x = sorted(map(int, input().split()))
q = int(input())
m = list((int(input()) for _ in range(q)))
for i in m:
	print(bisect.bisect_right(x, i))


n = int(input())
s = [int(i) for i in input().split()]
t = max(s)
a = [0] * (t + 1)
for i in s:
	a[i] = a[i] + 1
for i in range(1, t):
	a[i] = a[i] + a[i - 1]
for i in range(int(input())):
	m = int(input())
	if m >= t:
		print(n)
	else:
		print(a[m])


def bs(a, c):
	l = 0
	r = n - 1
	while l <= r:
		m = l + (r - l) // 2
		if c < a[m]:
			r = m - 1
		else:
			l = m + 1
	return r + 1
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
for i in range(q):
	c = int(input())
	print(bs(a, c))


def count(x, n, b):
	start = 0
	end = n - 1
	ans = 0
	while start <= end:
		mid = (start + end) // 2
		if x[mid] <= b:
			start = mid + 1
			ans = mid + 1
		else:
			end = mid - 1
	return ans
n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	b = int(input())
	print(count(x, n, b))


from bisect import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	m = int(input())
	print(bisect(a, m))


n = int(input())
str = input()
tokens = str.split(' ')
x = []
for token in tokens:
	x.append(int(token))
x.sort()
num_shops = {}
pos = 1
val = 0
for i in x:
	for j in range(pos, i):
		num_shops[j] = val
	val += 1
	pos = i
for j in range(i, 100001):
	num_shops[j] = val
q = int(input())
for i in range(0, q):
	m = int(input())
	if m > 100000:
		print(len(x))
	else:
		print(num_shops[m])


def UpperBound(A, key):
	left = -1
	right = len(A)
	while right > left + 1:
		middle = (left + right) // 2
		if A[middle] > key:
			right = middle
		else:
			left = middle
	return right
n = int(input())
N = sorted(list(map(int, input().split())))
q = int(input())
M = [0] * q
for i in range(q):
	m = int(input())
	print(UpperBound(N, m))


import bisect
input()
x = sorted([int(i) for i in input().split()])
q = int(input())
for _ in range(q):
	c = int(input())
	print(bisect.bisect(x, c))


n = int(input())
a = list(map(int, input().split()))
c = [0] * (10 ** 5 + 1)
d = [0] * (10 ** 5 + 1)
for i in range(n):
	c[a[i]] += 1
for i in range(1, 10 ** 5 + 1):
	d[i] += d[i - 1] + c[i]
q = int(input())
for i in range(q):
	t = int(input())
	print(n if t > 10 ** 5 else d[t])


from sys import stdin

def lower_bound(nums, target):
	(l, r) = (0, len(nums) - 1)
	while l <= r:
		mid = l + (r - l) // 2
		if nums[mid] > target:
			r = mid - 1
		else:
			l = mid + 1
	return l

def main():
	global a
	log = int(stdin.readline())
	a = [int(x) for x in stdin.readline().strip().split()]
	a.sort()
	cases = int(stdin.readline())
	while cases != 0:
		num = int(stdin.readline())
		print(lower_bound(a, num))
		cases -= 1
main()


from bisect import bisect_right
n = int(input())
X = [int(i) for i in input().split()]
q = int(input())
X.sort()
a = {}
for i in range(q):
	m = int(input())
	if m in a:
		print(a[m])
	else:
		t = bisect_right(X, m)
		a[m] = t
		print(t)


n = int(input())
x = [int(x) for x in input().split()]
q = int(input())
m = []
for i in range(q):
	y = int(input())
	m.append(y)
x.sort()
maxX = max(x)
table = {}
for i in range(x[0]):
	table[i] = 0
for j in range(n - 1):
	for i in range(x[j], x[j + 1]):
		table[i] = j + 1
for a in m:
	if a < maxX:
		print(table[a])
	else:
		print(n)


def fun(lst, ele):
	a = 0
	b = len(lst) - 1
	while a <= b:
		m = a + (b - a) // 2
		if lst[m] <= ele:
			a = m + 1
		else:
			b = m - 1
	if lst[m] <= ele:
		return m + 1
	else:
		return m
n = int(input())
l = list(map(int, input().split()))
l.sort()
p = int(input())
for _ in range(p):
	q = int(input())
	res = fun(l, q)
	print(res)


N = int(input())
shops = list(map(int, input().split()))
D = int(input())
ans = []
cnt = []
for i in range(100005):
	cnt.append(0)
	ans.append(0)
for e in shops:
	cnt[e] += 1
ans[0] = 0
for i in range(1, 100005):
	ans[i] = ans[i - 1] + cnt[i]
for i in range(D):
	query = min(int(input()), 100000)
	print(ans[query])


n = int(input())
a = list(map(int, input().split()))
q = int(input())
a.sort()
for _ in range(q):
	p = 0
	r = int(input())
	(start, end) = (0, n - 1)
	if a[-1] <= r:
		print(n)
		continue
	if a[0] > r:
		print(0)
		continue
	while start <= end:
		mid = (start + end) // 2
		if a[mid] <= r and a[mid + 1] > r:
			print(mid + 1)
			p = p + 1
			break
		if a[mid] <= r and a[mid + 1] <= r:
			start = mid + 1
		if a[mid] > r:
			end = mid - 1
	if p == 0:
		print('0')


from bisect import bisect_right
a = input()
prices = list(map(int, input().split()))
prices.sort()
for i in range(int(input())):
	b = int(input())
	print(bisect_right(prices, b))


from sys import stdin
from bisect import *
input = stdin.readline

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	for _ in ' ' * int(input()):
		print(bisect_right(a, int(input())))
main()


import bisect
n = int(input())
x = list(map(int, input().split()))
x.sort()
for f in range(int(input())):
	m = int(input())
	print(bisect.bisect_right(x, m))


import bisect
n = int(input())
prices = list(map(int, input().split(' ')))
prices.sort()
q = int(input())
for day in range(q):
	m = int(input())
	print(bisect.bisect(prices, m))


import bisect
k = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
for i in range(q):
	n = int(input())
	try:
		p = bisect.bisect_right(a, n, lo=0, hi=k)
		print(p)
	except:
		print(k)


n = int(input())
a = list(map(int, input().split()))
end = max(a) + 1
info = [0 for i in range(end)]
for i in range(n):
	info[a[i]] += 1
for i in range(1, end):
	info[i] = info[i] + info[i - 1]
for i in range(int(input())):
	number = int(input())
	if number > end - 1:
		print(n)
	else:
		print(info[number])


import sys

def binary_search(l: list, less_or_equal: int) -> int:

	def bs_internal(from_, to, item):
		if to - from_ < 2:
			return from_
		pivot = (from_ + to) // 2
		if l[pivot] <= item:
			return bs_internal(pivot, to, item)
		else:
			return bs_internal(from_, pivot, item)
	result = bs_internal(0, n, less_or_equal)
	if l[result] > less_or_equal:
		return -1
	return result
n = int(sys.stdin.readline())
prices = sorted((int(x) for x in sys.stdin.readline().split()))
q = int(sys.stdin.readline())
for _ in range(q):
	amount = int(sys.stdin.readline())
	print(binary_search(prices, amount) + 1)


arg = int(input())
list1 = list(map(int, input().strip().split()))
hashmap = [0 for a in range(0, 100001)]
for a in range(0, arg):
	hashmap[list1[a]] += 1
for d in range(1, 100001):
	hashmap[d] += hashmap[d - 1]
n = int(input())
for d in range(0, n):
	i = int(input())
	if i > 100000:
		print(hashmap[-1])
	else:
		print(hashmap[i])


s = int(input())
l = list(map(int, input().rstrip().split(' ')))
f = l.copy()
f.sort()
last = 0
res = []
j = 0
ma = max(l)
for i in f:
	r = i - last
	for ai in range(r):
		res.append(j)
	last = i
	j = j + 1
d = int(input())
while d:
	z = int(input())
	if z >= ma:
		print(s)
	else:
		print(res[z])
	d = d - 1


n = int(input())
v = sorted(list(map(int, input().split())))
q = int(input())
ans = ''

def tap(x):
	global n, v
	h = 0
	t = n - 1
	ret = 0
	while h <= t:
		mid = (h + t) // 2
		if v[mid] <= x:
			h = mid + 1
			ret = max(ret, h)
		else:
			t = mid - 1
	return ret
while q > 0:
	q -= 1
	x = int(input())
	ans += str(tap(x)) + '\n'
print(ans)


n = int(input())
lst = sorted(list(map(int, input().split())))
for i in range(int(input())):
	d = int(input())
	l = 0
	u = n - 1
	while l <= u:
		m = (l + u) // 2
		if lst[m] <= d:
			l = m + 1
		else:
			u = m - 1
	print(l)


def binary_search(A, x):
	L = 0
	R = len(A) - 1
	while R - L > 3:
		M = (L + R) // 2
		if A[M] <= x:
			L = M
		else:
			R = M
	for ans in range(R, L - 1, -1):
		if A[ans] <= x:
			return ans
	return -1
n = int(input())
A = sorted([int(x) for x in input().split()])
for q in range(int(input())):
	print(binary_search(A, int(input())) + 1)


import itertools
n = int(input())
x = [0] * 100001
for i in map(int, input().split()):
	x[i] += 1
x = list(itertools.accumulate(x))
for _ in range(int(input())):
	print(x[min(int(input()), 100000)])


n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	m = int(input())
	(l, r) = (-1, n)
	while r - l > 1:
		mid = (l + r) // 2
		if a[mid] <= m:
			l = mid
		else:
			r = mid
	print(l + 1)


n = int(input())
a = list(map(int, input().split()))
b = int(input())
c = []
for i in range(b):
	k = int(input())
	c.append(k)
a.sort()

def fun(a, k):
	if len(a) >= 2 and a[0] < k < a[1]:
		print(1)
	elif k >= a[len(a) - 1]:
		print(len(a))
	else:
		low = 0
		high = len(a) - 1
		ans = 0
		while low <= high:
			mid = low + (high - low) // 2
			if a[mid] == k and a[mid + 1] > k or a[mid] < k < a[mid + 1]:
				ans = mid + 1
				break
			elif a[mid] > k:
				high = mid - 1
			else:
				low = mid + 1
		print(ans)
for i in c:
	if i < a[0]:
		print(0)
	else:
		fun(a, i)


import bisect
n = int(input())
nn = list(map(int, input().rstrip().split()))
m = int(input())
arr = []
for i in range(m):
	arr.append(int(input()))
nn.sort()
for i in arr:
	print(bisect.bisect(nn, i))


from bisect import *
N = int(input())
shop = list(map(int, input().split()))
D = int(input())
shop.sort()
for d in range(D):
	money = int(input())
	print(bisect_right(shop, money))


from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write

def binarySearch(value):
	high = n - 1
	low = 0
	ind = -1
	while high >= low:
		mid = (high + low) // 2
		if x[mid] <= value:
			ind = mid
			low = ind + 1
		else:
			high = mid - 1
	return ind
n = int(cin())
x = list(map(int, cin().split()))
q = int(cin())
x.sort()
for _ in range(q):
	m = int(cin())
	cout(str(binarySearch(m) + 1) + '\n')


import bisect
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
t = int(input())
for _ in range(t):
	m = int(input())
	print(bisect.bisect_right(a, m))


n = int(input())
li = sorted(list(map(int, input().split())))
m = int(input())
for i in range(m):
	c = int(input())
	l = -1
	r = n
	while r > l + 1:
		mid = (l + r) // 2
		if li[mid] <= c:
			l = mid
		else:
			r = mid
	print(l + 1)


def binpoisk(d, n):
	global x
	l = 0
	r = n
	while r != l:
		mid = (r + l) // 2
		if d >= x[mid]:
			l = mid + 1
		else:
			r = mid
	return l - 1
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	m = int(input())
	print(1 + binpoisk(m, n))


def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return high
no_shops = int(input())
prices = list(map(int, input().split()))
days = int(input())
prices.sort()
count = 0
budget_list = {}
for i in range(days):
	budget = int(input())
	if budget in budget_list:
		print(budget_list[budget])
		continue
	searched = binary_search(prices, 0, len(prices) - 1, budget)
	if searched != -1:
		while searched <= no_shops - 2 and prices[searched] == prices[searched + 1]:
			searched += 1
		print(searched + 1)
		budget_list[budget] = searched + 1
	else:
		print(0)


import math
n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
x.append(0)
for i in range(q):
	m.append(int(input()))
x.sort()
x.append(math.pow(10, 9) + 1)
for a in m:
	l = 0
	r = n
	if a < x[1]:
		print(0)
	elif a >= x[len(x) - 2]:
		print(len(x) - 2)
	else:
		while r > l + 1:
			m = (l + r) // 2
			if x[m] > a:
				r = m
			else:
				l = m
		print(r - 1)


import bisect
shops = int(input())
costs = list(map(int, input().split(' ')))
costs.sort()
days = int(input())
for _ in range(days):
	can_spend = int(input())
	i = bisect.bisect_right(costs, can_spend)
	print(i)


n = int(input())
y = [int(i) for i in input().split()]
q = int(input())
qrs = []
for i in range(q):
	qrs.append(int(input()))
y = sorted(y)
for m in qrs:
	l = 0
	r = n
	while l < r:
		mid = (l + r) // 2
		if y[mid] <= m:
			l = mid + 1
		else:
			r = mid
	print(l)


n = int(input())
shops = input()
shops = list(map(int, shops.split()))
shops.sort()
days = int(input())
for i in range(0, days):
	coins = int(input())
	leftIndex = 0
	rightIndex = n - 1
	if shops[leftIndex] > coins:
		print(0)
	elif coins >= shops[rightIndex]:
		print(n)
	else:
		while leftIndex <= rightIndex:
			center = (rightIndex + leftIndex) // 2
			if shops[center] > coins:
				rightIndex = center - 1
			else:
				leftIndex = center + 1
		print(leftIndex)


dp = [0] * (int(1000000.0) + 1)
s = 0
n = int(input())
for i in map(int, input().split()):
	dp[i] += 1
for i in range(len(dp)):
	s += dp[i]
	dp[i] = s
q = int(input())
for i in (int(input()) for _ in range(q)):
	print(dp[i]) if i <= int(1000000.0) else print(n)


def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
q = int(input())
for _ in range(q):
	a = int(input())
	if a < l[0]:
		print(0)
	else:
		print(binarySearchCount(l, n, a))


from math import floor
input()
li = [int(x) for x in input().split()]
li.sort()
for _ in range(int(input())):
	key = int(input())
	l = 0
	h = len(li) - 1
	fk = 0
	ans = 0
	t = 0
	while l <= h:
		mid = (l + h) // 2
		if li[mid] == key:
			l = mid + 1
		elif li[mid] < key:
			l = mid + 1
		else:
			h = mid - 1
	print(l)


n = int(input())
prices = list(map(int, input().split()))
prices.sort()
dp = dict()
q = int(input())
guess = 0
prev_guess = 0
for i in range(q):
	coin = int(input())
	if str(coin) in dp.keys():
		print(dp[str(coin)])
		continue
	found = False
	count = 0
	low = 0
	high = n - 1
	p = int((low + high) / 2)
	if n > 10000 and prices[10000] == prices[0] + 10000 and (guess == coin - 1) and (prev_guess == coin - 2):
		count = i + 1
		print(count)
		prev_guess = guess
		guess = coin
		continue
	while coin != prices[p]:
		if coin < prices[0]:
			count = 0
			found = True
			break
		elif coin > prices[n - 1]:
			count = n
			found = True
			break
		elif coin < prices[p] and coin > prices[p - 1]:
			count = p
			found = True
			break
		elif coin < prices[p]:
			high = p - 1
		elif coin > prices[p]:
			low = p + 1
		p = int((low + high) / 2)
	if not found:
		temp = prices[p]
		high = n - 1
		low = p
		pend = low
		if p < n - 1001 and prices[p + 1000] == temp:
			while not (pend >= n - 1 or (prices[pend] == temp and prices[pend + 1] != temp)):
				if prices[pend] == temp:
					low = pend + 1
				else:
					high = pend - 1
				pend = int((low + high) / 2)
			count = pend + 1
		else:
			while p < n and prices[p] == temp:
				p += 1
			count = p
	print(count)
	dp[str(coin)] = count
	prev_guess = guess
	guess = coin


k = int(input())
a = list(map(int, input().split()))
a.sort()
l = 0
r = len(a) - 1
for i in range(int(input())):
	f = int(input())
	l = 0
	r = len(a) - 1
	b = 0
	while l <= r:
		b = (l + r) // 2
		if a[b] > f:
			r = b - 1
		else:
			l = b + 1
	if r != k - 1 and f == a[r + 1]:
		r += 1
	print(r + 1)


import bisect
n = int(input())
shops = list(map(int, input().split()))
shops.sort()
ndays = int(input())
for i in range(ndays):
	val = int(input())
	print(bisect.bisect_right(shops, val))


n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
c = []
for i in range(100000):
	c.append(0)
for i in x:
	c[i - 1] += 1
for i in range(1, 100000):
	c[i] += c[i - 1]
for i in range(q):
	if m[i] > 100000:
		print(n)
	else:
		print(c[m[i] - 1])


def bin(a, e):
	if e < a[0]:
		return 0
	if e >= a[-1]:
		return len(a)
	l = -1
	r = len(a)
	while l < r - 1:
		m = (l + r) // 2
		if e >= a[m] and e < a[m + 1]:
			return m + 1
		if a[m] > e:
			r = m
		else:
			l = m
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
m = int(input())
for i in range(m):
	k = int(input())
	print(bin(a, k))


n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	x = int(input())
	l = -1
	r = len(a)
	ans = r // 2
	while r - l > 1:
		ans = l + (r - l) // 2
		if x >= a[ans]:
			l = ans
		else:
			r = ans
	print(l + 1)


import bisect
int(input())
x = sorted([int(_) for _ in input().split()])
for _ in range(int(input())):
	print(bisect.bisect(x, int(input())))


maxCost = 10 ** 5
shops = [0] * (maxCost + 2)
n = int(input())
costs = list(map(int, input().split()))
for cost in costs:
	shops[cost] += 1
counts = [0] * (maxCost + 2)
for i in range(1, maxCost + 1):
	counts[i] = shops[i] + counts[i - 1]
q = int(input())
for i in range(q):
	m = int(input())
	print(counts[min(m, maxCost)])


import bisect as bi
n = int(input())
x = list(map(int, input().split(' ')))
q = int(input())
y = [None] * q
x.sort()
for i in range(0, q):
	y[i] = int(input())
for j in range(0, q):
	print(bi.bisect(x, y[j]))


def search(arr, l, r, x):
	while l < r:
		mid = l + (r - l) // 2
		if arr[mid] <= x and x < arr[mid + 1]:
			return mid
		if arr[mid] > x:
			r = mid
		elif arr[mid] <= x:
			l = mid
	return 0
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	m = int(input())
	if m < x[0]:
		print(0)
	elif m >= x[-1]:
		print(len(x))
	else:
		print(search(x, 0, len(x) - 1, m) + 1)


n = int(input())
x = list(map(int, input().split()))
x.sort(reverse=True)
cur = x[0]
my_dict = {x[0]: n}
for i in range(n):
	if x[i] < cur:
		cur = x[i]
		my_dict.update({cur: n - i})
keys = list(my_dict.keys())
l_keys = len(keys)
mx_key = max(keys)
mn_key = min(keys)
q = int(input())
for qq in range(q):
	m = int(input())
	if m >= mx_key:
		print(n)
	elif m < mn_key:
		print(0)
	else:
		jmin = 0
		jmax = l_keys
		while jmax > jmin + 1:
			j = (jmax + jmin) // 2
			if keys[j] > m:
				jmin = j
			else:
				jmax = j
		if keys[jmin + 1] > m:
			print(my_dict[keys[jmax]])
		else:
			print(my_dict[keys[jmin + 1]])


def bin_search(m):
	i = 0
	j = n - 1
	ans = -1
	while i <= j:
		mid = (i + j) // 2
		if l[mid] <= m:
			i = mid + 1
			ans = mid
		else:
			j = mid - 1
	return ans
n = int(input())
l = list(map(int, input().split()))
l.sort()
for _ in range(int(input())):
	m = int(input())
	p = bin_search(m)
	print(p + 1)


n = int(input())
xs = sorted([int(i) for i in input().split()])
q = int(input())

def build_data_structure():
	global d
	d = [0] * 100001
	can_buy = 0
	for i in range(100001):
		while can_buy < len(xs) and xs[can_buy] <= i:
			can_buy += 1
		d[i] = can_buy

def handle_query(m):
	if m > 100000:
		return len(xs)
	return d[m]
build_data_structure()
for _ in range(q):
	m = int(input())
	print(handle_query(m))


from collections import Counter
N = int(input())
raw = list(map(int, input().split()))
counting_dict = Counter(raw)
length = max(counting_dict.keys())
counting_list = [0] * length
for (key, value) in counting_dict.items():
	counting_list[key - 1] = value
num_list = [0] * length
num_list[0] = counting_list[0]
for i in range(1, len(num_list)):
	num_list[i] = num_list[i - 1] + counting_list[i]
num = int(input())
for n in range(num):
	inp = int(input())
	if inp < length:
		print(num_list[inp - 1])
	else:
		print(N)


def find(m, lst, start, end):
	length = end - start + 1
	if length == 1:
		if m >= lst[start]:
			return start + 1
		return start
	z = start + length // 2
	if lst[z - 1] <= m < lst[z]:
		return z
	elif m >= lst[z]:
		return find(m, lst, z + 1, end)
	elif m < lst[z]:
		return find(m, lst, start, z - 1)

def task(m, n, X):
	if m >= X[n - 1]:
		return n
	elif m < X[0]:
		return 0
	else:
		return find(m, X, 0, n - 1)

def main():
	n = int(input())
	X = sorted(map(int, input().split()))
	print('\n'.join((str(task(int(input()), n, X)) for i in range(int(input())))))
main()


from bisect import bisect
input()
s = sorted(map(int, input().split()))
for _ in range(int(input())):
	a = int(input())
	print(bisect(s, a))


import bisect

def ab():
	k = int(input())
	b = list(map(int, input().split()))
	b = sorted(b)
	c = int(input())
	for i in range(0, c):
		t = int(input())
		p = bisect.bisect_right(b, t)
		print(p)
ab()


n = int(input())
a = [0] * 100100
b = map(int, input().split())
for x in b:
	a[x] += 1
q = int(input())
for j in range(1, 100100):
	a[j] += a[j - 1]
for _ in range(q):
	h = min(100000, int(input()))
	print(a[h])


import bisect
prices = []
n = int(input())
prices = [int(x) for x in input().split(' ')]
prices.sort()
days = int(input())
cache2 = {}
for _ in range(days):
	coins = int(input())
	print(bisect.bisect_right(prices, coins))


from bisect import bisect_right
n = int(input())
price = sorted(map(int, input().split()))
q = int(input())
m = []
for i in range(q):
	print(bisect_right(price, int(input())))


import bisect
input()
a = [int(x) for x in input().split(' ')]
a.sort()
for i in range(int(input())):
	print(bisect.bisect(a, int(input())))


n = int(input())
arr = sorted(list(map(int, input().split())))
dic = {}
for _ in range(int(input())):
	coins = int(input())
	if coins < arr[0]:
		print(0)
	elif coins >= arr[-1]:
		print(n)
	elif coins in dic:
		print(dic.get(coins))
	else:
		(left, right) = (0, n + 1)
		while right - left > 1:
			pivot = (left + right) // 2
			if arr[pivot - 1] > coins:
				right = pivot
			else:
				left = pivot
		print(left)


n = int(input())
s = list(map(int, input().split()))
q = int(input())
s.sort()
y = max(s)
l = [0] * (y + 2)
x = 0
for i in range(n):
	l[s[i]] += 1
for i in range(1, y + 2):
	l[i] += l[i - 1]
for i in range(q):
	m = int(input())
	if m > y:
		print(n)
	else:
		print(l[m])


def searsh(b, do):
	left = 0
	right = len(b) - 1
	while left < right:
		mid = (left + right) // 2
		if b[mid] <= do:
			left = mid + 1
		else:
			right = mid
	return right

def result(b, do):
	result = searsh(b, do)
	if result == len(b) - 1 and do >= b[-1]:
		result += 1
	return result
a = int(input())
b = map(int, input().split())
b = sorted(b)
c = input()
c = int(c)
i = 0
while i < c:
	do = int(input())
	print(result(b, do))
	i += 1


input()
M = 100000 * [0]
m = 0
for x in map(int, input().split()):
	m = max(m, x)
	M[x - 1] += 1
for i in range(1, m):
	M[i] += M[i - 1]
for _ in range(int(input())):
	print(M[min(m, int(input())) - 1])


n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
a.sort()
for Q in range(q):
	val = int(input())
	(lb, ub) = (0, n - 1)
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if a[mid] <= val:
			lb = mid + 1
			ans = mid + 1
		else:
			ub = mid - 1
	print(ans)


n = int(input())
shops = list(map(int, input().split()))
shops.sort()
q = int(input())
for i in range(q):
	m = int(input())
	start = 0
	end = n - 1
	boro = True
	if m > shops[n - 1]:
		boro = False
		ans = n - 1
	elif m < shops[0]:
		boro = False
		ans = 0
	while boro:
		guess = (start + end + 1) // 2
		if end == start:
			ans = end
			break
		elif m < shops[guess]:
			end = guess - 1
		else:
			start = guess
	if m >= shops[ans]:
		ans += 1
	print(ans)


import sys

def read():
	return sys.stdin.readline()

def binsrch(val):
	s = 0
	e = n - 1
	while s <= e:
		mid = int(s + (e - s) / 2)
		if a[mid] <= val:
			s = mid + 1
		else:
			e = mid - 1
	return s
n = int(read())
a = list(map(int, read().split()))
q = int(read())
list.sort(a)
while q > 0:
	val = int(read())
	print(binsrch(val))
	q -= 1


def binarySearch(arr, val, low, high):
	if low > high:
		return -1
	mid = (low + high) // 2
	if arr[mid] == val:
		if mid + 1 >= len(arr):
			return mid
		elif arr[mid + 1] > val:
			return mid
		else:
			return binarySearch(arr, val, mid + 1, high)
	elif arr[mid] < val:
		if mid + 1 >= len(arr):
			return mid
		elif arr[mid + 1] > val:
			return mid
		else:
			return binarySearch(arr, val, mid + 1, high)
	else:
		return binarySearch(arr, val, low, mid - 1)
n = int(input())
s = list(map(int, input().split()))
d = int(input())
c = []
for i in range(d):
	c += [int(input())]
s.sort()
for i in range(d):
	if c[i] < s[0]:
		print(0)
	elif c[i] >= s[-1]:
		print(len(s))
	else:
		print(binarySearch(s, c[i], 0, len(s) - 1) + 1)


import sys
I = sys.stdin.readline
ans = ''
n = int(I())
x = list(map(int, I().split()))
q = int(I().strip())
x.sort()
dp = [0] * (x[-1] + 1)
for i in x:
	dp[i] += 1
for i in range(1, len(dp)):
	dp[i] += dp[i - 1]
for i in range(q):
	c = int(I().strip())
	if c > x[-1]:
		ans += str(n) + '\n'
	else:
		ans += str(dp[c]) + '\n'
print(ans)


shop_num = int(input())
raw_inp = input().split(' ')
shops = [int(i) for i in raw_inp]
shops.sort()
days = int(input())
days_coins = []
for i in range(days):
	days_coins.append(int(input()))

def get_count(coins):
	l = 0
	r = shop_num - 1
	while r > l:
		mid = (l + r + 1) // 2
		if shops[mid] > coins:
			r = mid - 1
		else:
			l = mid
	if shops[0] > coins:
		return 0
	else:
		return l + 1
for coin_num in days_coins:
	print(get_count(coin_num))


def binary(low, high, target):
	while low < high:
		mid = (low + high) // 2
		if bottles[mid] <= target:
			low = mid + 1
		else:
			high = mid
	return low
shops = int(input())
bottles = [int(s) for s in input().split()]
bottles.sort()
days = int(input())
while days > 0:
	days -= 1
	budget = int(input())
	print(binary(0, shops, budget))


n = int(input())
x = list(map(int, input().split(' ')))
x.sort()
q = int(input())
m = list()
for i in range(q):
	m_i = int(input())
	m.append([i, m_i, 0])
m.sort(key=lambda x: x[1])
i = 0
j = 0
count = 0
while j < q:
	if i == n:
		m[j][2] = count
		j += 1
		continue
	if x[i] <= m[j][1]:
		count += 1
		i += 1
	else:
		m[j][2] = count
		j += 1
m.sort(key=lambda x: x[0])
for x in m:
	print(x[2])


import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	b = int(input())
	print(bisect.bisect_right(a, b))


import bisect
n = int(input())
n = list(map(int, input().split()))
n.sort()
for i in range(int(input())):
	print(bisect.bisect(n, int(input())))


def binarysearch(A, key):
	l = -1
	r = len(A)
	while r > l + 1:
		m = (l + r) // 2
		if A[m] > key:
			r = m
		else:
			l = m
	return l
n = int(input())
lst = [int(i) for i in input().split()]
lst.sort()
m = int(input())
t = []
for i in range(m):
	x = int(input())
	t.append(binarysearch(lst, x))
for i in t:
	print(i + 1)


import bisect
n = int(input())
x = [int(a) for a in input().split()]
q = int(input())
x.sort()
for i in range(q):
	m = int(input())
	print(bisect.bisect(x, m))


def firstElemGreater(prices_sorted, coin):
	l = 0
	r = len(prices_sorted) - 1
	x = len(prices_sorted)
	while l <= r:
		mid = (l + r) // 2
		if prices_sorted[mid] <= coin:
			l = mid + 1
		else:
			x = mid
			r = mid - 1
	print(x)
	return

def solve():
	n = int(input())
	prices = [int(x) for x in input().split()]
	days = int(input())
	coins = []
	for i in range(days):
		coins.append(int(input()))
	prices_sorted = sorted(prices)
	for coin in coins:
		firstElemGreater(prices_sorted, coin)
solve()


import sys, threading, os.path
import string
import collections, heapq, math, bisect
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('in.txt'):
		input = open('in.txt', 'r')
	else:
		input = sys.stdin
	n = int(input.readline())
	shops = list(map(int, input.readline().split()))
	days = int(input.readline())
	money_per_day = []
	for i in range(days):
		money_per_day.append(int(input.readline()))
	shops.sort()
	result = []
	for x in money_per_day:
		result.append(bisect.bisect(shops, x))
	output = '\n'.join(map(str, result))
	if os.path.exists('out.txt'):
		open('out.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


a = int(input())
t = list(map(int, input().split()))
t.sort()
for j in range(int(input())):
	y = int(input())
	if y < t[0]:
		print(0)
	elif y >= t[-1]:
		print(a)
	else:
		l = 0
		r = a - 1
		ans = 0
		while l <= r:
			mid = l + (r - l) // 2
			if t[mid] > y:
				if t[mid - 1] < y:
					ans = mid
					break
				else:
					r = mid - 1
			elif t[mid] < y:
				if t[mid + 1] > y:
					ans = mid + 1
					break
				else:
					l = mid + 1
			elif t[mid + 1] > y:
				ans = mid + 1
				break
			else:
				l = mid + 1
		print(ans)


def main():
	num_of_shop = int(input())
	str_prices = input().strip().split(' ')
	prices = sorted([int(i) for i in str_prices])
	number_of_days = int(input())
	for d in range(number_of_days):
		coin = int(input())
		left = 0
		right = num_of_shop - 1
		ans = 0
		while left <= right:
			mid = (left + right) // 2
			if prices[mid] <= coin:
				left = mid + 1
				ans = mid + 1
			else:
				right = mid - 1
		print(ans)
main()


import bisect

def main():
	n = int(input())
	prices = list(map(lambda x: int(x), input().split()))
	prices.sort()
	q = int(input())
	coins = list()
	for _ in range(q):
		coins.append(int(input()))
	for c in coins:
		print(bisect.bisect(prices, c))
main()


def main():
	n = int(input())
	x = list(map(int, input().split(' ')))
	q = int(input())
	size = min(100001, max(x) + 1)
	c = [0] * size
	for i in range(n):
		c[x[i]] += 1
	s = [0] * size
	for i in range(1, size):
		s[i] = s[i - 1] + c[i]
	ans = ''
	for i in range(q):
		m = int(input())
		if m >= size:
			ans += str(n)
		else:
			ans += str(s[m])
		ans += '\n'
	print(ans)
main()


def binary_1(low, high, coins, prices):
	while low < high:
		mid = (low + high) // 2
		if prices[mid] <= coins:
			low = mid + 1
		else:
			high = mid
	return low
n = input()
prices = list(map(int, input().split()))
days = input()
coins = []
prices.sort()
for i in range(int(days)):
	data = int(input())
	coins.append(data)
for i in range(int(days)):
	print(binary_1(0, int(n), coins[i], prices))


def okk(a, b):
	l = 0
	r = len(a) - 1
	while r >= l:
		mid = int(l + (r - l) / 2)
		if a[mid] > b:
			r = mid - 1
		else:
			l = mid + 1
	return r + 1
input1 = input()
input2 = input().split()
input2 = sorted([int(x) for x in input2])
input3 = int(input())
for qn in range(input3):
	input_n = int(input())
	i = okk(input2, input_n)
	print(i)


import bisect
(n, prices, days, known) = (int(input()), sorted(list(map(int, input().split(' ')))), int(input()), dict())
for d in range(days):
	x = int(input())
	if x not in known:
		known[x] = bisect.bisect(prices, x)
	print(known[x])


def sol(q, x):
	if q < x[0]:
		return 0
	(hi, lo) = (len(x) - 1, 0)
	while lo <= hi:
		m = (hi + lo) // 2
		if x[m] <= q:
			lo = m + 1
		elif x[m] > q:
			hi = m - 1
	return lo
input()
x = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	print(sol(int(input()), x))


from bisect import bisect
n = int(input())
lis = list(map(int, input().split()))
q = int(input())
lis.sort()
for i in range(q):
	money = int(input())
	print(bisect(lis, money))


def drink(x, n, a):
	left = 0
	right = n - 1
	c = 0
	while left <= right:
		mid = int((right + left) / 2)
		if x[mid] <= a:
			c = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return c
n = int(input())
x = [int(x) for x in input().split()]
x.sort()
q = int(input())
for i in range(q):
	a = int(input())
	if a < x[0]:
		print(0)
	else:
		print(drink(x, n, a))


from sys import stdin
input = stdin.readline
n = int(input())
a = sorted(map(int, input().split()))
for i in range(int(input())):
	l = 0
	r = n - 1
	m = -1
	t = int(input()) + 1
	while 1:
		v = (l + r) // 2
		if a[v] < t:
			m = v
			l = v + 1
		else:
			r = v - 1
		if l > r:
			break
	print(m + 1)


import sys
import math
import bisect

def int_array(str):
	return [int(i) for i in str.split(' ')]
data_in = sys.stdin.readlines()
prices = sorted(int_array(data_in[1]))
for money_str in data_in[3:]:
	money = int(money_str)
	count = bisect.bisect(prices, money)
	print(count)


n = int(input())
list = input().strip().split()
for i in range(len(list)):
	list[i] = int(list[i])
list.sort()
m = int(input())
for i in range(m):
	c = int(input())
	l = -1
	r = n
	while r > l + 1:
		mid = (l + r) // 2
		if list[mid] <= c:
			l = mid
		else:
			r = mid
	print(l + 1)


import bisect

def myBisect(arr, val):
	lenght = len(arr) - 1
	end = lenght
	start = 0
	while 1:
		if arr[(start + end) // 2] == val:
			if start == end:
				return lenght + 1
			elif arr[(start + end) // 2 + 1] > val:
				return (start + end) // 2 + 1
			else:
				start = (start + end) // 2 + 1
		elif arr[(start + end) // 2] < val:
			start = (start + end) // 2
		elif arr[(start + end) // 2] > val:
			if arr[(start + end) // 2 - 1] <= val:
				return (start + end) // 2
			end = (start + end) // 2
input()
x = sorted(map(int, input().split()))
for j in range(int(input())):
	m = int(input())
	print(bisect.bisect_right(x, m))


n = int(input())
L = list(map(int, input().split()))
m = max(L) + 1
a = [0] * (m + 1)
for i in L:
	a[i] += 1
for i in range(1, m + 1):
	a[i] += a[i - 1]
q = int(input())
while q > 0:
	q = q - 1
	k = int(input())
	if k > m:
		print(n)
	else:
		print(a[k])


import sys

def binarySearch(sortedList, target):
	first = 0
	last = len(sortedList) - 1
	while first < last:
		mid = int((first + last) / 2)
		if sortedList[mid] == target:
			return mid
		elif sortedList[mid] > target:
			last = mid - 1 if mid - 1 > first else first
		else:
			first = mid + 1 if mid + 1 < last else last
	return last

def findIndex(sortedList, numList, target):
	index = binarySearch(sortedList, target)
	if sortedList[index] > target:
		return numList[index - 1]
	else:
		return numList[index]
sys.stdin.readline().strip()
rawInput = sys.stdin.readline().strip()
storePrices = [int(x) for x in rawInput.split(' ')]
storePrices.sort()
numList = []
sortedList = []
for i in range(len(storePrices)):
	if i > 0 and storePrices[i - 1] == storePrices[i]:
		numList[-1] = i + 1
	else:
		numList.append(i + 1)
		sortedList.append(storePrices[i])
mmin = sortedList[0]
mmax = sortedList[-1]
rawInput = sys.stdin.readline().strip()
for i in range(int(rawInput)):
	money = int(sys.stdin.readline().strip())
	if money < mmin:
		print(0)
	elif money >= mmax:
		print(numList[-1])
	else:
		print(findIndex(sortedList, numList, money))


stores = int(input())
prices = sorted(map(int, input().split()))
days = int(input())
moneys = [int(input()) for i in range(days)]
for i in range(days):
	l = -1
	r = len(prices)
	while r > l + 1:
		m = (l + r) // 2
		if prices[m] > moneys[i]:
			r = m
		else:
			l = m
	print(r)


n = int(input())
arr = list()
arr = list(map(int, input().split()))
arr.sort()
arr2 = [0] * 100001
for i in arr:
	arr2[i] += 1
for i in range(1, 100001):
	arr2[i] += arr2[i - 1]
q = int(input())
for i in range(0, q):
	k = int(input())
	if k > 100000:
		print(arr2[100000])
	else:
		print(arr2[k])


n = int(input())
arr = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	coins = int(input())
	(l, r) = (0, n + 1)
	while r - l > 1:
		p = (l + r) // 2
		if arr[p - 1] > coins:
			r = p
		else:
			l = p
	print(l)


def binarySearch(alist, item):
	low = 0
	high = len(alist)
	while low < high:
		mid = (low + high) // 2
		if alist[mid] <= item:
			low = mid + 1
		else:
			high = mid
	return low
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
printing = []
for j in range(q):
	printing.append(binarySearch(x, m[j]))
for z in range(q):
	print(printing[z])


import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
q = int(input())
m = max(arr)
mxn = 10 ** 6 + 10
dp = [0] * mxn
s = 0
c = 0
arr = sorted(arr)
for i in arr:
	diff = i - s
	for j in range(s, s + diff):
		dp[j] = c
	c += 1
	s = i
	dp[i] = c
while i < mxn:
	dp[i] = c
	i += 1
for i in range(q):
	_k = int(input())
	if _k >= m:
		print(n)
		continue
	print(dp[_k])


n = int(input())
arr = list(map(int, input().split()))
s = {}
for i in range(n):
	if arr[i] in s:
		s[arr[i]] += 1
	else:
		s[arr[i]] = 1
r = int(input())
d = []
max1 = 0
for _ in range(r):
	t = int(input())
	d.append(t)
max1 = max(arr)
aa = [0 for i in range(max1 + 1)]
for i in range(1, max1 + 1):
	if i in s:
		aa[i] = aa[i - 1] + s[i]
	else:
		aa[i] = aa[i - 1]
for i in d:
	if i > max1:
		print(n)
	else:
		print(aa[i])


n = int(input())
l = sorted(list(map(int, input().split())))
t = int(input())
while t:
	k = int(input())
	j = -1
	(q, w) = (0, n - 1)
	while q <= w:
		m = (q + w) // 2
		if l[m] <= k:
			j = m
			q = m + 1
		else:
			w = m - 1
	print(j + 1)
	t -= 1


def binarySearch(arr, n, val):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = (left + right) // 2
		if arr[mid] <= val:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
test = int(input())
for i in range(test):
	val = int(input())
	print(binarySearch(arr, n, val))


A = [0] * 100000
N = int(input())
pr = list(map(int, input().split()))
for p in pr:
	A[p - 1] += 1
for i in range(1, 100000):
	A[i] += A[i - 1]
n = int(input())
q = []
for i in range(n):
	q.append(int(input()) - 1)
for i in range(n):
	if q[i] >= 100000:
		print(N)
	else:
		print(A[q[i]])


x = int(input())
a = [int(j) for j in input().split()]
a = sorted(a)
x = int(input())
import bisect
res = []
for i in range(x):
	find = int(input())
	res.append(bisect.bisect_right(a, find))
for i in res:
	print(i)


def get_dp(prices: list, occucences: list):
	max_shops = [0] * 100010
	max_index = 0
	for i in range(1, len(max_shops)):
		if occurences[i] != 0:
			max_shops[i] = occurences[i] + max_shops[max_index]
			max_index = i
		else:
			max_shops[i] = max_shops[max_index]
	return max_shops
n = int(input())
p = list(map(int, input().split(' ')))
q = int(input())
min_money = [int(input()) for i in range(q)]
occurences = [0] * 100010
for i in p:
	occurences[i] += 1
dp = get_dp(p, occurences)
for i in min_money:
	if i >= len(dp):
		print(dp[-1])
	else:
		print(dp[i])


from bisect import *
N = int(input())
shop = list(map(int, input().split()))
days = int(input())
shop.sort()
output = []
for day in range(days):
	cost = int(input())
	output.append(bisect_right(shop, cost))
for o in output:
	print(o)


import sys
import math
from collections import defaultdict
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
n = int(input())
arr = intInp()
arr.sort()
q = int(input())
for i in range(q):
	coin = int(input())
	l = 0
	r = n - 1
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if coin > arr[m]:
			if m == n - 1:
				ans = n
				break
			if coin < arr[m + 1]:
				ans = m + 1
				break
			l = m + 1
		elif coin < arr[m]:
			r = m - 1
		else:
			if m == n - 1 or arr[m + 1] > coin:
				ans = m + 1
				break
			l = m + 1
	if ans == -1:
		print(0)
	else:
		print(ans)


n = int(input())
prices = [int(x) for x in input().split()]
prices.sort()
q = int(input())
for _ in range(q):
	x = int(input())
	l = 0
	r = n
	while l < r:
		mid = (l + r) // 2
		if prices[mid] <= x:
			l = mid + 1
		else:
			r = mid
	print(l)


n = int(input())
x = list(map(int, input().split()))
x = sorted(x)
q = int(input())
ans = [0] * q
rec = []
for i in range(q):
	rec.append((int(input()), i))
rec = sorted(rec)
k = 0
j = 0
while j < n:
	while k < q and rec[k][0] < x[j]:
		ans[rec[k][1]] = j
		k += 1
	j += 1
for i in range(k, q):
	ans[rec[i][1]] = j
for i in range(q):
	print(ans[i])


t = [0] * 100001
n = int(input())
l = [int(j) for j in input().split()]
for i in l:
	t[i] += 1
d = t[0]
for i in range(1, 100001):
	d += t[i]
	t[i] = d
q = int(input())
for i in range(q):
	a = int(input())
	if a > 100000:
		a = 100000
	print(t[a])


import math

def get_primes(prime_supr):
	is_prime = [0] * 2 + [1] * prime_supr
	for i in range(2, int(math.sqrt(prime_supr)) + 1):
		if is_prime[i]:
			for j in range(i * i, prime_supr + 1, i):
				is_prime[j] = 0
	return is_prime
get_int = lambda : map(int, input().split())
n = int(input())
x = {i: 0 for i in range(1, 100001)}
for i in sorted(list(get_int())):
	x[i] += 1
q = int(input())
h = []
z = 0
for i in x.values():
	z += i
	h.append(z)
ans = []
for i in range(q):
	ans.append(h[min(99999, int(input()) - 1)])
for i in ans:
	print(i)


from bisect import bisect_right as bi
from sys import stdin as read
from sys import stdout as out
n = int(read.readline())
x = list(map(int, read.readline().split()))
x.sort()
q = int(read.readline())
for i in range(q):
	l = int(read.readline())
	out.write(str(bi(x, l)))
	out.write('\n')


c = int
p = input
import bisect
p()
x = sorted(map(c, p().split()))
for i in ' ' * c(p()):
	print(bisect.bisect(x, c(p())))


import bisect
n = int(input())
a = sorted([int(i) for i in input().split(' ')])
d = int(input())
x = []
for i in range(d):
	x.append(int(input()))
for j in x:
	print(bisect.bisect(a, j))


nShops = int(input())
shopPrices = list(map(int, input().split()))
shopPrices.sort()
times = int(input())
answers = []

def binarySearch(array, target, carry):
	index = len(array)
	if len(array) == 0:
		return carry
	if index == 1:
		if target < array[0]:
			return carry
		else:
			return carry + 1
	index = index // 2
	if target < array[index]:
		newPrices = array[0:index]
		return binarySearch(newPrices, target, carry)
	else:
		carry += index
		newPrices = array[index:]
		return binarySearch(newPrices, target, carry)

def iterativeBinary(array, target):
	low = 0
	high = len(array) - 1
	while low <= high:
		mid = low + (high - low) // 2
		if array[mid] > target:
			high = mid - 1
		else:
			low = mid + 1
	return low
for time in range(times):
	money = int(input())
	buys = iterativeBinary(shopPrices, money)
	answers.append(buys)
for answer in answers:
	print(answer)


n = int(input())
a = list(map(int, input().split()))
c = []
j = 0
while j < n:
	while len(c) - 1 < a[j]:
		c.append(0)
	c[a[j]] += 1
	j += 1
for i in range(1, len(c)):
	c[i] += c[i - 1]
q = int(input())
for i in range(q):
	m = int(input())
	if m > len(c) - 1:
		print(n)
	else:
		print(c[m])


n = int(input())
p = [0] * 100001
t = [int(x) for x in input().split()]
for a in t:
	p[a] += 1
t = 0
for i in range(100001):
	p[i] += t
	t = p[i]
q = int(input())
for i in range(q):
	m = int(input())
	if m > 100000:
		m = 100000
	print(p[m])


n = int(input())
price = [int(i) for i in input().split()]
q = int(input())
acc = []
for i in range(q):
	k = int(input())
	acc.append(k)
price.sort()

def search(k, arr):
	l = 0
	r = len(arr) - 1
	ans = 0
	while l <= r:
		mid = l + int((r - l) / 2)
		if arr[mid] <= k:
			ans = mid + 1
			l = mid + 1
		else:
			r = mid - 1
	return ans
for j in acc:
	a = search(j, price)
	print(a)


n = int(input())
prices = list(map(int, input().split()))
prices = sorted(prices)
q = int(input())
ans = []
for i in range(q):
	money = int(input())
	(left, right) = (0, n)
	while left < right:
		mid = (left + right) // 2
		if money >= prices[mid]:
			left = mid + 1
		else:
			right = mid
	ans.append(left)
print(*ans, sep='\n')


from bisect import bisect_right as br
n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	p = int(input())
	idx = br(x, p)
	print(idx)


import bisect
n = int(input())
arr = sorted(list(map(int, input().split())))
dp = [0] * (arr[n - 1] + 1)
for i in range(n):
	dp[arr[i]] = i + 1
for i in range(arr[0], arr[n - 1] + 1):
	if dp[i] == 0:
		dp[i] = dp[i - 1]
for i in range(int(input())):
	a = int(input())
	if a >= len(dp):
		print(dp[len(dp) - 1])
	else:
		print(dp[a])


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
n = I()
l = L()
l.sort()
t = I()
for i in range(t):
	a = I()
	print(bisect.bisect_right(l, a))


def binSrch(a):
	global data, n
	l = 0
	r = n
	while r - l > 1:
		mid = (l + r) // 2
		if data[mid] > a:
			r = mid
		else:
			l = mid
	return l
global data, n
n = int(input())
data = [int(i) for i in input().split()]
data.sort()
q = int(input())
for i in range(q):
	box = int(input())
	ind = binSrch(box)
	if data[ind] <= box:
		print(ind + 1)
	else:
		print(0)


import sys
n = int(input())
arr = sorted(list(map(int, input().split())))
q = int(input())
arr2 = []
for i in range(q):
	coin = int(input())
	arr2.append(coin)

def binsrc(item):
	start = 0
	end = n - 1
	while start <= end:
		mid = int((start + end) / 2)
		if arr[mid] <= item:
			start = mid + 1
		else:
			end = mid - 1
	return end + 1
for i in range(q):
	print(binsrc(arr2[i]))


from bisect import *
n = int(input())
l = list(map(int, input().split()))
l.sort()
q = int(input())
for _ in range(q):
	print(bisect_right(l, int(input())))


def fun(l, r, x):
	t = 0
	while l <= r:
		m = l + r >> 1
		if a[m] <= x:
			t = m
			if m == n - 1 or a[m + 1] > x:
				break
			l = m + 1
		else:
			r = m - 1
	return t
n = int(input())
a = list(map(int, input().split()))
m = int(input())
a.sort()
ans = 0
for _ in range(m):
	s = int(input())
	if s < a[0]:
		print(0)
		continue
	ans = fun(0, n - 1, s)
	print(ans + 1)


import bisect
n = int(input())
lst = list((int(num) for num in input().split()))[:n]
lst = sorted(lst)
q = int(input())
for i in range(0, q):
	y = int(input())
	if lst[0] > y:
		print('0')
	elif y >= lst[n - 1]:
		print(n)
	else:
		print(bisect.bisect_right(lst, y, 0, n))


n = int(input())
arr = list(map(int, input().split()))
p = max(arr) + 1
dp = [0] * p
for a in arr:
	dp[a] += 1
for d in range(1, p):
	dp[d] += dp[d - 1]
q = int(input())
for _ in range(q):
	x = int(input())
	print(dp[min(x, p - 1)])


from bisect import bisect_right
str1 = '5'
str2 = '3 10 8 6 11'
str3 = '4'
str1 = input()
str2 = input()
str3 = input()
n = int(str1)
x = sorted(list(map(int, str2.split())))
q = int(str3)
y = list(map(int, '1 10 3 11'.split()))
y = list(range(q))
for i in range(q):
	y[i] = int(input())
q = 4
for m in y:
	print(bisect_right(x, m))


n = int(input())
price = list(map(int, input().split()))
price.sort()
outlist = []
for i in range(int(input())):
	l = 0
	r = len(price)
	curr = int(input())
	mid = int((l + r) / 2)
	while r - l > 1:
		if price[mid] <= curr:
			l = mid
		else:
			r = mid
		mid = int((l + r) / 2)
	if curr >= price[l]:
		outlist.append(l + 1)
	else:
		outlist.append(0)
for i in outlist:
	print(i)


import bisect
n = int(input())
p = list(map(int, input().split()))
p.sort()
q = int(input())
for i in range(q):
	c = int(input())
	print(bisect.bisect_right(p, c))


from operator import itemgetter
n = int(input())
xi = list(map(int, input().split()))
q = int(input())
mxi = [[int(input()), i] for i in range(q)]
ans = [0] * q
xi.sort()
mxi.sort(key=itemgetter(0))
num = 0
for i in range(q):
	for j in range(num, n):
		num = j + 1
		if xi[j] > mxi[i][0]:
			num -= 1
			break
	ans[mxi[i][1]] = num
for i in range(q):
	print(ans[i])


def binsearch(n, ls):
	l = 0
	u = len(ls) - 1
	pos = -1
	while u >= l:
		m = (u + l) // 2
		if ls[m] == n:
			pos = m
			l = m + 1
		elif ls[m] > n:
			u = m - 1
		else:
			l = m + 1
	return l if pos == -1 else pos + 1
n = int(input())
l = [int(i) for i in input().split()]
x = int(input())
inp = []
for i in range(x):
	inp.append(int(input()))
l.sort()
for i in range(x):
	print(binsearch(inp[i], l))


from collections import deque
from collections import Counter
from itertools import permutations
import heapq

def counterExample():
	arr = [1, 3, 4, 1, 2, 1, 1, 3, 4, 3, 5, 1, 2, 5, 3, 4, 5]
	counter = Counter(arr)
	top_three = counter.most_common(3)
	print(top_three)
q = deque()
import math

def find(money, shops):
	p = 0
	a = len(shops)
	while a >= 1:
		while a + p < len(shops) and shops[a + p] <= money:
			p += a
		a //= 2
	if money >= shops[p]:
		return p + 1
	return p

def main():
	n = int(input())
	shops = sorted([int(i) for i in input().split()])
	q = int(input())
	while q >= 1:
		money = int(input())
		print(find(money, shops))
		q -= 1
main()


n = int(input())
x = [int(v) for v in input().split()]
o = []
a = []
q = int(input())
x.sort()
for i in range(q):
	v = int(input())
	a.append(v)

def search(x, i):
	fp = 0
	lp = len(x) - 1
	if i < x[0]:
		return 0
	else:
		while fp <= lp:
			mid = (fp + lp) // 2
			if i < x[mid]:
				lp = mid - 1
			else:
				fp = mid + 1
		return lp + 1
for i in a:
	o.append(search(x, i))
for i in o:
	print(i)


import math, sys, re, itertools
(rs, ri, rai) = (input, lambda : int(input()), lambda : list(map(int, input().split())))
n = ri()
x = rai()
x.sort()
q = ri()
ma = list(map(int, sys.stdin.read().splitlines()))
res = [0] * 100000
i = 0
xi = 0
c = 0
while i < 100000:
	while xi < n and i >= x[xi]:
		c += 1
		xi += 1
	res[i] = c
	i += 1
for m in ma:
	if m >= 100000:
		print(n)
	else:
		print(res[m])


n = int(input())
shops = sorted([int(i) for i in input().split()])
for i in range(int(input())):
	m = int(input())
	if m < shops[0]:
		print(0)
		continue
	elif m >= shops[-1]:
		print(n)
		continue
	else:
		l = 0
		r = n - 1
		while r - l > 1:
			mid = (r + l) // 2
			if m >= shops[mid]:
				l = mid
			elif m < shops[mid]:
				r = mid
		for i in range(min(r + 2, n - 1), max(0, r - 2) - 1, -1):
			if m >= shops[i]:
				print(i + 1)
				break


n = int(input())
x = [int(i) for i in input().strip().split()]
q = int(input())
x.sort()
while q:
	q -= 1
	(low, mid, high) = (0, 0, n)
	v = int(input())
	while low < high:
		mid = (low + high) // 2
		if x[mid] <= v:
			low = mid + 1
		else:
			high = mid
	print(low)


from sys import stdin, stdout, maxsize
n = int(stdin.readline().rstrip())
x = [int(x) for x in stdin.readline().rstrip().split()]
x.sort()
x.append(maxsize)
q = int(stdin.readline().rstrip())
m = [int(stdin.readline().rstrip()) for i in range(q)]
m_sorted = m.copy()
m_sorted.sort()
z = {}
i = 0
for p in m_sorted:
	while (x[i] <= p) & (i <= n):
		i = i + 1
	z[p] = i
for p in m:
	stdout.write(str(z[p]) + '\n')


def a():
	n = int(input())
	s = list(map(int, input().split()))
	q = int(input())
	m = list()
	for i in range(q):
		x = int(input())
		m.append(x)
	s.sort()
	for i in m:
		print(b(s, i, 0, len(s)))

def b(s, x, l, h):
	while l < h:
		mid = (l + h) // 2
		if x < s[mid]:
			h = mid
		else:
			l = mid + 1
	return h
a()


from bisect import bisect
shop_num = int(input())
shop_price = list(map(int, input().split()))
shop_price.sort()
days = int(input())
coins = []
for x in range(days):
	coins.append(int(input()))
for x in coins:
	if x < shop_price[0]:
		print(0)
	else:
		i = bisect(shop_price, x)
		print(i)


import sys
num_shops = list(map(int, list(sys.stdin.readline().strip())))
shop_prices = list(map(int, sys.stdin.readline().split()))
shop_prices.sort()
n = len(shop_prices)
num_days = int(sys.stdin.readline().strip())
for day in range(num_days):
	coins_to_spend = int(sys.stdin.readline().strip())
	(left, right) = (0, n - 1)
	while left < right:
		mid = (left + right) // 2
		if shop_prices[mid] > coins_to_spend:
			right = mid
		else:
			left = mid + 1
	if left == 0 and shop_prices[0] > coins_to_spend:
		print(0)
	elif left == n - 1 and shop_prices[-1] <= coins_to_spend:
		print(n)
	else:
		print(left)


import bisect
n = int(input())
prices = [int(x) for x in input().split()]
prices = sorted(prices)
days = int(input())
for _ in range(days):
	coins = int(input())
	print(bisect.bisect(prices, coins))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
q = int(input())
for i in range(q):
	x = int(input())
	start = 0
	end = n - 1
	ans = -1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] > x:
			end = mid - 1
		else:
			ans = max(ans, mid)
			start = mid + 1
	print(ans + 1)


from sys import stdin, stdout
n = int(stdin.readline())
prices = sorted(list(map(int, stdin.readline().split())))
k = int(stdin.readline())
for i in range(k):
	money = int(stdin.readline())
	l = -1
	r = len(prices)
	while r > l + 1:
		m = (r + l) // 2
		if prices[m] > money:
			r = m
		else:
			l = m
	stdout.write(str(l + 1) + '\n')


shops_count = int(input())
shop_prices = sorted(list(map(int, input().split())))
days_count = int(input())
days_coins = []
for _ in range(days_count):
	days_coins.append(int(input()))
days_coins = sorted(list(enumerate(days_coins)), key=lambda x: x[1])
result = {}
border = 0

def find_next_border(amount):
	global border, shops_count, shop_prices
	while border <= shops_count - 1:
		if shop_prices[border] <= amount:
			border += 1
		else:
			break
	return border
for day in days_coins:
	border = find_next_border(day[1])
	result[day[0]] = border
for k in range(days_count):
	print(result[k])


import bisect
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
q = int(input())
if q > 0:
	for i in range(q):
		x = int(input())
		print(bisect.bisect(a, x))


def binarysearch(l, n, x):
	front = 0
	rear = n - 1
	m = 0
	while front <= rear:
		m = (front + rear) // 2
		if x < l[m]:
			rear = m - 1
		else:
			front = m + 1
			m += 1
	return m
n = int(input())
l = sorted(list(map(int, input().split())))
for i in range(int(input())):
	a = int(input())
	print(binarysearch(l, n, a))


n = int(input())
a = [int(x) for x in input().split()]
m = int(input())
a.append(float('inf'))
a.sort()

def howManyBefore(x, a):
	l = 0
	r = len(a) - 1
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if a[mid] == x:
			l = mid + 1
		elif a[mid] > x:
			ans = mid
			r = mid - 1
		else:
			l = mid + 1
	return ans
for i in range(m):
	x = int(input())
	y = howManyBefore(x, a)
	print(y)


def binarysearch(alist, item):
	first = 0
	last = len(alist)
	while first < last:
		midpoint = (first + last) // 2
		if item < alist[midpoint]:
			last = midpoint
		else:
			first = midpoint + 1
	return first
n = int(input())
price = [int(i) for i in input().split()]
price = sorted(price)
cnt = 0
z = int(input())
coins = []
for i in range(z):
	coins.append(int(input()))
	print(binarysearch(price, coins[i]))


def bin_search(lst, x):
	lower_bound = 0
	upper_bound = len(lst)
	while lower_bound != upper_bound:
		compared_value = (lower_bound + upper_bound) // 2
		if x == lst[compared_value]:
			while compared_value < len(lst) - 1 and x == lst[compared_value + 1]:
				compared_value += 1
			return compared_value + 1
		elif x < lst[compared_value]:
			upper_bound = compared_value
		else:
			lower_bound = compared_value + 1
	return None
n = int(input())
x = sorted([int(i) for i in input().split()])
q = int(input())
dp = [0 for i in range(x[-1] + 1)]
dp[0] = 0
for i in range(1, x[-1] + 1):
	a = bin_search(x, i)
	if a:
		dp[i] = a
	else:
		dp[i] = dp[i - 1]
for _ in range(q):
	a = int(input())
	if a > x[-1]:
		print(dp[-1])
	else:
		print(dp[a])


from sys import *
input = lambda : stdin.readline()
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
n = int(input())
arr = int_arr()
arr.sort()
m = int(input())
lst = []
for i in range(m):
	lst.append(int(input()))
lst1 = sorted(lst)
dic = {}
ct = 0
flag = 1
for i in range(m):
	while flag and lst1[i] >= arr[ct]:
		ct += 1
		dic[lst1[i]] = ct
		if ct >= n:
			flag = 0
	dic[lst1[i]] = ct
for i in lst:
	print(dic[i])


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(councils, a, k):
	summ = 0
	for x in a:
		summ += min(x, councils)
	return summ // councils >= k
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	n = int(input())
	prices = list(read())
	prices.sort()
	q = int(input())
	for i in range(q):
		m = int(input())
		print(bis.bisect_right(prices, m))
for _ in range(1):
	solve()


n = int(input())
arr = list(map(int, input().split()))
n = len(arr)
arr = sorted(arr)
for _ in range(int(input())):
	x = int(input())
	(lb, ub) = (0, n - 1)
	while lb <= ub:
		mid = (lb + ub) // 2
		if arr[mid] == x:
			lb = mid + 1
		elif x < arr[mid]:
			ub = mid - 1
		else:
			lb = mid + 1
	print(ub + 1)


def binary_search(a, x):
	start = 0
	end = len(a)
	while start < end:
		mid = (start + end) // 2
		if a[mid] > x:
			end = mid
		else:
			start = mid + 1
	return start
n = int(input())
x = [int(i) for i in input().split()]
x.sort()
q = int(input())
for i in range(0, q):
	m = int(input())
	print(binary_search(x, m))


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
q = int(input())
from bisect import bisect_right
for _ in range(q):
	k = int(input())
	print(bisect_right(l, k))


import bisect
input()
arr = sorted(map(int, input().split()))
for i in range(int(input())):
	k = int(input())
	print(bisect.bisect_right(arr, k))


n = int(input())
l = list(map(int, input().split()))
d = max(l)
q = int(input())
a = [0] * (d + 1)
for i in l:
	a[i] += 1
for i in range(1, d + 1):
	a[i] += a[i - 1]
for _ in range(q):
	c = int(input())
	print(a[min(c, d)])


n = int(input())
answers = []
prices = list(map(int, input().split()))
prices.sort()
test_index = 0
for money in range(max(prices)):
	if test_index < n:
		while money >= prices[test_index]:
			test_index += 1
	answers.append(test_index)
q = int(input())
for i in range(q):
	req = int(input())
	if req >= len(answers):
		print(n)
	else:
		print(answers[req])


n = int(input())
s = list(map(int, input().split()))
s.sort()
q = int(input())
p = {}
t = []
ans = []
for i in range(q):
	m = int(input())
	p[m] = -1
	ans.append(m)
	t.append(m)
t.sort()
(i, j) = (0, 0)
while j < q:
	if i == n or s[i] > t[j]:
		p[t[j]] = i
		j += 1
	else:
		i += 1
for i in ans:
	print(p[i])


import sys
n = int(input())
mx = int(100000.0)
price = [0 for _ in range(mx + 1)]
s = [0 for _ in range(mx + 1)]
p = list(map(int, input().split()))
for v in p:
	price[v] += 1
for i in range(1, mx + 1):
	s[i] = s[i - 1] + price[i]
for _ in range(int(input())):
	money = int(sys.stdin.readline())
	if money > mx:
		sys.stdout.write('{}\n'.format(s[mx]))
	else:
		sys.stdout.write('{}\n'.format(s[money]))


def bins(arr, x, l, r):
	if l == r:
		if arr[l] <= x:
			return l + 1
		else:
			return l
	if l < r:
		mid = (l + r) // 2
		if arr[mid] <= x:
			return bins(arr, x, mid + 1, r)
		else:
			return bins(arr, x, l, mid)
	return 0
n = int(input())
p = [int(x) for x in input().split()]
p.sort()
q = int(input())
for i in range(q):
	m = int(input())
	print(bins(p, m, 0, n - 1))


import bisect
n = int(input())
arr = list(map(int, input().split()))
m = int(input())
arr.sort()
for i in range(m):
	rs = int(input())
	ans = bisect.bisect(arr, rs)
	print(ans)


from bisect import bisect

def main():
	input()
	str_prices = input().strip().split(' ')
	prices = sorted([int(i) for i in str_prices])
	number_of_days = int(input())
	for d in range(number_of_days):
		coin = int(input())
		print(bisect(prices, coin))
main()


n = int(input())
num = sorted(map(int, input().split()))

def bs(val):
	l = 0
	r = n
	while l < r:
		mid = (l + r) // 2
		if num[mid] > val:
			r = mid
		else:
			l = mid + 1
	return l
for i in range(int(input())):
	print(bs(int(input())))


from bisect import bisect
n = int(input())
shops = list(map(int, input().split()))
shops.sort()
q = int(input())
for k in range(q):
	qi = int(input())
	n = bisect(shops, qi)
	print(n)


from bisect import bisect
(a, b, c) = (int(input()), sorted(list(map(int, input().split()))), [])
for i in range(int(input())):
	c.append(bisect(b, int(input())))
print(*c, sep='\n')


n = int(input())
l = [int(x) for x in input().split()]
l.sort()
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))

def getindex(elt, l):
	low = 0
	high = len(l) - 1
	while high >= low:
		i = (high + low) // 2
		if high == low:
			if elt < l[low]:
				return -1
			else:
				return low
		if elt >= (l[i] and l[i + 1]):
			low = i + 1
		elif elt >= l[i] and elt < l[i + 1]:
			return i
		elif i == 0:
			high = 0
		else:
			high = i - 1
for elt in m:
	print(getindex(elt, l) + 1)


from bisect import bisect
n = int(input())
shops = sorted(list(map(int, input().split())))
q = int(input())
res = ''
for _ in range(q):
	res += str(bisect(shops, int(input()))) + '\n'
print(res)


import bisect
n = int(input())
s = list(map(int, input().split()))
s.sort()
for i in range(int(input())):
	k = int(input())
	count = bisect.bisect_right(s, k, 0, n)
	print(count)


def binary(a, m):
	l = 0
	r = len(a) - 1
	ans = len(a)
	while l <= r:
		mid = l + (r - l) // 2
		if a[mid] > m:
			ans = mid
			r = mid - 1
		else:
			l = mid + 1
	return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
for i in range(q):
	x = int(input())
	print(binary(a, x))


def bin_search(x, left, right, num_list):
	if right - left <= 1:
		while x == num_list[left + 1]:
			left += 1
		return left + 1
	else:
		middle = (right + left) // 2
		if x >= num_list[middle]:
			return bin_search(x, middle, right, num_list)
		else:
			return bin_search(x, left, middle, num_list)
n = int(input())
prices = sorted(list(map(int, input().split())))
q = int(input())
money = list(map(lambda x: int(input()), range(q)))
for coins in money:
	if coins < prices[0]:
		print(0)
	elif coins >= prices[n - 1]:
		print(n)
	else:
		print(bin_search(coins, 0, n - 1, prices))


import sys
import bisect
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return list(map(int, input().split()))

def solve(x, arr):
	_min = x[0]
	_max = x[-1]
	for a in arr:
		if a < _min:
			print(0)
		elif a > _max:
			print(len(x))
		else:
			i = bisect.bisect(x, a)
			print(i)
inp()
x = sorted(inlt())
n = inp()
arr = []
for i in range(n):
	arr.append(inp())
solve(x, arr)


import bisect
n = int(input())
x = [int(x) for x in input().split()]
q = int(input())
x.sort()
s = ''
for i in range(q):
	m = int(input())
	t = bisect.bisect(x, m)
	s += str(t) + '\n'
print(s)


def countgreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
arr = [3, 3, 4, 7, 7, 7, 11, 13, 13]
n = len(arr)
k = 7
num_stores = int(input())
prices = list(map(int, input().split()))
prices.sort()
num_days = int(input())
for i in range(num_days):
	_count_greater = countgreater(prices, len(prices), int(input()))
	print(len(prices) - _count_greater)


def findIndex(num, li, lo, hi):
	while lo < hi:
		mid = lo + hi >> 1
		if num < li[mid]:
			hi = mid
		else:
			lo = mid + 1
	return hi
n = int(input())
prices = sorted(map(int, input().split()))
q = int(input())
for _ in range(q):
	money = int(input())
	options = findIndex(money, prices, 0, len(prices))
	print(options)


import sys
from bisect import bisect_right
num_shops = int(sys.stdin.readline())
prices = list(map(int, sys.stdin.readline().split()))
prices.sort()
num_days = int(sys.stdin.readline())
for _ in range(num_days):
	money = int(sys.stdin.readline())
	print(bisect_right(prices, money))


from collections import Counter

def binarysearch(x, t):
	left = 0
	right = len(x)
	while left < right:
		middle = (left + right) // 2
		if x[middle] <= t:
			left = middle + 1
		else:
			right = middle
	return left
n = int(input())
x = [int(i) for i in input().split()]
x.sort()
q = int(input())
m = [int(input()) for i in range(q)]
num = [0] * q
for i in range(q):
	if x[0] > m[i]:
		num[i] = '0'
	elif x[-1] <= m[i]:
		num[i] = str(n)
	else:
		num[i] = str(binarysearch(x, m[i]))
print('\n'.join(num))


import bisect
n = int(input())
a = list(map(int, input().split()))
q = int(input())
a.sort()
for _ in range(q):
	x = int(input())
	v = bisect.bisect(a, x)
	print(v)


I = lambda : map(int, input().split())

def cal(res, n, a):
	x = 0
	start = 1
	end = a[0]
	a.append(0)
	for j in range(n):
		for i in range(start, end):
			res[i] = x
		x += 1
		start = end
		end = a[j + 1]
	return res
n = int(input())
a = sorted(list(I()))
res = [n] * 100000
cal(res, n, a)
for i in range(int(input())):
	yy = int(input())
	if yy >= 100000:
		print(n)
	else:
		print(res[yy])


def position(a, b):
	if b < a[0]:
		return 0
	elif b >= a[n - 1]:
		return n
	else:
		(l, r) = (0, len(a) - 1)
		while l <= r:
			mid = (l + r) // 2
			if b >= a[mid] and b < a[mid + 1]:
				return mid + 1
			elif a[mid] <= b:
				l = mid + 1
			else:
				r = mid - 1
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	b = int(input())
	c = position(a, b)
	print(c)


n = int(input())
x = list(map(int, input().split()))
xs = set(x)
m = max(xs)
xn = [0] * (m + 1)
for i in range(n):
	xn[x[i]] += 1
dp = [0] * (m + 1)
for i in range(1, m + 1):
	if i in xs:
		dp[i] = dp[i - 1] + xn[i]
	else:
		dp[i] = dp[i - 1]
for i in range(int(input())):
	q = int(input())
	if q > m:
		print(dp[m])
	else:
		print(dp[q])


n = int(input())
x = list(map(int, input().split(' ')))
q = int(input())
m = [0] * q
for i in range(0, q):
	m[i] = int(input())
x.sort()
d = [0] * x[-1]
for i in x:
	d[i - 1] = d[i - 1] + 1
a = [0] * len(d)
a[0] = d[0]
for i in range(1, len(d)):
	a[i] = a[i - 1] + d[i]
for i in m:
	if i > len(d):
		print(len(x))
	else:
		print(a[i - 1])


import bisect
import math
nancy = int(input())
alpha = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	print(bisect.bisect_right(alpha, int(input()), 0, nancy))


from bisect import bisect_left, bisect_right
br = bisect_right
bl = bisect_left
input()
s = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	money = int(input())
	print(br(s, money))


n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
m = list(map(int, [input() for i in range(q)]))

def lower_bound(nums, target):
	(l, r) = (0, len(nums) - 1)
	while l <= r:
		mid = l + (r - l) // 2
		if nums[mid] > target:
			r = mid - 1
		else:
			l = mid + 1
	return l
for i in range(q):
	print(lower_bound(x, m[i]))


n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())

def binarySearch(value, xList):
	low = 0
	high = len(xList)
	while low != high:
		mid = (low + high) // 2
		if xList[mid] <= value:
			low = mid + 1
		else:
			high = mid
	return low
for i in range(q):
	m = int(input())
	print(binarySearch(m, x))


import sys

def binary_search(val, arr):
	left = 0
	right = len(arr) - 1
	ans = -1
	while left <= right:
		mid = left + (right - left) // 2
		if arr[mid] <= val:
			left = mid + 1
		else:
			ans = mid
			right = mid - 1
	return ans if ans != -1 else len(arr)

def main():
	sys.stdin.readline()
	inpt = [int(i) for i in sys.stdin.readline().strip().split()]
	inpt.sort()
	days = int(sys.stdin.readline().strip())
	vals = []
	for _ in range(days):
		coins = int(sys.stdin.readline().strip())
		vals.append(binary_search(coins, inpt))
	for i in vals:
		print(i)
main()


import bisect
n = int(input())
price = list(map(int, input().split()))
price = sorted(price)
k = int(input())
score = []
for i in range(k):
	x = int(input())
	score.append(bisect.bisect(price, x))
for i in score:
	print(i)


n = int(input())
xs = [int(x) for x in input().split(' ')]
q = int(input())
ms = []
for i in range(q):
	ms.append(int(input()))
store_count = {}
for x in xs:
	if x in store_count:
		store_count[x] += 1
	else:
		store_count[x] = 1
price2ans = {}
count = 0
prices = sorted(set(xs))
it = iter(prices)
curr_p = next(it)
for i in range(prices[0], prices[-1]):
	if i == curr_p:
		count += store_count[i]
		try:
			curr_p = next(it)
		except StopIteration:
			pass
	price2ans[i] = count
for m in ms:
	if m >= prices[-1]:
		print(len(xs))
	elif m < prices[0]:
		print(0)
	else:
		print(price2ans[m])


from bisect import bisect_left
input()
a = sorted(map(int, input().split()))
for i in range(int(input())):
	print(bisect_left(a, int(input()) + 1))


def binary(t, s):
	fir = 0
	last = len(t) - 1
	mid = 0
	while fir <= last:
		mid = (fir + last) // 2
		if t[mid] > s:
			last = mid - 1
		else:
			fir = mid + 1
	return last + 1
n = int(input())
t = list(map(int, input().split()))
m = int(input())
p = 0
t.sort()
for i in range(m):
	s = int(input())
	print(binary(t, s))


def ii():
	return int(input())

def ss():
	return [x for x in input()]

def si():
	return [int(x) for x in input().split()]

def mi():
	return map(int, input().split())
from bisect import bisect
a = ii()
s = si()
s.sort()
b = ii()
for i in range(b):
	it = ii()
	print(bisect(s, it))


from bisect import bisect
n = int(input())
p = input().split()
p = sorted([int(v) for v in p])
d = int(input())
c = [int(input()) for i in range(1, d + 1)]
n = 0
for x in c:
	if x < p[0]:
		print(0)
	else:
		i = bisect(p, x)
		print(i)


from sys import stdin, stdout

def bina(l, x, le):
	izq = 0
	der = le - 1
	ans = 0
	while izq <= der:
		m = (izq + der) // 2
		if l[m] > x:
			der = m - 1
			ans = m
		else:
			izq = m + 1
			ans = m + 1
	return ans

def main():
	le = int(stdin.readline())
	l = [int(x) for x in stdin.readline().split()]
	n = int(stdin.readline())
	d = [int(stdin.readline()) for k in range(n)]
	l.sort()
	m = l[-1]
	for k in d:
		print(bina(l, k, le))
main()


from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]
import bisect
nb_shops = read_int()
prices = sorted(read_ints())
nb_query = read_int()
for _ in range(nb_query):
	has = read_int()
	print(bisect.bisect(prices, has))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
pref_sum = []
count = 0
t = 0
for i in range(0, len(arr)):
	count += 1
	if i == n - 1 or arr[i + 1] != arr[i]:
		for j in range(-1, t):
			pref_sum.append(count)
		t = 0
	else:
		t += 1
t = int(input())
h = dict({})
for ti in range(0, t):
	r = int(input())
	if r in h.keys():
		print(h[r])
	elif r < arr[0]:
		print('0')
		h[r] = 0
	elif r == arr[0]:
		print(pref_sum[0])
		h[r] = pref_sum[0]
	elif r >= arr[n - 1]:
		print(n)
		h[r] = n
	else:
		i = 0
		j = n - 1
		mid = n // 2
		while i != j:
			if r == arr[mid]:
				print(pref_sum[mid])
				h[r] = pref_sum[mid]
				break
			elif r < arr[mid] and r > arr[mid - 1]:
				print(pref_sum[mid - 1])
				h[r] = pref_sum[mid - 1]
				break
			elif r > arr[mid] and r < arr[mid + 1]:
				print(pref_sum[mid])
				h[r] = pref_sum[mid]
				break
			elif r < arr[mid]:
				j = mid
				mid = (i + j) // 2
			else:
				i = mid
				mid = (i + j) // 2


import bisect
n = int(input())
price = [int(x) for x in input().split()]
price.sort()
q = int(input())
for i in range(q):
	t = int(input())
	num = bisect.bisect(price, t)
	print(num)


n = int(input())
ls = list(map(int, input().split()))
q = int(input())
lsq = []
for i in range(q):
	lsq.append(int(input()))
ls.sort()
lsqp = lsq[:]
lsq.sort()
d = {}
i = j = count = 0
while i < len(lsq) and j < len(ls):
	if lsq[i] >= ls[j]:
		count = count + 1
		j = j + 1
	else:
		d[lsq[i]] = count
		i = i + 1
while i < len(lsq):
	d[lsq[i]] = count
	i = i + 1
for k in lsqp:
	print(d[k])


n = int(input())
x = [int(_) for _ in input().split(' ')]
x.sort()
q = int(input())
output = []
for _ in range(q):
	m = int(input())
	if m >= x[-1]:
		output.append(str(n))
	elif m < x[0]:
		output.append(str(0))
	else:
		left = 0
		right = n - 1
		while left < right:
			middle = (left + right) // 2
			if x[middle] > m:
				right = middle
			else:
				left = middle + 1
		if x[left] > m:
			output.append(str(left))
		else:
			output.append(str(left + 1))
print('\n'.join(output))


from collections import Counter, defaultdict
n = int(input())
shop = [int(i) for i in input().split()]
queries = int(input())
c = defaultdict(int)
for s in shop:
	c[s] += 1
prefix = defaultdict(int)
mn = min(shop)
mx = max(shop)
for i in range(mn, mx + 1):
	prefix[i] = c[i] + prefix[i - 1]
res = []
for q in range(queries):
	q = int(input())
	if q > mx:
		res.append(str(len(shop)))
	else:
		res.append(str(prefix[q]))
print('\n'.join(res))


def ans(arr, x):
	index = bsearch(arr, x)
	if index is -1:
		return 0
	return index + 1
	pass

def bsearch(arr, x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] is x:
			ans = mid
			l = mid + 1
		elif arr[mid] < x:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans
	pass
n = int(input())
arr = list(map(int, input().strip().split(' ')))
arr.sort()
q = int(input())
for i in range(q):
	m = int(input())
	print(ans(arr, m))


n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for _ in range(q):
	m.append(int(input()))
orig_m = m[:]
x.sort()
m.sort()
num_shops = 0
c = 0
i = 0
d = {}
f = False
while i < len(x):
	if c >= len(m):
		break
	if m[c] < x[i]:
		d[m[c]] = num_shops
		c += 1
		f = True
		continue
	num_shops += 1
	i += 1
	f = False
if not f:
	for i in range(c, len(m)):
		d[m[i]] = num_shops
for i in orig_m:
	print(d[i])


import sys
n = int(input())
xl = [int(i) for i in sys.stdin.readline().strip('\n').split()]
q = int(input())
ml = []
for i in range(q):
	t = sys.stdin.readline()
	t = int(t)
	ml.append(t)
X = 100000
l = [0] * (X + 1)
for x in xl:
	l[x] += 1
for x in range(1, X + 1):
	l[x] += l[x - 1]
for m in ml:
	if m > X:
		m = X
	print(l[m])


from bisect import bisect_right
n = int(input())
a = list(map(int, input().rstrip().split()))
a.sort()
m = int(input())
for i in range(m):
	g = int(input())
	index = bisect_right(a, g)
	print(index)


n = int(input())
li = list(map(int, input().split()))
li.sort()
max = li[-1]
num = [0] * max
cur = 0
i = 0
while i < n:
	while i < n - 1 and li[i] == li[i + 1]:
		i += 1
		cur += 1
	cur += 1
	if i < n - 1:
		for x in range(li[i] - 1, li[i + 1] - 1):
			num[x] = cur
	else:
		num[li[i] - 1] = cur
	i += 1
q = int(input())
for i in range(q):
	m = int(input())
	if m >= max:
		print(num[-1])
	else:
		print(num[m - 1])


from bisect import bisect_right

def main():
	n = int(input())
	x = list(map(int, input().split()))
	x.sort()
	q = int(input())
	for i in range(q):
		m = int(input())
		res = bisect_right(x, m)
		print(res)
main()


shops = input()
price = input()
a = price.split()
p = list()
n = 0
while n < len(a):
	p.append(int(a[n]))
	n = n + 1
p.sort()

def khoj(list, coin):
	first = 0
	last = len(list) - 1
	ans = 0
	while first <= last:
		mid = int((first + last) // 2)
		if coin >= list[mid]:
			ans = mid + 1
			first = mid + 1
		else:
			last = mid - 1
	return ans
days = input()
d = 0
while d < int(days):
	coins = input()
	print(khoj(p, int(coins)))
	d = d + 1


import bisect
n_lojas = int(input())
lojas = [int(x) for x in input().split()]
lojas.sort()
days = int(input())
for i in range(days):
	din = int(input())
	print(bisect.bisect_left(lojas, din + 1))


import bisect
nos = int(input())
shops = list(map(int, input().split()))
nod = int(input())
shops.sort()
for i in range(nod):
	print(bisect.bisect_right(shops, int(input())))


n = int(input().strip())
x = list(map(int, input().strip().split()))
q = int(input().strip())
p_sums = [0] * (max(x) + 1)
for p in x:
	p_sums[p] += 1
for i in range(1, len(p_sums)):
	p_sums[i] += p_sums[i - 1]
for _ in range(q):
	m = int(input().strip())
	if m >= len(p_sums):
		price = n
	else:
		price = p_sums[m]
	print(price)


import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import accumulate, combinations, combinations_with_replacement, groupby, permutations, product
from math import acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians, sin, sqrt, tan
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits

def inp():
	return int(input())

def inlist():
	return list(map(int, input().split()))

def instr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())

def b_search(l, r, a, target):
	ans = -1
	while l <= r:
		mid = l + (r - l) // 2
		if a[mid] <= target:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans + 1

def main():
	n = inp()
	a = inlist()
	a = sorted(a)
	q = inp()
	for _ in range(q):
		target = inp()
		res = b_search(0, n - 1, a, target)
		print(res)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
s = list(map(int, input().split()))
s.sort()
q = int(input())
for _ in range(q):
	coins = int(input())
	res = 0
	(l, r) = (0, len(s) - 1)
	if coins < s[l]:
		print(0)
		continue
	elif coins >= s[r]:
		print(len(s))
		continue
	while l < r:
		mid = l + (r - l) // 2
		if s[mid] > coins:
			r = mid
		elif s[mid] <= coins:
			l = mid + 1
	res = r
	print(res)


from bisect import bisect_right
n = int(input())
shop = list(map(int, input().strip().split()))
shop.sort()
q = int(input())
for i in range(q):
	e = int(input())
	s = bisect_right(shop, e)
	print(s)


from sys import stdin

def binary(A, lo, hi, x):
	ans = -1
	if hi - lo == 1 or hi == lo or hi - lo == 2:
		if A[hi - 1] == x:
			return hi - 1
		elif A[lo] == x:
			return lo
	else:
		mid = lo + (hi - lo) // 2
		if x < A[mid]:
			ans = binary(A, lo, mid, x)
		else:
			ans = binary(A, mid + 1, hi, x)
	if ans == -1:
		if A[lo] > x:
			return lo - 1
		elif A[hi - 1] < x:
			return hi - 1
		else:
			return lo
	return ans

def main():
	a = int(stdin.readline().strip())
	b = [int(x) for x in stdin.readline().strip().split()]
	b.sort()
	c = int(stdin.readline().strip())
	d = []
	for i in range(c):
		e = int(stdin.readline().strip())
		ans = binary(b, 0, len(b), e) + 1
		print(ans)
main()


def Search(tab, n, x):
	moi = 0
	deb = 0
	fin = n - 1
	nb = 0
	while deb <= fin:
		moi = (deb + fin) // 2
		if tab[moi] > x:
			fin = moi - 1
		elif tab[moi] == x:
			nb += moi - deb + 1
			deb = moi + 1
		else:
			deb = moi + 1
			nb = moi + 1
	return nb
n = int(input())
l = []
l = [int(i) for i in input().split()]
l.sort()
q = int(input())
for i in range(q):
	m = int(input())
	f = Search(l, len(l), m)
	print(f)


import bisect as bis
n = int(input())
l = list(map(int, input().split()))
l.sort()
q = int(input())
for i in range(q):
	x = int(input())
	print(bis.bisect(l, x))


from bisect import bisect_right
n = int(input())
x = [*map(int, input().split())]
x.sort()
q = int(input())
for i in range(q):
	d = int(input())
	print(bisect_right(x, d))


def binarySearch(k, a):
	ans = 0
	l = 0
	r = len(a) - 1
	while l <= r:
		mid = l + (r - l) // 2
		if a[mid] <= k:
			ans = mid + 1
			l = mid + 1
		else:
			if a[mid] <= k:
				ans += 1
			r = mid - 1
	return ans
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
for _ in range(q):
	val = int(input())
	print(binarySearch(val, a))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	q = int(input())
	for qq in range(q):
		val = int(input())
		(lo, hi, ans) = (0, n - 1, 0)
		while lo <= hi:
			mid = (lo + hi) // 2
			if a[mid] <= val:
				ans = mid + 1
				lo = mid + 1
			else:
				hi = mid - 1
		print(ans)
main()


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	q = int(stdin.readline())
	a.sort()
	while q > 0:
		m = int(stdin.readline())
		ix = bisect_right(a, m)
		print(ix)
		q -= 1


count_shop = int(input())
cost_of_bank = list(map(int, input().split()))
cost_of_bank.append(100001)
cost_of_bank = sorted(cost_of_bank)
count_of_day = int(input())
for i in range(count_of_day):
	money = int(input())
	l = 0
	r = len(cost_of_bank) - 1
	if cost_of_bank[0] > money:
		print(0)
	else:
		while l != r - 1:
			mid = (l + r) // 2
			if cost_of_bank[mid] > money:
				r = mid
			else:
				l = mid
		print(l + 1)


def search(t, seq):
	first = 0
	last = len(seq) - 1
	while True:
		if last < first:
			return first
		m = (first + last) // 2
		if seq[m] < t:
			first = m + 1
		elif seq[m] > t:
			last = m - 1
		else:
			try:
				if seq[m] == seq[m + 1]:
					first = m + 1
				else:
					return m + 1
			except IndexError:
				return m + 1
n_shops = input()
shops = sorted(list(map(int, input().split())))
days = int(input())
coins = [int(input()) for i in range(days)]
for i in coins:
	print(search(i, shops))


import bisect
input()
bottles = [int(i) for i in input().split()]
bottles.sort()
d = int(input())
res = ''
for _ in range(d):
	f = int(input())
	res += str(bisect.bisect_right(bottles, f)) + '\n'
print(res)


import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
t = int(input())
for _ in range(t):
	x = int(input())
	print(bisect.bisect_right(l, x))


def binsearch(arr, x):
	start = 0
	result = -1
	end = len(arr) - 1
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] == x:
			result = mid + 1
			start = mid + 1
		elif x > arr[mid]:
			start = mid + 1
		else:
			end = mid - 1
	if result == -1:
		return start
	else:
		return result
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
q = int(input())
for _ in range(q):
	x = int(input())
	if x < arr[0]:
		print(0)
	elif x > arr[-1]:
		print(len(arr))
	else:
		print(binsearch(arr, x))


import bisect
n_lojas = int(input())
precos = list(map(int, input().split(' ')))
precos.sort()
dias = int(input())

def find_lt(a, x):
	i = bisect.bisect_right(a, x)
	if i:
		return i
	return 0
for i in range(dias):
	valor = int(input())
	lojas_aptas = 0
	print(find_lt(precos, valor))


def test(arr, value, position):
	if value >= arr[position]:
		if value < arr[position + 1]:
			return 0
		if value >= arr[position + 1]:
			return 1
	else:
		return -1

def search(arr, value):
	first = 0
	last = len(arr) - 1
	found = -1
	while first <= last and found == -1:
		midpoint = (first + last) // 2
		t = test(arr, value, midpoint)
		if t == 0:
			found = midpoint
		elif t < 0:
			last = midpoint - 1
		else:
			first = midpoint + 1
	return found
n = int(input())
a = list(map(int, input().split(' ')))
a.append(-1)
a.append(10 ** 9 + 1)
a.sort()
result = ''
q = int(input())
for i in range(0, q):
	temp = int(input())
	result += str(search(a, temp)) + '\n'
print(result)


def get_index(price, money):
	min = 0
	max = len(price) - 1
	while min < max:
		mid = (min + max) // 2
		if price[mid] <= money:
			min = mid + 1
		else:
			max = mid
	return max

def get_result(price, money):
	result = get_index(price, money)
	if result == len(price) - 1 and money >= price[-1]:
		result += 1
	return result
n = int(input())
x = map(int, input().split())
q = int(input())
x = sorted(x)
for i in range(q):
	m = int(input())
	print(get_result(x, m))


read = lambda : map(int, input().split())
n = int(input())
x = list(read())
q = int(input())
m = [int(input()) for i in range(q)]
N = 2 * 10 ** 5
cnt1 = [0] * N
cnt2 = [0] * N
for i in x:
	cnt1[i] += 1
cur = 0
for i in range(N):
	cur += cnt1[i]
	cnt2[i] = cur
for i in m:
	print(cnt2[min(N - 1, i)])


n = int(input())
a = [int(i) for i in input().split(' ')]
a.sort()
count = {}
maxi = 0
for i in a:
	if i in count:
		count[i] += 1
	else:
		count[i] = 1
	if i > maxi:
		maxi = i
result = []
for i in range(1, maxi + 1):
	if i == 1:
		if i in count:
			result.append(count[i])
		else:
			result.append(0)
	elif i in count:
		result.append(count[i] + result[-1])
	else:
		result.append(result[-1])
m = int(input())
for i in range(m):
	b = int(input())
	if b > maxi:
		print(result[-1])
	else:
		print(result[b - 1])


from bisect import bisect_right
input()
prices = sorted(map(int, input().split()))
print(*(bisect_right(prices, int(input())) for _ in range(int(input()))), sep='\n')


import bisect
n = int(input())
x = list(map(int, input().split()))
q = int(input())
x.sort()
for y in range(q):
	d = int(input())
	print(bisect.bisect_right(x, d))


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_right(a, x)
	if i != len(a):
		return i
	else:
		return len(a)

def main():
	try:
		n = I()
		l = list(In())
		d = {}
		l.sort()
		for q in range(I()):
			a = I()
			pos = find_gt(l, a)
			print(pos)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


n = int(input())
res = [0] * 100001
line = [int(i) for i in input().split()]
for i in line:
	res[i] += 1
k = 0
for i in range(100001):
	res[i] += k
	k = res[i]
num = int(input())
for i in range(num):
	m = int(input())
	if m > 100000:
		m = 100000
	print(res[m])


from sys import stdin

def bound(A, B, searchFirst):
	n = len(A)
	low = 0
	high = n - 1
	res = -1
	while low <= high:
		mid = low + (high - low) // 2
		if A[mid] <= B:
			res = mid
			if searchFirst:
				high = mid - 1
			else:
				low = mid + 1
		elif B > A[mid]:
			low = mid + 1
		else:
			high = mid - 1
	return res

def main():
	n = stdin.readline()
	arr = [int(x) for x in stdin.readline().strip().split()]
	arr.sort()
	q = int(input())
	for i in range(q):
		print(bound(arr, int(stdin.readline()), False) + 1)
main()


def binarySearchInsert(arr, start, end, x):
	while start < end:
		m = (start + end) // 2
		if arr[m] <= x:
			start = m + 1
		else:
			end = m
	return start
n = int(input().strip())
s = list(map(int, input().strip().split(' ')))
d = int(input().strip())
q = []
for _ in range(d):
	q.append(int(input().strip()))
s.sort()
for x in q:
	place = binarySearchInsert(s, 0, n, x)
	print(place)


from bisect import bisect
int(input())
xs = sorted(list(map(int, input().split())))
for _ in '0' * int(input()):
	print(bisect(xs, int(input())))


from bisect import bisect_right
from sys import stdin
all_in = stdin.read().splitlines()
n = int(all_in[0])
x = sorted(list(map(int, all_in[1].split())))
q = int(all_in[2])
ans = list()
for i in range(q):
	m = int(all_in[3 + i])
	ans.append(bisect_right(x, m))
print('\n'.join(map(str, ans)))


import bisect
n = int(input())
prices = list(map(int, input().split()))
t = int(input())
my = []
while t != 0:
	my.append(int(input()))
	t -= 1
prices.sort()
res = []
length = len(my)
for num in my:
	print(bisect.bisect_right(prices, num))


from bisect import *

def BinarySearch(a, x):
	i = bisect(a, x)
	if i:
		return i
	else:
		return -1
n = int(input())
x = list(map(int, input().split()))
q = int(input())
x.sort()
for i in range(q):
	a = int(input())
	k = BinarySearch(x, a)
	if k == -1:
		k = 0
	print(k)


import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
for _ in range(q):
	m = int(input())
	ans = bisect.bisect_left(a, m + 1)
	print(ans)


def bs(k, li):
	(l, r) = (0, len(li) - 1)
	if li[l] > k:
		return 0
	if li[r] <= k:
		return len(li)
	while True:
		if r - l < 2:
			return r
		m = l + (r - l >> 1)
		if li[m] > k:
			r = m
		else:
			l = m
n = int(input())
xn = sorted(list(map(int, input().split())))
q = int(input())
[print(bs(int(input()), xn)) for i in range(q)]


a = int(input())
b = list(map(int, input().strip().split()))
b.sort()
c = int(input())
for i in range(c):
	d = int(input())
	l = 0
	h = len(b) - 1
	found = False
	ans = -1
	mid = (l + h) // 2
	while l <= h:
		mid = (l + h) // 2
		if b[mid] <= d:
			l = mid + 1
			ans = l
		else:
			h = mid - 1
	if not found:
		if d < b[0]:
			print(0)
		elif d > b[-1]:
			print(len(b))
		else:
			print(ans)


import bisect
n = int(input())
s = input().split(' ')
arr = sorted(map(int, s))
x = int(input())
for i in range(x):
	ele = int(input())
	print(bisect.bisect(arr, ele))


from math import ceil, sqrt
from collections import defaultdict as dd

def mp():
	return map(int, input().split())
n = int(input())
l = sorted(list(mp()))
q = int(input())
for i in range(q):
	p = int(input())
	start = 0
	end = n - 1
	ans = 0
	if p >= l[-1]:
		print(n)
	else:
		while start <= end:
			mid = (start + end) // 2
			if l[mid - 1] <= p < l[mid]:
				ans += mid
				break
			elif l[mid] <= p:
				start = mid + 1
			else:
				end = mid - 1
		print(ans)


def b_s(a, key):
	left = -1
	right = len(a)
	while right - left > 1:
		m = (left + right) // 2
		if a[m] > key:
			right = m
		else:
			left = m
	return right
n = int(input())
cost = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	m = int(input())
	x = b_s(cost, m)
	print(x)


from sys import stdin
n = int(input())
list1 = list(map(int, input().split()))
list2 = [0] * 100001
for i in range(n):
	list2[list1[i]] += 1
for i in range(1, 100001):
	list2[i] = list2[i] + list2[i - 1]
m = int(input())
for i in range(m):
	x = int(input())
	if x > 100000:
		print(list2[100000])
	else:
		print(list2[x])


import bisect
n = int(input())
x = [int(i) for i in input().split()]
q = int(input())
x = sorted(x)
for i in range(q):
	m = int(input())
	pos = bisect.bisect(x, m)
	print(pos)


import bisect
n = int(input())
l = [int(w) for w in input().split()]
m = int(input())
x = sorted(l)
for j in range(m):
	k = int(input())
	print(bisect.bisect_right(x, k))


n = int(input())
X = list(map(int, input().split()))
q = int(input())
M = [int(input()) for _ in range(q)]
P = [0 for _ in range(100001)]
for i in range(n):
	P[X[i]] += 1
for i in range(1, 100001):
	P[i] = P[i] + P[i - 1]
for i in range(q):
	if M[i] >= 100000:
		print(n)
	else:
		print(P[M[i]])


n = int(input())
x = [int(s) for s in input().split()]
x.sort()
start = 0
stop = n - 1
kech = {}

def nsort(a, start, stop, isk):
	if stop - start == 1:
		print(start + 1)
		return
	b = (start + stop) // 2
	if a[b] <= isk:
		nsort(a, b, stop, isk)
	else:
		nsort(a, start, b, isk)
q = int(input())
for i in range(q):
	m = int(input())
	if m < x[0]:
		print(0)
	elif start == stop:
		print(start + 1)
	elif x[stop] <= m:
		print(stop + 1)
	else:
		nsort(x, start, stop, m)


import bisect
n = int(input())
prices = [int(x) for x in input().split()]
prices.sort()
q = int(input())
for _ in range(q):
	m = int(input())
	print(bisect.bisect(prices, m))


def solve():
	shops = int(input().rstrip())
	prices = list(map(int, input().rstrip().split()))
	prices.sort()
	d = int(input().rstrip())
	days = []
	for _ in range(d):
		days.append(int(input().rstrip()))
	for day in days:
		low = 0
		high = shops - 1
		if day < prices[0]:
			print(0)
			continue
		ans = 0
		while low <= high:
			mid = low + int((high - low) / 2)
			if prices[mid] <= day:
				ans = mid
				low = mid + 1
			else:
				high = mid - 1
		print(ans + 1)
solve()


import bisect
n = int(input())
d = list(map(int, input().split()))
d.sort()
h = int(input())
for i in range(h):
	k = int(input())
	print(bisect.bisect_right(d, k))


import bisect
t1 = int(input())
a = list(map(int, input().split()))
t = int(input())
a.sort()
for i in range(t):
	print(bisect.bisect(a, int(input())))


n = int(input())
x = list(map(int, input().split()))
q = int(input())
d = []
for i in range(0, q):
	d.append(int(input()))
x.sort()
for k in d:
	l = 0
	r = n - 1
	while l < r:
		m = (l + r + 1) // 2
		if x[m] <= k:
			l = m
		else:
			r = m - 1
	if x[l] > k:
		print(0)
	else:
		print(l + 1)


n = int(input())
a = list(map(int, input().split()))
a.sort()
from bisect import bisect_right
for _ in range(int(input())):
	num = int(input())
	place = bisect_right(a, num)
	print(place)


from sys import stdin, stdout
inp = stdin.readline
op = stdout.write
n = int(inp())
p = list(map(int, inp().split()))
p.sort()
q = int(inp())
ans = []
for _ in range(q):
	a = int(inp())
	l = 0
	r = n - 1
	while l <= r:
		mid = (l + r) // 2
		if p[mid] <= a:
			l = mid + 1
			temp = 1
		else:
			r = mid - 1
	if p[mid] <= a:
		mid = mid + 1
	ans.append(str(mid))
op('\n'.join(ans))


from itertools import accumulate
n = int(input())
arr = list(map(int, input().split()))
occs = [0] * 100001
for v in arr:
	occs[v] += 1
occs = list(accumulate(occs))
q = int(input())
ans = list()
for _ in range(q):
	ans.append(occs[min(int(input()), 100000)])
print('\n'.join(map(str, ans)))


import sys
line = sys.stdin.readlines()
n = int(line[0])
x = list(map(int, line[1].split()))
x.sort()
q = int(line[2])
y = []
for i in range(q):
	y.append((int(line[i + 3]), i))
y.sort()
ans = []
j = 0
cnt = 0
for (m, i) in y:
	while j < n and m >= x[j]:
		cnt += 1
		j += 1
	ans.append((i, cnt))
ans.sort()
for (i, a) in ans:
	print(a)


def binary_search(x, list1, end, start=0):
	middle = (start + end) // 2
	current_start = start
	current_end = end
	m = list1[middle]
	if x >= list1[current_end]:
		return current_end
	elif x >= list1[current_start] and x < list1[current_start + 1]:
		return current_start
	elif x < list1[current_start]:
		return -1
	elif x < m and x > list1[middle - 1]:
		return middle - 1
	elif x >= m and x < list1[middle + 1]:
		return middle
	elif x >= m:
		return binary_search(x, list1, end=current_end, start=middle)
	elif x < m:
		return binary_search(x, list1, end=middle, start=current_start)
n = int(input())
shop_prices = input().split(' ')
shop_prices = list(map(int, shop_prices))
shop_prices.sort()
days = int(input())
list_of_cash = []
for i in range(days):
	list_of_cash.append(int(input()))
for cash in list_of_cash:
	print(binary_search(cash, shop_prices, n - 1) + 1)


def bisect(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x < a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo
n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
x.sort()
for i in m:
	print(bisect(x, i))


def search(m, i, j):
	x = (i + j) // 2
	if j == i + 1:
		return i + 1
	if m >= prices[x]:
		return search(m, x, j)
	else:
		return search(m, i, x)
n = int(input())
prices = [int(x) for x in input().split()]
prices.sort()
q = int(input())
for i in range(q):
	m = int(input())
	if m < prices[0]:
		print(0)
	elif m >= prices[n - 1]:
		print(n)
	else:
		print(search(m, 0, n - 1))


import bisect
n = int(input())
d = sorted(list(map(int, input().split())))
nd = int(input())
i = 0
while i < nd:
	a = int(input())
	print(bisect.bisect_right(d, a))
	i = i + 1


n = int(input())
shops = [int(i) for i in input().split()]
shops.sort()
n = len(shops)
for _ in range(int(input())):
	pocket = int(input())
	(l, r) = (0, n - 1)
	while l <= r:
		mid = l + (r - l) // 2
		if shops[mid] > pocket:
			r = mid - 1
		else:
			l = mid + 1
	print(r + 1)


from sys import stdin
from bisect import bisect_right
n = int(stdin.readline())
x = list((int(x) for x in stdin.readline().strip().split(' ')))
q = int(stdin.readline())
x.sort()
for _ in range(q):
	m = int(stdin.readline().strip())
	print(bisect_right(x, m))


def Search(lst, x):
	left = 0
	right = len(lst) - 1
	index = -1
	while left <= right:
		mid = left + right >> 1
		if x >= lst[mid]:
			index = mid
			left = mid + 1
		else:
			right = mid - 1
	return index + 1
n = int(input())
x = list(map(int, input().split()))
q = int(input())
ans = []
x.sort()
for i in range(q):
	m = int(input())
	b = Search(x, m)
	print(b)


import bisect
n = int(input())
a = sorted(map(int, input().split()))
for _ in range(int(input())):
	print(bisect.bisect(a, int(input())))


def binarySearch(arr, n, x):
	mid = 0
	low = 0
	high = n - 1
	nb = 0
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] > x:
			high = mid - 1
		elif arr[mid] == x:
			nb += mid - low + 1
			low = mid + 1
		else:
			low = mid + 1
			nb = mid + 1
	return nb
n = int(input())
ai = list(map(int, input().split()))
nj = int(input())
L = []
for i in range(nj):
	L.append(int(input()))
ai.sort()
for i in range(nj):
	print(binarySearch(ai, n, L[i]))


def lower_bound(l, x):
	left = 0
	right = len(l) - 1
	while left + 1 < right:
		m = int((left + right) / 2)
		if l[m] >= x:
			right = m
		else:
			left = m
	return right - 1
nb_shop = int(input())
price_bottle = [-2] + [int(x) for x in input().split()] + [100002]
price_bottle.sort()
day = int(input())
coin = []
for i in range(day):
	coin.append(int(input()))
for i in range(day):
	print(lower_bound(price_bottle, coin[i] + 1))


def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count
n = int(input())
a = list(map(int, input().split()))
a.sort()
k = int(input())
for _ in range(k):
	t = int(input())
	print(binarySearchCount(a, n, t))


from bisect import bisect
input()
x = sorted(list(map(int, input().split(' '))))
q = int(input())
m = ''
for i in range(q):
	m += input() + ' '
for j in list(map(int, m.rstrip().split(' '))):
	print(bisect(x, j))


n = int(input())
price = list(map(int, input().split()))
price.sort()
ans = [0 for i in range(price[-1] + 1)]
i = 0
j = 0
count = 0
while j < n:
	if i >= price[j]:
		count += 1
		ans[i] = count
		j += 1
	else:
		ans[i] = count
		i += 1
n = int(input())
for i in range(n):
	print(ans[min(int(input()), len(ans) - 1)])


n = int(input())
A = list(map(int, input().split()))
A = sorted(A)
q = int(input())
for i in range(q):
	a = int(input())
	left = -1
	right = len(A)
	while right > left + 1:
		middle = (left + right) // 2
		if A[middle] > a:
			right = middle
		else:
			left = middle
	print(left + 1)


import bisect
n = int(input())
prices_per_shop = sorted(map(int, input().strip().split()))
q = int(input())
answers = []
for i in range(q):
	answers.append(bisect.bisect_right(prices_per_shop, int(input())))
[print(answer) for answer in answers]


import math
import array as arr
import bisect
inarr = lambda : map(int, input().split())
int(input())
s = sorted(list(inarr()), key=int)
for i in range(int(input())):
	print(bisect.bisect(s, int(input())))


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	x = list(map(int, input().split()))
	q = int(input())
	m = [int(input()) for _ in range(q)]
	x.sort()

	def bs(l, r, v):
		if v < x[l]:
			return 0
		while l <= r:
			m = l + r >> 1
			k = x[m]
			if v < k:
				r = m - 1
			else:
				l = m + 1
		return l
	print('\n'.join([str(bs(0, n - 1, m[i])) for i in range(q)]))
main()


n = int(input())
arr = list(map(int, input().strip().split()))
qu = int(input())
arr.sort()
s = [-1] * (arr[n - 1] + 1)
k = 0
s[0] = 0
for i in range(1, arr[n - 1] + 1):
	if i < arr[k]:
		s[i] = s[i - 1]
	else:
		s[i] = s[i - 1]
		while k < n and i >= arr[k]:
			s[i] += 1
			k += 1
for i in range(qu):
	q = int(input())
	if q < arr[n - 1]:
		print(s[q])
	else:
		print(s[arr[n - 1]])


from bisect import bisect_left, bisect_right
from itertools import accumulate
R = lambda : map(int, input().split())
n = int(input())
cs = sorted(list(R()))
for t in range(int(input())):
	print(bisect_right(cs, int(input())))


n = int(input())
X = tuple(sorted(map(int, input().split())))
Qty = []
index = 0
size = min(100001, max(X) + 1)
for i in range(size):
	while index < n and X[index] == i:
		index += 1
	Qty.append(index)
result = ''
for i in range(int(input())):
	m = int(input())
	if m >= size:
		result += str(Qty[size - 1])
	else:
		result += str(Qty[m])
	result += '\n'
print(result)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
x = list(mints())
x.sort()
q = mint()
for i in range(q):
	y = mint()
	l = -1
	r = n
	while r - l > 1:
		c = (l + r) // 2
		if x[c] > y:
			r = c
		else:
			l = c
	print(l + 1)


def binarySearch(x, value):
	l = 0
	r = len(x) - 1
	while l <= r:
		mid = (l + r) // 2
		if x[mid] <= value:
			l = mid + 1
		else:
			r = mid - 1
	return r + 1
n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
	value = int(input())
	print(binarySearch(x, value))


n = int(input())
ls = sorted(map(int, input().split()))
q = int(input())
l = [0] * (ls[-1] + 1)
for x in ls:
	l[x] += 1
for i in range(1, ls[-1] + 1):
	l[i] += l[i - 1]
ans = []
for _ in range(q):
	x = int(input())
	if x <= ls[-1]:
		ans += [str(l[x])]
	else:
		ans += [str(l[-1])]
print('\n'.join(ans))


from sys import stdin

def com(Pre_Tien, Monedas):
	if Pre_Tien[0] > Monedas:
		return 0
	elif Pre_Tien[-1] <= Monedas:
		return len(Pre_Tien)
	else:
		primero = 0
		ultimo = len(Pre_Tien)
		while primero <= ultimo:
			mitad = (primero + ultimo) // 2
			if Monedas < Pre_Tien[mitad]:
				ultimo = mitad - 1
			else:
				primero = mitad + 1
		return ultimo + 1

def main():
	Tiendas = int(stdin.readline().strip())
	Precio_T = list(map(int, stdin.readline().strip().split()))
	Precio_T = sorted(Precio_T)
	Dias = int(stdin.readline().strip())
	res = []
	while Dias > 0:
		Precio_D = int(stdin.readline().strip())
		nums = com(Precio_T, Precio_D)
		res.append(nums)
		Dias -= 1
	for i in res:
		print(i)
main()


n = int(input())
prices = list(map(int, input().split()))
prices.sort()

def search(start, end, n):
	mid = (start + end) // 2
	if prices[mid] <= n < prices[mid + 1]:
		return mid + 1
	elif prices[mid] > n:
		return search(start, mid - 1, n)
	else:
		return search(mid + 1, end, n)
dic = {}
m = int(input())
for i in range(m):
	x = int(input())
	if x in dic:
		print(dic[x])
	elif x < prices[0]:
		print(0)
	elif x >= prices[-1]:
		print(n)
	else:
		z = search(0, n - 1, x)
		print(z)
		dic[x] = z


n = int(input())
p = [int(x) for x in input().split()]
q = int(input())
p = sorted(p)
if n <= 1:
	for i in range(0, q):
		m = int(input())
		if m < p[0]:
			print(0)
		elif m >= p[n - 1]:
			print(n)
		else:
			for j in range(0, n):
				if m < p[j]:
					print(j)
					break
else:
	for i in range(0, q):
		m = int(input())
		if m < p[0]:
			print(0)
		elif m >= p[n - 1]:
			print(n)
		else:
			(a, b) = (0, n - 1)
			while b - a > 1:
				t = int((a + b) / 2)
				if m >= p[t]:
					(a, b) = (t, b)
				elif m < p[t]:
					(a, b) = (a, t)
			print(a + 1)


n = int(input())
prices = list(map(int, input().split()))
prices.sort()
q = int(input())
ans = [0] * q
for i in range(q):
	money = int(input()) + 1
	l = 0
	r = n - 1
	while l < r:
		m = (l + r) // 2
		if money > prices[m]:
			l = m + 1
		else:
			r = m
	ans[i] = r + 1 if money > prices[-1] else r
print('\n'.join(map(str, ans)))


from bisect import bisect
n = int(input())
prices = sorted(map(int, input().split()))
q = int(input())
coins = [int(input()) for _ in range(q)]
for coin in coins:
	print(bisect(prices, coin))


n = int(input())
p = list(map(int, input().split()))
p.sort()
c = int(input())
for _ in range(c):
	l = 0
	r = n
	m = int(input())
	while l < r:
		mid = (l + r) // 2
		if p[mid] <= m:
			l = mid + 1
		else:
			r = mid
	print(l)


import bisect

def main0():
	n = int(input())
	prices = list(map(lambda x: int(x), input().split()))
	prices.sort()
	q = int(input())
	coins = list()
	for _ in range(q):
		coins.append(int(input()))
	for c in coins:
		print(bisect.bisect(prices, c))

def main1():
	n = int(input())
	prices = list(map(lambda x: int(x), input().split()))
	prices.sort()
	prefix_sums = [0] * (1 + prices[-1])
	lo = 0
	for i in range(1, len(prefix_sums)):
		prefix_sums[i] = prefix_sums[i - 1]
		while lo < len(prices) and prices[lo] <= i:
			prefix_sums[i] += 1
			lo += 1
	q = int(input())
	coins = list()
	for _ in range(q):
		coins.append(int(input()))
	for c in coins:
		if c >= len(prefix_sums):
			print(prefix_sums[-1])
		else:
			print(prefix_sums[c])
main1()


n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
q = int(input())
query = []
for i in range(q):
	x = int(input())
	query.append(x)

def BinarySearch(arr, low, high, val):
	while low <= high:
		mid = (low + high) // 2
		if val == arr[mid]:
			index = mid
			low = mid + 1
		elif val > arr[mid]:
			low = mid + 1
		else:
			high = mid - 1
	return low
for val in query:
	res = BinarySearch(arr, 0, n - 1, val)
	print(res)


import bisect
n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
for _ in range(q):
	print(bisect.bisect(x, int(input())))


def BS(a, l, r, x):
	global g
	mid = l + (r - l) // 2
	if r >= l:
		if a[mid] > x:
			g = mid
			return BS(a, l, mid - 1, x)
		else:
			return BS(a, mid + 1, r, x)
	return g
n = int(input())
a = [int(v) for v in input().split()]
a.sort()
q = int(input())
for i in range(0, q):
	m = int(input())
	g = 0
	if m >= a[n - 1]:
		print(len(a))
	else:
		print(BS(a, 0, len(a) - 1, m))


import bisect
input()
arr1 = sorted(list(map(int, input().split())))
for i in range(int(input())):
	print(bisect.bisect_right(arr1, int(input())))


def search(arr, x, lo, hi):
	if lo >= hi:
		return hi
	mid = (lo + hi) // 2
	if arr[mid] > x:
		return search(arr, x, lo, mid)
	return search(arr, x, mid + 1, hi)
n = int(input())
x = [int(i) for i in input().split()]
x.sort()
q = int(input())
for _ in range(q):
	m = int(input())
	idx = search(x, m, 0, n)
	print(idx)


from bisect import bisect
n = int(input())
xi = list(map(int, input().split(' ')))
xi.sort()
q = int(input())
qi = []
for i in range(q):
	v = int(input())
	print(bisect(xi, v))


from bisect import bisect
num_shops = int(input())
shop_costs = sorted(map(int, input().split()))
num_days = int(input())
for d in range(num_days):
	today_money = int(input())
	print(bisect(shop_costs, today_money))


from bisect import bisect_right
n = int(input())
ls = sorted(list(map(int, input().split())))
m = int(input())
for i in range(m):
	val = int(input())
	ind = bisect_right(ls, val)
	print(ind)


n = int(input())
price = list(map(int, input().split()))
MAX = max(price) + 1
shop = [0] * MAX
for i in price:
	shop[i] += 1
for i in range(1, MAX):
	shop[i] += shop[i - 1]
q = int(input())
while q > 0:
	m = int(input())
	if m > MAX - 1:
		m = MAX - 1
	print(shop[m])
	q = q - 1


from bisect import bisect

def main():
	ans = []
	n = int(input())
	prices = list(map(int, input().split()))
	days = int(input())
	prices.sort()
	for i in range(days):
		money = int(input())
		index = bisect(prices, money)
		ans.append(index)
	for item in ans:
		print(item)
main()


from bisect import bisect
t = int(input())
l = [int(x) for x in input().split()]
l = sorted(l)
for _ in range(int(input())):
	q = int(input())
	print(bisect(l, q))


import sys
import math
import itertools
import collections

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def wr(arr):
	return ''.join(map(str, arr))

def revn(n):
	return str(n)[::-1]

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base=3):
	newnumber = ''
	while number > 0:
		newnumber = str(number % base) + newnumber
		number //= base
	return newnumber
n = ii()
a = sorted(li())
m = [0] * (a[-1] + 1)
pos = 0
for j in range(n):
	while pos < a[j]:
		m[pos] = j
		pos += 1
q = ii()
for i in range(q):
	p = ii()
	if p >= a[-1]:
		print(n)
	else:
		print(m[p])


n = int(input())
ans = [0] * 100000
res = [int(i) for i in input().split()]
for i in range(n):
	ans[res[i] - 1] += 1
for i in range(1, 100000):
	ans[i] += ans[i - 1]
a = []
q = int(input())
for i in range(q):
	b = int(input())
	if b > 100000:
		b = 100000
	a.append(str(ans[b - 1]))
print('\n'.join(a))


n = int(input())
arr = list(map(int, input().split()))[:n]
arr.sort()
no_of_times_buy = int(input())
can_spend = []
for _ in range(0, no_of_times_buy):
	money = int(input())
	can_spend.append(money)

def countGreater(k):
	l = 0
	r = n - 1
	left_greater = n
	while l <= r:
		mid = int(l + (r - l) / 2)
		if arr[mid] > k:
			left_greater = mid
			r = mid - 1
		else:
			l = mid + 1
	return n - (n - left_greater)
answer = []
for i in can_spend:
	answer.append(countGreater(i))
for j in answer:
	print(j)


from collections import deque
import bisect
n = int(input())
xi = list(map(int, input().split()))
q = int(input())
coins = deque()
for r in range(1, int(q) + 1):
	coins.append(input())
xi.sort()

def numdrinks(shops, prices, days, coins):
	for x in range(1, days + 1):
		today = int(coins.popleft())
		i = bisect.bisect_right(prices, today)
		count = i
		print(count)
numdrinks(n, xi, q, coins)


from itertools import accumulate as am, cycle as cy, permutations as perm, repeat
import math
from bisect import bisect

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
Xi = li()
Xi.sort()
q = ii()
for _ in range(q):
	num = ii()
	print(bisect(Xi, num))


from bisect import bisect_right
n = int(input())
a = sorted(map(int, input().split()))
for _ in range(int(input())):
	t = int(input())
	print(bisect_right(a, t))


import sys
n_str = input()
n = int(n_str)
x = [int(i) for i in input().split()]
q = int(input())
count = [0] * 100000
res = []
x.sort()

def search(target):
	left = 0
	right = n - 1
	if target < x[0]:
		return '0'
	if target >= x[n - 1]:
		return n_str
	while True:
		if right == left + 1:
			return str(right + 1) if target == x[right] else str(left + 1)
		curr = (left + right) // 2
		if target < x[curr]:
			right = curr
		else:
			left = curr
for i in range(100000):
	count[i] = search(i + 1)
lines = sys.stdin.readlines()
for line in lines:
	m = int(line.strip())
	if m > 100000:
		res.append(n_str)
	else:
		res.append(count[m - 1])
print('\n'.join(res))


n = int(input())
l = list(sorted(map(int, input().split())))
for _ in range(int(input())):
	m = int(input())
	start = 0
	end = n - 1
	while start < end:
		mid = (start + end + 1) // 2
		if l[mid] > m:
			end = mid - 1
		else:
			start = mid
	i = start
	if i == 0 and l[i] > m or (i == n - 1 and l[i] > m):
		print(i)
	else:
		print(i + 1)


import bisect as bi
n = int(input())
l = sorted(list(map(int, input().split())))
for i in range(int(input())):
	d = max(bi.bisect(l, int(input())), 0)
	print(d)


import bisect
n = int(input())
a = list(map(int, input().split()))
q = int(input())
a.sort()
for i in range(q):
	n1 = int(input())
	print(bisect.bisect(a, n1))


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
q = int(input())
for i in range(q):
	x = int(input())
	if x >= arr[-1]:
		print(n)
	elif x < arr[0]:
		print(0)
	else:
		(l, r) = (0, n - 1)
		while l < r:
			mid = (l + r) // 2
			if x >= arr[mid]:
				l = mid
			else:
				r = mid
			if r - l == 1:
				break
		if x >= arr[r]:
			print(r + 1)
		else:
			print(l + 1)


def tsearchrange(a, target, L, R):
	if L >= R:
		return L
	else:
		M = (L + R) // 2
		if target < a[M]:
			return tsearchrange(a, target, L, M - 1)
		elif target > a[M]:
			return tsearchrange(a, target, M + 1, R)
		elif a[M + 1] == target:
			return tsearchrange(a, target, M + 1, R)
		else:
			return M

def thanos_search(a, target):
	return tsearchrange(a, target, 0, len(a) - 1)
n = int(input())
x = sorted([int(x) for x in input().split()])
q = int(input())
for i in range(q):
	m = int(input())
	ans = thanos_search(x, m)
	if m >= x[ans]:
		ans += 1
	print(ans)


from sys import stdin, stdout
nbMagasins = int(stdin.readline())
prix = list(map(int, stdin.readline().split()))
prix.sort()
q = int(stdin.readline())
for i in range(q):
	prixMax = int(stdin.readline())
	inf = 0
	sup = nbMagasins - 1
	while sup > inf:
		milieu = (inf + sup) // 2
		if prix[milieu] > prixMax:
			sup = milieu
		else:
			inf = milieu + 1
	if prixMax < prix[0]:
		print(0)
	elif prixMax >= prix[-1]:
		print(nbMagasins)
	else:
		print(inf)


input()
s = sorted(map(int, input().split()))
n = int(input())
for i in range(n):
	b = int(input())
	l = 0
	u = len(s) - 1
	t = 0
	while l <= u:
		mid = l + (u - l) // 2
		if b >= s[mid]:
			t = mid + 1
			l = mid + 1
		else:
			u = mid - 1
	print(t)


def cp(a, b, s, e):
	while s <= e:
		m = (s + e) // 2
		if b < a[m] and b >= a[m - 1]:
			return m
		elif b >= a[m]:
			s = m + 1
		elif b <= a[m - 1]:
			e = m - 1
	return 0
n = int(input())
a = sorted(map(int, input().split()))
for _ in range(int(input())):
	b = int(input())
	if b >= a[-1]:
		print(len(a))
	elif b < a[0]:
		print(0)
	else:
		q = cp(a, b, 0, len(a) - 1)
		print(q)


n = int(input())
c = list(map(int, input().split()))
c.sort()
q = int(input())
for i in range(q):
	money = int(input())
	(l, r) = (0, n)
	while r - l > 1:
		mid = (l + r) // 2
		if money >= c[mid]:
			l = mid
		else:
			r = mid
	print(l + 1 if money >= c[0] else 0)


n = int(input())
ai = sorted(list(map(int, input().split(' '))))
for _ in range(int(input())):
	val = int(input())
	l = 0
	h = n
	while l < h:
		m = (l + h) // 2
		if val < ai[m]:
			h = m
		else:
			l = m + 1
	print(l)


from sys import stdin, stdout
inp = lambda : (int(o) for o in stdin.readline().split())
n = int(stdin.readline())
x = list(inp())
a = [0] * 100003
for i in range(n):
	a[x[i]] += 1
for i in range(1, 100003):
	a[i] += a[i - 1]
for i in range(int(stdin.readline())):
	print(a[min(int(stdin.readline()), 100002)])


from bisect import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
t = int(input())
for _ in range(t):
	q = int(input())
	count = bisect(l, q)
	print(count)


import time
n = int(input())
x = [int(i) for i in input().split()]
q = int(input())
x = sorted(x)
buy = [0]
j = 0
for i in range(1, x[n - 1] + 1):
	s = 0
	while j < n and x[j] == i:
		s += 1
		j += 1
	buy.append(buy[i - 1] + s)
ans = []
for i in range(q):
	m = int(input())
	if m < len(buy):
		ans.append(buy[m])
	else:
		ans.append(n)
start = time.time()
for i in range(q):
	print(ans[i])
finish = time.time()


def ubs(a, l, h, t):
	if l > h:
		return -1
	if l == h and a[l] <= t:
		return l
	mid = (l + h) // 2
	if a[mid] > t:
		return ubs(a, l, mid - 1, t)
	elif a[mid + 1] > t:
		return mid
	else:
		return ubs(a, mid + 1, h, t)
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
for i in range(q):
	m = int(input())
	print(ubs(a, 0, n - 1, m) + 1)


import sys
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
m = int(input())
arr2 = []
for i in range(m):
	num = int(input())
	arr2.append(num)

def binarySrc(a, item):
	first = 0
	last = n - 1
	found = 0
	while first <= last and found == 0:
		mid = int((first + last) / 2)
		if a[mid] <= item:
			first = mid + 1
		elif a[mid] > item:
			last = mid - 1
	print(last + 1)
for j in range(m):
	binarySrc(arr, arr2[j])


import bisect, math
for _ in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	n = int(input())
	for _ in range(n):
		q = int(input())
		print(bisect.bisect(arr, q))


import math

def main():
	n = int(input())
	shops = [int(x) for x in input().split()]
	q = int(input())
	m = max(shops)
	dp = [0] * (m + 1)
	for i in shops:
		dp[i] += 1
	for i in range(1, m + 1):
		dp[i] += dp[i - 1]
	for i in range(q):
		print(dp[min(m, int(input()))])
	return
main()


n = int(input())
mass = list(map(int, input().split()))
mass.sort()
q = int(input())
mass1 = []
for i in range(q):
	mass1.append(int(input()))
ans = []
for i in range(q):
	left = 0
	right = n - 1
	middle = (left + right + 1) // 2
	if mass1[i] < mass[0]:
		ans.append(0)
	else:
		while left < right:
			if mass[middle] > mass1[i]:
				right = middle - 1
			else:
				left = middle
			middle = (left + right + 1) // 2
		if left > right:
			ans.append(0)
		else:
			ans.append(left + 1)
for i in ans:
	print(i)


n = int(input())
x = list(map(int, input().split()))
q = int(input())
x.sort()
for i in range(q):
	y = int(input())
	lo = 0
	hi = len(x)
	while lo < hi:
		mid = (lo + hi) // 2
		if y < x[mid]:
			hi = mid
		else:
			lo = mid + 1
	print(lo)


from bisect import bisect

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	for _ in range(int(input())):
		t = int(input())
		print(bisect(a, t))
main()


from sys import stdin

def bound(A, B, searchFirst):
	n = len(A)
	low = 0
	high = n - 1
	res = -1
	while low <= high:
		mid = low + (high - low) // 2
		if A[mid] <= B:
			res = mid
			if searchFirst:
				high = mid - 1
			else:
				low = mid + 1
		else:
			high = mid - 1
	return res

def main():
	shops = stdin.readline()
	prices = [int(x) for x in stdin.readline().strip().split()]
	prices.sort()
	days = int(stdin.readline())
	for i in range(days):
		print(bound(prices, int(stdin.readline()), False) + 1)
main()


n = int(input())
prices = list(map(int, input().rstrip().split()))
prices.sort()
days = int(input())
for _ in range(days):
	coin = int(input())
	start = 0
	end = n - 1
	ans = 0
	while start <= end:
		mid = (start + end) // 2
		if prices[mid] <= coin:
			start = mid + 1
			ans = start
		else:
			end = mid - 1
	print(ans)


ln = int(input())
p = list(map(int, input().split()))
q = int(input())
p.sort()
u = q
m = []
ml = max(p)
dp = [0] * (ml + 1)
dp[0] = 0
fre = [0] * (ml + 1)
while q > 0:
	x = int(input())
	m.append(x)
	q = q - 1
num = p[0]
count = 1
for i in range(1, ln):
	if p[i] == num:
		count += 1
	else:
		fre[num] = count
		count = 1
		num = p[i]
fre[num] = count
for i in range(1, ml + 1):
	x = fre[i]
	dp[i] = dp[i - 1] + x
for i in range(u):
	if m[i] > ml:
		print(ln)
	else:
		print(dp[m[i]])


import bisect
a = int(input())
b = list(map(int, input().split()))
b.sort()
c = int(input())
for i in range(0, c):
	d = int(input())
	print(bisect.bisect_right(b, d))


import bisect
n = int(input())
x = [int(elt) for elt in input().split(' ')]
x.sort()
d = int(input())
maxx = max(x)
minn = min(x)
mi = x.count(minn)
ans = []
liste = {}
for i in range(d):
	m = int(input())
	ans.append(bisect.bisect_right(x, m, hi=n))
for elt in ans:
	print(elt)


from bisect import bisect_right
n = int(input())
prices = sorted(map(int, input().split()))
q = int(input())
for _ in range(q):
	money = int(input())
	print(bisect_right(prices, money))


def binary_search(prices, coins, length):
	high = length - 1
	low = 0
	while high - low > 1:
		mid = (high + low) // 2
		if shop_prices[mid] > coins:
			high = mid
		else:
			low = mid
	if shop_prices[low] > coins:
		print(0)
	elif shop_prices[high] <= coins:
		print(high + 1)
	else:
		print(low + 1)
get_shops = lambda x: list(map(int, x.split()))
length = int(input())
shop_prices = get_shops(input())
shop_prices.sort()
days = int(input())
for i in range(days):
	today = int(input())
	binary_search(shop_prices, today, length)


def binarySearch(list, n):
	first = 0
	last = len(list) - 1
	r = -1
	while first <= last:
		mid = first + (last - first) // 2
		if list[mid] <= n:
			r = mid
			first = mid + 1
		elif list[mid] > n:
			last = mid - 1
	return r + 1
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
coin = []
for i in range(q):
	coin.append(int(input()))
for i in coin:
	c = binarySearch(x, i)
	print(c)


from bisect import bisect_right as br
I = input
I()
a = sorted(map(int, I().split()))
for i in range(int(I())):
	print(br(a, int(I())))


def main():
	input()
	costs = [int(x) for x in input().split(' ')]
	costs.sort()
	n = int(input())
	for i in range(n):
		print(binsearch(costs, int(input())))

def binsearch(shops, coins):
	low = -1
	high = len(shops)
	while low + 1 < high:
		mid = low + (high - low) // 2
		if shops[mid] <= coins:
			low = mid
		else:
			high = mid
	return low + 1
main()


n = int(input())
prices = list(map(int, input().split()))
prices.sort()
q = int(input())
list_coins_n = []
cache = dict()
for i in range(1, n):
	if prices[i] != prices[i - 1]:
		cache[prices[i - 1]] = i
for a in range(q):
	c = int(input())
	if c < prices[0]:
		print(0)
		continue
	if c >= prices[n - 1]:
		print(n)
		continue
	if c in cache:
		print(cache[c])
		continue
	(i, j) = (0, n - 1)
	b_m = -1
	while j - i > 0:
		b_m = i + (j - i + 1) // 2
		if b_m == j:
			m = j - 1
		elif b_m == i:
			m = i + 1
		else:
			m = b_m
		if prices[m] > c:
			(i, j) = (i, m)
		else:
			(i, j) = (m, j)
		if j - i == 1 and prices[i] <= c < prices[j]:
			(i, j) = (i, i)
	ans = 0
	if j == 0:
		if c < prices[j]:
			ans = 0
		else:
			ans = 1
	elif i == n - 1:
		if c >= prices[i]:
			ans = n
		else:
			ans = n - 1
	else:
		ans = i + 1
	cache[c] = ans
	print(ans)


def f(A, m, n):
	if m < A[0]:
		return 0
	elif m >= A[-1]:
		return n
	else:
		l = 0
		h = n - 1
		while l <= h:
			mid = (l + h) // 2
			if A[mid] <= m and A[mid + 1] > m:
				return mid + 1
			elif A[mid] > m:
				h = mid - 1
			elif A[mid + 1] <= m:
				l = mid + 1
n = int(input())
a = input()
A = list(map(int, list(a.split())))
A.sort()
q = int(input())
t = q
while t > 0:
	t = t - 1
	m = int(input())
	print(f(A, m, n))


from collections import Counter

def binarySearch(num, low, high):
	while low <= high:
		mid = int((low + high) / 2)
		if num >= li[mid]:
			low = mid + 1
		else:
			high = mid - 1
	return low
n = int(input())
li = sorted(list(map(int, input().split())))
day = int(input())
l = []
for _ in range(day):
	x = int(input())
	index = binarySearch(x, 0, n - 1)
	l.append(index)
for e in l:
	print(e)


from bisect import bisect_right
n = int(input())
arr = sorted([int(p) for p in input().split()])
drink = int(input())
for i in range(drink):
	money = int(input())
	index = bisect_right(arr, money)
	print(index)


import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()
f = int(input())
for t in range(f):
	k = int(input())
	print(bisect.bisect_right(l, k))


n = int(input())
s = [int(n) for n in input().split()]
s.sort()
q = int(input())
for i in range(q):
	m = int(input())
	sh = -1
	(l, h) = (0, len(s) - 1)
	while l <= h:
		mid = (l + h) // 2
		if s[mid] <= m:
			sh = mid
			l = mid + 1
		if s[mid] > m:
			h = mid - 1
	print(sh + 1)


def binarySeach(arr, n, k):
	start = 0
	end = n
	res = 0
	while start <= end:
		mid = (start + end) // 2
		if arr[mid] <= k:
			start = mid + 1
			res = mid + 1
		else:
			end = mid - 1
	return res
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
m = int(input())
for i in range(m):
	a = int(input())
	if a < lst[0]:
		print(0)
	else:
		print(binarySeach(lst, n - 1, a))


n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
for j in range(q):
	num = 0
	if m[j] < x[0]:
		print(0)
		continue
	left = 0
	right = len(x) - 1
	while left < right:
		mid = (left + right + 1) // 2
		if x[mid] <= m[j]:
			left = mid
		else:
			right = mid - 1
	print(left + 1)


n = int(input())
y = [0] * 100001
for j in input().split():
	y[int(j)] = y[int(j)] + 1
for j in range(1, 100001):
	y[j] = y[j - 1] + y[j]
q = int(input())
for j in range(0, q):
	m = int(input())
	print(y[min(m, 100000)])


from itertools import accumulate
from bisect import bisect_right
n = int(input())
prices = [int(price) for price in input().split()]
prices.sort()
q = int(input())
print(*(bisect_right(prices, int(input())) for _ in range(q)), sep='\n')


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
n = int(I1())
a = sorted(list(I()))
q = int(I1())
for i in range(q):
	x = int(I1())
	print(bisect.bisect(a, x))


from bisect import bisect
m = int(input())
l = list(map(int, input().split()))
l.sort()
for _ in range(int(input())):
	n = int(input())
	print(bisect(l, n))


n = int(input())
X = tuple(sorted(map(int, input().split())))
Qty = []
index = 0
for i in range(100001):
	while index < n and X[index] == i:
		index += 1
	Qty.append(index)
result = ''
for i in range(int(input())):
	m = int(input())
	if m > 100000:
		print(Qty[100000])
	else:
		print(Qty[m])


n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	m = int(input())
	l = 0
	r = n - 1
	while l <= r:
		y = (l + r) // 2
		if m < x[y]:
			r = y - 1
		else:
			l = y + 1
	if r != n - 1 and m == x[r + 1]:
		r += 1
	print(r + 1)


from bisect import bisect_right as br
n = int(input())
a = sorted([int(i) for i in input().split()])
q = int(input())
for i in range(q):
	print(br(a, int(input())))


number_of_shops = int(input())
prices = input().split()
prices = [int(i) for i in prices]
prices.sort()
number_of_days = int(input())
money_available = []
for i in range(number_of_days):
	money_available.append(int(input()))

def findMoneyIndex(array, target):
	start = 0
	end = len(array) - 1
	if array[end] <= target:
		return len(array)
	while end - start > 1:
		midIndex = int((start + end) / 2)
		mid = array[midIndex]
		if mid == target:
			start = midIndex
		elif mid > target:
			end = midIndex
		elif mid < target:
			start = midIndex
	if array[start] <= target:
		while array[start] <= target and start < len(array):
			start += 1
	else:
		while start >= 0 and array[start] > target:
			start -= 1
	return 0 if start < 0 else start
for money in money_available:
	print(findMoneyIndex(prices, money))


def knowingShops(shopsNr, drinkPrices, money):
	result = -1
	l = 0
	r = shopsNr - 1
	while l <= r:
		mid = (l + r) // 2
		if drinkPrices[mid] <= money:
			result = mid
			l = mid + 1
		else:
			r = mid - 1
	return result
shopsNr = int(input())
drinkPrices = sorted([int(a) for a in input().split()])
days = int(input())
for m in range(days):
	money = int(input())
	res = knowingShops(shopsNr, drinkPrices, money)
	print(res + 1)


x = int(input())
s = sorted(list(map(int, input().split())))

def find(s, x):
	hi = len(s) - 1
	lo = 0
	mid = 0
	ans = 0
	while hi >= lo:
		mid = (hi + lo) // 2
		if s[mid] <= x:
			ans = mid + 1
			lo = mid + 1
		else:
			hi = mid - 1
	return ans
for n in range(int(input())):
	print(find(s, int(input())))


import bisect
n = int(input())
l = sorted(list(map(int, input().split())))
for i in range(int(input())):
	print(bisect.bisect_right(l, int(input())))


n = int(input())
Prices_old = [int(s) for s in input().split()]
Prices_old.sort()
q = int(input())
old_val = Prices_old[0]
Prices = [old_val]
Counts = []
count = 0
for i in range(n):
	new_val = Prices_old[i]
	if new_val == old_val:
		count += 1
	else:
		Prices.append(new_val)
		Counts.append(count)
		old_val = new_val
		count += 1
Counts.append(count)
n = len(Prices)
for i in range(q):
	m = int(input())
	L = 0
	R = n - 1
	if m < Prices[L]:
		print(0)
	elif m >= Prices[R]:
		print(Counts[n - 1])
	else:
		while R - L != 1:
			mid = (L + R) // 2
			if m > Prices[mid]:
				L = mid
			elif m < Prices[mid]:
				R = mid
			else:
				L = mid
				R = mid + 1
		print(Counts[L])


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
c1 = Counter(arr)
arr = sorted(list(set(arr)))
i = 0
c = Counter()
for j in range(10 ** 6 + 1):
	if i >= len(arr):
		c[j] = c[j - 1]
		continue
	if arr[i] == j:
		c[j] = c[j - 1] + c1[arr[i]]
		i += 1
	else:
		c[j] = c[j - 1]
q = int(input())
for _ in range(q):
	d = int(input())
	if d > 10 ** 6:
		print(n)
		continue
	print(c[d])


def binary_search(field, target):
	left = 0
	right = len(field)
	while left < right:
		mid = (left + right) // 2
		if field[mid] > target:
			right = mid
		else:
			left = mid + 1
	return left
n = int(input())
price = [int(x) for x in input().split()]
price = sorted(price)
q = int(input())
for test_case in range(q):
	tmp = int(input())
	print(binary_search(price, tmp))


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in range(n):
		if d.get(l[i]) == None:
			d[l[i]] = 1
		else:
			d[l[i]] += 1
	costs = [0]
	r = max(l)
	for i in range(1, r + 1):
		costs.append(costs[i - 1])
		if d.get(i) != None:
			costs[i] += d[i]
	for __ in range(int(input())):
		q = int(input())
		try:
			print(costs[q])
		except:
			print(costs[-1])


import bisect
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
while q:
	que = int(input())
	q -= 1
	p = bisect.bisect(a, que, 0, n)
	print(p)


from bisect import *
n = int(input())
arr = list(map(int, input().split()))
arr = sorted(arr)
q = int(input())
for j in range(q):
	k = int(input())
	d = bisect(arr, k)
	print(d)


n = int(input())
x = [int(x) for x in input().split()]
x.sort()
q = int(input())
l = max(x)
shops = [0] * l
for i in x:
	shops[i - 1] += 1
for i in range(1, l):
	shops[i] += shops[i - 1]
for _ in range(q):
	m = int(input())
	if m > l:
		print(shops[l - 1])
	else:
		print(shops[m - 1])


from collections import defaultdict as dc
from heapq import *
import math
import bisect
import sys
from collections import deque as dq
from heapq import heapify, heappush, heappop
mod = 10 ** 12

def inp():
	p = int(input())
	return p

def line():
	p = list(map(int, input().split()))
	return p

def digit(n):
	s = str(n)
	p = 0
	for i in s:
		p += int(i) ** 2
	return p
n = inp()
a = line()
q = inp()
ans = []
a.sort()
for i in range(q):
	z = inp()
	ans.append(bisect.bisect(a, z))
for i in ans:
	print(i)


n = int(input())
prices = map(int, input().split())
p_list = [0] * 100001
for p in prices:
	p_list[p] += 1
for x in range(1, 100001):
	p_list[x] = p_list[x] + p_list[x - 1]
q = int(input())
for _ in range(q):
	money = int(input())
	print(p_list[min(money, 100000)])


from sys import stdin

def bus(lista, n):
	izq = 0
	der = len(lista)
	midad = 0
	while izq < der:
		mitad = izq + (der - izq) // 2
		if lista[mitad] > n:
			if mitad == izq:
				return mitad
			der = mitad
		else:
			izq = mitad + 1
	return mitad + 1

def main():
	n = int(stdin.readline())
	lis = sorted(list(map(int, stdin.readline().split())))
	m = int(stdin.readline())
	for i in range(m):
		x = int(stdin.readline())
		print(bus(lis, x))
main()


n = int(input())
shops = list(map(int, input().split()))
shops.sort()
s = ''
for i in range(int(input())):
	(l, r) = (0, n - 1)
	value = int(input())
	while l <= r:
		mid = (l + r) // 2
		if shops[mid] <= value:
			l = mid + 1
		else:
			r = mid - 1
	s += str(l) + '\n'
print(s)


from bisect import bisect
input()
x = sorted([int(m) for m in input().split()])
k = int(input())
for i in range(k):
	a = int(input())
	print(bisect(x, a))


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def bs2(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def bs(arr, l, r, x):
	if x < arr[0]:
		return -1
	if x > arr[len(arr) - 1]:
		return len(arr)
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] <= x:
			l = mid + 1
		elif arr[mid] > x:
			r = mid - 1
	pos = l
	while pos < len(arr) and arr[pos] <= x:
		pos += 1
	return pos

def solve():
	n = iinp()
	x = intl()
	q = iinp()
	m = []
	for i in range(q):
		m.append(iinp())
	x.sort()
	for i in range(q):
		ans = bs(x, 0, n - 1, m[i])
		if ans == -1:
			print(0)
		else:
			print(ans)
solve()


n = int(input())
x = sorted(list(map(int, input().split())))
q = int(input())
s = []
j = 0
for i in range(100001):
	while j < n and x[j] <= i + 1:
		j += 1
	s.append(j)
for _ in range(q):
	r = int(input())
	if r > len(s):
		print(n)
	else:
		print(s[r - 1])


import bisect
x = int(input())
a = list(map(int, input().split()))
a.sort()
m = int(input())
for i in range(m):
	y = int(input())
	c = bisect.bisect(a, y)
	print(c)


from sys import *
from bisect import *
n = int(stdin.readline())
a = list(map(int, input().split()))
a.sort()
q = int(stdin.readline())
for i in range(q):
	m = int(input())
	print(bisect(a, m))


import sys
import bisect
n = int(sys.stdin.readline())
prices = [int(x) for x in sys.stdin.readline().split()]
prices = sorted(prices)
p = int(sys.stdin.readline())
for _ in range(p):
	coins = int(sys.stdin.readline())
	pos = bisect.bisect(prices, coins)
	print(pos)


import bisect

def main():
	n = input()
	num_shops = int(n)
	prices = []
	for x in input().split():
		prices.append(int(x))
	prices.sort()
	q = input()
	num_days = int(q)
	for m in range(num_days):
		i = input()
		num_coins = int(i)
		print(bisect.bisect_right(prices, num_coins))
main()


from bisect import bisect
n = int(input())
x = sorted(map(int, input().split()))
k = int(input())
for i in range(k):
	a = int(input())
	print(bisect(x, a))


def binary_search(arr, val):
	i = 0
	j = len(arr) - 1
	ans = 0
	while i <= j:
		mid = (i + j) // 2
		if arr[mid] <= val:
			ans = max(ans, mid + 1)
			i = mid + 1
		else:
			j = mid - 1
	return ans

def solve():
	n = int(input())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	q = int(input())
	while q:
		p = int(input())
		ans = binary_search(arr, p)
		print(ans)
		q -= 1
solve()


import bisect

def read():
	return [int(x) for x in input().split()]

def main():
	(n,) = read()
	x = read()
	x.sort()
	(q,) = read()
	for i in range(0, q):
		(m,) = read()
		b = bisect.bisect_right(x, m)
		print(b)
main()


import math
n = int(input())
price = input()
price = price.split(' ')
map = {}
price_max = -math.inf
for i in range(0, len(price)):
	price[i] = int(price[i])
	if price[i] in map:
		map[price[i]] += 1
	else:
		map[price[i]] = 1
	if price[i] > price_max:
		price_max = price[i]
q = int(input())
m = []
m_min = math.inf
m_max = -math.inf
for i in range(0, q):
	temp = int(input())
	m.append(temp)
	if temp < m_min:
		m_min = temp
	if temp > m_max:
		m_max = temp
cur = 0
dp = [0]
for i in range(1, price_max + 1):
	if i in map:
		dp.append(dp[i - 1] + map[i])
	else:
		dp.append(dp[i - 1])
for i in range(0, len(m)):
	if m[i] <= price_max:
		print(dp[m[i]])
	else:
		print(dp[price_max])


def recherche(element, liste_triee):
	a = 0
	b = len(liste_triee) - 1
	nb = 0
	while a <= b:
		m = (a + b) // 2
		if liste_triee[m] == element:
			nb += m - a + 1
			a = m + 1
		elif liste_triee[m] > element:
			b = m - 1
		else:
			a = m + 1
			nb = m + 1
	return nb
n = int(input())
ch = input()
l = ch.split(' ')
l1 = []
for i in l:
	l1.append(int(i))
q = int(input())
l1.sort()
for i in range(q):
	x = int(input())
	k = recherche(x, l1)
	print(k)


n = int(input())
ls = sorted(list(map(int, input().split())))
sm = 0
c = [0] * ls[-1]
s = []
for i in range(n):
	c[ls[i] - 1] += 1
for i in range(ls[-1]):
	sm += c[i]
	s.append(sm)
q = int(input())
for _ in range(q):
	query = int(input())
	if query >= ls[-1]:
		print(n)
	else:
		print(s[query - 1])


n = int(input())
a = [int(i) for i in input().split()]
mi = max(a)
pre = [0] * (mi + 1)
for i in range(n):
	pre[a[i]] += 1
for i in range(1, len(pre)):
	pre[i] = pre[i] + pre[i - 1]
q = int(input())
for j in range(q):
	m = int(input())
	if m > mi:
		print(n)
	else:
		print(pre[m])


import bisect

def find_all_stores(prices, money):
	sorted_prices = sorted(prices)
	available_prices = {}

	def find_le_index(m):
		index = bisect.bisect(sorted_prices, m)
		return index

	def find_stores(m):
		if m in available_prices:
			return available_prices[m]
		return find_le_index(m)
	for m in money:
		yield find_stores(m)
n_stores = int(input())
prices = [int(x) for x in input().split()]
days = int(input())
money = [0] * days
for i in range(days):
	money[i] = int(input())
print(*find_all_stores(prices, money), sep='\n')


import sys
import bisect
cont = 0
num_bar = int(input())
if num_bar < 1 or num_bar > 100000:
	sys.exit(0)
preco = []
valor = []
preco = input().split(' ')
for i in range(0, num_bar):
	valor.append(int(preco[i]))
	if valor[i] < 1 or valor[i] > 100000:
		sys.exit(0)
valor.sort()
dia = int(input())
if dia < 1 or dia > 100000:
	sys.exit(0)
dindias = []
for j in range(0, dia):
	dindin = int(input())
	if dindin < 1 or dindin > 10 ** 9:
		sys.exit(0)
	dindias.append(bisect.bisect_right(valor, dindin))
for x in dindias:
	print(x)


n = int(input())
p_l = sorted([int(i) for i in input().split()])
q = int(input())

def bin_idx_search(p_l, m, n):
	borders = [0, n - 1]
	while True:
		if n == 1:
			num = p_l[0]
			if m >= num:
				ans = 1
			else:
				ans = 0
			break
		mid_idx = (borders[0] + borders[1]) // 2
		if borders[0] == borders[1] and n - 1 == borders[0] or mid_idx == -1:
			ans = mid_idx + 1
			break
		if m >= p_l[mid_idx] and m < p_l[mid_idx + 1]:
			ans = mid_idx + 1
			break
		elif m < p_l[mid_idx]:
			borders[1] = mid_idx - 1
		elif m >= p_l[mid_idx + 1]:
			borders[0] = mid_idx + 1
	return ans
answers = []
for i in range(q):
	m = int(input())
	ans = bin_idx_search(p_l, m, n)
	answers.append(ans)
for i in answers:
	print(i)


import math

def s():
	n = int(input())
	prices = [int(x) for x in input().split(' ')]
	prices.sort()
	ans = [0 for i in range(prices[n - 1] + 1)]
	counter = 0
	temp = 0
	for i in range(1, prices[n - 1] + 1):
		while i >= prices[counter]:
			temp += 1
			counter += 1
			if counter == n:
				break
		ans[i] = temp
	q = int(input())
	for i in range(q):
		m = int(input())
		if m >= prices[n - 1]:
			print(ans[-1])
		else:
			print(ans[m])
s()


def solve(allowances, prices):
	for a in allowances:
		lb = 0
		ub = len(prices) - 1
		while ub > lb + 1:
			mid = (lb + ub) // 2
			if prices[mid] <= a:
				lb = mid
			else:
				ub = mid
		if prices[ub] <= a:
			print(ub + 1)
		elif prices[lb] <= a:
			print(ub)
		else:
			print(lb)

def to_l(string):
	return list(map(int, string.split(' ')))
shops = int(input())
prices = to_l(input())
days = int(input())
allowances = []
for _ in range(days):
	allowances.append(int(input()))
solve(allowances, sorted(prices))


import bisect

def main():
	n = int(input())
	tab = list(map(int, input().split()))
	tab.sort()
	q = int(input())
	for x in range(q):
		cur = int(input())
		i = bisect.bisect_right(tab, cur)
		print(i)
main()


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
k = int(input())

def first_x(x):
	l = 0
	r = len(arr) - 1
	ans = -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] <= x:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans
for i in range(k):
	print(first_x(int(input())) + 1)


import bisect
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
days = int(input())
for i in range(days):
	m = int(input())
	index = bisect.bisect_right(arr, m)
	print(index)


import bisect as bisect
n = int(input())
list1 = sorted(list(map(int, input().split())))
for i in range(int(input())):
	sol = bisect.bisect(list1, int(input()))
	print(sol)


def firstOccurance(numbers, length, searchnum):
	answer = -1
	start = 0
	end = length - 1
	while start <= end:
		middle = (start + end) // 2
		if numbers[middle] == searchnum:
			answer = middle + 1
			start = middle + 1
		elif numbers[middle] > searchnum:
			end = middle - 1
			answer = middle
		else:
			start = middle + 1
	return answer
shopNum = int(input())
nums = list(map(int, input().split()))[:shopNum]
nums.sort()
for i in range(int(input())):
	sn = int(input())
	if sn < nums[0]:
		print(0)
	elif sn >= nums[shopNum - 1]:
		print(shopNum)
	else:
		ans = firstOccurance(nums, shopNum, sn)
		print(ans)


import bisect

def solve(prices, coins):
	prices.sort()
	for coin in coins:
		result = bisect.bisect_right(prices, coin)
		print(result)
n = int(input())
prices = [int(e) for e in input().split()]
q = int(input())
coins = []
for i in range(q):
	coins.append(int(input()))
solve(prices, coins)


import bisect
n = int(input())
x = sorted((int(s) for s in input().split(' ')))
q = int(input())
print('\n'.join((str(bisect.bisect_right(x, int(input()))) for i in range(q))))


def binarySearch(arr, n, x):
	mid = 0
	low = 0
	high = n - 1
	nb = 0
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] > x:
			high = mid - 1
		elif arr[mid] == x:
			nb += mid - low + 1
			low = mid + 1
		else:
			low = mid + 1
			nb = mid + 1
	return nb
n = int(input())
l = []
for i in map(int, input().split()):
	l.append(i)
q = int(input())
l.sort()
k = []
for j in range(q):
	a = int(input())
	k.append(a)
for h in range(q):
	res = binarySearch(l, n, k[h])
	print(res)


def bst(A, x):
	if A[0] > x:
		return -1
	begin = 0
	end = len(A)
	while end - begin > 1:
		mid = (end + begin) // 2
		if A[mid] <= x:
			begin = mid
		else:
			end = mid
	return begin

def merge_sort(A):
	if len(A) == 1:
		return A
	mid = len(A) // 2
	B = merge_sort(A[:mid])
	C = merge_sort(A[mid:])
	i = j = 0
	A = []
	while i < len(B) and j < len(C):
		if B[i] < C[j]:
			A += [B[i]]
			i += 1
		else:
			A += [C[j]]
			j += 1
	A += B[i:] + C[j:]
	return A
n = int(input())
A = [int(i) for i in input().split()]
A = sorted(A)
d = int(input())
D = []
for i in range(d):
	D += [int(input())]
T = [A[0]]
for i in range(1, len(A)):
	T += [T[-1] + A[i]]
ans = []
for i in range(d):
	ans += [bst(A, D[i]) + 1]
for i in ans:
	print(i)


import bisect
n = int(input())
price = list(map(int, input().split(' ')))
price = sorted(price)
day = int(input())
for i in range(day):
	money = int(input())
	pos = bisect.bisect_right(price, money, 0, n - 1)
	if price[pos] <= money:
		print(pos + 1)
		continue
	print(pos)


from bisect import bisect_left
n = int(input())
x = sorted(list(map(int, input().split())))
for _ in range(int(input())):
	mi = int(input())
	pos = bisect_left(x, mi + 1, 0, n)
	print(pos + 1 if pos != n and x[pos] <= mi else pos)


nshops = int(input())
price_shop = list(map(int, input().split()))
ndays = int(input())
amt = []
for i in range(ndays):
	amt.append(int(input()))
price_shop.sort()
for i in amt:
	if i < price_shop[0]:
		print(0)
	elif i >= price_shop[-1]:
		print(nshops)
	else:
		start = 0
		end = nshops - 1
		while start < end:
			mid = start + (end - start) // 2
			if i >= price_shop[mid]:
				start = mid + 1
			else:
				end = mid
		print(end)


n = int(input())
x = list(map(int, input().rstrip().split()))
x.sort()
q = int(input())
for _ in range(q):
	m = int(input())
	start = 0
	end = n - 1
	ans = 0
	while start <= end:
		mid = (start + end) // 2
		if x[mid] <= m:
			start = mid + 1
			ans = start
		else:
			end = mid - 1
	print(ans)


n = int(input().strip())
x = [int(i) for i in input().strip().split(' ')]
q = int(input().strip())
c = [0 for i in range(10 ** 6 + 1)]
for i in range(n):
	c[x[i]] += 1
cumulative = 0
for i in range(len(c)):
	cumulative += c[i]
	c[i] = cumulative
for i in range(q):
	x = int(input().strip())
	if x < len(c):
		print(c[x])
	else:
		print(c[len(c) - 1])


import sys

def main():
	n = int(input())
	xl = [int(i) for i in sys.stdin.readline().strip('\n').split()]
	q = int(input())
	ml = []
	for i in range(q):
		t = sys.stdin.readline()
		t = int(t)
		ml.append(t)
	X = 100000
	l = [0] * (X + 1)
	for x in xl:
		l[x] += 1
	for x in range(1, X + 1):
		l[x] += l[x - 1]
	for m in ml:
		if m > X:
			m = X
		print(l[m])

def main2():
	n = int(input())
	xl = [int(i) for i in sys.stdin.readline().strip('\n').split()]
	q = int(input())
	ml = []
	for i in range(q):
		t = sys.stdin.readline()
		t = int(t)
		ml.append(t)
	xl.sort()
	for m in ml:
		(low_b, upp_b) = (0, n)
		diff = n
		if m >= xl[upp_b - 1]:
			print(n)
			continue
		elif m < xl[low_b]:
			print(0)
			continue
		while diff > 1:
			mid = (low_b + upp_b) // 2
			if m >= xl[mid]:
				low_b = mid
			else:
				upp_b = mid
			diff = upp_b - low_b
		print(low_b + 1)
main2()


def f(n):
	if p[n] <= currentmoney:
		return True
	else:
		return False

def boleanBinarySearchLast(start, end, val):
	while start < end:
		mid = int(start + (end - start + 1) / 2)
		c = f(mid)
		if c > val:
			start = mid + 1
		elif c < val:
			end = mid - 1
		else:
			start = mid
	if currentmoney < p[start]:
		return -1
	else:
		return start
currentmoney = 0
input()
p = list(map(int, input().split(' ')))
p.sort()
d = int(input())
money = []
for i in range(d):
	money.append(int(input()))
ln = len(p) - 1
for i in money:
	if ln == 0:
		if i >= p[0]:
			result = 0
		else:
			result = -1
	else:
		currentmoney = i
		result = boleanBinarySearchLast(0, ln, 1)
	print(result + 1)


from bisect import bisect_right
n = int(input())
a = list(map(int, input().split()))
a.sort()
k = int(input())
for x in range(0, k):
	f = int(input())
	print(bisect_right(a, f))


import math
n = int(input())
costs = [int(i) for i in input().split()]
q = int(input())
coins = [int(input()) for i in range(q)]
costs.sort()
for c in coins:
	l = 0
	r = n - 1
	m = n // 2
	c += 0.1
	while l <= r:
		if c < costs[m]:
			r = m - 1
		elif c > costs[m]:
			l = m + 1
		m = (l + r) // 2
	print(m + 1)


def solve(arr, q):
	pass
import bisect
n = int(input())
arr = list(map(int, input().split()))
q = int(input())
A = []
for _ in range(q):
	A.append(int(input()))
arr.sort()
for a in A:
	cnt = bisect.bisect_right(arr, a)
	print(cnt)


n = int(input())
a = list(map(int, input().split()))
a.sort()
q = int(input())
while q != 0:
	q -= 1
	x = int(input())
	if x < a[0]:
		print(0)
	elif x > a[-1]:
		print(n)
	else:
		(l, r, m, ans) = (0, n - 1, 0, 0)
		while l <= r:
			m = (l + r) // 2
			if a[m] <= x:
				(ans, l) = (m, m + 1)
			else:
				r = m - 1
		print(ans + 1)


from collections import defaultdict
from bisect import bisect_right
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
m = int(input())
query = []
for i in range(m):
	query.append(int(input()))
for i in range(m):
	print(bisect_right(lst, query[i]))


n = int(input())
o = []
l = [int(x) for x in input().split()]
l.sort()
j = 0
a = []
for i in range(10 ** 5 + 1):
	while j < n and l[j] <= i:
		j += 1
	a += [j]
m = int(input())
for i in range(m):
	t = int(input())
	if t <= 10 ** 5:
		o += [str(a[t])]
	else:
		o += [str(n)]
print('\n'.join(o))


n = int(input())
x = sorted(list(map(int, input().split())))
maximum = max(x)
b = (maximum + 1) * [0]
c = (maximum + 1) * [0]
(cnt, pointer) = (0, x[0])
for _ in range(n):
	c[x[_]] += 1
for j in range(1, maximum + 1):
	if j == pointer:
		cnt += c[j]
		if j != maximum:
			pointer = x[cnt]
	b[j] += cnt
for i in range(int(input())):
	q = int(input())
	if q >= maximum:
		ans = n
	else:
		ans = b[q]
	print(ans)


from bisect import bisect_right
input()
prices = input()
prices = prices.strip().split()
for i in range(len(prices)):
	prices[i] = int(prices[i])
prices.sort()
days = int(input())
for _ in range(days):
	res = 0
	v = int(input())
	print(bisect_right(prices, v))


n = int(input())
a = list(map(int, input().split()))
a.sort()
t = int(input())
d = []
e = []
for i in range(100001):
	d.append(0)
for i in range(n):
	d[a[i]] += 1
sum = 0
for i in range(100001):
	sum += d[i]
	e.append(sum)
for i in range(t):
	b = int(input())
	if b > 100000:
		print(n)
	else:
		print(e[b])


from bisect import *
n = int(input())
a = sorted(map(int, input().split()))
c = int(input())
for i in range(c):
	print(bisect_right(a, int(input())))


N = int(input())
shop_prices = [int(i) for i in input().split()]
shop_prices.sort()
D = int(input())
dm = [0] * D
ans = {}
for i in range(D):
	dm[i] = int(input())
day_money = list(set(dm.copy()))
day_money.sort()
last = 0
for i in range(len(day_money)):
	options = 0
	found = False
	for s in range(last, len(shop_prices)):
		if shop_prices[s] > day_money[i]:
			options = s
			found = True
			last = s
			break
	if not found:
		options = N
		last = N - 1
	ans[day_money[i]] = options
for i in range(len(dm)):
	print(ans[dm[i]])


Maxq = 100000
n = int(input())
A = list(map(int, input().strip().split(' ')))
q = int(input())
dp = [0] * (100000 + 1)
dp[0] = 0
for i in range(n):
	dp[A[i]] += 1
for i in range(1, len(dp)):
	dp[i] += dp[i - 1]
for i in range(q):
	m = int(input())
	if m > 100000:
		print(dp[100000])
	else:
		print(dp[m])


n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
a.sort()
b = [0] * 100100
for i in range(n):
	b[a[i]] = i + 1
for i in range(1, 100100):
	b[i] = max(b[i - 1], b[i])
for i in range(q):
	m = int(input())
	if m > 100010:
		print(b[100009])
	else:
		print(b[m])


import bisect
input()
lis = sorted(list(map(int, input().split())), key=int)
for x in range(int(input())):
	print(bisect.bisect(lis, int(input())))


from bisect import bisect
num = int(input())
prices = sorted(map(int, input().split()))
val = int(input())
for i in range(val):
	m = int(input())
	print(bisect(prices, m))


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

def List():
	return list(map(int, sys.stdin.readline().split()))

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def bsearch(a, n, p):
	s = 0
	e = n - 1
	c = 0
	while s <= e:
		mid = (s + e) // 2
		if a[mid] <= p:
			c = mid + 1
			s = mid + 1
		else:
			e = mid - 1
	return c

def solution():
	n = Int()
	a = List()
	m = Int()
	a.sort()
	for i in range(m):
		p = Int()
		ans = bsearch(a, n, p)
		print(ans)
solution()


def bin_search(l, r, n1):
	while l < r:
		mid = (l + r + 1) // 2
		if arr[mid] > n1:
			r = mid - 1
		else:
			l = mid
	return l
n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
q = int(input())
for _ in range(q):
	num = int(input())
	if num < arr[0]:
		print(0)
	else:
		ans = bin_search(0, n - 1, num)
		print(ans + 1)


import bisect
s = input()
P = sorted(map(int, input().split()))
q = int(input())
for _ in range(q):
	print(bisect.bisect(P, int(input())))


n = int(input())
prices = list(map(int, input().split()))
prices.sort()
days = int(input())
for i in range(days):
	coins = int(input())
	fr = 0
	la = n
	while fr < la:
		mid = fr + (la - fr) // 2
		if prices[mid] <= coins:
			fr = mid + 1
		else:
			la = mid
	print(fr)


global n, shops
(n, shops) = (int(input()), list(sorted(map(int, input().strip().split()))))

def HowManyShops(x):
	l = 0
	r = n - 1
	ans = -1
	while l <= r:
		mid = (l + r) // 2
		if shops[mid] <= x:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans + 1
for _ in range(int(input())):
	print(HowManyShops(int(input())))


from sys import stdin

def busqueda(lista, n):
	izq = 0
	der = len(lista)
	mitad = 0
	while izq < der:
		mitad = izq + (der - izq) // 2
		if lista[mitad] > n:
			if mitad == izq:
				return mitad
			der = mitad
		else:
			izq = mitad + 1
	return mitad + 1

def main():
	n = int(stdin.readline().strip())
	arreglo = sorted([int(x) for x in stdin.readline().strip().split()])
	casos = int(stdin.readline())
	for i in range(casos):
		result = busqueda(arreglo, int(stdin.readline()))
		print(result)
main()


n = int(input())
x = [int(x) for x in input().split()]
x.sort()
q = int(input())
m = []
for _ in range(q):
	m.append(int(input()))
m_ori = m.copy()
shops = {}
m.sort()
i = -1
for y in m:
	for j in range(i + 1, n):
		if x[j] <= y:
			i += 1
		else:
			break
	shops[y] = i + 1
for y in m_ori:
	print(shops[y])


import bisect
n = int(input())
L = sorted(map(int, input().split()))
q = int(input())
for _ in range(q):
	print(bisect.bisect(L, int(input())))


n = input()
priceEachStore = list(map(int, input().split()))
q = int(input())
coinsByDay = []
i = 0
while i < q:
	myMoney = int(input())
	coinsByDay.append(myMoney)
	i += 1

def bottlesInEachShop(priceEachStore, coinsByDay):
	priceEachStore.sort()

	def binary_search(a_list, target):
		inicio = 0
		final = len(a_list) - 1
		result = -1
		while inicio <= final:
			median = int(inicio + (final - inicio) / 2)
			if target == a_list[median]:
				result = median + 1
				inicio = median + 1
			elif target > a_list[median]:
				inicio = median + 1
			else:
				final = median - 1
		if result == -1:
			result = inicio
		return result
	for i in range(len(coinsByDay)):
		print(binary_search(priceEachStore, coinsByDay[i]))
bottlesInEachShop(priceEachStore, coinsByDay)


from sys import stdin

def upper_bound(nums, x):
	(l, r) = (0, len(nums) - 1)
	while l <= r:
		mid = l + (r - l) // 2
		if nums[mid] > x:
			r = mid - 1
		else:
			l = mid + 1
	return l

def main():
	n = int(stdin.readline())
	x = [int(x) for x in stdin.readline().split()]
	x.sort()
	y = int(stdin.readline())
	for i in range(y):
		z = int(stdin.readline())
		print(upper_bound(x, z))
main()


import bisect
n = int(input())
p = sorted(list(map(int, input().split())))
d = int(input())
for i in range(d):
	print(bisect.bisect(p, int(input())))


import bisect
s = int(input().strip())
price = sorted(map(int, input().strip().split()))
d = int(input().strip())
ans = 0
for i in range(d):
	q = int(input().strip())
	index = bisect.bisect_right(price, q)
	print(index)


def binarySearch(arr, l, r, y):
	while r - l > 1:
		mid = (r + l) // 2
		if arr[mid - 1] <= y:
			l = mid
		else:
			r = mid
	return l
n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
x.sort()
output = []
for i in range(q):
	m = int(input())
	val = binarySearch(x, 0, n + 1, m)
	output.append(val)
for val in output:
	print(val)


N = int(input())
prices = [int(i) for i in input().split()]
q = int(input())
prices = sorted(prices)
for _ in range(q):
	M = int(input())
	answer = 0
	(L, R) = (0, N - 1)
	while L <= R:
		m = (L + R) // 2
		if prices[m] <= M:
			L = m + 1
			answer = m + 1
		else:
			R = m - 1
	print(answer)


n = int(input())
L = sorted(map(int, input().split()))
L1 = [0] * (10 ** 5 + 1)
c = 1
for k in range(0, n - 1):
	for j in range(L[k], L[k + 1] + 1):
		L1[j] = c
	c += 1
for i in range(L[n - 1], 10 ** 5 + 1):
	L1[i] = c
q = int(input())
for h in range(q):
	a = int(input())
	if a >= 10 ** 5:
		print(n)
	else:
		print(L1[a])


def binary_search(arr, tar):
	(low, high) = (0, len(arr) - 1)
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] <= tar:
			low = mid + 1
		else:
			high = mid - 1
	return high + 1
n = int(input())
prices = sorted([int(x) for x in input().split()])
q = int(input())
i = 0
while i < q:
	coin = int(input())
	print(binary_search(prices, coin))
	i += 1


import sys
n = int(input())
x = list(map(int, sys.stdin.readline().split()))
q = int(input())
m = []
for _ in range(q):
	m.append(int(input()))
sol = dict()
sx = sorted(x, reverse=True)
sm = sorted(m, reverse=True)
ans = 0
while sm:
	k = sm.pop()
	while sx:
		if sx[-1] <= k:
			sx.pop()
			ans += 1
		else:
			break
	sol[k] = ans
for i in m:
	print(sol[i])


tp = int(input())
listNum = map(int, input().split())
data = [0] * 100001
for num in listNum:
	data[num] += 1
for i in range(1, 100001):
	data[i] += data[i - 1]
n = int(input())
for _ in range(n):
	num = int(input())
	if num > 100000:
		print(tp)
	else:
		print(data[num])


import math
import bisect

def solve():
	n = int(input())
	x = list(map(int, input().split()))
	x.sort()
	q = int(input())
	ans = 0
	for i in range(q):
		m = int(input())
		print(bisect.bisect(x, m))
solve()


import bisect

def get_ans():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	q = int(input())
	for i in range(q):
		x = int(input())
		ans = bisect.bisect(l, x)
		print(ans)
get_ans()


def bs(arr, m):
	n = len(arr)
	low = 0
	high = n
	while low != high:
		mid = (low + high) // 2
		if arr[mid] <= m:
			low = mid + 1
		else:
			high = mid
	return low
n = int(input())
ip = list(map(int, input().split()))
ip = sorted(ip)
for i in range(int(input())):
	m = int(input())
	print(bs(ip, m))


n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
x.sort()
for i in m:
	f = 0
	l = len(x) - 1
	c = -1
	while f <= l:
		mid = (l + f) // 2
		if x[mid] <= i:
			f = mid + 1
			c = mid
		elif x[mid] > i:
			l = mid - 1
	if c == -1:
		print(0)
	else:
		print(c + 1)


n = int(input())
xl = list(map(int, input().split()))
xl.sort()
xl += [xl[n - 1] + 1]
q = int(input())
ml = []
for i in range(q):
	x = int(input())
	if xl[n] <= x:
		x = xl[n - 1]
	ml += [x]
xl.sort()
xl += [xl[n - 1] + 1]
res = []
index = 0
for i in range(xl[n]):
	while i >= xl[index]:
		index += 1
	res += [index]
for i in range(q):
	print('%d' % res[ml[i]])


a = int(input())
z = list(map(int, input().split()))
t = [0 for i in range(max(z) + 1)]
r = [0]
for i in range(len(z)):
	t[z[i]] += 1
for i in range(1, len(t)):
	r.append(r[-1] + t[i])
l = int(input())
q = max(z)
for i in range(l):
	n = int(input())
	if n >= q:
		print(len(z))
	else:
		print(r[n])


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b

def chkprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
n = int(inp())
arr = lmp()
q = int(inp())
arr.sort()
for i in range(q):
	k = int(inp())
	ans = br(arr, k)
	out(ans)


def bs(k, n_list):
	l = 0
	r = len(n_list) - 1
	while l != r:
		mid = (l + r) // 2
		if k > n_list[mid]:
			l = mid + 1
		else:
			r = mid
	return l
a = input()
shop_prices = list(map(int, input().split()))
shop_prices.append(10 ** 10)
shop_prices.sort()
for day in range(int(input())):
	day_money = int(input())
	bs_data = bs(day_money + 1, shop_prices)
	print(bs_data)


import bisect
n = int(input())
a = [int(v) for v in input().split()]
q = int(input())
m = []
for i in range(0, q):
	x = int(input())
	m.append(x)
a.sort()
for i in range(0, q):
	if m[i] >= a[n - 1]:
		print(n)
	else:
		print(bisect.bisect_right(a, m[i]))


def binarySearch(arr, n, x):
	mid = 0
	low = 0
	high = n - 1
	nb = 0
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] > x:
			high = mid - 1
		elif arr[mid] == x:
			nb += mid - low + 1
			low = mid + 1
		else:
			low = mid + 1
			nb = mid + 1
	return nb
n = int(input())
l = []
l = [int(i) for i in input().split()]
l.sort()
q = int(input())
for i in range(q):
	m1 = int(input())
	k = binarySearch(l, len(l), m1)
	print(k)


n = int(input())
x = [int(x) for x in input().split()]
x.sort()
mc = x[len(x) - 1]
freq = [0] * (mc + 1)
count = 1
num = x[0]
for i in range(1, n):
	if x[i] == num:
		count += 1
	else:
		freq[num] = count
		count = 1
		num = x[i]
freq[num] = count
c = [0]
j = x[0]
ind = 0
for i in range(1, mc + 1):
	if i == j:
		c.append(c[i - 1] + freq[j])
		ind = ind + freq[j]
		if ind < len(x):
			j = x[ind]
	else:
		c.append(c[i - 1])
q = int(input())
for _ in range(q):
	m = int(input())
	if m > mc:
		print(n)
	else:
		print(c[m])


_ = int(input())
prices = list(map(int, input().split()))
prices.sort()
days_num = int(input())

def find_smallest(budget, prices, left=0, right=len(prices)):
	if left >= right:
		return left
	middle = (right + left) // 2
	if prices[middle] > budget:
		return find_smallest(budget, prices, left, middle)
	else:
		return find_smallest(budget, prices, middle + 1, right)
for _ in range(days_num):
	q = int(input())
	print(find_smallest(q, prices))


import math
n = int(input())
x = [int(x) for x in input().split()]
x.sort()
x1 = min(x)
x2 = max(x)
x = [0] + x + [100001]
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
for i in m:
	if i < x1:
		print(0)
	elif i >= x2:
		print(n)
	else:
		low = 0
		high = len(x) - 1
		while True:
			mid = math.floor((low + high) / 2)
			if i >= x[mid - 1] and i < x[mid]:
				print(mid - 1)
				break
			elif i >= x[mid]:
				low = mid + 1
			else:
				high = mid - 1


import bisect
n = int(input())
x = sorted([int(x) for x in input().split()])
for _ in range(int(input())):
	a = int(input())
	print(bisect.bisect_right(x, a))


def checkNumberOfShops(money, price_in_each_shop):
	global dict
	l = 0
	f = 0
	r = len(price_in_each_shop) - 1
	n = len(price_in_each_shop)
	if money < price_in_each_shop[0]:
		return 0
	elif money >= price_in_each_shop[-1]:
		return n
	else:
		while l <= r:
			m = int((l + r) / 2)
			if money > price_in_each_shop[m]:
				l = m + 1
			elif money < price_in_each_shop[m]:
				r = m - 1
			else:
				f = 1
				break
		if f == 1:
			while m + 1 != n:
				if price_in_each_shop[m + 1] != money:
					break
				m += 1
			dict[money] = m + 1
			return m + 1
		if l > m:
			dict[money] = m + 1
			return m + 1
		if r < m:
			dict[money] = m
			return m
global dict
dict = {}
number_of_shops = int(input())
price_in_each_shop = list(map(int, input().split()))
price_in_each_shop.sort()
no_of_days = int(input())
for i in range(no_of_days):
	t = int(input())
	if t in dict:
		print(dict[t])
	else:
		print(checkNumberOfShops(t, price_in_each_shop))


def binary_search(price_list, coins_day):
	l = 0
	h = len(price_list)
	while l != h:
		mid = (l + h) // 2
		if price_list[mid] > coins_day:
			h = mid
		else:
			l = mid + 1
	return l
n_shops = int(input())
price = list(map(int, input().split()))
price = sorted(price)
n_days = int(input())
for i in range(n_days):
	coins_day = int(input())
	r = binary_search(price, coins_day)
	print(r)


def findNearestLesser(l, key):
	lb = 0
	rb = len(l) - 1
	while lb <= rb:
		mid = (rb + lb) // 2
		if l[mid] == key:
			return mid
		if lb == rb:
			if l[lb] <= key:
				return mid
			return -1
		if l[mid] < key and l[mid + 1] > key:
			return mid
		if l[mid] > key:
			rb = mid
		else:
			lb = mid + 1

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count
n = input()
prices = list(map(int, input().split()))
prices.sort()
n = int(input())
memo = dict()
for _ in range(n):
	x = int(input())
	if x in memo:
		print(memo[x])
		continue
	res1 = binarySearchCount(prices, len(prices), x)
	print(res1)
	memo[x] = res1


from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
for _ in range(int(input())):
	x = int(input())
	l = 0
	pos = bisect_right(arr, x)
	print(pos)


import sys
readline = sys.stdin.readline

def binary_search(arr, x):
	(l, h) = (0, len(arr) - 1)
	while l <= h:
		mid = l + (h - l) // 2
		if x < arr[mid]:
			h = mid - 1
		else:
			l = mid + 1
	return l

def process():
	_ = int(readline())
	arr = sorted(map(int, readline().strip().split()))
	for _ in range(int(readline())):
		x = int(readline())
		print(binary_search(arr, x))
process()


import bisect
num_of_shop = int(input())
price = [int(x) for x in input().split(' ')]
price.sort()
num_of_days = int(input())
for i in range(num_of_days):
	coin = int(input())
	index = bisect.bisect_right(price, coin, hi=len(price))
	print(index)


n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = [0] * q
for i in range(q):
	m[i] = int(input())
x.sort()

def ans(val):
	a = 0
	b = n - 1
	if x[a] > val:
		return 0
	if x[b] <= val:
		return n
	while a + 1 < b:
		mid = (a + b) // 2
		if x[mid] > val:
			b = mid
		else:
			a = mid
	return a + 1
for mi in m:
	print(ans(mi))


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
m = int(input())
for i in range(m):
	q = int(input())
	low = 0
	high = n - 1
	while low <= high:
		mid = (low + high) // 2
		if a[mid] <= q:
			low = mid + 1
		else:
			high = mid - 1
	if low == n:
		count = n
	elif high == -1:
		count = 0
	elif a[low] <= q:
		count = low + 1
	else:
		count = low
	print(count)


input()
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	(a, b) = (0, len(x) - 1)
	t = int(input())
	if t < x[0]:
		print(0)
	elif t >= x[-1]:
		print(len(x))
	else:
		while a < b - 1:
			if x[(a + b) // 2] > t:
				b = (a + b) // 2
			else:
				a = (a + b) // 2
		print(b)


c = [0] * 100001
n = int(input())
for v in list(map(int, input().split())):
	c[v] += 1
for i in range(1, len(c)):
	c[i] += c[i - 1]
for i in range(int(input())):
	x = int(input())
	print(n if x > 100000 else c[x])


import bisect as bi
n = int(input())
X = list(map(int, input().split()))
X.sort()
q = int(input())
while q:
	m = int(input())
	q -= 1
	k = bi.bisect_right(X, m)
	print(k)


t = int(input())
d = list(map(int, input().split()))
d.sort()
q = int(input())
for i in range(q):
	target = int(input())
	start = 0
	end = len(d) - 1
	val = 0
	while start <= end:
		mid = (start + end) // 2
		if d[mid] <= target:
			val = mid + 1
			start = mid + 1
		else:
			end = mid - 1
	print(val)


from math import *
from copy import *
from string import *
from random import *
from sys import stdin
from sys import maxsize
from operator import *
from itertools import *
from collections import Counter
import math

def bin1(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = k ** mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin1(mid + 1, r, k, t, b, val, ans)
		else:
			return bin1(l, mid - 1, k, t, b, val, ans)

def bin2(l, r, k, t, b, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		v = t * k ** mid + b * mid
		if v == val:
			return v
		elif v > val:
			ans = mid
			return bin2(l, mid - 1, k, t, b, val, ans)
		else:
			return bin2(mid + 1, r, k, t, b, val, ans)

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	l = []
	for i in range(2, n + 1):
		if prime[i]:
			l.append(i)
	return l

def bin(l, r, ll, val):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		if val >= ll[mid][0] and val <= ll[mid][1]:
			return mid
		elif val < ll[mid][0]:
			return bin(l, mid - 1, ll, val)
		else:
			return bin(mid + 1, r, ll, val)

def deci(n):
	s = ''
	while n != 0:
		if n % 2 == 0:
			n = n // 2
			s = '0' + s
		else:
			n = n // 2
			s = '1' + s
	return s

def diff(s1, s2):
	if len(s1) < len(s2):
		v = len(s1)
		while v != len(s2):
			s1 = '0' + s1
			v = v + 1
	else:
		v = len(s2)
		while v != len(s1):
			s2 = '0' + s2
			v = v + 1
	c = 0
	for i in range(len(s1)):
		if s1[i:i + 1] != s2[i:i + 1]:
			c = c + 1
	return c
from sys import stdin, stdout

def fac(a, b):
	v = a
	while a != b:
		v *= a - 1
		a = a - 1
	return v

def bino(l, r, n):
	if l > r:
		return -1
	else:
		mid = (l + r) // 2
		val1 = math.log(n / mid + 1, 2)
		val2 = int(val1)
		if val1 == val2:
			return val1
		elif val1 < 1.0:
			return bino(l, mid - 1, n)
		else:
			return bino(mid + 1, r, n)

def binary(l, r, ll, val, ans):
	if l > r:
		return ans
	else:
		mid = (l + r) // 2
		if ll[mid] <= val:
			ans = mid + 1
			return binary(mid + 1, r, ll, val, ans)
		else:
			return binary(l, mid - 1, ll, val, ans)

def odd(n, ans, s):
	if n % 2 != 0 or n in s:
		return ans
	else:
		s.add(n)
		return odd(n // 2, ans + 1, s)
n = int(stdin.readline())
l = list(map(int, stdin.readline().split(' ')))
l.sort()
q = int(stdin.readline())
for i in range(q):
	val = int(stdin.readline())
	ans = binary(0, n - 1, l, val, 0)
	print(ans)


n = int(input())
a = sorted(list(map(int, input().split())))
m = int(input())
max_value = max(a)
b = [0] * (max_value - 1)
count = 0
for index in range(n):
	if index == 0:
		b[0:a[index] - 1] = [count] * (a[index] - 1)
	else:
		b[prev:a[index] - 1] = [count] * (a[index] - 1 - prev)
	prev = a[index] - 1
	count += 1
del a
while m > 0:
	money = int(input())
	if money >= max_value:
		print(n)
	else:
		print(b[money - 1])
	m -= 1


n = int(input())
shops = [0] + sorted(list(map(int, input().split()))) + [int(100000000000.0)]

def bs(q):
	global n
	l = 1
	r = n
	while l <= r:
		mid = (l + r) // 2
		if shops[mid] <= q and shops[mid + 1] > q:
			print(mid)
			return
		if shops[mid] > q:
			r = mid
		else:
			l = mid + 1
	return 0
for _ in range(int(input())):
	q = int(input())
	if q < shops[1]:
		print(0)
	elif q >= shops[-1]:
		print(n)
	else:
		bs(q)


from bisect import bisect as h
n = int(input())
l = list(sorted(map(int, input().split())))
q = int(input())
for i in range(q):
	a = int(input())
	b = h(l, a)
	print(b)


import bisect as b

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	l.sort()
	for _ in range(int(input())):
		x = int(input())
		print(b.bisect_right(l, x))
solve()


import bisect
while 1:
	try:
		n = int(input())
		x = [int(e) for e in input().split()]
		q = int(input())
	except:
		break
	x = sorted(x)
	an = []
	for i in range(q):
		s = int(input())
		an.append(bisect.bisect_right(x, s, hi=n))
	for i in an:
		print(i)


from bisect import bisect
n = int(input())
p = input()
x = sorted(map(int, p.split(' ')))
q = int(input())
for i in range(q):
	m = int(input())
	print(bisect(x, m))


n = 0
q = 0
preco = []
tem = []

def busca(dia):
	ini = 0
	fim = n - 1
	meio = 0
	resta = tem[dia]
	while ini <= fim:
		meio = (ini + fim) // 2
		if preco[meio] <= resta and resta < preco[meio + 1]:
			break
		elif preco[meio + 1] <= resta:
			ini = meio + 1
		else:
			fim = meio - 1
	if fim < 0:
		return 0
	else:
		return meio + 1

def main():
	global n, q, preco, tem
	n = int(input())
	preco = [int(i) for i in input().split()] + [100010]
	q = int(input())
	tem = [int(input()) for i in range(q)]
	preco.sort()
	for dia in range(q):
		print(busca(dia))
main()


from bisect import bisect_right
n = int(input())
price = list(map(int, input().split()))
days = int(input())
price.sort()
for i in range(0, days):
	money = int(input())
	print(bisect_right(price, money))


def bin_search(li, val):
	lo = 0
	hi = len(li) - 1
	while lo < hi:
		mid = lo + (hi - lo) // 2
		if li[mid] == val:
			return mid + 1
		elif li[mid] < val:
			lo = mid + 1
		else:
			hi = mid
	if li[hi] <= val:
		return hi + 1
	return hi
shops = int(input())
prices = [int(x) for x in input().split()]
days = int(input())
prices = sorted(prices)
for i in range(days):
	print(bin_search(prices, int(input()) + 0.5))


from math import sqrt
n = int(input())
a = sorted(list(map(int, input().split())))
q = int(input())
k = 0
kq = ''
r = n
l = 0
c = 0
for i in range(q):
	w = int(input())
	if w < a[0]:
		kq += str(0) + '\n'
	elif w >= a[-1]:
		kq += str(n) + '\n'
	else:
		while l + 1 != r:
			c = (r + l) // 2
			if w >= a[c]:
				l = c
			else:
				r = c
		l = 0
		r = n
		if a[c] == w:
			while a[c] == w:
				c += 1
				if a[c] > w:
					kq += str(c) + '\n'
					break
		elif a[c] > w:
			kq += str(c) + '\n'
		elif a[c] < w:
			kq += str(c + 1) + '\n'
		c = 0
print(kq)


n = int(input())
a = list(map(int, input().split()))
a.sort()
import bisect
k = int(input())
for i in range(k):
	p = int(input())
	print(bisect.bisect_right(a, p))


n = int(input())
X = [*sorted(map(int, input().split()))]
q = int(input())
for _ in range(q):
	m = int(input())
	(lo, hi) = (0, len(X))
	while lo < hi:
		mid = lo + (hi - lo) // 2
		if m < X[mid]:
			hi = mid
		else:
			lo = mid + 1
	print(lo)


import bisect
n = int(input())
l = list(map(int, input().strip().split()))
l.sort()
m = int(input())
for i in range(m):
	a = int(input())
	print(bisect.bisect(l, a))


def lowerBound(arr, x):
	ans = -1
	l = 0
	r = len(arr) - 1
	while l <= r:
		mid = (l + r) // 2
		if arr[mid] <= x:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	return ans
n = int(input())
drinks = [int(i) for i in input().split(' ')]
drinks.sort()
m = int(input())
for money in range(m):
	price = int(input())
	ind = lowerBound(drinks, price)
	print(ind + 1)


n = int(input())
x = [int(i) for i in input().split()]
x.sort()
mon = []
q = int(input())
dp = {}
a = []
for i in range(q):
	temp = int(input())
	mon.append(temp)
	a.append(temp)
	dp[temp] = 0
mon.sort()
ind = 0
for j in range(n):
	if mon[0] >= x[j]:
		dp[mon[0]] = j + 1
		ind = j
	else:
		break
for i in range(1, q):
	for j in range(ind, n):
		if mon[i] >= x[j]:
			ind = j
			dp[mon[i]] = j + 1
		else:
			break
for v in a:
	print(dp[v])


def func(arr, x):
	i = 0
	j = len(arr) - 1
	ans = 0
	while i <= j:
		mid = (i + j) // 2
		if x >= arr[mid]:
			ans = mid + 1
			i = mid + 1
		elif x < arr[mid]:
			j = mid - 1
	return ans
n = int(input())
a = [int(x) for x in input().split()]
k = int(input())
a.sort()
for i in range(k):
	x = int(input())
	print(func(a, x))


n = input()
prices = list(map(int, input().strip().split()))
q = int(input())
arr = sorted(prices)
for i in range(q):
	start = 0
	target = int(input())
	end = len(arr) - 1
	ans = -1
	gizmo = False
	if target >= arr[end]:
		gizmo = True
		print(len(arr))
	while start <= end and (not gizmo):
		mid = (start + end) // 2
		if arr[mid] <= target:
			start = mid + 1
		else:
			end = mid - 1
			ans = mid
	if not gizmo:
		print(ans)


import statistics
s = int(input())
arr = [int(new) for new in input().split()]
arr.sort()
d = int(input())
for x in range(d):
	money = int(input())
	print(statistics.bisect_right(arr, money))


from bisect import bisect_right as br
import sys
from collections import *
from math import *
import re

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	c = 0
	for i in range(2, n):
		if prime[i]:
			c += 1
	return c

def iseven(n):
	return [False, True][0 if n % 2 else 1]

def inp_arr():
	return list(map(int, input().split()))

def inp():
	return map(int, input().split())

def lcm(a, b):
	return a * b / gcd(a, b)
max_int = sys.maxsize
mod = 10 ** 9 + 7
n = int(input())
x = sorted(inp_arr())
q = int(input())
while q:
	print(br(x, int(input())))
	q -= 1


import bisect
n = int(input())
x = sorted(map(int, input().split()))
for _ in range(int(input())):
	m = int(input())
	print(bisect.bisect_right(x, m))


from bisect import bisect
n = int(input())
f = list(map(int, input().split()))
f.sort()
q = int(input())
for j in range(q):
	c = int(input())
	print(bisect(f, c))


n = int(input())
a = []
b = []
c = []
a = list(map(int, input().split()))
a.sort()
a = [0] + a
l = len(a)
now = 0
for i in range(1, l):
	for x in range(a[i] - a[i - 1]):
		b.append(now)
	now += 1
r = len(b)
k = int(input())
for i in range(k):
	v = int(input())
	if v < r:
		c.append(b[v])
	else:
		c.append(l - 1)
for i in c:
	print(i)


def bin_search(x, l, r):
	if r - l <= 1:
		return l
	else:
		m = (r + l) // 2
		if x >= prices[m]:
			l = m
		else:
			r = m
		return bin_search(x, l, r)
n = int(input())
prices = [-1]
prices += list(map(int, input().split()))
prices.append(float('inf'))
p_len = len(prices)
q = int(input())
money = []
for i in range(q):
	money.append(int(input()))
prices.sort()
for x in money:
	print(bin_search(x, 0, p_len))


N = int(input())
prices = sorted(list(map(int, input().split())))
Q = int(input())

def bs(p, b):
	(lo, hi) = (0, N)
	while lo < hi:
		mid = (lo + hi) // 2
		if p[mid] > b:
			hi = mid
		else:
			lo = mid + 1
	return lo
for i in range(Q):
	budget = int(input())
	num = bs(prices, budget)
	print(num)


import bisect
n = int(input())
a = [int(x) for x in input().split()]
b = []
a = sorted(a)
m = int(input())
for i in range(m):
	c = int(input())
	b.append(bisect.bisect(a, c))
for i in b:
	print(i)


maxx = 100100
n = int(input())
lis = list(map(int, input().split()))
bottle = [0] * maxx
for x in lis:
	bottle[x] += 1
for i in range(1, maxx, 1):
	bottle[i] += bottle[i - 1]
for _ in range(int(input())):
	x = int(input())
	if x > maxx:
		print(bottle[maxx - 1])
	else:
		print(bottle[x])


import sys
from bisect import bisect as br, bisect_left as bl
readline = sys.stdin.readline
N = int(readline())
X = list(map(int, readline().split()))
Q = int(readline())
X.sort()
Ans = [None] * Q
for qu in range(Q):
	m = int(readline())
	Ans[qu] = br(X, m)
print('\n'.join(map(str, Ans)))


n = int(input())
lx = list(map(int, input().split()))
q = int(input())
d = {}
for i in range(1, 100001):
	d[i] = 0
for j in lx:
	d[j] += 1
for k in range(2, 100001):
	d[k] += d[k - 1]
for i in range(q):
	m = int(input())
	if m <= 100000:
		print(d[m])
	else:
		print(n)


from sys import stdin, stdout
n = int(stdin.readline())
x = [int(s) for s in stdin.readline().split()]
q = int(stdin.readline())
m = [int(stdin.readline()) for i in range(q)]
x.sort()
m_sort = m.copy()
m_sort.sort()
z = {}
x.append(9223372036854775807)
i = 0
for p in m_sort:
	while (x[i] <= p) & (i <= n):
		i = i + 1
	z[p] = i
for p in m:
	print(z[p])


n = int(input())
x = list(map(int, input().split()))
k = max(x)
flag = [0] * (k + 1)
dp = [0] * (k + 1)
for i in range(n):
	flag[x[i]] += 1
for i in range(1, k + 1):
	if flag[i]:
		dp[i] = dp[i - 1] + flag[i]
	else:
		dp[i] = dp[i - 1]
q = int(input())
for i in range(q):
	m = int(input())
	if m >= k:
		print(n)
	else:
		print(dp[m])


n = int(input())
b = [0] * 100010
a = map(int, input().split())
for x in a:
	b[x] += 1
for i in range(1, 100010):
	b[i] += b[i - 1]
q = int(input())
while q:
	t = int(input())
	t = min(t, 100000)
	print(b[t])
	q -= 1


from bisect import bisect
n = int(input())
x = sorted([int(x) for x in input().split()])
q = int(input())
for _ in range(q):
	m = int(input())
	print(bisect(x, m))


n = int(input())
shop = [int(x) for x in input().split()]
shop.sort()
d = shop[-1]
shopnumber = [0] * (d + 1)
for i in shop:
	shopnumber[i] += 1
for i in range(2, d + 1):
	shopnumber[i] += shopnumber[i - 1]
for i in range(int(input())):
	m = int(input())
	if m >= d:
		print(n)
	else:
		print(shopnumber[m])


def s():
	n = int(input())
	import bisect
	a = list(map(int, input().split()))
	a.sort()
	m = int(input())
	for _ in range(m):
		print(bisect.bisect_right(a, int(input())))
s()


def UpperBound(t, key):
	left = -1
	right = len(t)
	while right > left + 1:
		middle = (left + right) // 2
		if t[middle] > key:
			right = middle
		else:
			left = middle
	return right
a = int(input())
b = input().split()
d = []
for i in range(a):
	d.append(int(b[i]))
d.sort()
e = int(input())
for i in range(e):
	f = int(input())
	if f > d[-1]:
		print(a)
	elif f < d[0]:
		print(0)
	else:
		index = UpperBound(d, f)
		print(index)


import sys, bisect

def interesting_drink_solve(r, w):
	num_shops = int(r.readline())
	shop_cost_data = r.readline().split()
	shop_cost = []
	for cost in shop_cost_data:
		shop_cost.append(int(cost))
	shop_cost.sort()
	num_days = int(r.readline())
	for _ in range(num_days):
		money_for_day = int(r.readline())
		result = bisect.bisect_right(shop_cost, money_for_day)
		print(result)
interesting_drink_solve(sys.stdin, sys.stdout)


from bisect import bisect_right
n = int(input())
lst = sorted(list(map(int, input().split())))
m = int(input())
query = [int(input()) for i in range(m)]
for i in range(m):
	print(bisect_right(lst, query[i]))


from bisect import bisect_right

def find_le(l, b):
	i = bisect_right(l, b)
	if i:
		return i
from sys import stdin, stdout
n = int(stdin.readline().rstrip())
x = sorted(map(int, stdin.readline().rstrip().split()))
q = int(stdin.readline().rstrip())
for i in range(q):
	m = int(stdin.readline().rstrip())
	if m >= x[0]:
		stdout.write(str(find_le(x, m)) + '\n')
	else:
		stdout.write('0\n')


n = int(input())
s = str(input()).split()
for i in range(n):
	s[i] = int(s[i])
s.sort()
q = int(input())
for i in range(q):
	x = int(input())
	a = 0
	b = len(s) - 1
	while a <= b:
		k = (a + b) // 2
		if a == b and s[k] != x:
			if s[k] > x:
				while k - 1 != -1 and s[k - 1] > x:
					k -= 1
				break
			else:
				while k != n and s[k] < x:
					k += 1
				break
		elif s[k] == x:
			while k != n - 1 and s[k + 1] == x:
				a = k + 1
				while a <= b:
					k = (a + b) // 2
					if s[k] == x:
						break
					elif s[k] > x:
						b = k - 1
			k += 1
			break
		elif s[k] > x:
			b = k - 1
		else:
			a = k + 1
	if b < a:
		if s[k] > x:
			while k - 1 != -1 and s[k - 1] > x:
				k -= 1
		else:
			while k != n and s[k] < x:
				k += 1
	print(k)


import bisect
input()
mat = sorted(map(int, input().split()))
res = ''
for i in range(int(input())):
	res += str(bisect.bisect_right(mat, int(input()))) + '\n'
print(res[0:-1])


n1 = int(input())
l = list(map(int, input().split()))
l.sort()
t = []
d = {}
n2 = int(input())
for i in range(n2):
	t.append(int(input()))
r = list(t)
t.sort()
j = 0
for i in range(len(t)):
	while j < len(l):
		if t[i] >= l[j]:
			pass
		else:
			break
		j = j + 1
	d[t[i]] = j
for i in r:
	print(d[i])


from bisect import bisect_right
n = int(input())
x = [int(x) for x in input().split()]
x.sort()
q = int(input())
for _ in range(q):
	e = int(input())
	print(bisect_right(x, e))


import bisect
shops = int(input())
coins = sorted([int(x) for x in input().split()])
for i in range(int(input())):
	m = int(input())
	print(bisect.bisect_right(coins, m))


n = int(input())
Shops = input().split()
Shops = sorted([int(num) for num in Shops])
q = int(input())
Coins = []
num_Shops = []
for i in range(q):
	k = int(input())
	Coins.append(k)

def Binary_Search(ele, arr, Min, Max, total):
	if Min == Max:
		if arr[Min] <= ele:
			return total + 1
		return total
	mid = (Min + Max) // 2
	if arr[mid] > ele:
		total = Binary_Search(ele, arr, Min, mid, total)
	else:
		total = mid + 1
		total = Binary_Search(ele, arr, mid + 1, Max, total)
	return total
for coin in Coins:
	num_Shops.append(Binary_Search(coin, Shops, 0, n - 1, 0))
for num in num_Shops:
	print(num)


import sys
import math
import bisect
import re

def main():
	n = int(input())
	A = list(map(int, input().split()))
	A.sort()
	q = int(input())
	while q:
		q -= 1
		a = int(input())
		first = 0
		last = bisect.bisect_right(A, a)
		print(last - first)
main()


def bisearch_modified(size, value):
	current = 0
	while size > 1:
		step = size // 2
		if value >= price[current + step]:
			current += step
			size -= step
		else:
			size = step
	return current

def main():
	n = int(input())
	global price
	price = list(map(int, input().split()))
	price.append(0)
	price.sort()
	q = int(input())
	for _ in range(q):
		coins = int(input())
		print(bisearch_modified(len(price), coins))
main()


n = int(input())
lis = [int(y) for y in input().split()]
lis.sort()
q = int(input())
for w in range(q):
	x = int(input())
	left = 0
	right = n - 1
	ind = -1
	while left <= right:
		mid = (left + right) // 2
		if lis[mid] <= x:
			ind = mid
			left = mid + 1
		else:
			right = mid - 1
	print(ind + 1)


shops_amount = int(input())
prices = list(map(int, input().strip().split()))[:shops_amount]
prices.sort()
days_amount = int(input())
wallet = [int(input()) for i in range(days_amount)]

def binary_search(item_list, item):
	idx = 0
	quantity = 0
	for _ in range(len(item)):
		first = 0
		last = len(item_list) - 1
		found = False
		while not found:
			mid = (first + last) // 2
			if first >= last:
				if mid < 0:
					quantity = 0
					found = True
				elif item_list[mid] > item[idx]:
					quantity = mid
					found = True
				else:
					quantity = mid + 1
					found = True
			elif item_list[mid] > item[idx]:
				last = mid - 1
			else:
				first = mid + 1
		print(quantity)
		quantity = 0
		idx += 1
binary_search(prices, wallet)


from collections import Counter
import bisect
n = int(input())
li = sorted(list(map(int, input().split())))
day = int(input())
l = []
for _ in range(day):
	x = int(input())
	index = bisect.bisect_left(li, x + 1, 0, n)
	l.append(index)
for e in l:
	print(e)


n = int(input())
shop = list(map(int, input().split(' ')))
tcount = list()
shop.sort()
total = 0
for i in range(0, shop[0]):
	tcount.append(total)
for i in range(0, n - 1):
	total = total + 1
	for j in range(shop[i], shop[i + 1]):
		tcount.append(total)
total = total + 1
tcount.append(total)
q = int(input())
for i in range(0, q):
	a = int(input())
	if a > shop[n - 1]:
		print(n)
	else:
		print(tcount[a])


from bisect import bisect_right as br
n = int(input())
prices = [int(x) for x in input().split()]
prices.sort()
mx = prices[-1]
q = int(input())
for i in range(q):
	coins = int(input())
	if coins < prices[0]:
		print(0)
	elif coins > mx:
		print(n)
	else:
		print(br(prices, coins))


n = int(input())
xs = list(map(int, input().split()))
count = [0] * 100009
for i in range(len(xs)):
	count[xs[i]] += 1
for i in range(1, 100009):
	count[i] += count[i - 1]
q = int(input())
for i in range(q):
	m = int(input())
	if m >= 100009:
		print(n)
	else:
		print(count[m])


import bisect
n = int(input())
l = list(map(int, input().split()))
t = int(input())
l.sort()
while t:
	print(bisect.bisect(l, int(input())))
	t = t - 1


def binary(l, f):
	a = 0
	b = len(l) - 1
	while a <= b:
		m = a + (b - a) // 2
		if l[m] <= f:
			a = m + 1
		else:
			b = m - 1
	if l[m] <= f:
		return m + 1
	else:
		return m
n = int(input())
shop_price = list(map(int, input().split(' ')))
shop_price.sort()
q = int(input())
for i in range(q):
	coins = int(input())
	a = binary(shop_price, coins)
	print(a)


def bst(A, x):
	if A[0] > x:
		return -1
	begin = 0
	end = len(A)
	while end - begin > 1:
		mid = (end + begin) // 2
		if A[mid] <= x:
			begin = mid
		else:
			end = mid
	return begin
n = int(input())
A = [int(i) for i in input().split()]
A = sorted(A)
d = int(input())
D = []
for i in range(d):
	D += [int(input())]
ans = []
for i in range(d):
	x = D[i]
	begin = 0
	end = len(A)
	while end - begin > 1:
		mid = (end + begin) // 2
		if A[mid] <= x:
			begin = mid
		else:
			end = mid
	oo = begin
	if A[0] > x:
		oo = -1
	ans += [oo + 1]
for i in ans:
	print(i)


def thanos(a, l, r, k):
	if l > r:
		return 0
	else:
		mid = (l + r) // 2
		if a[mid] > k:
			return thanos(a, l, mid - 1, k)
		elif mid + 1 < len(a):
			if a[mid + 1] > k:
				return mid + 1 - l
			else:
				return mid - l + thanos(a, mid + 1, r, k) + 1
		else:
			return 1
n = int(input())
x = input().split()
for i in range(len(x)):
	x[i] = int(x[i])
x.sort()
q = int(input())
qq = []
while q > 0:
	m = int(input())
	qq.append(thanos(x, 0, len(x) - 1, m))
	q -= 1
print(*qq, sep='\n')


from bisect import bisect_right
__author__ = 'artyom'

def main():
	n = read()
	ps = sorted(read(3))
	res = []
	for i in range(read()):
		m = read()
		res.append(bisect_right(ps, m))
	return res

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = '\n'.join(map(str, s))
	s = str(s)
	print(s, end='')
write(main())


from bisect import bisect
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
q = int(input())
for _ in range(q):
	a = int(input())
	if a >= l[-1]:
		print(len(l))
	elif a < l[0]:
		print(0)
	else:
		print(bisect(l, a))


def bs(a, x):
	high = n - 1
	low = 0
	while low < high:
		mid = low + (high - low) // 2
		if a[mid] <= x < a[mid + 1]:
			return mid
		elif a[mid] > x:
			high = mid
		elif a[mid] <= x:
			low = mid
	return 0
n = int(input())
a = list(map(int, input().split()))
a.sort()
k = int(input())
for i in range(k):
	x = int(input())
	if x < a[0]:
		print(0)
	elif x >= a[-1]:
		print(n)
	else:
		print(bs(a, x) + 1)


import bisect
n = int(input())
li = list(map(int, input().split()))
li.sort()
q = int(input())
for i in range(q):
	m = int(input())
	ind = bisect.bisect_right(li, m)
	if ind < n and li[ind] == m:
		print(ind + 1)
	else:
		print(ind)


num_shops = int(input())
shop_costs = sorted(map(int, input().split()))
num_days = int(input())
for d in range(num_days):
	today_money = int(input())
	lo = -1
	hi = len(shop_costs)
	while lo + 1 < hi:
		mid = int((lo + hi) / 2)
		if shop_costs[mid] <= today_money:
			lo = mid
		else:
			hi = mid
	print(lo + 1)


from sys import stdin, stdout
input_ = stdin.readline

def binary_search(arr, num):
	high = len(arr) - 1
	low = 0
	while low <= high:
		mid = (low + high) // 2
		if arr[mid] <= num:
			low = mid + 1
		elif arr[mid] > num:
			high = mid - 1
	return str(high + 1)
shops = int(input_())
arr = list(map(int, input_().split()))
arr.sort()
days = int(input_())
for i in range(days):
	price = int(input_())
	r = binary_search(arr, price)
	stdout.write(r + '\n')


def binSearch(a, x):
	l = -1
	r = len(a)
	while l < r - 1:
		m = (l + r) // 2
		if a[m] <= x:
			l = m
		else:
			r = m
	return r
n = int(input())
x = [int(i) for i in input().split()]
q = int(input())
x = sorted(x)
for i in range(q):
	m = int(input())
	print(binSearch(x, m))


n = int(input())
l = [int(x) for x in input().split()]
l = sorted(l)
mx = l[n - 1] + 1
dp = [0 for i in range(mx)]
cnt = 1
for i in range(0, n - 1):
	for j in range(l[i], l[i + 1]):
		dp[j] = cnt
	cnt += 1
q = int(input())
for _ in range(q):
	temp = int(input())
	if temp < l[n - 1]:
		print(dp[temp])
	else:
		print(n)


import bisect
num_s = int(input())
p_list = [int(i) for i in input().split()]
p_list.sort()
num_d = int(input())
found = dict()
for i in range(num_d):
	coins = int(input())
	num = bisect.bisect(p_list, coins)
	print(num)


from collections import defaultdict
import math
import sys
_ = input()
numbers = [int(i) for i in input().split(' ')]
numbers = sorted(numbers)
Q = int(input())
for _ in range(Q):
	N = int(input())
	if N < numbers[0]:
		print(0)
		continue
	l = 0
	r = len(numbers) - 1
	while l <= r:
		mid = l + (r - l) // 2
		curr = numbers[mid]
		if curr <= N:
			l = mid + 1
		elif curr > N:
			r = mid - 1
	print(l)


import sys
n = int(sys.stdin.readline().rstrip())
prices = [int(i) for i in sys.stdin.readline().rstrip().split()]
prices.sort()
q = int(sys.stdin.readline().rstrip())
coins = [int(sys.stdin.readline().rstrip()) for _ in range(q)]

def binsearch(coin):
	(hi, lo) = (len(prices) - 1, 0)
	while lo <= hi:
		mid = (hi + lo) // 2
		if prices[mid] > coin and prices[mid - 1] <= coin:
			return mid
		if prices[mid] > coin:
			hi = mid - 1
		else:
			lo = mid + 1
	if hi == len(prices) - 1:
		return len(prices)
	return 0
print('\n'.join([str(binsearch(coin)) for coin in coins]))


def count(arr, x):
	s = 0
	e = len(arr)
	while True:
		m = (s + e) // 2
		if arr[m] <= x:
			s = m
		else:
			e = m
		mn = (s + e) // 2
		if mn == m:
			break
	return e
n = int(input())
nums = sorted(list(map(int, input().split())))
q = int(input())
while q > 0:
	c = int(input())
	print(count(nums, c))
	q = q - 1


n = int(input())
A = list(map(int, input().split()))
A.sort()
q = int(input())
for i in range(q):
	a = int(input())
	l = -1
	r = n
	while l + 1 < r:
		m = (l + r) // 2
		if A[m] > a:
			r = m
		else:
			l = m
	print(r)


from sys import stdout
log = lambda *x: print(*x)

def cin(*fn, def_fn=str):
	(i, r) = (0, [])
	for c in input().split(' '):
		r += [(fn[i] if len(fn) > i else fn[0])(c)]
		i += 1
	return r
N = 100005
(n,) = cin(int)
x = cin(int)
(q,) = cin(int)
freq = [0] * (N + 1)
for v in x:
	freq[v] += 1
dp = [0] * (N + 1)
for i in range(1, N + 1):
	dp[i] = dp[i - 1] + freq[i]
for i in range(q):
	(m,) = cin(int)
	m = min(m, N)
	log(dp[m])


import math
from collections import Counter, defaultdict
import sys
mod = 10 ** 9 + 7
input = sys.stdin.readline
readInt = lambda : int(input().strip())
readfloat = lambda : float(input().strip())
readStr = lambda : input().strip()
intList = lambda : list(map(int, input().strip().split()))
intMap = lambda : map(int, input().strip().split())
floatList = lambda : list(map(float, input().strip().split()))
floatMap = lambda : map(float, input().strip().split())
strList = lambda : list(input().strip().split())

def print(*args, end='\n', sep=' '):
	for i in args:
		sys.stdout.write(str(i))
		sys.stdout.write(sep)
	sys.stdout.write(end)

def solve(coins):
	if coins in c:
		return c[coins]
	if coins < s[0]:
		return 0
	if coins > s[-1]:
		return n
	last = len(s)
	start = 0
	while start <= last:
		mid = (start + last) // 2
		if s[mid] < coins and s[mid + 1] > coins:
			return c[s[mid]]
		if s[mid] > coins and s[mid - 1] < coins:
			return c[s[mid - 1]]
		if coins > s[mid]:
			start = mid + 1
		else:
			last = mid - 1
	return c[s[start]]
n = readInt()
arr = intList()
c = Counter(arr)
s = sorted(set(arr))
prev = 0
for i in s:
	c[i] += prev
	prev = c[i]
for q in range(readInt()):
	coins = readInt()
	print(solve(coins))


n = int(input())
l = list(map(int, input().split()))
q = int(input())
l.sort()

def b_search(l, x):
	if l[0] > x:
		return 0
	if l[-1] <= x:
		return len(l)
	else:
		s = 0
		e = len(l) - 1
		while True:
			if l[(s + e) // 2] > x and l[(s + e) // 2 - 1] <= x:
				return (s + e) // 2
			elif l[(s + e) // 2] > x:
				e = (s + e) // 2 - 1
			else:
				s = (s + e) // 2 + 1
p = [int(input()) for _ in range(q)]
for i in p:
	print(b_search(l, i))


import bisect
n = int(input())
prices = sorted((int(c) for c in input().split()))
q = int(input())
for _ in range(q):
	coins = int(input())
	print(bisect.bisect_right(prices, coins))


import sys
f = sys.stdin
n = int(f.readline())
x = [int(bobo) for bobo in f.readline().split()]
q = int(f.readline())
m = []
for i in range(q):
	m.append(int(f.readline()))
x.sort()
x.append(9223372036854775807)
m_sort = m.copy()
m_sort.sort()
possible_bars = {}
total_bar = 0
for possible_money in m_sort:
	while x[total_bar] <= possible_money:
		total_bar = total_bar + 1
	possible_bars[possible_money] = total_bar
for money_now in m:
	print(possible_bars[money_now])


from bisect import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
dp = [n] * 100001
(i, j) = (0, 0)
c = 0
while i < n:
	e = l[i]
	if e > j:
		while e > j:
			dp[j] = c
			j = j + 1
		c = c + 1
		i = i + 1
		dp[j] = c
	elif e == j:
		i = i + 1
		c = c + 1
		dp[j] = c
q = int(input())
for i in range(q):
	e = int(input())
	if e > 100000:
		print(n)
	else:
		print(dp[e])


from bisect import bisect_left, bisect_right
n = int(input())
cost = [int(x) for x in input().split()]
q = int(input())
money = [int(x) for x in [input() for i in range(q)]]
cost.sort()
for money_in_day in money:
	print(bisect_right(cost, money_in_day))


n = int(input())
x = list(map(int, input().split()))
q = int(input())
x.sort()
s = []
for i in range(n):
	s += [i] * (x[i] - (0 if i == 0 else x[i - 1]))
for _ in range(q):
	k = int(input())
	if k < len(s):
		print(s[k])
	else:
		print(n)


from sys import stdin

def bs_upbound(lista, n, x):
	l = 0
	h = n
	while l < h:
		mid = (l + h) // 2
		cond = False
		if x >= lista[mid]:
			l = mid + 1
		else:
			h = mid
	if x >= lista[mid]:
		return mid + 1
	return mid

def main():
	long = int(stdin.readline())
	shops = [int(x) for x in stdin.readline().split()]
	shops.sort()
	n = int(stdin.readline())
	for i in range(n):
		z = int(stdin.readline())
		cont = 0
		print(bs_upbound(shops, long, z))
main()


def solve(arr, x):
	ans = 0
	(l, r) = (0, len(arr) - 1)
	while l <= r:
		mid = (l + r) // 2
		if x >= arr[mid]:
			ans = mid + 1
			l = mid + 1
		else:
			r = mid - 1
	return ans
n = int(input())
arr = sorted(list(map(int, input().split())))
m = int(input())
z = []
for i in range(m):
	x = int(input())
	r = solve(arr, x)
	z.append(r)
for i in z:
	print(i)


n = int(input())
ls = list(map(int, input().split()))
ls.sort()
mm = min(ls)
mx = max(ls)
q = int(input())
ans = []
for i in range(q):
	m = int(input())
	if m < mm:
		ans.append(0)
		continue
	elif m > mx:
		ans.append(n)
		continue
	else:
		flag = 0
		s = 0
		e = len(ls) - 1
		mid = int((s + e) / 2)
		if mid == 0:
			ans.append(1)
			continue
		while m >= ls[mid + 1] or m < ls[mid - 1] or m < ls[mid]:
			flag = 1
			if ls[mid] > m:
				e = mid
				if int((s + e) / 2) == mid:
					mid = mid + 1
				else:
					mid = int((s + e) / 2)
			else:
				s = mid
				if int((s + e) / 2) == mid:
					mid = mid + 1
				else:
					mid = int((s + e) / 2)
			if mid == n - 1 or mid == 0:
				break
		if mid == 0 and m < ls[mid]:
			ans.append(mid)
		else:
			ans.append(mid + 1)
for i in range(q):
	print(ans[i])


n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
ans = []
q = int(input())
for j in range(q):
	i = int(input())
	lo = -1
	up = n - 1
	while lo + 1 < up:
		mm = (lo + up) // 2
		if l[mm] > i:
			up = mm - 1
		else:
			lo = mm
	if lo + 1 < n and l[lo + 1] <= i:
		ans.append(lo + 2)
	else:
		ans.append(lo + 1)
print('\n'.join(map(str, ans)))


import bisect
n = input()
l = sorted(map(int, input().split()))
l2 = []
for i in range(int(input())):
	x = int(input())
	l2.append(bisect.bisect(l, x))
print(*l2, sep='\n')


def lower_bound(x, a):
	l = 0
	u = len(a) - 1
	res = 0
	while l <= u:
		m = (l + u) // 2
		if a[m] <= x:
			l = m + 1
			res = m + 1
		else:
			u = m - 1
	return res

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	q = int(input())
	while q > 0:
		x = int(input())
		print(lower_bound(x, a))
		q -= 1
t = 1
while t > 0:
	solve()
	t -= 1


n = int(input())
a = [int(i) for i in input().split()]
b = [0] * 100001
for i in a:
	b[i] += 1
c = [0] * 100001
t = b[0]
for i in range(100001):
	if i == 0:
		c[i] = t
	else:
		t += b[i]
		c[i] = t
d = int(input())
for i in range(d):
	t = int(input())
	if t > 100000:
		print(n)
	else:
		print(c[t])


def find(x, n, m):
	beg = 0
	end = n - 1
	ans = 0
	while beg <= end:
		mid = (beg + end) // 2
		if x[mid] <= m:
			ans = mid + 1
			beg = mid + 1
		else:
			end = mid - 1
	return ans
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	m = int(input())
	print(find(x, n, m))


n = int(input())
lst1 = list(map(int, input().split()))
q = int(input())
max1 = max(lst1)
dp = [0] * (max1 + 1)
a = 0
dict1 = {}
for i in range(n):
	if lst1[i] in dict1:
		dict1[lst1[i]] += 1
	else:
		dict1[lst1[i]] = 1
for i in range(min(lst1), max1 + 1):
	if i in dict1:
		a += dict1[i]
	dp[i] = a
for i in range(q):
	m = int(input())
	if m > max1:
		print(len(lst1))
	else:
		print(dp[m])


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())
n = ii()
a = li()
a.sort()
m = a[n - 1]
s = []
j = 0
for i in range(n):
	s += [i] * (a[i] - j)
	j = a[i]
for i in range(ii()):
	p = ii()
	print(s[p] if p < m else n)


n = int(input())
lst = list(map(int, input().split()))
lst.sort()
q = int(input())
for i in range(q):
	z = int(input())
	(l, r) = (0, n)
	while l < r:
		mid = (l + r) // 2
		if lst[mid] <= z:
			l = mid + 1
		else:
			r = mid
	print(l)


import bisect
n = int(input())
tab1 = [int(y) for y in input().split()]
q = int(input())
tab1.sort()
for i in range(q):
	x = int(input())
	print(bisect.bisect_right(tab1, x))


from bisect import bisect

def itd(l, k):
	c = len(l) - bisect(l, k)
	print(len(l) - c)
	return
n = int(input())
t = input()
l = list(map(int, t.split(' ')))
l.sort()
q = int(input())
for i in range(q):
	p = int(input())
	itd(l, p)


import bisect

def problem_answer(prices, daily_money):
	prices.sort()
	for money in daily_money:
		index = bisect.bisect_right(a=prices, x=money)
		print(str(index))
n = int(input())
prices = [int(x) for x in input().split()]
q = int(input())
daily_money = []
for i in range(q):
	daily_money.append(int(input()))
problem_answer(prices, daily_money)


def bibi(a, x):
	lo = 0
	high = len(a)
	while lo < high:
		mid = (lo + high) // 2
		if x < a[mid]:
			high = mid
		else:
			lo = mid + 1
	return lo
n = int(input())
s = list(map(int, input().split()))
q = int(input())
s2 = [int(input()) for i in range(q)]
s.sort()
for i in range(q):
	print(bibi(s, s2[i]))


import sys
input = lambda : sys.stdin.readline().strip()
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
for i in range(q):
	m = int(input())
	left = -1
	right = n - 1
	while right > left + 1:
		mid = (left + right) // 2
		if x[mid] > m:
			right = mid
		else:
			left = mid
	if x[right] > m:
		print(left + 1)
	else:
		print(right + 1)


import bisect
for t in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	for q in range(int(input())):
		m = int(input())
		pos = bisect.bisect_right(arr, m)
		print(pos)


import sys
import collections
import math
import functools
import itertools
import bisect
import operator
import heapq
import random
true = True
false = False
null = None
tcid = 0
tcmax = 99999999

def compute(val, func):
	return func(val)

def seq(lo, hi, step=1):
	return range(lo, hi + 1, step)

def sround(val, nd):
	return f'{val:.{nd}f}'

def ceil(a, b):
	ans = a // b
	if a % b != 0:
		ans += 1
	return ans

def perr(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def line():
	ln = sys.stdin.readline().strip()
	if ln == '':
		sys.exit()
	return ln

def lines(n):
	return [line() for i in range(n)]

def split(ln=None):
	return (ln or line()).split()

def nums(o=None):
	if o is not None:
		if isinstance(o, int):
			o = lines(o)
		elif isinstance(o, str):
			o = split(o)
	return list(map(eval, o or split()))

def num():
	return eval(line())

def mainloop(tcid=1):
	n = num()
	x = nums()
	q = num()
	m = nums(q)
	freq = [0] * 111111
	for xx in x:
		freq[xx] += 1
	for ii in range(len(freq) - 1):
		freq[ii + 1] += freq[ii]
	for mm in m:
		print(freq[mm] if mm < len(freq) else freq[-1])
while tcid < tcmax:
	tcid += 1
	mainloop(tcid)


from bisect import bisect
t = input
p = print
r = range
n = int(t())
x = list(map(int, t().split()))
q = int(t())
a = [0] * q
for i in r(q):
	a[i] = int(t())
x.sort()
for i in a:
	index = bisect(x, i)
	p(index)


import bisect
n = int(input())
arr = list(map(int, input().split()))
queries = []
arr.sort()
for i in range(int(input())):
	x = int(input())
	ans = bisect.bisect_right(arr, x, lo=0, hi=len(arr))
	print(ans)


from bisect import bisect_right
n = int(input())
x = list(map(int, input().split()))
x.sort()
q = int(input())
m = []
for _ in range(q):
	m.append(int(input()))
for i in m:
	tmp = bisect_right(x, i)
	print(tmp)


import bisect
n = int(input())
shops = [int(x) for x in input().split()]
shops.sort()
for _ in range(int(input())):
	m = int(input())
	print(bisect.bisect_right(shops, m))


from bisect import *
n = int(input())
l = list(map(int, input().split()))
l.sort()
for u in range(int(input())):
	x = int(input())
	print(bisect(l, x))


def solve(x_vec, m):
	l = 0
	r = len(x_vec) - 1
	if x_vec[l] > m:
		return 0
	if x_vec[r] <= m:
		return r + 1
	while r > l + 1:
		mid = (l + r) // 2
		if x_vec[mid] <= m:
			l = mid
		else:
			r = mid
	return l + 1
n = int(input())
x_vec = list(map(int, input().split()))
q = int(input())
m_vec = []
for i in range(q):
	m_vec.append(int(input()))
x_vec.sort()
for i in range(q):
	print(solve(x_vec, m_vec[i]))


def UpperBound(A, key):
	left = -1
	right = len(A)
	while right > left + 1:
		middle = (left + right) // 2
		if A[middle] > key:
			right = middle
		else:
			left = middle
	return right
n = int(input())
x = list(map(int, input().split()))
q = int(input())
m = []
for i in range(q):
	y = int(input())
	m.append(y)
x.sort()
for elem in m:
	i = UpperBound(x, elem)
	print(i)


from sys import stdin
n = int(stdin.readline().strip())
x = list((int(x) for x in stdin.readline().strip().split(' ')))
q = int(stdin.readline().strip())
yn = max(x) + 1
y = [0] * yn
z = 0
for i in range(n):
	y[x[i]] += 1
for i in range(yn):
	z += y[i]
	y[i] = z
for _ in range(q):
	m = int(stdin.readline().strip())
	if m >= len(y):
		print(n)
	else:
		print(y[m])


def binary_search(array, target):
	lower = 0
	upper = len(array)
	while lower < upper:
		x = lower + (upper - lower) // 2
		val = array[x]
		if target == val:
			return x
		elif target > val:
			if lower == x:
				return x
			lower = x
		elif target < val:
			upper = x
	return -1
n = int(input())
x = [0] * n
line2 = input()
line2 = line2.split(' ')
for i in range(n):
	x[i] = int(line2[i])
x.sort()
numStores = [0] * 100001
prevIndex = 0
for i in range(1, 100001):
	if i < x[0]:
		numStores[i] = 0
	elif i >= x[-1] or numStores[i - 1] == n:
		numStores[i] = n
	else:
		numStores[i] += numStores[i - 1]
		index = prevIndex
		while index < n:
			if x[index] <= i:
				index += 1
				numStores[i] += 1
			else:
				break
		prevIndex = index
q = int(input())
qlist = [0] * q
for _ in range(q):
	i = int(input())
	if i >= x[-1] or i >= 100000:
		print(n)
	else:
		print(numStores[i])


def bin_search(xs, x):

	def bin_search_rec(xs, x, s, e):
		if x < xs[s]:
			return s - 1
		elif x >= xs[e - 1]:
			return e - 1
		else:
			m = (s + e) // 2
			if x < xs[m]:
				return bin_search_rec(xs, x, s, m)
			elif x >= xs[m]:
				return bin_search_rec(xs, x, m + 1, e)
	return bin_search_rec(xs, x, 0, len(xs))
n = int(input())
xs = sorted([int(x) for x in input().split()])
ms = [int(input()) for _ in range(int(input()))]
memo = {}
for m in ms:
	if m not in memo:
		memo[m] = bin_search(xs, m) + 1
	print(memo[m])


n = int(input())
prices = list(map(int, input().split()))
days = int(input())
coins = [int(input()) for i in range(days)]

def solve(money, costs):
	lower = 0
	upper = len(costs) - 1
	while upper > lower + 1:
		middle = (upper + lower) // 2
		if costs[middle] <= money:
			lower = middle
		elif costs[middle] >= money:
			upper = middle
	if costs[upper] <= money:
		return upper + 1
	elif costs[lower] <= money:
		return upper
	elif costs[lower] > money:
		return lower
prices = sorted(prices)
for coin in coins:
	print(solve(coin, prices))


n = int(input())
x = [0] + [int(x) for x in input().split()]
Q = int(input())
x.sort()
while Q > 0:
	Q -= 1
	a = int(input())
	l = 1
	r = n
	ans = 0
	while l <= r:
		mid = (l + r) // 2
		if x[mid] <= a:
			ans = mid
			l = mid + 1
		else:
			r = mid - 1
	print(ans)


n = int(input())
input_x = map(int, input().split())
prices = {}
for i in input_x:
	if i in prices:
		prices[i] += 1
	else:
		prices[i] = 1
q = int(input())
m = []
for i in range(q):
	m.append(int(input()))
sum_arr = [0]
pivot = 0
for i in range(1, max(prices) + 1):
	if i in prices:
		sum_arr.append(sum_arr[i - 1] + prices[i])
	else:
		sum_arr.append(sum_arr[i - 1])
for i in m:
	if i < len(sum_arr):
		print(sum_arr[i])
	else:
		print(n)


import bisect
a = int(input())
x = list(map(int, input().split()))
x.sort()
x = [-1] + x + [float('INF')]
n = int(input())
for i in range(n):
	t = int(input())
	print(bisect.bisect_right(x, t) - 1)


from bisect import bisect_left, bisect, bisect_right

def find_le(a, x):
	i = bisect_right(a, x)
	return i
n = int(input())
prices = list(map(int, input().split()))
prices.sort()
for _ in range(int(input())):
	q = int(input())
	print(find_le(prices, q))


import math as m

def find_result():
	(low, high) = (0, len(price) - 1)
	while low <= high:
		mid = (low + high) // 2
		value = price[mid]
		if value > m:
			high = mid - 1
		else:
			low = mid + 1
	return low - 1
n = int(input())
price = list(map(int, input().split()))
price.sort()
q = int(input())
for i in range(q):
	m = int(input())
	res = find_result() + 1
	print(res)


def binarySearch(T, n, x):
	bottom = 0
	top = n - 1
	nb_shops = 0
	while bottom <= top:
		mid = (bottom + top) // 2
		if T[mid] > x:
			top = mid - 1
		elif T[mid] == x:
			nb_shops += mid - bottom + 1
			bottom = mid + 1
		else:
			bottom = mid + 1
			nb_shops = mid + 1
	return nb_shops

def main():
	n = int(input())
	L = list(map(int, input().split()))
	L.sort()
	q = int(input())
	M = list()
	for i in range(q):
		m = int(input())
		M.append(m)
	for i in M:
		nb_shops = binarySearch(L, n, i)
		print(nb_shops)
main()


import bisect
n = int(input())
x = list(map(int, input().rstrip().split()))
q = int(input())
x.sort()
for i in range(q):
	m = int(input())
	ind = bisect.bisect(x, m)
	print(ind)


n = int(input())
shops = [int(a) for a in input().split()]
HighestP = max(shops)
money = [0] * (HighestP + 1)
for shop in shops:
	money[shop] += 1
for i in range(1, HighestP + 1):
	money[i] += money[i - 1]
days = int(input())
results = [0] * days
for day in range(days):
	m = int(input())
	if m >= HighestP:
		results[day] = money[HighestP]
	else:
		results[day] = money[m]
for numb in results:
	print(numb)


def bsearch(lis, num):
	n = len(lis)
	first = 0
	last = n - 1
	while first <= last:
		mid = (first + last) // 2
		if lis[mid] <= num < lis[mid + 1]:
			return mid
		elif lis[mid] > num:
			last = mid - 1
		else:
			first = mid + 1
n = int(input())
nums = list(map(int, input().split()))
nums.append(0)
nums = sorted(nums)
days = int(input())
for day in range(days):
	money = int(input())
	if money >= nums[n]:
		print(n)
	else:
		ind = bsearch(nums, money)
		if nums[ind] <= money < nums[ind + 1]:
			print(ind)
		else:
			print(ind + 1)


import bisect
x = int(input())
a = list(map(int, input().split()))
n = int(input())
a.sort()
for __ in range(n):
	k = int(input())
	print(bisect.bisect(a, k))


def solve(l, h, x, m):
	count = 0
	while l <= h:
		mid = (l + h) // 2
		if m >= x[mid]:
			count = mid + 1
			l = mid + 1
		else:
			h = mid - 1
	return count
n = int(input())
x = list(map(int, input().split()))
x.sort()
d = int(input())
for _ in range(d):
	m = int(input())
	ans = solve(0, n - 1, x, m)
	print(ans)


n = int(input())
a = [int(x) for x in input().split()]
a.sort()
num = []
times = int(input())
ans = [0] * times
for i in range(times):
	num.append([int(input()), i])
num.sort(key=lambda x: x[0])
k = 0
for x in num:
	while k < n and a[k] <= x[0]:
		k += 1
	ans[x[1]] += k
print('\n'.join(map(str, ans)))


import os
import sys
from io import BytesIO, IOBase
from bisect import bisect_right
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def scanf(datatype=str):
	return datatype(sys.stdin.readline().rstrip())

def printf(answer=''):
	return sys.stdout.write(str(answer) + '\n')

def prints(answer):
	return sys.stdout.write(str(answer) + ' ')

def map_input(datatype=str):
	return map(datatype, sys.stdin.readline().split())

def list_input(datatype=str):
	return list(map(datatype, sys.stdin.readline().split()))

def testcase(number: int, solve_function):
	for _ in range(number):
		printf(solve_function())

def solve():
	n = scanf(int)
	arr = list_input(int)
	arr.sort()
	for _ in range(scanf(int)):
		m = scanf(int)
		printf(bisect_right(arr, m))
solve()


n = int(input())
x = [0] * n
line2 = input()
line2 = line2.split(' ')
for i in range(n):
	x[i] = int(line2[i])
x.sort()
numStores = [0] * 100001
prevIndex = 0
for i in range(1, 100001):
	if i < x[0]:
		numStores[i] = 0
	elif i >= x[-1] or numStores[i - 1] == n:
		numStores[i] = n
	else:
		numStores[i] += numStores[i - 1]
		index = prevIndex
		while index < n:
			if x[index] <= i:
				index += 1
				numStores[i] += 1
			else:
				break
		prevIndex = index
q = int(input())
qlist = [0] * q
for _ in range(q):
	i = int(input())
	if i >= x[-1] or i >= 100000:
		print(n)
	else:
		print(numStores[i])


import bisect
_ = input()
a = sorted([int(i) for i in input().split()])
for _ in range(int(input())):
	print(bisect.bisect(a, int(input())))


n = int(input())
line = list(map(int, input().split()))
a = [0] * 100002
q = int(input())
for i in line:
	a[i] += 1
for i in range(100002):
	a[i] = a[i - 1] + a[i]
for i in range(q):
	x = int(input())
	if x > 100002:
		print(n)
	else:
		print(a[x])


def find2(key, lst, lo, hi):
	while lo <= hi:
		mid = lo + (hi - lo) // 2
		val = lst[mid]
		if val <= key:
			if mid + 1 > hi or lst[mid + 1] > key:
				return mid
			else:
				lo = mid + 1
		elif val > key:
			hi = mid - 1
		else:
			return mid
	return -1

def main():
	n = int(input())
	X = sorted(map(int, input().split()))
	q = int(input())
	ans = ''
	for i in range(q):
		m = int(input())
		answer = find2(m, X, 0, n - 1) + 1
		ans += str(answer) + '\n'
	print(ans)
main()


from sys import stdin
import bisect
n = int(stdin.readline().strip())
m = sorted(list(map(int, stdin.readline().strip().split())))
q = int(stdin.readline().strip())
for i in range(q):
	s = int(stdin.readline().strip())
	print(bisect.bisect(m, s))


import math
import bisect

def mergeSort(lst):
	if len(lst) <= 1:
		return lst
	mid = math.floor(len(lst) / 2)
	left = mergeSort(lst[0:mid])
	right = mergeSort(lst[mid:])
	return merge(left, right)

def merge(arr1, arr2):
	i = 0
	j = 0
	lst = []
	while i < len(arr1) and j < len(arr2):
		if arr1[i] < arr2[j]:
			lst.append(arr1[i])
			i += 1
		else:
			lst.append(arr2[j])
			j += 1
	while i < len(arr1):
		lst.append(arr1[i])
		i += 1
	while j < len(arr2):
		lst.append(arr2[j])
		j += 1
	return lst
x = int(input())
lst = list(map(int, input().split()))
lst = mergeSort(lst)
y = int(input())
for i in range(0, y):
	money = int(input())
	count = bisect.bisect_right(lst, money, 0, len(lst))
	print(count)