package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	//输入t
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var c, d int64
		fmt.Fscan(in, &c, &d)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		sort.Ints(a)
		maxn := d * int64(a[n-1])
		if maxn < c {
			fmt.Fprintln(out, "Impossible")
			continue
		}
		sum := int64(0)
		for j := n - 1; j >= max(n-int(d), 0); j-- {
			sum += int64(a[j])
		}
		if sum >= c {
			fmt.Fprintln(out, "Infinity")
			continue
		}
		l := int64(0)
		r := int64(1e16 + 1)
		k := (l + r + 1) / 2
		for l < r {
			sum = int64(0)
			k = (l + r + 1) / 2
			if k+1 >= d {
				for j := n - 1; j >= max(n-int(d), 0); j-- {
					sum += int64(a[j])
				}
			} else {
				for j := n - 1; j >= max(n-int(k)-1, 0); j-- {
					sum += int64(a[j])
				}
				if k == 0 {
					sum = int64(a[n-1]) * d
				} else {
					times := d / (k + 1)
					tempSum := times * sum
					left := d % (k + 1)
					for j := n - 1; j >= max(n-int(left), 0); j-- {
						tempSum += int64(a[j])
					}
					sum = tempSum
				}

			}
			if sum > c {
				l = k
			} else if sum == c {
				l = k
			} else {
				r = k - 1
			}
		}
		// 输出res
		fmt.Fprintln(out, l)
	}
}

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

package main

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

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

var T, N, C, D int64
var A []int64

func solve() string {
	sort.Slice(A[:N], func(i, j int) bool {
		return A[i] > A[j]
	})

	for i := 1; int64(i) < N; i += 1 {
		A[i] += A[i-1]
	}

	if A[int(min(N-1, D-1))] >= C {
		return "Infinity"
	}

	if A[0]*D < C {
		return "Impossible"
	}

	l, r := int64(0), D
	for l <= r {
		m := l + (r-l)/2

		s := int64(0)
		if m <= N-1 {
			s += D / (m + 1) * A[m]
			r := D % (m + 1)
			if r > 0 {
				s += A[r-1]
			}
		} else {
			s += D / (m + 1) * A[N-1]
			r := D % (m + 1)
			if r > 0 {
				r = min(r, N)
				s += A[r-1]
			}
		}

		if s >= C {
			l = m + 1
		} else {
			r = m - 1
		}
	}

	return strconv.FormatInt(r, 10)

}

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

	defer func() {
		out.Flush()
	}()

	fmt.Fscan(in, &T)
	A = make([]int64, 200005)

	rs := make([]string, 0)
	for tt := int64(0); tt < T; tt += 1 {
		fmt.Fscan(in, &N, &C, &D)
		for i := 0; int64(i) < N; i += 1 {
			fmt.Fscan(in, &A[i])
		}

		rs = append(rs, solve())
	}

	for i := 0; int64(i) < T; i++ {
		fmt.Fprintln(out, rs[i])
	}
}

package main

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

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

var T, N, C, D int64
var A []int64

func solve() string {
	sort.Slice(A[:N], func(i, j int) bool {
		return A[i] > A[j]
	})

	for i := 1; int64(i) < N; i += 1 {
		A[i] += A[i-1]
	}

	if A[int(min(N-1, D-1))] >= C {
		return "Infinity"
	}

	if A[0]*D < C {
		return "Impossible"
	}

	l, r := int64(0), D
	for l <= r {
		m := l + (r-l)/2

		s := int64(0)
		if m <= N-1 {
			s += D / (m + 1) * A[m]
			r := D % (m + 1)
			if r > 0 {
				s += A[r-1]
			}
		} else {
			s += D / (m + 1) * A[N-1]
			r := D % (m + 1)
			if r > 0 {
				r = min(r, N)
				s += A[r-1]
			}
		}

		if s >= C {
			l = m + 1
		} else {
			r = m - 1
		}
	}

	return strconv.FormatInt(r, 10)

}

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

	fmt.Fscan(in, &T)
	A = make([]int64, 200005)
	for tt := int64(0); tt < T; tt += 1 {
		fmt.Fscan(in, &N, &C, &D)
		for i := 0; int64(i) < N; i += 1 {
			fmt.Fscan(in, &A[i])
		}

		fmt.Println(solve())
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	//输入t
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var c, d int64
		fmt.Fscan(in, &c, &d)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		sort.Ints(a)
		maxn := d * int64(a[n-1])
		if maxn < c {
			fmt.Fprintln(out, "Impossible")
			continue
		}
		sum := int64(0)
		for j := n - 1; j >= max(n-int(d), 0); j-- {
			sum += int64(a[j])
		}
		if sum >= c {
			fmt.Fprintln(out, "Infinity")
			continue
		}
		l := int64(-1)
		r := int64(d + 1)
		k := (l + r + 1) / 2
		for l < r {
			sum = int64(0)
			k = (l + r + 1) / 2
			if k+1 >= d {
				for j := n - 1; j >= max(n-int(d), 0); j-- {
					sum += int64(a[j])
				}
			} else {
				for j := n - 1; j >= max(n-int(k)-1, 0); j-- {
					sum += int64(a[j])
				}
				if k == 0 {
					sum = int64(a[n-1]) * d
				} else {
					times := d / (k + 1)
					tempSum := times * sum
					left := d % (k + 1)
					for j := n - 1; j >= max(n-int(left), 0); j-- {
						tempSum += int64(a[j])
					}
					sum = tempSum
				}

			}
			if sum > c {
				l = k
			} else if sum == c {
				l = k
				//break
			} else {
				r = k - 1
			}
		}
		// 输出res
		fmt.Fprintln(out, l)
	}
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

func bsearch1(ssum []int, l, r int, c int) int {
	if l == r { return l }
	m := (l + r + 1) >> 1
	if ssum[m] >= c { return bsearch1(ssum, m, r, c) }
	return bsearch1(ssum, l, m-1, c)
}

func bsearch2(l, r int, A, B int) int {
	if l == r { return l }
	m := (l + r + 1) >> 1
	if A*m <= B { return bsearch2(m, r, A, B) }
	return bsearch2(l, m-1, A, B)
}

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, c, d int
		fmt.Fscan(r, &n, &c, &d)

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

		sort.Ints(a)
		ssum := make([]int, n+1)
		for i := n-1; i >= 0; i-- {
			ssum[i] = a[i] + ssum[i+1]
		}

		if a[n-1]*d < c {
			fmt.Fprintln(w, "Impossible")
		} else if ssum[n-min(n, d)] >= c {
			fmt.Fprintln(w, "Infinity")
		} else {
			k := 0

			for i := n-1; i >= 0 && c/ssum[i] > 0 ; i-- {
				// fmt.Fprintln(w, "****************")
				// fmt.Fprintln(w, "i ", i)
				cycles := c / ssum[i]
				if c % ssum[i] == 0 {
					cycles--
				}
				// fmt.Fprintln(w, "cycles ", cycles)
				j := bsearch1(ssum, i, n, c - cycles*ssum[i])
				// fmt.Fprintln(w, "j ", j)
				l := bsearch2(0, d, cycles, d - n + j - cycles*(n-i))
				// fmt.Fprintln(w, "l ", l)
				if cycles*(n-i+l) + n - j <= d {
					k = max(k, n-i+l-1)
				}
				// fmt.Fprintln(w, "k ", k)
			}

			fmt.Fprintln(w, k)
		}
	}

}

package main

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

const cf = true

func solve() {
	var n, c, d int
	fmt.Fscan(in, &n, &c, &d)
	sums := make([]int, n)
	for i := range sums {
		fmt.Fscan(in, &sums[i])
	}
	sort.Slice(sums, func(i, j int) bool {
		return sums[i] > sums[j]
	})

	for i := 1; i < n; i++ {
		sums[i] += sums[i-1]
	}

	daysNeeded := c/sums[0] + min(c%sums[0], 1)
	if daysNeeded > d {
		fmt.Fprintln(out, "Impossible")
		return
	}
	mx := sums[n-1]
	if d <= n {
		mx = sums[d-1]
	}
	if mx >= c {
		fmt.Fprintln(out, "Infinity")
		return
	}

	good := func(k int) bool {
		sum := sums[n-1]
		if k < n {
			sum = sums[k]
		}
		cnt := d / (k + 1)

		left := d - cnt*(k+1)
		sumLeft := sums[n-1]
		if left == 0 {
			sumLeft = 0
		} else if left < n {
			sumLeft = sums[left-1]
		}
		return sum*cnt+sumLeft >= c
	}

	ans := 0
	l, r := 0, int(1e16)
	for l < r {
		mid := (l + r) / 2
		if good(mid) {
			ans = mid
			l = mid + 1
		} else {
			r = mid
		}
	}

	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

// For Codeforces
func main() {
	io := newStdIO()
	defer io.Flush()
	for T := io.ScanUInt16(); T > 0; T-- {
		solve(&io)
	}
}

func MaxCoin(arr []int64, k, d int64) int64 {
	tmp := SumN(arr[:Min(int64(len(arr)), k+1)])
	m := tmp * (d / (k + 1))
	m += SumN(arr[:Min(int64(len(arr)), d%(k+1))])
	return m
}
func solve(io *IO) {
	n := io.ScanInt32()
	arr := make([]int64, n)
	c := io.ScanInt64()
	d := io.ScanInt64()
	for i := int32(0); i < n; i++ {
		arr[i] = io.ScanInt64()
	}

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

	if MaxCoin(arr, d, d) >= c {
		io.PrintLn("Infinity")
		return
	}
	if MaxCoin(arr, 0, d) < c {
		io.PrintLn("Impossible")
		return
	}

	var l, r int64
	l = 0
	r = d
	for r-l > 1 {
		middle := (l + r + 1) / 2
		if MaxCoin(arr, middle, d) >= c {
			l = middle
		} else {
			r = middle
		}
	}
	io.PrintLn(l)

}
func SumN(n []int64) int64 {
	m := int64(0)
	for i := 0; i < len(n); i++ {
		m += n[i]
	}
	return m
}

// #region INTERFACES

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// #endregion
// #region Queue

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

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

// #endregion
// #region Stack

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

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

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

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

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

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

// #endregion

// #endregion

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

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

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

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

// #endregion

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

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

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

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

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

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

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

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

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

// #endregion

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

// #endregion

package main

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

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

// source: _
func solve() {
	n, c, d := _readInt(), _readInt(), _readInt()
	_, a := _readArr(n)
	sort.Slice(a, func(i, j int) bool {
		return a[i] > a[j]
	})

	//sum := 0
	//for i := 0; i < d && i < n; i++ {
	//	sum += a[i]
	//}
	//if sum > c {
	//	_print("Infinity")
	//	return
	//}

	if a[0]*d < c {
		_print("Impossible")
		return
	}

	m := _max(n, d)
	ps := make([]int, m)
	ps[0] = a[0]
	for i := 1; i < n; i++ {
		ps[i] = a[i] + ps[i-1]
	}
	for i := n; i < d; i++ {
		ps[i] = ps[i-1]
	}

	for k := 0; k < m; k++ {
		f, p := d/(k+1), d%(k+1)
		x := ps[k] * f
		if p > 0 {
			x += ps[p-1]
		}
		if x < c {
			_print(k - 1)
			return
		}
	}

	_print("Infinity")
	return
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		solve()
	}
}

// ====
func _readInt() int {
	var x int
	fmt.Fscan(in, &x)
	return x
}
func _readStr() string {
	var x string
	fmt.Fscan(in, &x)
	return x
}
func _readArr(x ...int) (int, []int) {
	var n int
	if len(x) == 0 {
		fmt.Fscan(in, &n)
	} else {
		n = x[0]
	}
	var v = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &v[i])
	}
	return n, v
}
func _print(x ...any) {
	fmt.Fprintln(out, x...)
}
func _max(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] > x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _min(x ...int) int {
	mi := 0
	for i := 1; i < len(x); i++ {
		if x[i] < x[mi] {
			mi = i
		}
	}
	return x[mi]
}
func _sum(x ...int) int {
	res := 0
	for _, i := range x {
		res += i
	}
	return res
}
func _abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func _sortStr(x string) string {
	r := []rune(x)
	sort.Slice(r, func(i, j int) bool {
		return r[i] < r[j]
	})
	return string(r)
}
func _reverseInts(x []int) {
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
}
func _reverseStr(s string) string {
	x := []rune(s)
	n := len(x)
	for i := 0; i < n/2; i++ {
		x[i], x[n-1-i] = x[n-1-i], x[i]
	}
	return string(x)
}
func _makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const mod int = 998244353
const N int = 5e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for T > 0 {
		T--
		n := nextInt()
		a := make([]int, n)
		c, d := nextInt64(), nextInt64()
		for i := 0; i < n; i++ {
			a[i] = nextInt()
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		a = append([]int{0}, a...)
		//fmt.Printf("%#v\n", a)
		s := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			s[i] = s[i-1] + int64(a[i])
		}
		if int64(a[1])*d < c {
			fmt.Println("Impossible")
		} else if s[min(d, int64(n))] >= c {
			fmt.Println("Infinity")
		} else {
			l, r := int64(0), d
			for l < r {
				mid := (l + r + 1) >> 1
				if func(x int64) bool {
					t1, t2 := d/(x+1), d%(x+1)
					return t1*s[min(int64(n), x+1)]+s[min(int64(n), t2)] >= c
				}(mid) {
					l = mid
				} else {
					r = mid - 1
				}
			}
			fmt.Println(l)
		}
	}
}

func min(args ...int64) int64 {
	res := args[0]
	for _, v := range args {
		if v < res {
			res = v
		}
	}
	return res
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		var c int64
		var d int64
		Fscan(in, &n, &c, &d)
		// int64 ?
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i] > a[j] })
		f := func(k int64) int64 {
			if k == 0 {
				return d * a[0]
			}
			if k < int64(n) {
				sz := k + 1
				sum := int64(0)
				for _, v := range a[:sz] {
					sum += v
				}
				sum2 := int64(0)
				for _, v := range a[:d%sz] {
					sum2 += v
				}
				res := d/sz*sum + sum2
				return res
			} else {
				sz := k + 1
				sum := int64(0)
				for _, v := range a {
					sum += v
				}
				sum2 := int64(0)
				if d%sz <= int64(n) {
					for _, v := range a[:d%sz] {
						sum2 += v
					}
				} else {
					sum2 = sum
				}

				res := d/sz*sum + sum2
				return res
			}
		}

		if f(0) < c {
			Fprintln(out, "Impossible")
		} else  {
			if f(d+10) >= c {
				Fprintln(out, "Infinity")
			} else {
				ans := sort.Search(int(d+10), func(k int) bool {
					k++
					return f(int64(k)) < c
				})
				Fprintln(out, ans)
			}
		}
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

	leftData, _ := ioutil.ReadAll(in)
	if s := strings.TrimSpace(string(leftData)); s != "" {
		panic("有未读入的数据：\n" + s)
	}

}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	//输入t
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var c, d int64
		fmt.Fscan(in, &c, &d)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		sort.Ints(a)
		maxn := d * int64(a[n-1])
		if maxn < c {
			fmt.Fprintln(out, "Impossible")
			continue
		}
		sum := int64(0)
		for j := n - 1; j >= max(n-int(d), 0); j-- {
			sum += int64(a[j])
		}
		if sum >= c {
			fmt.Fprintln(out, "Infinity")
			continue
		}
		l := int64(0)
		r := int64(1e16 + 1)
		k := (l + r + 1) / 2
		for l < r {
			sum = int64(0)
			k = (l + r + 1) / 2
			if k+1 >= d {
				for j := n - 1; j >= max(n-int(d), 0); j-- {
					sum += int64(a[j])
				}
			} else {
				for j := n - 1; j >= max(n-int(k)-1, 0); j-- {
					sum += int64(a[j])
				}
				if k == 0 {
					sum = int64(a[n-1]) * d
				} else {
					times := d / (k + 1)
					tempSum := times * sum
					left := d % (k + 1)
					for j := n - 1; j >= max(n-int(left), 0); j-- {
						tempSum += int64(a[j])
					}
					sum = tempSum
				}

			}
			if sum > c {
				l = k
			} else if sum == c {
				r = k
				l = k
				break
			} else {
				r = k - 1
			}
		}
		// 输出res
		fmt.Fprintln(out, l)
	}
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	//输入t
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var c, d int64
		fmt.Fscan(in, &c, &d)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		sort.Ints(a)
		maxn := d * int64(a[n-1])
		if maxn < c {
			fmt.Fprintln(out, "Impossible")
			continue
		}
		sum := int64(0)
		for j := n - 1; j >= max(n-int(d), 0); j-- {
			sum += int64(a[j])
		}
		if sum >= c {
			fmt.Fprintln(out, "Infinity")
			continue
		}
		l := int64(0)
		r := int64(1e16 + 1)
		k := (l + r) / 2
		for l < r {
			sum = int64(0)
			k = (l + r) / 2
			if k+1 >= d {
				for j := n - 1; j >= max(n-int(d), 0); j-- {
					sum += int64(a[j])
				}
			} else {
				for j := n - 1; j >= max(n-int(k)-1, 0); j-- {
					sum += int64(a[j])
				}
				if k == 0 {
					sum = int64(a[n-1]) * d
				} else {
					times := d / (k + 1)
					tempSum := times * sum
					left := d % (k + 1)
					for j := n - 1; j >= max(n-int(left), 0); j-- {
						tempSum += int64(a[j])
					}
					sum = tempSum
				}

			}
			if sum > c {
				l = k + 1
			} else if sum == c {
				r = k
				l = k
				break
			} else {
				r = k - 1
			}
		}
		// 输出res
		fmt.Fprintln(out, l)
	}
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	//输入t
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var c, d int64
		fmt.Fscan(in, &c, &d)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		sort.Ints(a)
		maxn := d * int64(a[n-1])
		if maxn < c {
			fmt.Fprintln(out, "Impossible")
			continue
		}
		sum := int64(0)
		for j := n - 1; j >= max(n-int(d), 0); j-- {
			sum += int64(a[j])
		}
		if sum >= c {
			fmt.Fprintln(out, "Infinity")
			continue
		}
		l := int64(0)
		r := int64(1e16 + 1)
		k := (l + r) / 2
		for l < r {
			sum = int64(0)
			k = (l + r) / 2
			if k+1 >= d {
				for j := n - 1; j >= max(n-int(d), 0); j-- {
					sum += int64(a[j])
				}
			} else {
				for j := n - 1; j >= max(n-int(k)-1, 0); j-- {
					sum += int64(a[j])
				}
				if k == 0 {
					sum = int64(a[n-1]) * d
				} else {
					times := d / (k + 1)
					tempSum := times * sum
					left := d % (k + 1)
					for j := n - 1; j >= max(n-int(left), 0); j-- {
						tempSum += int64(a[j])
					}
					sum = tempSum
				}

			}
			if sum > c {
				l = k + 1
			} else if sum == c {
				r = k
				//break
			} else {
				r = k - 1
			}
		}
		// 输出res
		fmt.Fprintln(out, l)
	}
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

package main

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

func bsearch(ssum []int, l, r int, d, c, n int) int {
	if l == r { return l }
	m := (l + r + 1) >> 1
	if (d/(m+1))*ssum[n-m-1] + ssum[n-(d%(m+1))] > c { return bsearch(ssum, l, m-1, d, c, n) }
	return bsearch(ssum, m, r, d, c, n)
}

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, c, d int
		fmt.Fscan(r, &n, &c, &d)

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

		sort.Ints(a)
		ssum := make([]int, n+1)
		for i := n-1; i >= 0; i-- {
			ssum[i] = a[i] + ssum[i+1]
		}

		if a[n-1]*d < c {
			fmt.Fprintln(w, "Impossible")
		} else if ssum[n-min(n, d)] >= c {
			fmt.Fprintln(w, "Infinity")
		} else {
			k := 0

			for i := n-1; i >= 0 && c/ssum[i] > 0 ; i-- {
				cycles := c / ssum[i]
				j := n
				for ; j >= i && cycles*ssum[i] + ssum[j] < c ; j-- {}
				for l := 0; cycles*(n-i+l) + n-j <= d ; l++ {
					k = max(k, n-i+l-1)
				}
			}

			fmt.Fprintln(w, k)
		}
	}

}

package main

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

func bsearch(ssum []int, l, r int, d, c, n int) int {
	if l == r { return l }
	m := (l + r + 1) >> 1
	if (d/(m+1))*ssum[n-m-1] + ssum[n-(d%(m+1))] > c { return bsearch(ssum, l, m-1, d, c, n) }
	return bsearch(ssum, m, r, d, c, n)
}

func max(a, b int) int {
	return -min(-a, -b)
}

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

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

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

		var n, c, d int
		fmt.Fscan(r, &n, &c, &d)

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

		sort.Ints(a)
		ssum := make([]int, n+1)
		for i := n-1; i >= 0; i-- {
			ssum[i] = a[i] + ssum[i+1]
		}

		if a[n-1]*d < c {
			fmt.Fprintln(w, "Impossible")
		} else if ssum[n-min(n, d)] >= c {
			fmt.Fprintln(w, "Infinity")
		} else {
			k := 0

			for i := n-1; i >= 0 && c/ssum[i] > 0 ; i-- {
				cycles := c / ssum[i]
				j := n-1
				for ; j >= i && cycles*ssum[i] + ssum[j] < c ; j-- {}
				for l := 0; cycles*(n-i+l) + n-j <= d ; l++ {
					k = max(k, n-i+l-1)
				}
			}

			fmt.Fprintln(w, k)
		}
	}

}

package main

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

const cf = true

func solve() {
	var n, c, d int
	fmt.Fscan(in, &n, &c, &d)
	sums := make([]int, n)
	for i := range sums {
		fmt.Fscan(in, &sums[i])
	}
	sort.Slice(sums, func(i, j int) bool {
		return sums[i] > sums[j]
	})
	daysNeeded := c/sums[0] + min(c%sums[0], 1)
	if daysNeeded > d {
		fmt.Fprintln(out, "Impossible")
		return
	}
	if sums[0] >= c {
		fmt.Fprintln(out, "Infinity")
		return
	}

	for i := 1; i < n; i++ {
		sums[i] += sums[i-1]
	}

	good := func(k int) bool {
		sum := sums[n-1]
		if k < n {
			sum = sums[k]
		}
		cnt := d / (k + 1)

		left := d - cnt*(k+1)
		sumLeft := sums[n-1]
		if left == 0 {
			sumLeft = 0
		} else if left < n {
			sumLeft = sums[left-1]
		}
		return sum*cnt+sumLeft >= c
	}

	ans := 0
	l, r := 0, int(1e16)
	for l < r {
		mid := (l + r) / 2
		if good(mid) {
			ans = mid
			l = mid + 1
		} else {
			r = mid
		}
	}

	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

const cf = true

func solve() {
	var n, c, d int
	fmt.Fscan(in, &n, &c, &d)
	sums := make([]int, n)
	for i := range sums {
		fmt.Fscan(in, &sums[i])
	}
	sort.Slice(sums, func(i, j int) bool {
		return sums[i] > sums[j]
	})
	daysNeeded := c / sums[0]
	if daysNeeded > d {
		fmt.Fprintln(out, "Impossible")
		return
	}
	if sums[0] >= c {
		fmt.Fprintln(out, "Infinity")
		return
	}

	for i := 1; i < n; i++ {
		sums[i] += sums[i-1]
	}

	good := func(k int) bool {
		sum := sums[n-1]
		if k < n {
			sum = sums[k]
		}
		cnt := d / (k + 1)

		left := d - cnt*(k+1)
		sumLeft := sums[n-1]
		if left == 0 {
			sumLeft = 0
		} else if left < n {
			sumLeft = sums[left-1]
		}
		return sum*cnt+sumLeft >= c
	}

	ans := 0
	l, r := 0, int(1e16)
	for l < r {
		mid := (l + r) / 2
		if good(mid) {
			ans = mid
			l = mid + 1
		} else {
			r = mid
		}
	}

	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}


package main

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

type op struct {
	step []int
	cost int
}

func (o op) clone() op {
	a := make([]int, len(o.step))
	copy(a, o.step)
	return op{step: a, cost: o.cost}
}

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		var m, n int
		fmt.Fscan(in, &n, &m)
		tasks := make([]int, n)
		operations := make([][][3]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &tasks[i])
		}
		for i := 0; i < m; i++ {
			var e, ti, p int
			fmt.Fscan(in, &e, &ti, &p)
			operations[e-1] = append(operations[e-1], [3]int{ti, p, i + 1})
		}
		//fmt.Println(operations)
		var ans []int
		used := 0
		for k := 0; k < n; k++ {
			dp := [101]op{}
			for i := 1; i < 101; i++ {
				dp[i] = op{cost: 1000000001}
			}
			for _, ints := range operations[k] {
				for i := 99; i >= 0; i-- {
					if dp[i].cost == 1000000001 {
						continue
					}
					time, p, number := ints[0], ints[1], ints[2]
					p += i
					if p > 100 {
						p = 100
					}
					if time+dp[i].cost+used <= tasks[k] && dp[p].cost > time+dp[i].cost {
						dp[p] = dp[i].clone()
						dp[p].step = append(dp[p].step, number)
						dp[p].cost += time
					}
				}
			}
			//fmt.Println(used, k, dp[100])
			used += dp[100].cost
			if used > tasks[k] {
				ans = []int{}
				break
			}
			ans = append(ans, dp[100].step...)
		}
		if len(ans) != 0 {
			fmt.Fprintln(out, len(ans))
			for i, an := range ans {
				fmt.Fprint(out, an)
				if i < len(ans)-1 {
					fmt.Fprint(out, " ")
				} else {
					fmt.Fprintln(out)
				}
			}
		} else {
			fmt.Fprintln(out, -1)
		}

	}
}

package main

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

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

	var T, n, m, e, t, p int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		type pair struct{ t, p, i int }
		gs := make([][]pair, n)
		for i := 1; i <= m; i++ {
			Fscan(in, &e, &t, &p)
			gs[e-1] = append(gs[e-1], pair{t, p, i})
		}

		ans := []interface{}{}
		t := 0
		for k, g := range gs {
			dp := [101]int{}
			from := make([][101]int, len(g))
			for i := range dp {
				dp[i] = 1e9 + 1
			}
			dp[0] = 0
			for i, p := range g {
				for j := 100; j > 0; j-- {
					k := j - p.p
					if k < 0 {
						k = 0
					}
					if v := dp[k] + p.t; v < dp[j] {
						dp[j] = v
						from[i][j] = k
					} else {
						from[i][j] = j
					}
				}
			}
			t += dp[100]
			if t > a[k] {
				Fprintln(out, -1)
				continue o
			}
			for i, j := len(g)-1, 100; i >= 0; i-- {
				if from[i][j] != j {
					ans = append(ans, g[i].i)
					j = from[i][j]
				}
			}
		}
		Fprintln(out, len(ans))
		Fprintln(out, ans...)
	}
}

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


package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n, x, y, ans int
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		ans = max(ans, x+y)
	}
	fmt.Println(ans)
}

package main

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

func main() {
	var n, x, y, result int
	in := bufio.NewReaderSize(os.Stdin, 1024*1024)
	fmt.Fscanf(in, "%d\n", &n)
	for ; n > 0; n-- {
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		if x+y > result {
			result = x + y
		}
	}
	fmt.Println(result)
}

package main

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

func main() {
	var n, x, y, result int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	for ; n > 0; n-- {
		fmt.Fscanf(in, "%d %d\n", &x, &y)
		if x+y > result {
			result = x + y
		}
	}
	fmt.Println(result)
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	var ans int
	for i := 0; i < n; i++ {
		x := readi()
		y := readi()
		d := y + x
		ans = max(ans, d)
	}
	println(ans)
}

package main

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

func main() {
	scanner := bufio.NewReadWriter(bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout))

	var input int64
	fmt.Fscanf(scanner, "%d\n", &input)

	var maxX int64 = -1//; var maxY int64 = -1
	for i := int64(0); i < input; i++ {
		var x, y int64
		fmt.Fscanf(scanner, "%d %d\n", &x, &y)
		//// fmt.Printf("%d %d %d/%d", x, y, i, input)
		//if x == y {
		//	maxX = maxI(maxX, x)
		//} else {
		//	maxY = maxI(maxY, maxI(x, y))
		//}
		maxX = maxI(maxX, x+y)
	}
	fmt.Fprintf(scanner, "%d", maxX)

	// fmt.Printf("max %d %d", maxX, maxY)
	//if maxY > maxX {
	//	fmt.Printf("%d\n", maxY+1)
	//} else {
	//	fmt.Printf("%d\n", maxX*2)
	//}
	scanner.Flush()
}

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var x, y, ans float64
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &y)
		ans = math.Max(ans, x+y)
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var input int64
	fmt.Scanf("%d", &input)

	var maxX int64 = -1; var maxY int64 = -1
	for i := int64(0); i < input; i++ {
		var x, y int64
		fmt.Scanf("%d %d", &x, &y)
		if x == y {
			maxX = maxI(maxX, x)
		} else {
			maxY = maxI(maxY, maxI(x, y))
		}
	}

	if maxX >= maxY {
		fmt.Printf("%d", maxX*2)
	} else {
		fmt.Printf("%d", maxY+1)
	}
}

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

package main

import "fmt"

func main() {
	var input int64
	fmt.Scanf("%d", &input)

	var maxX int64 = -1; var maxY int64 = -1
	for i := int64(0); i < input; i++ {
		var x, y int64
		fmt.Scanf("%d %d", &x, &y)
		fmt.Printf("%d %d %d/%d", x, y, i, input)
		if x == y {
			maxX = maxI(maxX, x)
		} else {
			maxY = maxI(maxY, maxI(x, y))
		}
	}

	fmt.Printf("max %d %d", maxX, maxY)
	if maxY > maxX {
		fmt.Printf("%d\n", maxY+1)
	} else {
		fmt.Printf("%d\n", maxX*2)
	}
}

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

package main

import "fmt"

func main() {
	var input int64
	fmt.Scanf("%d\n", &input)

	var maxX int64 = -1; var maxY int64 = -1
	for i := int64(0); i < input; i++ {
		var x, y int64
		fmt.Scanf("%d %d\n", &x, &y)
		// fmt.Printf("%d %d %d/%d", x, y, i, input)
		if x == y {
			maxX = maxI(maxX, x)
		} else {
			maxY = maxI(maxY, maxI(x, y))
		}
	}

	// fmt.Printf("max %d %d", maxX, maxY)
	if maxY > maxX {
		fmt.Printf("%d\n", maxY+1)
	} else {
		fmt.Printf("%d\n", maxX*2)
	}
}

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

package main

import "fmt"

func main() {
	var input int64
	fmt.Scanf("%d", &input)

	var maxX int64 = -1; var maxY int64 = -1
	for i := int64(0); i < input; i++ {
		var x, y int64
		fmt.Scanf("%d %d", &x, &y)
		if x == y {
			maxX = maxI(maxX, x)
		} else {
			maxY = maxI(maxY, maxI(x, y))
		}
	}

	if maxY > maxX {
		fmt.Printf("%d", maxY+1)
	} else {
		fmt.Printf("%d", maxX*2)
	}
}

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


package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1059D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	const eps = 1e-8
	search := func(l, r float64, f func(x float64) bool) float64 {
		for i := 0; i < 200; i++ {
			mid := (l + r) / 2
			if f(mid) {
				r = mid
			} else {
				l = mid
			}
		}
		return (l + r) / 2
	}

	var n int
	Fscan(in, &n)
	type pair struct{ x, y float64 }
	ps := make([]pair, n)
	for i := range ps {
		Fscan(in, &ps[i].x, &ps[i].y)
		if ps[i].y*ps[0].y < 0 {
			Fprint(out, -1)
			return
		}
	}
	if ps[0].y < 0 {
		for i := range ps {
			ps[i].y = -ps[i].y
		}
	}

	ans := search(0, 1e50, func(r float64) bool {
		minOx := math.MaxFloat64
		for _, p := range ps {
			if 2*r < p.y {
				return false
			}
			if x := p.x + math.Sqrt(p.y*(2*r-p.y)); x < minOx {
				minOx = x
			}
		}
		for _, p := range ps {
			if (p.x-minOx)*(p.x-minOx) > (1+eps)*p.y*(2*r-p.y) {
				return false
			}
		}
		return true
	})
	Fprintf(out, "%.16f", ans)
}

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

package main

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

const (
	Inf   = 1e20
	Steps = 128
)

type point struct {
	x, y float64
}

var n int
var points []point

func intersect(center point, r float64) []float64 {
	p := center.x * center.x + center.y * center.y - 2 * center.y * r
	b := -2 * center.x
	d := b * b - 4 * p
	if d < 0 {
		return nil
	}
	d = math.Sqrt(d)
	return []float64{(-b - d) / 2, (-b + d) / 2}
}

func check(r float64) bool {
	start, end := -Inf, Inf
	for i := 0; i < n; i++ {
		intersection_points := intersect(points[i], r)
		if len(intersection_points) == 0 {
			return false
		}
		if start < intersection_points[0] {
			start = intersection_points[0]
		}
		if end > intersection_points[1] {
			end = intersection_points[1]
		}
		if start > end {
			return false
		}
	}
	return true
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	points = make([]point, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%f %f\n", &points[i].x, &points[i].y)
	}
	above, under := false, false
	for i := 0; i < n; i++ {
		if points[i].y < 0 {
			under = true
		} else {
			above = true
		}
	}
	if above && under {
		fmt.Println(-1)
		return
	}
	if under {
		for i := 0; i < n; i++ {
			points[i].y *= -1
		}
	}
	lo, hi := -Inf, Inf
	for i := 0; i < Steps; i++ {
		r := (lo + hi) / 2
		if check(r) {
			hi = r
		} else {
			lo = r
		}
	}
	fmt.Printf("%f\n", (hi + lo) / 2)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1059D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	search := func(l, r float64, f func(x float64) bool) float64 {
		for i := 0; i < 70; i++ {
			mid := (l + r) / 2
			if f(mid) {
				r = mid
			} else {
				l = mid
			}
		}
		return (l + r) / 2
	}

	var n int
	Fscan(in, &n)
	type pair struct{ x, y float64 }
	ps := make([]pair, n)
	for i := range ps {
		Fscan(in, &ps[i].x, &ps[i].y)
		if ps[i].y*ps[0].y < 0 {
			Fprint(out, -1)
			return
		}
	}
	if ps[0].y < 0 {
		for i := range ps {
			ps[i].y = -ps[i].y
		}
	}

	ans := search(0, 1e14, func(r float64) bool {
		minOx := math.MaxFloat64
		for _, p := range ps {
			if 2*r < p.y {
				return false
			}
			if x := p.x + math.Sqrt(p.y*(2*r-p.y)); x < minOx {
				minOx = x
			}
		}
		for _, p := range ps {
			if (p.x-minOx)*(p.x-minOx) > (1+1e-8)*p.y*(2*r-p.y) {
				return false
			}
		}
		return true
	})
	Fprintf(out, "%.16f", ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1059D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	const eps = 1e-7
	search := func(l, r float64, f func(x float64) bool) float64 {
		for i := 0; i < 200; i++ {
			mid := (l + r) / 2
			if f(mid) {
				r = mid
			} else {
				l = mid
			}
		}
		return (l + r) / 2
	}

	var n int
	Fscan(in, &n)
	type pair struct{ x, y float64 }
	ps := make([]pair, n)
	for i := range ps {
		Fscan(in, &ps[i].x, &ps[i].y)
		if ps[i].y*ps[0].y < 0 {
			Fprint(out, -1)
			return
		}
	}
	if ps[0].y < 0 {
		for i := range ps {
			ps[i].y = -ps[i].y
		}
	}

	ans := search(0, 1e50, func(r float64) bool {
		minOx := math.MaxFloat64
		for _, p := range ps {
			if 2*r < p.y {
				return false
			}
			if x := p.x + math.Sqrt(r*r-(r-p.y)*(r-p.y)); x < minOx {
				minOx = x
			}
		}
		for _, p := range ps {
			if (p.x-minOx)*(p.x-minOx)+(p.y-r)*(p.y-r) > r*r+eps {
				return false
			}
		}
		return true
	})
	Fprintf(out, "%.18f", ans)
}

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

package main

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

const (
	Inf   = 1e20
	Steps = 128
)

type point struct {
	x, y float64
}

var n int
var points []point

func intersect(center point, r float64) []float64 {
	p := center.x * center.x + center.y * center.y - 2 * center.y * r
	b := -2 * center.x
	d := b * b - 4 * p
	if d < 0 {
		return nil
	}
	d = math.Sqrt(d)
	return []float64{(-b - d) / 2, (-b + d) / 2}
}

func check(r float64) bool {
	start, end := -Inf, Inf
	for i := 0; i < n; i++ {
		intersection_points := intersect(points[i], r)
		if len(intersection_points) == 0 {
			return false
		}
		if start < intersection_points[0] {
			start = intersection_points[0]
		}
		if end > intersection_points[1] {
			end = intersection_points[1]
		}
		if start > end {
			return false
		}
	}
	return true
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	points = make([]point, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%f %f\n", &points[i].x, &points[i].y)
	}
	above, under := false, false
	for i := 0; i < n; i++ {
		if points[i].y < 0 {
			under = true
		} else {
			above = true
		}
	}
	if above && under {
		fmt.Println(-1)
		return
	}
	lo, hi := -Inf, Inf
	fmt.Println((lo + hi + 2) / 2)
	for i := 0; i < Steps; i++ {
		r := (lo + hi) / 2
		if check(r) {
			hi = r
		} else {
			lo = r
		}
	}
	fmt.Printf("%f\n", (hi + lo) / 2)
}

package main

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

const (
	Inf   = 1e20
	Steps = 128
)

type point struct {
	x, y float64
}

var n int
var points []point

func intersect(center point, r float64) []float64 {
	p := center.x * center.x + center.y * center.y - 2 * center.y * r
	b := -2 * center.x
	d := b * b - 4 * p
	if d < 0 {
		return nil
	}
	d = math.Sqrt(d)
	return []float64{(-b - d) / 2, (-b + d) / 2}
}

func check(r float64) bool {
	start, end := -Inf, Inf
	for i := 0; i < n; i++ {
		intersection_points := intersect(points[i], r)
		if len(intersection_points) == 0 {
			return false
		}
		if start < intersection_points[0] {
			start = intersection_points[0]
		}
		if end > intersection_points[1] {
			end = intersection_points[1]
		}
		if start > end {
			return false
		}
	}
	return true
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	points = make([]point, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%f %f\n", &points[i].x, &points[i].y)
	}
	above, under := false, false
	for i := 0; i < n; i++ {
		if points[i].y < 0 {
			under = true
		} else {
			above = true
		}
	}
	if above && under {
		fmt.Println(-1)
		return
	}
	lo, hi := -Inf, Inf
	for i := 0; i < Steps; i++ {
		r := (lo + hi) / 2
		if check(r) {
			hi = r
		} else {
			lo = r
		}
	}
	fmt.Printf("%f\n", (hi + lo) / 2)
}


package main

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

func main() {
	//var read, _ = os.Open("dat.txt")
	//var write, _ = os.Create("result.txt")
	var read = bufio.NewReader(os.Stdin)
	var write = bufio.NewWriter(os.Stdout)
	var n int
	fmt.Fscan(read, &n)
	var a = make([]int, n)
	for i := 0; i < n; i++ {
		var ai int
		fmt.Fscan(read, &ai)
		a[i] = ai
	}
	sort.Ints(a)
	var res = "NO"
	if a[n-1] < a[n-2]+a[n-3] {
		res = "YES"
	}
	fmt.Fprintln(write, res)
	if res == "YES" {
		for i := 0; i < n-2; i++ {
			fmt.Fprint(write, a[i], " ")
		}
		fmt.Fprint(write, a[n-1], " ")
		fmt.Fprint(write, a[n-2], " ")
	}
	write.Flush()
	//read.Close()
	//write.Close()
}

// Author: sighduck
// URL: https://codeforces.com/contest/1189/problem/B

package main

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

type Solution struct {
	Exists bool
	Array  []int
}

func Solve(n int, a []int) Solution {
	sort.Ints(a)
	output := make([]int, n)
	output[0] = a[n-1]
	output[1] = a[n-2]
	for i := 0; i < n-2; i++ {
		output[i+2] = a[i]
	}
	for i := 0; i < n; i++ {
		if output[i] >= (output[(i-1+n)%n] + output[(i+1+n)%n]) {
			return Solution{Exists: false, Array: []int{}}
		}
	}
	return Solution{Exists: true, Array: output}
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}
	fmt.Fscanf(reader, "\n")
	solution := Solve(n, a)
	if !solution.Exists {
		fmt.Fprintf(writer, "NO\n")
	} else {
		fmt.Fprintf(writer, "YES\n")
		for i := 0; i < n; i++ {
			fmt.Fprintf(writer, "%d ", solution.Array[i])
		}
		fmt.Fprintf(writer, "\n")
	}
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSpace(line)
	for i, v := range strings.Split(line, " ") {
		x, e := strconv.Atoi(v)
		a[i] = x
		if e != nil {
			fmt.Println(e)
		}
	}
	sort.Ints(a)
	if a[n-1] < (a[n-2] + a[n-3]) {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

    var n int
    fmt.Fscan(reader, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(reader, &a[i])
    }
    sort.Ints(a)
    if a[n - 1] >= a[n - 2] + a[n - 3] {
        fmt.Fprintln(writer, "NO")
    } else {
        fmt.Fprintln(writer, "YES")
        for i := 0; i < n; i += 2 {
            fmt.Fprint(writer, a[i], " ")
        }
        for i := n - (n % 2) - 1; i > 0; i -= 2 {
            fmt.Fprint(writer, a[i], " ")
        }
    }
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)
	ints := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	strI := strings.Split(line, " ")

	var c int
	for c < n {
		d := strI[c]
		ints[c], _ = strconv.Atoi(strings.TrimSpace(d))
		c++
	}
	sort.Ints(ints)

	if ints[n-2]+ints[n-3] <= ints[n-1] {
		fmt.Println("NO")
		return
	}

	ints[n-1], ints[n-2] = ints[n-2], ints[n-1]

	fmt.Println("YES")
	for i := 0; i < len(ints); i++ {
		fmt.Print(" ", ints[i])
	}
}

package main

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

func main() {
	var n int
	// var a int
	fmt.Scanln(&n)
	// var str string
	// fmt.Scanln(&str)
	ints := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	// fmt.Println(line)
	strI := strings.Split(line, " ")

	var c int
	// now := time.Now() // current local time
	// nsec := now.UnixNano()
	for c < n {
		// fmt.Scan(&a)
		d := strI[c]
		// fmt.Println(d)
		ints[c], _ = strconv.Atoi(strings.TrimSpace(d))
		c++
	}
	// now = time.Now() // current local time
	// nsec -= now.UnixNano()
	// if n > 10000 {
	// 	fmt.Println("YES")
	// 	fmt.Print(nsec)
	// 	for i := 0; i < len(ints); i++ {
	// 		fmt.Print(" ", ints[i])
	// 	}
	// }
	// fmt.Println(ints)
	sort.Ints(ints)

	if ints[n-2]+ints[n-3] <= ints[n-1] {
		fmt.Println("NO")
		return
	}

	ints[n-1], ints[n-2] = ints[n-2], ints[n-1]

	fmt.Println("YES")
	for i := 0; i < len(ints); i++ {
		fmt.Print(" ", ints[i])
	}
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	for i, v := range strings.Split(line, " ") {
		a[i], _ = strconv.Atoi(v)
	}
	sort.Ints(a)
	if a[n-1] < (a[n-2] + a[n-3]) {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	fmt.Println(line)
	fmt.Println(n)
	for i, v := range strings.Split(line, " ") {
		a[i], _ = strconv.Atoi(v)
	}
	sort.Ints(a)
	if a[n-1] < (a[n-2] + a[n-3]) {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	b, _ := reader.ReadBytes('\n')
	n := toInt(b)

	s, _ := reader.ReadString('\n')
	as := strings.Fields(s)
	a := make([]int, n)
	for _, v := range as {
		x, _ :=strconv.Atoi(v)
		a = append(a, x)
	}

	sort.Ints(a)
	if a[n-1] < a[n-2]+a[n-3] {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSpace(line)
	for i, v := range strings.Split(line, " ") {
		fmt.Printf("%U", []rune(v))
		a[i], _ = strconv.Atoi(v)
	}
	sort.Ints(a)
	if a[n-1] < (a[n-2] + a[n-3]) {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"bytes"
	"fmt"
	"sort"
	"strconv"
)

func arrayToString(A []int, delim string) string {
	var buffer bytes.Buffer
	for i := 0; i < len(A); i++ {
		buffer.WriteString(strconv.Itoa(A[i]))
		if i != len(A)-1 {
			buffer.WriteString(delim)
		}
	}
	return buffer.String()
}

func main() {
	var n int
	var x int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&x)
		a[i] = x
	}
	if a[n-1] < a[n-2]+a[n-3] {
		sort.Ints(a)
		temp := a[n-1]
		a[n-1] = a[n-2]
		a[n-2] = temp
		fmt.Println("YES")
			fmt.Println(arrayToString(a, " "))
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	for i, v := range strings.Split(line, " ") {
		a[i], _ = strconv.Atoi(v)
	}
	sort.Ints(a)
	if a[n-1] < (a[n-2] + a[n-3]) {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf[:len(buf)-1] {
		n = n*10 + int(v-'0')
	}
	return
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	b, _ := reader.ReadBytes('\n')
	n := toInt(b)

	s, _ := reader.ReadString('\n')
	as := strings.Fields(s)
	a := make([]int, n)
	for i, v := range as {
		x, _ :=strconv.Atoi(v)
		a[i] = x
	}

	sort.Ints(a)
	if a[n-1] < a[n-2]+a[n-3] {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	for i, v := range strings.Split(line, " ") {
	    fmt.Println(v)
		a[i], _ = strconv.Atoi(v)
	}
	sort.Ints(a)
	if a[n-1] < (a[n-2] + a[n-3]) {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)
	a := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	for i, v := range strings.Split(line, " ") {
		a[i], _ = strconv.Atoi(v)
	}
	fmt.Println(a)
	sort.Ints(a)
	fmt.Println(a)
	if a[n-1] < (a[n-2] + a[n-3]) {
		a[n-1], a[n-2] = a[n-2], a[n-1]
		fmt.Println("YES")
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

    var n int
    fmt.Fscan(reader, &n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Fscan(reader, &a[i])
    }
    sort.Ints(a)
    if a[n - 1] >= a[n - 2] + a[n - 3] {
        fmt.Fprintln(writer, "NO")
    } else {
        fmt.Fprintln(writer, "YES")
        for i := 0; i < n; i += 2 {
            fmt.Fprint(writer, a[i], " ")
        }
        if n % 2 == 0 {
            fmt.Fprint(writer, a[n - 1], " ")
        }
        for i := n - (n % 2) - 1; i > 0; i -= 2 {
            fmt.Fprint(writer, a[i], " ")
        }
    }
}

package main

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

func main() {
	var n int
	// var a int
	fmt.Scanln(&n)
	// var str string
	// fmt.Scanln(&str)
	ints := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	// fmt.Println(line)
	strI := strings.Split(line, " ")

	var c int
	now := time.Now() // current local time
	nsec := now.UnixNano()
	for c < n {
		// fmt.Scan(&a)
		d := strI[c]
		// fmt.Println(d)
		ints[c], _ = strconv.Atoi(strings.TrimSpace(d))
		c++
	}
	now = time.Now() // current local time
	nsec -= now.UnixNano()
	if n > 10000 {
		fmt.Println("YES")
		fmt.Print(nsec)
		for i := 0; i < len(ints); i++ {
			fmt.Print(" ", ints[i])
		}
	}
	// fmt.Println(ints)
	sort.Ints(ints)

	if ints[n-2]+ints[n-3] <= ints[n-1] {
		fmt.Println("NO")
		return
	}

	ints[n-1], ints[n-2] = ints[n-2], ints[n-1]

	fmt.Println("YES")
	for i := 0; i < len(ints); i++ {
		fmt.Print(" ", ints[i])
	}
}

package main

import (
	"errors"
	"fmt"
	"sort"
)

func circle(ints []int) ([]int, error) {
	ret := make([]int, len(ints))
	n := len(ints) - 1

	for i := 0; i < len(ints)/3+1; i++ {
		c := i * 3
		if c >= len(ints) {
			break
		}
		// fmt.Println("a ", i, c, n, ret)
		ret[c] = ints[i]
		if n-2*i > i && c <= n {
			ret[c+1] = ints[n-2*i]
		}
		if n-2*i-1 > i && c <= n {
			ret[c+2] = ints[n-2*i-1]
		}
		if ret[(i+1)%n] > ret[i]+ret[(i+2)%n] {
			return nil, errors.New("NO")
		}
	}
	return ret, nil
}
func valid(cyc []int) bool {
	n := len(cyc)
	for i := 0; i < n+1; i++ {
		if cyc[(i+1)%n] > cyc[(i)%n]+cyc[(i+2)%n] {
			return false
		}
	}
	return true
}
func main() {
	var n int
	var a int
	fmt.Scanln(&n)
	ints := make([]int, n)
	var c int
	for c < n {
		fmt.Scan(&a)
		ints[c] = a
		c++
	}
	sort.Ints(ints)
	cyc, err := circle(ints)
	// fmt.Println("Ints:   ", ints)
	if err != nil {
		fmt.Println("NO")
		return
	}
	if !valid(cyc) {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	// fmt.Println("Cyc: ", cyc)
	for i := 0; i < len(cyc)-1; i++ {
		fmt.Printf("%v ", cyc[i])
	}
	fmt.Printf("%v\n", cyc[len(cyc)-1])

}

package main

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

func main() {
	var n int
	// var a int
	fmt.Scanln(&n)
	// var str string
	// fmt.Scanln(&str)
	ints := make([]int, n)
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	strI := strings.Split(line, " ")

	var c int
	now := time.Now() // current local time
	nsec := now.UnixNano()
	for c < n {
		// fmt.Scan(&a)
		d := strI[c]
		// fmt.Println(d)
		ints[c], _ = strconv.Atoi(d)
		c++
	}
	now = time.Now() // current local time
	nsec -= now.UnixNano()
	if n > 10000 {
		fmt.Println("YES")
		fmt.Print(nsec)
		for i := 0; i < len(ints); i++ {
			fmt.Print(" ", ints[i])
		}
	}
	sort.Ints(ints)

	if ints[n-2]+ints[n-3] <= ints[n-1] {
		fmt.Println("NO")
		return
	}

	ints[n-1], ints[n-2] = ints[n-2], ints[n-1]

	fmt.Println("YES")
	for i := 0; i < len(ints); i++ {
		fmt.Print(" ", ints[i])
	}
}

package main

import (
	"errors"
	"fmt"
	"sort"
)

func circle(ints []int) ([]int, error) {
	ret := make([]int, len(ints))
	n := len(ints) - 1

	for i := 0; i < len(ints)/3+1; i++ {
		c := i * 3
		if c >= len(ints) {
			break
		}
		// fmt.Println("a ", i, c, n, ret)
		ret[c] = ints[i]
		if n-2*i > i && c <= n {
			ret[c+1] = ints[n-2*i]
		}
		if n-2*i-1 > i && c <= n {
			ret[c+2] = ints[n-2*i-1]
		}
		if ret[(i+1)%n] > ret[i]+ret[(i+2)%n] {
			return nil, errors.New("NO")
		}
	}
	return ret, nil
}
func main() {
	var n int
	var a int
	fmt.Scanln(&n)
	ints := make([]int, n)
	var c int
	for c < n {
		fmt.Scan(&a)
		ints[c] = a
		c++
	}
	sort.Ints(ints)
	cyc, err := circle(ints)
	// fmt.Println("Ints:   ", ints)
	if err != nil {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	// fmt.Println("Cyc: ", cyc)
	for _, n := range cyc {
		fmt.Printf("%v ", n)
	}

}

package main

import (
	"errors"
	"fmt"
	"sort"
)

func circle(ints []int) ([]int, error) {
	ret := make([]int, len(ints))
	n := len(ints) - 1

	for i := 0; i < len(ints)/3+1; i++ {
		c := i * 3
		if c >= len(ints) {
			break
		}
		// fmt.Println("a ", i, c, n, ret)
		ret[c] = ints[i]
		if n-2*i > i && c <= n {
			ret[c+1] = ints[n-2*i]
		}
		if n-2*i-1 > i && c <= n {
			ret[c+2] = ints[n-2*i-1]
		}
		if ret[(i+1)%n] > ret[i]+ret[(i+2)%n] {
			return nil, errors.New("NO")
		}
	}
	return ret, nil
}
func main() {
	var n int
	var a int
	fmt.Scanln(&n)
	ints := make([]int, n)
	var c int
	for c < n {
		fmt.Scan(&a)
		ints[c] = a
		c++
	}
	sort.Ints(ints)
	cyc, err := circle(ints)
	// fmt.Println("Ints:   ", ints)
	if err != nil {
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")
	// fmt.Println("Cyc: ", cyc)
	for i := 0; i < len(cyc)-1; i++ {
		fmt.Printf("%v ", cyc[i])
	}
	fmt.Printf("%v\n", cyc[len(cyc)-1])

}


package main

// Solution for https://codeforces.com/problemset/problem/814/C

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

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

	var n, q int
	var s string
	fmt.Fscanf(stdin, "%d\n", &n)
	fmt.Fscanf(stdin, "%s\n", &s)
	fmt.Fscanf(stdin, "%d\n", &q)

	reals := []byte(s)
	for i := range reals {
		reals[i] -= 'a'
	}

	m := make([]int16, q)
	c := make([]byte, q)
	var maxm [26]int16

	var mi int16
	var ci string
	for i := 0; i < q; i++ {
		fmt.Fscanf(stdin, "%d", &mi)
		fmt.Fscanf(stdin, "%s\n", &ci)
		realc := ci[0] - 'a'
		m[i] = mi
		c[i] = realc
		if maxm[realc] < mi {
			maxm[realc] = mi
		}
	}

	var goods [26][]int16

	for a := byte(0); a < 26; a++ {
		maxm1 := maxm[a]
		if maxm1 == 0 {
			continue
		}
		firstGood := reals[0] == a
		prevGood := firstGood
		islands := []int16{1}
		for i := 1; i < n; i++ {
			good := reals[i] == a
			if good == prevGood {
				islands[len(islands)-1]++
			} else {
				islands = append(islands, 1)
			}
			prevGood = good
		}

		// Convert it to list of pairs (good, bad).
		if !firstGood {
			islands = islands[1:]
		}
		if len(islands)%2 == 1 {
			islands = append(islands, 0)
		}

		maxGood := make([]int16, maxm1+1) // Key is required badness.
		nislands := len(islands) / 2
		for from := 0; from < nislands; from++ {
			goodness := islands[from*2]
			badness := int16(0)
			if maxGood[badness] < goodness {
				maxGood[badness] = goodness
			}
			for to := from + 1; to < nislands; to++ {
				goodness += islands[to*2-1] + islands[to*2]
				badness += islands[to*2-1]
				if badness > maxm1 {
					break
				}
				if maxGood[badness] < goodness {
					maxGood[badness] = goodness
				}
			}
		}

		for badness := int16(1); badness <= maxm1; badness++ {
			if maxGood[badness] < maxGood[badness-1]+1 {
				maxGood[badness] = maxGood[badness-1] + 1
			}
			if maxGood[badness] > int16(n) {
				maxGood[badness] = int16(n)
			}
		}

		goods[a] = maxGood
	}

	var ans []string
	for i := 0; i < q; i++ {
		ans = append(ans, strconv.Itoa(int(goods[c[i]][m[i]])))
	}
	fmt.Println(strings.Join(ans, "\n"))
}

package main

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

type Reader struct {
  scanner *bufio.Scanner
}

func StdinReader() Reader {
  reader := Reader{bufio.NewScanner(os.Stdin)}
  reader.scanner.Split(bufio.ScanWords)
  return reader
}

func (r *Reader) ReadString() string {
  ok := r.scanner.Scan()
  if !ok {
    panic("EOF")
  }
  return r.scanner.Text()
}

func (r *Reader) ReadByte() byte {
  s := r.ReadString()
  return s[0]
}

func (r *Reader) ReadInt() int {
  i, err := strconv.Atoi(r.ReadString())
  if err != nil {
    panic("no int")
  }
  return i
}

func main() {
  in := StdinReader()

  n := in.ReadInt()
  s := in.ReadString()
  q := in.ReadInt()

  prefix := make([][]int, 26)
  for c := 0; c < 26; c++ {
    prefix[c] = make([]int, n + 1)
    prefix[c][0] = 0
    for i := 0; i < n; i++ {
      prefix[c][i + 1] = prefix[c][i]
      if s[i] - 'a' != byte(c) {
        prefix[c][i + 1]++
      }
    }
  }

  for i := 0; i < q; i++ {
    m := in.ReadInt()
    c := in.ReadByte()
    curr_prefix := prefix[c - 'a']
    ans := m
    for j := m; j <= n; j++ {
      for ; (ans + 1) <= j && curr_prefix[j] - curr_prefix[j - (ans + 1)] <= m; {
        ans++
      }
    }
    fmt.Printf("%d\n", ans)
  }

}

package main

import "fmt"
import "bufio"
import "os"

var (
    n int
    s string
    q int
    mm, cc int
)

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

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

    for {
        _, err := fmt.Fscan(in, &n)
        if err != nil { break }

        a := make([]int, n + 1)
        fmt.Fscan(in, &s)
        for i := 0; i < len(s); i++ {
            a[i + 1] = int(s[i]) - int('a');
        }

        var f [26][2][1501]int
        var g [26][2][1501]int

        var x int
        for c := 0; c < 26; c++ {
            prev := 0
            var now int

            for i := 1; i <= n; i++ {
                now = (prev + 1) % 2

                f[c][now][0] = f[c][prev][0]
                if a[i] == c {
                    g[c][now][0] = 1 + g[c][prev][0]
                } else {
                    g[c][now][0] = 0
                }
                f[c][now][0] = maxInt(f[c][prev][0], g[c][now][0])

                for j := 1; j <= i; j++ {
                    g[c][now][j] = g[c][now][j-1]

                    if a[i] == c {
                        g[c][now][j] = maxInt(g[c][now][j], g[c][prev][j] + 1)
                    } else {
                        g[c][now][j] = maxInt(g[c][now][j], g[c][prev][j-1] + 1)
                    }

                    f[c][now][j] = maxInt(f[c][now][j-1], f[c][prev][j])
                    f[c][now][j] = maxInt(f[c][now][j], g[c][now][j])
                }

                prev = now
            }
            x = now
        }

        fmt.Fscan(in, &q)
        for i := 0; i < q; i++ {
            var str string
            fmt.Fscan(in, &mm, &str)
            var c int = int(str[0]) - int('a')
            fmt.Println(f[c][x][mm])
        }
    }
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
  N := io.NextInt()
  S := io.NextLine()

  ans := make(map[byte][]int)
  for c := byte('a'); c <= 'z'; c++ {
    ans[c] = Compute(S, c)
  }

  Q := io.NextInt()

  for q := 0; q < Q; q++ {
    M := io.NextInt()
    C := io.NextString()[0]

    val := ans[C][M]
    if val == 0 {
      io.Println(N)
    } else {
      io.Println(val)
    }
  }
}

func Compute(S string, c byte) []int {
  N := len(S)

  ans := make([]int, N + 1)
  for i := 0; i < N; i++ {
    if S[i] == c {
      continue
    }
    j := i
    for j > 0 && S[j - 1] == c {
      j--
    }
    p := i
    add := 0
    for p < N {
      p++
      for p < N && S[p] == c {
        p++
      }
      add++
      ans[add] = Max(ans[add], p - j)
    }
  }
  return ans
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
  N := io.NextInt()
  S := io.NextLine()

  ans := make(map[byte][]int)
  for c := byte('a'); c <= 'z'; c++ {
    ans[c] = Compute(S, c)
  }

  Q := io.NextInt()

  for q := 0; q < Q; q++ {
    M := io.NextInt()
    C := io.NextString()[0]

    val := ans[C][M]
    if val == 0 {
      io.Println(N)
    } else {
      io.Println(val)
    }
  }
}

func Compute(S string, c byte) []int {
  N := len(S)

  skip := make([]int, N + 1)
  skip[N] = N
  end := N
  for i := N - 1; i >= 0; i-- {
    if S[i] != c {
      end = i
    }
    skip[i] = end
  }

  ans := make([]int, N + 1)
  for i := 0; i < N; i++ {
    if S[i] == c {
      continue
    }
    j := i
    for j > 0 && S[j - 1] == c {
      j--
    }
    p := i
    add := 0
    for p < N {
      p++
      p = skip[p]
      add++
      ans[add] = Max(ans[add], p - j)
    }
  }
  return ans
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
  N := io.NextInt()
  S := io.NextLine()

  ans := make(map[byte][]int)
  for c := byte('a'); c <= 'z'; c++ {
    ans[c] = Compute(S, c)
  }

  Q := io.NextInt()

  for q := 0; q < Q; q++ {
    M := io.NextInt()
    C := io.NextString()[0]

    val := ans[C][M]
    if val == 0 {
      io.Println(N)
    } else {
      io.Println(val)
    }
  }
}

func Compute(S string, c byte) []int {
  N := len(S)

  // pos := make(map[int]int)
  // idx := 0
  // for idx < N {
  //   if S[idx] != c {
  //     prev := idx
  //     idx++
  //     for idx < N && S[idx] == c {
  //       idx++
  //     }
  //     S[prev] = idx
  //   } else {
  //     idx++
  //   }
  // }

  ans := make([]int, N + 1)
  for i := 0; i < N; i++ {
    if S[i] == c {
      continue
    }
    j := i
    for j > 0 && S[j - 1] == c {
      j--
    }
    p := i
    add := 0
    for p < N {
      p++
      for p < N && S[p] == c {
        p++
      }
      add++
      ans[add] = Max(ans[add], p - j)
      // if c == 'o' {
      //   fmt.Printf("START(%d): %d -> %d - %d = %d\n", i, add, p, i, p - i)
      // }
    }
  }
  return ans
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

import "fmt"

var (
    n int
    s string
    q int
    mm, cc int
)

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

func main() {
    for {
        _, err := fmt.Scan(&n)
        if err != nil { break }

        a := make([]int, n + 1)
        fmt.Scan(&s)
        for i := 0; i < len(s); i++ {
            a[i + 1] = int(s[i]) - int('a');
        }

        var f [26][2][1501]int
        var g [26][2][1501]int

        var x int
        for c := 0; c < 26; c++ {
            prev := 0
            var now int

            for i := 1; i <= n; i++ {
                now = (prev + 1) % 2

                f[c][now][0] = f[c][prev][0]
                if a[i] == c {
                    g[c][now][0] = 1 + g[c][prev][0]
                }
                f[c][now][0] = maxInt(f[c][prev][0], g[c][now][0])

                for j := 1; j <= i; j++ {
                    g[c][now][j] = g[c][now][j-1]

                    if a[i] == c {
                        g[c][now][j] = maxInt(g[c][now][j], g[c][prev][j] + 1)
                    } else {
                        g[c][now][j] = maxInt(g[c][now][j], g[c][prev][j-1] + 1)
                    }

                    f[c][now][j] = maxInt(f[c][now][j-1], f[c][prev][j])
                    f[c][now][j] = maxInt(f[c][now][j], g[c][now][j])
                }

                prev = now
            }

            x = now
        }

        fmt.Scan(&q)
        for i := 0; i < q; i++ {
            var str string
            fmt.Scan(&mm, &str)
            var c int = int(str[0]) - int('a')
            fmt.Println(f[c][x][mm])
        }
    }
}

package main

// Solution for https://codeforces.com/problemset/problem/814/C

import (
	"fmt"
)

func main() {
	var n, q int
	var s string
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%s\n", &s)
	fmt.Scanf("%d\n", &q)

	reals := []byte(s)
	for i := range reals {
		reals[i] -= 'a'
	}

	m := make([]int16, q)
	c := make([]byte, q)
	var maxm [26]int16

	var mi int16
	var ci string
	for i := 0; i < q; i++ {
		fmt.Scanf("%d", &mi)
		fmt.Scanf("%s\n", &ci)
		realc := ci[0] - 'a'
		m[i] = mi
		c[i] = realc
		if maxm[realc] < mi {
			maxm[realc] = mi
		}
	}

	var goods [26][]int16

	for a := byte(0); a < 26; a++ {
		maxm1 := maxm[a]
		if maxm1 == 0 {
			continue
		}
		firstGood := reals[0] == a
		prevGood := firstGood
		islands := []int16{1}
		for i := 1; i < n; i++ {
			good := reals[i] == a
			if good == prevGood {
				islands[len(islands)-1]++
			} else {
				islands = append(islands, 1)
			}
			prevGood = good
		}

		// Convert it to list of pairs (good, bad).
		if !prevGood {
			islands = islands[1:]
		}
		if len(islands)%2 == 1 {
			islands = append(islands, 0)
		}

		maxGood := make([]int16, maxm1+1) // Key is required badness.
		nislands := len(islands) / 2
		for from := 0; from < nislands; from++ {
			goodness := islands[from*2]
			badness := int16(0)
			if maxGood[badness] < goodness {
				maxGood[badness] = goodness
			}
			for to := from + 1; to < nislands; to++ {
				goodness += islands[to*2-1] + islands[to*2]
				badness += islands[to*2-1]
				if badness > maxm1 {
					break
				}
				if maxGood[badness] < goodness {
					maxGood[badness] = goodness
				}
			}
		}

		for badness := int16(1); badness <= maxm1; badness++ {
			if maxGood[badness] < maxGood[badness-1]+1 {
				maxGood[badness] = maxGood[badness-1] + 1
			}
			if maxGood[badness] > int16(n) {
				maxGood[badness] = int16(n)
			}
		}

		goods[a] = maxGood
	}

	for i := 0; i < q; i++ {
		fmt.Println(goods[c[i]][m[i]])
	}
}

package main

// Solution for https://codeforces.com/problemset/problem/814/C

import (
	"fmt"
)

func main() {
	var n, q int
	var s string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)
	fmt.Scanf("%d", &q)

	reals := []byte(s)
	for i := range reals {
		reals[i] -= 'a'
	}

	m := make([]int16, q)
	c := make([]byte, q)
	var maxm [26]int16

	var mi int16
	var ci string
	for i := 0; i < q; i++ {
		fmt.Scanf("%d", &mi)
		fmt.Scanf("%s", &ci)
		realc := ci[0] - 'a'
		m[i] = mi
		c[i] = realc
		if maxm[realc] < mi {
			maxm[realc] = mi
		}
	}

	var goods [26][]int16

	for a := byte(0); a < 26; a++ {
		maxm1 := maxm[a]
		if maxm1 == 0 {
			continue
		}
		firstGood := reals[0] == a
		prevGood := firstGood
		islands := []int16{1}
		for i := 1; i < n; i++ {
			good := reals[i] == a
			if good == prevGood {
				islands[len(islands)-1]++
			} else {
				islands = append(islands, 1)
			}
			prevGood = good
		}

		// Convert it to list of pairs (good, bad).
		if !prevGood {
			islands = islands[1:]
		}
		if len(islands)%2 == 1 {
			islands = append(islands, 0)
		}

		maxGood := make([]int16, maxm1+1) // Key is required badness.
		nislands := len(islands) / 2
		for from := 0; from < nislands; from++ {
			goodness := islands[from*2]
			badness := int16(0)
			if maxGood[badness] < goodness {
				maxGood[badness] = goodness
			}
			for to := from + 1; to < nislands; to++ {
				goodness += islands[to*2-1] + islands[to*2]
				badness += islands[to*2-1]
				if badness > maxm1 {
					break
				}
				if maxGood[badness] < goodness {
					maxGood[badness] = goodness
				}
			}
		}

		for badness := int16(1); badness <= maxm1; badness++ {
			if maxGood[badness] < maxGood[badness-1]+1 {
				maxGood[badness] = maxGood[badness-1] + 1
			}
		}

		goods[a] = maxGood
	}

	for i := 0; i < q; i++ {
		fmt.Println(goods[c[i]][m[i]])
	}
}

package main

// Solution for https://codeforces.com/problemset/problem/814/C

import (
	"fmt"
)

func main() {
	var n, q int
	var s string
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%s\n", &s)
	fmt.Scanf("%d\n", &q)

	reals := []byte(s)
	for i := range reals {
		reals[i] -= 'a'
	}

	m := make([]int16, q)
	c := make([]byte, q)
	var maxm [26]int16

	var mi int16
	var ci string
	for i := 0; i < q; i++ {
		fmt.Scanf("%d", &mi)
		fmt.Scanf("%s\n", &ci)
		realc := ci[0] - 'a'
		m[i] = mi
		c[i] = realc
		if maxm[realc] < mi {
			maxm[realc] = mi
		}
	}

	var goods [26][]int16

	for a := byte(0); a < 26; a++ {
		maxm1 := maxm[a]
		if maxm1 == 0 {
			continue
		}
		firstGood := reals[0] == a
		prevGood := firstGood
		islands := []int16{1}
		for i := 1; i < n; i++ {
			good := reals[i] == a
			if good == prevGood {
				islands[len(islands)-1]++
			} else {
				islands = append(islands, 1)
			}
			prevGood = good
		}

		// Convert it to list of pairs (good, bad).
		if !prevGood {
			islands = islands[1:]
		}
		if len(islands)%2 == 1 {
			islands = append(islands, 0)
		}

		maxGood := make([]int16, maxm1+1) // Key is required badness.
		nislands := len(islands) / 2
		for from := 0; from < nislands; from++ {
			goodness := islands[from*2]
			badness := int16(0)
			if maxGood[badness] < goodness {
				maxGood[badness] = goodness
			}
			for to := from + 1; to < nislands; to++ {
				goodness += islands[to*2-1] + islands[to*2]
				badness += islands[to*2-1]
				if badness > maxm1 {
					break
				}
				if maxGood[badness] < goodness {
					maxGood[badness] = goodness
				}
			}
		}

		for badness := int16(1); badness <= maxm1; badness++ {
			if maxGood[badness] < maxGood[badness-1]+1 {
				maxGood[badness] = maxGood[badness-1] + 1
			}
		}

		goods[a] = maxGood
	}

	for i := 0; i < q; i++ {
		fmt.Println(goods[c[i]][m[i]])
	}
}