There are $$$n$$$ segments on a $$$Ox$$$ axis $$$[l_1, r_1]$$$, $$$[l_2, r_2]$$$, ..., $$$[l_n, r_n]$$$. Segment $$$[l, r]$$$ covers all points from $$$l$$$ to $$$r$$$ inclusive, so all $$$x$$$ such that $$$l \le x \le r$$$.Segments can be placed arbitrarily  — be inside each other, coincide and so on. Segments can degenerate into points, that is $$$l_i=r_i$$$ is possible.Union of the set of segments is such a set of segments which covers exactly the same set of points as the original set. For example:  if $$$n=3$$$ and there are segments $$$[3, 6]$$$, $$$[100, 100]$$$, $$$[5, 8]$$$ then their union is $$$2$$$ segments: $$$[3, 8]$$$ and $$$[100, 100]$$$;  if $$$n=5$$$ and there are segments $$$[1, 2]$$$, $$$[2, 3]$$$, $$$[4, 5]$$$, $$$[4, 6]$$$, $$$[6, 6]$$$ then their union is $$$2$$$ segments: $$$[1, 3]$$$ and $$$[4, 6]$$$. Obviously, a union is a set of pairwise non-intersecting segments.You are asked to erase exactly one segment of the given $$$n$$$ so that the number of segments in the union of the rest $$$n-1$$$ segments is maximum possible.For example, if $$$n=4$$$ and there are segments $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$, then:  erasing the first segment will lead to $$$[2, 3]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union;  erasing the second segment will lead to $$$[1, 4]$$$, $$$[3, 6]$$$, $$$[5, 7]$$$ remaining, which have $$$1$$$ segment in their union;  erasing the third segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[5, 7]$$$ remaining, which have $$$2$$$ segments in their union;  erasing the fourth segment will lead to $$$[1, 4]$$$, $$$[2, 3]$$$, $$$[3, 6]$$$ remaining, which have $$$1$$$ segment in their union. Thus, you are required to erase the third segment to get answer $$$2$$$.Write a program that will find the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.Note that if there are multiple equal segments in the given set, then you can erase only one of them anyway. So the set after erasing will have exactly $$$n-1$$$ segments.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. Then the descriptions of $$$t$$$ test cases follow. The first of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the number of segments in the given set. Then $$$n$$$ lines follow, each contains a description of a segment — a pair of integers $$$l_i$$$, $$$r_i$$$ ($$$-10^9 \le l_i \le r_i \le 10^9$$$), where $$$l_i$$$ and $$$r_i$$$ are the coordinates of the left and right borders of the $$$i$$$-th segment, respectively. The segments are given in an arbitrary order. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

Print $$$t$$$ integers — the answers to the $$$t$$$ given test cases in the order of input. The answer is the maximum number of segments in the union of $$$n-1$$$ segments if you erase any of the given $$$n$$$ segments.

package main

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

type node struct {
	left  int
	right int
}

type ByLeft []node

func (a ByLeft) Len() int           { return len(a) }
func (a ByLeft) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByLeft) Less(i, j int) bool { return a[i].left < a[j].left }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := []node{}
		for i := 0; i < n; i++ {
			l, r := 0, 0
			fmt.Fscanf(in, "%d %d\n", &l, &r)
			a = append(a, node{l, r})
		}
		sort.Sort(ByLeft(a))
		curBoard := a[0]
		curOnTopNum := 0
		curOnTopRight := a[0].left - 1
		ans := 0
		for i := 1; i < n; i++ {
			next := a[i]
			if next.left > curOnTopRight {
				if next.left <= curBoard.right {
					curOnTopNum++
					ans = max(ans, curOnTopNum)
					if next.right > curOnTopRight {
						curOnTopRight = next.right
					}
					if curOnTopRight > curBoard.right {
						nextRight := curBoard.right
						curBoard = next
						curOnTopNum = 1
						curOnTopRight = nextRight
					}
				} else {
					// change board
					curBoard = next
					curOnTopNum = 0
					curOnTopRight = curBoard.left - 1
				}
			} else {
				curOnTopRight = max(curOnTopRight, next.right)
				if curOnTopRight > curBoard.right {
					nextRight := curBoard.right
					curBoard = next
					curOnTopNum = 1
					curOnTopRight = nextRight
				}
			}
			//fmt.Println(curBoard, curOnTopNum, curOnTopRight, ans)
		}
		curAns := 1
		curRight := a[0].right
		for i := 1; i < n; i++ {
			if a[i].left > curRight {
				curAns++
			}
			curRight = max(curRight, a[i].right)
		}
		//fmt.Println(curAns)
		fmt.Fprintf(out, "%d\n", curAns+ans-1)
	}
	return
}

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

package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

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

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

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 {
			fmt.Fprint(wr, " ")
		}
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

var (
	T     int
	n     int
	hsLen int
	l     []int
	r     []int
	hs    []int
	cnt   []int
	pcnt  []int
	id    []int
	pid   []int
	ans   []int
)

func unique(a []int) []int {
	n := len(a)
	if n == 0 {
		return a
	}
	var cur []int
	cur = append(cur, a[0])
	for i := 1; i < n; i++ {
		if a[i] != a[i-1] {
			cur = append(cur, a[i])
		}
	}
	return cur
}

func lowerBound(a []int, value int) int {
	low, high, mid := 0, len(a), 0
	for low <= high {
		mid = (low + high) >> 1
		if a[mid] < value {
			low = mid + 1
		} else if a[mid] > value {
			high = mid - 1
		} else {
			break
		}
	}
	return mid
}

func calc(l, r int) int {
	ret := -1
	if l-1 >= 0 && cnt[l-1] > 0 || pcnt[l] > 1 {
		ret++
	}
	if r+1 < hsLen-1 && cnt[r+1] > 0 || pcnt[r+1] > 1 {
		ret++
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	T = scanInt()
	for cas := 0; cas < T; cas++ {
		n = scanInt()
		l = make([]int, n)
		r = make([]int, n)
		ans = make([]int, n)
		hs = make([]int, 0)
		for i := 0; i < n; i++ {
			l[i] = scanInt()
			r[i] = scanInt()
			hs = append(hs, l[i])
			hs = append(hs, r[i])
			hs = append(hs, r[i]+1)
		}
		sort.Ints(hs)
		hs = unique(hs)
		hsLen = len(hs)
		cnt = make([]int, len(hs))
		id = make([]int, len(hs))
		pid = make([]int, len(hs))
		pcnt = make([]int, len(hs))
		for i := 0; i < n; i++ {
			l[i] = lowerBound(hs, l[i])
			r[i] = lowerBound(hs, r[i])
			cnt[l[i]]++
			cnt[r[i]]--
			pcnt[l[i]]++
			pcnt[r[i]+1]--
			id[l[i]] += i
			id[r[i]] -= i
			pid[l[i]] += i
			pid[r[i]+1] -= i
		}
		for i := 1; i < hsLen; i++ {
			cnt[i] += cnt[i-1]
			id[i] += id[i-1]
			pcnt[i] += pcnt[i-1]
			pid[i] += pid[i-1]
		}

		cur := 0
		for i, j := 0, 0; i < hsLen-1; i = j + 1 {
			j = i
			if cnt[i] == 0 {
				continue
			}
			cur++
			for j+1 < hsLen-1 && cnt[j+1] != 0 {
				j++
			}
		}
		for i := 0; i < hsLen; i++ {
			if pcnt[i] > 0 {
				if (i == 0 || cnt[i-1] == 0) && cnt[i] == 0 {
					cur++
				}
			}
		}
		for i, j := 0, 0; i < hsLen-1; i = j + 1 {
			j = i
			if cnt[i] != 1 {
				continue
			}
			for j+1 < hsLen-1 && cnt[j+1] == 1 && id[j+1] == id[i] && pcnt[j+1] == 1 {
				j++
			}
			ans[id[i]] += calc(i, j)
		}
		ret := 0
		for i := 0; i < n; i++ {
			ans[i] += cur
			if l[i] == r[i] {
				p := l[i]
				if pcnt[p] == 1 && (p == 0 || cnt[p-1] == 0) && cnt[p] == 0 {
					ans[i]--
				}
			}
			if ans[i] > ret {
				ret = ans[i]
			}
		}
		fmt.Println(ret)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"sync"
)
type node struct {
	l int
	r int
}
type Node []node
func (a Node) Len() int { return len(a) }
func (a Node) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Node) Less(i, j int) bool {
	if a[i].l == a[j].l {
		return a[i].r < a[j].r
	}
	return a[i].l < a[j].l
}

type Seg struct {
	tag, sum, L, R int
}
var cat [400001 * 4]Seg
func pushdown(o, ls, rs int) {
	if cat[o].tag == 1 {
		cat[ls].sum, cat[ls].tag, cat[rs].sum, cat[rs].tag = 1, 1, 1, 1
		cat[ls].L = min(cat[ls].L, cat[o].L)
		cat[ls].R = max(cat[ls].R, cat[o].R)
		cat[rs].L = min(cat[rs].L, cat[o].L)
		cat[rs].R = max(cat[rs].R, cat[o].R)
		cat[o].tag = 0
	}
}
func pushup(ls, rs Seg) Seg {
	tmp := Seg{}
	tmp.tag = 0
	tmp.sum = ls.sum + rs.sum
	tmp.L = ls.L
	tmp.R = rs.R
	if ls.R > rs.L {
		tmp.sum--
	}
	return tmp
}
func up(o, l, r, ql, qr int) {
	if l >= ql && r <= qr {
		cat[o].tag, cat[o].sum = 1, 1
		cat[o].L = min(cat[o].L, ql)
		cat[o].R = max(cat[o].R, qr)
		return
	}
	mid, ls, rs := (l + r) / 2, o * 2, o * 2 + 1
	pushdown(o, ls, rs)
	if ql <= mid {
		up(ls, l, mid, ql, qr)
	}
	if qr > mid {
		up(rs, mid + 1, r, ql, qr)
	}
	cat[o] = pushup(cat[ls], cat[rs])
}
func qu(o, l, r, ql, qr int) Seg {
	if l >= ql && r <= qr {
		return cat[o]
	}
	mid, ls, rs := (l + r) / 2, o * 2, o * 2 + 1
	pushdown(o, ls, rs)
	if qr <= mid {
		return qu(ls, l, mid, ql, qr)
	} else if ql > mid {
		return qu(rs, mid + 1, r, ql, qr)
	} else {
		Ls := qu(ls, l, mid, ql, qr)
		Rs := qu(rs, mid + 1, r, ql, qr)
		return pushup(Ls, Rs)
	}
}
const inf int = 1000000001
func work() {
	n := ReadInt()
	a := []node{}
	x := []int{}

    a = append(a, node{-inf, 0})
    x = append(x, -inf)
	for i := 1; i <= n; i++ {
		l := ReadInt()
		r := ReadInt()
		a = append(a, node{l, r})
		x = append(x, l)
		x = append(x, r)
	}
	sort.Ints(x)
	sort.Sort(Node(a))
	mp := map[int]int{}
	for i := 1; i <= 2 * n; i++ {
		mp[x[i]] = i
	}
	A := make([]int, n + 1)
	m := 2 * n
	Mx := make([]int, n + 1)
	Mn := make([]int, m + 1)
	for i := 1; i <= m; i++ {
		Mn[i] = i
	}
	mx, L := 0, 0
	for i := 1; i <= n; i++ {
		a[i].l = mp[a[i].l]
		a[i].r = mp[a[i].r]
		A[i] = A[i - 1]
		if a[i].l > mx {
			A[i]++
			L = a[i].l
		}
		mx = max(mx, a[i].r)
		Mx[i] = mx
		Mn[mx] = L
	}
	for i := 1; i <= 4 * m; i++ {
		cat[i].R, cat[i].sum, cat[i].tag = 0, 0, 0
		cat[i].L = m + 1
	}
	ans := 0
	for i := n; i > 0; i-- {
		flag := 0
		if i > 1 {
			flag = qu(1, 1, m,Mn[Mx[i - 1]], Mx[i - 1]).sum
		}
		ans = max(ans, A[i - 1] + cat[1].sum - flag)
		up(1, 1, m, a[i].l, a[i].r)
	}
	fmt.Println(ans)
}
func main() {
	for i := ReadInt(); i > 0; i-- {
		work()
	}
	close(out)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _  := strconv.Atoi(intStr)
	return i
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}

package main

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

type node struct {
	left  int
	right int
}

type ByLeft []node

func (a ByLeft) Len() int           { return len(a) }
func (a ByLeft) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByLeft) Less(i, j int) bool { return a[i].left < a[j].left }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n := 0
		fmt.Fscanf(in, "%d\n", &n)
		a := []node{}
		for i := 0; i < n; i++ {
			l, r := 0, 0
			fmt.Fscanf(in, "%d %d\n", &l, &r)
			a = append(a, node{l, r})
		}
		sort.Sort(ByLeft(a))
		curBoard := a[0]
		curOnTopNum := 0
		curOnTopRight := a[0].left - 1
		ans := 0
		for i := 1; i < n; i++ {
			next := a[i]
			if next.left > curOnTopRight {
				if next.left <= curBoard.right {
					curOnTopNum++
					ans = max(ans, curOnTopNum)
					if next.right > curOnTopRight {
						curOnTopRight = next.right
					}
					if curOnTopRight > curBoard.right {
						nextRight := curBoard.right
						curBoard = next
						curOnTopNum = 1
						curOnTopRight = nextRight
					}
				} else {
					if curOnTopNum > ans {
						ans = curOnTopNum
					}
					// change board
					curBoard = next
					curOnTopNum = 0
					curOnTopRight = curBoard.left - 1
				}
			} else {
				curOnTopRight = max(curOnTopRight, next.right)
				if curOnTopRight > curBoard.right {
					nextRight := curBoard.right
					curBoard = next
					curOnTopNum = 1
					curOnTopRight = nextRight
				}
			}
		}
		curAns := 1
		curRight := a[0].right
		for i := 1; i < n; i++ {
			if a[i].left > curRight {
				curAns++
			}
			curRight = max(curRight, a[i].right)
		}
		if ans == 0 {
			ans = 1
		}
		fmt.Fprintf(out, "%d\n", curAns+ans-1)
	}
	return
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"sync"
)
type node struct {
	l int
	r int
}
type Node []node
func (a Node) Len() int { return len(a) }
func (a Node) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a Node) Less(i, j int) bool {
	if a[i].l == a[j].l {
		return a[i].r < a[j].r
	}
	return a[i].l < a[j].l
}

type Seg struct {
	tag, sum, L, R int
}
var cat [200001 * 4]Seg
func pushdown(o, ls, rs int) {
	if cat[o].tag == 1 {
		cat[ls].sum, cat[ls].tag, cat[rs].sum, cat[rs].tag = 1, 1, 1, 1
		cat[ls].L = min(cat[ls].L, cat[o].L)
		cat[ls].R = max(cat[ls].R, cat[o].R)
		cat[rs].L = min(cat[rs].L, cat[o].L)
		cat[rs].R = max(cat[rs].R, cat[o].R)
		cat[o].tag = 0
	}
}
func pushup(ls, rs Seg) Seg {
	tmp := Seg{}
	tmp.tag = 0
	tmp.sum = ls.sum + rs.sum
	tmp.L = ls.L
	tmp.R = rs.R
	if ls.R > rs.L {
		tmp.sum--
	}
	return tmp
}
func up(o, l, r, ql, qr int) {
	if l >= ql && r <= qr {
		cat[o].tag, cat[o].sum = 1, 1
		cat[o].L = min(cat[o].L, ql)
		cat[o].R = max(cat[o].R, qr)
		return
	}
	mid, ls, rs := (l + r) / 2, o * 2, o * 2 + 1
	pushdown(o, ls, rs)
	if ql <= mid {
		up(ls, l, mid, ql, qr)
	}
	if qr > mid {
		up(rs, mid + 1, r, ql, qr)
	}
	cat[o] = pushup(cat[ls], cat[rs])
}
func qu(o, l, r, ql, qr int) Seg {
	if l >= ql && r <= qr {
		return cat[o]
	}
	mid, ls, rs := (l + r) / 2, o * 2, o * 2 + 1
	pushdown(o, ls, rs)
	if qr <= mid {
		return qu(ls, l, mid, ql, qr)
	} else if ql > mid {
		return qu(rs, mid + 1, r, ql, qr)
	} else {
		Ls := qu(ls, l, mid, ql, qr)
		Rs := qu(rs, mid + 1, r, ql, qr)
		return pushup(Ls, Rs)
	}
}
func work() {
	n := ReadInt()
	a := []node{}
	x := []int{}

    a = append(a, node{0, 0})
    x = append(x, 0)
	for i := 1; i <= n; i++ {
		l := ReadInt()
		r := ReadInt()
		a = append(a, node{l, r})
		x = append(x, l)
		x = append(x, r)
	}
	sort.Ints(x)
	sort.Sort(Node(a))
	mp := map[int]int{}
	for i := 1; i <= 2 * n; i++ {
		mp[x[i]] = i
	}
	A := make([]int, n + 1)
	m := 2 * n
	Mx := make([]int, n + 1)
	Mn := make([]int, m + 1)
	for i := 1; i <= m; i++ {
		Mn[i] = i
	}
	mx, L := 0, 0
	for i := 1; i <= n; i++ {
		a[i].l = mp[a[i].l]
		a[i].r = mp[a[i].r]
		A[i] = A[i - 1]
		if a[i].l > mx {
			A[i]++
			L = a[i].l
		}
		mx = max(mx, a[i].r)
		Mx[i] = mx
		Mn[mx] = L
	}
	for i := 1; i <= 4 * m; i++ {
		cat[i].R, cat[i].sum, cat[i].tag = 0, 0, 0
		cat[i].L = m + 1
	}
	ans := 0
	for i := n; i > 0; i-- {
		flag := 0
		if i > 1 {
			flag = qu(1, 1, m,Mn[Mx[i - 1]], Mx[i - 1]).sum
		}
		ans = max(ans, A[i - 1] + cat[1].sum - flag)
		up(1, 1, m, a[i].l, a[i].r)
	}
	fmt.Println(ans)
}
func main() {
	for i := ReadInt(); i > 0; i-- {
		work()
	}
	close(out)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup
func ReadString() string {
	in.Scan()
	return in.Text()
}
func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}
func ReadInt() int {
	intStr := ReadString()
	i, _  := strconv.Atoi(intStr)
	return i
}
func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt()
	}
	return arr
}
func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	//set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(write *bufio.Writer) {
		defer outWg.Done()
		defer write.Flush()

		for line := range out {
			write.WriteString(line + "\n")
		}
	}(writer)
}


You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft $$$k$$$ torches. One torch can be crafted using one stick and one coal.Hopefully, you've met a very handsome wandering trader who has two trade offers:  exchange $$$1$$$ stick for $$$x$$$ sticks (you lose $$$1$$$ stick and gain $$$x$$$ sticks).  exchange $$$y$$$ sticks for $$$1$$$ coal (you lose $$$y$$$ sticks and gain $$$1$$$ coal). During one trade, you can use only one of these two trade offers. You can use each trade offer any number of times you want to, in any order.Your task is to find the minimum number of trades you need to craft at least $$$k$$$ torches. The answer always exists under the given constraints.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains three integers $$$x$$$, $$$y$$$ and $$$k$$$ ($$$2 \le x \le 10^9$$$; $$$1 \le y, k \le 10^9$$$) — the number of sticks you can buy with one stick, the number of sticks required to buy one coal and the number of torches you need, respectively.

For each test case, print the answer: the minimum number of trades you need to craft at least $$$k$$$ torches. The answer always exists under the given constraints.

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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
}

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

func Gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return Gcd(b, a%b)
}

const mod = 1000000007

func Add(a, b int64) int64 {
	return (a + b) % mod
}

func Mult(a, b int64) int64 {
	return (a * b) % mod
}

func Sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	x, y, k := nextLong()-1, nextLong(), nextLong()
	printf("%d\n", k+((y+1)*k+x-2)/x)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "foreign"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create(name + ".out")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// 	printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	var testCases int64
	fmt.Sscanf(tc, "%d", &testCases)
	for testCases > 0 {
		input, _ := reader.ReadString('\n')
		var x, y, k int64
		var mul, result, rem int64

		fmt.Sscanf(input, "%d %d %d", &x, &y, &k)

		mul = k * (y + 1)
		rem = (mul - 1) % (x - 1)

		if rem == 0 {
			result = (mul-1)/(x-1) + k
		} else {
			result = (mul-1)/(x-1) + k + 1
		}

		fmt.Println(result)

		testCases--

	}

}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		x, y, k := readThreeNums(reader)

		res := solve(x, y, k)

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(x int, y int, k int) int64 {
	X, Y, K := int64(x), int64(y), int64(k)

	N := (K*Y + K - 1 + X - 2) / (X - 1)
	return N + K
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		var x, y, k int64
		scanf("%d %d %d\n", &x, &y, &k)

		printf("%d\n", calc(x, y, k))
	}
}

func calc(x, y, k int64) int64 {
	reqS := k + (k * y)                // required sticks
	reqC := k + ((reqS - 1) / (x - 1)) // required conversions

	if (reqS-1)%(x-1) != 0 {
		reqC++
	}

	return reqC
}

package main

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

func main(){
	var (
		t int
		x,y,k,ans uint64
	)
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &t)
	for i:=1;i<=t;i++{
		fmt.Fscan(in, &x, &y, &k)
		ans = k
		k = (k*(y+1)-1)
		x--
		if(k%x==0){
			ans = ans + k/x
		}else{
			ans = ans + k/x + 1
		}
		fmt.Fprintln(out, ans)
	}
	out.Flush()
}

/*
URL:
https://codeforces.com/contest/1418/problem/A
*/

package main

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

var (
	t int

	x, y, k int64
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		x, y, k = readll3()

		solve()
	}
}

func solve() {
	bunshi := k*(1+y) - 1
	bunbo := x - 1

	s := Kiriage(bunshi, bunbo)

	fmt.Println(s + k)
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int64) int64 {
	return (a + (b - 1)) / b
}

/*******************************************************************/

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
)

// modi can calculate a right residual whether value is positive or negative.
func modi(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// modll can calculate a right residual whether value is positive or negative.
func modll(val, m int64) int64 {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

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

func solve() {
	t := readInt()
	for i := 0; i < t; i++ {
		x := readInt64()
		y := readInt64()
		k := readInt64()
		reqX := k + y * k - 1

		steps := (reqX + (x - 2)) / (x - 1)
		fmt.Println(steps + k)
	}
}

var scanner *bufio.Scanner

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

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

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

// IO

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

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

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

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

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

package main

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

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

	var T, x, y, k int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x, &y, &k)
		t := ((y+1)*k-2)/(x-1) + 1
		Fprintln(out, t+k)
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var t int
	var x, y, k, ans int64
	scan(&t)
	for ; t > 0; t--{
		scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		print(ans, "\n")
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

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

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var t int
	var x, y, k, ans int64
	scan(&t)
	for ; t > 0; t--{
		scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		print(ans, "\n")
	}
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	tt := rw.NextInt()
	for i := 0; i < tt; i++ {
		solveCase()
	}
}

func solveCase() {
	x, y, k := rw.NextInt64(), rw.NextInt64(), rw.NextInt64()
	// y * k <= (x - 1) * t
	t := (y*k + x - 2) / (x - 1)
	s := t*(x-1) + 1 - y*k
	if s < k {
		t += (k - s + x - 2) / (x - 1)
	}
	rw.Println(t + k)
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

func ceild(num, denom int64) int64 {
	return (num + denom - 1) / denom
}

func solve(r *bufio.Reader, w *bufio.Writer) {
	var x, y, k int64
	fmt.Fscanln(r, &x, &y, &k)
	trades := ceild(k*(y+1)-1, x-1)
	trades += k
	fmt.Fprintln(w, trades)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var t int
	fmt.Fscanln(reader, &t)
	for ; t > 0; t-- {
		solve(reader, writer)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	lst := strings.Split(tc, " ")
	testCases, _ := strconv.Atoi(lst[0])
	for testCases > 0 {
		input, _ := reader.ReadString('\n')

		list := strings.Split(input, " ")
		var a, b, c int
		var x, y, k int64
		a, _ = strconv.Atoi(list[0])
		b, _ = strconv.Atoi(list[1])
		c, _ = strconv.Atoi(list[2])

		x, y, k = int64(a), int64(b), int64(c)
		var result, sticks, coals int64 = 0, 1, 0
		var tarSticks, tarCoals int64 = k, k

		for {
			if sticks >= tarSticks && coals >= tarCoals {
				fmt.Println(result)
				break
			}

			if !(sticks >= k) {

				sticks--
				sticks += x
				result++

			}

			if !(coals >= k) {
				sticks -= y
				coals++
				result++

			}
		}
		testCases--
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	lst := strings.Split(tc, " ")
	testCases, _ := strconv.Atoi(lst[0])
	for testCases > 0 {
		input, _ := reader.ReadString('\n')

		list := strings.Split(input, " ")
		var x, y, k int64
		x, _ = strconv.ParseInt(list[0], 10, 64)
		y, _ = strconv.ParseInt(list[1], 10, 64)
		k, _ = strconv.ParseInt(list[2], 10, 64)

		var result, sticks, coals int64 = 0, 1, 0
		var tarSticks, tarCoals int64 = k, k

		for {
			if sticks >= tarSticks && coals >= tarCoals {
				fmt.Println(result)
				break
			}

			if !(sticks >= k) {

				sticks--
				sticks += x
				result++

			}

			if !(coals >= k) {
				sticks -= y
				coals++
				result++

			}
		}
		testCases--
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	lst := strings.Split(tc, " ")
	testCases, _ := strconv.Atoi(lst[0])
	for testCases > 0 {
		input, _ := reader.ReadString('\n')

		list := strings.Split(input, " ")
		var x, y, k int64
		x, _ = strconv.ParseInt(list[0], 10, 64)
		y, _ = strconv.ParseInt(list[1], 10, 64)
		k, _ = strconv.ParseInt(list[2], 10, 64)

		var result, sticks, coals int64 = 0, 1, 0
		var tarSticks, tarCoals int64 = k, k

		for {
			if sticks >= tarSticks && coals >= tarCoals {
				fmt.Printf("%d\n", result)
				break
			}

			if !(sticks >= k) {

				sticks--
				sticks += x
				result++

			}

			if !(coals >= k) {
				sticks -= y
				coals++
				result++

			}
		}
		testCases--
	}

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	tc, _ := reader.ReadString('\n')
	lst := strings.Split(tc, " ")
	testCases, _ := strconv.Atoi(lst[0])
	for testCases > 0 {
		input, _ := reader.ReadString('\n')

		list := strings.Split(input, " ")
		var x, y, k int64
		x, _ = strconv.ParseInt(list[0], 10, 64)
		y, _ = strconv.ParseInt(list[1], 10, 64)
		k, _ = strconv.ParseInt(list[2], 10, 64)

		var result, sticks, coals int64 = 0, 1, 0
		var tarSticks, tarCoals int64 = k, k

		for {

			if x == 1 && y == 1 && k == 1 {
				break
			}

			if sticks >= tarSticks && coals >= tarCoals {
				fmt.Printf("%d\n", result)
				break
			}

			if !(sticks >= k) {

				sticks--
				sticks += x
				result++

			}

			if !(coals >= k) {
				sticks -= y
				coals++
				result++

			}
		}
		testCases--
	}

}

package main

import "fmt"

func main() {
	var x, y, k int64
	fmt.Scanf("%d %d %d", &x, &y, &k)
	var result, sticks, coals int64 = 0, 1, 0
	var tarSticks, tarCoals int64 = k, k

	for {
		if sticks >= tarSticks && coals >= tarCoals {
			fmt.Println(result)
			break
		}

		if !(sticks >= k) {

			sticks--
			sticks += x
			result++

		}

		if !(coals >= k) {
			sticks -= y
			coals++
			result++

		}
	}
}

package main

import "fmt"

func main() {
	var t int
	_, err := fmt.Scanf("%d\n", &t)
	if err != nil {
		panic(err)
	}

	for i := 0; i < t; i++ {
		var x, y, k int
		_, err := fmt.Scanf("%d %d %d\n", &x, &y, &k)
		if err != nil {
			panic(err)
		}

		fmt.Println(calc(x, y, k))
	}
}

func calc(x, y, k int) int {
	reqS := k + (k * y)                // required sticks
	reqC := k + ((reqS - 1) / (x - 1)) // required conversions

	if (reqS-1)%(x-1) != 0 {
		reqC += 1
	}

	return reqC
}

package main

import "fmt"

func main() {
	var t int
	_, err := fmt.Scanf("%d\n", &t)
	if err != nil {
		panic(err)
	}

	for i := 0; i < t; i++ {
		var x, y, k int
		_, err := fmt.Scanf("%d %d %d\n", &x, &y, &k)
		if err != nil {
			panic(err)
		}

		fmt.Printf("%d\n", calc(x, y, k))
	}
}

func calc(x, y, k int) int {
	reqS := k + (k * y)                // required sticks
	reqC := k + ((reqS - 1) / (x - 1)) // required conversions

	if (reqS-1)%(x-1) != 0 {
		reqC++
	}

	return reqC
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++{
		var x, y, k, ans int64
		fmt.Scan(x,y,k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++{
		var x, y, k, ans int
		fmt.Scan(&x, &y, &k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		fmt.Println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var x, y, k, ans int64
	fmt.Scan(&t)
	for ; t > 1; t--{
		fmt.Scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		fmt.Println(ans)
	}
}

package main

import "fmt"

func main() {
	var t int16
	fmt.Scan(&t)
	for ; t > 0; t--{
		var x, y, k, ans int64
		fmt.Scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		println(ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var a string
	var t int16
	var x, y, k, ans int64
	fmt.Scan(&t)
	for ; t > 0; t--{
		fmt.Scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		a += string(ans) + " "
	}
	fmt.Println(a)
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++{
		var x, y, k, ans int
		fmt.Scan(&x)
		fmt.Scan(&y)
		fmt.Scan(&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r *bufio.Reader = bufio.NewReader(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

func main() {
	defer w.Flush()

	var a string
	fmt.Scan(&a)

	var h = "hello"
	var index = 0
	for i := 0; i < len(a) && index < 5; i++{
		if h[index] == a[i]  {
			index++
		}
	}
	if index >= 5 {
		print("YES")
	}else {
		print("NO")
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	var x, y, k, ans int64
	fmt.Scan(&t)
	for ; t > 1; t--{
		fmt.Scan(&x,&y,&k)
		ans = k
		k += k*y
		ans += (k-1)/(x-1)
		if (k-1)%(x-1) != 0 {
			ans++;
		}
		fmt.Println(ans,t)
	}
}


A progress bar is an element of graphical interface that displays the progress of a process for this very moment before it is completed. Let's take a look at the following form of such a bar.A bar is represented as n squares, located in line. To add clarity, let's number them with positive integers from 1 to n from the left to the right. Each square has saturation (ai for the i-th square), which is measured by an integer from 0 to k. When the bar for some i (1 ≤ i ≤ n) is displayed, squares 1, 2, ... , i - 1 has the saturation k, squares i + 1, i + 2, ... , n has the saturation 0, and the saturation of the square i can have any value from 0 to k.So some first squares of the progress bar always have the saturation k. Some last squares always have the saturation 0. And there is no more than one square that has the saturation different from 0 and k.The degree of the process's completion is measured in percents. Let the process be t% completed. Then the following inequation is fulfilled: An example of such a bar can be seen on the picture.  For the given n, k, t determine the measures of saturation for all the squares ai of the progress bar.

We are given 3 space-separated integers n, k, t (1 ≤ n, k ≤ 100, 0 ≤ t ≤ 100).

Print n numbers. The i-th of them should be equal to ai.

package main
import "fmt"

func main(){
	var n,k,t,pr float64
	fmt.Scan(&n,&k,&t)
	pr= n*t/100
	x:=int(pr)
	for i:=0 ;i<int(n);i++ {
		if i<x {
			fmt.Print(k," ")
		}else if i==x {
			ans:= int((pr-float64(x)) * k)
			fmt.Print(ans, " ")
		}else{
			fmt.Print(0)
			if i==int(n) {
				fmt.Println()
			}else{
				fmt.Print(" ")
			}
		}
	}
}

// 71B
package main

import (
	"fmt"
)

func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}
func main() {
	var n, k, t, i int
	fmt.Scan(&n, &k, &t)
	t = n * k * t / 100
	for i = 0; i < n; i++ {
		fmt.Print(min(t, k), " ")
		t -= min(t, k)
	}
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k, t float64
	fmt.Scanf("%f%f%f", &n, &k, &t)

	var _nk, nk float64
	var lnk int
	_nk = n * t / 100
	nk = _nk - float64(int(_nk))
	lnk = int(_nk)

	var r []string

	for i := 0; i < lnk; i++ {
		r = append(r, strconv.Itoa(int(k)))
	}

	if nk > 0 {
		r = append(r, strconv.Itoa(int(nk*k)))
	}

	l := int(n) - len(r)
	for x := 0; x < l; x++ {
		r = append(r, strconv.Itoa(0))
	}

	fmt.Println(strings.Join(r, " "))
}

package main

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

var scanner *bufio.Scanner

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

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

  n, k, t := getI(), getI(), getI()
  line := make([]int, n)
  sum := int(float64(n*k*t)/100)
  for i := 0; sum != 0; i++ {
    if sum > k {
      line[i] = k
      sum -= k
    } else {
      line[i] = sum
      sum = 0
    }
  }
  writer.WriteString(fmt.Sprintf("%d", line[0]))
  for i := 1; i < n; i++ {
    writer.WriteString(fmt.Sprintf(" %d", line[i]))
  }
  writer.WriteString("\n")
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k, t float64
	fmt.Scanf("%f%f%f", &n, &k, &t)

	var _nk, nk float64
	var lnk int
	_nk = n * t / 100
	nk = _nk - float64(int(_nk))
	lnk = int(_nk)

	var r []string

	for i := 0; i < lnk; i++ {
		r = append(r, strconv.Itoa(int(k)))
	}

	r = append(r, strconv.Itoa(int(nk*k)))

	l := int(n) - len(r)
	for x := 0; x < l; x++ {
		r = append(r, strconv.Itoa(0))
	}

	fmt.Println(strings.Join(r, " "))
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k, t float64
	fmt.Scanf("%f%f%f", &n, &k, &t)

	var _nk float64
	var nk, lnk int
	_nk = n * t / 100
	nk = int((_nk - float64(int(_nk))) * 10)
	lnk = int(_nk)

	var r []string

	for i := 0; i < lnk; i++ {
		r = append(r, strconv.Itoa(int(k)))
	}

	r = append(r, strconv.Itoa(nk))

	l := 10 - len(r)
	for x := 0; x < l; x++ {
		r = append(r, strconv.Itoa(0))
	}

	fmt.Println(strings.Join(r, " "))
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var n, k, t float64
	fmt.Scanf("%f%f%f", &n, &k, &t)

	var _nk float64
	var nk, lnk int
	_nk = n * t / 100
	nk = int((_nk - float64(int(_nk))) * 10)
	lnk = int(_nk)

	var r []string

	for i := 0; i < lnk; i++ {
		r = append(r, strconv.Itoa(int(k)))
	}

	r = append(r, strconv.Itoa(nk))

	l := int(n) - len(r)
	for x := 0; x < l; x++ {
		r = append(r, strconv.Itoa(0))
	}

	fmt.Println(strings.Join(r, " "))
}


A non-empty digit string is diverse if the number of occurrences of each character in it doesn't exceed the number of distinct characters in it.For example:   string "7" is diverse because 7 appears in it $$$1$$$ time and the number of distinct characters in it is $$$1$$$;  string "77" is not diverse because 7 appears in it $$$2$$$ times and the number of distinct characters in it is $$$1$$$;  string "1010" is diverse because both 0 and 1 appear in it $$$2$$$ times and the number of distinct characters in it is $$$2$$$;  string "6668" is not diverse because 6 appears in it $$$3$$$ times and the number of distinct characters in it is $$$2$$$. You are given a string $$$s$$$ of length $$$n$$$, consisting of only digits $$$0$$$ to $$$9$$$. Find how many of its $$$\frac{n(n+1)}{2}$$$ substrings are diverse.A string $$$a$$$ is a substring of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.Note that if the same diverse string appears in $$$s$$$ multiple times, each occurrence should be counted independently. For example, there are two diverse substrings in "77" both equal to "7", so the answer for the string "77" is $$$2$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the string $$$s$$$. The second line of each test case contains a string $$$s$$$ of length $$$n$$$. It is guaranteed that all characters of $$$s$$$ are digits from $$$0$$$ to $$$9$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the number of diverse substrings of the given string $$$s$$$.

NoteIn the first test case, the diverse substring is "7".In the second test case, the only diverse substring is "7", which appears twice, so the answer is $$$2$$$.In the third test case, the diverse substrings are "0" ($$$2$$$ times), "01", "010", "1" ($$$2$$$ times), "10" ($$$2$$$ times), "101" and "1010".In the fourth test case, the diverse substrings are "0" ($$$3$$$ times), "01", "011", "0110", "1" ($$$2$$$ times), "10", "100", "110" and "1100".In the fifth test case, the diverse substrings are "3", "39", "399", "6", "9" ($$$4$$$ times), "96" and "996".In the sixth test case, all $$$15$$$ non-empty substrings of "23456" are diverse.

package main

import (
	"bufio"
	"fmt"
	"log"
	"math/bits"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, 1000000), 0)
	for i := 0; scanner.Scan(); i++ {
		if i == 0 || i%2 == 1 {
			continue
		}
		fmt.Printf("%d\n", count(digits(scanner.Text())))
	}
	if err := scanner.Err(); err != nil {
		log.Fatal(err)
	}
}

func digits(s string) []byte {
	bs := make([]byte, len(s))
	for i := range s {
		bs[i] = s[i] - '0'
	}
	return bs
}

func count(bs []byte) int {
	numD := byte(10)
	numDSq := numD * numD
	n := 0
	for s := 0; s < len(bs); s++ {
		occur := uint64(0)
		seen := uint16(0)
		maxOccur := byte(0)
		for l := 1; l <= int(numDSq) && s+l-1 < len(bs); l++ {
			x := bs[s+l-1] % numD
			c := occur
			c >>= (4 * x)
			c++
			d := byte(c & 15)
			if d > maxOccur {
				maxOccur = d
			}
			occur = c<<(4*x) | (occur & (1<<(4*x) - 1))
			seen |= (1 << x)
			if maxOccur > numD {
				break
			}
			if maxOccur <= byte(bits.OnesCount16(seen)) {
				n++
			}
		}
	}
	return n
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

package main

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

func Solve(reader *bufio.Reader, writer *bufio.Writer) {
	zero := []byte("0")[0]
	var n int
	var str string
	fmt.Fscan(reader, &n)
	fmt.Fscan(reader, &str)
	bstr := []byte(str)

	for i := range bstr {
		bstr[i] -= zero
	}

	var ans int
	for i := 0; i < n; i++ {
		u := 1
		isThere := make([]bool, 10)
		isThere[bstr[i]] = true
		count := make([]int, 10)
		mx := 0
		for j := i; j < i+100 && j < n; j++ {
			count[bstr[j]]++
			if count[bstr[j]] > mx {
				mx = count[bstr[j]]
			}
			if !isThere[bstr[j]] {
				u++
				isThere[bstr[j]] = true
			}
			if u >= mx {
				ans++
			}
		}
	}

	fmt.Fprintf(writer, "%d\n", ans)
}

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

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

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

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

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

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

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

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

}

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

package main

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

func solve(r *bufio.Reader) {
	var n int
	var s string
	fmt.Fscan(r, &n, &s)
	total := 0
	for i := 0; i < n; i++ {
		max := 0
		occ := make(map[byte]int)
		for j := i; j < n; j++ {
			occ[s[j]]++
			if occ[s[j]] > max {
				max = occ[s[j]]
			}
			if max > 10 {
				break
			}
			if max <= len(occ) {
				total++
			}
		}
	}
	fmt.Println(total)
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

import "fmt"

func main() {
  var T int
  fmt.Scan(&T)
  for t := 0; t < T; t += 1 {
    var N int
    fmt.Scan(&N)
    var S string
    fmt.Scan(&S)
    ans := 0
    for l := 0; l < N; l += 1 {
      var occ [10]int
      max := 0
      num := 0
      for r := l; r < N && max <= 10; r += 1 {
        d := S[r] - '0'
        if occ[d] == 0 {
          num += 1
        }
        occ[d] += 1
        if occ[d] > max {
          max = occ[d]
        }
        if max <= num {
          ans += 1
        }
      }
    }
    fmt.Println(ans)
  }
}

package main

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

func main() {
	var t, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		var s string
		fmt.Fscan(in, &s)
		sum := 0
		for j := 0; j < n; j++ {
			pd := make([]bool, 10)
			sl := make([]int, 10)
			zl := 0
			mx := 0
			for k := j; k < j+100 && k < n; k++ {
				sl[s[k]-'0']++
				if mx < sl[s[k]-'0'] {
					mx = sl[s[k]-'0']
				}
				if !pd[s[k]-'0'] {
					zl++
					pd[s[k]-'0'] = true
				}
				if zl >= mx {
					sum++
				}
			}
		}
		fmt.Println(sum)
	}
}

package main

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

func solve(reader *bufio.Reader, writer *bufio.Writer) {
	n := readInt(reader)
	s := readString(reader)

	var ans int
	for i := 0; i < n; i++ {
		var a [10]int
		for j := i; j < n && j-i < 100; j++ {
			a[s[j]-'0']++
			var cnt, maxx int
			for _, v := range a {
				if v > 0 {
					cnt++
				}
				maxx = max(maxx, v)
			}
			if maxx <= cnt {
				ans++
			}
		}
	}

	fmt.Fprintln(writer, ans)
}

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

	t := readInt(reader)

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

	writer.Flush()
}

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

	return b
}

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

	return b
}

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

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

	return x
}

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

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

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

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

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

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

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

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

	return value
}

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

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

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

	var ar []int

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

	return ar
}

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

	var ar []int64

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

	return ar
}

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

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

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

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

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	var str string
	fmt.Fscan(in, &str)
	prefix := make([][]int, 10)
	for i := range prefix {
		prefix[i] = make([]int, n)
	}
	for i := range str {
		integer := int(str[i] - '0')
		if i > 0 {
			for j := range prefix {
				prefix[j][i] = prefix[j][i-1]
			}
		}
		prefix[integer][i]++
	}

	ans := 0
	for i := 0; i < n; i++ {
		for cur := max(0, i-101); cur <= i; cur++ {
			diff := 0
			mx := 0
			for j := range prefix {
				curPref := prefix[j][i]
				if cur > 0 {
					curPref -= prefix[j][cur-1]
				}
				if curPref > 0 {
					diff++
				}
				mx = max(mx, curPref)
			}
			if mx > diff {
				continue
			} else {
				ans++
			}
		}
	}

	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
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

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

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

func ans() {
	var n int
	var s string
	ans := 0
	Fscan(in, &n)
	Fscan(in, &s)
	for l := 0; l < len(s); l++ {
		var cnt []int = make([]int, 10)
		uniq := 0
		for r := l; r < len(s) && r < l+110; r++ {
			if cnt[s[r]-'0'] == 0 {
				uniq++
			}
			cnt[s[r]-'0']++
			good := true
			for d := 0; d < 10; d++ {
				if cnt[d] > uniq {
					good = false
					break
				}
			}
			if good {
				ans++
			}
		}
	}
	Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	var t int
	Fscan(in, &t)
	for i := 0; i < t; i++ {
		ans()
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; scanner.Scan(); i++ {
		if i == 0 || i%2 == 1 {
			continue
		}
		fmt.Printf("%d\n", count(digits(scanner.Text())))
	}
}

func digits(s string) []byte {
	bs := make([]byte, len(s))
	for i := range s {
		bs[i] = s[i] - '0'
	}
	return bs
}

func count(bs []byte) int {
	n := 0
	for s := 0; s < len(bs); s++ {
		occur := uint64(0)
		seen := uint16(0)
		maxOccur := byte(0)
		for l := 1; l <= 100 && s+l-1 < len(bs); l++ {
			x := bs[s+l-1]
			c := occur
			c >>= (4 * x)
			c++
			d := byte(c & 15)
			if d > maxOccur {
				maxOccur = d
			}
			occur = c<<(4*x) | (occur & (1<<(4*x) - 1))
			seen |= (1 << x)
			if maxOccur > 10 {
				break
			}
			if maxOccur <= byte(bits.OnesCount16(seen)) {
				n++
			}
		}
	}
	return n
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; scanner.Scan(); i++ {
		if i == 0 || i%2 == 1 {
			continue
		}
		fmt.Printf("%d\n", count(digits(scanner.Text())))
	}
}

func digits(s string) []byte {
	bs := make([]byte, len(s))
	for i := range s {
		bs[i] = s[i] - '0'
	}
	return bs
}

func count(bs []byte) int {
	n := 0
	for s := 0; s < len(bs); s++ {
		occur := map[byte]int{}
		maxOccur := 0
		for l := 1; l <= 100 && s+l <= len(bs); l++ {
			x := bs[s+l-1]
			occur[x]++
			if occur[x] > maxOccur {
				maxOccur = occur[x]
			}
			if maxOccur > len(occur) {
				if maxOccur > 10 {
					break
				}
				continue
			}
			n++
		}
	}
	return n
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

package main

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

func Solve(reader *bufio.Reader, writer *bufio.Writer) {
	zero := []byte("0")[0]
	var n int
	var str string
	fmt.Fscan(reader, &n)
	fmt.Fscan(reader, &str)
	bstr := []byte(str)

	for i := range bstr {
		bstr[i] -= zero
	}

	var ans int
	for i := 0; i < n; i++ {
		u := 1
		isThere := make([]bool, 10)
		isThere[bstr[i]] = true
		count := make([]int, 10)
		mx := 0
		for j := i; j < i+100 && j < n; j++ {
			count[bstr[j]]++
			if count[bstr[j]] > mx {
				mx = count[bstr[j]]
			}
			if !isThere[bstr[j]] {
				u++
				isThere[bstr[j]] = true
			}
			fmt.Println(i, j, u, mx)
			if u >= mx {
				ans++
				fmt.Println("^ cool ^")
			}
		}
	}

	fmt.Fprintf(writer, "%d\n", ans)
}

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

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

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

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

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

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

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

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

}

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


Note that girls in Arpa’s land are really attractive.Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th chair, and his girlfriend, sitting on the bi-th chair. The chairs were numbered 1 through 2n in clockwise direction. There was exactly one person sitting on each chair.  There were two types of food: Kooft and Zahre-mar. Now Mehrdad wonders, was there any way to serve food for the guests such that:   Each person had exactly one type of food,  No boy had the same type of food as his girlfriend,  Among any three guests sitting on consecutive chairs, there was two of them who had different type of food. Note that chairs 2n and 1 are considered consecutive. Find the answer for the Mehrdad question. If it was possible, find some arrangement of food types that satisfies the conditions.

The first line contains an integer n (1  ≤  n  ≤  105) — the number of pairs of guests. The i-th of the next n lines contains a pair of integers ai and bi (1  ≤ ai, bi ≤  2n) — the number of chair on which the boy in the i-th pair was sitting and the number of chair on which his girlfriend was sitting. It's guaranteed that there was exactly one person sitting on each chair.

If there is no solution, print -1. Otherwise print n lines, the i-th of them should contain two integers which represent the type of food for the i-th pair. The first integer in the line is the type of food the boy had, and the second integer is the type of food the girl had. If someone had Kooft, print 1, otherwise print 2. If there are multiple solutions, print any of them.

package main

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

func solve() {
    n := readInt()
    a := make([][]int, 2*n)
    order := make([]int, 2*n)
    for i := 0; i < n; i++ {
        l, r := 2*i, 2*i+1
        a[l] = append(a[l], r)
        a[r] = append(a[r], l)
        u, v := readInt()-1, readInt()-1
        order[l], order[r] = u, v
        a[u] = append(a[u], v)
        a[v] = append(a[v], u)
    }

    was, ans := make([]bool, 2*n), make([]int, 2*n)
    for v := range a {
        if was[v] {
            continue
        }
        q, val := []int{v}, 0
        was[v] = true
        for len(q) > 0 {
            c := q[len(q)-1]
            q = q[:len(q)-1]
            ans[c], val = val, (val+1)%2
            for _, u := range a[c] {
                if !was[u] {
                    was[u] = true
                    q = append(q, u)
                    break
                }
            }
        }
    }

    for i := 0; i < len(order); i += 2 {
        for j := i; j <= i+1; j++ {
            fmt.Print(ans[order[j]]+1, " ")
        }
        fmt.Println()
    }
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

// Math

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

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

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

// IO

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

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

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

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

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

// Sort

type Ints64 []int64

func (a Ints64) Len() int           { return len(a) }
func (a Ints64) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Ints64) Less(i, j int) bool { return a[i] < a[j] }

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

func main() {
	n := readi()
	people := make([]Person, 2*n)
	pairs := make([][2]int, n)
	for i := 0; i < n; i++ {
		a, b := read2i()
		a--
		b--
		people[a] = Person{pair: b}
		people[b] = Person{pair: a}
		pairs[i] = [2]int{a, b}
	}
	for i := 0; i < 2*n; i++ {
		dfs(people, i, 1)
	}
	for _, pair := range pairs {
		fmt.Fprintln(writer, people[pair[0]].color, people[pair[1]].color)
	}
	writer.Flush()
}

func dfs(people []Person, idx, color int) {
	if people[idx].color == 0 {
		people[idx].color = color
		reversed := ((color - 1) ^ 1) + 1
		if idx%2 == 0 {
			dfs(people, (idx+1)%len(people), reversed)
		}
		if idx%2 == 1 {
			dfs(people, (idx-1+len(people))%len(people), reversed)
		}
		dfs(people, people[idx].pair, reversed)
	}
}

type Person struct {
	color int
	pair  int
}

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

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

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

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

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

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

var (
	reader = bufio.NewReaderSize(os.Stdin, 1<<13)
	writer = bufio.NewWriterSize(os.Stdout, 1<<13)
)

func readi() int {
	return int(readi64())
}

func read2i() (int, int) {
	return readi(), readi()
}

func readis(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = readi()
	}
	return res
}

func readi64() int64 {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	sign, res := int64(1), int64(0)
	if b == '-' {
		sign *= -1
		b, err = reader.ReadByte()
	}
	for isValid(b, err) {
		res = res*10 + int64(b-'0')
		b, err = reader.ReadByte()
	}
	return res * sign
}

func readline() string {
	res := new(bytes.Buffer)
	for {
		line, isPrefix, err := reader.ReadLine()
		if err != nil {
			panic(err)
		}
		res.Write(line)
		if !isPrefix {
			break
		}
	}
	return res.String()
}

func isValid(b byte, err error) bool {
	return err == nil && (('0' <= b && b <= '9') || b == '-')
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type Node struct {
	Adj     []*Node
	Visited bool
	Food    int
}

type Graph []Node

func (g Graph) AddEdge(x, y int) {
	g[x].Adj = append(g[x].Adj, &g[y])
}

func main() {
	reader := RapidReader()
	n := 0
	fmt.Fscan(reader, &n)

	graph := Graph(make([]Node, n*2))
	boy, girl := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &boy[i], &girl[i])
		boy[i]--
		girl[i]--
		graph.AddEdge(boy[i], girl[i])
		graph.AddEdge(girl[i], boy[i])
	}

	for i := 0; i < n; i++ {
		graph.AddEdge(i*2, (i*2+1)%(2*n))
		graph.AddEdge((i*2+1)%(2*n), i*2)
	}

	for i := 0; i < len(graph); i++ {
		if !graph[i].Visited {
			dfs(&graph[i], 1)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(graph[boy[i]].Food, graph[girl[i]].Food)
	}
}

func dfs(x *Node, food int) {
	x.Visited = true
	x.Food = food
	for _, y := range x.Adj {
		if !y.Visited {
			dfs(y, 3-food)
		}
	}
}

package main

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

const MAX = 200010

type Edge struct {
	u, v int
}

func addEdge(edges []Edge, First, Next []int, x, y, cnt int) {

	edges[cnt].u = x
	edges[cnt].v = y
	Next[cnt] = First[x]
	First[x] = cnt

}

func match(edges []Edge, First, Next, res []int, root int) {

	for j := First[root]; j != -1; j = Next[j] {
		t := edges[j].v
		if res[t] == 0 {
			if res[root] == 1 {
				res[t] = 2
			} else {
				res[t] = 1
			}
			match(edges, First, Next, res, t)
		}
	}

}

func main() {

	var n, cnt int
	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

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

	edges := make([]Edge, 4*n+1)
	First := make([]int, n*2+1)
	Next := make([]int, n*4+1)
	res := make([]int, n*2+1)
	lx := make([]int, n+1)
	rx := make([]int, n+1)

	for i := 1; i <= 2*n; i++ {
		First[i] = -1
		res[i] = 0
	}

	cnt = 0
	for i := 1; i <= n; i++ {
		fmt.Fscanf(r, "%d %d\n", &lx[i], &rx[i])
		cnt++
		addEdge(edges, First, Next, lx[i], rx[i], cnt)
		cnt++
		addEdge(edges, First, Next, rx[i], lx[i], cnt)
		cnt++
		addEdge(edges, First, Next, 2*i-1, 2*i, cnt)
		cnt++
		addEdge(edges, First, Next, 2*i, 2*i-1, cnt)

	}

	/*
			fmt.Printf("n = %d, cnt = %d\n", n, cnt)

			for i := 1; i <= 2*n; i++ {
				fmt.Printf("i = %d: ", i)
				for j := First[i]; j != -1; j = Next[j] {
					fmt.Printf("%d ", edges[j].v)
				}
				fmt.Printf("\n")
			}

		res[1] = 1
		match(1)
	*/

	for i := 1; i <= 2*n; i++ {
		if res[i] == 0 {
			res[i] = 1
			match(edges, First, Next, res, i)
		}
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d\n", res[lx[i]], res[rx[i]])
	}

}

package main

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

const MAX = 400010

type Edge struct {
	u, v int64
}

var edges []Edge
var First, Next, res, lx, rx []int64
var cnt int64

func init_func() {
	edges = make([]Edge, MAX)
	First = make([]int64, MAX)
	Next = make([]int64, MAX)
	res = make([]int64, MAX)
	lx = make([]int64, MAX)
	rx = make([]int64, MAX)

	for i := 0; i < MAX; i++ {
		First[i] = -1
		Next[i] = -1
		res[i] = 0
	}

	cnt = 0
}

func addEdge(x, y int64) {
	cnt++
	edges[cnt].u = x
	edges[cnt].v = y
	Next[cnt] = First[x]
	First[x] = cnt
}

var n int64

func match(root int64) {

	for j := First[root]; j != -1; j = Next[j] {
		t := edges[j].v
		if res[t] == 0 {
			if res[root] == 1 {
				res[t] = 2
			} else {
				res[t] = 1
			}
			match(t)
		}
	}

}

func main() {

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

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

	for i := int64(1); i <= n; i++ {
		fmt.Fscanf(r, "%v %v\n", &lx[i], &rx[i])
		addEdge(lx[i], rx[i])
		addEdge(rx[i], lx[i])
		addEdge(2*i-1, 2*i)
		addEdge(2*i, 2*i-1)
	}
	/*
			fmt.Printf("n = %d, cnt = %d\n", n, cnt)

			for i := 1; i <= 2*n; i++ {
				fmt.Printf("i = %d: ", i)
				for j := First[i]; j != -1; j = Next[j] {
					fmt.Printf("%d ", edges[j].v)
				}
				fmt.Printf("\n")
			}

		res[1] = 1
		match(1)
	*/

	for i := int64(1); i <= 2*n; i++ {
		if res[i] == 0 {
			res[i] = 1
			match(i)
		}
	}

	for i := int64(1); i <= n; i++ {
		fmt.Printf("%v %v\n", res[lx[i]], res[rx[i]])
	}

}

package main

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

func main() {
	n := readi()
	people := make([]Person, 2*n)
	pairs := make([][2]int, n)
	for i := 0; i < n; i++ {
		a, b := read2i()
		a--
		b--
		people[a] = Person{pair: b}
		people[b] = Person{pair: a}
		pairs[i] = [2]int{a, b}
	}
	for i := 0; i < n; i++ {
		dfs(people, i, 1)
	}
	for _, pair := range pairs {
		fmt.Fprintln(writer, people[pair[0]].color, people[pair[1]].color)
	}
	writer.Flush()
}

func dfs(people []Person, idx, color int) {
	if people[idx].color == 0 {
		people[idx].color = color
		reversed := ((color - 1) ^ 1) + 1
		if idx%2 == 0 {
			dfs(people, (idx+1)%len(people), reversed)
		}
		if idx%2 == 1 {
			dfs(people, (idx-1+len(people))%len(people), reversed)
		}
		dfs(people, people[idx].pair, reversed)
	}
}

type Person struct {
	color int
	pair  int
}

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

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

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

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

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

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

var (
	reader = bufio.NewReaderSize(os.Stdin, 1<<13)
	writer = bufio.NewWriterSize(os.Stdout, 1<<13)
)

func readi() int {
	return int(readi64())
}

func read2i() (int, int) {
	return readi(), readi()
}

func readis(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = readi()
	}
	return res
}

func readi64() int64 {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	sign, res := int64(1), int64(0)
	if b == '-' {
		sign *= -1
		b, err = reader.ReadByte()
	}
	for isValid(b, err) {
		res = res*10 + int64(b-'0')
		b, err = reader.ReadByte()
	}
	return res * sign
}

func readline() string {
	res := new(bytes.Buffer)
	for {
		line, isPrefix, err := reader.ReadLine()
		if err != nil {
			panic(err)
		}
		res.Write(line)
		if !isPrefix {
			break
		}
	}
	return res.String()
}

func isValid(b byte, err error) bool {
	return err == nil && (('0' <= b && b <= '9') || b == '-')
}

package main

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

func main() {
	n := readi()
	people := make([]Person, 2*n)
	pairs := make([][2]int, n)
	for i := 0; i < n; i++ {
		a, b := read2i()
		a--
		b--
		people[a] = Person{pair: b}
		people[b] = Person{pair: a}
		pairs[i] = [2]int{a, b}
	}
	for i := 0; i < n; i++ {
		dfs(people, i, 1)
	}
	for _, pair := range pairs {
		fmt.Fprintln(writer, people[pair[0]].color, people[pair[1]].color)
	}
	writer.Flush()
}

func dfs(people []Person, idx, color int) {
	if people[idx].color == 0 {
		people[idx].color = color
		reversed := ((color - 1) ^ 1) + 1
		if idx%2 == 0 && idx+1 < len(people) && people[idx+1].color == 0 {
			dfs(people, idx+1, reversed)
		}
		if idx%2 == 1 && idx-1 >= 0 && people[idx-1].color == 0 {
			dfs(people, idx-1, reversed)
		}
		dfs(people, people[idx].pair, reversed)
	}
}

type Person struct {
	color int
	pair  int
}

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

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

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

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

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

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

var (
	reader = bufio.NewReaderSize(os.Stdin, 1<<13)
	writer = bufio.NewWriterSize(os.Stdout, 1<<13)
)

func readi() int {
	return int(readi64())
}

func read2i() (int, int) {
	return readi(), readi()
}

func readis(n int) []int {
	res := make([]int, n)
	for i := range res {
		res[i] = readi()
	}
	return res
}

func readi64() int64 {
	b, err := reader.ReadByte()
	for !isValid(b, err) {
		b, err = reader.ReadByte()
	}
	sign, res := int64(1), int64(0)
	if b == '-' {
		sign *= -1
		b, err = reader.ReadByte()
	}
	for isValid(b, err) {
		res = res*10 + int64(b-'0')
		b, err = reader.ReadByte()
	}
	return res * sign
}

func readline() string {
	res := new(bytes.Buffer)
	for {
		line, isPrefix, err := reader.ReadLine()
		if err != nil {
			panic(err)
		}
		res.Write(line)
		if !isPrefix {
			break
		}
	}
	return res.String()
}

func isValid(b byte, err error) bool {
	return err == nil && (('0' <= b && b <= '9') || b == '-')
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type Node struct {
	Adj     []*Node
	Visited bool
	Food    int
}

type Graph []Node

func (g Graph) AddEdge(x, y int) {
	g[x].Adj = append(g[x].Adj, &g[y])
}

func main() {
	reader := RapidReader()
	n := 0
	fmt.Fscan(reader, &n)

	graph := Graph(make([]Node, n*2))
	boy, girl := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &boy[i], &girl[i])
		boy[i]--
		girl[i]--
		graph.AddEdge(boy[i], girl[i])
		graph.AddEdge(girl[i], boy[i])
	}

	for i := 0; i < n; i++ {
		graph.AddEdge(i*2, (i*2+1)%(2*n))
		graph.AddEdge((i*2+1)%(2*n), i*2)
	}

	dfs(&graph[0], 1)
	for i := 0; i < n; i++ {
		fmt.Println(graph[boy[i]].Food, graph[girl[i]].Food)
	}
}

func dfs(x *Node, food int) {
	x.Visited = true
	x.Food = food
	for _, y := range x.Adj {
		if !y.Visited {
			dfs(y, 3-food)
		}
	}
}

package main

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

func RapidReader() io.Reader {
	b, _ := ioutil.ReadAll(os.Stdin)
	return bytes.NewReader(b)
}

type Node struct {
	Adj     []*Node
	Visited bool
	Food    int
}

type Graph []Node

func (g Graph) AddEdge(x, y int) {
	g[x].Adj = append(g[x].Adj, &g[y])
}

func main() {
	reader := RapidReader()
	n := 0
	fmt.Fscan(reader, &n)

	graph := Graph(make([]Node, n*2))
	boy, girl := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &boy[i], &girl[i])
		boy[i]--
		girl[i]--
		graph.AddEdge(boy[i], girl[i])
		graph.AddEdge(girl[i], boy[i])
	}

	for i := 0; i < n; i++ {
		graph.AddEdge(i*2, (i*2+1)%(2*n))
		graph.AddEdge((i*2+1)%(2*n), i*2)
	}

	for i := 0; i < n; i++ {
		if !graph[i].Visited {
			dfs(&graph[i], 1)
		}
	}

	for i := 0; i < n; i++ {
		fmt.Println(graph[boy[i]].Food, graph[girl[i]].Food)
	}
}

func dfs(x *Node, food int) {
	x.Visited = true
	x.Food = food
	for _, y := range x.Adj {
		if !y.Visited {
			dfs(y, 3-food)
		}
	}
}

package main

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

const MAX = 200010

type Edge struct {
	u, v int
}

func addEdge(edges []Edge, First, Next []int, x, y, cnt int) {
	fmt.Printf("x = %d, y = %d\n", x, y)
	edges[cnt].u = x
	edges[cnt].v = y
	Next[cnt] = First[x]
	First[x] = cnt

}

func match(edges []Edge, First, Next, res []int, root int) {

	for j := First[root]; j != -1; j = Next[j] {
		t := edges[j].v
		if res[t] == 0 {
			if res[root] == 1 {
				res[t] = 2
			} else {
				res[t] = 1
			}
			match(edges, First, Next, res, t)
		}
	}

}

func main() {

	var n, cnt int
	b, _ := ioutil.ReadAll(os.Stdin)
	r := bytes.NewReader(b)

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

	edges := make([]Edge, 4*n+1)
	First := make([]int, n*2+1)
	Next := make([]int, n*4+1)
	res := make([]int, n*2+1)
	lx := make([]int, n+1)
	rx := make([]int, n+1)

	for i := 1; i <= 2*n; i++ {
		First[i] = -1
		res[i] = 0
	}

	cnt = 0
	for i := 1; i <= n; i++ {
		fmt.Fscanf(r, "%d %d\n", &lx[i], &rx[i])
		cnt++
		addEdge(edges, First, Next, lx[i], rx[i], cnt)
		cnt++
		addEdge(edges, First, Next, rx[i], lx[i], cnt)
		cnt++
		addEdge(edges, First, Next, 2*i-1, 2*i, cnt)
		cnt++
		addEdge(edges, First, Next, 2*i, 2*i-1, cnt)

	}

	fmt.Printf("cnt = %d\n", cnt)
	/*
			fmt.Printf("n = %d, cnt = %d\n", n, cnt)

			for i := 1; i <= 2*n; i++ {
				fmt.Printf("i = %d: ", i)
				for j := First[i]; j != -1; j = Next[j] {
					fmt.Printf("%d ", edges[j].v)
				}
				fmt.Printf("\n")
			}

		res[1] = 1
		match(1)
	*/

	for i := 1; i <= 2*n; i++ {
		if res[i] == 0 {
			res[i] = 1
			match(edges, First, Next, res, i)
		}
	}

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d\n", res[lx[i]], res[rx[i]])
	}

}

package main

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

const MAX = 20010

type Edge struct {
	u, v int
}

var edges []Edge
var First, Next, res, lx, rx []int
var cnt int

func init_func() {
	edges = make([]Edge, MAX)
	First = make([]int, MAX)
	Next = make([]int, MAX)
	res = make([]int, MAX)
	lx = make([]int, MAX)
	rx = make([]int, MAX)

	for i := 0; i < MAX; i++ {
		First[i] = -1
		Next[i] = -1
		res[i] = 0
	}

	cnt = 0
}

func addEdge(x, y int) {
	cnt++
	edges[cnt].u = x
	edges[cnt].v = y
	Next[cnt] = First[x]
	First[x] = cnt
}

var n int

func match(root int) {

	for j := First[root]; j != -1; j = Next[j] {
		t := edges[j].v
		if res[t] == 0 {
			if res[root] == 1 {
				res[t] = 2
			} else {
				res[t] = 1
			}
			match(t)
		}
	}

}

func main() {

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

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

	for i := 1; i <= n; i++ {
		fmt.Fscanf(r, "%d %d\n", &lx[i], &rx[i])
		addEdge(lx[i], rx[i])
		addEdge(rx[i], lx[i])
		addEdge(2*i-1, 2*i)
		addEdge(2*i, 2*i-1)
	}

	fmt.Printf("n = %d, cnt = %d\n", n, cnt)

	for i := 1; i <= 2*n; i++ {
		fmt.Printf("i = %d: ", i)
		for j := First[i]; j != -1; j = Next[j] {
			fmt.Printf("%d ", edges[j].v)
		}
		fmt.Printf("\n")
	}

	res[1] = 1
	match(1)
	/*
		for i := 1; i <= 2*n; i++ {
			if res[i] == 0 {
				res[i] = 1
				match(i)
			}
		}
	*/

	for i := 1; i <= n; i++ {
		fmt.Printf("%d %d\n", res[lx[i]], res[rx[i]])
	}

}

package main

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

const MAX = 20010

type Edge struct {
	u, v int
}

var edges []Edge
var First, Next, res []int
var cnt int

func init_func() {
	edges = make([]Edge, MAX)
	First = make([]int, MAX)
	Next = make([]int, MAX)
	res = make([]int, MAX)

	for i := 0; i < MAX; i++ {
		First[i] = -1
		Next[i] = -1
		res[i] = 0
	}

	cnt = 0
}

func addEdge(x, y int) {
	cnt++
	edges[cnt].u = x
	edges[cnt].v = y
	Next[cnt] = First[x]
	First[x] = cnt
}

var n int

func match(root int) {
	if res[root] == 1 {
		for j := First[root]; j != -1; j = Next[j] {
			tmp := edges[j].v
			if res[tmp] == 0 {
				res[tmp] = 2
				match(tmp)
			}
		}
	} else {
		for j := First[root]; j != -1; j = Next[j] {
			tmp := edges[j].v
			if res[tmp] == 0 {
				res[tmp] = 1
				match(tmp)
			}
		}
	}

}

func main() {

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

	var x, y int

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

	for i := 1; i <= n; i++ {
		fmt.Fscanf(r, "%d %d\n", &x, &y)
		addEdge(x, y)
		addEdge(y, x)
		addEdge(2*i-1, 2*i)
		addEdge(2*i, 2*i-1)
	}

	/*
		fmt.Printf("n = %d, cnt = %d\n", n, cnt)

		for i := 1; i <= n; i++ {
			fmt.Printf("i = %d: ", i)
			for j := First[i]; j != -1; j = Next[j] {
				fmt.Printf("%d ", edges[j].v)
			}
			fmt.Printf("\n")
		}

	*/
	res[1] = 1
	match(1)

	for i := 1; i <= n; i++ {
		x, y := edges[i].u, edges[i].v
		fmt.Printf("%d %d\n", res[x], res[y])
	}

}