Dima, Inna and Seryozha have gathered in a room. That's right, someone's got to go. To cheer Seryozha up and inspire him to have a walk, Inna decided to cook something. Dima and Seryozha have n fruits in the fridge. Each fruit has two parameters: the taste and the number of calories. Inna decided to make a fruit salad, so she wants to take some fruits from the fridge for it. Inna follows a certain principle as she chooses the fruits: the total taste to the total calories ratio of the chosen fruits must equal k. In other words,  , where aj is the taste of the j-th chosen fruit and bj is its calories.Inna hasn't chosen the fruits yet, she is thinking: what is the maximum taste of the chosen fruits if she strictly follows her principle? Help Inna solve this culinary problem — now the happiness of a young couple is in your hands!Inna loves Dima very much so she wants to make the salad from at least one fruit.

The first line of the input contains two integers n, k (1 ≤ n ≤ 100, 1 ≤ k ≤ 10). The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100) — the fruits' tastes. The third line of the input contains n integers b1, b2, ..., bn (1 ≤ bi ≤ 100) — the fruits' calories. Fruit number i has taste ai and calories bi.

If there is no way Inna can choose the fruits for the salad, print in the single line number -1. Otherwise, print a single integer — the maximum possible sum of the taste values of the chosen fruits.

NoteIn the first test sample we can get the total taste of the fruits equal to 18 if we choose fruit number 1 and fruit number 2, then the total calories will equal 9. The condition  fulfills, that's exactly what Inna wants.In the second test sample we cannot choose the fruits so as to follow Inna's principle.

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()
}
const MAXN = 200000 + 10
const fi = 100000
func max(a , b int) int{

	if(a > b){
		return a
	}

	return b
}

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

	n := getI()
	k := getI()

	var a,b [100+10]int
	var vis [MAXN]bool
	var dp,x [MAXN]int
	vis[fi] = true
	for i := 0 ; i < n ; i ++{
		a[i] = getI()
	}

	for i := 0 ; i < n ; i ++{
		b[i] = getI()
	}

	ch := false

	for i := 0 ; i < n ; i ++{
		tmp := a[i] - k*b[i]
		var v []int
		for j := 0 ; j <= 200000 ; j ++{
			x[j] = 0
			if vis[j]{
				v = append(v,j)
			}
		}
		l := len(v)

		for j := 0 ; j < l ; j ++{
			idx := v[j] + tmp
			if idx < 0 {
				continue
			}

			x[idx] = max(x[idx], dp[v[j]] + a[i])

			vis[idx] = true
			if idx == fi {
				ch = true
			}
		 }

		 for j := 0 ; j <= 200000 ; j ++ {
			 dp[j] = max(dp[j],x[j])
		 }
	}

	if ch {
		writer.WriteString(fmt.Sprintf("%v\n",dp[fi]))
	}else{
		writer.WriteString(fmt.Sprintf("-1\n"))
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF366C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mx int = 1e4
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, k, s int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		Fscan(in, &b[i])
		if a[i] == k*b[i] {
			s += a[i]
		}
	}

	dp1 := make([]int, mx+1)
	for i := range dp1 {
		dp1[i] = -1e9
	}
	dp1[0] = 0
	for i, v := range a {
		if w := v - k*b[i]; w > 0 {
			for j := mx; j >= w; j-- {
				dp1[j] = max(dp1[j], dp1[j-w]+v)
			}
		}
	}
	dp2 := make([]int, mx+1)
	for i := range dp2 {
		dp2[i] = -1e9
	}
	dp2[0] = 0
	for i, v := range a {
		if w := k*b[i] - v; w > 0 {
			for j := mx; j >= w; j-- {
				dp2[j] = max(dp2[j], dp2[j-w]+v)
			}
		}
	}
	ans := 0
	for i, d := range dp1 {
		if d > 0 && dp2[i] > 0 {
			ans = max(ans, d+dp2[i])
		}
	}
	ans += s
	if ans == 0 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

import (
	"fmt"
)

type node struct {
	a int
	b int
	c int
}

var data [101]node

func main() {
	var n, k int

	fmt.Scanf("%d %d\n", &n, &k)
	for i := 0; i < n-1; i++ {
		fmt.Scanf("%d", &data[i].a)
	}

	fmt.Scanf("%d\n", &data[n-1].a)

	for i := 0; i < n-1; i++ {
		fmt.Scanf("%d", &data[i].b)
		data[i].c = k*data[i].b - data[i].a
	}

	fmt.Scanf("%d\n", &data[n-1].b)
	data[n-1].c = k*data[n-1].b - data[n-1].a

	var ans map[int]int = make(map[int]int)
	var tmp map[int]int

	ans[0] = 0

	for i := 0; i < n; i++ {
		tmp = make(map[int]int)

		for k, v := range ans {
			tmp[k+data[i].c] = v + data[i].a
		}

		for k, v := range tmp {
			if ans[k] < v {
				ans[k] = v
			}
		}
	}

	if ans[0] == 0 {
		fmt.Printf("%d\n", -1)
	} else {
		fmt.Printf("%d\n", ans[0])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF366C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mx int = 1e4
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, k int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		Fscan(in, &b[i])
	}

	dp1 := make([]int, mx+1)
	for i := range dp1 {
		dp1[i] = -1e9
	}
	dp1[0] = 0
	for i, v := range a {
		w := v - k*b[i]
		if w < 0 {
			continue
		}
		for j := mx; j >= w; j-- {
			dp1[j] = max(dp1[j], dp1[j-w]+v)
		}
	}
	dp2 := make([]int, mx+1)
	for i := range dp2 {
		dp2[i] = -1e9
	}
	dp2[0] = 0
	for i, v := range a {
		w := k*b[i] - v
		if w <= 0 {
			continue
		}
		for j := mx; j >= w; j-- {
			dp2[j] = max(dp2[j], dp2[j-w]+v)
		}
	}
	ans := 0
	for i, d := range dp1 {
		if d > 0 && dp2[i] > 0 {
			ans = max(ans, d+dp2[i])
		}
	}
	if ans == 0 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF366C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	const mx int = 1e4
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var n, k, s int
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int, n)
	for i := range b {
		Fscan(in, &b[i])
		if a[i] == k*b[i] {
			s += a[i]
		}
	}

	dp1 := make([]int, mx+1)
	for i := range dp1 {
		dp1[i] = -1e9
	}
	dp1[0] = 0
	for i, v := range a {
		w := v - k*b[i]
		if w < 0 {
			continue
		}
		for j := mx; j >= w; j-- {
			dp1[j] = max(dp1[j], dp1[j-w]+v)
		}
	}
	dp2 := make([]int, mx+1)
	for i := range dp2 {
		dp2[i] = -1e9
	}
	dp2[0] = 0
	for i, v := range a {
		w := k*b[i] - v
		if w <= 0 {
			continue
		}
		for j := mx; j >= w; j-- {
			dp2[j] = max(dp2[j], dp2[j-w]+v)
		}
	}
	ans := 0
	for i, d := range dp1 {
		if d > 0 && dp2[i] > 0 {
			ans = max(ans, d+dp2[i])
		}
	}
	ans += s
	if ans == 0 {
		ans = -1
	}
	Fprint(out, ans)
}

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

package main

import (
	"fmt"
)

type node struct {
	a int
	b int
	c int
}

var data [101]node

func main() {
	var n, k int

	fmt.Scanf("%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i].a)
		fmt.Printf("%d ", data[i].a)
	}

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i].b)
		data[i].c = k*data[i].b - data[i].a

		fmt.Printf("%d ", data[i].b)
	}

	var ans map[int]int = make(map[int]int)
	var tmp map[int]int

	ans[0] = 0

	for i := 0; i < n; i++ {
		tmp = make(map[int]int)

		for k, v := range ans {
			tmp[k+data[i].c] = v + data[i].a
		}

		for k, v := range tmp {
			if ans[k] < v {
				ans[k] = v
			}
		}
	}

	if ans[0] == 0 {
		fmt.Printf("%d\n", -1)
	} else {
		fmt.Printf("%d\n", ans[0])
	}
}

package main

import (
	"fmt"
)

type node struct {
	a int
	b int
	c int
}

var data [101]node

func main() {
	var n, k int

	fmt.Scanf("%d %d\n", &n, &k)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i].a)
	}

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &data[i].b)
		data[i].c = k*data[i].b - data[i].a
	}

	var ans map[int]int = make(map[int]int)
	var tmp map[int]int

	ans[0] = 0

	for i := 0; i < n; i++ {
		tmp = make(map[int]int)

		for k, v := range ans {
			tmp[k+data[i].c] = v + data[i].a
		}

		for k, v := range tmp {
			if ans[k] < v {
				ans[k] = v
			}
		}
	}

	if ans[0] == 0 {
		fmt.Printf("%d\n", -1)
	} else {
		fmt.Printf("%d\n", ans[0])
	}
}


Vasya wrote down two strings s of length n and t of length m consisting of small English letters 'a' and 'b'. What is more, he knows that string t has a form "abab...", namely there are letters 'a' on odd positions and letters 'b' on even positions.Suddenly in the morning, Vasya found that somebody spoiled his string. Some letters of the string s were replaced by character '?'.Let's call a sequence of positions i, i + 1, ..., i + m - 1 as occurrence of string t in s, if 1 ≤ i ≤ n - m + 1 and t1 = si, t2 = si + 1, ..., tm = si + m - 1.The boy defines the beauty of the string s as maximum number of disjoint occurrences of string t in s. Vasya can replace some letters '?' with 'a' or 'b' (letters on different positions can be replaced with different letter). Vasya wants to make some replacements in such a way that beauty of string s is maximum possible. From all such options, he wants to choose one with the minimum number of replacements. Find the number of replacements he should make.

The first line contains a single integer n (1 ≤ n ≤ 105) — the length of s. The second line contains the string s of length n. It contains small English letters 'a', 'b' and characters '?' only. The third line contains a single integer m (1 ≤ m ≤ 105) — the length of t. The string t contains letters 'a' on odd positions and 'b' on even positions.

Print the only integer — the minimum number of replacements Vasya has to perform to make the beauty of string s the maximum possible.

NoteIn the first sample string t has a form 'a'. The only optimal option is to replace all characters '?' by 'a'.In the second sample using two replacements we can make string equal to "aba?aba??". It is impossible to get more than two occurrences.

package main

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

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 toInt(buf []byte) (o int) {
    for _, v := range buf {
        o = o*10 + int(v-'0')
    }
    return
}

type pair struct {
	first int
	second int
}

type pairs []pair

func (a pairs) Len() int {return len(a)}
func (a pairs) Swap(i,j int) {a[i], a[j] = a[j], a[i]}
func (a pairs) Less(i,j int) bool {
	return a[i].first < a[j].first
	if a[i].first > a[j].first {
		return false
	}
	return a[i].second <= a[j].second
}

var MD int64 = 1000000007
var s string
var char,op_char,num_question_marks int
var question_marks,dp [100005]int
var cnt [2][2]int

func deg(d int) int64 {
	if d == 0 {
		return 1
	}
	t := deg(d / 2)
	t *= t
	t %= MD
	if d % 2 == 1 {
		t = t * 2 % MD
	}
	return t
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(in, "%d\n", &n)
	s, _ := in.ReadString('\n')
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	if t % 2 == 0 {
		char = 1
		op_char = 0
	} else {
		char = 0
		op_char = 1
	}
	for i := 0; i < len(s) - 1; i++ {
		dp[i + 1] = dp[i]
		question_marks[i + 1] = question_marks[i]

		if s[i] == '?' {
			num_question_marks++
		} else {
			if s[i] == 'a' {
				cnt[0][(i + 1)%2]++
			} else {
				cnt[1][(i + 1)%2]++
			}
		}

		d := i - t
		if d >= 0 {
			if s[d] == '?' {
				num_question_marks--
			} else {
				if s[d] == 'a' {
					cnt[0][(d + 1)%2]--
				} else {
					cnt[1][(d + 1)%2]--
				}
			}
		}

		if i + 1 >= t {
			b := cnt[char][i % 2]
			c := cnt[op_char][(i + 1) % 2]
			//fmt.Println(">>",i,b,c)
			if b == 0 && c == 0 {
				if dp[i + 1] < dp[i + 1 - t] + 1 {
					dp[i + 1] = dp[i + 1 - t] + 1
					question_marks[i + 1] = question_marks[i + 1 - t] + num_question_marks
				} else {
					if dp[i + 1] == dp[i + 1 - t] + 1 {
						question_marks[i + 1] = min(question_marks[i + 1], question_marks[i + 1 - t] + num_question_marks)
					}
				}
			}
		}
	}
	fmt.Println(question_marks[n])
}


The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - 1 games, numbered starting from 1. In game i, team 2·i - 1 will play against team 2·i. The loser is eliminated and the winner advances to the next round (there are no ties). Each subsequent round has half as many games as the previous round, and in game i the winner of the previous round's game 2·i - 1 will play against the winner of the previous round's game 2·i.Every year the office has a pool to see who can create the best bracket. A bracket is a set of winner predictions for every game. For games in the first round you may predict either team to win, but for games in later rounds the winner you predict must also be predicted as a winner in the previous round. Note that the bracket is fully constructed before any games are actually played. Correct predictions in the first round are worth 1 point, and correct predictions in each subsequent round are worth twice as many points as the previous, so correct predictions in the final game are worth 2N - 1 points.For every pair of teams in the league, you have estimated the probability of each team winning if they play against each other. Now you want to construct a bracket with the maximum possible expected score.

Input will begin with a line containing N (2 ≤ N ≤ 6). 2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of the i-th row will add to exactly 100.

Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if .

NoteIn the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1.

package main

import "fmt"

var win [][]float64

func probScore(i, j, w uint) (prob, score float64) {
	if i+1 == j {
		return 1, 0
	}
	points := (j - i) / 2
	var cp, cs float64
	if w < i+points {
		cp, cs = probScore(i, i+points, w)
		for k := i + points; k < j; k++ {
			p, s := probScore(i+points, j, k)
			prob += p * win[w][k]
			if score < s {
				score = s
			}
		}
	} else {
		cp, cs = probScore(i+points, j, w)
		for k := i; k < i+points; k++ {
			p, s := probScore(i, i+points, k)
			prob += p * win[w][k]
			if score < s {
				score = s
			}
		}
	}
	return prob * cp, score + cs + prob*cp*float64(points)
}

func main() {
	var n uint
	fmt.Scan(&n)
	win = make([][]float64, 1<<n)
	for i := range win {
		win[i] = make([]float64, 1<<n)
		for j := range win[i] {
			fmt.Scan(&win[i][j])
			win[i][j] /= 100
		}
	}
	ans := 0.
	for i := range win {
		_, s := probScore(0, uint(len(win)), uint(i))
		if ans < s {
			ans = s
		}
	}
	fmt.Printf("%.10f", ans)
}


You are given two arrays of integers $$$a_1, a_2, \ldots, a_n$$$ and $$$b_1, b_2, \ldots, b_n$$$.Let's define a transformation of the array $$$a$$$:  Choose any non-negative integer $$$k$$$ such that $$$0 \le k \le n$$$.  Choose $$$k$$$ distinct array indices $$$1 \le i_1 < i_2 < \ldots < i_k \le n$$$.  Add $$$1$$$ to each of $$$a_{i_1}, a_{i_2}, \ldots, a_{i_k}$$$, all other elements of array $$$a$$$ remain unchanged.  Permute the elements of array $$$a$$$ in any order. Is it possible to perform some transformation of the array $$$a$$$ exactly once, so that the resulting array is equal to $$$b$$$?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Descriptions of test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-100 \le a_i \le 100$$$). The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-100 \le b_i \le 100$$$).

For each test case, print "YES" (without quotes) if it is possible to perform a transformation of the array $$$a$$$, so that the resulting array is equal to $$$b$$$. Print "NO" (without quotes) otherwise. You can print each letter in any case (upper or lower).

NoteIn the first test case, we can make the following transformation:  Choose $$$k = 2$$$.  Choose $$$i_1 = 1$$$, $$$i_2 = 2$$$.  Add $$$1$$$ to $$$a_1$$$ and $$$a_2$$$. The resulting array is $$$[0, 2, 0]$$$.  Swap the elements on the second and third positions. In the second test case there is no suitable transformation.In the third test case we choose $$$k = 0$$$ and do not change the order of elements.

package main

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

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

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt(reader)
		b := readArrayInt(reader)

		sort.Ints(a)
		sort.Ints(b)
		ok := true
		for i := 0; i < n; i++ {
			if a[i] == b[i] || a[i] + 1 == b[i] {
				continue
			}
			fmt.Fprintln(writer, "NO")
			ok = false
			break
		}

		if ok {
			fmt.Fprintln(writer, "YES")
		}

		t--
	}

	writer.Flush()
}

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

func gcd(x int64, y int64) int64 {
	for y > 0 {
		x, y = y, x % y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x*y/gcd(x,y)
}

package main

import (
	"fmt"
	"sort"
)

var (
	t, n int
	a    = make([]int, 1024)
	b    = make([]int, 1024)
)

func main() {
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {

		fmt.Scanf("%d\n", &n)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &a[j])
		}
		fmt.Scanf("\n")
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &b[j])
		}
		fmt.Scanf("\n")
		sort.Ints(a[0:n])
		sort.Ints(b[0:n])
		// fmt.Printf("a is %v\n", a)
		// fmt.Printf("b is %v\n", b)
		ret := true
		for j := 0; j < n; j++ {
			if b[j] < a[j] || b[j] > a[j]+1 {
				ret = false
				break
			}
		}
		if ret {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

package main

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

/*
3
1
4
5
1
3
5
3
1 2 4
2 3 4
---
YES
NO
YES
====
1
1
3
5
---
NO
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		b := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &b[i])
		}
		scanf("\n")

		sort.Ints(a)
		sort.Ints(b)

		possible := true

		for i, numA := range a {
			numB := b[i]
			if numA != numB && numA+1 != numB {
				possible = false
				break
			}
		}

		if possible {
			fmt.Fprintln(&bld, "YES")
		} else {
			fmt.Fprintln(&bld, "NO")
		}
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scan(&n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] < a[j]
		})
		b := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&b[j])
		}
		sort.Slice(b, func(i, j int) bool {
			return b[i] < b[j]
		})

		no := false
		for j := 0; j < n; j++ {
			if a[j] == b[j] {
				continue
			}
			if a[j]+1 != b[j] {
				fmt.Println("NO")
				no = true
				break
			}
		}

		if !no {
			fmt.Println("YES")
		}

	}
}

package main

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

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

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readArrayInt(reader)
		b := readArrayInt(reader)

		sort.Ints(a)
		sort.Ints(b)
		ok := true
		for i := 0; i < n; i++ {
			if a[i] == b[i] || a[i] + 1 == b[i] {
				continue
			}
			fmt.Fprintln(writer, "NO")
			ok = false
		}

		if ok {
			fmt.Fprintln(writer, "YES")
		}

		t--
	}

	writer.Flush()
}

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

func gcd(x int64, y int64) int64 {
	for y > 0 {
		x, y = y, x % y
	}

	return x
}

func lcm(x int64, y int64) int64 {
	return x*y/gcd(x,y)
}

package main

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

/*
3
1
4
5
1
3
5
3
1 2 4
2 3 4
---
YES
NO
YES
====
1
1
3
5
---
NO
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	bld := strings.Builder{}

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		b := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &b[i])
		}
		scanf("\n")

		possible := equals(a, b)

		if !possible {
			for k := 0; k < n; k++ {
				a[k]++

				if equals(a, b) {
					possible = true
					break
				}
			}
		}

		if possible {
			fmt.Fprintln(&bld, "YES")
		} else {
			fmt.Fprintln(&bld, "NO")
		}
	}

	printf("%s", bld.String())
}

func equals(a, b []int) bool {
	if len(a) != len(b) {
		return false
	}

	sortedA := make([]int, len(a))
	sortedB := make([]int, len(b))

	copy(sortedA, a)
	copy(sortedB, b)

	sort.Ints(sortedA)
	sort.Ints(sortedB)

	for i, num := range sortedA {
		if num != sortedB[i] {
			return false
		}
	}

	return true
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	x int64
	y int64
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}


You are given a string $$$s$$$. You need to find two non-empty strings $$$a$$$ and $$$b$$$ such that the following conditions are satisfied:  Strings $$$a$$$ and $$$b$$$ are both subsequences of $$$s$$$.  For each index $$$i$$$, character $$$s_i$$$ of string $$$s$$$ must belong to exactly one of strings $$$a$$$ or $$$b$$$.  String $$$a$$$ is lexicographically minimum possible; string $$$b$$$ may be any possible string. Given string $$$s$$$, print any valid $$$a$$$ and $$$b$$$.Reminder:A string $$$a$$$ ($$$b$$$) is a subsequence of a string $$$s$$$ if $$$a$$$ ($$$b$$$) can be obtained from $$$s$$$ by deletion of several (possibly, zero) elements. For example, "dores", "cf", and "for" are subsequences of "codeforces", while "decor" and "fork" are not.A string $$$x$$$ is lexicographically smaller than a string $$$y$$$ if and only if one of the following holds:  $$$x$$$ is a prefix of $$$y$$$, but $$$x \ne y$$$;  in the first position where $$$x$$$ and $$$y$$$ differ, the string $$$x$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$y$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first and only line of each test case contains one string $$$s$$$ ($$$2 \le |s| \le 100$$$ where $$$|s|$$$ means the length of $$$s$$$). String $$$s$$$ consists of lowercase Latin letters.

For each test case, print the strings $$$a$$$ and $$$b$$$ that satisfy the given conditions. If there are multiple answers, print any.

NoteIn the first test case, there are only two choices: either $$$a =$$$ f and $$$b = $$$ c or $$$a = $$$ c and $$$b = $$$ f. And $$$a = $$$c is lexicographically smaller than $$$a = $$$ f.In the second test case, a is the only character in the string.In the third test case, it can be proven that b is the lexicographically smallest subsequence of $$$s$$$. The second string can be of two variants; one of them is given here.

package main

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

type CF1602A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1602A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1602A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1602A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1602A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1602A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1602A
Date: 21/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1602/A
Problem: CF1602A
**/
func (in *CF1602A) Run() {
	var ans strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		min := str[0]
		for i := 0; i < len(str); i++ {
			if str[i] < min {
				min = str[i]
			}
		}
		ans.WriteString(fmt.Sprintf("%s ", string(min)))
		found := false
		for i := 0; i < len(str); i++ {
			if str[i] == min && !found {
				found = true
				continue
			} else {
				ans.WriteString(string(str[i]))
			}
		}
		ans.WriteString("\n")
	}
	fmt.Print(ans.String())
}

func NewCF1602A(r *bufio.Reader) *CF1602A {
	return &CF1602A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1602A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

type CF1602A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1602A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1602A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1602A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1602A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1602A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1602A
Date: 21/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1602/A
Problem: CF1602A
**/
func (in *CF1602A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		arr := make([]int, len(str))
		for i := 0; i < len(str); i++ {
			arr[i] = int(str[i])
		}
		sort.Ints(arr)

		fmt.Print(string(arr[0]), " ")

		found := false
		for i := 0; i < len(str); i++ {
			if str[i] == uint8(arr[0]) && !found {
				found = true
				continue
			} else {
				fmt.Print(string(str[i]))
			}
		}
		fmt.Println()
	}
}

func NewCF1602A(r *bufio.Reader) *CF1602A {
	return &CF1602A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1602A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var s string
		fmt.Fscan(in, &s)

		var idx int
	Loop:
		for i := 'a'; i <= 'z'; i++ {
			for k, ch := range s {
				if ch == i {
					idx = k
					break Loop
				}
			}
		}

		fmt.Fprintf(out, "%c %s\n", s[idx], s[:idx]+s[idx+1:])
	}
}

package main

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

var s string

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int

	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(r, &s)

		solve()

		fmt.Println()
	}
}

func solve() {

	var min byte = 'z'
	var minidx int

	for i := 0; i < len(s); i++ {
		if s[i] - 'a' < min - 'a' {
			min = s[i]
			minidx = i
		}
	}

	fmt.Print(string(min))
	fmt.Print(" ")
	if minidx == 0 {
		fmt.Print(s[1 :])
	} else if minidx == len(s) - 1 {
		fmt.Print(s[ : len(s) - 1])
	} else {
		fmt.Print(s[0 : minidx] + s[minidx + 1 :])
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
)

func solve(s []byte) string {
	var (
		a byte
		b []byte
		m = make(map[byte]int)
		r = len(s)
	)
	for i := 0; i < r; i++ {
		if m[s[i]] == 0 {
			m[s[i]] = i + 1
		}
	}
	for i := byte('a'); i <= 'z'; i++ {
		if m[i] > 0 {
			a = i
			b = append(s[:m[i]-1], s[m[i]:]...)
			break
		}
	}
	return fmt.Sprintf("%c %s", a, b)
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var s []byte
		fmt.Fscan(reader, &s)
		fmt.Println(solve(s))
	}
}

package main

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

var (
	input = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assert!")}
}

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var s string
    fmt.Fscan(input, &s)
    pos := 0
    for i := 0; i < len(s); i++ {
        if s[pos] > s[i] {
            pos = i
        }
    }
    fmt.Fprint(output, string(s[pos]), " ")
    for i := 0; i < len(s); i++ {
        if i != pos {
            fmt.Fprint(output, string(s[i]))
        }
    }
    fmt.Fprintln(output)
    output.Flush()
}

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

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

package main

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

/*
5
fc
aaaa
thebrightboiler
ab
ba
---
c f
a aaa
b therightboiler
a b
a b
*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

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

	bld := strings.Builder{}

	for k := 0; k < t; k++ {
		var s string
		scanf("%s\n", &s)

		chars := make([]pair, 0)

		for i, ch := range s {
			chars = append(chars, pair{ch, i})
		}

		sort.Slice(chars, func(i, j int) bool {
			return chars[i].fst < chars[j].fst
		})

		a := string(chars[0].fst)

		var b string

		idx := chars[0].snd
		b = s[0:idx] + s[idx+1:]

		fmt.Fprintf(&bld, "%s %s\n", a, b)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

//goland:noinspection GoUnusedType
type pair struct {
	fst rune
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//goland:noinspection GoUnusedFunction
func isPrime(n int) bool {
	if n == 2 || n == 3 {
		return true
	}

	if n <= 1 || n%2 == 0 || n%3 == 0 {
		return false
	}

	for i := 5; i*i <= n; i += 6 {
		if n%i == 0 || n%(i+2) == 0 {
			return false
		}
	}

	return true
}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

func ChangeStringToDate(x string) (t time.Time, err error) {
	t, err = time.Parse("2006-01-02", x)
	return
}

func DiffrenceBetweenTwoDates(first, second time.Time) int64 {
	date := first
	date2 := second
	k := date.Unix() - date2.Unix()
	return k
}

func Union(a, b []int) []int {
	m := make(map[int]bool)

	for _, item := range a {
		m[item] = true
	}

	for _, item := range b {
		if _, ok := m[item]; !ok {
			a = append(a, item)
		}
	}
	return a
}

// for o := 0; o < t; o++ {
// 	var a, b, c int
// 	fmt.Fscan(input, &a, &b, &c)

// 	A := a % 2
// 	B := b % 2
// 	C := c % 2
// 	if A+B+C == 0 {
// 		fmt.Println(0)
// 	}
// 	if A+B+C == 1 {
// 		if A == 1 {
// 			fmt.Println(1)
// 		}
// 		if B == 1 {
// 			if a >= 2 {
// 				fmt.Println(0)
// 			} else {
// 				fmt.Println(2)
// 			}
// 		}
// 		if C == 1 {
// 			if a > 0
// 			fmt.Println(1)
// 		}
// 	}
// 	if A+B+C == 2 {

// 	}
// 	if A+B+C == 3 {
// 		fmt.Println(0)
// 	}

// }

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

func Ans(ARR []int) {
	if len(ARR) < 2 {
		return
	}
	if len(ARR) == 2 {
		fmt.Println(ARR[1])
		fmt.Println(-ARR[0])
	} else {
		if len(ARR) == 3 {
			first := ARR[0]
			Midd := ARR[1]
			Last := ARR[2]
			var F, M, L int
			Pos := 0
			Neg := 0
			if first > 0 {
				Pos++
			} else {
				Neg++
			}
			if Midd > 0 {
				Pos++
			} else {
				Neg++
			}
			if Last > 0 {
				Pos++
			} else {
				Neg++
			}
			if Pos*Neg != 0 {
				if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
					if first == Midd {
						if Midd == Last {
							F = -1
							M = -1
							L = 2
						} else {
							F = 1
							M = 1
							L = 2
						}
					} else {
						if first == Last {
							F = 1
							L = 1
							M = 2
						} else {
							M = 1
							L = 1
							F = 2
						}
					}
				} else {
					One := first + Midd
					Two := Midd + Last
					Thr := first + Last
					l := 0
					if One != 0 && ABS(One) <= 10000 {
						F = Last
						M = Last
						L = -One
						l = 1
					}

					if Two != 0 && ABS(Two) <= 10000 && l == 0 {
						F = -Two
						M = first
						L = first
						l = 1
					}
					if Thr != 0 && ABS(Thr) <= 10000 && l == 0 {
						F = Midd
						M = -Thr
						L = Midd
					}

				}
			} else {
				if ABS(first) == ABS(Midd) && ABS(Midd) == ABS(Last) {
					F = -1
					M = -1
					L = 2
				} else {
					One := first - Midd
					Two := Midd - Last
					Thr := first - Last
					l := 0
					if One != 0 && ABS(One) <= 10000 {
						F = -Last
						M = Last
						L = One
						l = 1
					}

					if Two != 0 && ABS(Two) <= 10000 && l == 0 {
						F = Two
						M = -first
						L = first
						l = 1
					}
					if Thr != 0 && ABS(Thr) <= 10000 && l == 0 {
						F = -Midd
						M = Thr
						L = Midd
					}

				}
			}

			fmt.Println(F)
			fmt.Println(M)
			fmt.Println(L)
		} else {
			Q := make([]int, 0)
			P := make([]int, 0)
			P = append(P, ARR[0], ARR[1])
			p := len(ARR)
			for i := 2; i < p; i++ {
				Q = append(Q, ARR[i])
			}
			Ans(P)
			Ans(Q)
		}
	}
}

var t int

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

	for o := 0; o < t; o++ {
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)

		k := len(STRING)
		ARR := make([]int, 0)
		for i := 0; i < k; i++ {
			ARR = append(ARR, int(STRING[i]))
		}

		sort.Ints(ARR)

		for i := 0; i < k; i++ {
			if int(STRING[i]) == ARR[0] {
				fmt.Println(string(STRING[i]))
				ans := string(STRING[:i]) + string(STRING[i+1:])

				fmt.Println(ans)
				break
			}
		}
	}

}


Polycarp has a poor memory. Each day he can remember no more than $$$3$$$ of different letters. Polycarp wants to write a non-empty string of $$$s$$$ consisting of lowercase Latin letters, taking minimum number of days. In how many days will he be able to do it?Polycarp initially has an empty string and can only add characters to the end of that string.For example, if Polycarp wants to write the string lollipops, he will do it in $$$2$$$ days:   on the first day Polycarp will memorize the letters l, o, i and write lolli;  On the second day Polycarp will remember the letters p, o, s, add pops to the resulting line and get the line lollipops. If Polycarp wants to write the string stringology, he will do it in $$$4$$$ days:   in the first day will be written part str;  on day two will be written part ing;  on the third day, part of olog will be written;  on the fourth day, part of y will be written. For a given string $$$s$$$, print the minimum number of days it will take Polycarp to write it.

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of a non-empty string $$$s$$$ consisting of lowercase Latin letters (the length of the string $$$s$$$ does not exceed $$$2 \cdot 10^5$$$) — the string Polycarp wants to construct. It is guaranteed that the sum of string lengths $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single number — minimum number of days it will take Polycarp to write the string $$$s$$$ from memory.

6

lollipops

stringology

abracadabra

codeforces

test

f

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		s := readString(reader)
		res := solve(s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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

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

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

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

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

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

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

	return i
}

func solve(s string) int {
	n := len(s)
	var res int

	for i := 0; i < n; {
		mem := make(map[byte]int)
		for i < n && len(mem) <= 3 {
			mem[s[i]]++
			i++
		}
		if len(mem) > 3 {
			i--
		}

		res++
	}

	return res
}

package main

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

var maxSize int

func init() {
	maxSize = 2 * int(math.Pow(10, 5)) + 3
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, maxSize), maxSize)
	scanner.Scan()

	n, _ := strconv.Atoi(scanner.Text())

	for i := 0; i < n; i++ {
		scanner.Scan()
		t := scanner.Text()

		c := 0
		uniq := make(map[rune]struct{}, 3)

		for _, r := range t {
			uniq[r] = struct{}{}

			if len(uniq) > 3 {
				c++
				uniq = map[rune]struct{}{r: {}}
			}
		}

		if len(uniq) > 0 {
			c++
		}

		fmt.Println(c)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	m := make(map[byte]struct{})
	for t > 0 {
		var s string
		fmt.Scan(&s)
		var cnt, ans int
		for i := range s {
			if _, ok := m[s[i]]; !ok {
				cnt++
				if cnt > 3 {
					cnt = 1
					ans++
					m = make(map[byte]struct{})
				}
				m[s[i]] = struct{}{}
			}
		}
		if cnt > 0 {
			ans += 1
		}
		fmt.Println(ans)
		t--
		m = make(map[byte]struct{})
	}
}

package main

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

func solve(in io.Reader, out io.Writer) {
	var str string
	fmt.Fscan(in, &str)
	var ans int

	for i := 0; i < len(str); i++ {
		ans++
		mp := make(map[byte]bool)
		mp[str[i]] = true
		for i+1 < len(str) {
			if len(mp) == 3 && !mp[str[i+1]] {
				break
			}
			mp[str[i+1]] = true
			i++
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		solve(in, os.Stdout)
		t--
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var word string
		fmt.Fscan(in,&word)
		var days int
		for j:=0;j<len(word);j++{
			days++
			mapper:= make(map[string]bool)
			counter:=0
			for k:=j;k<len(word);k++{
				if mapper[string(word[k])] == true {
					continue
				}
				mapper[string(word[k])] = true
				counter++
				if counter > 3 {
					j=(k-1)
					goto out
				}
			}
			break
			out:
		}
		fmt.Fprintln(out,days)
	}
}

package main

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

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

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

func main() {

	defer writer.Flush()
	var tc int
	var s string
	var ch []byte
	var ans int
	scanws(&tc)
	for t := 1; t <= tc; t++ {
		scanws(&s)
		ans = 1
		n := len(s)
		ch = nil
		for i := 0; i < n; i++ {
			nn := len(ch)
			flag := true
			for j := 0; j < nn; j++ {
				if byte(s[i]) == ch[j] {
					flag = false
				}
			}
			if flag == true {
				if nn == 3 {
					ans++
					ch = nil
				}
				ch = append(ch, s[i])
			}
		}
		printf("%d\n", ans)
	}
}

package main

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

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

	numCases := 0
	fmt.Fscan(in, &numCases)

	for ; numCases > 0; numCases-- {
		str := ""
		fmt.Fscan(in, &str)
		uniq := make(map[rune]struct{}, 3)
		daysCnt := 0
		for _, r := range str {
			_, ok := uniq[r]
			if !ok {
				if len(uniq) == 3 {
					daysCnt++
					uniq = map[rune]struct{}{}
				}
				uniq[r] = struct{}{}
			}
		}
		if len(uniq) > 0 {
			daysCnt++
		}
		fmt.Fprintln(out, daysCnt)
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	s      string
)

func solve(s string) int {
	var result = 1
	var charInDay = make(map[rune]bool)
	for _, x := range s {
		charInDay[x] = true
		if len(charInDay) == 4 {
			result++
			charInDay = make(map[rune]bool)
			charInDay[x] = true
		}
	}
	return result
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &s)
		fmt.Println(solve(s))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
  // "reflect"
)

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var s string
	scan(&s)
  r := 0
  // a := []int{}
  m := map[int]bool{}
  for _, c := range s{
    // fmt.Println(m)
    m[int(c)] = true
    if len(m) > 3{
      r += 1
      m = map[int]bool{
        int(c) : true,
      }
    }
  }
  if len(m) > 0{
    r += 1
  }
  printf("%d\n",r)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"fmt"
)

func main() {
	TC := new(int)
	fmt.Scan(TC)
	for (*TC) > 0 {
		var str string
		fmt.Scan(&str)
		hashmap := make(map[byte]bool)
		l := len(str)

		count := 0
		oscilator := 0

		for i := 0; i < l; i++ {
			if(!hashmap[str[i]]) {
//				hashmap[str[i]] = true;
//				count += 1
				if(oscilator >= 3 && !hashmap[str[i]]) {
					oscilator = 1
					count += 1
//					hashmap = nil
					hashmap = make(map[byte]bool)
				} else {
					oscilator += 1
				}
				hashmap[str[i]] = true
			}
		}
		if oscilator > 0 {
			count += 1
		}
		fmt.Println(count)
		*TC -= 1
	}
}

package main

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

type CF1702B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1702B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1702B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1702B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1702B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1702B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1702B
Date: 16/07/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1702/B
Problem: CF1702B
**/
func (in *CF1702B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()

		ans := 1
		last := 0
		for last < len(str) {
			mapa := make(map[uint8]bool)
			for i := last; i < len(str); i++ {
				mapa[str[i]] = true
				if len(mapa) == 4 {
					ans++
					last = i
					break
				}
				if i + 1 == len(str){
					last = len(str)
				}
			}
		}

		fmt.Println(ans)
	}
}

func NewCF1702B(r *bufio.Reader) *CF1702B {
	return &CF1702B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1702B(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func Solve(s string) int {
	m := map[byte]bool{}
	l := len(s)
	ans := 0
	for i := 0; i < l; i++ {
		if _, ok := m[s[i]]; !ok {
			m[s[i]] = true
			if len(m) == 4 {
				m = map[byte]bool{}
				ans += 1
				m[s[i]] = true
			}
		}
	}
	if len(m) > 0 {
		ans += 1
	}
	return ans
}

func main(){

	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for i := 0; i < t; i++ {
		var s string
		fmt.Fscan(cin, &s)
		fmt.Println(Solve(s))
	}

}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var s string
	fmt.Fscan(rr, &s)
	ans := 0
	hash := make(map[byte]bool)
	for i:=0;i<=len(s);i++ {
		if i == len(s) || (len(hash) == 3 && !hash[s[i]]) {
			ans++
			hash = make(map[byte]bool)
		}
		if i == len(s) {
			break
		}
		hash[s[i]] = true
	}
	fmt.Fprintln(ww, ans)
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

func b1702(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var x string

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &x)
		ans := 0
		a := map[int32]bool{}
		for _, v := range x {
			if a[v] {
				continue
			}
			if len(a) < 3 {
				a[v] = true
			} else {
				ans++
				a = map[int32]bool{v: true}
			}
		}
		if len(a) > 0 {
			ans++
		}
		Fprintln(out, ans)

	}
}

package main

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

var (
	_r = bufio.NewReader(os.Stdin)
	_w = bufio.NewWriter(os.Stdout)
)

type Tint interface {
	int | int32 | int64
}

func min[T Tint](x, y T) T {
	if x <= y {
		return x
	}
	return y
}
func max[T Tint](x, y T) T {
	if x >= y {
		return x
	}
	return y
}
func main() {
	defer _w.Flush()

	var _t int
	// n = 1
	fmt.Fscan(_r, &_t)
	for ; _t > 0; _t-- {
		var s string
		fmt.Fscan(_r, &s)
		mp := make(map[uint8]bool)
		ans := 0
		for i := 0; i < len(s); i++ {
			ans++
			for ; i < len(s); i++ {
				if _, ok := mp[s[i]]; !ok {
					if len(mp) >= 3 {
						i--
						mp = make(map[uint8]bool, 0)
						break
					}
					mp[s[i]] = true
				}
			}
		}
		fmt.Fprintln(_w, ans)
	}
}

package main

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

func toi(s string) int64 {
  x, _ := strconv.ParseInt(s, 10, 64)
  return x
}

func tos(i int64) string {
  return strconv.FormatInt(i, 10)
}

func solve(sc *bufio.Scanner, wr *bufio.Writer) {
  sc.Scan()
  s := []rune(sc.Text())
  counter := int64(0)
  for len(s) != 0 {
    a := map[rune]struct{}{}
    i := 0
    for i < len(s) && len(a) < 4 {
      a[s[i]] = struct{}{}
      i++
    }
    if i != len(s) || len(a) > 3 {
      i--
    }
    s = s[i:]
    counter++
  }
  wr.WriteString(tos(counter))
  wr.WriteRune('\n')
}

const (
  once = false
  maxBufSize = 10000000
)

func main() {
  sc := bufio.NewScanner(bufio.NewReader(os.Stdin))
  sc.Split(bufio.ScanWords)
  sc.Buffer(make([]byte, maxBufSize), maxBufSize)

  wr := bufio.NewWriter(os.Stdout)
  defer wr.Flush()

  if once {
    solve(sc, wr)
  } else {
    sc.Scan()
    times, _ := strconv.Atoi(sc.Text())
    for times > 0 {
      solve(sc, wr)
      times--
    }
  }
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s string
		fmt.Fscan(in, &s)

		var tot int
		aa := make([]int, 26)
		var c int
		for i := 0; i < len(s); i++ {
			if aa[s[i]-'a'] == 0 {
				aa[s[i]-'a']++
				c++
				if c == 1 {
					tot++
				} else if c == 4 {
					i--
					c = 0
					aa = make([]int, 26)
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var _, _, _ = main, rw, do

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var s string
		fmt.Fscan(r, &s)
		w1 := do(s)
		fmt.Fprintln(w, w1)
	}
}

func do(s string) int {
	var m map[rune]struct{}
	a := 0
	for _, c := range s {
		if _, ok := m[c]; ok {
			continue
		}
		if len(m) == 0 || len(m) == 3 {
			a++
			m = make(map[rune]struct{})
		}
		m[c] = struct{}{}
	}
	return a
}

package main

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

func A0() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var s string
		Fscan(in, &s)
		var i int
		var cnt int
		for i < len(s) {
			m := map[byte]int{}
			cnt++
			for i < len(s) && len(m) <= 3 {
				m[s[i]]++
				i++
			}
			if len(m) > 3 {
				i--
			}
		}
		Fprintln(out, cnt)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A0() }

// 1702B. Polycarp Writes a String from Memory
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var s string
		fmt.Fscan(reader, &s)
		m := make(map[byte]int)
		ans := 0
		for i := 0; i < len(s); i++ {
			m[s[i]]++
			if len(m) == 4 {
				ans++
				m = make(map[byte]int)
				m[s[i]]++
			}
		}
		if len(m) > 0 {
			ans++
		}
		fmt.Println(ans)

	}
}

package main

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

func solve(str string) int {
	day := 0
	i := 0

	for {
		day += 1
		cache := map[byte]bool{}

		for {
			if i == len(str) {
				break
			}

			ch := str[i]
			if _, ok := cache[ch]; ok {
				i++
				continue
			}

			if len(cache) == 3 {
				break
			} else {
				cache[ch] = true
				i++
				continue
			}
		}

		if i == len(str) {
			break
		}
	}

	return day
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var str string
		fmt.Fscanln(inp, &str)

		res := solve(str)

		fmt.Fprintln(out, res)
	}

	out.Flush()
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		s := readString(reader)
		res := solve(s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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

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

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

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

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

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

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

	return i
}

func solve(s string) int {
	n := len(s)
	var res int

	for i := 0; i < n; {
		mem := make(map[byte]int)
		for i < n && len(mem) <= 3 {
			mem[s[i]]++
			i++
		}
		if len(mem) > 3 {
			i--
		}

		res++
	}

	return res
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		s := readString(reader)
		res := solve(s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

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

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

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

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

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

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

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

	return i
}

func solve(s string) int {
	n := len(s)
	var res int

	for i := 0; i < n; {
		mem := make(map[byte]int)
		for i < n && len(mem) <= 3 {
			mem[s[i]]++
			i++
		}
		res++
		if len(mem) > 3 {
			i--
		}
	}

	return res
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 2<<4), 2*int(math.Pow(10, 5)))
	scanner.Scan()

	n, _ := strconv.Atoi(scanner.Text())

	for i := 0; i < n; i++ {
		scanner.Scan()
		t := scanner.Text()

		c := 0
		uniq := make(map[rune]struct{})

		for _, r := range t {
			uniq[r] = struct{}{}

			if len(uniq) > 3 {
				c++
				uniq = map[rune]struct{}{r: {}}
			}
		}

		if len(uniq) > 0 {
			c++
		}

		fmt.Println(c)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	m := make(map[byte]struct{})
	for t > 0 {
		var s string
		fmt.Scan(&s)
		var cnt, ans int
		for i := range s {
			if _, ok := m[s[i]]; !ok {
				cnt++
				if cnt > 3 {
					cnt = 1
					ans++
					m = make(map[byte]struct{})
				}
				m[s[i]] = struct{}{}
			}
		}
		if cnt > 0 {
			ans += 1
		}
		fmt.Println(ans)
		t--
	}
}

package main

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

func solve(in io.Reader, out io.Writer) {
	var str string
	fmt.Fscan(in, &str)
	var ans int

	for i := 0; i < len(str); i++ {
		ans++
		mp := make(map[byte]bool)
		mp[str[i]] = true
		for i+1 < len(str) {
			if len(mp) == 3 && !mp[str[i+1]] {
				break
			}
			mp[str[i+1]] = true
			i++
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	f, _ := os.Create("out.txt")
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		solve(in, f)
		t--
	}
}