package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			a, b := in.NextInt(), in.NextInt()
			min := 0
			if a < b {
				min = a
				arr[i] = b
			} else {
				min = b
				arr[i] = a
			}
			sum += int64(2) * int64(min)
		}

		sort.Ints(arr)

		if n == 1 {
			sum += 2 * int64(arr[0])
		} else {
			for i := 0; i < n; i++ {
				if i == 0 {
					sum += int64(arr[i])
				} else if i > 0 {
					sum += int64(arr[i]) - int64(arr[i-1])
				}
				if i+1 == n {
					sum += int64(arr[i])
				}
			}
		}

		fmt.Println(sum)
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	var str strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		sum := 0
		maxH := 0
		for i := 0; i < n; i++ {
			a, b := in.NextInt(), in.NextInt()
			if a < b {
				sum += 2 * a
				if maxH < b {
					maxH = b
				}
			} else {
				sum += 2 * b
				if maxH < a {
					maxH = a
				}
			}
		}
		sum += 2 * maxH

		str.WriteString(fmt.Sprintf("%v\n", sum))
	}
	fmt.Print(str.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	//var str strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		sum := 0
		maxH := 0
		for i := 0; i < n; i++ {
			a, b := in.NextInt(), in.NextInt()
			if a < b {
				sum += 2 * a
				if maxH < b {
					maxH = b
				}
			} else {
				sum += 2 * b
				if maxH < a {
					maxH = a
				}
			}
		}
		sum += 2 * maxH
		fmt.Println(sum)
		//str.WriteString(fmt.Sprintf("%v\n", sum))
	}
	//fmt.Print(str.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	var str strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		sum := int64(0)
		maxH := int64(0)
		for i := 0; i < n; i++ {
			a, b := in.NextInt64(), in.NextInt64()
			min := int64(0)
			if a < b {
				min = a

				if maxH < b {
					maxH = b
				}
			} else {
				min = b

				if maxH < a {
					maxH = a
				}
			}
			sum += int64(2) * int64(min)
		}

		sum += 2 * maxH

		str.WriteString(fmt.Sprintf("%v\n", sum))
	}
	fmt.Print(str.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	var str strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			a, b := in.NextInt(), in.NextInt()
			min := 0
			if a < b {
				min = a
				arr[i] = b
			} else {
				min = b
				arr[i] = a
			}
			sum += int64(2) * int64(min)
		}

		sort.Ints(arr)

		if n == 1 {
			sum += 2 * int64(arr[0])
		} else {
			for i := 0; i < n; i++ {
				if i == 0 {
					sum += int64(arr[i])
				} else if i > 0 {
					sum += int64(arr[i]) - int64(arr[i-1])
				}
				if i+1 == n {
					sum += int64(arr[i])
				}
			}
		}
		str.WriteString(fmt.Sprintf("%v\n", sum))
	}
	fmt.Print(str.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([][]int64, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			a, b := in.NextInt64(), in.NextInt64()
			if a < b {
				arr[i] = []int64{a, b}
			} else {
				arr[i] = []int64{b, a}
			}
			sum += 2 * arr[i][0]
		}

		sort.Slice(arr, func(i, j int) bool {
			if arr[i][1] == arr[j][1] {
				if arr[i][0] < arr[j][0] {
					return true
				}
			} else {
				if arr[i][1] < arr[j][1] {
					return true
				}
			}
			return false
		})

		if n == 1 {
			sum += 2 * arr[0][1]
		} else {
			for i := 0; i < n; i++ {
				if i == 0 {
					sum += arr[i][1]
				} else if i > 0 {
					sum += arr[i][1] - arr[i-1][1]
				}
				if i+1 == n {
					sum += arr[i][1]
				}
			}
		}

		fmt.Println(sum)
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([][]int64, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			a, b := in.NextInt64(), in.NextInt64()
			if a < b {
				arr[i] = []int64{a, b}
			} else {
				arr[i] = []int64{b, a}
			}
			sum += 2 * arr[i][0]
		}

		sort.Slice(arr, func(i, j int) bool {
			if arr[i][0] == arr[j][0] {
				if arr[i][1] < arr[j][1] {
					return true
				}
			} else {
				if arr[i][0] < arr[j][0] {
					return true
				}
			}
			return false
		})

		sort.Slice(arr, func(i, j int) bool {
			if arr[i][1] == arr[j][1] {
				if arr[i][0] < arr[j][0] {
					return true
				}
			} else {
				if arr[i][1] < arr[j][1] {
					return true
				}
			}
			return false
		})

		if n == 1 {
			sum += 2 * arr[0][1]
		} else {
			for i := 0; i < n; i++ {
				if i == 0 {
					sum += arr[i][1]
				} else if i > 0 {
					sum += arr[i][1] - arr[i-1][1]
				}
				if i+1 == n {
					sum += arr[i][1]
				}
			}
		}

		fmt.Println(sum)
	}
}

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

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

package main

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

func main() {
	minPerimeter()
}

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

	var tc int
	for fmt.Fscan(r, &tc); tc > 0; tc-- {
		var a, b int
		minPerimeter, maxLen := 0, 0
		count := 0
		for fmt.Fscan(r, &count); count > 0; count-- {
			fmt.Fscan(r, &a, &b)
			l := max(a, b)
			maxLen = max(l, maxLen)
			w := min(a, b)
			minPerimeter += w * 2
		}
		minPerimeter += maxLen * 2
		fmt.Println(minPerimeter)
	}
}

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

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

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func scan(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	var t int

	scan("%d\n", &t)

	for i := 0; i < t; i++ {
		var n int
		scan("%d\n", &n)

		solve(n)
	}
}

func solve(n int) {
	var a, b int
	var res = 0
	var sl = make([]int, n)
	for i := 0; i < n; i++ {
		scan("%d %d\n", &a, &b)
		res += min(a, b) * 2
		sl[i] = a + b - min(a, b)
	}

	sort.Ints(sl)

	res += sl[0] + sl[n-1]

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

	fmt.Println(res)
}

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

	return b
}

package main

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

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

	if err := run(r, w); err != nil {
		log.Fatal(err)
	}
}

func run(r io.Reader, w io.Writer) (err error) {
	var count int
	if _, err = fmt.Fscanln(r, &count); err != nil {
		return err
	}

	var data [][2]int
	var list CheesList

	for i := 0; i < count; i++ {
		if data, err = readData(r); err != nil {
			return err
		}

		list = NewCheesList(data)
		fmt.Fprintln(w, list.MinPerimetr())
	}

	return nil
}

func readData(r io.Reader) (data [][2]int, err error) {
	var count int
	if _, err = fmt.Fscanln(r, &count); err != nil {
		return nil, err
	}

	data = make([][2]int, count)
	for i := range data {
		if _, err := fmt.Fscanln(r, &data[i][0], &data[i][1]); err != nil {
			return nil, err
		}
	}
	return
}

type Chees struct {
	x, y int
}

type CheesList []Chees

func NewCheesList(data [][2]int) (list CheesList) {
	list = make(CheesList, len(data))
	for i, v := range data {
		if v[0] < v[1] {
			list[i].x, list[i].y = v[0], v[1]
		} else {
			list[i].x, list[i].y = v[1], v[0]
		}
	}
	return list
}

func (cl CheesList) Perimetr() int {
	var res int

	for i, c := range cl {
		res += c.x * 2
		if i == 0 {
			res += c.y
		} else {
			res += mod(c.y - cl[i-1].y)
		}
		if i+1 == len(cl) {
			res += c.y
		}
	}
	return res
}

func (cl CheesList) MinPerimetr() int {
	sort.Slice(cl, func(i, j int) bool {
		return cl[i].y < cl[j].y
	})

	left := make(CheesList, 0, len(cl)+1)
	right := make(CheesList, 0, len(cl)+1)

	for i, c := range cl {
		if i%2 == 0 {
			left = append(left, c)
		} else {
			right = append(right, c)
		}
	}

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

	for i, c := range left {
		cl[i] = c
	}
	for i, c := range right {
		cl[i+len(left)] = c
	}
	return cl.Perimetr()
}

func mod(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, max, area, l, b int
		fmt.Fscan(r, &n)

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &l, &b)
			if b > max { max = b }
			if l > max { max = l }
			if l > b { l = b }
			area += 2*l
		}
		area += 2*max

		fmt.Fprintln(w, area)
	}

}

package main

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

func main() {
	var TC int

	r_ := bufio.NewReader(os.Stdin)
	w_ := bufio.NewWriter(os.Stdout)

	defer w_.Flush()
	fmt.Fscan(r_, &TC)

	for t := 1; t <= TC; t++ {

		var n int
		fmt.Fscan(r_, &n)

		arr1 := make([]int, n)
		arr2 := make([]int, n)
		minSum := 0
		for i := 0; i < n; i++ {
			var x, y int
			fmt.Fscan(r_, &x, &y)

			arr1[i] = min(x, y)
			arr2[i] = max(x, y)
			minSum += 2 * arr1[i]
		}

		output := solve(&arr2, minSum, n)

		fmt.Fprintln(w_, output)
	}
}

func solve(arr *[]int, minSum, n int) int {
	sort.Ints(*arr)
	t1 := (*arr)[0]

	for i := 1; i < n; i++ {
		t1 += (*arr)[i] - (*arr)[i-1]
	}
	t1 += (*&*arr)[n-1]

	return minSum + t1
}
func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

package main

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

type point struct {
	x int64
	y int64
}

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

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		var a = make([]point, n)

		for i := 0; i < n; i++ {
			x, y := readTwoInt64(reader)
			if x > y {
				a[i].x = y
				a[i].y = x
			} else {
				a[i].x = x
				a[i].y = y
			}
		}
		sort.Slice(a, func(i, j int) bool {
			if a[i].y < a[j].y {
				return true
			}

			return false
		})

		var ansx, ansy int64 = 0, 0
		for i := 0; i < n; i++ {
			ansx += a[i].x
			if i == 0 || i == n-1 {
				ansy += a[i].y
			}
			if i > 0 {
				ansy += a[i].y - a[i-1].y
			}
		}

		if n == 1 {
			ansy += a[0].y
		}

		fmt.Fprintln(writer, 2*ansx+ansy)

		t--
	}

	writer.Flush()
}

func max(a int, b int) int {
	return int(maxInt64(int64(a), int64(b)))
}

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

	return b
}

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

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

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

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

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

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

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

	return value
}

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

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

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

	var ar []int

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

	return ar
}

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

	var ar []int64

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

	return ar
}

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

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

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

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

package main

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		var x, y int64
		for i := 0; i < n; i++ {
			var tx, ty int64
			fmt.Fscan(in, &tx, &ty)
			tx, ty = com(tx, ty)
			x += tx
			_, y = com(ty, y)
		}
		fmt.Fprintln(out, x*2+y*2)
	}
	out.Flush()
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

const (
	DEBUG = false
)

func debug(a ...interface{}) {
	if !DEBUG {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func debugCondn(condn bool, a ...interface{}) {
	if !DEBUG || !condn {
		return
	}
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func assert(condn bool) {
	if !condn {
		panic("assertion error")
	}
}

func solve(tt int) {
	var n int
	scanf("%d\n", &n)
	a := make([]int64, n)
	b := make([]int64, n)
	sum := int64(0)
	mx := int64(0)
	for i:=0; i<n; i++ {
		scanf("%d %d\n", &a[i], &b[i])
		if a[i] < b[i] {
			a[i], b[i] = b[i], a[i]
		}
		sum += b[i]
		if a[i] > mx {
			mx = a[i]
		}
	}

	res := 2*(sum + mx)
	printf("%d\n", res)
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		solve(tt)
	}
}

package main

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

const cf = true

type tower struct {
	h int
	w int
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	towers := make([]tower, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &towers[i].h, &towers[i].w)
		if towers[i].h < towers[i].w {
			towers[i].h, towers[i].w = towers[i].w, towers[i].h
		}
	}
	sort.Slice(towers, func(i, j int) bool {
		return towers[i].h < towers[j].h
	})
	prev := 0
	ans := 0
	for _, tower := range towers {
		ans += tower.w*2 + tower.h - prev
		prev = tower.h
	}
	ans += towers[len(towers)-1].h
	fmt.Fprintln(out, ans)
}

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

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

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

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

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

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

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

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

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	var str strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([]int, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			a, b := in.NextInt(), in.NextInt()
			min := 0
			if a < b {
				min = a
				arr[i] = b
			} else {
				min = b
				arr[i] = a
			}
			sum += int64(2) * int64(min)
		}

		sort.Ints(arr)

		if n == 1 {
			sum += 2 * int64(arr[0])
		} else {
			for i := 0; i < n; i++ {
				if i == 0 {
					sum += int64(arr[i])
				} else if i > 0 {
					sum += int64(arr[i]) - int64(arr[i-1])
				}

			}
		}
		str.WriteString(fmt.Sprintf("%v\n", sum+int64(arr[n-1])))
	}
	fmt.Print(str.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([][]int64, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			a, b := in.NextInt64(), in.NextInt64()
			//if a < b {
				arr[i] = []int64{a, b}
			//} else {
			//	arr[i] = []int64{b, a}
			//}
			sum += 2 * arr[i][0]
		}

		sort.Slice(arr, func(i, j int) bool {
			if arr[i][1] == arr[j][1] {
				if arr[i][0] < arr[j][0] {
					return true
				}
			} else {
				if arr[i][1] < arr[j][1] {
					return true
				}
			}
			return false
		})

		if n == 1 {
			sum += 2 * arr[0][1]
		} else {
			for i := 0; i < n; i++ {
				if i == 0 {
					sum += arr[i][1]
				} else if i > 0 {
					sum += arr[i][1] - arr[i-1][1]
				}
				if i+1 == n {
					sum += arr[i][1]
				}
			}
		}

		fmt.Println(sum)
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([][]int64, n)
		sum := int64(0)
		for i := 0; i < n; i++ {
			a, b := in.NextInt64(), in.NextInt64()
			if a < b {
				arr[i] = []int64{a, b}
			} else {
				arr[i] = []int64{b, a}
			}
			sum += 2 * arr[i][0]
		}

		sort.Slice(arr, func(i, j int) bool {
			if arr[i][0] == arr[j][0] {
				if arr[i][1] < arr[j][1] {
					return true
				}
			} else {
				if arr[i][0] < arr[j][0] {
					return true
				}
			}
			return false
		})

		if n == 1 {
			sum += 2 * arr[0][1]
		} else {
			for i := 0; i < n; i++ {
				if i == 0 {
					sum += arr[i][1]
				} else if i > 0 {
					sum += arr[i][1] - arr[i-1][1]
				}
				if i+1 == n {
					sum += arr[i][1]
				}
			}
		}

		fmt.Println(sum)
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1740B
Date: 11/17/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1740/B
Problem: CF1740B
**/
func (in *CF1740B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		arr := make([][]int, n)
		sum := 0
		for i := 0; i < n; i++ {
			a, b := in.NextInt(), in.NextInt()
			if a < b {
				arr[i] = []int{a, b}
			} else {
				arr[i] = []int{b, a}
			}
			sum += 2 * arr[i][0]
		}

		sort.Slice(arr, func(i, j int) bool {
			if arr[i][0] == arr[j][0] {
				if arr[i][1] < arr[j][1] {
					return true
				}
			} else {
				if arr[i][0] < arr[j][0] {
					return true
				}
			}
			return false
		})

		if n == 1 {
			sum += 2 * arr[0][1]
		} else {
			for i := 0; i < n; i++ {
				if i == 0 {
					sum += arr[i][1]
				} else if i > 0 {
					sum += arr[i][1] - arr[i-1][1]
				}
				if i+1 == n {
					sum += arr[i][1]
				}
			}
		}

		fmt.Println(sum)
	}
}

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

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

package main

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

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

	if err := run(r, w); err != nil {
		log.Fatal(err)
	}
}

func run(r io.Reader, w io.Writer) (err error) {
	var count int
	if _, err = fmt.Fscanln(r, &count); err != nil {
		return err
	}

	var data [][2]int
	var list CheesList

	for i := 0; i < count; i++ {
		if data, err = readData(r); err != nil {
			return err
		}

		list = NewCheesList(data)
		fmt.Fprintln(w, list.MinPerimetr())
	}

	return nil
}

func readData(r io.Reader) (data [][2]int, err error) {
	var count int
	if _, err = fmt.Fscanln(r, &count); err != nil {
		return nil, err
	}

	data = make([][2]int, count)
	for i := range data {
		if _, err := fmt.Fscanln(r, &data[i][0], &data[i][1]); err != nil {
			return nil, err
		}
	}
	return
}

type Chees struct {
	x, y int
}

type CheesList []Chees

func NewCheesList(data [][2]int) (list CheesList) {
	list = make(CheesList, len(data))
	for i, v := range data {
		if v[0] < v[1] {
			list[i].x, list[i].y = v[0], v[1]
		} else {
			list[i].x, list[i].y = v[1], v[0]
		}
	}
	return list
}

func (cl CheesList) Perimetr() int {
	var res int

	for i, c := range cl {
		res += c.x * 2
		if i == 0 {
			res += c.y
		} else {
			res += mod(c.y - cl[i-1].y)
		}
		if i+1 == len(cl) {
			res += c.y
		}
	}
	return res
}

func (cl CheesList) MinPerimetr() int {
	sort.Slice(cl, func(i, j int) bool {
		return cl[i].y < cl[j].y
	})

	mid := len(cl) / 2
	sort.Slice(cl[mid:], func(i, j int) bool {
		return cl[i].y > cl[j].y
	})

	return cl.Perimetr()
}

func mod(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {
		var n, max, area, l, b int
		fmt.Fscan(r, &n)

		for i := 0; i < n; i++ {
			fmt.Fscan(r, &l, &b)
			if b > max { max = b }
			if l > max {
				max = l
				l = b
			}
			area += 2*l
		}
		area += 2*max

		fmt.Fprintln(w, area)
	}

}


package main

import "fmt"

func main() {
	var str string
	var n int
	fmt.Scan(&n)
	for n != 0 {
		fmt.Scan(&str)
		num := len(str)
		ans := 0
		flag := byte('a')
		for i := 0; i < num; i++ {
			if flag == byte('a') {
				if str[i] == '0' {
					ans++
					flag = '0'
				} else {
					flag = '1'
				}
			} else {
				if str[i] == flag {
					continue
				} else {
					if str[i] == '0' {
						ans++
						flag = '0'
					} else {
						flag = '1'
					}
				}
			}

		}
		if ans > 2 {
			ans = 2
		}
		fmt.Println(ans)

		n--
	}

}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1566B
Date: 29/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1566/B
Problem: CF1566B
**/
func (in *CF1566B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		ones := 0
		zeros := 0
		blocksZeros := 0
		tmp := 0
		for i := 0; i < len(str); i++ {
			if str[i] == '0' {
				zeros++
				tmp++
			} else {
				if tmp > 0 {
					blocksZeros++
					tmp = 0
				}
				ones++
			}
		}
		if tmp > 0 {
			blocksZeros++
			tmp = 0
		}

		if zeros == 0 {
			fmt.Println(0)
		} else if ones == 0 {
			fmt.Println(1)
		} else {

			if blocksZeros > 2 {
				fmt.Println(2)
			} else {
				fmt.Println(blocksZeros)
			}

		}

	}
}

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

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

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}

func solve() {
	var s string
	scan(&s)
	zero := 0
	lastZero := -1
	for i, c := range s {
		if c == '0' {
			if lastZero == -1 || i-lastZero > 1 {
				zero++
			}
			lastZero = i
		}
	}
	ans := 2
	if zero == 0 {
		ans = 0
	} else {
		if ans > zero {
			ans = zero
		}
	}
	printf("%d\n", ans)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import (
	"fmt"
	"os"
)

func findZeros(b []byte) int {
	prev := byte('#')
	n := 0
	for _, c := range b {
		if c != prev && c == '0' {
			n++
		}
		prev = c
	}
	return n
}

func testit() {
	var s string
	fmt.Fscanln(os.Stdin, &s)
	b := []byte(s)
	n := findZeros(b)
	if n > 1 {
		fmt.Println(2)
	} else if n == 1 {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}

func main() {
	var nTests uint32
	fmt.Fscanln(os.Stdin, &nTests)
	for nTests > 0 {
		testit()
		nTests--
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

		}
		return m
	}
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

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

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

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

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {

		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)

		var Zero, One int

		q := len(STRING)
		for i := 0; i < q-1; i++ {
			if string(STRING[i]) == "0" && string(STRING[i+1]) == "1" {
				Zero++
			}
			if string(STRING[i]) == "1" {
				One++
			}
		}
		if string(STRING[q-1]) == "0" {

			Zero++

		}

		if Zero > 2 {
			fmt.Println(2)
		} else {
			fmt.Println(Zero)
		}

	}
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int

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

	for t := 0; t < T; t++ {
		var s string
		fmt.Fscanf(r, "%s\n", &s)

		c := [2]int{}
		for i := 0; i < len(s); i++ {
			c[s[i]-'0']++
		}

		if c[0] == 0 {
			fmt.Println("0")
		} else {
			lz := -1
			can := true
			for i := 0; i < len(s); i++ {
				if s[i] == '0' {
					if i-lz > 1 && lz != -1 {
						can = false
						break
					}
					lz = i
				}
			}

			if can {
				fmt.Println("1")
			} else {
				fmt.Println("2")
			}
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1566B
Date: 29/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1566/B
Problem: CF1566B
**/
func (in *CF1566B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		ones := 0
		zeros := 0
		for i := 0; i < len(str); i++ {
			if str[i] == '0' {
				zeros++
			} else {
				ones++
			}
		}
		if zeros == 0 {
			fmt.Println(0)
		} else if ones == 0 {
			fmt.Println(1)
		} else {

			if zeros > 2 {
				fmt.Println(2)
			} else {
				fmt.Println(zeros)
			}

		}

	}
}

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

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF687B(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n, k := read(), read()
	if k == 1 {
		Fprint(out, "Yes")
		return
	}

	factors := []int{}
	exponents := []int{}
	kk := k
	for i := 2; i*i <= kk; i++ {
		cnt := 0
		for ; kk%i == 0; kk /= i {
			cnt++
		}
		if cnt > 0 {
			factors = append(factors, i)
			exponents = append(exponents, cnt)
		}
	}
	if kk > 1 {
		factors = append(factors, kk)
		exponents = append(exponents, 1)
	}

	match := make([]bool, len(factors))
	for i := 0; i < n; i++ {
		c := read()
		for j, f := range factors {
			cnt := 0
			for ; c%f == 0; c /= f {
				cnt++
			}
			if cnt >= exponents[j] {
				match[j] = true
			}
		}
	}
	for _, ok := range match {
		if !ok {
			Fprint(out, "No")
			return
		}
	}
	Fprint(out, "Yes")
}

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

package main

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

func gcd(a int64, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s := strings.Split(text, " ")
	x, _ := strconv.ParseInt(s[0], 10, 64)
	totalv, _ := strconv.ParseInt(s[1], 10, 64)

	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s = strings.Split(text, " ")
	var a int64
	a = 1
	if x != int64(len(s)) {
		fmt.Println("Read Error")
	}
	for _, ss := range s {

		v, _ := strconv.ParseInt(ss, 10, 64)

		a = (v * a) / gcd(v, a)
		a = gcd(a, totalv)
		if a%totalv == 0 {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}

package main

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

var in *bufio.Scanner

func main() {
    var n int
    var k int64
    in = bufio.NewScanner(os.Stdin)
    const MaxTokenLength = 1024 * 1024
    in.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
    in.Split(bufio.ScanWords)
    n = readInt()
    k = (int64)(readInt())
    var ans int64 = 1
    for i := 0;i < n;i++ {
        var t int64 = (int64)(readInt())
        t = gcd(t,k)
        ans = ans * t / gcd(ans,t)
    }
    if ans % k == 0 {
      fmt.Println("Yes")
    } else {
      fmt.Println("No")
    }
}
func gcd(a,b int64) int64 {
    if b == 0 {
        return a
    } else {
        return gcd(b,a % b)
    }
}

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

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

package main

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

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

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

	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &c[i])
	}

	can := true
	for _, f := range factors(k) {
		ok := false
		for _, e := range c {
			if e%f == 0 {
				ok = true
				break
			}
		}
		if !ok {
			can = false
			break
		}
	}

	if can {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func factors(a int) []int {
	var f []int
	for p := 2; p*p <= a; p++ {
		if a%p != 0 {
			continue
		}
		factor := 1
		for a%p == 0 {
			factor *= p
			a /= p
		}
		f = append(f, factor)
	}
	if a > 1 {
		f = append(f, a)
	}
	return f
}

package main

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

func gcd(a int64, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	totalv, _ := strconv.ParseInt(s[1], 10, 64)
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	var a int64
	a = 1
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		a = (v * a) / gcd(v, a)
		a /= gcd(a, totalv)
	}
	if a%totalv == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

package main

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

func gcd(a int64, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	totalv, _ := strconv.ParseInt(s[1], 10, 64)
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	var a int64
	a = 1
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		a = (v * a) / gcd(v, a)
		a = gcd(a, totalv)
		if a%totalv == 0 {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}

package main

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

func gcd(a int64, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	totalv, _ := strconv.ParseInt(s[1], 10, 64)
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	var a int64
	a = 1
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		a = (v * a)
		a /= gcd(a, totalv)
	}
	if a%totalv == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

package main

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

func gcd(a int64, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	x, _ := strconv.ParseInt(s[0], 10, 64)
	totalv, _ := strconv.ParseInt(s[1], 10, 64)
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	var a int64
	a = 1
	if x != int64(len(s)) {
		fmt.Println("Read Error")
	}
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		a = (v * a) / gcd(v, a)
		a = gcd(a, totalv)
		if a%totalv == 0 {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}

package main

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

func main() {
	var primes []byte
	var i int64
	var mp int64
	mp = 1000000
	for i = 0; i < mp; i++ {
		primes = append(primes, 0)
	}
	primes[0] = 1
	primes[1] = 1
	for i = 2; i < mp; i++ {
		if primes[i] == 0 {
			var j int64
			for j = i * 2; j < mp; j += i {
				primes[j] = 1
			}
		}
	}
	p := []int{}
	for i, v := range primes {
		if v == 0 {
			p = append(p, i)
		}
	}

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	v, _ := strconv.ParseInt(s[1], 10, 64)
	expected := make(map[int]int)
	for v != 1 {
		i := 0
		for i < len(p) {
			if int(v)%p[i] == 0 {
				expected[p[i]] += 1
				v /= int64(p[i])
			} else {
				i++
			}
		}
	}
	exp := []int64{}
	for v, ex := range expected {
		exp = append(exp, int64(v)*int64(ex))
	}
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	used := map[int64]bool{}
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		if used[v] {
			continue
		}
		e := []int64{}

		used[v] = true
		for _, x := range exp {

			if v%int64(x) != 0 {
				e = append(e, x)
			} else {
				v /= int64(x)
			}
		}
		exp = e
		if len(exp) == 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

package main

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

func main() {
	var primes []byte
	var i int64
	var mp int64
	mp = 1000000
	for i = 0; i < mp; i++ {
		primes = append(primes, 0)
	}
	primes[0] = 1
	primes[1] = 1
	for i = 2; i < mp; i++ {
		if primes[i] == 0 {
			var j int64
			for j = i * 2; j < mp; j += i {
				primes[j] = 1
			}
		}
	}
	p := []int{}
	for i, v := range primes {
		if v == 0 {
			p = append(p, i)
		}
	}

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	v, _ := strconv.ParseInt(s[1], 10, 64)
	expected := []int{}
	for v != 1 {
		i := 0
		for i < len(p) {
			if int(v)%p[i] == 0 {
				expected = append(expected, p[i])
				v /= int64(p[i])
			} else {
				i++
			}
		}
	}
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		e := []int{}
		for _, x := range expected {

			if v%int64(x) != 0 {
				e = append(e, x)
			} else {
				v /= int64(x)
			}
		}
		expected = e
		if len(expected) == 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

package main

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

func main() {
	var primes []byte
	var i int64
	var mp int64
	mp = 1000000
	for i = 0; i < mp; i++ {
		primes = append(primes, 0)
	}
	primes[0] = 1
	primes[1] = 1
	for i = 2; i < mp; i++ {
		if primes[i] == 0 {
			var j int64
			for j = i * 2; j < mp; j += i {
				primes[j] = 1
			}
		}
	}
	p := []int{}
	for i, v := range primes {
		if v == 0 {
			p = append(p, i)
		}
	}

	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s := strings.Split(text, " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	v, _ := strconv.ParseInt(s[1], 10, 64)
	expected := make(map[int]int)
	for v != 1 {
		i := 0
		for i < len(p) {
			if int(v)%p[i] == 0 {
				expected[p[i]] += 1
				v /= int64(p[i])
			} else {
				i++
			}
		}
	}
	exp := []int64{}
	for v, ex := range expected {
		exp = append(exp, int64(v)*int64(ex))
	}
	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s = strings.Split(text, " ")
	used := map[int64]bool{}
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		if used[v] {
			continue
		}
		e := []int64{}

		used[v] = true
		for _, x := range exp {

			if v%int64(x) != 0 {
				e = append(e, x)
			} else {
				v /= int64(x)
			}
		}
		exp = e
		if len(exp) == 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

package main

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

func gcd(a int64, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	totalv, _ := strconv.ParseInt(s[1], 10, 64)
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	var a int64
	a = 1
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		a = (v * a) / gcd(v, a)
		if a%totalv == 0 {
			fmt.Println("Yes")
			return
		}
		a /= gcd(a, totalv)
	}

	fmt.Println("No")
}

package main

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

func gcd(a int64, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	totalv, _ := strconv.ParseInt(s[1], 10, 64)
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	var a int64
	a = 1
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		a = (v * a) / gcd(v, a)
	}
	if a%totalv == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

package main

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

func main() {
	var primes []byte
	var i int64
	var mp int64
	mp = 1000000
	for i = 0; i < mp; i++ {
		primes = append(primes, 0)
	}
	primes[0] = 1
	primes[1] = 1
	for i = 2; i < mp; i++ {
		if primes[i] == 0 {
			var j int64
			for j = i * 2; j < mp; j += i {
				primes[j] = 1
			}
		}
	}
	p := []int{}
	for i, v := range primes {
		if v == 0 {
			p = append(p, i)
		}
	}

	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s := strings.Split(text, " ")
	x, _ := strconv.ParseInt(s[0], 10, 64)
	v, _ := strconv.ParseInt(s[1], 10, 64)
	expected := make(map[int]int)
	for v != 1 {
		i := 0
		for i < len(p) {
			if int(v)%p[i] == 0 {
				expected[p[i]] += 1
				v /= int64(p[i])
			} else {
				i++
			}
		}
	}
	exp := []int64{}
	for v, ex := range expected {
		exp = append(exp, int64(v)*int64(ex))
	}
	text, _ = reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s = strings.Split(text, " ")
	used := map[int64]bool{}
	if x != int64(len(s)) {
		fmt.Println("Read Error")
	}
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		if used[v] {
			continue
		}
		e := []int64{}

		used[v] = true
		for _, x := range exp {

			if v%int64(x) != 0 {
				e = append(e, x)
			} else {
				v /= int64(x)
			}
		}
		exp = e
		if len(exp) == 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

package main

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

func main() {
	var primes []byte
	var i int64
	var mp int64
	mp = 1000000
	for i = 0; i < mp; i++ {
		primes = append(primes, 0)
	}
	primes[0] = 1
	primes[1] = 1
	for i = 2; i < mp; i++ {
		if primes[i] == 0 {
			var j int64
			for j = i * 2; j < mp; j += i {
				primes[j] = 1
			}
		}
	}
	p := []int{}
	for i, v := range primes {
		if v == 0 {
			p = append(p, i)
		}
	}

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	v, _ := strconv.ParseInt(s[1], 10, 64)
	expected := []int{}
	for v != 1 {
		i := 0
		for i < len(p) {
			if int(v)%p[i] == 0 {
				expected = append(expected, p[i])
				v /= int64(p[i])
			} else {
				i++
			}
		}
	}
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		e := []int{}
		for _, x := range expected {

			if v%int64(x) != 0 {
				e = append(e, x)
			} else {
				for (v % int64(x)) == 0 {
					v /= int64(x)
				}
			}
		}
		expected = e
		if len(expected) == 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}

package main

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

func gcd(a int64, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := strings.Split(scanner.Text(), " ")
	//x, _ = strconv.ParseInt(s[1], 10, 64)
	totalv, _ := strconv.ParseInt(s[1], 10, 64)
	scanner.Scan()
	s = strings.Split(scanner.Text(), " ")
	var a int64
	a = 1
	for _, ss := range s {
		v, _ := strconv.ParseInt(ss, 10, 64)
		a = (v * a) / gcd(v, a)
		if a%totalv == 0 {
			fmt.Println("Yes")
			return
		}
	}

	fmt.Println("No")
}

package main

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

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

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

	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &c[i])
	}

	f := New()
	l := f.lcm(c)

	divides := true
	for p, v := range f.factorise(k) {
		if v > l[p] {
			divides = false
			break
		}
	}

	if divides {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

type Factoriser struct {
	fact []int
}

func New() *Factoriser {
	limit := int(1e6) + 1
	p := make([]bool, limit)

	f := make([]int, limit)
	for i := 2; i < limit; i++ {
		if p[i] {
			continue
		}
		f[i] = i
		if i > limit/i {
			continue
		}
		for j := i * i; j < limit; j += i + i {
			p[j] = true
			f[j] = i
		}
	}

	return &Factoriser{fact: f}
}

func (f *Factoriser) factorise(num int) map[int]int {
	l := make(map[int]int)
	for num > 1 {
		d := f.fact[num]
		l[d]++
		num /= d
	}
	return l
}

func (f *Factoriser) lcm(a []int) map[int]int {
	l := make(map[int]int)
	for _, e := range a {
		for k, v := range f.factorise(e) {
			if _, ok := l[k]; ok {
				l[k] = max(l[k], v)
			} else {
				l[k] = v
			}
		}
	}
	return l
}

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

package main

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

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

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

	c := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(r, "%d", &c[i])
	}

	f := New()
	l := lcm(c)

	divides := true
	for p, v := range f.factorise(k) {
		if v > l[p] {
			divides = false
			break
		}
	}

	if divides {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

type Factoriser struct {
	fact map[int]int
}

func New() *Factoriser {
	limit := int(1e6) + 1
	p := make([]bool, limit)

	for i := 2; i < limit; i++ {
		p[i] = true
	}

	f := make(map[int]int)
	for i := 2; i < limit; i++ {
		if !p[i] {
			continue
		}
		f[i] = i
		for j := i + i; j < limit; j += i {
			p[j] = false
			f[j] = i
		}
	}

	return &Factoriser{fact: f}
}

func (f *Factoriser) factorise(num int) map[int]int {
	l := make(map[int]int)
	for num > 1 {
		d := f.fact[num]
		l[d]++
		num /= d
	}
	return l
}

func lcm(a []int) map[int]int {
	f := New()
	l := make(map[int]int)
	for _, e := range a {
		for k, v := range f.factorise(e) {
			l[k] += v
		}
	}
	return l
}


// 303A-Andre,Dikai,Eric
package main

import (
	"fmt"
)

func main() {
	var n,i,j int
	fmt.Scan(&n)
	if n%2 == 0{
		fmt.Println("-1")
		return

	}
	for i=0;i<2;i++{
		for j=0;j<n;j++ {
			fmt.Print(j," ")
		}
		fmt.Println()
	}
	for j=0;j<n;j++{
		fmt.Print((2*j)%n," ")

	}
}

// 303A-mic
package main

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

func main() {
	z := bufio.NewWriter(os.Stdout)
	var n, i int
	fmt.Scan(&n)
	if n&1 == 1 {
		for i = 0; i < n; i++ {
			z.WriteString(strconv.Itoa(i) + " ")
		}
		z.WriteString("\n")
		for i = 0; i < n; i++ {
			z.WriteString(strconv.Itoa(i) + " ")
		}
		z.WriteString("\n")
		for i = 0; i < n; i++ {
			z.WriteString(strconv.Itoa((2*i)%n) + " ")
		}
		z.WriteString("\n")
	} else {
		z.WriteString("-1")
		z.WriteString("\n")
	}
	z.Flush()
}

// 303A
package main

import (
	"fmt"
)

func main() {
	var n, i int
	fmt.Scan(&n)
	if n%2 != 0 {
		for i = 0; i < n; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		for i = 0; i < n; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		for i = 0; i < n; i++ {
			fmt.Printf("%d ", (i+i)%n)
		}
		fmt.Println()
	} else {
		fmt.Println(-1)
	}
}

package main

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

var w *bufio.Writer

var sc *bufio.Scanner

const minus, zero byte = '-', '0'

func nextInt() int {
	var ans, fst int = 0, 0
	var neg bool = false
	sc.Scan()
	if sc.Bytes()[0] == minus {
		fst = 1
		neg = true
	}
	for _, j := range sc.Bytes()[fst:] {
		ans = ans*10 + int(j-zero)
	}
	if neg == true {
		ans = -ans
	}
	return ans
}

func printInt(n int) {
	w.WriteString(strconv.Itoa(n) + " ")
}

func main() {

	w = bufio.NewWriter(os.Stdout)
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	if n%2 == 0 {
		w.WriteString("-1")
		w.Flush()
		return
	}
	for i := 0; i < n; i++ {
		printInt(i)
	}
	w.WriteString("\n")
	for i := 0; i < n; i++ {
		printInt(i)
	}
	w.WriteString("\n")
	for i := 0; i < n; i++ {
		printInt((i * 2) % n)
	}
	w.WriteString("\n")
	w.Flush()
	//YOU FORGOT TO FLUSH!
}

//303A
package main
import (
	//"fmt"
	"os"
	"bufio"
	"strconv"
)

func main() {
	var nn int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	nn, _ = strconv.Atoi(r.Text())

	if nn%2==0 {
		w.WriteString("-1\n")
	} else {
		for i:=0; i<nn ; i+=1 {
			if i>0 {
				w.WriteString(" ")
			}
			w.WriteString(strconv.Itoa(i))
		}
		w.WriteString("\n")

		for i:=0; i<nn ; i+=1 {
			if i>0 {
				w.WriteString(" ")
			}
			w.WriteString(strconv.Itoa(i))
		}
		w.WriteString("\n")

		for i:=0; i<nn ; i+=1 {
			if i>0 {
				w.WriteString(" ")
				//fmt.Print(" ")
			}
			w.WriteString(strconv.Itoa((i+i)%nn))
		}
		w.WriteString("\n")
	}
	w.Flush()
}

package main

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

var w *bufio.Writer

var sc *bufio.Scanner

const minus, zero byte = '-', '0'

func nextInt() int {
	var ans, fst int = 0, 0
	var neg bool = false
	sc.Scan()
	if sc.Bytes()[0] == minus {
		fst = 1
		neg = true
	}
	for _, j := range sc.Bytes()[fst:] {
		ans = ans*10 + int(j-zero)
	}
	if neg == true {
		ans = -ans
	}
	return ans
}

func printInt(n int) {
	w.WriteString(strconv.Itoa(n) + " ")
}

func main() {

	w = bufio.NewWriter(os.Stdout)
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	if n == 2 {
		w.WriteString("-1")
		return
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			w.WriteString("-1")
			return
		}
	}
	for i := 0; i < n; i++ {
		printInt(i)
	}
	w.WriteString("\n")
	for i := 0; i < n; i++ {
		printInt(i)
	}
	w.WriteString("\n")
	for i := 0; i < n; i++ {
		printInt((i * 2) % n)
	}
	w.WriteString("\n")
	w.Flush()
	//YOU FORGOT TO FLUSH!
}

package main

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

var w *bufio.Writer

var sc *bufio.Scanner

const minus, zero byte = '-', '0'

func nextInt() int {
	var ans, fst int = 0, 0
	var neg bool = false
	sc.Scan()
	if sc.Bytes()[0] == minus {
		fst = 1
		neg = true
	}
	for _, j := range sc.Bytes()[fst:] {
		ans = ans*10 + int(j-zero)
	}
	if neg == true {
		ans = -ans
	}
	return ans
}

func printInt(n int) {
	w.WriteString(strconv.Itoa(n) + " ")
}

func main() {

	w = bufio.NewWriter(os.Stdout)
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			w.WriteString("-1")
			return
		}
	}
	for i := 0; i < n; i++ {
		printInt(i)
	}
	w.WriteString("\n")
	for i := 0; i < n; i++ {
		printInt(i)
	}
	w.WriteString("\n")
	for i := 0; i < n; i++ {
		printInt((i * 2) % n)
	}
	w.WriteString("\n")
	w.Flush()
	//YOU FORGOT TO FLUSH!
}

package main

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

var w *bufio.Writer

var sc *bufio.Scanner

const minus, zero byte = '-', '0'

func nextInt() int {
	var ans, fst int = 0, 0
	var neg bool = false
	sc.Scan()
	if sc.Bytes()[0] == minus {
		fst = 1
		neg = true
	}
	for _, j := range sc.Bytes()[fst:] {
		ans = ans*10 + int(j-zero)
	}
	if neg == true {
		ans = -ans
	}
	return ans
}

func printInt(n int) {
	w.WriteString(strconv.Itoa(n) + " ")
}

func main() {

	w = bufio.NewWriter(os.Stdout)
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	if n == 2 {
		w.WriteString("-1")
		w.Flush()
		return
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			w.WriteString("-1")
			w.Flush()
			return
		}
	}
	for i := 0; i < n; i++ {
		printInt(i)
	}
	w.WriteString("\n")
	for i := 0; i < n; i++ {
		printInt(i)
	}
	w.WriteString("\n")
	for i := 0; i < n; i++ {
		printInt((i * 2) % n)
	}
	w.WriteString("\n")
	w.Flush()
	//YOU FORGOT TO FLUSH!
}

// 303A-Andre,Dikai,Eric
package main

import (
    "fmt"
)

func main() {
    var n,i,j int
    fmt.Scan(&n)
    if n%2 == 0{
        fmt.Println("-1")
        return
    }
    for i=0;i<2;i++{
        for j=0;j<n;j++ {
            fmt.Println(j," ")
        }
    }
    for j=0;j<n;j++{
        fmt.Println((2*j)%n," ")
        return
    }
}

// 303A-Andre,Dikai,Eric
package main

import (
	"fmt"
)

func main() {
	var n,i,j int
	fmt.Scan(&n)
	if n%2 == 0{
		fmt.Println("-1")

	}
	for i=0;i<2;i++{
		for j=0;j<n;j++ {
			fmt.Print(j," ")
		}
		fmt.Println()
	}
	for j=0;j<n;j++{
		fmt.Print((2*j)%n," ")

	}
}

// 303A
package main

import (
	"fmt"
)

func main() {
	var n, i int
	fmt.Scan(&n)
	if n%2 != 0 {
		for i = 0; i < n; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		for i = 0; i < n; i++ {
			fmt.Printf("%d ", i)
		}
		fmt.Println()
		for i = 0; i < n; i++ {
			fmt.Printf("%d ", (i+i)%n)
		}
		fmt.Println()
	} else {
		fmt.Println()
	}
}