An arcade game player wants to climb to the top of the leaderboard and track their ranking. The game uses Dense Ranking, so its leaderboard works like this:  

The player with the highest score is ranked number $1$ on the leaderboard. 
Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number.

Example  

$ranked=[100,90,90,80]$ 

$player=[70,80,105]$  

The ranked players will have ranks $1$, $2$, $2$, and $3$, respectively.  If the player's scores are $70$, $\textbf{80}$ and $105$, their rankings after each game are $4^{th}$, $3^{rd}$ and $1^{st}$. Return $[4,3,1]$.

Function Description  

Complete the climbingLeaderboard function in the editor below.  

climbingLeaderboard has the following parameter(s):  

int ranked[n]: the leaderboard scores  
int player[m]: the player's scores  

Returns  

int[m]:  the player's rank after each new score

Input Format

The first line contains an integer $n$, the number of players on the leaderboard. 

The next line contains $n$ space-separated integers $\textit{ranked[i]}$, the leaderboard scores in decreasing order. 

The next line contains an integer, $m$, the number games the player plays. 

The last line contains $m$ space-separated integers $\textit{player}[j]$, the game scores.

Constraints

$1\leq n\leq2\times10^5$
$1\leq m\leq2\times10^5$
$0\leq\textit{ranked[i]}\leq10^9$ for $0\leq i<n$
$0\leq\textit{player}[j]\leq10^9$ for $0\leq j\lt m$
The existing leaderboard, $\textit{ranked}$, is in descending order.
The player's scores, $\textit{player}$, are in ascending order.

Subtask

For $\textbf{60\%}$ of the maximum score:

$1\leq n\leq200$
$1\leq m\leq200$

Sample Input 1

7
100 100 50 40 40 20 10
4
5 25 50 120

Sample Output 1

6
4
2
1

Explanation 1

Alice starts playing with $7$players already on the leaderboard, which looks like this:

After Alice finishes game $0$, her score is  $5$and her ranking is $6$:

After Alice finishes game $1$, her score is  $25$and her ranking is $4$:

After Alice finishes game $2$, her score is  $50$and her ranking is tied with Caroline at $2$:

After Alice finishes game $3$, her score is  $120$and her ranking is $1$:

Sample Input 2

6
100 90 90 80 75 60
5
50 65 77 90 102

Sample Output 2

6
5
4
2
1

Source: hackerrank | Difficulty: MEDIUM
Tags: Implementation


Solutions:
n = int(input().strip())
scores = list(reversed(sorted(list(set([int(scores_temp) for scores_temp in input().strip().split(' ')])))))
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
for x in alice:
	while len(scores) > 0 and scores[-1] <= x:
		del scores[-1]
	print(len(scores) + 1)


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = list(sorted(set(scores)))
aa = [bisect.bisect_right(scores, a) for a in alice]
for a in aa:
	v = len(scores) + 1 - a
	print(v)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = sorted(list(set(scores)))[::-1]
back = len(scores) - 1
for a in alice:
	while back >= 0 and a > scores[back]:
		back -= 1
	if scores[back] == a:
		print(back + 1)
	else:
		print(back + 2)


N = int(input())
scores = list(map(int, input().split(' ')))
M = int(input())
alice = list(map(int, input().split(' ')))
compressed_scores = []
for score in scores:
	if len(compressed_scores) == 0 or compressed_scores[-1] != score:
		compressed_scores.append(score)
i = len(compressed_scores) - 1
for cum_score in alice:
	while i >= 0 and cum_score > compressed_scores[i]:
		i -= 1
	if cum_score == compressed_scores[i]:
		print(i + 1)
	else:
		print(i + 2)


ns = int(input())
S = [int(x) for x in input().split()]
na = int(input())
A = [int(x) for x in input().split()]
rank = []
x = 0
last = 10000000000
for s in S:
	if last > s:
		x += 1
		last = s
	rank.append(x)

def currank(r, start):
	if r >= S[0]:
		return (1, 0)
	if r < S[-1]:
		return (rank[-1] + 1, len(S) - 1)
	i = start
	while True:
		if S[i] == r:
			return (rank[i], i)
		if S[i] > r:
			return (rank[i] + 1, i)
		i -= 1
i = len(S) - 1
for a in A:
	(r, i) = currank(a, i)
	print(r)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
rank = 0
ranks = []
lastscore = -1
for score in scores:
	if score != lastscore:
		rank += 1
	ranks.append(rank)
	lastscore = score
last = rank + 1
lastscoreindex = len(scores) - 1
for score in alice:
	rank = last
	for i in range(lastscoreindex, -1, -1):
		if score < scores[i]:
			break
		rank = ranks[i]
		lastscoreindex = i
	print(rank)


import sys
from bisect import bisect_left
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
s = set()
for i in scores:
	s.add(i)
scores = list(s)
scores.sort()
for item in alice:
	place = bisect_left(scores, item)
	if place < len(scores) and scores[place] == item:
		print(len(scores) - place)
	else:
		print(len(scores) - place + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
scores = list(set(scores))
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores.sort(reverse=True)
pos = len(scores) + 1
length = len(scores) - 1
for i in alice:
	for j in range(length, -1, -1):
		if i >= scores[j]:
			pos = j + 1
		else:
			break
	print(pos)
	if pos < length:
		length = pos


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ranks = [1 for x in range(n)]
rank = 1
for i in range(1, n):
	if scores[i] != scores[i - 1]:
		rank += 1
	ranks[i] = rank
j = n - 1
for i in alice:
	while j >= 0 and i > scores[j]:
		j -= 1
	if j == -1:
		print(1)
	elif scores[j] == i:
		print(ranks[j])
	else:
		print(ranks[j] + 1)


import bisect
(_, scores) = (input(), sorted(set(map(int, input().split()))))
n = len(scores)
input()
pos = 0
for alice in map(int, input().split()):
	pos = bisect.bisect(scores, alice, pos)
	print(n - pos + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
s = []
s.append(scores[0])
for i in range(1, n):
	if scores[i] != scores[i - 1]:
		s.append(scores[i])
length = len(s)
temp = length - 1
for i in alice:
	f = 0
	for j in range(temp, -1, -1):
		if i < s[j]:
			print(j + 2)
			f = 1
			temp = j
			break
		elif i == s[j]:
			print(j + 1)
			f = 1
			temp = j
			break
	if f == 0:
		print(1)


from bisect import bisect
n = int(input().strip())
scores = sorted(set(map(int, input().split())))
m = int(input().strip())
alice = map(int, input().split())
for k in alice:
	print(len(scores) - bisect(scores, k) + 1)


import sys

def process_scores(scores):
	densed_scores = []
	for i in range(len(scores)):
		if i == 0 or scores[i] != scores[i - 1]:
			densed_scores.append(scores[i])
	return densed_scores
n = input()
scores = [int(scores_temp) for scores_temp in sys.stdin.readline().strip().split(' ')]
m = input()
alice = [int(alice_temp) for alice_temp in sys.stdin.readline().strip().split(' ')]
densed_scores = process_scores(scores)
total_score = 0
current_rank = len(densed_scores) + 1
for alice_score in alice:
	total_score += alice_score
	while current_rank > 1 and densed_scores[current_rank - 2] <= alice_score:
		current_rank -= 1
	print(current_rank)


inf = float('inf')
read_ints = lambda : list(map(int, input().split()))

def ub(arr, k):
	l = 0
	r = len(arr) - 1
	while l < r:
		m = (l + r + 1) // 2
		if arr[m] > k:
			l = m
		else:
			r = m - 1
	return l

def solve(scores, alices):
	scores = [inf] + scores
	ranks = [0, 1]
	for i in range(2, len(scores)):
		if scores[i - 1] != scores[i]:
			ranks.append(ranks[-1] + 1)
		else:
			ranks.append(ranks[-1])
	for a in alices:
		u = ub(scores, a)
		print(ranks[u] + 1)
n = int(input())
scores = read_ints()
m = int(input())
alices = read_ints()
solve(scores, alices)


import sys
from collections import Counter
from bisect import bisect_left
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
counts = Counter(scores)
counts = sorted(counts)
n = len(counts)
for a in alice:
	i = bisect_left(counts, a)
	if i < n and counts[i] == a:
		print(n - i)
	else:
		print(n + 1 - i)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
(unique_scores, score_set) = (list(), set())
for score in scores:
	if score not in score_set:
		unique_scores.append(score)
		score_set.add(score)
score_rit = len(unique_scores) - 1
for a_j in alice:
	while score_rit >= 0 and unique_scores[score_rit] <= a_j:
		score_rit -= 1
	print(score_rit + 2)


n = int(input())
leader = list(map(int, input().split()))
m = int(input())
alicelvl = list(map(int, input().split()))
rank = [1]
count = 1
for each in range(1, n):
	if leader[each] == leader[each - 1]:
		rank.append(count)
	else:
		count += 1
		rank.append(count)
i = 0
j = n - 1
while i < m:
	while j >= 0:
		if j == 0 and leader[j] <= alicelvl[i]:
			print(1)
			break
		if leader[j] < alicelvl[i]:
			j -= 1
			continue
		elif leader[j] == alicelvl[i]:
			print(rank[j])
			break
		else:
			print(rank[j] + 1)
			break
		j -= 1
	i += 1


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = list(set(scores))
scores.sort()
slen = len(scores) + 1
for score in alice:
	print(slen - bisect.bisect(scores, score))


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
r = 1
rank = [1]
k = 1
while k < n:
	if scores[k] != scores[k - 1]:
		r = r + 1
	rank.append(r)
	k = k + 1
i = n - 1
j = 0
while j < m:
	if alice[j] > scores[0]:
		print(1)
	elif alice[j] < scores[i]:
		print(rank[i] + 1)
	elif alice[j] == scores[i]:
		print(rank[i])
	else:
		while alice[j] > scores[i]:
			i = i - 1
		if alice[j] == scores[i]:
			print(rank[i])
		else:
			print(rank[i] + 1)
	j = j + 1


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
for i in range(len(scores) - 1, -1, -1):
	if scores[i] == scores[i - 1]:
		del scores[i]
index = len(scores)
for k in range(len(alice)):
	score = alice[k]
	while len(scores) > 0 and score >= scores[-1]:
		scores.pop()
	print(len(scores) + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
L = list(set(scores))
L.sort()
ans = 0
for u in alice:
	while ans < len(L) and L[ans] <= u:
		ans += 1
	print(len(L) - ans + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = sorted(list(set(scores)), reverse=True)
n = len(scores)
j = n - 1
for i in range(m):
	while j >= 0:
		if alice[i] > scores[j]:
			if j == 0:
				print(1)
				break
			else:
				j -= 1
		elif alice[i] == scores[j]:
			print(j + 1)
			break
		else:
			print(j + 2)
			break


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = sorted(set(scores))
n = len(scores)
i = 0
for j in range(n):
	while alice[i] < scores[j]:
		print(n - j + 1)
		i += 1
		if i >= len(alice):
			break
while i < len(alice):
	print(1)
	i += 1


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
rmax = len(set(scores))
rdict = {}
rank = 1
for score in scores:
	if score not in rdict.keys():
		rdict[score] = rank
		rank += 1
cidx = n - 1
for al in alice:
	while scores[cidx] < al and cidx >= 0:
		cidx -= 1
	if cidx == -1:
		print(1)
	elif scores[cidx] == al:
		print(rdict[scores[cidx]])
	else:
		print(rdict[scores[cidx]] + 1)


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
ranks = [1]
for i in range(1, n):
	if scores[i - 1] == scores[i]:
		ranks.append(ranks[-1])
	else:
		ranks.append(ranks[-1] + 1)
ranks.append(ranks[-1] + 1)
scores.sort()
ranks = ranks[::-1]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
aliceResult = 0
aliceRank = ranks[0] + 1
for q in alice:
	i = bisect.bisect_right(scores, q)
	print(ranks[i])


import sys

def dedup(arr):
	seen = set()
	dedupped = []
	for x in arr:
		if not x in seen:
			dedupped.append(x)
			seen.add(x)
	return dedupped

def pos(her_score, scores):
	(left, right) = (0, len(scores))
	if her_score >= scores[0]:
		return 1
	if her_score < scores[-1]:
		return right + 1
	while left <= right:
		mid = (left + right) // 2
		if her_score < scores[mid] and her_score >= scores[mid + 1]:
			return mid + 2
		elif her_score >= scores[mid]:
			right = mid
		else:
			left = mid + 1
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = dedup(scores)
for i in alice:
	print(pos(i, scores))


import sys
n = int(input().strip())
scores_temp = input().strip().split(' ')
(scores, prev) = ([], '')
for sc in scores_temp:
	if sc != prev:
		scores.append(int(sc))
	prev = sc
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
(j, total) = (len(scores) - 1, 0)
for i in range(m):
	while alice[i] > scores[j] and j > 0:
		j -= 1
	if alice[i] < scores[j]:
		print(j + 2)
	else:
		print(j + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
rankList = [None] * len(alice)
current = len(alice) - 1
currentRank = 0
lastScore = None
for score in scores:
	if lastScore == None or lastScore > score:
		lastScore = score
		currentRank += 1
	while current > -1 and alice[current] >= lastScore:
		rankList[current] = currentRank
		current -= 1
	if current < 0:
		break
for i in range(len(rankList)):
	if rankList[i] != None:
		break
	rankList[i] = currentRank + 1
for rank in rankList:
	print(rank)


import sys

def get_ranks(scores):
	n = len(scores)
	rv = []
	rv.append(scores[0])
	for i in range(1, n):
		if scores[i] != scores[i - 1]:
			rv.append(scores[i])
	return rv

def get_place(curScore, scores):
	l = -1
	r = len(scores) - 1
	while r - l > 1:
		m = (l + r) // 2
		if curScore < scores[m]:
			l = m
		else:
			r = m
	if curScore >= scores[r]:
		return r
	else:
		return r + 1
n = int(input().strip())
input_scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = get_ranks(input_scores)
places = []
for curScore in alice:
	places.append(get_place(curScore, scores))
print('\n'.join(map(str, [item + 1 for item in places])))


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]

def get_positions(scores):
	positions = [1]
	for index in range(1, len(scores)):
		if scores[index] < scores[index - 1]:
			positions.append(positions[-1] + 1)
		elif scores[index] == scores[index - 1]:
			positions.append(positions[-1])
	return positions
pos = get_positions(scores)
sorted_scores = sorted(scores)
scores_len = len(scores)
for alice_score in alice:
	index = bisect.bisect(sorted_scores, alice_score)
	pos_index = scores_len - index
	try:
		rank = pos[pos_index]
	except IndexError:
		rank = pos[-1] + 1
	print(rank)


import sys
import heapq

def rank(scores):
	ranked_score = [scores[0]]
	for score in scores[1:]:
		if score != ranked_score[-1]:
			ranked_score.append(score)
	return ranked_score
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
ranked_score = rank(scores)
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
for a in alice:
	while len(ranked_score) > 0 and a >= ranked_score[-1]:
		ranked_score.pop()
	print(len(ranked_score) + 1)


n = int(input())
score = [int(x) for x in input().split()]
d = {}
rank = 1
prev = -1
for i in score:
	if rank not in d and prev != i:
		d[rank] = i
		rank += 1
		prev = i
m = int(input())
last = rank - 1
alice = 0
for i in [int(x) for x in input().split()]:
	alice = i
	if d[last] > alice:
		print(last + 1)
	elif d[last] == alice:
		print(last)
	else:
		f = 0
		while alice >= d[last]:
			if last == 1:
				f = 1
				break
			last -= 1
		if f:
			print(1)
			d[1] = alice
		else:
			last += 1
			d[last] = alice
			print(last)


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ranks = []
last_score = scores[0]
current_rank = 1
for i in range(n):
	if scores[i] < last_score:
		current_rank += 1
		last_score = scores[i]
	ranks.append(current_rank)
scores = list(reversed(scores))
ranks = list(reversed(ranks))
for x in alice:
	t = bisect.bisect_left(scores, x)
	if t == n:
		print(1)
		continue
	if x == scores[t]:
		print(ranks[t])
	else:
		print(ranks[t] + 1)


import sys
import bisect
n = int(input().strip())
scores = [-int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [-int(alice_temp) for alice_temp in input().strip().split(' ')]
myset = set(scores)
myscores = sorted(list(myset))
for mark in alice:
	i = bisect.bisect_left(myscores, mark, 0, len(myscores))
	print(i + 1)


a = int(input())
b = input().split()
c = int(input())
d = input().split()
e = list(set(b))
h = len(e)
for i in range(h):
	e[i] = int(e[i])
p = h + 1
c = h - 1
e.sort(reverse=True)
for i in d:
	while p != 1 and int(i) >= e[c]:
		c = c - 1
		p = p - 1
	print(p)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
current_ranks = [1]
i = 1
k = len(alice) - 1
alice_ranks = []
while k >= 0:
	if alice[k] >= scores[0]:
		alice_ranks.append(1)
		k = k - 1
	else:
		break
j = 1
while j < len(scores):
	if scores[j] == scores[j - 1]:
		current_ranks.append(i)
	else:
		i = i + 1
		current_ranks.append(i)
	if k >= 0:
		while alice[k] in range(scores[j], scores[j - 1]):
			alice_ranks.append(i)
			k = k - 1
	j = j + 1
if len(alice_ranks) < len(alice):
	diff = len(alice) - len(alice_ranks)
	j = [current_ranks[n - 1] + 1 for i in range(diff)]
	alice_ranks.extend(j)
alice_ranks.reverse()
for u in alice_ranks:
	print(u)


n = int(input())
l = [int(x) for x in input().split()]
j = int(input())
alice = [int(x) for x in input().split()]
l = list(set(l))
l.sort()
ptr = 0
ln = len(l)
asc = 0
for i in alice:
	asc = i
	if ptr == ln:
		print('1')
		continue
	if l[ptr] > asc:
		print(ln - ptr + 1)
	elif l[ptr] == asc:
		print(ln - ptr)
	else:
		while l[ptr] < asc:
			ptr += 1
			if ptr == ln:
				break
		if ptr == ln:
			print('1')
		elif l[ptr] > asc:
			print(ln - ptr + 1)
		elif l[ptr] == asc:
			print(ln - ptr)


n = int(input())
a = sorted(set([int(x) for x in input().split()]), reverse=True)
m = int(input())
b = [int(x) for x in input().split()]
max_position = len(a) - 1
for i in range(len(b)):
	item = b[i]
	while max_position >= 0 and item >= a[max_position]:
		max_position -= 1
	print(max_position + 2)


import sys

def bin_search(l, k, left=0, right=-1):
	if right == -1:
		right = len(l)
	if left == right:
		return left + 1
	mid = (left + right) // 2
	value = l[mid]
	if value == k:
		return mid + 1
	if value < k:
		return bin_search(l, k, left, mid)
	if value > k:
		return bin_search(l, k, mid + 1, right)
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = list(set(scores))
scores.sort(reverse=True)
for x in alice:
	print(bin_search(scores, x))


import sys
n = int(input().strip())
scores = {int(scores_temp) for scores_temp in input().strip().split(' ')}
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
n = 0
ranks = []
for (i, s) in enumerate(reversed(sorted(scores))):
	n += 1
	if s <= alice[m - 1]:
		iter_m = m
		for j in range(iter_m - 1, -1, -1):
			if s <= alice[j]:
				ranks.append(i + 1)
				m -= 1
			else:
				break
	if m < 0:
		break
if m >= 0:
	for i in range(m):
		ranks.append(n + 1)
for r in reversed(ranks):
	print(r)


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = sorted(set(scores))
l = len(scores)
for alice_score in alice:
	a = bisect.bisect_left(scores, alice_score)
	if a < l and scores[a] == alice_score:
		a += 1
	print(l + 1 - a)


import sys

def binarySearch(alist, item):
	first = 0
	last = len(alist) - 1
	found = False
	while first <= last and (not found):
		midpoint = (first + last) // 2
		if alist[midpoint] == item:
			return midpoint
		elif item < alist[midpoint]:
			first = midpoint + 1
		else:
			last = midpoint - 1
	if first > last:
		return first
	elif last > first:
		return last
	return midpoint
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
tmp = list(set(scores))
tmp.sort(reverse=True)
N = len(tmp)
for k in range(m):
	entry = alice[k]
	print(binarySearch(tmp, entry) + 1)


import sys
from time import sleep
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
rank = 1
ranks = [1]
last_score = scores[0]
for s in scores[1:]:
	if s != last_score:
		rank += 1
	ranks.append(rank)
	last_score = s

def binary_search(lst, target, start=None, end=None):
	if start is None:
		start = 0
	if end is None:
		end = len(target)
	if end == start + 1:
		pass
	i = (start + end) // 2

def find_rank(score, start=0, end=len(ranks)):
	if end <= start + 1:
		if score >= scores[start]:
			return ranks[start]
		else:
			return ranks[start] + 1
	i = (start + end) // 2
	if score > scores[i]:
		return find_rank(score, start=start, end=i)
	if score <= scores[i]:
		return find_rank(score, start=i, end=end)
for a in alice:
	print(find_rank(a))


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
(ranks, cur_rank) = ({}, 1)
for score in scores:
	if score not in ranks:
		ranks[score] = cur_rank
		cur_rank += 1
last_rank = cur_rank
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
i = n - 1
for score in alice:
	if score in ranks:
		print(ranks[score])
	else:
		while 1:
			if i == -1:
				print(1)
				break
			if scores[i] > score:
				if i == 0:
					print(2)
					break
				if i == n - 1:
					print(last_rank)
				else:
					print(ranks[scores[i + 1]])
				break
			i -= 1


import sys
from bisect import bisect_left
n = int(input().strip())
scores = sorted(list(set([int(scores_temp) for scores_temp in input().strip().split(' ')])))
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
for a in alice:
	ind = bisect_left(scores, a)
	print(len(scores) - ind + (0 if ind < len(scores) and scores[ind] == a else 1))


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores.append(0)
ranks = [0] * (n + 1)
ranks[0] = 1
for i in range(1, n + 1):
	if scores[i] == scores[i - 1]:
		ranks[i] = ranks[i - 1]
	else:
		ranks[i] = ranks[i - 1] + 1
cur_score_index = n
alice_score = 0
for alice_score in alice:
	while cur_score_index > 0 and alice_score >= scores[cur_score_index - 1]:
		cur_score_index -= 1
	print(ranks[cur_score_index])


import sys
n = int(input().strip())
scores = sorted(list(set([int(scores_temp) for scores_temp in input().strip().split(' ')])), reverse=True)
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
alice2 = sorted(list(set(alice)), reverse=True)
d = {}
count = 0
temp = alice2[count]
for x in range(len(scores)):
	while scores[x] <= temp and count < len(alice2) - 1:
		d[temp] = x + 1
		count += 1
		temp = alice2[count]
	if count == len(alice2) - 1:
		if alice2[count] >= scores[x]:
			d[alice2[count]] = x + 1
			break
for x in alice:
	if x in d:
		print(d[x])
	else:
		print(len(scores) + 1)


import bisect
n = int(input())
L = map(int, input().split())
L = sorted(list(set(list(L))))
n = len(L)
m = int(input())
for a in list(map(int, input().split())):
	print(1 + n - bisect.bisect_right(L, a))


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
score_set = set(scores)
scores = list(score_set)
scores.sort(reverse=True)
a_ptr = len(scores) - 1
for a in alice:
	if a > scores[0]:
		print(1)
	else:
		while a_ptr > 0 and a > scores[a_ptr]:
			a_ptr -= 1
		print(a_ptr + (2 if a != scores[a_ptr] else 1))


import sys
from bisect import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = list(sorted(set(scores)))
n = len(scores)
for i in range(m):
	print(n - bisect(scores, alice[i]) + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = sorted(set(scores))
import bisect
for score in alice:
	print(len(scores) - bisect.bisect(scores, score) + 1)


import sys
n = int(input().strip())
scores = {int(scores_temp): 0 for scores_temp in input().strip().split(' ')}
scores = {i: k for (i, k) in enumerate(sorted(scores.keys(), reverse=True), 1)}
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
r = len(scores) + 1
for al in alice:
	for i in range(r - 1, 0, -1):
		if scores[i] <= al:
			r = i
		else:
			break
	print(r)


N = int(input().strip())
S = [int(scores_temp) for scores_temp in input().strip().split(' ')]
S = set(S)
S = list(S)
S.sort()
S.reverse()
N = len(S)
(mn, mx) = (min(S), max(S))
M = int(input().strip())
A = [int(alice_temp) for alice_temp in input().strip().split(' ')]
mini = N - 1
j = 0
while j < M:
	if A[j] >= mx:
		for k in range(j, M):
			print(1)
		break
	if A[j] < mn:
		print(mini + 2)
		j += 1
	elif A[j] == mn:
		print(mini + 1)
		j += 1
	else:
		mini -= 1
		mn = S[mini]


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
rankings = []
rank = 0
curscore = 10 ** 9 + 1
for score in scores:
	if score < curscore:
		curscore = score
		rank += 1
	rankings.append(rank)
position = n - 1
for score in alice:
	while score > scores[position] and position != 0:
		position -= 1
	if score > scores[position]:
		print(1)
	elif score == scores[position]:
		print(rankings[position])
	else:
		print(rankings[position] + 1)


import sys
numPlayers = int(input().strip())
playerScores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
numLevels = int(input().strip())
aliceScores = [int(alice_temp) for alice_temp in input().strip().split(' ')]

def solveProblem(numPlayers, playerScores, numLevels, aliceScores):
	playerRanks = [1]
	for i in range(1, numPlayers):
		if playerScores[i] == playerScores[i - 1]:
			playerRanks.append(playerRanks[i - 1])
		else:
			playerRanks.append(playerRanks[i - 1] + 1)
	curPlayerIndex = numPlayers - 1
	for i in range(numLevels):
		while curPlayerIndex > 0 and aliceScores[i] > playerScores[curPlayerIndex]:
			curPlayerIndex -= 1
		if aliceScores[i] >= playerScores[curPlayerIndex]:
			print(playerRanks[curPlayerIndex])
		else:
			print(playerRanks[curPlayerIndex] + 1)
solveProblem(numPlayers, playerScores, numLevels, aliceScores)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
if n > 0:
	ranks = [1]
	for i in range(1, n):
		if scores[i] < scores[i - 1]:
			ranks.append(ranks[i - 1] + 1)
		else:
			ranks.append(ranks[i - 1])
	aliceIndex = 0
	scoresIndex = n - 1
	while aliceIndex < m:
		while scoresIndex > -1 and scores[scoresIndex] <= alice[aliceIndex]:
			scoresIndex -= 1
		if scoresIndex == -1:
			print('1')
		else:
			print(ranks[scoresIndex] + 1)
		aliceIndex += 1
else:
	for i in range(m):
		print('1')


n = int(input())
scores = [int(_) for _ in input().split()]
m = int(input())
alice = [int(_) for _ in input().split()]
currank = 1
ranks = []
pr_sc = scores[0]
for sc in scores:
	if sc < pr_sc:
		currank += 1
	ranks.append(currank)
	pr_sc = sc
a_j = len(scores)
for a_sc in alice:
	while a_j > 0 and a_sc >= scores[a_j - 1]:
		a_j -= 1
	if a_j == 0:
		print(1)
	else:
		print(ranks[a_j - 1] + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
max_rank = len(set(scores))
cur_rank = max_rank + 1
cur_rank_score = scores[-1]
index = len(scores) - 1
for a in alice:
	if a >= scores[0]:
		print(1)
	else:
		while index >= 0:
			if a < cur_rank_score:
				break
			elif scores[index] > cur_rank_score:
				cur_rank -= 1
				cur_rank_score = scores[index]
			index -= 1
		if a > cur_rank_score:
			cur_rank = 1
		print(cur_rank)


def calculate_rank(scores, new_score, last_rank):
	l = len(scores)
	for i in range(last_rank - 2, -1, -1):
		if new_score < scores[i]:
			return i + 2
		elif new_score == scores[i]:
			return i + 1
	return 1
n = int(input())
raw_scores = [int(score) for score in input().split()]
scores = [raw_scores[0]]
for score in raw_scores[1:]:
	if score != scores[-1]:
		scores.append(score)
m = int(input())
alice_scores = [int(score) for score in input().split()]
current_rank = len(scores) + 1
for current_score in alice_scores:
	current_rank = calculate_rank(scores, current_score, current_rank)
	print(current_rank)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')] + [0]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
level = 1
scr_i = 0
a_ranks = []
while alice:
	a_score = alice.pop()
	while scr_i < len(scores) and a_score < scores[scr_i]:
		scr_i += 1
		if scores[scr_i - 1] != scores[scr_i]:
			level += 1
	a_ranks.append(level)
for rank in a_ranks[::-1]:
	print(rank)


import sys
n = int(input().strip())
s = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
a = [int(alice_temp) for alice_temp in input().strip().split(' ')]
s = sorted(list(set(s)), reverse=True)
ss = len(s) - 1
aa = 0
while ss >= 0 and aa < m:
	if a[aa] < s[ss]:
		print(ss + 2)
		aa += 1
	elif a[aa] == s[ss]:
		print(ss + 1)
		aa += 1
	else:
		ss -= 1
while aa < m:
	print(1)
	aa += 1


import sys
from bisect import bisect_right

def find_le(a, x):
	i = bisect_right(a, x)
	if i:
		return i - 1
	return -1
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = sorted(set(scores))
for score in alice:
	print(len(scores) - find_le(scores, score))


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
tmp = {}
rscores = sorted(list(set(scores)), reverse=True)
j = len(rscores)
for i in range(m):
	while j > 0 and alice[i] >= rscores[j - 1]:
		j -= 1
	print(j + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = 1
ranking = [m]
for i in range(1, n):
	if scores[i] != scores[i - 1]:
		m += 1
	ranking.append(m)
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
high1 = scores[0]
low1 = scores[-1]
mid1 = scores[n // 2]
for t in range(m):
	x = alice[t]
	if x < low1:
		print(ranking[-1] + 1)
	elif x == low1:
		print(ranking[-1])
	elif x >= high1:
		print(1)
	elif x == mid1:
		print(ranking[n // 2])
	else:
		low = 0
		high = n - 1
		while True:
			j = (high + low) // 2
			if scores[j] == x:
				print(ranking[j])
				break
			if scores[j] < x:
				if scores[j] < x <= scores[j - 1]:
					if scores[j - 1] == x:
						print(ranking[j - 1])
						break
					print(ranking[j])
					break
				else:
					high = j
			elif scores[j] > x >= scores[j + 1]:
				if scores[j + 1] == x:
					print(ranking[j + 1])
					break
				print(ranking[j + 1])
				break
			else:
				low = j


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ss = list(set(scores))
ss.sort()
last = len(ss) + 1
pos = 0
for i in alice:
	if i >= ss[last - 2]:
		print(1)
	else:
		while i >= ss[pos]:
			pos += 1
		print(last - pos)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
singles = [scores[0]]
prev = scores[0]
for score in scores[1:]:
	if score < prev:
		singles.append(score)
		prev = score
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
rank = len(singles) - 1
curr = 0
for score in alice:
	while rank >= 0 and singles[rank] <= score:
		rank -= 1
	print(rank + 2)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ranks = [1] * n
for i in range(1, n):
	if scores[i] < scores[i - 1]:
		ranks[i] = ranks[i - 1] + 1
	else:
		ranks[i] = ranks[i - 1]

def get_rank(value, scores, end, ranks):
	if not scores:
		return (1, -1)
	if scores[end] > value:
		return (ranks[end] + 1, end)
	left = 0
	right = end
	while left < right:
		mid = (left + right) // 2
		score = scores[mid]
		if score <= value:
			right = mid
		else:
			left = mid + 1
	return (ranks[right], right)
end = n - 1
for i in range(m):
	(rank, end) = get_rank(alice[i], scores, end, ranks)
	print(rank)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
position = 1
previous = 0
current = alice[0]
answ = []
for score in scores:
	if current >= score:
		break
	else:
		if score == previous:
			continue
		answ.append([position, score])
		position += 1
		previous = score
print(position)
j = len(answ) - 1
previous = -1
position = -1
if len(answ) == 0:
	answ.append([0, 0])
for curr in alice[1:]:
	if curr == previous:
		print(position)
		continue
	if curr > answ[0][1]:
		print(1)
		continue
	for vro in range(j, -1, -1):
		if curr > answ[vro][1]:
			j -= 1
			continue
		if curr < answ[vro][1]:
			print(answ[vro][0] + 1)
			previous = curr
			position = answ[vro][0] + 1
			break
		if curr == answ[vro][1]:
			print(answ[vro][0])
			j -= 1
			previous = answ[vro][1]
			position = answ[vro][0]
			break


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ranks = [1]
for i in range(1, n):
	if scores[i] < scores[i - 1]:
		ranks.append(ranks[i - 1] + 1)
	else:
		ranks.append(ranks[i - 1])
scores.reverse()
ranks.reverse()
s = 0
cur_rank = ranks[0] + 1
for a in alice:
	if s >= n:
		print(1)
		continue
	while a >= scores[s]:
		cur_rank = ranks[s]
		s += 1
		if s >= n:
			break
	print(cur_rank)


import sys, collections
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
res = []
i = len(scores) - 1
r = len(set(scores)) + 1
for s in alice:
	if scores[i] > s:
		res.append(r)
	else:
		while i >= 0 and scores[i] <= s:
			if i == len(scores) - 1 or scores[i] != scores[i + 1]:
				r -= 1
			i -= 1
		res.append(r)
for rank in res:
	print(rank)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ranks = [1]
current_rank = 1
for i in range(1, n):
	if scores[i - 1] == scores[i]:
		ranks.append(current_rank)
	else:
		current_rank += 1
		ranks.append(current_rank)
pos = n - 1
for a in alice:
	while pos >= 0 and a >= scores[pos]:
		pos -= 1
	if pos == -1:
		print(1)
	else:
		print(ranks[pos] + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
s = sorted(list(set(scores)), reverse=True)
for j in alice:
	try:
		while j >= s[-1]:
			s.pop()
		else:
			print(len(s) + 1)
	except IndexError:
		print(1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
mod_scores = list(set(scores))
mod_scores.sort(reverse=True)
pos = len(mod_scores) + 1
for i in range(0, m):
	flag = True
	if pos > 1:
		for j in range(pos - 2, -1, -1):
			if alice[i] < mod_scores[j]:
				pos = j + 2
				flag = False
				print(pos)
				break
	if flag:
		print(1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ladder = sorted(set(scores), reverse=True)
i = len(ladder) - 1
for a in alice:
	while i >= 0 and ladder[i] <= a:
		i -= 1
	print(i + 2)


import sys
import itertools
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scoreSet = []
for (k, g) in itertools.groupby(scores):
	scoreSet.append(k)
last = len(scoreSet) - 1
for i in alice:
	for j in range(last, -1, -1):
		if scoreSet[j] > i:
			print(j + 2)
			last = j
			break
	else:
		print(1)
		last = 0


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = list(set(scores))
scores.sort()
rank = len(scores) + 1
pos = 0
for x in alice:
	while pos != len(scores) and x >= scores[pos]:
		rank -= 1
		pos += 1
	print(rank)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores2 = [scores[0]]
for x in scores:
	if x < scores2[-1]:
		scores2.append(x)
scores = scores2
cur = len(scores) - 1
for x in alice:
	while cur >= 0 and x >= scores[cur]:
		cur -= 1
	if cur < 0:
		print('1')
		continue
	print(str(cur + 2))


import sys
from bisect import bisect_left
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
prev_score = -1
prev_rank = 0
ranks = []
for score in scores:
	if score == prev_score:
		ranks.append(prev_rank)
	else:
		prev_score = score
		prev_rank += 1
		ranks.append(prev_rank)
scores.reverse()
ranks.reverse()
for alice_score in alice:
	index = bisect_left(scores, alice_score)
	if index >= n:
		print(1)
	elif alice_score < scores[index]:
		print(ranks[index] + 1)
	else:
		print(ranks[index])


import sys

def getRanking(scores):
	unique = set(scores)
	s = sorted(unique, reverse=True)
	return [(i + 1, s[i]) for i in range(len(s))]
n = int(input().strip())
scores = map(int, input().strip().split(' '))
m = int(input().strip())
ranks = getRanking(scores)
alice = map(int, input().strip().split(' '))
index = len(ranks) - 1
for k in alice:
	while index >= 0 and ranks[index][1] < k:
		index -= 1
	if index == -1:
		print(1)
	elif k == ranks[index][1]:
		print(ranks[index][0])
	else:
		print(ranks[index][0] + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
total_rank = 2
prev = scores[0]
for s in scores:
	if s != prev:
		total_rank += 1
	prev = s
i = len(scores) - 1
back_rank = 0
for s in alice:
	while s > scores[i]:
		if i == 0:
			print(1)
			break
		if scores[i] != scores[i - 1]:
			back_rank += 1
		i = i - 1
	if s == scores[i] or (i != 0 and s == scores[i]):
		print(total_rank - back_rank - 1)
	elif s <= scores[i] or i != 0:
		print(total_rank - back_rank)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
s = []
s.append(scores[0])
for i in scores:
	if i != s[len(s) - 1]:
		s.append(i)
s.reverse()
rank = len(s)
for i in range(len(alice)):
	while rank > 1:
		if alice[i] >= s[len(s) - rank]:
			rank -= 1
		else:
			print(rank + 1)
			break
	if rank == 1:
		if alice[i] >= s[-1]:
			print(1)
		else:
			print(2)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
positions = sorted(set(scores))[::-1]
length = len(positions)
position = length + 1
threshold = positions[position - 2]
for alice_score in alice:
	printed = False
	while not printed:
		if alice_score < threshold or position == 1:
			print(position)
			printed = True
		else:
			position -= 1
			threshold = positions[position - 2]


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
a = []
k = 1
for i in range(n):
	if i != 0 and scores[i] != scores[i - 1]:
		k += 1
	a.append([scores[i], k])
p = n - 1
for i in alice:
	flag = 1
	for j in range(p, -1, -1):
		if i < a[j][0]:
			print(a[j][1] + 1)
			p = j
			flag = 0
			break
		if i == a[j][0]:
			print(a[j][1])
			p = j
			flag = 0
			break
	if flag == 1:
		print(1)


import sys
from bisect import bisect
n = int(input().strip())
scores = sorted(set([int(scores_temp) for scores_temp in input().strip().split(' ')]))
n = len(scores)
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
for v in alice:
	i = bisect(scores, v)
	print(n - i + 1)


n = int(input().strip())
score = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
dense = score[:1]
for s in score:
	if s < dense[-1]:
		dense.append(s)
score = [-s for s in dense]
from bisect import bisect_left
for a in alice:
	print(1 + bisect_left(score, -a))


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
currRank = 1
currScore = scores[0]
ranks = []
for score in scores:
	if score < currScore:
		currRank += 1
		currScore = score
	ranks.append(currRank)
i = len(scores) - 1
for als in alice:
	while scores[i] < als and i > 0:
		i -= 1
	if scores[i] <= als:
		print(ranks[i])
	elif i == len(scores) - 1:
		print(ranks[i] + 1)
	else:
		print(ranks[i + 1])


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]

def unique(scores):
	seen = set()
	uniq = []
	for score in scores:
		if score not in seen:
			uniq.append(score)
			seen.add(score)
	return uniq
uniquescore = unique(scores)

def bisect_right(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]:
			lo = mid + 1
		else:
			hi = mid
	return lo + 1

def rankAlice(uniquescore, alice):
	result = []
	for mark in alice:
		result.append(bisect_right(uniquescore, mark))
	return result
ranks = rankAlice(uniquescore, alice)
for rank in ranks:
	print(rank)


import sys

def bin_search(arr, num, s, e):
	if s == e or e == 0:
		return e
	mid = (s + e) // 2
	if arr[mid] == num:
		return mid
	if arr[mid] < num:
		if mid != 0 and arr[mid - 1] > num:
			return mid
		return bin_search(arr, num, s, mid)
	else:
		if mid != len(arr) - 1 and arr[mid + 1] < num:
			return mid + 1
		return bin_search(arr, num, mid + 1, e)
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
temp = []
temp.append(scores[0])
for i in range(1, len(scores)):
	if scores[i] != temp[-1]:
		temp.append(scores[i])
scores = temp
for i in range(m):
	print(bin_search(scores, alice[i], 0, len(scores)) + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ranks = [None] * len(scores)
for i in range(0, len(scores)):
	if i == 0:
		ranks[i] = 1
	elif scores[i - 1] == scores[i]:
		ranks[i] = ranks[i - 1]
	else:
		ranks[i] = ranks[i - 1] + 1

def find_place(total, start, end):
	if start == end:
		if total == scores[start]:
			return start
		else:
			return start + 1
	mid = start + (end - start) // 2
	if mid == 0:
		if total >= scores[0]:
			return 0
		else:
			return 1
	if total == scores[mid]:
		return mid
	if scores[mid] < total and scores[mid - 1] > total:
		return mid
	if scores[mid] > total and scores[mid + 1] < total:
		return mid + 1
	if scores[mid] > total:
		return find_place(total, mid + 1, end)
	else:
		return find_place(total, start, mid - 1)
for score in alice:
	place = find_place(score, 0, len(scores) - 1)
	if place > len(ranks) - 1:
		print(ranks[-1] + 1)
	else:
		print(ranks[place])


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ws = [scores[0]]
for i in range(1, n):
	if scores[i] != scores[i - 1]:
		ws.append(scores[i])
n = len(ws)
j = n - 1
for i in range(len(alice)):
	while j >= 0 and ws[j] <= alice[i]:
		j -= 1
	print(j + 2)


import sys
n = 0
scores = []

def _find(v, f, to):
	if f == to:
		return f
	mid = (f + to) // 2
	if v == scores[mid]:
		return mid
	elif v > scores[mid]:
		return _find(v, f, mid)
	else:
		return _find(v, mid + 1, to)
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
first = scores[0]
last = scores[-1]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
place = []
p = 0
v = -1
for i in range(n):
	if scores[i] != v:
		p = p + 1
		v = scores[i]
	place.append(p)
for i in range(m):
	v = alice[i]
	if v > first:
		print('1')
	elif v < last:
		print('{}'.format(place[n - 1] + 1))
	else:
		print('{}'.format(place[_find(v, 0, n - 1)]))


import sys
n = int(input())
scores = list(map(int, input().split()))
m = int(input())
alice = list(map(int, input().split()))

def bin_search(arr, pred, lo=0, hi=None):
	if hi is None:
		hi = len(arr)
	while lo < hi:
		mid = (lo + hi) // 2
		if pred(arr[mid]):
			hi = mid
		else:
			lo = mid + 1
	return lo

def get_ranks(scores):
	r = 1
	ranks = [1]
	for i in range(1, len(scores)):
		if scores[i] != scores[i - 1]:
			r += 1
		ranks.append(r)
	return ranks

def main():
	ranks = get_ranks(scores)
	idx = len(scores)
	for a in alice:
		idx = bin_search(scores, lambda x: x <= a, 0, idx)
		if idx == len(scores):
			print(ranks[-1] + 1)
		else:
			print(ranks[idx])
main()


import bisect
import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
last_val = None
rank = 0
ranks = [None] * len(scores)
for (ii, score) in enumerate(scores):
	if score != last_val:
		last_val = score
		rank += 1
	ranks[ii] = rank
scores = list(reversed(scores))
ranks = list(reversed(ranks))
ii = None
for aa in alice:
	ii = bisect.bisect(scores, aa)
	if ii >= len(scores):
		print('%d' % 1)
	else:
		print('%d' % (ranks[ii] + 1))


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
uniq = []
uniq.append(scores[0])
for i in range(1, n):
	if scores[i - 1] != scores[i]:
		uniq.append(scores[i])
uniq = list(reversed(uniq))
for ch in alice:
	index = bisect.bisect_left(uniq, ch)
	if index < len(uniq) and uniq[index] == ch:
		print(len(uniq) - index)
	else:
		if index >= len(uniq):
			uniq.append(ch)
		else:
			uniq.insert(index, ch)
		print(len(uniq) - index)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
new_scores = [scores[0]]
for score in scores:
	if score != new_scores[-1]:
		new_scores.append(score)
index = len(new_scores)
for score in alice:
	while index != 0 and score >= new_scores[index - 1]:
		index -= 1
	print(index + 1)


import sys
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
ranks = [1]
for i in range(0, len(scores) - 1):
	if scores[i] == scores[i + 1]:
		ranks.append(ranks[-1])
	else:
		ranks.append(ranks[-1] + 1)
acc = len(ranks) - 1
for a in alice:
	while a > scores[acc] and acc > 0:
		acc -= 1
	if a < scores[acc]:
		print(ranks[acc] + 1)
	elif a == scores[acc]:
		print(ranks[acc])
	else:
		print('1')


import sys
from collections import OrderedDict
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scores = list(OrderedDict.fromkeys(scores))
si = len(scores) - 1
for a in alice:
	while si >= 0 and a >= scores[si]:
		si -= 1
	print(si + 2)


import sys
import bisect
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
scoreSet = sorted(set(scores))
size = len(scoreSet)
for i in range(m):
	index = bisect.bisect_left(scoreSet, alice[i])
	if index != size and alice[i] == scoreSet[index]:
		print(size - index)
	else:
		print(size + 1 - index)


input()
scores = [1000000001]
for score in (int(scores_temp) for scores_temp in input().split()):
	if score != scores[-1]:
		scores.append(score)
input()
current = len(scores)
scores_itr = reversed(scores)
better_score = next(scores_itr)
for alice in (int(alice_temp) for alice_temp in input().split()):
	while alice >= better_score:
		current -= 1
		better_score = next(scores_itr)
	print(current)


import sys

def find(x, lst, a, b):
	if b - a == 0:
		return b
	pivot = (b + a) // 2
	if x == lst[pivot]:
		return pivot
	elif x > lst[pivot]:
		return find(x, lst, a, pivot)
	else:
		return find(x, lst, pivot + 1, b)
n = int(input().strip())
scores = [int(scores_temp) for scores_temp in input().strip().split(' ')]
m = int(input().strip())
alice = [int(alice_temp) for alice_temp in input().strip().split(' ')]
last = -1
l = list()
for s in scores:
	if s != last:
		l.append(s)
	last = s
last = len(l)
for x in alice:
	last = find(x, l, 0, last)
	print(last + 1)