A binary string is a string that consists of characters $$$0$$$ and $$$1$$$. A bi-table is a table that has exactly two rows of equal length, each being a binary string.Let $$$\operatorname{MEX}$$$ of a bi-table be the smallest digit among $$$0$$$, $$$1$$$, or $$$2$$$ that does not occur in the bi-table. For example, $$$\operatorname{MEX}$$$ for $$$\begin{bmatrix} 0011\\ 1010 \end{bmatrix}$$$ is $$$2$$$, because $$$0$$$ and $$$1$$$ occur in the bi-table at least once. $$$\operatorname{MEX}$$$ for $$$\begin{bmatrix} 111\\ 111 \end{bmatrix}$$$ is $$$0$$$, because $$$0$$$ and $$$2$$$ do not occur in the bi-table, and $$$0 < 2$$$.You are given a bi-table with $$$n$$$ columns. You should cut it into any number of bi-tables (each consisting of consecutive columns) so that each column is in exactly one bi-table. It is possible to cut the bi-table into a single bi-table — the whole bi-table.What is the maximal sum of $$$\operatorname{MEX}$$$ of all resulting bi-tables can be?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Description of the test cases follows. The first line of the description of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of columns in the bi-table. Each of the next two lines contains a binary string of length $$$n$$$ — the rows of the bi-table. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print a single integer — the maximal sum of $$$\operatorname{MEX}$$$ of all bi-tables that it is possible to get by cutting the given bi-table optimally.

NoteIn the first test case you can cut the bi-table as follows:  $$$\begin{bmatrix} 0\\ 1 \end{bmatrix}$$$, its $$$\operatorname{MEX}$$$ is $$$2$$$. $$$\begin{bmatrix} 10\\ 10 \end{bmatrix}$$$, its $$$\operatorname{MEX}$$$ is $$$2$$$. $$$\begin{bmatrix} 1\\ 1 \end{bmatrix}$$$, its $$$\operatorname{MEX}$$$ is $$$0$$$. $$$\begin{bmatrix} 0\\ 1 \end{bmatrix}$$$, its $$$\operatorname{MEX}$$$ is $$$2$$$. $$$\begin{bmatrix} 0\\ 0 \end{bmatrix}$$$, its $$$\operatorname{MEX}$$$ is $$$1$$$. $$$\begin{bmatrix} 0\\ 0 \end{bmatrix}$$$, its $$$\operatorname{MEX}$$$ is $$$1$$$.The sum of $$$\operatorname{MEX}$$$ is $$$8$$$.

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(reader, &n, &s1, &s2)

		ans := 0
		found_zero := 0
		found_one := 0
		for i := 0; i < n; i++ {
			if s1[i] == '0' && s2[i] == '1' || s1[i] == '1' && s2[i] == '0' {
				ans += found_zero + 2
				found_one = 0
				found_zero = 0
			} else if found_zero > 0 && s1[i] == '1' && s2[i] == '1' {
				ans += found_zero + 1
				found_zero = 0
				found_one = 0
			} else if found_one > 0 && s1[i] == '0' && s2[i] == '0' {
				ans += 2
				found_zero = 0
				found_one = 0
			} else if s1[i] == '0' && s2[i] == '0' {
				found_zero++
			} else if s1[i] == '1' && s2[i] == '1' {
				found_one++
			}
		}
		ans += found_zero
		write(f, ans, "\n")
	}
}

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++ {
		var n int
		fmt.Fscan(input, &n)

		First := make([]byte, 0)
		Second := make([]byte, 0)

		fmt.Fscan(input, &First)

		fmt.Fscan(input, &Second)
		var Ans int

		ARRAY := make([]int, n)

		for i := 0; i < n-1; {
			if First[i]+Second[i] == 97 {
				Ans = Ans + 2
				ARRAY[i] = 1
				i = i + 1
			} else {
				if First[i]+Second[i] == 96 {
					if First[i+1]+Second[i+1] == 98 {
						Ans = Ans + 2
						ARRAY[i] = 1
						ARRAY[i+1] = 2
						i = i + 2
					} else {
						Ans = Ans + 1
						ARRAY[i] = 1

						i = i + 1
					}

				} else {
					if First[i]+Second[i] == 98 {
						if First[i+1]+Second[i+1] == 96 {
							Ans = Ans + 2
							ARRAY[i] = 1
							ARRAY[i+1] = 2
							i = i + 2
						} else {
							ARRAY[i] = 1
							i = i + 1

						}
					}
				}

			}
		}
		if First[n-1]+Second[n-1] == 97 {
			Ans = Ans + 2
		}
		if n == 1 {
			if First[n-1]+Second[n-1] == 96 {
				Ans = Ans + 1
			}
		} else {
			if First[n-1]+Second[n-1] == 96 {
				if First[n-2]+Second[n-2] == 98 {
					if ARRAY[n-1] != 2 {
						Ans = Ans + 1
					}
				} else {
					Ans = Ans + 1

				}
			}
		}
		fmt.Println(Ans)

	}
}

package main

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

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

	var T, n int
	var s0, s1 []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s0, &s1)
		ans := 0
		use := -1
		for i, b := range s0 {
			if b != s1[i] {
				ans += 2
			} else if b == '0' || i > 0 && s0[i-1] == '0' && s1[i-1] == '0' && use != i-1 {
				ans++
			} else if i < n-1 && s0[i+1] == '0' && s1[i+1] == '0' {
				ans++
				use = i + 1
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

func cost(a, b string) int {
	c := [2]int{}
	for i := 0; i < len(a); i++ {
		c[a[i]-'0']++
		c[b[i]-'0']++
	}

	if c[0] == 0 {
		return 0
	} else if c[1] == 0 {
		return 1
	}
	return 2
}

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 n int
		s := [2]string{}
		fmt.Fscanf(r, "%d\n", &n)
		fmt.Fscanf(r, "%s\n%s\n", &s[0], &s[1])

		f := make([]int, n)
		for i := 0; i < n; i++ {
			for j := 0; j <= 10 && i-j >= 0; j++ {
				x := cost(s[0][i-j:i+1], s[1][i-j:i+1])

				if i-j-1 >= 0 {
					x += f[i-j-1]
				}
				if x > f[i] {
					f[i] = x
				}
			}
		}

		fmt.Println(f[n-1])
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(reader, &n, &s1, &s2)
		if t == 102 {
			fmt.Println(n, s1, s2)
		}
		ans := 0
		found_zero := 0
		found_one := 0
		for i := 0; i < n; i++ {
			if s1[i] == '0' && s2[i] == '1' || s1[i] == '1' && s2[i] == '0' {
				ans += found_zero + 2
				found_one = 0
				found_zero = 0
			} else if found_zero > 0 && s1[i] == '1' && s2[i] == '1' {
				ans += found_zero + 1
				found_zero = 0
				found_one = 0
			} else if found_one > 0 && s1[i] == '0' && s2[i] == '0' {
				ans += 2
				found_zero = 0
				found_one = 0
			} else if s1[i] == '0' && s2[i] == '0' {
				found_zero++
			} else if s1[i] == '1' && s2[i] == '1' {
				found_one++
			}
		}
		ans += found_zero
		write(f, ans, "\n")
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(reader, &n, &s1, &s2)
		if t == 102 {
			fmt.Println(n, s1, s2)
		}
		ans := 0
		found_zero := 0
		found_one := 0
		for i := 0; i < n; i++ {
			if s1[i] == '0' && s2[i] == '1' || s1[i] == '1' && s2[i] == '0' {
				ans += found_zero + 2
				found_one = 0
				found_zero = 0
			} else if found_zero > 0 && s1[i] == '1' && s2[i] == '1' {
				if found_zero == 2 {
					ans += 3
				} else {
					ans += 2
				}
				found_zero = 0
				found_one = 0
			} else if found_one > 0 && s1[i] == '0' && s2[i] == '0' {
				ans += 2
				found_zero = 0
				found_one = 0
			} else if s1[i] == '0' && s2[i] == '0' {
				found_zero++
			} else if s1[i] == '1' && s2[i] == '1' {
				found_one++
			}
		}
		ans += found_zero
		write(f, ans, "\n")
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(reader, &n, &s1, &s2)
		ans := 0
		found_zero := 0
		found_one := 0
		for i := 0; i < n; i++ {
			if s1[i] == '0' && s2[i] == '1' || s1[i] == '1' && s2[i] == '0' {
				ans += found_zero + 2
				found_one = 0
				found_zero = 0
			} else if found_zero > 0 && s1[i] == '1' && s2[i] == '1' {
				if found_zero == 2 {
					ans += 3
				} else {
					ans += 2
				}
				found_zero = 0
				found_one = 0
			} else if found_one > 0 && s1[i] == '0' && s2[i] == '0' {
				ans += 2
				found_zero = 0
				found_one = 0
			} else if s1[i] == '0' && s2[i] == '0' {
				found_zero++
			} else if s1[i] == '1' && s2[i] == '1' {
				found_one++
			}
		}
		ans += found_zero
		write(f, ans, "\n")
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(reader, &n, &s1, &s2)
		ans := 0
		found_zero := 0
		found_one := 0
		for i := 0; i < n; i++ {
			if s1[i] == '0' && s2[i] == '1' || s1[i] == '1' && s2[i] == '0' {
				if found_zero > 0 {
					ans += 3
				} else {
					ans += 2
				}
				found_one = 0
				found_zero = 0
			} else if found_zero > 0 && s1[i] == '1' && s2[i] == '1' {
				if found_zero == 2 {
					ans += 3
				} else {
					ans += 2
				}
				found_zero = 0
				found_one = 0
			} else if found_one > 0 && s1[i] == '0' && s2[i] == '0' {
				ans += 2
				found_zero = 0
				found_one = 0
			} else if s1[i] == '0' && s2[i] == '0' {
				found_zero++
			} else if s1[i] == '1' && s2[i] == '1' {
				found_one++
			}
		}
		ans += found_zero
		write(f, ans, "\n")
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(reader, &n, &s1, &s2)
		ans := 0
		found_zero := false
		found_one := false
		for i := 0; i < n; i++ {
			if s1[i] == '0' && s2[i] == '1' || s1[i] == '1' && s2[i] == '0' {
				if found_zero {
					ans += 3
				} else {
					ans += 2
				}
				found_one = false
				found_zero = false
			} else if found_zero && s1[i] == '1' && s2[i] == '1' {
				ans += 2
				found_zero = false
				found_one = false
			} else if (found_one || found_zero) && s1[i] == '0' && s2[i] == '0' {
				ans += 2
				found_zero = false
				found_one = false
			} else if s1[i] == '0' && s2[i] == '0' {
				found_zero = true
			} else if s1[i] == '1' && s2[i] == '1' {
				found_one = true
			}
		}
		if found_zero {
			ans++
		}
		write(f, ans, "\n")
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		var s1, s2 string
		fmt.Fscan(reader, &n, &s1, &s2)
		ans := 0
		found_zero := false
		found_one := false
		for i := 0; i < n; i++ {
			if s1[i] == '0' && s2[i] == '1' || s1[i] == '1' && s2[i] == '0' {
				ans += 2
				found_one = false
				found_zero = false
			} else if found_zero && s1[i] == '1' && s2[i] == '1' {
				ans += 2
				found_zero = false
				found_one = false
			} else if (found_one || found_zero) && s1[i] == '0' && s2[i] == '0' {
				ans += 2
				found_zero = false
				found_one = false
			} else if s1[i] == '0' && s2[i] == '0' {
				found_zero = true
			} else if s1[i] == '1' && s2[i] == '1' {
				found_one = true
			}
		}
		if found_zero {
			ans++
		}
		write(f, ans, "\n")
	}
}

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++ {
		var n int
		fmt.Fscan(input, &n)

		First := make([]byte, 0)
		Second := make([]byte, 0)

		fmt.Fscan(input, &First)

		fmt.Fscan(input, &Second)
		var Ans int

		ARRAY := make([]int, n)

		for i := 0; i < n-1; {
			if First[i]+Second[i] == 97 {
				Ans = Ans + 2
				ARRAY[i] = 1
				i = i + 1
			} else {
				if First[i]+Second[i] == 96 {
					if First[i+1]+Second[i+1] == 98 {
						Ans = Ans + 2
						ARRAY[i] = 1
						ARRAY[i+1] = 2
						i = i + 2
					} else {
						Ans = Ans + 1
						ARRAY[i] = 1

						i = i + 1
					}

				} else {
					if First[i]+Second[i] == 98 {
						if First[i+1]+Second[i+1] == 96 {
							Ans = Ans + 2
							ARRAY[i] = 1
							ARRAY[i+1] = 2
							i = i + 2
						} else {
							ARRAY[i] = 1
							i = i + 1

						}
					}
				}

			}
		}
		if First[n-1]+Second[n-1] == 97 {
			Ans = Ans + 2
		}
		if n == 1 {
			if First[n-1]+Second[n-1] == 96 {
				Ans = Ans + 2
			}
		} else {
			if First[n-1]+Second[n-1] == 96 {
				if First[n-2]+Second[n-2] == 98 {
					if ARRAY[n-1] != 2 {
						Ans = Ans + 1
					}
				} else {
					Ans = Ans + 1

				}
			}
		}
		fmt.Println(Ans)

	}
}

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++ {
		var n int
		fmt.Fscan(input, &n)

		First := make([]byte, 0)
		Second := make([]byte, 0)

		fmt.Fscan(input, &First)

		fmt.Fscan(input, &Second)
		var Ans int

		ARRAY := make([]int, n)

		for i := 0; i < n-1; {
			if First[i]+Second[i] == 97 {
				Ans = Ans + 2
				ARRAY[i] = 1
				i = i + 1
			} else {
				if First[i]+Second[i] == 96 {
					if First[i+1]+Second[i+1] == 98 {
						Ans = Ans + 2
						ARRAY[i] = 1
						ARRAY[i+1] = 2
						i = i + 2
					} else {
						Ans = Ans + 1
						ARRAY[i] = 1

						i = i + 1
					}

				} else {
					if First[i]+Second[i] == 98 {
						if First[i+1]+Second[i+1] == 96 {
							Ans = Ans + 2
							ARRAY[i] = 1
							ARRAY[i+1] = 2
							i = i + 2
						} else {
							ARRAY[i] = 1
							i = i + 1

						}
					}
				}

			}
		}
		if First[n-1]+Second[n-1] == 97 {
			Ans = Ans + 2
		}
		if n == 1 {
			if First[n-1]+Second[n-1] == 96 {
				Ans = Ans + 2
			}
		} else {
			if First[n-1]+Second[n-1] == 96 {
				if First[n-2]+Second[n-2] == 98 {
					if ARRAY[n-2] == 2 {
						Ans = Ans + 1
					}
				} else {
					Ans = Ans + 1

				}
			}
		}
		fmt.Println(Ans)

	}
}

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++ {
		var n int
		fmt.Fscan(input, &n)

		First := make([]byte, 0)
		Second := make([]byte, 0)

		fmt.Fscan(input, &First)

		fmt.Fscan(input, &Second)
		var Ans int

		for i := 0; i < n-1; {
			if First[i]+Second[i] == 97 {
				Ans = Ans + 2
				i = i + 1
			} else {
				if First[i]+Second[i] == 96 {
					if First[i+1]+Second[i+1] == 98 {
						Ans = Ans + 2
						i = i + 2
					} else {
						Ans = Ans + 1
						i = i + 1
					}

				} else {
					if First[i]+Second[i] == 98 {
						if First[i+1]+Second[i+1] == 96 {
							Ans = Ans + 2
							i = i + 2
						} else {
							i = i + 1

						}
					}
				}

			}
		}
		if First[n-1]+Second[n-1] == 97 {
			Ans = Ans + 2
		}
		if n == 1 {
			if First[n-1]+Second[n-1] == 96 {
				Ans++
			}
		} else {
			if First[n-1]+Second[n-1] == 96 {
				if First[n-2]+Second[n-2] != 98 {
					Ans++
				}
			}
		}
		fmt.Println(Ans)

	}
}

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++ {
		var n int
		fmt.Fscan(input, &n)

		First := make([]byte, 0)
		Second := make([]byte, 0)

		fmt.Fscan(input, &First)

		fmt.Fscan(input, &Second)
		var Ans int
		var B int

		for i := 0; i < n-1; {
			if First[i]+Second[i] == 97 {
				Ans = Ans + 2
				i = i + 1

			} else {
				if First[i]+Second[i] == 96 {
					if First[i+1]+Second[i+1] == 98 {
						Ans = Ans + 1
						B++
						i = i + 2
					} else {
						Ans = Ans + 1

						i = i + 1
					}

				} else {
					if First[i]+Second[i] == 98 {
						if First[i+1]+Second[i+1] == 96 {
							B++
							Ans = Ans + 1
							i = i + 2
						} else {
							i = i + 1

						}
					}
				}

			}
		}
		if First[n-1]+Second[n-1] == 97 {
			Ans = Ans + 2
		}

		if First[n-1]+Second[n-1] == 96 {
			Ans = Ans + 1
		}
		fmt.Println(Ans + B)

	}
}

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++ {

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

		First := make([]byte, 0)
		Second := make([]byte, 0)

		fmt.Fscan(input, &First)

		fmt.Fscan(input, &Second)
		var Ans int

		if n > 1 {
			for i := 0; i < n-1; {
				if First[i]+Second[i] == 97 {
					Ans = Ans + 2
					i = i + 1
				} else {
					if First[i]+Second[i] == 96 {
						if First[i+1]+Second[i+1] == 98 {
							Ans = Ans + 2
							i = i + 2
						} else {
							Ans = Ans + 1
							i = i + 1
						}
					} else {
						if First[i+1]+Second[i+1] == 96 {
							Ans = Ans + 2
							i = i + 2
						} else {
							i = i + 1
						}

					}
				}

			}
			if First[n-1]+Second[n-1] == 96 {
				if First[n-2]+Second[n-2] != 98 {
					Ans = Ans + 1
				}
			}

			if First[n-1]+Second[n-1] == 97 {
				Ans = Ans + 2
			}
			fmt.Println(Ans)

		} else {
			if First[0]+Second[0] == 96 {
				fmt.Println(1)
			}
			if First[0]+Second[0] == 97 {
				fmt.Println(2)
			}
			if First[0]+Second[0] == 98 {
				fmt.Println(0)
			}
		}
	}
}


DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter c DZY knows its value wc. For each special string s = s1s2... s|s| (|s| is the length of the string) he represents its value with a function f(s), where Now DZY has a string s. He wants to insert k lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?

The first line contains a single string s (1 ≤ |s| ≤ 103). The second line contains a single integer k (0 ≤ k ≤ 103). The third line contains twenty-six integers from wa to wz. Each such number is non-negative and doesn't exceed 1000.

Print a single integer — the largest possible value of the resulting string DZY could get.

NoteIn the test sample DZY can obtain "abcbbc", value = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	s := []uint8(next())
	k := nextInt()
	w := make([]int, 26)
	value, max := 0, 0

	for i := 0; i < 26; i++ {
		w[i] = nextInt()
		if w[i] > max {
			max = w[i]
		}
	}

	for i := 0; i < len(s); i++ {
		value += w[s[i] - 'a'] * (i + 1)
	}

	for i := 0; i < k; i++ {
		value += max * (i + len(s) + 1)
	}

	println(value)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	s := string(scanner.Text())

	scanner.Scan()
	k, err := strconv.Atoi(scanner.Text())
	if err != nil {
		return
	}

	ws := make([]int, 26)
	max_w := 0
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		ws[i] = a
		if ws[i] > max_w {
			max_w = ws[i]
		}
	}

	var value int = 0
	idx := 0
	for ; idx < len(s); idx++ {
		value += (ws[int(s[idx]-'a')] * (idx + 1))
	}
	for i := 0; i < k; i++ {
		idx++
		value += max_w * idx
	}

	fmt.Println(value)
}

package main

import "fmt"

func main() {
    var s string
    var k int
    var w [26]int
    fmt.Scan(&s)
    fmt.Scan(&k)
    max := -1
    for i := 0; i < 26; i++ {
        fmt.Scan(&w[i])
        if max < w[i] { max = w[i] }
    }
    ans := 0
    for i := 0; i < len(s); i++ {
        ans += (i+1)*w[s[i]-'a']
    }
    for i := 0; i < k; i++ {
        ans += (i+len(s)+1)*max
    }
    fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var s string
	var n, max, ans int
	val := make([]int, 26)
	fmt.Scan(&s, &n)
	for i := 0; i < 26; i++ {
		fmt.Scan(&val[i])
		if val[i] > max {
			max = val[i]
		}
	}
	for i, c := range s {
		ans += (i + 1) * val[c-'a']
	}
	for i := 1; i <= n; i++ {
		ans += (i + len(s)) * max
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	s := ""
	fmt.Scan(&s)

	k := 0
	fmt.Scan(&k)

	w := make([]int, 26, 26)
	m := 0
	for i := 0; i < 26; i++ {
		fmt.Scan(&w[i])
		if m < w[i] {
			m = w[i]
		}
	}

	ans := 0
	for i := 0; i < len(s); i++ {
		ans += (i + 1) * w[int(s[i]-'a')]
	}
	for i := 0; i < k; i++ {
		ans += m * (len(s) + i + 1)
	}

	fmt.Println(ans)
}

// 447B-mic
package main

import (
	"fmt"
	"math"
)

func main() {
	var s string
	var k, m int
	var w [26]int
	fmt.Scan(&s, &k)
	for i := 0; i < 26; i++ {
		fmt.Scan(&w[i])
		m = int(math.Max(float64(m), float64(w[i])))
	}

	l := int(len(s))
	res := 0
	for i := 1; i <= l; i++ {
		res += i * w[(int(s[i-1])-97)]
	}

	for i := (l + 1); i <= l+k; i++ {
		res += i * m
	}
	fmt.Println(res)
}

// cf447b project main.go
package main

import (
	"fmt"
)

func main() {
	var s string
	var n int
	var o [26]int
	fmt.Scan(&s, &n)
	for i := 0; i < 26; i++ {
		fmt.Scan(&o[i])
	}
	m := 0
	f := 0
	for i := 1; i <= len(s); i++ {
		f += i * o[s[i-1]-97]
	}
	for _, a := range o {
		if a > m {
			m = a
		}
	}

	for i := len(s) + 1; i <= len(s)+n; i++ {
		f += i * m
	}
	fmt.Println(f)
}

package main

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

func main() {
	var s string

	reader := bufio.NewReader(os.Stdin)
	if _s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = _s
	}

	var k int
	if _, err := fmt.Scanf("%d\n", &k); err != nil {
		return
	}

	ws := make([]int, 26)
	max_w := 0
	for i := 0; i < 25; i++ {
		if _, err := fmt.Scanf("%d", &ws[i]); err != nil {
			return
		}
		if ws[i] > max_w {
			max_w = ws[i]
		}
	}
	if _, err := fmt.Scanf("%d\n", &ws[25]); err != nil {
		return
	}
	if ws[25] > max_w {
		max_w = ws[25]
	}

	var value int = 0
	idx := 0
	for ; s[idx] >= 'a' && s[idx] <= 'z'; idx++ {
		value += (ws[int(s[idx]-'a')] * (idx + 1))
	}
	for i := 0; i < k; i++ {
		idx++
		value += max_w * idx
	}

	fmt.Println(value)
}

package main

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

func main() {
	var s string

	reader := bufio.NewReader(os.Stdin)
	if _s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		s = _s
	}

	var k int
	if _, err := fmt.Scanf("%d\n", &k); err != nil {
		return
	}

	ws := make([]int, 26)
	max_w := 0
	for i := 0; i < 26; i++ {
		if _, err := fmt.Scanf("%d", &ws[i]); err != nil {
			return
		}
		if ws[i] > max_w {
			max_w = ws[i]
		}
	}

	var value int = 0
	idx := 0
	for ; s[idx] >= 'a' && s[idx] <= 'z'; idx++ {
		value += (ws[int(s[idx]-'a')] * (idx + 1))
	}
	for i := 0; i < k; i++ {
		idx++
		value += max_w * idx
	}

	fmt.Println(value)
}

package main

import (
	"fmt"
)

func main() {
	var s string
	var n, max, ans int
	val := make([]int, 26)
	fmt.Scan(&s, &n)
	for i := 0; i < 26; i++ {
		fmt.Scan(&val[i])
		if val[i] > max {
			max = val[i]
		}
	}
	for i, c := range s {
		ans += (i + 1) * val[c-'a']
	}
	for i := 1; i <= n; i++ {
		ans += (i + len(s)) * max
	}
	fmt.Println(max)
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var s string
	var n, max, ans int
	val := make([]int, 26)
	fmt.Scan(&s, &n)
	for i := 0; i < 26; i++ {
		fmt.Scan(&val[i])
		if val[i] > max {
			max = val[i]
		}
	}
	for i, c := range s {
		ans += (i + 1) * val[c-'a']
	}
	for i := 1; i <= n; i++ {
		ans += (i + n) * max
	}
	fmt.Println(ans)
}


You are given an array $$$a$$$ of $$$n$$$ integers, and another integer $$$k$$$ such that $$$2k \le n$$$.You have to perform exactly $$$k$$$ operations with this array. In one operation, you have to choose two elements of the array (let them be $$$a_i$$$ and $$$a_j$$$; they can be equal or different, but their positions in the array must not be the same), remove them from the array, and add $$$\lfloor \frac{a_i}{a_j} \rfloor$$$ to your score, where $$$\lfloor \frac{x}{y} \rfloor$$$ is the maximum integer not exceeding $$$\frac{x}{y}$$$.Initially, your score is $$$0$$$. After you perform exactly $$$k$$$ operations, you add all the remaining elements of the array to the score.Calculate the minimum possible score you can get.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100$$$; $$$0 \le k \le \lfloor \frac{n}{2} \rfloor$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2 \cdot 10^5$$$).

Print one integer — the minimum possible score you can get.

NoteLet's consider the example test.In the first test case, one way to obtain a score of $$$2$$$ is the following one:  choose $$$a_7 = 1$$$ and $$$a_4 = 2$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{2} \rfloor = 0$$$, the array becomes $$$[1, 1, 1, 1, 3]$$$;  choose $$$a_1 = 1$$$ and $$$a_5 = 3$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{3} \rfloor = 0$$$, the array becomes $$$[1, 1, 1]$$$;  choose $$$a_1 = 1$$$ and $$$a_2 = 1$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{1} \rfloor = 1$$$, the array becomes $$$[1]$$$;  add the remaining element $$$1$$$ to the score, so the resulting score is $$$2$$$. In the second test case, no matter which operations you choose, the resulting score is $$$16$$$.In the third test case, one way to obtain a score of $$$0$$$ is the following one:  choose $$$a_1 = 1$$$ and $$$a_2 = 3$$$ for the operation; the score becomes $$$0 + \lfloor \frac{1}{3} \rfloor = 0$$$, the array becomes $$$[3, 7]$$$;  choose $$$a_1 = 3$$$ and $$$a_2 = 7$$$ for the operation; the score becomes $$$0 + \lfloor \frac{3}{7} \rfloor = 0$$$, the array becomes empty;  the array is empty, so the score doesn't change anymore. In the fourth test case, no operations can be performed, so the score is the sum of the elements of the array: $$$4 + 2 = 6$$$.

package main

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

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

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

func main() {
	defer writer.Flush()
	var T, n, k int
	Fscan(reader, &T)
	for cas := 1; cas <= T; cas++ {
		Fscan(reader, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(reader, &a[i])
		}
		sort.Ints(a)
		ans := 0
		for i := 1; i <= k; i++ {
			ans += a[n-i-k] / a[n-i]
		}
		for i := 0; i < n-k-k; i++ {
			ans += a[i]
		}
		Fprintln(writer, ans)
	}
}

package main

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

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

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

func main() {
	var T, n, k int
	Scan(&T)
	for cas := 1; cas <= T; cas++ {
		Scan(&n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Scan(&a[i])
		}
		sort.Ints(a)
		ans := 0
		for i := 1; i <= k; i++ {
			ans += a[n-i-k] / a[n-i]
		}
		for i := 0; i < n-k-k; i++ {
			ans += a[i]
		}
		Println(ans)
	}
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)
func insertionSort(a []int) {
	var n = len(a)
	for i:=0; i<n; i++ {
		j:=i
		for j>0 {
			if a[j-1]>a[j] {
				a[j-1], a[j] = a[j], a[j-1]
			}
			j--
		}
	}
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	tests, _ := strconv.Atoi(scanner.Text())

	for i := 1; i <= tests; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		a := make([]int, n, n)
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < n; i++ {
			scanner.Scan()
			a[i], _ = strconv.Atoi(scanner.Text())
		}
		//fmt.Println(a)
		insertionSort(a)
		//fmt.Println(a)
		//fmt.Println()
		sum := 0
		for i := n - 2*k; i < n-k; i++ {
			sum += a[i] / a[i+k]
		}
		for i := 0; i < n-2*k; i++ {
			sum += a[i]
		}
		fmt.Println(sum)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for t > 0 {
		t--
		var n, k int
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d %d", &n, &k)
		numbers := make([]int, n)
		sum := 0
		scanner.Scan()
		for i, m := range strings.Fields(scanner.Text()) {
			numbers[i], _ = strconv.Atoi(m)
			sum += numbers[i]
		}
		sort.Ints(numbers)
		i, j := n-k-1, n-1
		for k > 0 {
			k--
			sum += numbers[i] / numbers[j]
			sum -= numbers[i] + numbers[j]
			i--
			j--
		}
		fmt.Println(sum)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1618D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var T, n, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		s := 0
		for _, v := range a[:n-k*2] {
			s += v
		}
		for i := n - k; i < n; i++ {
			s += a[i-k] / a[i]
		}
		Fprintln(out, s)
	}
}

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

package main

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

		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}

		sort.Ints(nums)
		var sum int
		for i := 0; i < k; i++ {
			sum += nums[n-i-k-1] / nums[n-i-1]
		}

		for i := 0; i < n-k-k; i++ {
			sum += nums[i]
		}
		fmt.Fprintln(out, sum)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, k, p := 0, 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &k)
		o, sum := []int{}, 0
		for j := 0; j < n; j++ {
			fmt.Fscan(f, &p)
			o = append(o, p)
		}
		sort.Ints(o)
		for j := 0; j < k; j++ {
			sum += o[n-k-j-1] / o[n-j-1]
		}
		for j := 0; j < n-(2*k); j++ {
			sum += o[j]
		}
		fmt.Fprintln(w, sum)
	}
	w.Flush()
}

func main() {
	solve()
}

package main

import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)
func insertionSort(a []int) {
	var n = len(a)
	for i:=0; i<n; i++ {
		j:=i
		for j>0 {
			if a[j-1]>a[j] {
				a[j-1], a[j] = a[j], a[j-1]
			}
			j--
		}
	}
}
func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	tests, _ := strconv.Atoi(scanner.Text())

	for i := 1; i <= tests; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		a := make([]int, n, n)
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < n; i++ {
			scanner.Scan()
			a[i], _ = strconv.Atoi(scanner.Text())
		}
		insertionSort(a)
		sum := 0
		for i := n - 2*k; i < n-k; i++ {
			sum += a[i] / a[i+k]
		}
		for i := 0; i < k; i++ {
			sum += a[i]
		}
		fmt.Println(sum)
	}
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers.Let's call a pair of indices $$$i$$$, $$$j$$$ good if $$$1 \le i < j \le n$$$ and $$$\gcd(a_i, 2a_j) > 1$$$ (where $$$\gcd(x, y)$$$ is the greatest common divisor of $$$x$$$ and $$$y$$$).Find the maximum number of good index pairs if you can reorder the array $$$a$$$ in an arbitrary way.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of the test case contains a single integer $$$n$$$ ($$$2 \le n \le 2000$$$) — the number of elements in the array. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case, output a single integer — the maximum number of good index pairs if you can reorder the array $$$a$$$ in an arbitrary way.

NoteIn the first example, the array elements can be rearranged as follows: $$$[6, 3, 5, 3]$$$.In the third example, the array elements can be rearranged as follows: $$$[4, 4, 2, 1, 1]$$$.

package main

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

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

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

		m := make([]int, n)
		var pos int
		for i := n - 1; i >= 0; i-- {
			if arr[i]%2 == 0 {
				m[pos] = arr[i]
				pos++
			}
		}

		for i := n - 1; i >= 0; i-- {
			if arr[i]%2 != 0 {
				m[pos] = arr[i]
				pos++
			}
		}

		var c int
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if gcd(m[i], 2*m[j]) > 1 {
					c++
				}
			}
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

/*
1
33
27 49 32 95 100 20 58 39 92 30 67 89 58 81 100 66 73 29 75 81 70 55 18 28 7 35 98 52 30 11 69 48 84
*/

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

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

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

		a := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		for i, j := 0, n-1; i < j; {
			if a[i]%2 == 0 {
				i++
				continue
			}

			if a[j]%2 != 0 {
				j--
				continue
			}

			a[i], a[j] = a[j], a[i]
		}

		cnt := 0

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if (gcd(a[i], 2*a[j])) > 1 {
					cnt++
				}
			}
		}

		fmt.Fprintln(writer, cnt)
	}
}

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

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	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))
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	Test:= io.NextInt()
	for i := 0; i < Test; i++ {
		n := io.NextInt()
		var ans int64=0
		arr:=make([]int,n)
		var odd []int
		var even []int
		for i:=0 ; i < n ; i++{
		    x:=io.NextInt()
		    arr[i]=x
		    if(x%2==1){
		        odd=append(odd,x)
		    }else{
		        even=append(even,x)
		    }
		}
		var c int64=int64(len(odd))
		var d int64=int64(len(even))
		var cc int=len(odd)
		ans+=c*d
		ans+=(d*(d-1))/2
		for i:=0 ; i < cc; i++{
		    for j:=i+1 ; j < cc; j++{
		        if(GCD(odd[i],odd[j])>1){
		            ans+=1
		        }
		    }
		}
		io.Println(ans)
	}
}
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}
func min(i,j int64)int64{
    if(i>j){
        return j
    }
    return i
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

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

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

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

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

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

// 00
package main

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

func gcd(a int, b int) int {
	if a > b {
		return gcd(b, a)
	}
	if b%a == 0 {
		return a
	} else {
		return gcd(b%a, a)
	}
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, curr int
		fmt.Fscan(reader, &n)
		odds := make([]int, 0)
		o := 0
		e := 0
		ans := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &curr)
			if curr%2 == 0 {
				e++
			} else {
				o++
				odds = append(odds, curr)
			}
		}
		ans += o * e
		ans += (e * (e - 1)) / 2
		for i := 0; i < len(odds); i++ {
			for j := i + 1; j < len(odds); j++ {
				if gcd(odds[i], odds[j]) > 1 {
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

func gcd(x, y int) int {
	if y > x {
		return gcd(y, x)
	}
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func solve(n int, a []int) int {
	var (
		x    []int
		c, r int
	)
	for _, v := range a {
		if v%2 == 1 {
			x = append(x, v)
		} else {
			c++
		}
	}
	r = n*c - c*(c+1)/2
	for i := 0; i < len(x); i++ {
		for j := i + 1; j < len(x); j++ {
			if gcd(x[i], x[j]) > 1 {
				r++
			}
		}
	}
	return r
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, a))
	}
}

package main

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

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	solve := func() {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i]&1 == 0
		})
		c := 0
		for l, v := range a {
			for r := l + 1; r < len(a); r++ {
				w := a[r]
				if gcd(v, w*2) > 1 {
					c++
				}
			}
		}
		Fprintln(out, c)
	}
	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve()
	}
}

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

package main

import (
	"bufio"
	"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-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for i, _ := range a {
			fmt.Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool { return a[i]%2 < a[j]%2 })
		c := 0
		for i, u := range a {
			for j := i + 1; j < len(a); j++ {
				v := a[j]
				if gcd(u, 2*v) > 1 {
					c++
				}
			}
		}
		fmt.Fprintln(out, c)

	}
}

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

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

package main

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

// 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 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 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 {
	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 LITTLE(x int) int64 {
	var answer int64
	answer = answer + int64((x*x*x*x-x*x)/4) + int64(x*x*(x-1)*(x-1)/8) - int64(x*(x-1)*(x+x+1)*(x+x-1)/12)
	return answer
}

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
}

var t int

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

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

		Even := make([]int, 0)
		Odd := make([]int, 0)

		for i := 1; i < n+1; i++ {
			var m int
			fmt.Fscan(input, &m)
			if m%2 == 0 {
				Even = append(Even, m)
			} else {
				Odd = append(Odd, m)
			}
		}
		var Answer int
		q := len(Even)
		q1 := len(Odd)

		Answer = int(q*(q-1)/2) + q*q1

		sort.Ints(Odd)

		for i := q1 - 1; i > 0; i-- {
			for j := i - 1; j > -1; j-- {
				if GCD(int64(Odd[i]), int64(Odd[j])) > 1 {
					Answer++
				}
			}
		}
		fmt.Println(Answer)

	}

}

package main

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

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		var n int

		fmt.Fscan(in , &n)

		arr  := make([]int,n)

		for i := 0 ; i < n ; i++{
			fmt.Fscan(in , &arr[i])

		}

		count := 0

		arr = ArrayReorder(arr)

		for i := 0 ; i < n ; i++{
			for j := i+1 ; j < len(arr);j++{

				if GCD(arr[i] , 2 * arr[j]) > 1{
						count++
				}

			}
		}

		fmt.Fprintln(out , count)
	}

	T := 1

	fmt.Fscan(in ,&T)

	for o := 0 ; o < T ; o++{
		solve()
	}
}

func ArrayReorder(arr []int)[]int{

 sort.Slice(arr , func(a , b int) bool{

 	return arr[a] & 1 == 0   // even and odd sort
 })
 	return arr
}

func GCD(a , b int)int{

	for a != 0{
		a , b = b % a , a
	}

	return b
}

func main(){

	run(os.Stdin , os.Stdout)
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i]&1 == 0
		})
		c:=0
		for l, v := range a {
			for r := l + 1; r < len(a); r++ {
				w := a[r]
				if gcd(v,w*2) > 1 {
					c++
				}
			}
		}
		Fprintln(out, c)
	}

	T := 1
	Fscan(in, &T) //
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

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

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

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

package main

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

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

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

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

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

		var c int
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if gcd(arr[i], 2*arr[j]) > 1 {
					c++
				}
			}
		}
		fmt.Fprintln(out, c)
	}
}

package main

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

/*

 */

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

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

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

		a := make([]int, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		for i, j := 0, n-1; i < j; i++ {
			for j >= 0 && a[j]%2 != 0 {
				j--
			}

			if j < 0 {
				break
			}

			if a[i]%2 != 0 {
				a[i], a[j] = a[j], a[i]
			}
		}

		cnt := 0

		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				if (gcd(a[i], 2*a[j])) > 1 {
					cnt++
				}
			}
		}

		fmt.Fprintln(writer, cnt)
	}
}

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

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	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))
}


Binary Spiders are species of spiders that live on Mars. These spiders weave their webs to defend themselves from enemies.To weave a web, spiders join in pairs. If the first spider in pair has $$$x$$$ legs, and the second spider has $$$y$$$ legs, then they weave a web with durability $$$x \oplus y$$$. Here, $$$\oplus$$$ means bitwise XOR.Binary Spiders live in large groups. You observe a group of $$$n$$$ spiders, and the $$$i$$$-th spider has $$$a_i$$$ legs.When the group is threatened, some of the spiders become defenders. Defenders are chosen in the following way. First, there must be at least two defenders. Second, any pair of defenders must be able to weave a web with durability at least $$$k$$$. Third, there must be as much defenders as possible.Scientists have researched the behaviour of Binary Spiders for a long time, and now they have a hypothesis that they can always choose the defenders in an optimal way, satisfying the conditions above. You need to verify this hypothesis on your group of spiders. So, you need to understand how many spiders must become defenders. You are not a Binary Spider, so you decided to use a computer to solve this problem.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 3\cdot10^5$$$, $$$0 \le k \le 2^{30} - 1$$$), the amount of spiders in the group and the minimal allowed durability of a web. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$0 \le a_i \le 2^{30}-1$$$) — the number of legs the $$$i$$$-th spider has.

In the first line, print a single integer $$$\ell$$$ ($$$2 \le \ell \le n$$$), the maximum possible amount of defenders. In the second line, print $$$\ell$$$ integers $$$b_i$$$, separated by a single space ($$$1 \le b_i \le n$$$) — indices of spiders that will become defenders. If there exists more than one way to choose the defenders, print any of them. Unfortunately, it may appear that it's impossible to choose the defenders. In this case, print a single integer $$$-1$$$.

NoteConsider the examples above.In the first example, the group of spiders is illustrated on the picture below:  We choose the two-legged, the ten-legged and the $$$16$$$-legged spiders. It's not hard to see that each pair may weave a web with enough durability, as $$$2 \oplus 10 = 8 \ge 8$$$, $$$2 \oplus 16 = 18 \ge 8$$$ and $$$10 \oplus 16 = 26 \ge 8$$$.This is not the only way, as you can also choose, for example, the spiders with indices $$$3$$$, $$$4$$$, and $$$6$$$.In the second example, no pair of spiders can weave the web with durability $$$1024$$$ or more, so the answer is $$$-1$$$.

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
type trieNode struct {
	son     [2]*trieNode
	cnt, id int
}

type trie struct{ root *trieNode }

func newTrie() *trie { return &trie{&trieNode{}} }

const trieBitLen = 31

//func (trie) bin(v int) []byte {
//	s := make([]byte, trieBitLen)
//	for i := range s {
//		s[i] = byte(v >> (trieBitLen - 1 - i) & 1)
//	}
//	return s
//}

func (t *trie) put(v, id int) *trieNode {
	o := t.root
	for i := trieBitLen - 1; i >= 0; i-- {
		b := v >> i & 1
		if o.son[b] == nil {
			o.son[b] = &trieNode{}
		}
		o = o.son[b]
		o.cnt++
	}
	o.id = id
	return o
}

//func (t *trie) del(v int) *trieNode {
//	o := t.root
//	for i := trieBitLen - 1; i >= 0; i-- {
//		o = o.son[v>>i&1]
//		o.cnt--
//	}
//	return o
//}

// NOTE: 调用前确保至少插入了一个数
func (t *trie) maxXor(v int) (ans, id int) {
	o := t.root
	for i := trieBitLen - 1; i >= 0; i-- {
		b := v >> i & 1
		if o.son[b^1] != nil && o.son[b^1].cnt > 0 {
			ans |= 1 << i
			b ^= 1
		}
		o = o.son[b]
	}
	id = o.id
	return
}

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

	var n, k int
	Fscan(in, &n, &k)
	if k == 0 {
		Fprintln(out, n)
		for i := 1; i <= n; i++ {
			Fprint(out, i, " ")
		}
		return
	}

	kl := bits.Len(uint(k))

	type pair struct{ v, i int }
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].v)
		a[i].i = i + 1
	}
	sort.Slice(a, func(i, j int) bool { return a[i].v < a[j].v })

	maxXor := func(a []pair) (int, int) {
		if len(a) <= 1 {
			// todo
			//panic(-1)
			return -1,-1
		}
		t := newTrie()
		t.put(a[0].v, a[0].i)
		for _, p := range a[1:] {
			xor, id := t.maxXor(p.v)
			if xor >= k {
				return id, p.i
			}
			t.put(p.v, p.i)
		}
		return -1, -1
	}

	i, j := maxXor(a)
	if i < 0 {
		Fprintln(out, -1)
		return
	}

	ll := bits.Len(uint(a[n-1].v))
	if ll < kl {
		Fprintln(out, -1)
		return
	}

	if ll == kl {
		Fprintln(out, 2)
		Fprintln(out, i, j)
		return
	}

	ans := []int{}

	var f func(a []pair)
	f = func(a []pair) {
		if len(a) == 0 {
			return
		}
		if len(a) == 1 {
			ans = append(ans, a[0].i)
			return
		}

		ll := bits.Len(uint(a[len(a)-1].v))
		if ll < kl {
			ans = append(ans, a[0].i)
			return
		}
		if ll == kl {
			i, j := maxXor(a)
			if i < 0 {
				ans = append(ans, a[0].i)
			} else {
				ans = append(ans, i, j)
			}
			return
		}

		//if bits.Len(uint(a[0].v)) > kl {
		//
		//}

		//next := func(a []pair) {
		//
		//}

		for i, p := range a {
			if l:= bits.Len(uint(p.v));l > kl { // 必然会成立
				j := i+1
				for ; j < len(a); j++ {
					if bits.Len(uint(a[j].v)) > l {
						break
					}
				}
				for ii := i; ii < j; ii++ {
					a[ii].v ^= 1 << (l - 1)
				}
				f(a[i:j])
				f(a[j:])

				//if i == len(a)-1 {
				//	ans = append(ans, p.i)
				//} else {
				//	for j := i+1; j < len(a); j++ {
				//		if bits.Len(uint(a[i].v)) > bits.Len(uint(a[i-1].v)) {
				//			f(a[i:])
				//
				//			a = a[i:]
				//			break
				//		}
				//	}
				//}

				//f(a[i:])
				//a = a[:i]
				//break

				if i >= 2 {
					ii, jj := maxXor(a[:i])
					if ii < 0 {
						// 随便选一个
						ans = append(ans, a[0].i)
					} else {
						// 都选
						ans = append(ans, ii, jj)
					}
				} else if i > 0{
					// 随便选一个
					ans = append(ans, a[0].i)
				}
				break
			}
		}

		//for i := 1; i < len(a); i++ {
		//	if bits.Len(uint(a[i].v)) > bits.Len(uint(a[i-1].v)) {
		//		f(a[i:])
		//
		//		a = a[i:]
		//		break
		//	}
		//}
		//
		//l := bits.Len(uint(a[0].v))
		//for j := range a {
		//	a[j].v ^= 1 << (l - 1)
		//}

	}
	f(a)

	//for i, p := range a {
	//	if bits.Len(uint(p.v)) > kl {
	//
	//		f(a[i:])
	//
	//		if i >= 2 {
	//			ii, jj := maxXor(a[:i])
	//			if ii < 0 {
	//				// 随便选一个
	//				ans = append(ans, a[0].i)
	//			} else {
	//				// 都选
	//				ans = append(ans, ii, jj)
	//			}
	//		}
	//		break
	//	}
	//}

	Fprintln(out, len(ans))
	for _, v := range ans {
		Fprint(out, v, " ")
	}
}

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


Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya wonders eagerly what minimum lucky number has the sum of digits equal to n. Help him cope with the task.

The single line contains an integer n (1 ≤ n ≤ 106) — the sum of digits of the required lucky number.

Print on the single line the result — the minimum lucky number, whose sum of digits equals n. If such number does not exist, print -1.

package main
import (
	"fmt"
	"bufio"
	"os"
	//"strconv"
)
func main() {
	var n,x int
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n)
	flag:=false
	for s:=0;s<=n;s+=4 {
		x=n-s
		if x%7==0 {
			flag=true
			for i:=s/4;i>0;i-- {
				out.WriteRune('4')
			}
			for k:=x/7;k>0;k-- {
				out.WriteRune('7')
			}
			break
		}
	}
	if flag==false {
		out.WriteString("-1")
	}
	out.Flush()
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    n7 := n/7
    n %= 7
    for (n7 > 0) && (n%4 != 0) {
        n7--
        n += 7
    }
    if n%4 == 0 {
        n4 := n/4
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else {
        writer.WriteString("-1")
    }
    writer.WriteRune('\n')
    writer.Flush()
}

// 109A-mic
package main

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

func main() {
    z := bufio.NewWriter(os.Stdout)
    var f, s, i, n int
    fmt.Scan(&n)
    for n > 0 {
        if n%7 != 0 {
            n -= 4
            f++

        } else {
            s += n / 7
            n = 0
        }
    }
    if n < 0 {
        fmt.Println("-1")
        return
    }
    for i = 0; i < f; i++ {
        z.WriteRune('4')
        z.Flush()
    }
    for i = 0; i < s; i++ {
        z.WriteRune('7')
        z.Flush()
    }
    fmt.Println()
}

//https://codeforces.com/contest/110/problem/C

package main

import (
	"bytes"
	"fmt"
)

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		fmt.Println(err)
	} else {
		sliceResult := findComposedLuckyNumbers(n)
		fmt.Print(sliceResult)
	}
}

func findComposedLuckyNumbers(x int) string {
	if x%4 == 0 {
		xIn4 := x / 4
		return buildNumberSequence(xIn4, 0)
	}

	if x%7 == 0 {
		xIn7 := x / 7
		return buildNumberSequence(0, xIn7)
	}

	xIn7 := 0
	for x > 7 {
		x -= 7
		xIn7++
		if x%4 == 0 {
			xIn4 := x / 4
			return buildNumberSequence(xIn4, xIn7)
		}
	}
	return "-1"
}

func buildNumberSequence(xIn4 int, xIn7 int) string {
	for xIn4 >= 7 {
		xIn7 += 4
		xIn4 -= 7
	}

	var result bytes.Buffer

	i := 0
	for ; i < xIn4; i++ {
		result.WriteString("4")
	}

	for ; i < xIn4+xIn7; i++ {
		result.WriteString("7")
	}

	return result.String()
}

package main
import (
	"fmt"
	"bufio"
	"os"
	//"strconv"
)
func main() {
	var n,x int
	out := bufio.NewWriter(os.Stdout)
	fmt.Scan(&n)
	flag:=false
	for s:=0;s<=n;s+=4 {
		x=n-s
		if x%7==0 {
			flag=true
			for i:=s/4;i>0;i-- {
				out.WriteRune('4')
			}
			for k:=x/7;k>0;k-- {
				out.WriteRune('7')
			}
		}
	}
	if flag==false {
		out.WriteString("-1")
	}
	out.Flush()
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    if (n%4)%7 == 0 {
        n4, n7 := n/4, (n%4)/7
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else if (n%7)%4 == 0 {
        n4, n7 := (n%7)/4, n/7
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else {
        writer.WriteString("-1")
    }
    writer.WriteRune('\n')
    writer.Flush()
}

package main

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

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    if (n%4)%7 == 0 {
        n4, n7 := n/4, (n%4)/7
        n7 += (n4/7)*4
        n4 %= 7
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else if (n%7)%4 == 0 {
        n4, n7 := (n%7)/4, n/7
        for ; n4 > 0; n4-- { writer.WriteRune('4') }
        for ; n7 > 0; n7-- { writer.WriteRune('7') }
    } else {
        writer.WriteString("-1")
    }
    writer.WriteRune('\n')
    writer.Flush()
}

// 109A-mic
package main

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

func main() {
    z := bufio.NewWriter(os.Stdout)
    var f, s, i, n int
    fmt.Scan(&n)
    for n > 0 {
        if n%7 == 1 {
            n -= 4
            f++
        } else {
            s += n / 7
            n = 0
        }
    }
    if n < 0 {
        fmt.Println("-1")
        return
    }
    for i = 0; i < f; i++ {
        z.WriteRune('4')
    }
    for i = 0; i < s; i++ {
        z.WriteRune('7')
    }
    fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		fmt.Println(err)
	} else {
		sliceResult := findLuckyNumbers(n)
		for i := 0; i < len(sliceResult); i++ {
			fmt.Print(sliceResult[i])
		}
	}
}

func findLuckyNumbers(x int) []int {
	//Number formed by sums of n-seq of 4's AND s-seq of 7's
	slice4 := []int{}
	slice7 := []int{}
	for {
		slice4 = genNextSequenceValue(slice4, 4, 7)
		digitsSum := sumDigits(slice4)
		if int64(x) == digitsSum {
			return slice4
		}
		if digitsSum > int64(x) {
			break
		}
	}

	for {
		slice7 = genNextSequenceValue(slice7, 7, 4)
		digitsSum := sumDigits(slice7)
		if int64(x) == digitsSum {
			return slice7
		}
		if digitsSum > int64(x) {
			return []int{-1}
		}
	}
}

func genNextSequenceValue(sliceNumber []int, prefix int, suffix int) []int {
	sliceNumberLen := len(sliceNumber)
	if sliceNumberLen == 0 {
		return []int{prefix}
	}
	lastItem := sliceNumber[sliceNumberLen-1]
	if lastItem == prefix {
		sliceNumber[sliceNumberLen-1] = suffix
	} else {
		sliceNumber[sliceNumberLen-1] = prefix
		sliceNumber = append(sliceNumber, prefix)
	}
	return sliceNumber
}

func sumDigits(sliceNumber []int) (sum int64) {
	sliceSize := len(sliceNumber)
	for i := 0; i < sliceSize; i++ {
		sum += int64(sliceNumber[i])
	}
	return sum
}