package main

import (
	"fmt"

	"os"
	"io"
	"bufio"
	"bytes"

	"strings"
	"strconv"
	// "sort"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}
func NewConsole() Console {
	return Console{ bufio.NewWriter(os.Stdout) }
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

// sort 済み配列からとりあえず一致した要素のindexを返す
func LowerBound(list []int, key int, compare func(int, int) int) int {
	// fmt.Printf("key%d\n", key)
	// func
	// lhs > rhs -> positive
	// lhs < rhs -> negative
	return LowerBoundProc(list, 0, len(list) -1, key, compare)
}

func LowerBoundProc(list []int, begin int, end int, key int, compare func(int, int) int) int {
	cur := (end - begin) / 2 + begin
	// fmt.Printf("b:%d, c: %d, e:%d\n", begin, cur, end)
	// over the range 
	if len(list) - 1 < begin {
		return len(list)
	}
	if end < 0 {
		return 0
	}

	cmp := compare(key, list[cur])
	if cmp == 0 {
		if cur == 0 {
			return cur
		} 
		if list[cur-1] < list[cur] {
			return cur
		} else {
			return LowerBoundProc(list, begin, cur - 1, key, compare)
		}
	// to right
	} else if 0 < cmp {
		if cur+1 <= len(list) - 1 && compare(key, list[cur+1]) < 0 {
			return cur + 1
		}
		return LowerBoundProc(list, cur + 1, end, key, compare)
	// to left
	} else {
		// if 0 <= cur - 1 && 0 < compare(key, list[cur-1]) {
		// 	fmt.Println("l1")
		// 	return cur - 1
		// }
		return LowerBoundProc(list, begin, cur - 1, key, compare)
	}
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}


func main() {
	con := NewConsole()
	defer con.Flush()

	// create list
	var n int
	fmt.Scanf("%d", &n)

	list := make([]int, n)
	lines, _ := ReadLongLines(1)

	elements := strings.Split(lines[0], " ")
	for i := range elements{
		x, _ := strconv.Atoi(elements[i])
		list[i] = x
	}

	var q int
	fmt.Scanf("%d", &q)
	lines, _ = ReadLongLines(q)

	for i := range lines {
		x, _ := strconv.Atoi(lines[i])
		res := LowerBound(list, x, func(lhs, rhs int) int {
			if lhs == rhs {
				return 0
			} else if lhs > rhs {
				// fmt.Printf("%d %d +\n", lhs, rhs)
				return 1
			} else {
				// fmt.Printf("%d %d -\n", lhs, rhs)
				return -1
			}
		})
		con.Printf("%d\n", res)
	}
}


Measured memory_bytes: 10928