package main

import (
	"bufio"
	"fmt"
	"os"
)

func Abs(a int32) int32 {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)

	var tt int32
	fmt.Fscan(reader, &tt)

TT:
	for ; tt > 0; tt-- {
		var l, r, x, a, b int32
		fmt.Fscan(reader, &l, &r, &x, &a, &b)
		var limits [2]int32 = [2]int32{l, r}

		if a == b {
			// a equals b : 0
			fmt.Fprintf(writer, "0\n")
			continue TT

		} else if Abs(a-b) >= x {
			// |a - b| >= x : 1
			fmt.Fprintf(writer, "1\n")
			continue TT

		} else {

			// a limit h such that |a - h| >= x and |b - h| >= x : 2
			for h := 0; h < 2; h++ {
				if Abs(limits[h]-a) >= x && Abs(limits[h]-b) >= x {
					fmt.Fprintf(writer, "2\n")
					continue TT
				}
			}

			// 2 limits h, k such that |a - h| >= x and |b - k| >= x : 3
			for h := 0; h < 2; h++ {
				if Abs(limits[h]-b) >= x && Abs(limits[(h+1)%2]-a) >= x {
					fmt.Fprintf(writer, "3\n")
					continue TT
				}
			}

			fmt.Fprintf(writer, "-1\n")
		}
	}

	writer.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func solve(l, r, x, a, b int) int {
	if a == b {
		return 0
	}
	if b-a >= x {
		return 1
	}
	if a-b >= x {
		return 1
	}

	if r-a >= x && r-b >= x {
		return 2
	}
	if a-l >= x && b-l >= x {
		return 2
	}

	if r-a >= x && r-l >= x && b-l >= x {
		return 3
	}
	if a-l >= x && r-l >= x && r-b >= x {
		return 3
	}

	return -1
}

func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var test int
	fmt.Fscanln(inp, &test)
	for test > 0 {
		test--
		var l, r, x, a, b int
		fmt.Fscanln(inp, &l, &r, &x)
		fmt.Fscanln(inp, &a, &b)
		fmt.Fprintln(out, solve(l, r, x, a, b))
	}

	out.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	l, r, x := readThreeInt(reader)
	a, b := readTwoInt(reader)

	if a == b {
		fmt.Fprintln(writer, 0)
		return
	}

	if abs(l-b) < x && abs(r-b) < x || abs(a-l) < x && abs(a-r) < x {
		fmt.Fprintln(writer, -1)
		return
	}

	if abs(a-b) >= x {
		fmt.Fprintln(writer, 1)
		return
	}

	if abs(a-l) >= x && abs(l-b) >= x || abs(a-r) >= x && abs(r-b) >= x {
		fmt.Fprintln(writer, 2)
		return
	}

	fmt.Fprintln(writer, 3)
}

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		solve(reader, writer)
		t--
	}

	writer.Flush()
}

func min[T int | int64](a, b T) T {
	if a < b {
		return a
	}

	return b
}

func max[T int | int64](a, b T) T {
	if a > b {
		return a
	}

	return b
}

func abs[T int | int64](a T) T {
	if a < 0 {
		return a * -1
	} else {
		return a
	}
}

func gcd[T int | int64](x, y T) T {
	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func lcm[T int | int64](x, y T) T {
	return x * y / gcd(x, y)
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func abs(a int) int {
	if a < 0 { return -a }
	return a
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var L, R, X, A, B int
		fmt.Fscan(r, &L, &R, &X, &A, &B)

		res := 3
		if A == B {
			res = 0
		} else if abs(L-A) < X && abs(R-A) < X {
			res = -1
		} else if abs(L-B) < X && abs(R-B) < X {
			res = -1
		} else if abs(A-B) >= X {
			res = 1
		} else if B > A && B+X <= R {
			res = 2
		} else if B > A && A-X >= L {
			res = 2
		} else if B < A && B-X >= L {
			res = 2
		} else if B < A && A+X <= R {
			res = 2
		}

		fmt.Fprintln(w, res)
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var l, r, x, a, b int
		fmt.Fscan(in, &l, &r, &x)
		fmt.Fscan(in, &a, &b)
		if a == b {
			fmt.Fprintln(out, "0")
			continue
		}
		if a > b {
			a, b = b, a
		}
		if b-a >= x {
			fmt.Fprintln(out, "1")
			continue
		}
		if (a-l >= x && b-l >= x) || (r-a >= x && r-b >= x) {
			fmt.Fprintln(out, "2")
			continue
		}
		if (r-a >= x && b-l >= x) || (a-l >= x && r-b >= x) {
			fmt.Fprintln(out, "3")
			continue
		}
		fmt.Fprintln(out, "-1")
	}
	out.Flush()
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"index/suffixarray"
	"log"
	"math"
	"net"
	"os"
	"path"
	"sort"
	"strconv"
	"strings"
	"time"
)

// For Codeforces
func main() {
	io := newStdIO()
	defer io.Flush()
	for T := io.ScanUInt16(); T > 0; T-- {
		solve(&io)
	}
}
func solve(io *IO) {
	l := io.ScanInt64()
	r := io.ScanInt64()
	x := io.ScanInt64()
	a := io.ScanInt64()
	b := io.ScanInt64()

	if a == b {
		io.PrintLn(0)
		return
	}
	if Abs(a-b) >= x {
		io.PrintLn(1)
		return
	}

	if a < b && Abs(a-l) >= x {
		io.PrintLn(2)
		return
	}
	if a < b && Abs(a-r) >= x && Abs(b-r) >= x {
		io.PrintLn(2)
		return
	}
	if a > b && Abs(a-r) >= x {
		io.PrintLn(2)
		return
	}
	if a > b && Abs(a-l) >= x && Abs(b-l) >= x {
		io.PrintLn(2)
		return
	}

	if a > b && Abs(a-l) >= x && Abs(r-b) >= x {
		io.PrintLn(3)
		return
	}
	if a < b && Abs(a-r) >= x && Abs(b-l) >= x {
		io.PrintLn(3)
		return
	}
	io.PrintLn(-1)
}

// #region INTERFACES

// From https://pkg.go.dev/golang.org/x/exp/constraints
type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}
type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
type Integer interface {
	Signed | Unsigned
}
type Float interface {
	~float32 | ~float64
}
type Complex interface {
	~complex64 | ~complex128
}
type Ordered interface {
	Integer | Float | ~string
}

type Prioritizable[T any] interface {
	PriorTo(x T) bool // If you take this as a relation: if (a,b) in R => (b,a) not in R
}

// #endregion
// #region TYPES WITH METHODS
// #region SingleLinkedList
type singleLinkedListNode[T comparable] struct {
	Value T
	Next  *singleLinkedListNode[T]
}

type SingleLinkedList[T comparable, IndexType Unsigned] struct {
	first  *singleLinkedListNode[T]
	last   *singleLinkedListNode[T]
	length IndexType
}

func NewSingleLinkedList[T comparable, IndexType Unsigned]() *SingleLinkedList[T, IndexType] {
	return &SingleLinkedList[T, IndexType]{
		first:  nil,
		last:   nil,
		length: 0,
	}
}
func (l *SingleLinkedList[T, I]) Len() I { return l.length }

// length > 0
func (l *SingleLinkedList[T, I]) First() T { return l.first.Value }

// length > 0
func (l *SingleLinkedList[T, I]) Last() T { return l.last.Value }

func (l *SingleLinkedList[T, I]) InsertFirst(value T) {
	if l.length == 0 {
		nodeToInsert := &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
		l.first = nodeToInsert
		l.last = nodeToInsert
	} else {
		l.first = &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
	}
	l.length++
}

func (l *SingleLinkedList[T, I]) InsertLast(value T) {
	if l.length == 0 {
		nodeToInsert := &singleLinkedListNode[T]{
			Value: value,
			Next:  l.first,
		}
		l.first = nodeToInsert
		l.last = nodeToInsert
	} else {
		l.last.Next = &singleLinkedListNode[T]{
			Value: value,
			Next:  nil,
		}
		l.last = l.last.Next
	}
	l.length++
}

// index <= length
func (l *SingleLinkedList[T, I]) InsertAt(index I, value T) {
	if index == 0 {
		l.InsertFirst(value)
		return
	}
	if index == l.length {
		l.InsertLast(value)
		return
	}

	n := l.first
	for index > 1 {
		n = n.Next
		index--
	}
	n.Next = &singleLinkedListNode[T]{
		Value: value,
		Next:  n.Next,
	}
	l.length++
}

func (l *SingleLinkedList[T, I]) Contains(value T) bool {
	tmp := l.first
	for i := I(0); i < l.length; i++ {
		if tmp.Value == value {
			return true
		}
		tmp = tmp.Next
	}
	return false
}
func (l *SingleLinkedList[T, I]) Clear() {
	l.first = nil
	l.last = nil
	l.length = 0
}

// index < length
func (l *SingleLinkedList[T, I]) GetElementAt(index I) T {
	n := l.first
	for index > 0 {
		n = n.Next
		index--
	}
	return n.Value
}

// index < length
func (l *SingleLinkedList[T, I]) SetElementAt(index I, value T) {
	n := l.first
	for index > 0 {
		n = n.Next
		index--
	}
	n.Value = value
}

func (l *SingleLinkedList[T, I]) RemoveFirst() T {
	tmp := l.first
	l.first = l.first.Next
	l.length--
	if l.length == 0 {
		l.last = nil
	}
	return tmp.Value
}
func (l *SingleLinkedList[T, I]) RemoveLast() (value T) {
	value = l.last.Value
	if l.length == 1 {
		l.first = nil
		l.last = nil
		l.length = 0
		return
	}

	tmp := l.first
	for i := I(2); i < l.length; i++ {
		tmp = tmp.Next
	}
	l.last = tmp
	return
}

func (l *SingleLinkedList[T, I]) RemoveAt(index I) T {
	if index == 0 {
		return l.RemoveFirst()
	}
	if index == l.length-1 {
		return l.RemoveLast()
	}

	tmp := l.first
	for i := I(1); i < index; i++ {
		tmp = tmp.Next
	}
	res := tmp.Next.Value
	tmp.Next = tmp.Next.Next
	return res
}

func (l *SingleLinkedList[T, I]) ToSlice() (res []T) {
	res = make([]T, 0, l.length)
	tmp := l.first
	for i := I(0); i < l.length; i++ {
		res = append(res, tmp.Value)
		tmp = tmp.Next
	}
	return
}
func (it *SingleLinkedList[T, I]) String() string {
	return "Qua:: " + fmt.Sprint(it.ToSlice())
}

// #endregion
// #region Queue

type Queue[T comparable, I Unsigned] struct {
	l SingleLinkedList[T, I]
}

func NewQueue[T comparable, I Unsigned]() *Queue[T, I] {
	return &Queue[T, I]{
		l: SingleLinkedList[T, I]{
			first:  nil,
			last:   nil,
			length: 0,
		},
	}
}
func (q *Queue[T, I]) Len() I          { return q.l.length }
func (q *Queue[T, I]) Enqueue(value T) { q.l.InsertLast(value) }
func (q *Queue[T, I]) Dequeue(T) T     { return q.l.RemoveFirst() }
func (q *Queue[T, I]) Preview() T      { return q.l.First() }
func (q *Queue[T, I]) String() string  { return q.l.String() }

// #endregion
// #region Stack

type Stack[T comparable, I Unsigned] struct {
	l SingleLinkedList[T, I]
}

func NewStack[T comparable, I Unsigned]() *Stack[T, I] {
	return &Stack[T, I]{
		l: SingleLinkedList[T, I]{
			first:  nil,
			last:   nil,
			length: 0,
		},
	}
}
func (s *Stack[T, I]) Len() I         { return s.l.length }
func (s *Stack[T, I]) Push(value T)   { s.l.InsertFirst(value) }
func (s *Stack[T, I]) Pop(T) T        { return s.l.RemoveFirst() }
func (s *Stack[T, I]) Preview() T     { return s.l.First() }
func (s *Stack[T, I]) String() string { return s.l.String() }

// #endregion
// #region Heap
type BinaryHeap[T Prioritizable[T], I Signed] struct {
	s []T
}

func NewBinaryHeap[T Prioritizable[T], I Signed](s []T) (h *BinaryHeap[T, I]) {
	h = &BinaryHeap[T, I]{
		s: s,
	}

	for i := (h.Len() - 2) / 2; i >= 0; i-- {
		h.heapifyDown(i)
	}
	return
}
func (h *BinaryHeap[T, I]) Len() I {
	return I(len(h.s))
}
func (h *BinaryHeap[T, I]) Push(value T) {
	h.s = append(h.s, value)
	h.heapifyUp(h.Len() - 1)
}
func (h *BinaryHeap[T, I]) Pop() (res T) {
	res = h.s[0]
	h.s[0] = h.s[h.Len()-1]
	h.s = h.s[:h.Len()-1]
	h.heapifyDown(0)
	return
}

func (h *BinaryHeap[T, I]) heapifyDown(index I) bool {
	origin := index
	for {
		j := index*2 + 2
		if j < h.Len() {
			if h.s[j-1].PriorTo(h.s[j]) {
				j--
			}
		} else {
			if j <= h.Len() && !h.s[j].PriorTo(h.s[index]) {
				h.s[j], h.s[index] = h.s[index], h.s[j]
			}
			break
		}
		if h.s[j].PriorTo(h.s[index]) {
			h.s[j], h.s[index] = h.s[index], h.s[j]
			index = j
		} else {
			break
		}
	}
	return origin != index
}
func (h *BinaryHeap[T, I]) heapifyUp(index I) {
	for {
		parent := (index - 1) / 2
		if parent == index || h.s[parent].PriorTo(h.s[index]) {
			break
		}
		h.s[index], h.s[parent] = h.s[parent], h.s[index]
		index = parent
	}
}

// #endregion

// #endregion

// #region FUNCTIONS
func Max[T Ordered](a, b T) T {
	if a >= b {
		return a
	}
	return b
}
func Min[T Ordered](a, b T) T {
	if a <= b {
		return a
	}
	return b
}
func Abs[T Integer | Float](a T) T {
	if a < 0 {
		return -a
	}
	return a
}
func Swap[T any](a, b *T) {
	*a, *b = *b, *a
}

// At least one != 0
func GCD[T Unsigned](a, b T) T {
	if b < a {
		Swap(&a, &b)
	}
	for {
		if a == 0 {
			return b
		}
		r := (b % a)
		b = a
		a = r
	}
}

// At least one != 0
func LCM[T Unsigned](a, b T) T {
	return (a * b) / GCD(a, b)
}

func First[T any](a T, _ any) T { return a }

// #endregion

// #region IO STUFF
type IO struct {
	r *bufio.Reader
	w *bufio.Writer
}

func newStdIO() IO {
	return IO{
		r: bufio.NewReader(os.Stdin),
		w: bufio.NewWriter(os.Stdout),
	}
}

// Is assumed that input.txt file exists
func newFileIO() IO {
	return IO{
		r: bufio.NewReader(First(os.Open("input.txt"))),
		w: bufio.NewWriter(First(os.OpenFile("output.txt", os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.ModePerm))),
	}
}

func (io *IO) ScanInt8() (x int8)   { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt16() (x int16) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt32() (x int32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanInt64() (x int64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanUInt8() (x uint8)   { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt16() (x uint16) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt32() (x uint32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanUInt64() (x uint64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanFloat32() (x float32) { fmt.Fscan(io.r, &x); return }
func (io *IO) ScanFloat64() (x float64) { fmt.Fscan(io.r, &x); return }

func (io *IO) ScanString() (x string) { fmt.Fscan(io.r, &x); return }

func (io *IO) Print(x ...any)   { fmt.Fprint(io.w, x...) }
func (io *IO) PrintLn(x ...any) { fmt.Fprintln(io.w, x...) }

func (io *IO) Flush() { io.w.Flush() }

// #endregion

// #region KEEP IMPORTS
func D() {
	_ = bufio.Reader{}
	_ = bytes.Buffer{}
	_ = suffixarray.Index{}
	_ = log.Default()
	_ = math.Abs(0)
	_ = net.Dialer{}
	_ = path.ErrBadPattern
	_ = sort.Float64sAreSorted(nil)
	_ = strconv.ErrRange
	_ = strings.Builder{}
	_ = time.ANSIC
	_ = newStdIO()
	_ = newFileIO()
}

// #endregion

package main

import (
	"bufio"
	"fmt"
	"os"
)

func Solve(reader *bufio.Reader, writer *bufio.Writer) {
	var l, r, x int
	fmt.Fscan(reader, &l, &r, &x)
	var a, b int
	fmt.Fscan(reader, &a, &b)
	if a == b {
		fmt.Fprintf(writer, "0")
	} else if max(abc(b-l), abc(b-r)) < x || max(abc(a-l), abc(a-r)) < x {
		fmt.Fprintf(writer, "-1")
	} else if abc(a-b) >= x {
		fmt.Fprintf(writer, "1")
	} else {
		ans := 3
		if abc(b-l) >= x {
			if abc(a-l) >= x {
				ans = 2
			}
		}
		if abc(b-r) >= x {
			if abc(a-r) >= x {
				ans = 2
			}
		}
		fmt.Fprintf(writer, "%v", ans)
	}

	fmt.Fprintf(writer, "\n")
}

func abc(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}

func main() {
	var reader *bufio.Reader
	var writer *bufio.Writer

	filename_in := "data.in"
	filename_out := "data.out"

	stdinout := true
	readtests := true
	tests := 1

	if (!stdinout || inArgs("local")) && !inArgs("std") {
		infile, inerr := os.Open(filename_in)
		if inerr != nil {
			if os.IsNotExist(inerr) {
				os.Create(filename_in)
			}
			fmt.Println(inerr)
			return
		}
		defer infile.Close()

		outfile, outerr := os.OpenFile(filename_out, os.O_WRONLY, os.ModeAppend)
		if outerr != nil {
			if os.IsNotExist(outerr) {
				outfile, outerr = os.Create(filename_out)
				if outerr != nil {
					fmt.Println(outerr)
					return
				}
			}
		}
		defer outfile.Close()

		reader = bufio.NewReader(infile)
		writer = bufio.NewWriter(outfile)
	} else if stdinout || inArgs("std") {
		reader = bufio.NewReader(os.Stdin)
		writer = bufio.NewWriter(os.Stdout)
	}
	defer func() {
		err := writer.Flush()
		if err != nil {
			fmt.Println(err)
		}
	}()

	if readtests || inArgs("local") {
		fmt.Fscanf(reader, "%d\n", &tests)
	}

	for i := 0; i < tests; i++ {
		Solve(reader, writer)
		fmt.Fscanf(reader, "\n")
	}

}

func inArgs(arg string) bool {
	for _, a := range os.Args {
		if a == arg {
			return true
		}
	}
	return false
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func solve(l, r, x, a, b int) int {
	if a == b {
		return 0
	}
	if b-a >= x {
		return 1
	}

	if r-a >= x && r-b >= x {
		return 2
	}
	if a-l >= x && b-l >= x {
		return 2
	}

	if r-a >= x && r-l >= x && b-l >= x {
		return 3
	}
	if a-l >= x && r-l >= x && r-b >= x {
		return 3
	}

	return -1
}

func main() {
	inp := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)

	var test int
	fmt.Fscanln(inp, &test)
	for test > 0 {
		test--
		var l, r, x, a, b int
		fmt.Fscanln(inp, &l, &r, &x)
		fmt.Fscanln(inp, &a, &b)
		fmt.Fprintln(out, solve(l, r, x, a, b))
	}

	out.Flush()
}


package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	out = bufio.NewWriter(os.Stdout)
	in  = bufio.NewReader(os.Stdin)
)

func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}

func main() {
	defer out.Flush()

	var (
		n, m, q  int
		inPoints []uint
		a, b     int
		t        int
		minNum   int
	)
	fmt.Fscan(in, &n, &m)
	inPoints = make([]uint, n)
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &a, &b)
		minNum = a
		if a > b {
			minNum = b
		}

		inPoints[minNum]++
	}

	var tAns int
	for _, p := range inPoints {
		if p == 0 {
			tAns++
		}
	}

	fmt.Fscan(in, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(in, &t)
		if t == 1 {
			fmt.Fscan(in, &a, &b)

			minNum = a
			if a > b {
				minNum = b
			}

			inPoints[minNum]++
			if inPoints[minNum] == 1 {
				tAns--
			}
		} else if t == 2 {
			fmt.Fscan(in, &a, &b)

			minNum = a
			if a > b {
				minNum = b
			}

			inPoints[minNum]--
			if inPoints[minNum] == 0 {
				tAns++
			}
		} else if t == 3 {
			printf("%d\n", tAns)
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1548A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n, m, v, w, q, tp, ans int
	Fscan(in, &n, &m)
	c := make([]int, n+1)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		c[min(v, w)]++
	}
	for _, v := range c[1:] {
		if v == 0 {
			ans++
		}
	}
	for Fscan(in, &q); q > 0; q-- {
		if Fscan(in, &tp); tp < 3 {
			Fscan(in, &v, &w)
			v = min(v, w)
			if tp == 1 {
				if c[v] == 0 {
					ans--
				}
				c[v]++
			} else {
				c[v]--
				if c[v] == 0 {
					ans++
				}
			}
		} else {
			Fprintln(out, ans)
		}
	}
}

func main() { CF1548A(os.Stdin, os.Stdout) }

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	n int
	m int
)

var neighborCnt []int

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	inp := bufio.NewScanner(os.Stdin)
	inp.Buffer(make([]byte, 1000000), 1000000)

	inp.Scan()
	fmt.Sscan(inp.Text(), &n, &m)
	neighborCnt = make([]int, n+1)

	for i := 0; i < m; i++ {
		var (
			u int
			v int
		)
		inp.Scan()
		fmt.Sscan(inp.Text(), &u, &v)

		if u > v {
			neighborCnt[v]++
		} else {
			neighborCnt[u]++
		}
	}
	var surviveCnt int
	for i := 1; i <= n; i++ {
		if neighborCnt[i] == 0 {
			surviveCnt++
		}
	}

	var q int
	inp.Scan()
	fmt.Sscan(inp.Text(), &q)

	for ; q > 0; q-- {
		var (
			t int
			u int
			v int
		)
		inp.Scan()
		fmt.Sscan(inp.Text(), &t)
		if t == 3 {
			fmt.Println(surviveCnt)
		} else {
			fmt.Sscan(inp.Text(), &t, &u, &v)
			if t == 1 {
				// fmt.Println(u, v, neighborCnt[u], neighborCnt[v])
				if neighborCnt[u] == 0 {
					surviveCnt--
				}
				if neighborCnt[v] == 0 {
					surviveCnt--
				}

				if u > v {
					neighborCnt[v]++
				} else {
					neighborCnt[u]++
				}

				if neighborCnt[u] == 0 {
					surviveCnt++
				}
				if neighborCnt[v] == 0 {
					surviveCnt++
				}
			} else {
				if neighborCnt[u] == 0 {
					surviveCnt--
				}
				if neighborCnt[v] == 0 {
					surviveCnt--
				}

				if u > v {
					neighborCnt[v]--
				} else {
					neighborCnt[u]--
				}

				if neighborCnt[u] == 0 {
					surviveCnt++
				}
				if neighborCnt[v] == 0 {
					surviveCnt++
				}
			}
		}
		// fmt.Println("GGG", surviveCnt)

	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

// var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	// fmt.Fscan(input, &t)

	var n, m int
	fmt.Fscan(input, &n, &m)

	ARRAY := make([]int, n)

	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscan(input, &u, &v)
		p := MINN(u, v)
		ARRAY[p-1]++
	}

	var quantity int
	for i := 0; i < n; i++ {
		if ARRAY[i] == 0 {
			quantity++
		}
	}

	var q int
	fmt.Fscan(input, &q)

	for j := 0; j < q; j++ {
		var typeINt int
		fmt.Fscan(input, &typeINt)
		if typeINt == 1 {
			var u, v int
			fmt.Fscan(input, &u, &v)
			p := MINN(u, v)
			ARRAY[p-1]++
			if ARRAY[p-1] == 1 {
				quantity--
			}
		}
		if typeINt == 2 {
			var u, v int
			fmt.Fscan(input, &u, &v)
			p := MINN(u, v)
			ARRAY[p-1]--
			if ARRAY[p-1] == 0 {
				quantity++
			}
		}
		if typeINt == 3 {
			fmt.Println(quantity)
		}

	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	n int
	m int
)

var neighborCnt []int

func Max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	inp := bufio.NewScanner(os.Stdin)
	inp.Buffer(make([]byte, 1000000), 1000000)

	inp.Scan()
	fmt.Sscan(inp.Text(), &n, &m)
	neighborCnt = make([]int, n+1)

	for i := 0; i < m; i++ {
		var (
			u int
			v int
		)
		inp.Scan()
		fmt.Sscan(inp.Text(), &u, &v)

		if u > v {
			neighborCnt[v]++
		} else {
			neighborCnt[u]++
		}
	}
	var surviveCnt int
	for i := 1; i <= n; i++ {
		if neighborCnt[i] == 0 {
			surviveCnt++
		}
	}

	var q int
	inp.Scan()
	fmt.Sscan(inp.Text(), &q)

	for ; q > 0; q-- {
		var (
			t int
			u int
			v int
		)
		inp.Scan()
		fmt.Sscan(inp.Text(), &t)
		if t == 3 {
			fmt.Println(surviveCnt)
		} else {
			fmt.Sscan(inp.Text(), &u, &v)
			if t == 1 {
				if neighborCnt[u] == 0 {
					surviveCnt--
				}
				if neighborCnt[v] == 0 {
					surviveCnt--
				}

				if u > v {
					neighborCnt[v]++
				} else {
					neighborCnt[u]++
				}

				if neighborCnt[u] == 0 {
					surviveCnt++
				}
				if neighborCnt[v] == 0 {
					surviveCnt++
				}
			} else {
				if neighborCnt[u] == 0 {
					surviveCnt--
				}
				if neighborCnt[v] == 0 {
					surviveCnt--
				}

				if u > v {
					neighborCnt[v]--
				} else {
					neighborCnt[u]--
				}

				if neighborCnt[u] == 0 {
					surviveCnt++
				}
				if neighborCnt[v] == 0 {
					surviveCnt++
				}
			}
		}

	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := getInt()
	k := getInt()
	a := getNint(n)
	b := getNint(n)

	ispossible := func(c int64) bool {
		k := k
		for i := 0; i < n; i++ {
			q := int64(a[i])*c - int64(b[i])
			if q > int64(k) {
				return false
			}
			if q > 0 {
				k -= int(q)
			}
		}
		return true
	}

	fmt.Println(bin_search_max64(ispossible, 0, 2000000001))
}

// largest argument, for which f(arg) is true
// logic function should be non-increasing
func bin_search_max64(f func(int64) bool, lo, up int64) int64 {
	var mid, step int64
	const eps = 1
	lo--
	cnt := up - lo
	for cnt >= eps {
		step = cnt / 2
		mid = up - step
		if !f(mid) {
			up = mid - eps
			cnt -= step + eps
		} else {
			cnt = step
		}
	}
	return up
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getWordOk() (string, bool) {
	ok := globalInput.Scan()
	return globalInput.Text(), ok
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func minStr(a, b string) string {
	if a < b {
		return a
	}
	return b
}
func maxStr(a, b string) string {
	if a < b {
		return b
	}
	return a
}
func remin(a *int, b int) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax(a *int, b int) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func remin64(a *int64, b int64) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remax64(a *int64, b int64) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}
func reminStr(a *string, b string) bool {
	if b < *a {
		*a = b
		return true
	}
	return false
}
func remaxStr(a *string, b string) bool {
	if b > *a {
		*a = b
		return true
	}
	return false
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

type (
	FLess    func(i, j int) bool
	FSwap    func(i, j int)
	wrapSort struct {
		Length int
		FLess
		FSwap
	}
)

func (w *wrapSort) Len() int           { return w.Length }
func (w *wrapSort) Less(i, j int) bool { return w.FLess(i, j) }
func (w *wrapSort) Swap(i, j int)      { w.FSwap(i, j) }
func wsort(length int, fless func(i, j int) bool, fswap func(i, j int)) {
	sort.Sort(&wrapSort{length, fless, fswap})
}

// Using binary search to validate the "answers" within lg(n) times.
// This solution is far away from solving D2 :(
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n, k, scanner := 0, 0, bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	scanner.Scan()
	k, _ = strconv.Atoi(scanner.Text())
	a, b := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		b[i], _ = strconv.Atoi(scanner.Text())
	}

	answer, l, r := -1, int64(0), int64(2000000000)
	for l <= r {
		mid, match, newK := (l+r)/2, false, int64(k)
		for i := 0; i < len(a); i++ {
			extra := int64(a[i])*mid - int64(b[i])
			if extra > newK {
				break
			} else if extra > 0 {
				newK -= extra
			}
			if i == (len(a) - 1) {
				match = true
			}
		}
		if match {
			l = mid + 1
			answer = int(mid)
		} else {
			r = mid - 1
		}
	}

	fmt.Println(answer)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var N, K int

func CheckBake(cookie int64, magic int64, A []int, B []int) bool {
	for i := 0; i < N; i++ {
		need := cookie * int64(A[i])
		rest := int64(B[i]) - need
		if rest < 0 {
			magic += int64(rest)
		}
		if magic < 0 {
			return false
		}
	}
	return true
}

func main() {
	fsc := NewFastScanner()
	N = fsc.NextInt()
	K = fsc.NextInt()
	A := make([]int, N)
	B := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = fsc.NextInt()
	}
	for i := 0; i < N; i++ {
		B[i] = fsc.NextInt()
	}
	left := int64(0)
	right := int64(10000000000)
	for right-left > 1 {
		var med int64
		med = (right + left) / 2
		flag := CheckBake(med, int64(K), A, B)

		if flag { //bake
			left = med
		} else {
			right = med
		}
	}
	fmt.Println(left)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

// Using binary search to validate the "answers" within lg(n) times.
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n, k, scanner := 0, 0, bufio.NewScanner(os.Stdin)
	fmt.Scan(&n, &k)
	scanner.Split(bufio.ScanWords)
	a, b := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := 0; i < n; i++ {
		scanner.Scan()
		b[i], _ = strconv.Atoi(scanner.Text())
	}

	answer, l, r := -1, 0, 2000
	for l <= r {
		mid, match, newK := (l+r)/2, false, k
		for i := 0; i < len(a); i++ {
			extra := a[i]*mid - b[i]
			if extra > newK {
				break
			} else if extra > 0 {
				newK -= extra
			}
			if i == (len(a) - 1) {
				match = true
			}
		}
		if match {
			l = mid + 1
			answer = mid
		} else {
			r = mid - 1
		}
	}

	fmt.Println(answer)
}


package main

import (
	"bufio"
	"os"
	"strconv"
)

var in *bufio.Scanner
var out *bufio.Writer

const maxn = 100005

var n, q int
var cnt [maxn]int

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	in.Scan()
	n, _ = strconv.Atoi(in.Text())

	for x := 0; x < maxn; x++ {
		cnt[x] = 0
	}

	for i := 1; i <= n; i++ {
		in.Scan()
		x, _ := strconv.Atoi(in.Text())
		cnt[x]++
	}

	for x := 1; x < maxn; x++ {
		cnt[x] += cnt[x-1]
	}

	in.Scan()
	q, _ = strconv.Atoi(in.Text())

	for i := 0; i < q; i++ {
		in.Scan()
		x, _ := strconv.Atoi(in.Text())
		if x > maxn-1 {
			x = maxn - 1
		}
		out.WriteString(strconv.Itoa(cnt[x]))
		out.WriteByte('\n')
	}
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "sort"
    "strconv"
    "strings"
)

func main() {

    in := bufio.NewReader(os.Stdin)
    text, _ := in.ReadString('\n')
    text, _ = in.ReadString('\n')
    shopsString := strings.Split(text, " ")
    var shops []int
    for _, shopString := range shopsString {
    //    fmt.Println("A")
        shop, _ := strconv.Atoi(strings.TrimSpace(shopString))
        shops = append(shops, shop)
    }
    //fmt.Println(shops)
    sort.Ints(shops)
//    fmt.Println(shops)

    text, _ = in.ReadString('\n')
    //fmt.Printf("|%s|\n", text)
    nDays, _ := strconv.Atoi(strings.TrimSpace(text))
    //fmt.Println(nDays)
    for i := 0; i < nDays; i++ {
        text, _ = in.ReadString('\n')
        money, _ := strconv.Atoi(strings.TrimSpace(text))
        fmt.Println(solve(shops, money))
    }

}

func solve(shops []int, money int) int {

    lo := 0
    hi := len(shops) - 1

    if money < shops[0] { return 0 }

    for lo < hi {
        mid := (lo + hi) / 2
        n := shops[mid]

        //fmt.Printf("%d to %d, %d at %d, looking for %d\n", lo, hi, n, mid, money)

        if n > money {
            hi = mid - 1
        } else {
            if mid + 1 == len(shops) {
                return len(shops)
            }

            if shops[mid + 1] > money {
                return mid + 1
            } else {
                lo = mid + 1
            }
        }
    }
    return lo + 1
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const MAX_AMOUNT = 100000

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(reader, &n)

	dp := make(map[int]int)

	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)

		dp[x]++
	}

	for i := 1; i <= MAX_AMOUNT; i++ {
		dp[i] += dp[i-1]
	}

	var qr int
	fmt.Fscan(reader, &qr)

	for qr > 0 {
		var x int
		fmt.Fscan(reader, &x)

		fmt.Println(dp[min(x, MAX_AMOUNT)])
		qr--
	}
}

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n int

	fmt.Fscan(reader, &n)

	stores := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &stores[i])
	}

	sort.Ints(stores)
	var qr int
	fmt.Fscan(reader, &qr)

	// fmt.Println(stores)
	for i := 0; i < qr; i++ {
		var q int
		fmt.Fscan(reader, &q)

		found := false
		l, r := 0, n
		var pos int
		for l < r {
			mid := (l + r) / 2

			if stores[mid] > q {
				r = mid
			} else if stores[mid] <= q {
				l, pos, found = mid+1, mid, true
			}
		}

		if found {
			fmt.Println(pos + 1)
		} else {
			fmt.Println(0)
		}
	}
}

package main

import (
	"fmt"
	"strings"
	"strconv"
	"bufio"
	"os"
)

func main() {
	n := largeInt()
	maxx := 100000

	x := make([]int, maxx + 1)

	ls := largeIntArray()

	for k := 0; k < n; k++ {
		x[ls[k]]++
	}

	for i := 1; i <= maxx; i++ {
		x[i] += x[i - 1]
	}
	q := largeInt()

	for i := 0; i < q; i++ {
		m := largeInt()

		if m > maxx {
			m = maxx
		}
		fmt.Println(x[m])

	}

}

var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func largeIntArray() []int {
	s := readLine()
	vs := strings.Split(s, " ")
	N := len(vs)
	data := make([]int, N)
	for i := 0; i < N; i++ {
		var e error
		data[i], e = strconv.Atoi(vs[i])
		if (e != nil) {
			panic(e)
		}
	}
	return data
}
func largeInt() (ret int) {
	s := readLine()
	ret, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return ret
}

package main

import (
	"fmt"
	"strings"
	"strconv"
	"bufio"
	"os"
)

func main() {
	n := largeInt()
	maxx := 100000

	x := make([]int, maxx + 1)

	ls := largeIntArray()

	for k := 0; k < n; k++ {
		x[ls[k]]++
	}

	for i := 1; i <= maxx; i++ {
		x[i] += x[i - 1]
	}
	q := largeInt()

	for i := 0; i < q; i++ {
		m := largeInt()

		if m > maxx {
			m = maxx
		}
		fmt.Println(x[m])

	}

}

var rdr = bufio.NewReaderSize(os.Stdin, 10000)

func readLine() string {
	buf := make([]byte, 0, 10000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func largeIntArray() []int {
	s := readLine()
	vs := strings.Split(s, " ")
	N := len(vs)
	data := make([]int, N)
	for i := 0; i < N; i++ {
		var e error
		data[i], e = strconv.Atoi(vs[i])
		if (e != nil) {
			panic(e)
		}
	}
	return data
}
func largeInt() (ret int) {
	s := readLine()
	ret, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return ret
}

package main

import (
	"fmt"
	"sort"
	"math"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	a := make([]int, n)
	b := make(map[int]int)
	min := math.MaxInt32
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i],_ = strconv.Atoi(scanner.Text())
		v, ok := b[a[i]]
		if ok {
			b[a[i]] = v+1
		} else {
			b[a[i]]=1
		}
		if min > a[i] {
			min = a[i]
		}
	}
	var c, v int
	sort.Ints(a)
	scanner.Scan()
	m,_ := strconv.Atoi(scanner.Text())
	e := make([]int, m)
	for i := 0; i < m; i++ {
		scanner.Scan()
		v, _ = strconv.Atoi(scanner.Text())
		if v < min {
			c = 0
		} else {
			w, ok := b[v]
			d := sort.SearchInts(a, int(v))
			if ok {
				c = d+w
			} else {
				c = d
			}
		}
		e[i]=int(c)
	}
	for i := 0; i < m ; i++  {
		fmt.Println(e[i])
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func init() {
	in.Split(bufio.ScanWords)
}
func exit() {
	out.Flush()
}

// custom
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}

/*
 */
var n int
var prices []int
var d int
var mone []int

func main() {
	defer exit()

	n = nextInt()
	prices = make([]int, n+1, n+1)

	for i := 1; i != n+1; i++ {
		prices[i] = nextInt()
	}
	sort.Ints(prices[1:])

	d := nextInt()
	mone = make([]int, d+1, d+1)
	for i := 1; i != d+1; i++ {
		target := nextInt()
		l := 0
		r := n
		for {
			if l == r {
				break
			}
			mid := (l + r + 1) / 2
			midv := prices[mid]
			if midv > target {
				r = mid - 1
			} else {
				l = mid
			}
		}
		fmt.Fprintln(out, l)
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanf(reader, "%d ", &n)
	prices := make([]int, 100001)
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscanf(reader, "%d ", &x)
		prices[x]++
	}
	for i := 1; i <= 100000; i++ {
		prices[i] += prices[i-1]
	}

	var q int
	fmt.Fscanf(reader, "%d ", &q)
	m := make([]int, q)
	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d ", &m[i])
	}
	for i := 0; i < q; i++ {
		mm := m[i]
		if mm > 100000 {
			mm = 100000
		}
		fmt.Printf("%d\n", prices[mm])
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const MAX_PRICE = 100000

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var shops int
	fmt.Fscanf(reader, "%d\n", &shops)
	prices := make([]int, shops)
	var cumulative [MAX_PRICE + 1]int64
	for i := 0; i < shops; i++ {
		fmt.Fscanf(reader, "%d", &prices[i])
		cumulative[prices[i]]++
	}
	for i := 1; i <= MAX_PRICE; i++ {
		cumulative[i] += cumulative[i-1]
	}
	var days int
	fmt.Fscanf(reader, "\n%d", &days)
	for i := 0; i < days; i++ {
		var spend_limit int64
		fmt.Fscanf(reader, "\n%d", &spend_limit)
		if spend_limit > int64(MAX_PRICE) {
			spend_limit = MAX_PRICE
		}
		fmt.Fprintln(writer, cumulative[spend_limit])
	}
}

package main

import (
	"fmt"
	"strings"
	"strconv"
	"bufio"
	"os"
)

func main() {
	n := largeInt()
	maxx := 100000

	x := make([]int, maxx + 1)

	ls := largeIntArray()

	for k := 0; k < n; k++ {
		x[ls[k]]++
	}

	for i := 1; i <= maxx; i++ {
		x[i] += x[i - 1]
	}
	q := largeInt()

	for i := 0; i < q; i++ {
		m := largeInt()

		if m > maxx {
			m = maxx
		}
		fmt.Println(x[m])

	}

}

var rdr = bufio.NewReader(os.Stdin)

func readLine() string {
	buf := make([]byte, 0)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}
func largeIntArray() []int {
	s := readLine()
	vs := strings.Split(s, " ")
	N := len(vs)
	data := make([]int, N)
	for i := 0; i < N; i++ {
		var e error
		data[i], e = strconv.Atoi(vs[i])
		if (e != nil) {
			panic(e)
		}
	}
	return data
}
func largeInt() (ret int) {
	s := readLine()
	ret, e := strconv.Atoi(s)
	if e != nil {
		panic(e)
	}
	return ret
}

    package main

    import (
    	"bufio"
    	"fmt"
    	"os"
    	"sort"
    )

    func main() {
    	var numOfShop int
    	reader := bufio.NewReader(os.Stdin)

    	fmt.Fscan(reader, &numOfShop)

    	priceOfShop := make([]int, numOfShop)

    	for i := 0; i < numOfShop; i++ {
    		fmt.Fscan(reader,&priceOfShop[i])
    	}
    	sort.Ints(priceOfShop)
    	var numOfDay int
    	fmt.Fscan(reader,&numOfDay)
    	var coins int
    	for i := 0; i < numOfDay; i++ {
    		fmt.Fscan(reader,&coins)

    		result :=0
    		if priceOfShop[0] > coins {
    			fmt.Println("0")
    			continue
    		}
    		if priceOfShop[len(priceOfShop)-1] <= coins  {
    			fmt.Println(len(priceOfShop))
    			continue
    		}
    		l := 0
    		r:= len(priceOfShop)
    		for l <= r {
    			mid := l + (r-l)/2
    			if priceOfShop[mid] == coins || priceOfShop[mid] < coins {
    				result = mid+1
    				l = mid + 1
    			} else {
    				r = mid - 1
    			}
    		}

    		fmt.Println(result)
    	}

    }

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var (
	reader *bufio.Reader
)

func findPos(a []int, x, l, r int) (pos int) {

	if a[0] > x {
		return 0
	}

	if a[len(a)-1] <= x {
		return len(a)
	}

	for l < r {
		m := l/2 + r/2
		if a[m] <= x {
			l = m + 1
		} else {
			r = m - 1
		}
	}

	if a[l] > x {
		pos = l
	} else {
		pos = l + 1
	}

	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	sort.Ints(x)

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n * 10 + int(v - '0')
	}
	return
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n := toInt(scanner.Bytes())
	shops := make([]int, n)

	for i := 0; i < n; i++ {
		scanner.Scan()
		shops[i] = toInt(scanner.Bytes())
	}
	scanner.Scan()
	sort.Ints(shops)
	q := toInt(scanner.Bytes())
	for i := 0; i < q; i++ {
		scanner.Scan()
		m := toInt(scanner.Bytes())
		j := 0
		z := n - 1
		if m < shops[0] {
			fmt.Println(0)
			continue
		}else if m >= shops[n - 1] {
			fmt.Println(n)
			continue
		}
		for j <= z {
			y := (z + j) / 2
			if shops[y] <= m {
				j = y + 1
			}else if shops[y] > m {
				z = y - 1
			}
		}
		fmt.Println(j)

	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
func main(){
	var n int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n)
	shops := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &shops[i])
	}
	sort.Ints(shops)
	var days, money int
	fmt.Fscan(reader, &days)
	for i:=0; i<days; i++{
		fmt.Fscan(reader, &money)
		count := 0
		if shops[0] > money {
			fmt.Println(count)
			continue
		}
		if shops[len(shops)-1] <= money {
			fmt.Println(len(shops))
			continue
		}
		left := 0
		right := len(shops)
		for left <= right {
			mid := left + (right - left)/2
			if shops[mid] == money || shops[mid] < money {
				count = mid + 1
				left = mid +1
			} else {
				right = mid -1
			}
		}
		fmt.Println(count)
	}
}

package main

import (
	"fmt"
	"io"
	"os"
	"bufio"
	"sort"
	"strings"
	"strconv"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	// get number of shops
	line, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	line = strings.TrimSpace(line)
	n, _ := strconv.Atoi(line)

	// get prices of bottles
	priceLine, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	priceLine = strings.TrimSpace(priceLine)
	priceStrings := strings.Fields(priceLine)
	var prices = []int{}

	for _, j := range priceStrings {
		price, _ := strconv.Atoi(j)
		prices = append(prices, price)
	}

	sort.Ints(prices)
	//fmt.Printf("-- %v --\n", prices)
	// get number of days
	daysLine, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	daysLine = strings.TrimSpace(daysLine)
	q, _ := strconv.Atoi(daysLine)

	dailyLimits := make(map[int]int)

	for i := 0; i < q; i++ {

		numShops := 0

		// get coin limit for the day
		coinLine, err := reader.ReadString('\n')
		if err != nil && err != io.EOF {
			os.Exit(3)
		}

		coinLine = strings.TrimSpace(coinLine)
		m, _ := strconv.Atoi(coinLine)

		if shopLimit, ok := dailyLimits[m]; ok == true {
			fmt.Printf("%v\n", shopLimit)
			continue
		}

		ndx := sort.Search(n, func(i int) bool { return prices[i] >= m})
        //fmt.Printf("== m: %v, ndx: %v ==\n", m, ndx)
		if ndx < n && prices[ndx] == m {
			// the ndx-th shop has the same price as the daily limit
			numShops = ndx + 1

			// continue through the array in case there is more than one shop with the same price
			ndx++
			for ndx < n && prices[ndx] == m {
				numShops++
				ndx++
			}
		} else {
			// the ndx-th shop returned is above the daily limit
            if ndx == 0 {
                numShops = 0
            } else {
                numShops = ndx
            }
		}

		dailyLimits[m] = numShops
		fmt.Printf("%v\n", numShops)
	}
}

package main

import (
	"bufio"
	"os"
	"strconv"
)

var in *bufio.Scanner
var out *bufio.Writer

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	const nmax = 100005;
	var n int;

	in.Scan()
	n, _ = strconv.Atoi(in.Text())

	cnt := make([]int, nmax)

	for i:=0; i<n; i++ {
		var temp int;
		in.Scan();
		temp, _ = strconv.Atoi(in.Text());
		cnt[temp]++;
	}
	for i:=1; i<nmax;i++ {
		cnt[i] +=cnt[i-1];
	}

	in.Scan();
	q, _ := strconv.Atoi(in.Text());
	for i:=0; i<q; i++ {
		var temp int;
		in.Scan();
		temp, _ = strconv.Atoi(in.Text());
		if (temp>=nmax) {
			temp = nmax-1;
		};
		out.WriteString(strconv.Itoa(cnt[temp]));
		out.WriteByte('\n');
	}
}

// http://codeforces.com/problemset/problem/706/B

package main

import (
	"fmt"
	"bufio"
	"sort"
	"os"
)

func main() {
	var n, q int

	input := bufio.NewReaderSize(os.Stdin, 1024*1024)
	fmt.Fscanln(input, &n)
	prices := make([]int, n)

	for i := 0; i < n; i++ {
		var price int
		if i == n -1 {
			fmt.Fscanln(input, &price)
		} else {
			fmt.Fscan(input, &price)
		}

		prices[i] = price
	}

	sort.Ints(prices)

	fmt.Fscanln(input, &q)
	for i := 0; i < q; i++ {
		var m int
		fmt.Fscanln(input, &m)

		// Solve
		fmt.Println(sort.Search(len(prices), func(i int) bool { return prices[i] > m }))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var numOfShop int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &numOfShop)

	var priceOfShop int
	checkList := make([]int,100001)
	for i := 0; i < numOfShop; i++ {
		fmt.Fscan(reader,&priceOfShop)
		checkList[priceOfShop] +=1
	}

	for i:= 1; i<=100000; i++{
		checkList[i] += checkList[i-1]
	}

	var numOfDay, coins int
	fmt.Fscan(reader,&numOfDay)
	for i := 0; i < numOfDay; i++ {
		fmt.Fscan(reader,&coins)
		if coins > len(checkList){
			fmt.Println(checkList[len(checkList)-1])
			continue
		}
		fmt.Println(checkList[coins])
	}

}

package main

import (
	"fmt"
	"sort"
	"math"
)

func main() {
	var n int32
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	b := make(map[int]bool)
	min := int32(math.MaxInt32)
	for i := int32(0); i < n; i++ {
		fmt.Scanf("%d", &a[i])
		b[a[i]] = true
		if min > int32(a[i]) {
			min = int32(a[i])
		}
	}
	var m, c int32
	var v int
	sort.Ints(a)
	fmt.Scanf("%d", &m)
	for i := int32(0); i < m; i++ {
		fmt.Scanf("%d", &v)
		if int32(v) < min {
			c = 0
		} else {
			_, ok := b[v]
			d := int32(sort.SearchInts(a, int(v)))
			if ok {
				c = d+1
			} else {
				c = d
			}
		}
		fmt.Println(c)

	}
}

package main

import (
	"fmt"
	"sort"
	"math"
)

func main() {
	var n int32
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	b := make(map[int]bool)
	min := int32(math.MaxInt32)
	for i := int32(0); i < n; i++ {
		fmt.Scanf("%d", &a[i])
		b[a[i]] = true
		if min > int32(a[i]) {
			min = int32(a[i])
		}
	}
	var m, c int32
	var v int
	sort.Ints(a)
	fmt.Scanf("%d", &m)
	e := make([]int, m)
	for i := int32(0); i < m; i++ {
		fmt.Scanf("%d", &v)
		if int32(v) < min {
			c = 0
		} else {
			_, ok := b[v]
			d := int32(sort.SearchInts(a, int(v)))
			if ok {
				c = d+1
			} else {
				c = d
			}
		}
		e[i]=int(c)
	}
	for i := int32(0); i < m ; i++  {
		fmt.Println(e[i])
	}
}

package main

import (
	"fmt"
	"sort"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a:=make([]int,n)
	min := math.MaxInt32
	for i:=0; i<n; i++  {
		fmt.Scanf("%d", &a[i])
		if min>a[i] {min=a[i]}
	}
	var m,v int
	sort.Ints(a[:])
	fmt.Scanf("%d", &m)
	for i:=0; i<n ; i++ {
		fmt.Scanf("%d", &v)
		if v<min {
			fmt.Println(0)
		} else {
			fmt.Println(sort.SearchInts(a[:], v)+1)
		}
	}
}

package main

import (
	"fmt"
	"sort"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	b := make(map[int]bool)
	min := math.MaxInt32
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		b[a[i]] = true
		if min > a[i] {
			min = a[i]
		}
	}
	var m, v, c int
	sort.Ints(a)
	fmt.Scanf("%d", &m)
	for i := 0; i < m; i++ {
		fmt.Scanf("%d", &v)
		if v < min {
			c = 0
		} else {
			_, ok := b[v]
			d := sort.SearchInts(a[:], v)
			if ok {
				c = d+1
			} else {
				c = d
			}
		}
		fmt.Println(c)

	}
}

package main

import (
	"fmt"
	"sort"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a := make([]int, n)
	b := make(map[int]bool)
	min := math.MaxInt32
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
		b[a[i]] = true
		if min > a[i] {
			min = a[i]
		}
	}
	var m, v, c int
	sort.Ints(a[:])
	fmt.Scanf("%d", &m)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &v)
		if v < min {
			c = 0
		} else {
			_, ok := b[v]
			d := sort.SearchInts(a[:], v)
			if ok {
				c = d+1
			} else {
				c = d
			}
		}
		fmt.Println(c)

	}
}

package main

import (
	"fmt"
	"sort"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	a:=make([]int,n)
	min := math.MaxInt32
	for i:=0; i<n; i++  {
		fmt.Scanf("%d", &a[i])
		if min>a[i] {min=a[i]}
	}
	fmt.Println(min)
	var m,v int
	sort.Ints(a[:])
	fmt.Scanf("%d", &m)
	for i:=0; i<n ; i++ {
		fmt.Scanf("%d", &v)
		if v<min {
			fmt.Println(0)
		} else {
			fmt.Println(sort.SearchInts(a[:], v)+1)
		}
	}
}

package main

import (
	"fmt"
	"sort"
	"math"
	"bufio"
	"os"
	"strconv"
)

func main() {
	var n int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ = strconv.Atoi(scanner.Text())
	a := make([]int, n)
	b := make(map[int]bool)
	min := math.MaxInt32
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i],_ = strconv.Atoi(scanner.Text())
		b[a[i]] = true
		if min > a[i] {
			min = a[i]
		}
	}
	var c, v int
	sort.Ints(a)
	scanner.Scan()
	m,_ := strconv.Atoi(scanner.Text())
	e := make([]int, m)
	for i := 0; i < m; i++ {
		scanner.Scan()
		v, _ = strconv.Atoi(scanner.Text())
		if v < min {
			c = 0
		} else {
			_, ok := b[v]
			d := sort.SearchInts(a, int(v))
			if ok {
				c = d+1
			} else {
				c = d
			}
		}
		e[i]=int(c)
	}
	for i := 0; i < m ; i++  {
		fmt.Println(e[i])
	}
}

package main

import (
	"fmt"
	"sort"
)
func inputArr() []int {
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	sort.Ints(arr)
	return arr
}
func main(){
	shops := inputArr()
	var days, money int
	fmt.Scan(&days)
	for i:=0; i<days; i++{
		fmt.Scan(&money)
		count := 0
		if shops[0] > money {
			fmt.Println(count)
			break
		}
		if shops[len(shops)-1] <= money {
			fmt.Println(len(shops))
			break
		}
		left := 0
		right := len(shops)
		for left <= right {
			mid := left + (right - left)/2
			if shops[mid] == money || shops[mid] < money {
				count = mid + 1
				left = mid +1
			} else {
				right = mid -1
			}
		}
		fmt.Println(count)
	}
}

package main

import (
	"fmt"
	"io"
	"os"
	"bufio"
	"sort"
	"strings"
	"strconv"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	// get number of shops
	line, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	line = strings.TrimSpace(line)
	n, _ := strconv.Atoi(line)

	// get prices of bottles
	priceLine, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	priceLine = strings.TrimSpace(priceLine)
	priceStrings := strings.Fields(priceLine)
	var prices = []int{}

	for _, j := range priceStrings {
		price, _ := strconv.Atoi(j)
		prices = append(prices, price)
	}
	sort.Ints(prices)

	// get number of days
	daysLine, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	daysLine = strings.TrimSpace(daysLine)
	q, _ := strconv.Atoi(daysLine)

	for i := 0; i < q; i++ {
		numShops := 0

		// get coin limit for the day
		coinLine, err := reader.ReadString('\n')
		if err != nil && err != io.EOF {
			os.Exit(3)
		}

		coinLine = strings.TrimSpace(coinLine)
		m, _ := strconv.Atoi(coinLine)

		ndx := sort.Search(n, func(i int) bool { return prices[i] >= m})
		if ndx < n && prices[ndx] == m {
			// the ndx-th shop has the same price as the daily limit
			numShops = ndx + 1

			// continue through the array in case there is more than one shop with the same price
			ndx++
			for ndx < n && prices[ndx] == m {
				numShops++
				ndx++
			}
		} else {
			// the ndx-th shop returned is above the daily limit
            if ndx == 0 {
                numShops = 0
            } else {
                numShops = ndx + 1
            }
		}

		fmt.Printf("%v\n", numShops)
	}
}

package main

import (
	"fmt"
	"io"
	"os"
	"bufio"
	"strings"
	"strconv"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	// get number of shops
	line, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	line = strings.TrimSpace(line)
	//n, _ := strconv.Atoi(line)

	// get prices of bottles
	priceLine, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	priceLine = strings.TrimSpace(priceLine)
	prices := strings.Fields(priceLine)

	// get number of days
	daysLine, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	daysLine = strings.TrimSpace(daysLine)
	q, _ := strconv.Atoi(daysLine)

	var numShops int
	for i := 0; i < q; i++ {
		numShops = 0

		// get coin limit for the day
		coinLine, err := reader.ReadString('\n')
		if err != nil && err != io.EOF {
			os.Exit(3)
		}

		coinLine = strings.TrimSpace(coinLine)
		m, _ := strconv.Atoi(coinLine)

		for _, price := range prices {
			x, _ := strconv.Atoi(price)
			if m >= x {
				numShops++
			} else {
				break
			}
		}

		fmt.Printf("%v\n", numShops)
	}
}

package main

import (
	"fmt"
	"io"
	"os"
	"bufio"
	"sort"
	"strings"
	"strconv"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	// get number of shops
	line, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	line = strings.TrimSpace(line)
	n, _ := strconv.Atoi(line)

	// get prices of bottles
	priceLine, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	priceLine = strings.TrimSpace(priceLine)
	priceStrings := strings.Fields(priceLine)
	var prices = []int{}

	for _, j := range priceStrings {
		price, _ := strconv.Atoi(j)
		prices = append(prices, price)
	}

	sort.Ints(prices)
	fmt.Printf("-- %v --\n", prices)
	// get number of days
	daysLine, err := reader.ReadString('\n')
	if err != nil && err != io.EOF {
		os.Exit(3)
	}

	daysLine = strings.TrimSpace(daysLine)
	q, _ := strconv.Atoi(daysLine)

	for i := 0; i < q; i++ {
		numShops := 0

		// get coin limit for the day
		coinLine, err := reader.ReadString('\n')
		if err != nil && err != io.EOF {
			os.Exit(3)
		}

		coinLine = strings.TrimSpace(coinLine)
		m, _ := strconv.Atoi(coinLine)

		ndx := sort.Search(n, func(i int) bool { return prices[i] >= m})
        fmt.Printf("== m: %v, ndx: %v ==\n", m, ndx)
		if ndx < n && prices[ndx] == m {
			// the ndx-th shop has the same price as the daily limit
			numShops = ndx + 1

			// continue through the array in case there is more than one shop with the same price
			ndx++
			for ndx < n && prices[ndx] == m {
				numShops++
				ndx++
			}
		} else {
			// the ndx-th shop returned is above the daily limit
            if ndx == 0 {
                numShops = 0
            } else {
                numShops = ndx + 1
            }
		}

		fmt.Printf("%v\n", numShops)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	var numOfShop int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &numOfShop)

	priceOfShop := make([]int, numOfShop)
	checkList := make([]int,100001)
	for i := 0; i < numOfShop; i++ {
		fmt.Fscan(reader, &priceOfShop[i])
		checkList[priceOfShop[i]] +=1
	}

	for i:= 1; i<=100000; i++{
		checkList[i] += checkList[i-1]
	}

	var numOfDay, coins int
	fmt.Fscan(reader, &numOfDay)
	for i := 0; i < numOfDay; i++ {
		fmt.Scan(&coins)
		if coins > len(checkList){
			fmt.Println(checkList[len(checkList)-1])
			continue
		}
		fmt.Println(checkList[coins])
	}

}

package main

import (
	"fmt"
)

func main() {
	var numOfShop int
	fmt.Scan(&numOfShop)
	checkList := make([]int,100001)
	var price int
	for i := 0; i < numOfShop; i++ {
		fmt.Scan(&price)
		checkList[price] +=1
	}

	for i := 1; i <= 100000; i++ {
		checkList[i] += checkList[i-1]
	}

	var numOfDay,coins int

	fmt.Scan(&numOfDay)
	for i := 0; i < numOfDay; i++ {
		fmt.Scanln(&coins)
		if coins >100000{
			fmt.Println(checkList[100000])
			continue
		}
		fmt.Println(checkList[coins])
	}

}

package main

import (
	"fmt"
	"sort"
)

func binarySearch(arr []int, l int, r int, x int) int {
	if arr[0] > x {
		return 0
	}
	if arr[len(arr)-1] < x || arr[len(arr)-1] == x {
		return len(arr)
	}

	for l <= r {
		mid := l + (r-l)/2
		if arr[mid] == x &&  arr[mid+1] > x {
				return mid + 1
		}else if arr[mid] < x && arr[mid+1] > x {
				return mid + 1

		} else {

			if arr[mid-1] < x {
				return mid
			}
			if arr[mid]>x{
				r = mid - 1
				continue
			}
			l = mid + 1
		}
	}
	return 0

}

func main() {
	var numOfShop int
	fmt.Scan(&numOfShop)

	priceOfShop := make([]int, numOfShop)

	for i := 0; i < numOfShop; i++ {
		fmt.Scan(&priceOfShop[i])
	}
	sort.Ints(priceOfShop)
	var numOfDay int
	fmt.Scan(&numOfDay)
	var coins int
	for i := 0; i < numOfDay; i++ {
		fmt.Scan(&coins)
		result := binarySearch(priceOfShop, 0, numOfShop-1, coins)
		fmt.Println(result)
	}

}

package main

import "fmt"

func getResult(priceOfShop []int, coint int) int {
	count := 0
	for i := 0; i < len(priceOfShop); i++ {
		if coint >= priceOfShop[i] {
			count++
			continue
		}
	}
	return count

}

func main() {
	var numOfShop int
	fmt.Scan(&numOfShop)

	priceOfShop := make([]int, numOfShop)

	for i := 0; i < numOfShop; i++ {
		fmt.Scan(&priceOfShop[i])
	}

	var numOfDay int
	fmt.Scan(&numOfDay)
	var numOfCoint int
	for i := 0; i < numOfShop; i++ {
		fmt.Scan(&numOfCoint)
		fmt.Println(getResult(priceOfShop, numOfCoint))
	}

}

package main

import (
	"fmt"
)

func main() {
	var numOfShop int64
	fmt.Scan(&numOfShop)
	checkList := make([]int64,100001)
	var price int64
	var i int64
	for i=0; i < numOfShop; i++ {
		fmt.Scan(&price)
		checkList[price] +=1
	}

	for i := 1; i <= 100000; i++ {
		checkList[i] += checkList[i-1]
	}

	var numOfDay,coins int64

	fmt.Scan(&numOfDay)
	for i = 0; i < numOfDay; i++ {
		fmt.Scanln(&coins)
		if coins >100000{
			fmt.Println(checkList[100000])
			continue
		}
		fmt.Println(checkList[coins])
	}

}

package main

import (
    "bufio"
    "fmt"
    "os"
    "sort"
    "strconv"
    "strings"
)

func main() {

    in := bufio.NewReader(os.Stdin)
    text, _ := in.ReadString('\n')
    text, _ = in.ReadString('\n')
    shopsString := strings.Split(text, " ")
    var shops []int
    for _, shopString := range shopsString {
    //    fmt.Println("A")
        shop, _ := strconv.Atoi(strings.TrimSpace(shopString))
        shops = append(shops, shop)
    }
    //fmt.Println(shops)
    sort.Ints(shops)
//    fmt.Println(shops)

    text, _ = in.ReadString('\n')
    //fmt.Printf("|%s|\n", text)
    nDays, _ := strconv.Atoi(strings.TrimSpace(text))
    //fmt.Println(nDays)
    for i := 0; i < nDays; i++ {
        text, _ = in.ReadString('\n')
        money, _ := strconv.Atoi(strings.TrimSpace(text))
        fmt.Println(solve(shops, money))
    }

}

func solve(shops []int, money int) int {
    //fmt.Println(money)
    //fmt.Println(shops[0])
    if money < shops[0] { return 0 }
    lo := 0
    hi := len(shops) - 1
    for lo < hi {
        mid := (lo + hi) / 2
    //    fmt.Printf("lo %d mid %d hi %d n %d\n", lo, mid, hi, money)
        if money >= shops[mid] {
            lo = mid + 1
        } else {
            hi = mid
        }
    }
    return lo + 1
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "sort"
    "strconv"
    "strings"
)

func main() {

    in := bufio.NewReader(os.Stdin)
    text, _ := in.ReadString('\n')
    text, _ = in.ReadString('\n')
    shopsString := strings.Split(text, " ")
    var shops []int
    for _, shopString := range shopsString {
    //    fmt.Println("A")
        shop, _ := strconv.Atoi(strings.TrimSpace(shopString))
        shops = append(shops, shop)
    }
    //fmt.Println(shops)
    sort.Ints(shops)
//    fmt.Println(shops)

    text, _ = in.ReadString('\n')
    //fmt.Printf("|%s|\n", text)
    nDays, _ := strconv.Atoi(strings.TrimSpace(text))
    //fmt.Println(nDays)
    for i := 0; i < nDays; i++ {
        text, _ = in.ReadString('\n')
        money, _ := strconv.Atoi(strings.TrimSpace(text))
        fmt.Println(solve(shops, money))
    }

}

func solve(shops []int, money int) int {

    lo := 0
    hi := len(shops) - 1

    for lo < hi {
        mid := (lo + hi) / 2
        n := shops[mid]

        //fmt.Printf("%d to %d, %d at %d, looking for %d\n", lo, hi, n, mid, money)

        if n > money {
            hi = mid - 1
        } else {
            if mid + 1 == len(shops) {
                return len(shops)
            }

            if shops[mid + 1] > money {
                return mid + 1
            } else {
                lo = mid + 1
            }
        }
    }
    return lo + 1
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "sort"
    "strconv"
    "strings"
)

func main() {

    in := bufio.NewReader(os.Stdin)
    text, _ := in.ReadString('\n')
    text, _ = in.ReadString('\n')
    shopsString := strings.Split(text, " ")
    var shops []int
    for _, shopString := range shopsString {
    //    fmt.Println("A")
        shop, _ := strconv.Atoi(strings.TrimSpace(shopString))
        shops = append(shops, shop)
    }
    //fmt.Println(shops)
    sort.Ints(shops)
//    fmt.Println(shops)

    text, _ = in.ReadString('\n')
    //fmt.Printf("|%s|\n", text)
    nDays, _ := strconv.Atoi(strings.TrimSpace(text))
    //fmt.Println(nDays)
    for i := 0; i < nDays; i++ {
        text, _ = in.ReadString('\n')
        money, _ := strconv.Atoi(strings.TrimSpace(text))
        fmt.Println(solve(shops, money))
    }

}

func solve(shops []int, money int) int {
    //fmt.Println(money)
    //fmt.Println(shops[0])
    if money < shops[0] { return 0 }
    lo := 0
    hi := len(shops) - 1
    for lo < hi {
        mid := (lo + hi) / 2
    //    fmt.Printf("lo %d mid %d hi %d n %d\n", lo, mid, hi, money)
        if money > shops[mid] {
            lo = mid + 1
        } else {
            hi = mid
        }
    }
    return lo + 1
}

package main

import (
    "bufio"
    "fmt"
    "os"
    "sort"
    "strconv"
    "strings"
)

func main() {

    in := bufio.NewReader(os.Stdin)
    text, _ := in.ReadString('\n')
    text, _ = in.ReadString('\n')
    shopsString := strings.Split(text, " ")
    var shops []int
    for _, shopString := range shopsString {
    //    fmt.Println("A")
        shop, _ := strconv.Atoi(strings.TrimSpace(shopString))
        shops = append(shops, shop)
    }
    //fmt.Println(shops)
    sort.Ints(shops)
//    fmt.Println(shops)

    text, _ = in.ReadString('\n')
    //fmt.Printf("|%s|\n", text)
    nDays, _ := strconv.Atoi(strings.TrimSpace(text))
    //fmt.Println(nDays)
    for i := 0; i < nDays; i++ {
        text, _ = in.ReadString('\n')
        money, _ := strconv.Atoi(strings.TrimSpace(text))
        fmt.Println(solve(shops, money))
    }

}

func solve(shops []int, money int) int {
    //fmt.Println(money)
    //fmt.Println(shops[0])
    if money < shops[0] { return 0 }
    lo := 0
    hi := len(shops) - 1
    for lo < hi {
        mid := (lo + hi) / 2
    //    fmt.Printf("lo %d mid %d hi %d n %d\n", lo, mid, hi, money)
        if money > shops[mid] {
            lo = mid + 1
        } else if money == shops[mid] {
            if mid + 1 == len(shops) {
                lo = mid
                hi = mid
                break
            }
            if shops[mid + 1] <= money {
                lo = mid + 1
            } else {
                lo = mid
                hi = mid
            }
        } else {
            hi = mid
        }
    }
    return lo + 1
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n int

	fmt.Fscan(reader, &n)

	stores := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &stores[i])
	}

	sort.Ints(stores)
	var qr int
	fmt.Fscan(reader, &qr)

	fmt.Println(stores)
	for i := 0; i < qr; i++ {
		var q int
		fmt.Fscan(reader, &q)

		found := false
		l, r := 0, n
		var pos int
		for l < r {
			mid := (l + r) / 2

			if stores[mid] > q {
				r = mid
			} else if stores[mid] <= q {
				l, pos, found = mid+1, mid, true
			}
		}

		if found {
			fmt.Println(pos + 1)
		} else {
			fmt.Println(0)
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const MAX_AMOUNT = 100000

func main() {
	reader := bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscan(reader, &n)

	dp := make(map[int]int)

	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(reader, &x)

		dp[x]++
	}

	for i := 1; i <= MAX_AMOUNT; i++ {
		dp[i] += dp[i-1]
	}

	var qr int
	fmt.Fscan(reader, &qr)

	for qr > 0 {
		var x int
		fmt.Fscan(reader, &x)

		fmt.Println(dp[x])
		qr--
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, q int
	fmt.Scan(&n)
	maxx := 100000

	x := make([]int, maxx + 1)

	for k := 0; k < n; k++ {
		var l int
		fmt.Scan(&l)
		x[l]++
	}

	for i := 1; i < maxx; i++ {
		x[i] += x[i - 1]
	}
	sort.Ints(x)
	fmt.Scan(&q)

	for i := 0; i < q; i++ {
		var m int
		fmt.Scan(&m)
		if m > maxx {
			m = maxx
		}
		fmt.Println(x[m])
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader
)

func swap(a, b *int) {
	var tmp int
	tmp = *a
	*a = *b
	*b = tmp
}

func sort(a []int) []int {
	for i := range a {
		for j := i; j < len(a)-1; j++ {
			if a[i] > a[j] {
				swap(&a[i], &a[j])
			}

		}
	}
	return a
}

func findPos(a []int, x, l, r int) (pos int) {
	for l < r {
		m := (l + r) / 2
		if x >= a[m] {
			l = m + 1
		} else {
			r = m
		}
	}
	pos = l
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	x = sort(x)

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader
)

func swap(a, b *int) {
	var tmp int
	tmp = *a
	*a = *b
	*b = tmp
}

func sort(a []int) []int {
	for i := range a {
		for j := i; j < len(a); j++ {
			if a[i] > a[j] {
				swap(&a[i], &a[j])
			}

		}
	}
	return a
}

func findPos(a []int, x, l, r int) (pos int) {
	for l != r {

		m := (l + r) / 2
		if a[m] < x {
			l = m + 1
		} else {
			r = m
		}
	}

	if l == len(a) {
		pos = l
	} else if a[l] > x {
		pos = l
	} else {
		pos = l + 1
	}
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	x = sort(x)

	fmt.Println(x)

	findPos(x, 1, 0, len(x))

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader
)

func swap(a, b *int) {
	var tmp int
	tmp = *a
	*a = *b
	*b = tmp
}

func sort(a []int) []int {
	for i := range a {
		for j := i; j < len(a)-1; j++ {
			if a[i] > a[j] {
				swap(&a[i], &a[j])
			}

		}
	}
	return a
}

func findPos(a []int, x, l, r int) (pos int) {
	for l != r {

		m := (l + r) / 2
		if a[m] < x {
			l = m + 1
		} else {
			r = m
		}
	}

	if l == 0 && a[0] > x {
		pos = 0
	} else {
		pos = l + 1
	}
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	x = sort(x)

	findPos(x, 1, 0, len(x))

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader
)

func swap(a, b *int) {
	var tmp int
	tmp = *a
	*a = *b
	*b = tmp
}

func sort(a []int) []int {
	for i := range a {
		for j := i; j < len(a)-1; j++ {
			if a[i] > a[j] {
				swap(&a[i], &a[j])
			}

		}
	}
	return a
}

func findPos(a []int, x, l, r int) (pos int) {
	for l != r {

		m := (l + r) / 2
		if a[m] < x {
			l = m + 1
		} else {
			r = m
		}
	}

	if l == 0 && a[0] > x {
		pos = 0
	} else if l < len(a) && a[l] == x {
		pos = l + 1
	} else {
		pos = l
	}
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	x = sort(x)

	findPos(x, 1, 0, len(x))

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader
)

func swap(a, b *int) {
	var tmp int
	tmp = *a
	*a = *b
	*b = tmp
}

func sort(a []int) []int {
	for i := range a {
		for j := i; j < len(a); j++ {
			if a[i] > a[j] {
				swap(&a[i], &a[j])
			}

		}
	}
	return a
}

func findPos(a []int, x, l, r int) (pos int) {
	for l != r {

		m := (l + r) / 2
		if a[m] < x {
			l = m + 1
		} else {
			r = m
		}
	}

	if l == len(a) {
		pos = l
	} else if a[l] > x {
		pos = l
	} else {
		pos = l + 1
	}
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	x = sort(x)

	findPos(x, 1, 0, len(x))

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader
)

func swap(a, b *int) {
	var tmp int
	tmp = *a
	*a = *b
	*b = tmp
}

func sort(a []int) []int {
	for i := range a {
		for j := i; j < len(a)-1; j++ {
			if a[i] > a[j] {
				swap(&a[i], &a[j])
			}

		}
	}
	return a
}

func findPos(a []int, x, l, r int) (pos int) {
	for l != r {

		m := (l + r) / 2
		if a[m] < x {
			l = m + 1
		} else {
			r = m
		}
	}

	if l == len(a) {
		pos = l
	} else if a[l] > x {
		pos = l
	} else {
		pos = l + 1
	}
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	x = sort(x)

	findPos(x, 1, 0, len(x))

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var (
	reader *bufio.Reader
)

func findPos(a []int, x, l, r int) (pos int) {
	for l < r {
		m := l/2 + r/2
		if a[m] <= x {
			l = m + 1
			pos = l
		} else {
			r = m - 1
		}
	}
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	sort.Ints(x)

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	reader *bufio.Reader
)

func swap(a, b *int) {
	var tmp int
	tmp = *a
	*a = *b
	*b = tmp
}

func sort(a []int) []int {
	for i := range a {
		for j := i; j < len(a)-1; j++ {
			if a[i] > a[j] {
				swap(&a[i], &a[j])
			}

		}
	}
	return a
}

func findPos(a []int, x, l, r int) (pos int) {
	for l < r {
		m := (l + r) / 2

		if a[m] == x {
			pos = m
			break
		} else if a[m] < x {
			l = m + 1
			pos = l
		} else {
			r = m - 1
			pos = r
		}
	}
	pos++
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	x = sort(x)

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

var (
	reader *bufio.Reader
)

func findPos(a []int, x, l, r int) (pos int) {
	for l < r {
		m := l/2 + r/2
		if a[m] < x {
			l = m + 1
		} else {
			r = m
		}
	}

	if l == len(a) {
		pos = l
	} else if a[l] > x {
		pos = l
	} else {
		pos = l + 1
	}
	return
}

func main() {

	reader = bufio.NewReader(os.Stdin)

	var n, q, tmp int
	var x []int

	fmt.Fscan(reader, &n)
	x = make([]int, n)
	for i := range x {
		fmt.Fscan(reader, &x[i])
	}

	sort.Ints(x)

	fmt.Fscan(reader, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &tmp)
		fmt.Println(findPos(x, tmp, 0, len(x)))
	}
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

func scanString() string {
	scanner.Scan()
	return scanner.Text()
}

func scanInt64() int64 {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v
}

func scanInt() int {
	scanner.Scan()
	v, _ := strconv.Atoi(scanner.Text())
	return v
}

func scanInts(n int) []int {
	l := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.Atoi(scanner.Text())
	}

	return l
}

func scanInts64(n int64) []int64 {
	l := make([]int64, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}

	return l
}

func scanBool() bool {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v == 1
}

func scanBools(n int64) []bool {
	l := make([]bool, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		l[i] = v == 1
	}

	return l
}

func main() {
	n, m, l := scanInt64(), scanInt64(), scanInt64()
	sizes := scanInts64(n)

	intervals := int64(0)

	for i := int64(0); i < n; i++ {
		if i == 0 && sizes[i] > l {
			intervals++
			continue
		}

		if sizes[i] <= l {
			continue
		}

		if sizes[i-1] <= l {
			intervals++
		}
	}

	for i := int64(0); i < m; i++ {
		action := scanInt64()
		if action == 0 {
			fmt.Println(intervals)
			continue
		}

		pos, d := scanInt64()-1, scanInt64()

		oldSize := sizes[pos]

		sizes[pos] += d

		if sizes[pos] <= l || (oldSize > l && sizes[pos] > l) {
			continue
		}

		if len(sizes) == 1 {
			if sizes[pos] > l {
				intervals++
			}

			continue
		}

		if pos == 0 {
			if sizes[pos+1] <= l {
				intervals++
			}

			continue
		}

		if pos == n-1 {
			if sizes[pos-1] <= l {
				intervals++
			}

			continue
		}

		if sizes[pos-1] > l || sizes[pos+1] > l {
			if sizes[pos-1] > l && sizes[pos+1] > l {
				intervals--
				continue
			}

			continue
		}

		intervals++
	}
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}

	return -a
}

func min(a, b int64) int64 {
	if a < b {
		return a
	}

	return b
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()

	var n, m int
	var l int64
	// bt, _, _ := reader.ReadLine()
	// str := string(bt)
	// strs := strings.Split(str, " ")
	// n, _ = strconv.Atoi(strs[0])
	// m, _ = strconv.Atoi(strs[1])
	// ll, _ := strconv.Atoi(strs[2])
	// l = int64(ll)
	scanf("%d %d %d\n", &n, &m, &l)
	//fmt.Println(n, m, l)

	arr := make([]int64, n)

	ans := 0
	last := false

	// bt, _, _ = reader.ReadLine()
	// str = string(bt)
	// strs = strings.Split(str, " ")

	for i := 0; i < n; i++ {
		//ll, _ = strconv.Atoi(strs[i])
		//arr[i] = int64(ll)
		scanf("%d", &arr[i])
		//fmt.Scan(&arr[i])
		if arr[i] > l {
			if last == false {
				ans++
			}
			last = true
		} else {
			last = false
		}
	}
	scanf("\n")
	//fmt.Scanln()

	for t := 0; t < m; t++ {
		var p int
		var str string
		var d int64
		//scanf("%d\n", &t1)
		bt, _, _ := reader.ReadLine()
		//scanf("\n")
		str = string(bt)
		strs := strings.Split(str, " ")
		//fmt.Scan(&t1)
		if len(strs) == 1 {
			printf("%d\n", ans)
			//scanf("\n")
			//fmt.Println("Hic 0 ", t1)
			//fmt.Scanln()
		} else {
			pp, _ := strconv.Atoi(strs[1])
			dd, _ := strconv.Atoi(strs[2])
			p = pp
			d = int64(dd)
			//fmt.Println("hic 1 ", 1, p, d)
			//fmt.Scan(&p, &d)
			p--
			if arr[p] > l {
				continue
			}

			arr[p] += d

			if arr[p] > l {
				if p > 0 && arr[p-1] > l && p < n-1 && arr[p+1] > l {
					ans--
				}
				if p > 0 && arr[p-1] > l {
					continue
				}
				if p < n-1 && arr[p+1] > l {
					continue
				}
				ans++
			}
		}
	}

}


package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = (2 * node) + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	if M[l] > M[r] {
		M[node] = M[l]
	} else {
		M[node] = M[r]
	}

	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = (2 * node) + 1
	var sum = 0
	sum += solve(l, level-1, M[l]-A[l]) + (lit - M[l])
	sum += solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d\n", &n)
	p = (1 << uint(n+1)) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}

package main

import (
  "os"
  "bufio"
  "strconv"
  "fmt"
)

var scanner *bufio.Scanner
var writer *bufio.Writer

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Node struct {
  Id, Value, MinCost int
  Parent, Left, Right *Node
}

func buildTree(maxDepth, depth, id int, parent *Node) *Node {
  node := &Node{ Id: id, Parent: parent }
  if depth < maxDepth {
    node.Left = buildTree(maxDepth, depth+1, 2*id, node)
    node.Right = buildTree(maxDepth, depth+1, 2*id+1, node)
  }
  return node
}

var values []int
var maxValue int

func setValue(node *Node, value int) {
  node.Value = value
  if value > maxValue {
    maxValue = value
  }
  if node.Left != nil {
    setValue(node.Left, value + values[2*node.Id-2])
    setValue(node.Right, value + values[2*node.Id-1])
  }
}

func setMinCost(node *Node) int {
  if node.Left == nil {
    node.MinCost = maxValue - node.Value
  } else {
    left, right := setMinCost(node.Left), setMinCost(node.Right)
    if left < right {
      node.MinCost = left
    } else {
      node.MinCost = right
    }
  }
  //writer.WriteString(fmt.Sprintf("%d: %d\n", node.Id, node.MinCost))
  return node.MinCost
}

func getResult(node *Node, value int) int {
  cost := node.MinCost - value
  if node.Left == nil {
    return cost
  }
  left := getResult(node.Left, value + cost)
  right := getResult(node.Right, value + cost)
  return cost + left + right
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  h := getI()
  children := 1
  for i := 0; i <= h; i++ {
    children *= 2
  }
  values = make([]int, children-2)
  for i := range values {
    values[i] = getI()
  }
  tree := buildTree(h, 0, 1, nil)
  setValue(tree, 0)
  setMinCost(tree)

  result := getResult(tree, 0)
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	if M[l] > M[r] {
		M[node] = M[l]
	} else {
		M[node] = M[r]
	}

	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	var sum = 0
	sum += solve(l, level-1, M[l]-A[l]) + (lit - M[l])
	sum += solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = 1<<uint(n+1) - 1
	for i := 0; i <= p; i++ {
		A[i] = 0
		M[i] = 0
	}

	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	M[node] = max(M[l], M[r])
	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	var sum = solve(l, level-1, M[l]-A[l]) + (lit - M[l]) +
		solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = 1<<uint(n+1) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	if M[l] > M[r] {
		M[node] = M[l]
	} else {
		M[node] = M[r]
	}

	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	var sum = 0
	sum += solve(l, level-1, M[l]-A[l]) + (lit - M[l])
	sum += solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = 1<<uint(n+1) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}

package main

import (
	"fmt"
)

const MaxN = 4096

var A [MaxN]int
var M [MaxN]int

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func computeMaximums(node, level int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	M[l] = A[l] + computeMaximums(l, level-1)
	M[r] = A[r] + computeMaximums(r, level-1)
	M[node] = max(M[l], M[r])
	return M[node]
}

func solve(node, level, lit int) int {
	if level == 0 {
		return 0
	}
	var l = 2 * node
	var r = 2*node + 1
	var sum = solve(l, level-1, M[l]-A[l]) + (lit - M[l]) +
		solve(r, level-1, M[r]-A[r]) + (lit - M[r])
	return sum
}

func main() {
	var n, p int
	_, _ = fmt.Scanf("%d", &n)
	p = 1<<uint(n+1) - 1
	for i := 2; i <= p; i++ {
		_, _ = fmt.Scanf("%d", &A[i])
	}

	var maxLit = computeMaximums(1, n)
	var ans = solve(1, n, maxLit)
	fmt.Printf("%d\n", ans)
}