You are given three integers $$$a \le b \le c$$$.In one move, you can add $$$+1$$$ or $$$-1$$$ to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation several times with one number. Note that you cannot make non-positive numbers using such operations.You have to perform the minimum number of such operations in order to obtain three integers $$$A \le B \le C$$$ such that $$$B$$$ is divisible by $$$A$$$ and $$$C$$$ is divisible by $$$B$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given on a separate line as three space-separated integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a \le b \le c \le 10^4$$$).

For each test case, print the answer. In the first line print $$$res$$$ — the minimum number of operations you have to perform to obtain three integers $$$A \le B \le C$$$ such that $$$B$$$ is divisible by $$$A$$$ and $$$C$$$ is divisible by $$$B$$$. On the second line print any suitable triple $$$A, B$$$ and $$$C$$$.

package main

import (
	"fmt"
)

const MaxInt = 10000000

var(
	test int
	a int
	b int
	c int
)

func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}

func valid(i , j ,k int) (int){
	if( j%i != 0 || k%j != 0){
		return MaxInt
	}
	return abs(a-i) + abs(b-j) + abs(c-k)
}

func main(){
	fmt.Scan(&test)
	var ans[3] int
	for ; test > 0 ; test-- {
		fmt.Scan(&a,&b,&c)
		cost := MaxInt
		for i:=1 ; i <= 12000 ; i++{
			for j:=i ; j <= 12000 ; j+=i{
				for k:= j ; k <= 12000 ; k+=j{
					cur := valid(i,j,k)
					if(cur < cost){
						cost = cur
						ans = [3]int {i,j,k}
					}
				}
			}
		}
		fmt.Println(cost)
		fmt.Println(ans[0],ans[1],ans[2])
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a, b, c int
		fmt.Scanf("%d %d %d\n", &a, &b, &c)
		distance, aa, bb, cc := 50000.0, 0, 0, 0
		for i := 1; i <= 10000; i++ {
			for j := i; j <= 20000; j += i {
				left := c / j
				if (c - left*j) < (left+1)*j-c {
					left = left*j
				} else {
					left = (left+1)*j
				}
				d := math.Abs(float64(a-i)) + math.Abs(float64(b-j)) + math.Abs(float64(c-left))
				if d < distance {
					distance = d
					aa = i
					bb = j
					cc = left
				}

			}
		}
		fmt.Println(int(distance))
		fmt.Println(aa, bb, cc)
	}
}

package main

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

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

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

	for t := 0; t < ts; t++ {
		var a, b, c int
		fmt.Fscanf(r, "%d %d %d\n", &a, &b, &c)

		var ta, tb, tc int
		best := int(1e9)

		for i := 1; i <= c; i++ {
			for j := i; j <= c+i; j += i {
				cc := Abs(a-i) + Abs(b-j)
				if j >= c {
					cc += Abs(c - j)
				} else {
					cc += min(c-(c/j)*j, ((c+j-1)/j)*j-c)
				}

				if best > cc {
					best = cc
					ta = i
					tb = j
					if c-(c/j)*j <= ((c+j-1)/j)*j-c {
						tc = (c / j) * j
					} else {
						tc = ((c + j - 1) / j) * j
					}
				}
			}
		}

		fmt.Fprintf(w, "%d\n", best)
		fmt.Fprintf(w, "%d %d %d\n", ta, tb, tc)
	}
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1311D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}

	var t, a, b, c, ti, tj, tk int
	for Fscan(in, &t); t > 0; t-- {
		ans := int(1e9)
		Fscan(in, &a, &b, &c)
		for i := 1; i < 2*a; i++ {
			for j := i; j < 2*b; j += i {
				k := c / j
				if k == 0 {
					k = j
				} else {
					k *= j
					if abs(k+j-c) < abs(k-c) {
						k += j
					}
				}
				if v := abs(i-a) + abs(j-b) + abs(k-c); v < ans {
					ans, ti, tj, tk = v, i, j, k
				}
			}
		}
		Fprintln(out, ans)
		Fprintln(out, ti, tj, tk)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1311D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}

	var t, a, b, c, ti, tj, tk int
	for Fscan(in, &t); t > 0; t-- {
		ans := int(1e9)
		Fscan(in, &a, &b, &c)
		for i := 1; i < 2*a; i++ {
			for j := i; j < 2*b; j += i {
				k := c - c%j
				if k == 0 {
					k = j
				} else if abs(k+j-c) < abs(k-c) {
					k += j
				}
				if v := abs(i-a) + abs(j-b) + abs(k-c); v < ans {
					ans, ti, tj, tk = v, i, j, k
				}
			}
		}
		Fprintln(out, ans)
		Fprintln(out, ti, tj, tk)
	}
}

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

package main

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

func main() {

	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		diff := math.MaxInt32

		A, B, C := -1, -1, -1

		for i := 1; i <= 2*a; i++ {
			for j := i; j <= 2*b; j += i {
				for k := 0; k < 2; k++ {

					cc := j*(c/j) + (k * j)

					res := abs(a-i) + abs(b-j) + abs(c-cc)
					if res < diff {
						diff = res
						A, B, C = i, j, cc
					}
				}
			}
		}
		P(diff)
		P(A, B, C)
	}
	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		aValue, bValue, cValue := -1, -1, -1
		ultraMax := 20005
		answer := 10005
		for i := 1; i <= ultraMax; i++{
			for j := i; j <= ultraMax; j+=i{
				cost := abs(i - a) + abs(j-b)
				if cost < answer{
					cModified := (c + j/2) / j*j
					cost += abs(cModified - c)
					if cost < answer {
						answer = cost
						aValue = i
						bValue = j
						cValue = cModified
					}
				}
			}
		}
		fmt.Println(answer)
		fmt.Println(aValue, bValue, cValue)
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		aValue, bValue, cValue := -1, -1, -1
		answer := 10005
		for i := 1; i <= c+100; i++{
			for j := i; j <= c+100; j+=i{
				cost := abs(i - a) + abs(j-b)
				if cost < answer{
					cModified := (c + j/2) / j*j
					cost += abs(cModified - c)
					if cost < answer {
						answer = cost
						aValue = i
						bValue = j
						cValue = cModified
					}
				}
			}
		}
		fmt.Println(answer)
		fmt.Println(aValue, bValue, cValue)
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		aValue, bValue, cValue := -1, -1, -1
		//ultraMax := 20005
		answer := 10005
		for i := 1; i <= 2*a; i++{
			for j := i; j <= 2*b; j+=i{
				cost := abs(i - a) + abs(j-b)
				if cost < answer{
					cModified := (c + j/2) / j*j
					cost += abs(cModified - c)
					if cost < answer {
						answer = cost
						aValue = i
						bValue = j
						cValue = cModified
					}
				}
			}
		}
		fmt.Println(answer)
		fmt.Println(aValue, bValue, cValue)
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		aValue, bValue, cValue := -1, -1, -1
		answer := 10005
		for i := 1; i <= c+50; i++{
			for j := i; j <= c+50; j+=i{
				cost := abs(i - a) + abs(j-b)
				if cost < answer{
					cModified := (c + j/2) / j*j
					cost += abs(cModified - c)
					if cost < answer {
						answer = cost
						aValue = i
						bValue = j
						cValue = cModified
					}
				}
			}
		}
		fmt.Println(answer)
		fmt.Println(aValue, bValue, cValue)
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		aValue, bValue, cValue := -1, -1, -1
		answer := 10005
		for i := 1; i <= c+10; i++{
			for j := i; j <= c+10; j+=i{
				cost := abs(i - a) + abs(j-b)
				if cost < answer{
					cModified := (c + j/2) / j*j
					cost += abs(cModified - c)
					if cost < answer {
						answer = cost
						aValue = i
						bValue = j
						cValue = cModified
					}
				}
			}
		}
		fmt.Println(answer)
		fmt.Println(aValue, bValue, cValue)
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		var a, b, c int
		fmt.Scanf("%d %d %d\n", &a, &b, &c)
		distance, aa, bb, cc := 40000.0, 0, 0, 0
		for i := 1; i <= 10000; i++ {
			for j := i; j <= 10000; j += i {
				left := c / j
				if (c - left*j) < (left+1)*j-c {
					left = left*j
				} else {
					left = (left+1)*j
				}
				d := math.Abs(float64(a-i)) + math.Abs(float64(b-j)) + math.Abs(float64(c-left))
				if d < distance {
					distance = d
					aa = i
					bb = j
					cc = left
				}

			}
		}
		fmt.Println(int(distance))
		fmt.Println(aa, bb, cc)
	}
}

package main

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

func main() {

	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		diff := math.MaxInt32

		A, B, C := 0, 0, 0

		for i := 1; i < 2*a; i++ {
			for j := 1; j < 2*b; j++ {
				for k := 0; k < 2; k++ {
					cc := j*(c/j) + (k * i)

					res := abs(a-i) + abs(b-j) + abs(c-cc)
					if res < diff {
						diff = res
						A, B, C = i, j, cc
					}
				}
			}
		}
		P(diff)
		P(A, B, C)
	}
	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {

	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		diff := math.MaxInt32

		A, B, C := -1, -1, -1

		for i := 1; i <= 2*a; i++ {
			for j := i; j <= 2*b; j += i {
				for k := 0; k < 2; k++ {

					cc := j*(c/j) + (k * i)

					res := abs(a-i) + abs(b-j) + abs(c-cc)
					if res < diff {
						diff = res
						A, B, C = i, j, cc
					}
				}
			}
		}
		P(diff)
		P(A, B, C)
	}
	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		aValue, bValue, cValue := -1, -1, -1
		answer := 10005
		for i := 1; i <= c+1; i++{
			for j := i; j <= c+1; j+=i{
				cost := abs(i - a) + abs(j-b)
				if cost < answer{
					cModified := (c + j/2) / j*j
					cost += abs(cModified - c)
					if cost < answer {
						answer = cost
						aValue = i
						bValue = j
						cValue = cModified
					}
				}
			}
		}
		fmt.Println(answer)
		fmt.Println(aValue, bValue, cValue)
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		aValue, bValue, cValue := -1, -1, -1
		ultraMax := 20005
		answer := 10005
		for i := 1; i <= ultraMax; i++{
			for j := i; j <= ultraMax; j+=i{
				cost := abs(i - a) + abs(j-b)
				if cost < answer{
					cModified := (c + j/2) / j*j
					cost += abs(cModified - c)
					fmt.Println(cost)
					fmt.Println(answer)
					fmt.Println()
					if cost < answer {
						answer = cost
						aValue = i
						bValue = j
						cValue = cModified
					}
				}
			}
		}
		fmt.Println(answer)
		fmt.Println(aValue, bValue, cValue)
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		a, b, c := ScanInt(), ScanInt(), ScanInt()
		aValue, bValue, cValue := -1, -1, -1
		answer := 10005
		for i := 1; i <= c; i++{
			for j := i; j <= c; j+=i{
				cost := abs(i - a) + abs(j-b)
				if cost < answer{
					cModified := (c + j/2) / j*j
					cost += abs(cModified - c)
					if cost < answer {
						answer = cost
						aValue = i
						bValue = j
						cValue = cModified
					}
				}
			}
		}
		fmt.Println(answer)
		fmt.Println(aValue, bValue, cValue)
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

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

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.A Bitlandish string is a string made only of characters "0" and "1".BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.

The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 106.

Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.

package main

import "os"
import "bufio"

func main(){
	var a string
	var b string
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	a, _ = r.ReadString('\n')
	b, _ = r.ReadString('\n')

	lena := len(a)
	lenb := len(b)

	found1 := 0
	found2 := 0
	if lena != lenb {
		w.WriteString("NO")
		w.Flush()
	} else {
		for i:=0; i<lena; i++ {
			if string(a[i]) == "1" {
				found1 = 1
			}
			if string(b[i]) == "1" {
				found2 = 1
			}
			if found1 == 1 && found2 == 1 {
				break
			}
		}
		if found1^found2 == 0 {
			w.WriteString("YES")
			w.Flush()
		} else {
			w.WriteString("NO")
			w.Flush()
		}
	}

	w.WriteString("\n")
	w.Flush()
}

package main

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

func main() {
    reader := bufio.NewReader(os.Stdin)
    var a,b string
    fmt.Fscan(reader,&a,&b)
    ans := false
    if len(a) == len(b) {
        ina, inb := 0, 0
        for i := 0; i < len(a); i++ {
            if (ina == i) && (a[ina] == '0') { ina++ }
            if (inb == i) && (b[inb] == '0') { inb++ }
        }
        if ((ina == len(a)) && (inb == len(b))) || ((ina != len(a)) && (inb != len(b))) { ans = true }
    }
    if ans { fmt.Println("YES") } else { fmt.Println("NO") }
}

package main

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

var in = bufio.NewReader(os.Stdin)

func xor(x, y bool) bool {
	if x == y {
		return false
	}
	return true
}

func main() {
	a, _ := in.ReadString('\n')
	b, _ := in.ReadString('\n')
	if len(a) != len(b) || xor(!strings.Contains(a, "1"), !strings.Contains(b, "1")) {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	a, _ := in.ReadString('\n')
	b, _ := in.ReadString('\n')
	if len(a) != len(b) || strings.Contains(a, "1") != strings.Contains(b, "1") {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

// 282C
package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	a, _ := in.ReadString('\n')
	b, _ := in.ReadString('\n')
	al, bl := len(a), len(b)
	if strings.Contains(a, "1") != strings.Contains(b, "1") || al != bl {
		fmt.Print("NO")
	} else {
		fmt.Print("YES")
	}
}

// 282C-mic_rizal
package main

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

func main() {
    var s1, s2 string
    z := bufio.NewReader(os.Stdin)
    var l1, l2, o1, o2 int
    fmt.Fscan(z, &s1, &s2)
    l1 = len(s1)
    l2 = len(s2)
    if l1 != l2 {
        fmt.Println("NO")
    } else {
        for i := 0; i < l1; i++ {
            if s1[i] == '1' {
                o1 = 1
            }
        }
        for i := 0; i < l2; i++ {
            if s2[i] == '1' {
                o2 = 1
            }
        }
        if (o1 ^ o2) > 0 {
            fmt.Println("NO")
        } else {
            fmt.Println("YES")
        }
    }
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/282/C

package main

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

func allZeros(s string) bool {
	for _, elem := range s {
		if string(elem) == "1" {
			return false
		}
	}
	return true
}

func Solve(a string, b string) string {
	if len(a) != len(b) {
		return "NO"
	}
	if allZeros(a) != allZeros(b) {
		return "NO"
	}
	return "YES"
}

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

	var a, b string
	fmt.Fscanf(reader, "%s\n", &a)
	fmt.Fscanf(reader, "%s\n", &b)

	fmt.Fprintf(writer, "%s\n", Solve(a, b))
}

package main

import "os"
import "bufio"
import "strings"
//import "strconv"

func cari(x, a string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			ketemu = true
			return ketemu
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if a == b {
		w.WriteString("YES")
		w.Flush()
	} else if len(a) != len(b) || strings.Contains(a, "1") != strings.Contains(b, "1") {
		w.WriteString("NO")
		w.Flush()
	} else {
		w.WriteString("YES")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
//import "strconv"

func cari(x, a, b string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			for j:=0; j<len(b); j++ {
				if string(b[j]) == x {
					ketemu = true
					return ketemu
				}
			}
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if len(a) != len(b) {
		w.WriteString("NO")
		w.Flush()
	} else if string(a) == "0" && string(b) == "0" {
		w.WriteString("YES")
		w.Flush()
	} else if cari("1", a, b) {
		w.WriteString("YES")
		w.Flush()
	} else {
		w.WriteString("NO")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
//import "strconv"

func cari(x, a, b string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			for j:=0; j<len(b); j++ {
				if string(b[j]) == x {
					ketemu = true
					return ketemu
				}
			}
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if len(a) != len(b) {
		w.WriteString("NO")
		w.Flush()
	} else if string(a) == "0" && string(b) == "0" {
		w.WriteString("NO")
		w.Flush()
	} else if cari("1", a, b) {
		w.WriteString("YES")
		w.Flush()
	} else {
		w.WriteString("NO")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
//import "strconv"

func cari(x, a string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			ketemu = true
			return ketemu
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if len(a) != len(b) || cari("1", a) != cari("1", b) {
		w.WriteString("NO")
		w.Flush()
	} else {
		w.WriteString("YES")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
import "strings"
//import "strconv"

func cari(x, a string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			ketemu = true
			return ketemu
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	con := strings.Contains(a, "1") != strings.Contains(b, "1")
	if a == b {
		w.WriteString("YES")
		w.Flush()
	} else if len(a) != len(b) || con == true {
		w.WriteString("NO")
		w.Flush()
	} else {
		w.WriteString("YES")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
//import "strconv"

func cari(x, a, b string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			for j:=0; j<len(b); j++ {
				if string(b[j]) == x {
					ketemu = true
					return ketemu
				}
			}
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if len(a) != len(b) || !cari("1", a, b) {
		w.WriteString("NO")
		w.Flush()
	} else {
		w.WriteString("YES")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "fmt"
import "os"
import "bufio"
//import "strconv"

func cari(x, a string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			ketemu = true
			return ketemu
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	con := cari("1", a) != cari("1", b)
	if len(a) != len(b) || con == true {
		fmt.Print("NO")
	} else {
		fmt.Print("YES")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
//import "strconv"

func cari(x, a, b string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			for j:=0; j<len(b); j++ {
				if string(b[j]) == x {
					ketemu = true
					return ketemu
				}
			}
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if len(a) != len(b) {
		w.WriteString("NO")
		w.Flush()
	} else if cari("1", a, b) {
		w.WriteString("YES")
		w.Flush()
	} else {
		w.WriteString("NO")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()

	lena := len(a)
	lenb := len(b)

	found1 := 0
	found2 := 0
	if lena != lenb {
		w.WriteString("NO")
		w.Flush()
	} else {
		for i:=0; i<lena; i++ {
			if string(a[i]) == "1" {
				found1 = 1
			}
			if string(b[i]) == "1" {
				found2 = 1
			}
			if found1 == 1 && found2 == 1 {
				break
			}
		}
		if found1^found2 == 0 {
			w.WriteString("YES")
			w.Flush()
		} else {
			w.WriteString("NO")
			w.Flush()
		}
	}

	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
//import "strconv"

func cari(x, a, b string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			for j:=0; j<len(b); j++ {
				if string(b[j]) == x {
					ketemu = true
					return ketemu
				}
			}
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if len(a) != len(b) {
		w.WriteString("NO")
		w.Flush()
	} else if a == b {
		w.WriteString("YES")
		w.Flush()
	} else if cari("1", a, b) {
		w.WriteString("YES")
		w.Flush()
	} else {
		w.WriteString("NO")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
//import "strconv"

func cari(x, a, b string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			for j:=0; j<len(b); j++ {
				if string(b[j]) == x {
					ketemu = true
					return ketemu
				}
			}
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if a == b {
		w.WriteString("YES")
		w.Flush()
	} else if len(a) != len(b) || !cari("1", a, b) {
		w.WriteString("NO")
		w.Flush()
	} else {
		w.WriteString("YES")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "fmt"
import "os"
import "bufio"
//import "strconv"

func cari(x, a string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			ketemu = true
			return ketemu
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if len(a) != len(b) || cari("1", a) != cari("1", b) {
		fmt.Print("NO")
	} else {
		fmt.Print("YES")
	}
	w.WriteString("\n")
	w.Flush()
}

package main

import "os"
import "bufio"
//import "strconv"

func cari(x, a, b string) bool {
	ketemu := false
	for i:=0; i<len(a); i++ {
		if string(a[i]) == x {
			for j:=0; j<len(b); j++ {
				if string(b[j]) == x {
					ketemu = true
					return ketemu
				}
			}
		}
	}
	return ketemu
}

func main(){
	var a string
	var b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	if a == b {
		w.WriteString("YES")
		w.Flush()
	} else if len(a) != len(b) {
		w.WriteString("NO")
		w.Flush()
	} else if !cari("1", a, b) {
		w.WriteString("NO")
		w.Flush()
	} else {
		w.WriteString("YES")
		w.Flush()
	}
	w.WriteString("\n")
	w.Flush()
}

// 282C
package main

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

func main() {
	var (
		a, b [1000005]int
		m, n int
	)
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &a)
	fmt.Fscan(in, &b)
	m = len(a)
	n = len(b)

	if m != n {
		fmt.Print("NO")
		return
	}
	p, q := 0, 0
	for i := 0; i < n; i++ {
		if a[i] == '1' {
			p = 1
		}
		if b[i] == '1' {
			q = 1
		}
	}
	if p == q {
		fmt.Fprint(out, "YES")
	} else {
		fmt.Fprint(out, "NO")
	}
	out.Flush()
}

// 282C
package main

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

func main() {
	var (
		a, b [1000005]int
		m, n int
	)
	in := bufio.NewScanner(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	in.Split(bufio.ScanWords)
	in.Scan()
	a[m], _ = strconv.Atoi(in.Text())
	in.Scan()
	b[n], _ = strconv.Atoi(in.Text())
	m = len(a)
	n = len(b)

	if m != n {
		fmt.Print("NO")
		return
	}
	p, q := 0, 0
	for i := 0; i < n; i++ {
		if a[i] == '1' {
			p = 1
		}
		if b[i] == '1' {
			q = 1
		}
	}
	if p == q {
		fmt.Fprint(out, "YES")
	} else {
		fmt.Fprint(out, "NO")
	}
	out.Flush()
}


Every superhero has been given a power value by the Felicity Committee. The avengers crew wants to maximize the average power of the superheroes in their team by performing certain operations.Initially, there are $$$n$$$ superheroes in avengers team having powers $$$a_1, a_2, \ldots, a_n$$$, respectively. In one operation, they can remove one superhero from their team (if there are at least two) or they can increase the power of a superhero by $$$1$$$. They can do at most $$$m$$$ operations. Also, on a particular superhero at most $$$k$$$ operations can be done.Can you help the avengers team to maximize the average power of their crew?

The first line contains three integers $$$n$$$, $$$k$$$ and $$$m$$$ ($$$1 \le n \le 10^{5}$$$, $$$1 \le k \le 10^{5}$$$, $$$1 \le m \le 10^{7}$$$) — the number of superheroes, the maximum number of times you can increase power of a particular superhero, and the total maximum number of operations. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^{6}$$$) — the initial powers of the superheroes in the cast of avengers.

Output a single number — the maximum final average power. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-6}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-6}$$$.

NoteIn the first example, the maximum average is obtained by deleting the first element and increasing the second element four times.In the second sample, one of the ways to achieve maximum average is to delete the first and the third element and increase the second and the fourth elements by $$$2$$$ each.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"

	"math"
	"sort"
)

func main() {
	n, k, m := readInt3()
	a := readInts()

	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	if m < k {
		k = m
	}
	var s float64
	var r float64

	for i := 1; i <= n; i++ {
		s += float64(a[i-1])
		ds := math.Min(float64(m-(n-i)), float64(k)*float64(i))
		r1 := (s+ds) / float64(i)
		if ds >= 0 && r1 > r {
			r = r1
		}
	}

	fmt.Println(r)
}

var (
	stdin = bufio.NewReader(os.Stdin)
)

func readLine() string {
	s, _ := stdin.ReadString('\n')
	return s
}

func readInts() (r []int) {
	reader := strings.NewReader(readLine())
	for {
		var x int
		_, err := fmt.Fscan(reader, &x)
		if err != nil {
			break
		}
		r = append(r, x)
	}
	return
}

func readInt3() (int, int, int) {
	a := readInts()
	return a[0], a[1], a[2]
}

package main

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

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 min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

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

func main() {
	defer writer.Flush()
	var n, k, m int
	var t1, tot, cum, mm int64
	arr := []int64{}
	scanf("%d %d %d\n", &n, &k, &m)

	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		arr = append(arr, t1)
		tot += t1
	}
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})

	ansf := float64(0)
	tem := float64(0)

	for i := 0; i < n; i++ {
		mm = int64(m - i)
		if mm < 0 {
			break
		}
		canInc := min(mm, int64(n-i)*int64(k))
		t1 = tot - cum + canInc

		tem = float64(t1)
		tem /= float64(n - i)

		if tem > ansf {
			ansf = tem
		}
		cum += arr[i]
	}

	printf("%.10f", ansf)
}

package main

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

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 min(x, y int64) int64 {
	if x < y {
		return x
	}
	return y
}

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

func main() {
	defer writer.Flush()
	var n, k, m int
	var t1, tot, cum, mm int64
	arr := []int64{}
	scanf("%d %d %d\n", &n, &k, &m)

	for i := 0; i < n; i++ {
		scanf("%d", &t1)
		arr = append(arr, t1)
		tot += t1
	}
	sort.Slice(arr, func(i, j int) bool {
		return arr[i] < arr[j]
	})

	ansf := float64(0)
	tem := float64(0)

	for i := 0; i < n; i++ {
		mm = int64(m - i)
		canInc := min(mm, int64(n-i)*int64(k))
		t1 = tot - cum + canInc

		tem = float64(t1)
		tem /= float64(n - i)

		if tem > ansf {
			ansf = tem
		}
		cum += arr[i]
	}

	printf("%.10f", ansf)
}


Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase.Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters.To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions.

The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105.

Print a single number — the least number of actions needed to make the message fancy.

package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	prefix := make([]int, len(s) + 1)
	suffix := make([]int, len(s) + 2)
	for i := 1;i <= len(s);i ++ {
		if s[i - 1] >= 'a' && s[i - 1] <= 'z' {
			prefix[i] = prefix[i - 1] + 1
		} else {
			prefix[i] = prefix[i - 1]
		}
	}
	for i := len(s);i > 0;i -- {
		if s[i - 1] >= 'A' && s[i - 1] <= 'Z' {
			suffix[i] = suffix[i + 1] + 1
		} else {
			suffix[i] = suffix[i + 1]
		}
	}
	min := 9999999
	for i := 1;i <= len(s);i ++ {
		if prefix[i] + suffix[i] < min {
			min = prefix[i] + suffix[i]
		}
	}
	fmt.Printf("%d", min - 1)
}

//http://codeforces.com/problemset/problem/180/C
//C. Letter

package main

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

func main() {
	var (
		s0, s1, b0, b1 int32 // small,big
		in             *bufio.Reader
		c              byte
		tc             int8
	)

	in = bufio.NewReader(os.Stdin)

	min := func(x, y int32) int32 {
		if x < y {
			return x
		}
		return y
	}

	readltr := func() {
		c, _ = in.ReadByte()
		if 'a' <= c && c <= 'z' {
			tc = -1
			return
		}
		if 'A' <= c && c <= 'Z' {
			tc = 1
			return
		}
		tc = 0
	}

	for {
		readltr()
		if tc != 0 {
			break
		}
	}

	//fmt.Printf("%c\n", c)

	if tc > 0 {
		s1 = 1
		b1 = 0
	} else {
		s1 = 0
		b1 = 1
	}

LOOP:
	for {
		b0, s0 = b1, s1
		readltr()
		//fmt.Printf("%c\n", c)

		switch tc {
		case 1:
			b1, s1 = b0, 1+min(b0, s0)
		case -1:
			b1, s1 = 1+b0, min(b0, s0)
		case 0:
			break LOOP
		}
	}

	fmt.Println(min(s1, b1))
}

//http://codeforces.com/problemset/problem/180/C
//C. Letter

package main

import (
	"fmt"
)

func main() {
	var (
		i, lmsg, s0, s1, b0, b1 int32 // small,big
		msg                     string
	)

	min := func(x, y int32) int32 {
		if x < y {
			return x
		}
		return y
	}

	fmt.Scan(&msg)
	lmsg = int32(len(msg))
	if msg[0] <= 'Z' {
		s0 = 1
		b0 = 0
	} else {
		s0 = 0
		b0 = 1
	}

	for i = 1; i < lmsg; i++ {
		if msg[i] <= 'Z' {
			b1, s1 = b0, 1+min(b0, s0)
		} else {
			b1, s1 = 1+b0, min(b0, s0)
		}
		b0, s0 = b1, s1
	}

	fmt.Println(min(s1, b1))
}

//http://codeforces.com/problemset/problem/180/C
//C. Letter

package main

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

func main() {
	var (
		i, lmsg, s0, s1, b0, b1 int32 // small,big
		msg                     string
		in                      *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	min := func(x, y int32) int32 {
		if x < y {
			return x
		}
		return y
	}

	msg, _ = in.ReadString('\n')
	lmsg = int32(len(msg))
	if msg[0] <= 'Z' {
		s0 = 1
		b0 = 0
	} else {
		s0 = 0
		b0 = 1
	}

	for i = 1; i < lmsg; i++ {
		if msg[i] <= 'Z' {
			b1, s1 = b0, 1+min(b0, s0)
		} else {
			b1, s1 = 1+b0, min(b0, s0)
		}
		b0, s0 = b1, s1
	}

	fmt.Println(min(s1, b1))
}


Kuznecov likes art, poetry, and music. And strings consisting of lowercase English letters.Recently, Kuznecov has found two strings, $$$a$$$ and $$$b$$$, of lengths $$$n$$$ and $$$m$$$ respectively. They consist of lowercase English letters and no character is contained in both strings. Let another string $$$c$$$ be initially empty. Kuznecov can do the following two types of operations:  Choose any character from the string $$$a$$$, remove it from $$$a$$$, and add it to the end of $$$c$$$.  Choose any character from the string $$$b$$$, remove it from $$$b$$$, and add it to the end of $$$c$$$. But, he can not do more than $$$k$$$ operations of the same type in a row. He must perform operations until either $$$a$$$ or $$$b$$$ becomes empty. What is the lexicographically smallest possible value of $$$c$$$ after he finishes?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 \neq 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$$$.

There are several test cases in the input data. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. This is followed by the test cases description. The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1\leq n,m,k \leq 100$$$) — parameters from the statement. The second line of each test case contains the string $$$a$$$ of length $$$n$$$. The third line of each test case contains the string $$$b$$$ of length $$$m$$$.  The strings contain only lowercase English letters. It is guaranteed that no symbol appears in $$$a$$$ and $$$b$$$ simultaneously.

In each test case, output a single string $$$c$$$ — the answer to the problem.

3

6 4 2

aaaaaa

bbbb

5 9 3

caaca

bedededeb

7 7 1

noskill

wxhtzdy

NoteIn the first test case, it is optimal to take two 'a's from the string $$$a$$$ and add them to the string $$$c$$$. Then it is forbidden to take more characters from $$$a$$$, hence one character 'b' from the string $$$b$$$ has to be taken. Following that logic, we end up with $$$c$$$ being 'aabaabaa' when string $$$a$$$ is emptied.In the second test case it is optimal to take as many 'a's from string $$$a$$$ as possible, then take as many 'b's as possible from string $$$b$$$. In the end, we take two 'c's from the string $$$a$$$ emptying it.

package main

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

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

func (in *CF1689A) 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 *CF1689A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1689A
Date: 2/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1689/A
Problem: CF1689A
**/
func (in *CF1689A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, m, k := in.NextInt(), in.NextInt(), in.NextInt()
		g := in.NextString()
		h := in.NextString()

		a := make([]uint8, n)
		b := make([]uint8, m)

		for i := 0; i < n; i++ {
			a[i] = g[i]
		}

		sort.Slice(a, func(i, j int) bool {
			if a[i] < a[j] {
				return true
			}
			return false
		})

		for i := 0; i < m; i++ {
			b[i] = h[i]
		}

		sort.Slice(b, func(i, j int) bool {
			if b[i] < b[j] {
				return true
			}
			return false
		})

		sol := ""
		for i, j, p, q := 0, 0, 0, 0; ; {
			x := uint8('-')
			if i < n {
				x = a[i]
			}

			y := uint8('-')
			if j < m {
				y = b[j]
			}
			if x != '-' && y != '-' {
				if x < y {
					if p < k {
						sol += string(rune(x))
						p++
						q = 0
						i++
					} else {
						sol += string(rune(y))
						p = 0
						q = 1
						j++
					}
				} else {
					if q < k {
						sol += string(rune(y))
						q++
						j++
						p = 0
					} else {
						sol += string(rune(x))
						q = 0
						p = 1
						i++
					}
				}
			} else {
				break
			}
		}
		fmt.Println(sol)

	}
}

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

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

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
	for iter := 0; iter < ntests; iter++ {
		var n, m, k int
		fmt.Fscan(scanner, &n, &m, &k)
		var rs1, rs2 string
		fmt.Fscan(scanner, &rs1, &rs2)
		s1 := []byte(rs1)
		s2 := []byte(rs2)
		sort.Slice(s1, func(i, j int) bool { return s1[i] < s1[j] })
		sort.Slice(s2, func(i, j int) bool { return s2[i] < s2[j] })
		res := make([]byte, n+m-1)
		last, reps := 1, 0
		var i int
		for i = 0; len(s1)*len(s2) != 0; i++ {
			if s1[0] <= s2[0] {
				if reps != k {
					if last == 1 {
						reps++
					} else {
						last, reps = 1, 1
					}
					res[i] = s1[0]
					s1 = s1[1:]
				} else {
					if last == 2 {
						last, reps = 1, 1
						res[i] = s1[0]
						s1 = s1[1:]
					} else {
						last, reps = 2, 1
						res[i] = s2[0]
						s2 = s2[1:]
					}
				}
			} else {
				if reps != k {
					if last == 2 {
						reps++
					} else {
						last, reps = 2, 1
					}
					res[i] = s2[0]
					s2 = s2[1:]
				} else {
					if last == 1 {
						last, reps = 2, 1
						res[i] = s2[0]
						s2 = s2[1:]
					} else {
						last, reps = 1, 1
						res[i] = s1[0]
						s1 = s1[1:]
					}
				}
			}
		}
		for j := 0; j < i; j++ {
			fmt.Fprintf(writer, "%c", res[j])
		}
		fmt.Fprintln(writer)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,M,K := gi(),gi(),gi(); A := gbs(); B := gbs()
		sort.Slice(A,func(i,j int) bool { return A[i] < A[j] } )
		sort.Slice(B,func(i,j int) bool { return B[i] < B[j] } )
		C := make([]byte,0,M+N); last := -1; lastcnt := 0; aidx := 0; bidx := 0
		for {
			if lastcnt == K && last == 0 {
				C = append(C,B[bidx]); bidx++; last,lastcnt = 1,1; if bidx == M { break }
			} else if lastcnt == K && last == 1 {
				C = append(C,A[aidx]); aidx++; last,lastcnt = 0,1; if aidx == N { break }
			} else if A[aidx] < B[bidx] {
				C = append(C,A[aidx]); aidx++; if last == 0 { lastcnt++ } else { last,lastcnt = 0,1 }; if aidx == N { break }
			} else {
				C = append(C,B[bidx]); bidx++; if last == 1 { lastcnt++ } else { last,lastcnt = 1,1 }; if bidx == M { break }
			}
		}
		fmt.Fprintln(wrtr,string(C))
	}
}

package main

import (
	"fmt"
)

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

	for i := 0; i < N; i++ {
		var n, m, k int
		fmt.Scan(&n, &m, &k)
		var sn, sm []byte
		fmt.Scan(&sn, &sm)

		var n0, m0, kn, km int
		for n0 < n && m0 < m {
			nmin := sn[n0]
			mmin := sm[m0]
			for ni := n0; ni < n; ni++ {
				if sn[ni] < nmin {
					nmin = sn[ni]
					sn[ni] = sn[n0]
					sn[n0] = nmin
				}
			}
			for mi := m0; mi < m; mi++ {
				if sm[mi] < mmin {
					mmin = sm[mi]
					sm[mi] = sm[m0]
					sm[m0] = mmin
				}
			}
			if (km == k) || (nmin < mmin && kn < k) {
				fmt.Printf("%c", nmin)
				n0++
				kn++
				km = 0
			} else if (kn == k) || (nmin > mmin && km < k) {
				fmt.Printf("%c", mmin)
				m0++
				km++
				kn = 0
			}
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
	"sort"
	"strings"
)

func printslice(a []string) {
	for _, v := range a {
		fmt.Printf("%s\n", v)
	}
}

func fillSlice(a []string, n int) []string {
	var tmp string
	fmt.Scan(&tmp)
	for i := 0; i < len(tmp); i++ {
		a = append(a, string(tmp[i]))
	}

	return a
}

func solution() {
	results := make([]string, 0)
	var t, n, m, k int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		this_solution := make([]string, 0)
		fmt.Scan(&n, &m, &k)
		a := make([]string, 0)
		b := make([]string, 0)
		a = fillSlice(a, n)
		b = fillSlice(b, m)
		sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
		sort.Slice(b, func(i, j int) bool { return b[i] < b[j] })

		var i, j, ka, kb int

		for i < n && j < m {
			if a[i] < b[j] {
				if ka < k {
					this_solution = append(this_solution, a[i])
					ka++
					kb = 0
					i++
				} else {
					this_solution = append(this_solution, b[j])
					ka = 0
					kb++
					j++
				}
			} else {
				if kb < k {
					this_solution = append(this_solution, b[j])
					ka = 0
					kb++
					j++
				} else {
					this_solution = append(this_solution, a[i])
					ka++
					kb = 0
					i++
				}
			}
		}
		results = append(results, strings.Join(this_solution, ""))
	}
	printslice(results)

}
func main() {
	solution()
}

package main

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

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 n, m, k int
		fmt.Fscan(in, &n, &m, &k)

		var s1, s2 string
		fmt.Fscan(in, &s1, &s2)

		m1, m2 := make([]rune, n), make([]rune, m)
		for i, ch := range s1 {
			m1[i] = ch
		}
		for i, ch := range s2 {
			m2[i] = ch
		}

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

		var buf bytes.Buffer
		var c0, c1 int
		var p0, p1 int
		for p0 < n && p1 < m {
			var ch rune
			if m1[p0] < m2[p1] {
				if c0 == k {
					ch = m2[p1]
					p1++
					c0, c1 = 0, 1
				} else {
					ch = m1[p0]
					p0++
					c0, c1 = c0+1, 0
				}
			} else {
				if c1 == k {
					ch = m1[p0]
					p0++
					c0, c1 = 1, 0
				} else {
					ch = m2[p1]
					p1++
					c0, c1 = 0, c1+1
				}
			}

			buf.WriteRune(ch)
		}
		fmt.Fprintln(out, buf.String())
	}
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for c := 0; c < testCases; c++ {
		var n, m, k int
		var a, b string
		Fscan(in, &n, &m, &k)
		Fscan(in, &a)
		Fscan(in, &b)

		Fprintln(out, solve(k, a, b))
	}
}

func solve(k int, a, b string) string {

	s1 := []rune(a)
	s2 := []rune(b)

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

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

	var ans []rune
	c1 := 0
	c2 := 0
	n := len(s1)
	m := len(s2)
	i := 0
	j := 0
	tryAgain := true
	for tryAgain && i < n && j < m {
		tryAgain = false
		if i >= n && c2 < k {
			ans = append(ans, take(s2, j)...)
			j++
			c2++
			c1 = 0
			tryAgain = true
			continue
		}

		if j >= m && c1 < k {
			ans = append(ans, take(s1, i)...)
			i++
			c1++
			c2 = 0
			tryAgain = true
			continue
		}

		if (s1[i] < s2[j] && c1 < k) || (s1[i] > s2[j] && c2 >= k) {
			ans = append(ans, take(s1, i)...)
			i++
			c1++
			c2 = 0
			tryAgain = true
		} else if c2 < k {
			ans = append(ans, take(s2, j)...)
			j++
			c2++
			c1 = 0
			tryAgain = true
		}
	}

	return string(ans)
}

func take(s []rune, idx int) []rune {
	if idx >= len(s) {
		return nil
	}
	return []rune{s[idx]}
}

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

package main

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

/*
1
3 5 2
aaa
bbbbb
---
aababb
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m, k int
	var a, b string
	scanf("%d %d %d\n%s\n%s\n", &n, &m, &k, &a, &b)

	arrA := []rune(a)
	sort.Slice(arrA, func(i, j int) bool {
		return arrA[i] < arrA[j]
	})

	arrB := []rune(b)
	sort.Slice(arrB, func(i, j int) bool {
		return arrB[i] < arrB[j]
	})

	i, j := 0, 0

	res := make([]rune, 0)

	aCnt := 0
	bCnt := 0

	for i < len(arrA) && j < len(arrB) {
		useA := true

		if i < len(arrA) && j < len(arrB) {
			useA = i < len(arrA) && arrA[i] < arrB[j]
		}

		if useA && aCnt == k {
			useA = false
		} else if !useA && bCnt == k {
			useA = true
		}

		if useA {
			res = append(res, arrA[i])
			i++

			aCnt++
			bCnt = 0
		} else {
			res = append(res, arrB[j])
			j++

			aCnt = 0
			bCnt++
		}
	}

	//for i < len(arrA) && aCnt != k {
	//	res = append(res, arrA[i])
	//	i++
	//
	//	aCnt++
	//}
	//
	//for j < len(arrB) && bCnt != k {
	//	res = append(res, arrB[j])
	//	j++
	//
	//	bCnt++
	//}

	fmt.Fprintln(writer, string(res))
}

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

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

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(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 {
	if num == 0 {
		return 0
	}

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}


In Absurdistan, there are n towns (numbered 1 through n) and m bidirectional railways. There is also an absurdly simple road network — for each pair of different towns x and y, there is a bidirectional road between towns x and y if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour.A train and a bus leave town 1 at the same time. They both have the same destination, town n, and don't make any stops on the way (but they can wait in town n). The train can move only along railways and the bus can move only along roads.You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town n) simultaneously.Under these constraints, what is the minimum number of hours needed for both vehicles to reach town n (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town n at the same moment of time, but are allowed to do so.

The first line of the input contains two integers n and m (2 ≤ n ≤ 400, 0 ≤ m ≤ n(n - 1) / 2) — the number of towns and the number of railways respectively. Each of the next m lines contains two integers u and v, denoting a railway between towns u and v (1 ≤ u, v ≤ n, u ≠ v). You may assume that there is at most one railway connecting any two towns.

Output one integer — the smallest possible time of the later vehicle's arrival in town n. If it's impossible for at least one of the vehicles to reach town n, output  - 1.

NoteIn the first sample, the train can take the route  and the bus can take the route . Note that they can arrive at town 4 at the same time.In the second sample, Absurdistan is ruled by railwaymen. There are no roads, so there's no way for the bus to reach town 4.

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)
//defer writer.Flush()

const (
	//MaxScanTokenSize = 64 * 1024 // package default
	MaxScanTokenSize = 8 * 1024 * 1024 // 8M
)

func init() {
	scanner.Buffer(make([]byte, 0, MaxScanTokenSize), MaxScanTokenSize)
	scanner.Split(bufio.ScanWords)
}

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(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; 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
}

func readFloat64() float64 {
	v, _ := strconv.ParseFloat(readString(), 64)
	return v
}

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

type Edge struct {
	From int
	To int
	Cap int
	Flow int
}

type Graph struct {
	NNode int
	NEdge int
	Edges []Edge
	Nodes [][]int
}

func NewGraph(nNode, nEdge int) *Graph {
	g := &Graph{
		NNode: nNode,
		NEdge: nEdge,
		Edges: make([]Edge, 0, nEdge),
		Nodes: make([][]int, nNode, nNode),
	}
	return g
}

func (g *Graph) AddEdge(from, to, cap, flow int) {
	g.Nodes[from] = append(g.Nodes[from], len(g.Edges))
	g.Edges = append(g.Edges, Edge{from, to, cap, flow})
	g.Nodes[to] = append(g.Nodes[to], len(g.Edges))
	g.Edges = append(g.Edges, Edge{to, from, cap, flow})
}

func (g *Graph) Show() {
	fmt.Printf("n node = %d, n edge = %d\n", g.NNode, g.NEdge)
	for i, cur := range g.Nodes {
		fmt.Printf("[%d]", i)
		for _, next := range cur {
			fmt.Printf(" %d", g.Edges[next].To)
		}
		fmt.Println()
	}
}

type QueueStack struct {
	data []interface{}
}

func (q *QueueStack) size() int {
	return len(q.data)
}

func (q *QueueStack) push(v interface{}) {
	q.data = append(q.data, v)
}

func (q *QueueStack) popFront() interface{} {
	v := q.data[0]
	q.data = q.data[1:]
	return v
}

func (q *QueueStack) pop() interface{} {
	last := len(q.data) - 1
	v := q.data[last]
	q.data = q.data[:last]
	return v
}

func spfa(g *Graph, from, to int) int {
	n := g.NNode
	dist := make([]int, n, n)
	dist[0] = 0
	for i := 1; i < n; i++ {
		dist[i] = n
	}

	q := &QueueStack{}
	q.push(from)
	for q.size() > 0 {
		cur := q.pop().(int)
		for _, ie := range g.Nodes[cur] {
			e := g.Edges[ie]
			if dist[cur] + 1 < dist[e.To] {
				dist[e.To] = dist[cur] + 1
				q.push(e.To)
			}
		}
	}

	return dist[to]
}

func main() {
	defer writer.Flush()

	n, m := readInt(), readInt()

	gFull := make([][]int, n, n)
	for i := 0; i < n; i++ {
		gFull[i] = make([]int, n, n)
	}

	g := NewGraph(n, m)
	for i := 0; i < m; i++ {
		x, y := readInt(), readInt()
		x--
		y--
		g.AddEdge(x, y, 0, 0)
		gFull[x][y] = 1
		gFull[y][x] = 1
	}

	d1 := spfa(g, 0, n - 1)

	if d1 == n {
		fmt.Fprintf(writer, "-1\n")
		return
	}

	g = NewGraph(n, n * (1 + n) / 2 - m)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if gFull[i][j] == 0 {
				g.AddEdge(i, j, 0, 0)
			}
		}
	}

	d2 := spfa(g, 0, n - 1)
	if d2 == n {
		fmt.Fprintf(writer, "-1\n")
		return
	}

	ans := d1
	if d1 < d2 {
		ans = d2
	}
	fmt.Fprintf(writer, "%d\n", ans)
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/601/A

package main

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

type Edge struct {
	from int
	to   int
}

type QueueItem struct {
	town int
	d    int
}

func bfs(n int, matrix [][]int, flag int) int {
	queue := []QueueItem{{1, 0}}
	visited := make(map[int]bool)
	visited[1] = true
	for len(queue) > 0 {
		current := queue[0]
		queue = queue[1:]
		if current.town == n {
			return current.d
		}
		for v := 1; v <= n; v++ {
			if !visited[v] && matrix[current.town-1][v-1] == flag {
				visited[v] = true
				queue = append(queue, QueueItem{v, current.d + 1})
			}
		}
	}
	return -1
}

func createMatrix(n int, edges []Edge) [][]int {
	adjMatrix := make([][]int, n)
	for i := 0; i < n; i++ {
		adjMatrix[i] = make([]int, n)
	}
	for _, edge := range edges {
		adjMatrix[edge.to-1][edge.from-1] = 1
		adjMatrix[edge.from-1][edge.to-1] = 1
	}
	return adjMatrix
}

func Solve(n int, edges []Edge) int {
	matrix := createMatrix(n, edges)
	if matrix[0][n-1] == 1 {
		return bfs(n, matrix, 0)
	}
	return bfs(n, matrix, 1)
}

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

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	edges := make([]Edge, m)
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%d %d\n", &edges[i].from, &edges[i].to)
	}

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

package main

import "fmt"

type WayType bool

func (w WayType) String() string {
	if bool(w) == true {
		return "Rail"
	} else {
		return "Road"
	}
}

const (
	RAIL WayType = true
	ROAD WayType = false

	MAX_DIST = 100100100
)

type Town struct {
	VistTag bool
	MinDist int
}

var way [500][500]WayType
var towns [500]Town

func findMinDistWay(n int, wt WayType, tid int) int {
	if towns[tid].MinDist != 0 {
		return towns[tid].MinDist
	}
	//fmt.Printf("WT=%s - way[%d][1]=%s\n", wt, tid, way[tid][1])
	if way[tid][1] == wt {
		towns[tid].MinDist = 1
		return 1
	}

	towns[tid].VistTag = true
	minDist := MAX_DIST
	for i := 2; i <= n; i++ {
		if towns[i].VistTag {
			continue
		}
		//fmt.Printf("WT=%s -- way[%d][%d]=%s\n", wt, tid, i, way[tid][i])
		if way[tid][i] == wt {
			m := findMinDistWay(n, wt, i)
			if m < 0 {
				continue
			}
			m++
			if m < minDist {
				minDist = m
			}
		}
	}
	towns[tid].VistTag = false
	if minDist == MAX_DIST {
		towns[tid].MinDist = -1
	} else {
		towns[tid].MinDist = minDist
	}
	return towns[tid].MinDist
}

func main() {
	var n, m, x, y int
	fmt.Scan(&n, &m)

	for i := 0; i < m; i++ {
		fmt.Scan(&x, &y)
		way[x][y] = RAIL
		way[y][x] = RAIL
	}

	var ans int
	if way[1][n] == RAIL {
		//fmt.Println("WTF RAIL")
		ans = findMinDistWay(n, ROAD, n)
	} else {
		//fmt.Println("WTF ROAD")
		ans = findMinDistWay(n, RAIL, n)
	}
	if ans < 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

package main

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

type WayType bool

func (w WayType) String() string {
	if bool(w) == true {
		return "Rail"
	} else {
		return "Road"
	}
}

const (
	RAIL WayType = true
	ROAD WayType = false

	MAX_DIST = 100100100
)

type Town struct {
	VistTag bool
	MinDist int
}

var way [500][500]WayType
var towns [500]Town

func findMinDistWay(n int, wt WayType, tid int) int {
	if towns[tid].MinDist != 0 {
		return towns[tid].MinDist
	}
	//fmt.Printf("WT=%s - way[%d][1]=%s\n", wt, tid, way[tid][1])
	if way[tid][1] == wt {
		towns[tid].MinDist = 1
		return 1
	}

	towns[tid].VistTag = true
	minDist := MAX_DIST
	for i := 2; i <= n; i++ {
		if towns[i].VistTag {
			continue
		}
		//fmt.Printf("WT=%s -- way[%d][%d]=%s\n", wt, tid, i, way[tid][i])
		if way[tid][i] == wt {
			m := findMinDistWay(n, wt, i)
			if m < 0 {
				continue
			}
			m++
			if m < minDist {
				minDist = m
			}
		}
	}
	towns[tid].VistTag = false
	if minDist == MAX_DIST {
		towns[tid].MinDist = -1
	} else {
		towns[tid].MinDist = minDist
	}
	return towns[tid].MinDist
}

func main() {
	var n, m, x, y int
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n, &m)

	for i := 0; i < m; i++ {
		fmt.Fscan(in, &x, &y)
		way[x][y] = RAIL
		way[y][x] = RAIL
	}

	var ans int
	if way[1][n] == RAIL {
		//fmt.Println("WTF RAIL")
		ans = findMinDistWay(n, ROAD, n)
	} else {
		//fmt.Println("WTF ROAD")
		ans = findMinDistWay(n, RAIL, n)
	}
	if ans < 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}

package main

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

type node struct {
	children [] int
	index    int
}

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	graph := make([]node, n)
	for i, _ := range graph {
		graph[i] = node{index: i}
	}

	scan := bufio.NewScanner(os.Stdin)
	scan.Split(bufio.ScanWords)
	for i := 0; i < k; i++ {
		scan.Scan()
		from, _ := strconv.Atoi(scan.Text())
		from--

		scan.Scan()
		to, _ := strconv.Atoi(scan.Text())
		to--

		graph[from].children = append(graph[from].children, to)
		graph[to].children = append(graph[to].children, from)
	}

	minRailWay := getMinRailWay(graph)
	if minRailWay == 0 {
		fmt.Println(-1)
		return
	}

	minRoadWay := getMinRoadWay(graph)
	if minRoadWay == 0 {
		fmt.Println(-1)
		return
	}

	fmt.Println(getMax(minRailWay, minRoadWay))
}

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

func getMinRoadWay(graph [] node) int {
	distances := make([]int, len(graph))
	BFS_road(graph, distances)
	return distances[len(graph)-1]
}

func BFS_road(graph [] node, distances [] int) {
	visited := make([]bool, len(graph))
	queue := make([]int, 0)
	queue = append(queue, 0)

	for len(queue) > 0 {
		x := queue[0]
		visited[x] = true

		for i := 0; i < len(graph); i++ {
			if !contains(graph[x].children, i) && !visited[i] {
				distances[i] = distances[x] + 1
				visited[i] = true
				queue = append(queue, i)
			}
		}
		queue = queue[1:]
	}
}

func contains(array [] int, elem int) bool {
	for _, v := range array {
		if elem == v {
			return true
		}
	}
	return false
}

func getMinRailWay(graph [] node) int {
	distances := make([]int, len(graph))
	BFS(graph, distances)
	return distances[len(graph)-1]
}

func BFS(graph [] node, distances [] int) {
	visited := make([]bool, len(graph))
	queue := make([]int, 0)
	queue = append(queue, 0)

	for len(queue) > 0 {
		x := queue[0]
		visited[x] = true

		for _, v := range graph[x].children {
			if !visited[v] {
				distances[v] = distances[x] + 1
				visited[v] = true
				queue = append(queue, v)
			}
		}
		queue = queue[1:]
	}
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)
//defer writer.Flush()

const (
	//MaxScanTokenSize = 64 * 1024 // package default
	MaxScanTokenSize = 8 * 1024 * 1024 // 8M
)

func init() {
	scanner.Buffer(make([]byte, 0, MaxScanTokenSize), MaxScanTokenSize)
	scanner.Split(bufio.ScanWords)
}

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(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; 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
}

func readFloat64() float64 {
	v, _ := strconv.ParseFloat(readString(), 64)
	return v
}

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

type Edge struct {
	From int
	To int
	Cap int
	Flow int
}

type Graph struct {
	NNode int
	NEdge int
	Edges []Edge
	Nodes [][]int
}

func NewGraph(nNode, nEdge int) *Graph {
	g := &Graph{
		NNode: nNode,
		NEdge: nEdge,
		Edges: make([]Edge, 0, nEdge),
		Nodes: make([][]int, nNode, nNode),
	}
	return g
}

func (g *Graph) AddEdge(from, to, cap, flow int) {
	g.Nodes[from] = append(g.Nodes[from], len(g.Edges))
	g.Edges = append(g.Edges, Edge{from, to, cap, flow})
	g.Nodes[to] = append(g.Nodes[to], len(g.Edges))
	g.Edges = append(g.Edges, Edge{to, from, cap, flow})
}

func (g *Graph) Show() {
	fmt.Printf("n node = %d, n edge = %d\n", g.NNode, g.NEdge)
	for i, cur := range g.Nodes {
		fmt.Printf("[%d]", i)
		for _, next := range cur {
			fmt.Printf(" %d", g.Edges[next].To)
		}
		fmt.Println()
	}
}

type QueueStack struct {
	data []interface{}
}

func (q *QueueStack) size() int {
	return len(q.data)
}

func (q *QueueStack) push(v interface{}) {
	q.data = append(q.data, v)
}

func (q *QueueStack) popFront() interface{} {
	v := q.data[0]
	q.data = q.data[1:]
	return v
}

func (q *QueueStack) pop() interface{} {
	last := len(q.data) - 1
	v := q.data[last]
	q.data = q.data[:last]
	return v
}

func spfa(g *Graph, from, to int) int {
	n := g.NNode
	dist := make([]int, n, n)
	dist[0] = 0
	for i := 1; i < n; i++ {
		dist[i] = n
	}

	q := &QueueStack{}
	q.push(from)
	for q.size() > 0 {
		cur := q.pop().(int)
		for _, ie := range g.Nodes[cur] {
			e := g.Edges[ie]
			if dist[cur] + 1 < dist[e.To] {
				dist[e.To] = dist[cur] + 1
				q.push(e.To)
			}
		}
	}

	return dist[to]
}

func main() {
	defer writer.Flush()

	n, m := readInt(), readInt()

	gFull := make([][]int, n, n)
	for i := 0; i < n; i++ {
		gFull[i] = make([]int, n, n)
	}

	g := NewGraph(n, m)
	for i := 0; i < m; i++ {
		x, y := readInt(), readInt()
		x--
		y--
		g.AddEdge(x, y, 0, 0)
		gFull[x][y] = 1
		gFull[y][x] = 1
	}
	g.Show()

	d1 := spfa(g, 0, n - 1)

	if d1 == n {
		fmt.Fprintf(writer, "-1\n")
		return
	}

	g = NewGraph(n, n * (1 + n) / 2 - m)
	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if gFull[i][j] == 0 {
				g.AddEdge(i, j, 0, 0)
			}
		}
	}

	d2 := spfa(g, 0, n - 1)
	if d2 == n {
		fmt.Fprintf(writer, "-1\n")
		return
	}

	ans := d1
	if d1 < d2 {
		ans = d2
	}
	fmt.Fprintf(writer, "%d\n", ans)
}