When you play the game of thrones, you win, or you die. There is no middle ground.Cersei Lannister, A Game of Thrones by George R. R. MartinThere are $$$n$$$ nobles, numbered from $$$1$$$ to $$$n$$$. Noble $$$i$$$ has a power of $$$i$$$. There are also $$$m$$$ "friendships". A friendship between nobles $$$a$$$ and $$$b$$$ is always mutual.A noble is defined to be vulnerable if both of the following conditions are satisfied:   the noble has at least one friend, and  all of that noble's friends have a higher power. You will have to process the following three types of queries.   Add a friendship between nobles $$$u$$$ and $$$v$$$.  Remove a friendship between nobles $$$u$$$ and $$$v$$$.  Calculate the answer to the following process. The process: all vulnerable nobles are simultaneously killed, and all their friendships end. Then, it is possible that new nobles become vulnerable. The process repeats itself until no nobles are vulnerable. It can be proven that the process will end in finite time. After the process is complete, you need to calculate the number of remaining nobles.Note that the results of the process are not carried over between queries, that is, every process starts with all nobles being alive!

The first line contains the integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2\cdot 10^5$$$, $$$0 \le m \le 2\cdot 10^5$$$) — the number of nobles and number of original friendships respectively. The next $$$m$$$ lines each contain the integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$, $$$u \ne v$$$), describing a friendship. No friendship is listed twice. The next line contains the integer $$$q$$$ ($$$1 \le q \le 2\cdot {10}^{5}$$$) — the number of queries.  The next $$$q$$$ lines contain the queries themselves, each query has one of the following three formats.    $$$1$$$ $$$u$$$ $$$v$$$ ($$$1 \le u,v \le n$$$, $$$u \ne v$$$) — add a friendship between $$$u$$$ and $$$v$$$. It is guaranteed that $$$u$$$ and $$$v$$$ are not friends at this moment.  $$$2$$$ $$$u$$$ $$$v$$$ ($$$1 \le u,v \le n$$$, $$$u \ne v$$$) — remove a friendship between $$$u$$$ and $$$v$$$. It is guaranteed that $$$u$$$ and $$$v$$$ are friends at this moment.  $$$3$$$ — print the answer to the process described in the statement.

For each type $$$3$$$ query print one integer to a new line. It is guaranteed that there will be at least one type $$$3$$$ query.

NoteConsider the first example. In the first type 3 query, we have the diagram below.In the first round of the process, noble $$$1$$$ is weaker than all of his friends ($$$2$$$ and $$$3$$$), and is thus killed. No other noble is vulnerable in round 1. In round 2, noble $$$3$$$ is weaker than his only friend, noble $$$4$$$, and is therefore killed. At this point, the process ends, and the answer is $$$2$$$.  In the second type 3 query, the only surviving noble is $$$4$$$.    The second example consists of only one type $$$3$$$ query. In the first round, two nobles are killed, and in the second round, one noble is killed. The final answer is $$$1$$$, since only one noble survives.

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"
	"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"
	"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++
				}
			}
		}

	}
}


Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school which has k pupils. Santa decided to treat them with tangerines.However, there can be too few tangerines to present at least one tangerine to each pupil. So Santa decided to divide tangerines into parts so that no one will be offended. In order to do this, he can divide a tangerine or any existing part into two smaller equal parts. If the number of slices in the part he wants to split is odd, then one of the resulting parts will have one slice more than the other. It's forbidden to divide a part consisting of only one slice.Santa Claus wants to present to everyone either a whole tangerine or exactly one part of it (that also means that everyone must get a positive number of slices). One or several tangerines or their parts may stay with Santa.Let bi be the number of slices the i-th pupil has in the end. Let Santa's joy be the minimum among all bi's.Your task is to find the maximum possible joy Santa can have after he treats everyone with tangerines (or their parts).

The first line contains two positive integers n and k (1 ≤ n ≤ 106, 1 ≤ k ≤ 2·109) denoting the number of tangerines and the number of pupils, respectively. The second line consists of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 107), where ai stands for the number of slices the i-th tangerine consists of.

If there's no way to present a tangerine or a part of tangerine to everyone, print -1. Otherwise, print the maximum possible joy that Santa can have.

NoteIn the first example Santa should divide the second tangerine into two parts with 5 and 4 slices. After that he can present the part with 5 slices to the first pupil and the whole first tangerine (with 5 slices, too) to the second pupil.In the second example Santa should divide both tangerines, so that he'll be able to present two parts with 6 slices and two parts with 7 slices.In the third example Santa Claus can't present 2 slices to 3 pupils in such a way that everyone will have anything.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

const MAX = 20000010

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

	var n, k int64

	fmt.Fscanf(r, "%v %v\n", &n, &k)

	a := make([]int64, MAX)

	var t, sum, max int64

	for i := int64(1); i < n; i++ {

		fmt.Fscanf(r, "%v ", &t)
		a[t]++
		sum += t
		if t > max {
			max = t
		}
	}
	fmt.Fscanf(r, "%v\n", &t)
	a[t]++
	sum += t
	if t > max {
		max = t
	}

	if sum < k {
		fmt.Printf("%v\n", -1)
		return
	}

	var ans int64

	for i := max; i >= 1; i-- {
		ans += a[i]
		ans = ans - a[i*2+1]
		ans = ans - a[i*2]

		if i > 1 {
			ans = ans - a[i*2-1]
		}

		//		fmt.Printf("ans = %v\n", ans)

		if ans >= k {
			fmt.Printf("%v\n", i)
			return
		}
		ans += a[i*2-1]
		a[i/2] += a[i]
		a[i-i/2] += a[i]
	}

}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

var a []int64
var k int64

func judge(n int, x int64) bool {

	if x == int64(0) {
		return false
	}

	cnt := int64(0)

	for i := 1; i <= n; i++ {
		cnt += a[i] / x
	}

	return cnt >= k

}

func main() {

	var n int

	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

	fmt.Fscanf(r, "%v %v\n", &n, &k)
	//fmt.Printf("%v %v\n", n, k)

	a = make([]int64, n+1)

	var sum int64

	for i := 1; i < n; i++ {
		fmt.Fscanf(r, "%d ", &a[i])
		sum += a[i]
	}
	fmt.Fscanf(r, "%d\n", &a[n])
	sum += a[n]

	left, right := int64(0), sum

	for left < right {
		mid := (left + right + 1) / int64(2)

		if judge(n, mid) {
			left = mid
		} else {
			right = mid - 1
		}
	}

	if left == int64(0) {
		fmt.Printf("%v\n", -1)
	} else {
		fmt.Printf("%v\n", left)
	}

}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

const MAX = 20000010

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

	var n, k int64

	fmt.Fscanf(r, "%v %v\n", &n, &k)

	a := make([]int64, MAX)

	var t, sum, max int64

	for i := int64(1); i < n; i++ {

		fmt.Fscanf(r, "%v ", &t)
		a[t]++
		sum += t
		if t > max {
			max = t
		}
	}
	fmt.Fscanf(r, "%v\n", &t)
	a[t]++
	sum += t
	if t > max {
		max = t
	}

	if sum < k {
		fmt.Printf("%v\n", -1)
		return
	}

	var ans int64

	for i := max; i >= 1; i-- {
		ans += a[i]
		ans = ans - a[i*2+1]
		ans = ans - a[i*2-1]
		ans = ans - a[i*2]

		//	fmt.Printf("ans = %v\n", ans)

		if ans >= k {
			fmt.Printf("%v\n", i)
			return
		}
		ans += a[i*2-1]
		a[i/2] += a[i]
		a[i-i/2] += a[i]
	}

}


The term of this problem is the same as the previous one, the only exception — increased restrictions.

The first line contains two positive integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 109) — the number of ingredients and the number of grams of the magic powder. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, needed to bake one cookie. The third line contains the sequence b1, b2, ..., bn (1 ≤ bi ≤ 109), where the i-th number is equal to the number of grams of the i-th ingredient, which Apollinaria has.

Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder.

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.
// 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"
	"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.
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)
}


Dima has a hamsters farm. Soon N hamsters will grow up on it and Dima will sell them in a city nearby.Hamsters should be transported in boxes. If some box is not completely full, the hamsters in it are bored, that's why each box should be completely full with hamsters.Dima can buy boxes at a factory. The factory produces boxes of K kinds, boxes of the i-th kind can contain in themselves ai hamsters. Dima can buy any amount of boxes, but he should buy boxes of only one kind to get a wholesale discount.Of course, Dima would buy boxes in such a way that each box can be completely filled with hamsters and transported to the city. If there is no place for some hamsters, Dima will leave them on the farm.Find out how many boxes and of which type should Dima buy to transport maximum number of hamsters.

The first line contains two integers N and K (0 ≤ N ≤ 1018, 1 ≤ K ≤ 105) — the number of hamsters that will grow up on Dima's farm and the number of types of boxes that the factory produces. The second line contains K integers a1, a2, ..., aK (1 ≤ ai ≤ 1018 for all i) — the capacities of boxes.

Output two integers: the type of boxes that Dima should buy and the number of boxes of that type Dima should buy. Types of boxes are numbered from 1 to K in the order they are given in input. If there are many correct answers, output any of them.

package main

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

func solve() {
	n := readInt64()
	k := readInt()
	a := readInt64Array(k)

	best := -1
	bestR := int64(0)
	for i := 0; i < k; i++ {
		c := n / a[i]
		r := n - c*a[i]
		if best == -1 || r < bestR {
			best = i
			bestR = r
		}
	}
	if best == -1 {
		fmt.Println("0 1")
	} else {
		fmt.Println(best+1, n/a[best])
	}

}

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

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}


Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins.Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent mi coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains n integers xi (1 ≤ xi ≤ 100 000) — prices of the bottles of the drink in the i-th shop. The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink. Then follow q lines each containing one integer mi (1 ≤ mi ≤ 109) — the number of coins Vasiliy can spent on the i-th day.

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

NoteOn the first day, Vasiliy won't be able to buy a drink in any of the shops.On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.On the third day, Vasiliy can buy a drink only in the shop number 1.Finally, on the last day Vasiliy can buy a drink in any shop.

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"
)

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"
	"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 (
	"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 (
    	"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"
)
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"
	"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 (
    "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"
	"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"
)

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 (
	"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)))
	}
}


This is an easier version of the problem E with smaller constraints.Twilight Sparkle has received a new task from Princess Celestia. This time she asked to decipher the ancient scroll containing important knowledge of pony origin.To hide the crucial information from evil eyes, pony elders cast a spell on the scroll. That spell adds exactly one letter in any place to each word it is cast on. To make the path to the knowledge more tangled elders chose some of words in the scroll and cast a spell on them.Twilight Sparkle knows that the elders admired the order in all things so the scroll original scroll contained words in lexicographically non-decreasing order. She is asked to delete one letter from some of the words of the scroll (to undo the spell) to get some version of the original scroll. Unfortunately, there may be more than one way to recover the ancient scroll. To not let the important knowledge slip by Twilight has to look through all variants of the original scroll and find the required one. To estimate the maximum time Twilight may spend on the work she needs to know the number of variants she has to look through. She asks you to find that number! Since that number can be very big, Twilight asks you to find it modulo $$$10^9+7$$$.It may occur that princess Celestia has sent a wrong scroll so the answer may not exist.A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 1000$$$): the number of words in the scroll.  The $$$i$$$-th of the next $$$n$$$ lines contains a string consisting of lowercase English letters: the $$$i$$$-th word in the scroll. The length of each word is more or equal than $$$1$$$. The sum of lengths of words does not exceed $$$20000$$$.

Print one integer: the number of ways to get a version of the original from the scroll modulo $$$10^9+7$$$.

6
lapochka
kartyshka
bigbabytape
morgenshtern
ssshhhiiittt
queen

NoteNotice that the elders could have written an empty word (but they surely cast a spell on it so it holds a length $$$1$$$ now).

package main

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

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

	n := readNum(reader)
	S := make([]string, n)

	for i := 0; i < n; i++ {
		s, _ := reader.ReadBytes('\n')
		var j int
		for j < len(s) {
			if s[j] < 'a' || s[j] > 'z' {
				break
			}
			j++
		}
		S[i] = string(s[:j])
	}
	fmt.Println(solve(n, S))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var MOD = [...]int64{1000000007, 1000000009}

const MAX_C = 1000010

var P [2]int64
var R [2]int64

var p [2][MAX_C]int64

var nxt [MAX_C]int

var A [MAX_C]int

var dp [2][MAX_C]int64

func init() {
	P[0] = 29
	P[1] = 31
	R[0] = pow(P[0], MOD[0]-2, MOD[0])
	R[1] = pow(P[1], MOD[1]-2, MOD[1])
	for j := 0; j < 2; j++ {
		p[j][0] = 1
		for i := 1; i < MAX_C; i++ {
			p[j][i] = (P[j] * p[j][i-1]) % MOD[j]
		}
	}
}

func pow(a, b, mod int64) int64 {
	var res int64 = 1
	for b > 0 {
		if b&1 == 1 {
			res = (res * a) % mod
		}
		a = (a * a) % mod
		b >>= 1
	}
	return res
}

func solve(n int, S []string) int {
	H := make([][][]int64, n)
	sorted := make([][]int, n)
	for i := 0; i < n; i++ {
		H[i] = make([][]int64, 2)
		for j := 0; j < 2; j++ {
			H[i][j] = make([]int64, 0, len(S[i])+1)
			H[i][j] = append(H[i][j], 0)
			for pos := 0; pos < len(S[i]); pos++ {
				H[i][j] = append(H[i][j], (H[i][j][pos]+p[j][pos]*int64(S[i][pos]-'a'+1))%MOD[j])
			}
		}

		nxt[len(S[i])-1] = len(S[i]) - 1

		for pos := len(S[i]) - 2; pos >= 0; pos-- {
			if S[i][pos] != S[i][pos+1] {
				nxt[pos] = pos + 1
			} else {
				nxt[pos] = nxt[pos+1]
			}
		}
		var l, r = 0, len(S[i]) - 1
		for pos := 0; pos < len(S[i]); pos++ {
			if S[i][nxt[pos]] <= S[i][pos] {
				A[l] = pos
				l++
			} else {
				A[r] = pos
				r--
			}
		}
		sorted[i] = make([]int, 0, len(S[i])+1)
		for j := 0; j < len(S[i]); j++ {
			sorted[i] = append(sorted[i], A[j])
			if A[j] == len(S[i])-1 {
				sorted[i] = append(sorted[i], len(S[i]))
			}
		}
	}

	for i := 0; i <= len(S[0]); i++ {
		dp[0][i] = 1
	}

	var getHash func(t int, i int, x int, l int) int64

	getHash = func(t int, i int, x int, l int) int64 {
		if l <= x {
			return H[i][t][l]
		}
		res1 := H[i][t][x]
		res2 := (H[i][t][l+1] - H[i][t][x+1] + MOD[t]) % MOD[t]
		res2 *= R[t]
		res2 %= MOD[t]

		return (res1 + res2) % MOD[t]
	}

	getHashPair := func(i, x, l int) Pair {
		first := getHash(0, i, x, l)
		second := getHash(1, i, x, l)
		return Pair{first, second}
	}

	var getAt func(i, x, l int) byte

	getAt = func(i, x, l int) byte {
		if l < x {
			return S[i][l]
		}
		if l+1 < len(S[i]) {
			return S[i][l+1]
		}
		return ' '
	}

	check := func(i int, x int, j int, y int) bool {
		len1 := len(S[i])
		len2 := len(S[j])
		if x != len1 {
			len1--
		}
		if y != len2 {
			len2--
		}
		var left, right = 0, min(len1, len2) + 1
		for right-left > 1 {
			mid := (left + right) / 2
			if getHashPair(i, x, mid) == getHashPair(j, y, mid) {
				left = mid
			} else {
				right = mid
			}
		}

		return getAt(i, x, left) >= getAt(j, y, left)
	}

	for i := 1; i < n; i++ {
		oks := i % 2
		var ptr int
		var sum int64
		for k := 0; k < len(sorted[i]); k++ {
			for ptr < len(sorted[i-1]) && check(i, sorted[i][k], i-1, sorted[i-1][ptr]) {
				sum += dp[oks^1][ptr]
				if sum >= MOD[0] {
					sum -= MOD[0]
				}
				ptr++
			}
			dp[oks][k] = sum
		}
	}

	var ans int64

	for i := 0; i <= len(S[n-1]); i++ {
		ans += dp[(n-1)%2][i]
		if ans >= MOD[0] {
			ans -= MOD[0]
		}
	}
	return int(ans)
}

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

type Pair struct {
	first, second int64
}

package main

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

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

	n := readNum(reader)
	S := make([]string, n)

	for i := 0; i < n; i++ {
		s, _ := reader.ReadBytes('\n')
		var j int
		for j < len(s) {
			if s[j] < 'a' || s[j] > 'z' {
				break
			}
			j++
		}
		S[i] = string(s[:j])
	}
	fmt.Println(solve(n, S))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var MOD = [...]int64{1000000007, 1000000009}

const MAX_C = 1000010

var P [2]int64
var R [2]int64

var p [2][MAX_C]int64

var nxt [MAX_C]int

var A [MAX_C]int

var dp [2][MAX_C]int64

func init() {
	P[0] = 29
	P[1] = 31
	R[0] = pow(P[0], MOD[0]-2, MOD[0])
	R[1] = pow(P[1], MOD[1]-2, MOD[1])
	for j := 0; j < 2; j++ {
		p[j][0] = 1
		for i := 1; i < MAX_C; i++ {
			p[j][i] = (P[j] * p[j][i-1]) % MOD[j]
		}
	}
}

func pow(a, b, mod int64) int64 {
	var res int64 = 1
	for b > 0 {
		if b&1 == 1 {
			res = (res * a) % mod
		}
		a = (a * a) % mod
		b >>= 1
	}
	return res
}

func solve(n int, S []string) int {
	H := make([][][]int64, n)
	sorted := make([][]int, n)
	for i := 0; i < n; i++ {
		H[i] = make([][]int64, 2)
		for j := 0; j < 2; j++ {
			H[i][j] = make([]int64, 0, len(S[i])+1)
			H[i][j] = append(H[i][j], 0)
			for pos := 0; pos < len(S[i]); pos++ {
				H[i][j] = append(H[i][j], (H[i][j][pos]+p[j][pos]*int64(S[i][pos]-'a'+1))%MOD[j])
			}
		}

		nxt[len(S[i])-1] = len(S[i]) - 1

		for pos := len(S[i]) - 2; pos >= 0; pos-- {
			if S[i][pos] != S[i][pos+1] {
				nxt[pos] = pos + 1
			} else {
				nxt[pos] = nxt[pos+1]
			}
		}
		var l, r = 0, len(S[i]) - 1
		for pos := 0; pos < len(S[i]); pos++ {
			if S[i][nxt[pos]] <= S[i][pos] {
				A[l] = pos
				l++
			} else {
				A[r] = pos
				r--
			}
		}
		sorted[i] = make([]int, 0, len(S[i])+1)
		for j := 0; j < len(S[i]); j++ {
			sorted[i] = append(sorted[i], A[j])
			if A[j] == len(S[i])-1 {
				sorted[i] = append(sorted[i], len(S[i]))
			}
		}
	}

	for i := 0; i <= len(S[0]); i++ {
		dp[0][i] = 1
	}

	var getHash func(t int, i int, x int, l int) int64

	getHash = func(t int, i int, x int, l int) int64 {
		if l < x {
			return H[i][t][l]
		}
		if l+1 >= len(H[i][t]) {
			l = len(H[i][t]) - 2
		}
		if x+1 >= len(H[i][t]) {
			x = len(H[i][t]) - 2
		}
		res1 := H[i][t][x]
		res2 := H[i][t][l+1] - H[i][t][x+1] + MOD[t]
		res2 %= MOD[t]
		res2 *= R[t]
		res2 %= MOD[t]

		return (res1 + res2) % MOD[t]
	}

	getHashPair := func(i, x, l int) Pair {
		first := getHash(0, i, x, l)
		second := getHash(1, i, x, l)
		return Pair{first, second}
	}

	var getAt func(i, x, l int) byte

	getAt = func(i, x, l int) byte {
		if l < x {
			return S[i][l]
		}
		if l+1 < len(S[i]) {
			return S[i][l+1]
		}
		return ' '
	}

	check := func(i int, x int, j int, y int) bool {
		len1 := len(S[i])
		len2 := len(S[j])
		if x != len1 {
			len1--
		}
		if y != len2 {
			len2--
		}
		var left, right = 0, min(len1, len2) + 1
		for right-left > 1 {
			mid := (left + right) / 2
			if getHashPair(i, x, mid) == getHashPair(j, y, mid) {
				left = mid
			} else {
				right = mid
			}
		}

		return getAt(i, x, left) >= getAt(j, y, left)
	}

	for i := 1; i < n; i++ {
		oks := i % 2
		var ptr int
		var sum int64
		for k := 0; k < len(sorted[i]); k++ {
			for ptr < len(sorted[i-1]) && check(i, sorted[i][k], i-1, sorted[i-1][ptr]) {
				sum += dp[oks^1][ptr]
				if sum >= MOD[0] {
					sum -= MOD[0]
				}
				ptr++
			}
			dp[oks][k] = sum
		}
	}

	var ans int64

	for i := 0; i <= len(S[n-1]); i++ {
		ans += dp[(n-1)%2][i]
		if ans >= MOD[0] {
			ans -= MOD[0]
		}
	}
	return int(ans)
}

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

type Pair struct {
	first, second int64
}

package main

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

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

	n := readNum(reader)
	S := make([]string, n)

	for i := 0; i < n; i++ {
		s, _ := reader.ReadBytes('\n')
		var j int
		for j < len(s) {
			if s[j] < 'a' || s[j] > 'z' {
				break
			}
			j++
		}
		S[i] = string(s[:j])
	}
	fmt.Println(solve(n, S))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var MOD = [...]int64{1000000007, 1000000009}

const MAX_C = 1000010

var P [2]int64
var R [2]int64

var p [2][MAX_C]int64

var nxt [MAX_C]int

var A [MAX_C]int

var dp [2][MAX_C]int64

func init() {
	P[0] = 29
	P[1] = 31
	R[0] = pow(P[0], MOD[0]-2, MOD[0])
	R[1] = pow(P[1], MOD[1]-2, MOD[1])
	for j := 0; j < 2; j++ {
		p[j][0] = 1
		for i := 1; i < MAX_C; i++ {
			p[j][i] = (P[j] * p[j][i-1]) % MOD[j]
		}
	}
}

func pow(a, b, mod int64) int64 {
	var res int64 = 1
	for b > 0 {
		if b&1 == 1 {
			res = (res * a) % mod
		}
		a = (a * a) % mod
		b >>= 1
	}
	return res
}

func solve(n int, S []string) int {
	H := make([][][]int64, n)
	sorted := make([][]int, n)
	for i := 0; i < n; i++ {
		H[i] = make([][]int64, 2)
		for j := 0; j < 2; j++ {
			H[i][j] = make([]int64, 0, len(S[i])+1)
			H[i][j] = append(H[i][j], 0)
			for pos := 0; pos < len(S[i]); pos++ {
				H[i][j] = append(H[i][j], (H[i][j][pos]+p[j][pos]*int64(S[i][pos]-'a'+1))%MOD[j])
			}
		}

		nxt[len(S[i])-1] = len(S[i]) - 1

		for pos := len(S[i]) - 2; pos >= 0; pos-- {
			if S[i][pos] != S[i][pos+1] {
				nxt[pos] = pos + 1
			} else {
				nxt[pos] = nxt[pos+1]
			}
		}
		var l, r = 0, len(S[i]) - 1
		for pos := 0; pos < len(S[i]); pos++ {
			if S[i][nxt[pos]] <= S[i][pos] {
				A[l] = pos
				l++
			} else {
				A[r] = pos
				r--
			}
		}
		sorted[i] = make([]int, 0, len(S[i])+1)
		for j := 0; j < len(S[i]); j++ {
			sorted[i] = append(sorted[i], A[j])
			if A[j] == len(S[i])-1 {
				sorted[i] = append(sorted[i], len(S[i]))
			}
		}
	}

	for i := 0; i <= len(S[0]); i++ {
		dp[0][i] = 1
	}

	var getHash func(t int, i int, x int, l int) int64

	getHash = func(t int, i int, x int, l int) int64 {
		if l < x {
			return H[i][t][l]
		}
		if l+1 >= len(H[i][t]) {
			l = len(H[i][t]) - 2
		}
		if x+1 >= len(H[i][t]) {
			x = len(H[i][t]) - 2
		}
		res1 := H[i][t][x]
		res2 := (H[i][t][l+1] - H[i][t][x+1] + MOD[t]) % MOD[t]
		res2 *= R[t]
		res2 %= MOD[t]

		return (res1 + res2) % MOD[t]
	}

	getHashPair := func(i, x, l int) Pair {
		first := getHash(0, i, x, l)
		second := getHash(1, i, x, l)
		return Pair{first, second}
	}

	var getAt func(i, x, l int) byte

	getAt = func(i, x, l int) byte {
		if l < x {
			return S[i][l]
		}
		if l+1 < len(S[i]) {
			return S[i][l+1]
		}
		return ' '
	}

	check := func(i int, x int, j int, y int) bool {
		len1 := len(S[i])
		len2 := len(S[j])
		if x != len1 {
			len1--
		}
		if y != len2 {
			len2--
		}
		var left, right = 0, min(len1, len2) + 1
		for right-left > 1 {
			mid := (left + right) / 2
			if getHashPair(i, x, mid) == getHashPair(j, y, mid) {
				left = mid
			} else {
				right = mid
			}
		}

		return getAt(i, x, left) >= getAt(j, y, left)
	}

	for i := 1; i < n; i++ {
		oks := i % 2
		var ptr int
		var sum int64
		for k := 0; k < len(sorted[i]); k++ {
			for ptr < len(sorted[i-1]) && check(i, sorted[i][k], i-1, sorted[i-1][ptr]) {
				sum += dp[oks^1][ptr]
				if sum >= MOD[0] {
					sum -= MOD[0]
				}
				ptr++
			}
			dp[oks][k] = sum
		}
	}

	var ans int64

	for i := 0; i <= len(S[n-1]); i++ {
		ans += dp[(n-1)%2][i]
		if ans >= MOD[0] {
			ans -= MOD[0]
		}
	}
	return int(ans)
}

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

type Pair struct {
	first, second int64
}

package main

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

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

	n := readNum(reader)
	S := make([]string, n)

	for i := 0; i < n; i++ {
		s, _ := reader.ReadBytes('\n')
		var j int
		for j < len(s) {
			if s[j] < 'a' || s[j] > 'z' {
				break
			}
			j++
		}
		S[i] = string(s[:j])
	}
	fmt.Println(solve(n, S))
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var MOD = [...]int64{1000000007, 1000000009}

const MAX_C = 1000010

var P [2]int64
var R [2]int64

var p [2][MAX_C]int64

var nxt [MAX_C]int

var A [MAX_C]int

var dp [2][MAX_C]int64

func init() {
	P[0] = 29
	P[1] = 31
	R[0] = pow(P[0], MOD[0]-2, MOD[0])
	R[1] = pow(P[1], MOD[1]-2, MOD[1])
	for j := 0; j < 2; j++ {
		p[j][0] = 1
		for i := 1; i < MAX_C; i++ {
			p[j][i] = (P[j] * p[j][i-1]) % MOD[j]
		}
	}
}

func pow(a, b, mod int64) int64 {
	var res int64 = 1
	for b > 0 {
		if b&1 == 1 {
			res = (res * a) % mod
		}
		a = (a * a) % mod
		b >>= 1
	}
	return res
}

func solve(n int, S []string) int {
	H := make([][][]int64, n)
	sorted := make([][]int, n)
	for i := 0; i < n; i++ {
		H[i] = make([][]int64, 2)
		for j := 0; j < 2; j++ {
			H[i][j] = make([]int64, 0, len(S[i])+1)
			H[i][j] = append(H[i][j], 0)
			for pos := 0; pos < len(S[i]); pos++ {
				H[i][j] = append(H[i][j], (H[i][j][pos]+p[j][pos]*int64(S[i][pos]-'a'+1))%MOD[j])
			}
		}

		nxt[len(S[i])-1] = len(S[i]) - 1

		for pos := len(S[i]) - 2; pos >= 0; pos-- {
			if S[i][pos] != S[i][pos+1] {
				nxt[pos] = pos + 1
			} else {
				nxt[pos] = nxt[pos+1]
			}
		}
		var l, r = 0, len(S[i]) - 1
		for pos := 0; pos < len(S[i]); pos++ {
			if S[i][nxt[pos]] <= S[i][pos] {
				A[l] = pos
				l++
			} else {
				A[r] = pos
				r--
			}
		}
		sorted[i] = make([]int, 0, len(S[i])+1)
		for j := 0; j < len(S[i]); j++ {
			sorted[i] = append(sorted[i], A[j])
			if A[j] == len(S[i])-1 {
				sorted[i] = append(sorted[i], len(S[i]))
			}
		}
	}

	for i := 0; i <= len(S[0]); i++ {
		dp[0][i] = 1
	}

	var getHash func(t int, i int, x int, l int) int64

	getHash = func(t int, i int, x int, l int) int64 {
		if l < x {
			return H[i][t][l]
		}
		if l+1 >= len(H[i][t]) {
			l = len(H[i][t]) - 2
		}
		if x+1 >= len(H[i][t]) {
			x = len(H[i][t]) - 2
		}
		res1 := H[i][t][x]
		res2 := H[i][t][l+1] - H[i][t][x+1] + MOD[t]
		res2 *= R[t]

		return (res1 + res2) % MOD[t]
	}

	getHashPair := func(i, x, l int) Pair {
		first := getHash(0, i, x, l)
		second := getHash(1, i, x, l)
		return Pair{first, second}
	}

	var getAt func(i, x, l int) byte

	getAt = func(i, x, l int) byte {
		if l < x {
			return S[i][l]
		}
		if l+1 < len(S[i]) {
			return S[i][l+1]
		}
		return ' '
	}

	check := func(i int, x int, j int, y int) bool {
		len1 := len(S[i])
		len2 := len(S[j])
		if x != len1 {
			len1--
		}
		if y != len2 {
			len2--
		}
		var left, right = 0, min(len1, len2) + 1
		for right-left > 1 {
			mid := (left + right) / 2
			if getHashPair(i, x, mid) == getHashPair(j, y, mid) {
				left = mid
			} else {
				right = mid
			}
		}

		return getAt(i, x, left) >= getAt(j, y, left)
	}

	for i := 1; i < n; i++ {
		oks := i % 2
		var ptr int
		var sum int64
		for k := 0; k < len(sorted[i]); k++ {
			for ptr < len(sorted[i-1]) && check(i, sorted[i][k], i-1, sorted[i-1][ptr]) {
				sum += dp[oks^1][ptr]
				if sum >= MOD[0] {
					sum -= MOD[0]
				}
				ptr++
			}
			dp[oks][k] = sum
		}
	}

	var ans int64

	for i := 0; i <= len(S[n-1]); i++ {
		ans += dp[(n-1)%2][i]
		if ans >= MOD[0] {
			ans -= MOD[0]
		}
	}
	return int(ans)
}

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

type Pair struct {
	first, second int64
}


Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most $$$l$$$ centimeters after haircut, where $$$l$$$ is her favorite number. Suppose, that the Alice's head is a straight line on which $$$n$$$ hairlines grow. Let's number them from $$$1$$$ to $$$n$$$. With one swing of the scissors the hairdresser can shorten all hairlines on any segment to the length $$$l$$$, given that all hairlines on that segment had length strictly greater than $$$l$$$. The hairdresser wants to complete his job as fast as possible, so he will make the least possible number of swings of scissors, since each swing of scissors takes one second.Alice hasn't decided yet when she would go to the hairdresser, so she asked you to calculate how much time the haircut would take depending on the time she would go to the hairdresser. In particular, you need to process queries of two types:  $$$0$$$ — Alice asks how much time the haircut would take if she would go to the hairdresser now.  $$$1$$$ $$$p$$$ $$$d$$$ — $$$p$$$-th hairline grows by $$$d$$$ centimeters. Note, that in the request $$$0$$$ Alice is interested in hypothetical scenario of taking a haircut now, so no hairlines change their length.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$l$$$ ($$$1 \le n, m \le 100\,000$$$, $$$1 \le l \le 10^9$$$) — the number of hairlines, the number of requests and the favorite number of Alice. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — the initial lengths of all hairlines of Alice. Each of the following $$$m$$$ lines contains a request in the format described in the statement. The request description starts with an integer $$$t_i$$$. If $$$t_i = 0$$$, then you need to find the time the haircut would take. Otherwise, $$$t_i = 1$$$ and in this moment one hairline grows. The rest of the line than contains two more integers: $$$p_i$$$ and $$$d_i$$$ ($$$1 \le p_i \le n$$$, $$$1 \le d_i \le 10^9$$$) — the number of the hairline and the length it grows by.

For each query of type $$$0$$$ print the time the haircut would take.

NoteConsider the first example:  Initially lengths of hairlines are equal to $$$1, 2, 3, 4$$$ and only $$$4$$$-th hairline is longer $$$l=3$$$, and hairdresser can cut it in $$$1$$$ second.  Then Alice's second hairline grows, the lengths of hairlines are now equal to $$$1, 5, 3, 4$$$  Now haircut takes two seonds: two swings are required: for the $$$4$$$-th hairline and for the $$$2$$$-nd.  Then Alice's first hairline grows, the lengths of hairlines are now equal to $$$4, 5, 3, 4$$$  The haircut still takes two seconds: with one swing hairdresser can cut $$$4$$$-th hairline and with one more swing cut the segment from $$$1$$$-st to $$$2$$$-nd hairline.  Then Alice's third hairline grows, the lengths of hairlines are now equal to $$$4, 5, 4, 4$$$  Now haircut takes only one second: with one swing it is possible to cut the segment from $$$1$$$-st hairline to the $$$4$$$-th.

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++
			}
		}
	}

}