Some company is going to hold a fair in Byteland. There are $$$n$$$ towns in Byteland and $$$m$$$ two-way roads between towns. Of course, you can reach any town from any other town using roads.There are $$$k$$$ types of goods produced in Byteland and every town produces only one type. To hold a fair you have to bring at least $$$s$$$ different types of goods. It costs $$$d(u,v)$$$ coins to bring goods from town $$$u$$$ to town $$$v$$$ where $$$d(u,v)$$$ is the length of the shortest path from $$$u$$$ to $$$v$$$. Length of a path is the number of roads in this path.The organizers will cover all travel expenses but they can choose the towns to bring goods from. Now they want to calculate minimum expenses to hold a fair in each of $$$n$$$ towns.

There are $$$4$$$ integers $$$n$$$, $$$m$$$, $$$k$$$, $$$s$$$ in the first line of input ($$$1 \le n \le 10^{5}$$$, $$$0 \le m \le 10^{5}$$$, $$$1 \le s \le k \le min(n, 100)$$$) — the number of towns, the number of roads, the number of different types of goods, the number of different types of goods necessary to hold a fair. In the next line there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_{i} \le k$$$), where $$$a_i$$$ is the type of goods produced in the $$$i$$$-th town. It is guaranteed that all integers between $$$1$$$ and $$$k$$$ occur at least once among integers $$$a_{i}$$$. In the next $$$m$$$ lines roads are described. Each road is described by two integers $$$u$$$ $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) — the towns connected by this road. It is guaranteed that there is no more than one road between every two towns. It is guaranteed that you can go from any town to any other town via roads.

Print $$$n$$$ numbers, the $$$i$$$-th of them is the minimum number of coins you need to spend on travel expenses to hold a fair in town $$$i$$$. Separate numbers with spaces.

package main

import (
	"io/ioutil"
	"fmt"
	"os"
	"strings"
	"strconv"
)

const (
	maxk, maxn, inf int = 105, 1e5 + 5, 0x7fffffff
)

var (
	n, m, s, k int
	t [maxk][]int
	g, d [maxn][]int
)

func str2Ints(str string) []int {
	ret := make([]int, 0)
	str = strings.TrimSpace(str)
	// fmt.Println(strings.Split(str, " "))
	for _, item := range strings.Split(str, " ") {
		num,_ := strconv.Atoi(item)
		ret = append(ret, num)
	}
	return ret
}

func getInts() []int {
	//assumes POSITIVE INTEGERS. Check v for '-' if you have negative.
	var buf []byte
	buf, _ = ioutil.ReadAll(os.Stdin)
	// fmt.Println("here")
	var ints []int
	num := int(0)
	found := false
	for _, v := range buf {
		if '0' <= v && v <= '9' {
			num = 10*num + int(v - '0') //could use bitshifting here.
			found = true
		} else if found {
			ints = append(ints, num)
			found = false
			num = 0
		}
	}
	if found {
		ints = append(ints, num)
		found = false
		num = 0
	}
	// fmt.Println(len(ints))
	return ints
}

func read() {
	nums := getInts()

	n, m, k, s = nums[0], nums[1], nums[2], nums[3]
	idx := 4

	for ; idx < 4 + n; idx++ {
		t[nums[idx]] = append(t[nums[idx]], idx - 3)
	}

	for idx < 4 + n + 2 * m {
		st := nums[idx]
		idx++
		ed := nums[idx]
		idx++
		g[st] = append(g[st], ed)
		g[ed] = append(g[ed], st)
	}

	for i := 1; i <= n; i++ {
		d[i] = append(d[i], 0)
		for j := 1; j <= k; j++ { d[i] = append(d[i], inf) }
	}

}

func bfs(x int) {
	q := make([]int, 0)
	for _, item := range t[x] {
		q = append(q, item)
		d[item][x] = 0
	}
	for len(q) != 0 {
		hd := q[0]
		q = q[1:]
		for _, nxt := range g[hd] {
			if d[nxt][x] != inf { continue }
			d[nxt][x] = d[hd][x] + 1
			q = append(q, nxt)
		}
	}
}

func swap(x, y *int) {
	*x, *y = *y, *x
}

func partition(a *[]int, l, r int) int {
	// fmt.Println("l: ", l, ", r: ", r)
	idx := r
	r--
	for l <= r {
		for l < idx && (*a)[l] <= (*a)[idx] { l++ }
		for r > l && (*a)[r] >= (*a)[idx] { r-- }
		if l >= r { break }
		swap(&((*a)[l]), &((*a)[r]))
	}
	swap(&((*a)[l]), &((*a)[idx]))
	return l
}

func kthElement(a *[]int, l, r, k int) int {
	// fmt.Println("searching ", k, "...")
	idx := -1
	for {
		idx = partition(a, l, r)
		if idx < k {
			l = idx + 1
		} else if idx > k {
			r = idx - 1
		} else { break }
	}
	return (*a)[idx]
}

func solve() {
	for i := 1; i <= k; i++ {
		bfs(i)
	}
	for i := 1; i <= n; i++ {
		kthElement(&d[i], 1, k, s)
		var ans = 0
		for j := 1; j <= s; j++ { ans += d[i][j] }
		fmt.Printf("%v ", ans)
	}
}

func main() {
	read()
	solve()
}

package main

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

const (
    maxk, maxn, inf int = 105, 1e5 + 5, 0x7fffffff
)

var (
    n, m, s, k int
    t [maxk][]int
    g, d [maxn][]int
)

func str2Ints(str string) []int {
	ret := make([]int, 0)
	str = strings.TrimSpace(str)
	// fmt.Println(strings.Split(str, " "))
	for _, item := range strings.Split(str, " ") {
		num,_ := strconv.Atoi(item)
		ret = append(ret, num)
	}
	return ret
}

func read() {
    reader := bufio.NewReader(os.Stdin)
	input,_ := reader.ReadString('\n')
	nums := str2Ints(input)
	n, m, k, s = nums[0], nums[1], nums[2], nums[3]
	// fmt.Println(n, m, k, s)

	input,_ = reader.ReadString('\n')
	nums = str2Ints(input)
	for i, item := range nums {
		t[item] = append(t[item], i + 1)
	}

	for i := 0; i < m; i++ {
		input,_ = reader.ReadString('\n')
		nums = str2Ints(input)
		st, ed := nums[0], nums[1]
		g[st] = append(g[st], ed)
		g[ed] = append(g[ed], st)
	}

	for i := 1; i <= n; i++ {
	    d[i] = append(d[i], 0)
	    for j := 1; j <= k; j++ { d[i] = append(d[i], inf) }
	}

}

func bfs(x int) {
    q := make([]int, 0)
    for _, item := range t[x] {
        q = append(q, item)
        d[item][x] = 0
    }
    for len(q) != 0 {
        hd := q[0]
        q = q[1:]
        for _, nxt := range g[hd] {
            if d[nxt][x] != inf { continue }
            d[nxt][x] = d[hd][x] + 1
            q = append(q, nxt)
        }
    }
}

func swap(x, y *int) {
	*x, *y = *y, *x
}

func partition(a *[]int, l, r int) int {
	// fmt.Println("l: ", l, ", r: ", r)
	idx := r
	r--
	for l <= r {
		for l < idx && (*a)[l] <= (*a)[idx] { l++ }
		for r > l && (*a)[r] >= (*a)[idx] { r-- }
		if l >= r { break }
		swap(&((*a)[l]), &((*a)[r]))
	}
	swap(&((*a)[l]), &((*a)[idx]))
	return l
}

func kthElement(a *[]int, l, r, k int) int {
	// fmt.Println("searching ", k, "...")
	idx := -1
	for {
		idx = partition(a, l, r)
		if idx < k {
			l = idx + 1
		} else if idx > k {
			r = idx - 1
		} else { break }
	}
	return (*a)[idx]
}

func solve() {
    for i := 1; i <= k; i++ {
        bfs(i)
    }
    for i := 1; i <= n; i++ {
        kthElement(&d[i], 1, k, s)
        var ans = 0
        for j := 1; j <= s; j++ { ans += d[i][j] }
        fmt.Printf("%v ", ans)
    }
}

func main() {
    read()
    solve()
}

package main

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

const (
	maxk, maxn, max, inf int = 105, 1e5 + 5, 1e7 + 5, 0x7fffffff
)

var (
	n, m, s, k int
	t [maxk][]int
	g, d [maxn][]int
)

func str2Ints(str string) []int {
	ret := make([]int, 0)
	str = strings.TrimSpace(str)
	// fmt.Println(strings.Split(str, " "))
	for _, item := range strings.Split(str, " ") {
		num,_ := strconv.Atoi(item)
		ret = append(ret, num)
	}
	return ret
}

func getInts() []int {
	//assumes POSITIVE INTEGERS. Check v for '-' if you have negative.
	var buf [max]byte
	os.Stdin.Read(buf[:])
	var ints []int
	num := int(0)
	found := false
	for _, v := range buf {
		if '0' <= v && v <= '9' {
			num = 10*num + int(v - '0') //could use bitshifting here.
			found = true
		} else if found {
			ints = append(ints, num)
			found = false
			num = 0
		}
	}
	if found {
		ints = append(ints, num)
		found = false
		num = 0
	}
	return ints
}

func read() {
	nums := getInts()

	n, m, k, s = nums[0], nums[1], nums[2], nums[3]
	idx := 4

	for ; idx < 4 + n; idx++ {
		t[nums[idx]] = append(t[nums[idx]], idx - 3)
	}

	for idx < 4 + n + 2 * m {
		st := nums[idx]
		idx++
		ed := nums[idx]
		idx++
		g[st] = append(g[st], ed)
		g[ed] = append(g[ed], st)
	}

	for i := 1; i <= n; i++ {
		d[i] = append(d[i], 0)
		for j := 1; j <= k; j++ { d[i] = append(d[i], inf) }
	}

}

func bfs(x int) {
	q := make([]int, 0)
	for _, item := range t[x] {
		q = append(q, item)
		d[item][x] = 0
	}
	for len(q) != 0 {
		hd := q[0]
		q = q[1:]
		for _, nxt := range g[hd] {
			if d[nxt][x] != inf { continue }
			d[nxt][x] = d[hd][x] + 1
			q = append(q, nxt)
		}
	}
}

func swap(x, y *int) {
	*x, *y = *y, *x
}

func partition(a *[]int, l, r int) int {
	// fmt.Println("l: ", l, ", r: ", r)
	idx := r
	r--
	for l <= r {
		for l < idx && (*a)[l] <= (*a)[idx] { l++ }
		for r > l && (*a)[r] >= (*a)[idx] { r-- }
		if l >= r { break }
		swap(&((*a)[l]), &((*a)[r]))
	}
	swap(&((*a)[l]), &((*a)[idx]))
	return l
}

func kthElement(a *[]int, l, r, k int) int {
	// fmt.Println("searching ", k, "...")
	idx := -1
	for {
		idx = partition(a, l, r)
		if idx < k {
			l = idx + 1
		} else if idx > k {
			r = idx - 1
		} else { break }
	}
	return (*a)[idx]
}

func solve() {
	for i := 1; i <= k; i++ {
		bfs(i)
	}
	for i := 1; i <= n; i++ {
		kthElement(&d[i], 1, k, s)
		var ans = 0
		for j := 1; j <= s; j++ { ans += d[i][j] }
		fmt.Printf("%v ", ans)
	}
}

func main() {
	read()
	solve()
}

package main

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

const (
	INF = 1234567890
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	M := io.NextInt()
	K := io.NextInt()
	S := io.NextInt()
	A := io.NextIntArrayOffset(N, 1)

	adj := make([][]int, N + 1)
	for i := 0; i < M; i++ {
		U := io.NextInt()
		V := io.NextInt()

		adj[U] = append(adj[U], V)
		adj[V] = append(adj[V], U)
	}

	count := make([]int, N + 1)
	best := make([][]int, N + 1)
	for i := 1; i <= N; i++ {
		best[i] = make([]int, K + 1)
		for j := 1; j <= K; j++ {
			best[i][j] = INF
		}
	}

	qlen := S * (N + M)
	qu := make([]int, qlen)
	qi := make([]int, qlen)
	qd := make([]int, qlen)
	idx := 0
	sz := 0
	for i := 1; i <= N; i++ {
		qu[sz] = i
		qi[sz] = A[i]
		sz++
		best[i][A[i]] = 0
		count[i]++
	}
	for idx < sz {
		u := qu[idx]
		i := qi[idx]
		d := qd[idx]
		idx++
		for _, v := range adj[u] {
			if count[v] < S && best[v][i] == INF {
				qu[sz] = v
				qi[sz] = i
				qd[sz] = d + 1
				sz++
				best[v][i] = d + 1
				count[v]++
			}
		}
	}

	for i := 1; i <= N; i++ {
		sum := 0
		for j := 1; j <= K; j++ {
			if best[i][j] != INF {
				sum += best[i][j]
			}
		}
		io.Printf("%d ", sum)
	}
	io.Println()
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func solve() {
	n := readInt()
	m := readInt()
	k := readInt()
	s := readInt()
	goods := make([][]int, n)
	for i := 0; i < n; i++ {
		value := readInt() - 1
		goods[value] = append(goods[value], i)
	}
	uv := make([][]int, n)
	for i := 0; i < len(uv); i++ {
		uv[i] = make([]int, 0)
	}
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		uv[u] = append(uv[u], v)
		uv[v] = append(uv[v], u)
	}
	cost := make([][]int, n)
	for i := 0; i < n; i++ {
		cost[i] = make([]int, k)
	}
	for j := 0; j < k; j++ {
		queue := make([]int, 0)
		ans := make([]int, n)
		for i := 0; i < n; i++ {
			ans[i] = math.MaxInt32

		}
		for i := 0; i < len(goods[j]); i++ {
			cityId := goods[j][i]
			queue = append(queue, cityId)
			ans[cityId] = 0
		}
		for len(queue) > 0 {
			curCity := queue[0]
			queue = queue[1:]
			for _, nextCity := range uv[curCity] {
				if ans[nextCity] > ans[curCity]+1 {
					queue = append(queue, nextCity)
					ans[nextCity] = ans[curCity] + 1
				}
			}
		}
		for i := 0; i < n; i++ {
			cost[i][j] = ans[i]
		}
	}
	for i := 0; i < len(cost); i++ {
		res := 0
		sort.Ints(cost[i])
		for j := 0; j < s; j++ {
			res += cost[i][j]
		}
		if i > 0 {
			fmt.Print(" ")
		}
		fmt.Print(res)
	}
	fmt.Println()
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

import (
    "fmt"
	"time"
)

const (
    maxk, maxn, inf int = 105, 1e5 + 5, 0x7fffffff
)

var (
    n, m, s, k int
    t [maxk][]int
    g, d [maxn][]int
)

func read() {
    fmt.Scanf("%d %d %d %d", &n, &m, &k, &s)
    var tmp, st, ed int
    for i := 1; i <= n; i++ {
        fmt.Scan(&tmp)
        t[tmp] = append(t[tmp], i)
    }
    for i := 0; i < m; i++ {
        fmt.Scan(&st, &ed)
        g[st] = append(g[st], ed)
        g[ed] = append(g[ed], st)
    }
    for i := 1; i <= n; i++ {
        d[i] = append(d[i], 0)
        for j := 1; j <= k; j++ { d[i] = append(d[i], inf) }
    }
}

func bfs(x int) {
    q := make([]int, 0)
    for _, item := range t[x] {
        q = append(q, item)
        d[item][x] = 0
    }
    for len(q) != 0 {
        hd := q[0]
        q = q[1:]
        for _, nxt := range g[hd] {
            if d[nxt][x] != inf { continue }
            d[nxt][x] = d[hd][x] + 1
            q = append(q, nxt)
        }
    }
}

func swap(x, y *int) {
	*x, *y = *y, *x
}

func partition(a *[]int, l, r int) int {
	idx := r
	r--
	for l <= r {
		for l < idx && (*a)[l] <= (*a)[idx] { l++ }
		for r > l && (*a)[r] >= (*a)[idx] { r-- }
		if l >= r { break }
		swap(&((*a)[l]), &((*a)[r]))
	}
	swap(&((*a)[l]), &((*a)[idx]))
	return l
}

func kthElement(a *[]int, l, r, k int) int {
	idx := -1
	for {
		idx = partition(a, l, r)
		if idx < k {
			l = idx + 1
		} else if idx > k {
			r = idx - 1
		} else { break }
	}
	return (*a)[idx]
}

func solve() {
    for i := 1; i <= k; i++ {
        bfs(i)
    }
    for i := 1; i <= n; i++ {
        kthElement(&d[i], 1, k, s)
        var ans = 0
        for j := 1; j <= s; j++ { ans += d[i][j] }
        fmt.Printf("%v ", ans)
    }
}

func main() {
	start := time.Now()
    read()
	end := time.Now()
	fmt.Println(end.Sub(start))
    solve()
}


Given $$$n$$$ strings, each of length $$$2$$$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and the $$$i$$$-th string and the $$$j$$$-th string differ in exactly one position.In other words, count the number of pairs $$$(i, j)$$$ ($$$i < j$$$) such that the $$$i$$$-th string and the $$$j$$$-th string have exactly one position $$$p$$$ ($$$1 \leq p \leq 2$$$) such that $$${s_{i}}_{p} \neq {s_{j}}_{p}$$$.The answer may not fit into 32-bit integer type, so you should use 64-bit integers like long long in C++ to avoid integer overflow.

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of strings. Then follows $$$n$$$ lines, the $$$i$$$-th of which containing a single string $$$s_i$$$ of length $$$2$$$, consisting of lowercase Latin letters from 'a' to 'k'. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print a single integer — the number of pairs $$$(i, j)$$$ ($$$i < j$$$) such that the $$$i$$$-th string and the $$$j$$$-th string have exactly one position $$$p$$$ ($$$1 \leq p \leq 2$$$) such that $$${s_{i}}_{p} \neq {s_{j}}_{p}$$$.  Please note, that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

4
6
ab
cb
db
aa
cc
ef
7
aa
bb
cc
ac
ca
bb
aa
4
kk
kk
ab
ab
5
jf
jf
jk
jk
jk

NoteFor the first test case the pairs that differ in exactly one position are: ("ab", "cb"), ("ab", "db"), ("ab", "aa"), ("cb", "db") and ("cb", "cc").For the second test case the pairs that differ in exactly one position are: ("aa", "ac"), ("aa", "ca"), ("cc", "ac"), ("cc", "ca"), ("ac", "aa") and ("ca", "aa").For the third test case, the are no pairs satisfying the conditions.

// @Title
// @Description
// @Author
// @Update
package main

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

func fun(in *bufio.Reader) {
        n := 1
        mp := make([][]int64, 12)
        for i := 0; i < 12; i++ {
                mp[i] = make([]int64, 12)
        }
        fmt.Fscan(in, &n)
        var ans int64 = 0
        for i := 0; i < n; i++ {
                s := ""
                fmt.Fscan(in, &s)
                for j := 0; j < 2; j++ {
                        for c := byte('a'); c <= byte('k'); c++ {
                                if c == s[j] {
                                        continue
                                }
                                a, b := s[0], s[1]
                                if j == 0 {
                                        a = c
                                } else {
                                        b = c
                                }
                                ans += mp[a-byte('a')][b-byte('a')]
                        }
                }
                mp[s[0]-byte('a')][s[1]-byte('a')]++
        }
        fmt.Println(ans)
}
func main() {
        t := 1
        fmt.Scan(&t)
        in := bufio.NewReader(os.Stdin)
        for i := 1; i <= t; i++ {
                fun(in)
        }

}

package main

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

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

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

	var T int
	var x string
	var n int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)

		ans := int64(0)
		cnt := map[string]int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)

			for a := byte('a'); a <= 'k'; a++ {
				if a != x[0] {
					ans += int64(cnt[string([]byte{a, x[1]})])
				}
			}
			for a := byte('a'); a <= 'k'; a++ {
				if a != x[1] {
					ans += int64(cnt[string([]byte{x[0], a})])
				}
			}

			cnt[x]++
		}

		Fprintln(out, ans)
	}
}

package main

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

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

func out(x ...interface{}) {
	fmt.Fprint(wr, x...)
}

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for Case := 1; Case <= T; Case++ {
		solve()
	}
}

func solve() {
	n := nextInt()
	mp := make(map[string]int, n)
	var res int64 = 0
	for i := 0; i < n; i++ {
		s := next()
		for i := 0; i < 26; i++ {
			if i+int('a') != int(s[0]) {
				ts := fmt.Sprintf("%c%c", (int)('a')+i,s[1])
				res+=int64(mp[ts])
			}
		}
		for i := 0; i < 26; i++ {
			if i+int('a') != int(s[1]) {
				ts := fmt.Sprintf("%c%c",s[0], (int)('a')+i)
				res+=int64(mp[ts])
			}
		}
		mp[s] ++
	}

	fmt.Printf("%d\n", res)
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		mmid := make(map[uint8]map[uint8]int)
		for i := 'a'; i <= 'k'; i++ {
			mmid[uint8(i)] = make(map[uint8]int)
		}
		var str string
		res := int64(0)

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s\n", &str)

			for k := 'a'; k <= 'k'; k++ {
				if str[0] == uint8(k) {
					continue
				}
				res += int64(mmid[uint8(k)][str[1]])
			}
			for k := 'a'; k <= 'k'; k++ {
				if str[1] == uint8(k) {
					continue
				}
				res += int64(mmid[str[0]][uint8(k)])
			}
			mmid[str[0]][str[1]]++

		}

		fmt.Fprintln(out, res)
	}
}

package main

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

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

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

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

		m := make(map[string]int64)
		for i := 0; i < n; i++ {
			var s string
			fmt.Fscan(in, &s)

			m[s]++
		}

		var tot int64
		for k, v := range m {

			for i := 0; i < 26; i++ {
				s1 := fmt.Sprintf("%c%c", k[0], i+'a')
				s2 := fmt.Sprintf("%c%c", i+'a', k[1])

				if s1 != k {
					tot += v * m[s1]
				}

				if s2 != k {
					tot += v * m[s2]
				}
			}
		}
		fmt.Fprintln(out, tot/2)
	}
}

package main

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

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

	var n int
	Fscan(in, &n)

	for ; n > 0; n-- {
		var m int
		Fscan(in, &m)
		maps := map[string]int64{}
		for ; m > 0; m-- {
			var str string
			Fscan(in, &str)
			maps[str]++
		}

		var res int64
		for str, cnt := range maps {
			if cnt == 0 {
				continue
			}
			a, b := []byte(str), []byte(str)
			for i := 0; i <= 11; i++ {
				if b[0] != byte(i+'a') {
					a[0] = (byte)(i + 'a')
					count, _ := maps[string(a)]
					if count != 0 {
						res += count * cnt
					}
				}

				if a[1] != byte(i+'a') {
					b[1] = byte(i + 'a')
					count, _ := maps[string(b)]
					if count != 0 {
						res += count * cnt
					}
				}
			}
			maps[str] = 0
		}
		Fprintln(out, res)
	}
}

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

package main

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

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

	var T, n int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &n)
		var ans int64
		var s string
		var cnt1, cnt2 [11][11]int
		var cnta, cntb [11]int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &s)
			a, b := s[0] - 'a', s[1] - 'a'
			ans += int64(cnta[a] - cnt1[a][b]) + int64(cntb[b] - cnt2[b][a])

			cnta[a]++
			cntb[b]++
			cnt1[a][b]++
			cnt2[b][a]++
			// fmt.Fprintln(out, ans)
		}
		fmt.Fprintln(out, ans)
	}
}

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

package main

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

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

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

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)

		fstore, sstore := map[uint8]int64{}, map[uint8]int64{}
		fdstore, sdstore := map[uint8]map[uint8]int64{}, map[uint8]map[uint8]int64{}
		ans := int64(0)

		for ; n > 0; n-- {
			var input string
			fmt.Fscan(in, &input)

			firstLetter, secondLetter := input[0], input[1]

			if _, ok := fdstore[firstLetter]; !ok {
				fdstore[firstLetter] = map[uint8]int64{}
			}

			if _, ok := sdstore[secondLetter]; !ok {
				sdstore[secondLetter] = map[uint8]int64{}
			}

			ans += fstore[firstLetter] - fdstore[firstLetter][secondLetter]
			fstore[firstLetter] = fstore[firstLetter] + 1
			fdstore[firstLetter][secondLetter] = fdstore[firstLetter][secondLetter] + 1

			ans += sstore[secondLetter] - sdstore[secondLetter][firstLetter]
			sstore[secondLetter] = sstore[secondLetter] + 1
			sdstore[secondLetter][firstLetter] = sdstore[secondLetter][firstLetter] + 1
		}

		fmt.Fprintln(out, ans)
	}

}

package main

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

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

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	t := nextInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	n := nextInt()

	ans := int64(0)
	memo := make([][]int, 11)
	for i := range memo {
		memo[i] = make([]int, 11)
	}

	for i := 0; i < n; i++ {
		s := next()
		s1 := int(s[0] - 'a')
		s2 := int(s[1] - 'a')

		for alp1 := 0; alp1 < 11; alp1++ {
			for alp2 := 0; alp2 < 11; alp2++ {
				if alp1 != s1 && alp2 == s2 {
					ans += int64(memo[alp1][alp2])
				}
				if alp1 == s1 && alp2 != s2 {
					ans += int64(memo[alp1][alp2])
				}
			}
		}
		memo[s1][s2]++
	}

	out(ans)
}

package main

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

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

func main(){
    var numTest int
    fmt.Fscan(reader,&numTest)

    const MAXC int = 11

    for t := 1; t <= numTest; t++ {
        var n int
        fmt.Fscan(reader,&n)

        f := make([][]int,MAXC + 1)
        for i, _ := range f {
            f[i] = make([]int,MAXC + 1)
        }

        var ans int64
        ans = 0

        for i := 1; i <= n; i++ {
            var s string
            fmt.Fscan(reader,&s)

            for p := 0; p <= 1; p++ {
                for j := 0;j < MAXC; j++ {
                    if j != int(s[p ^ 1]) - int('a') {
                        cur := int(s[p]) - int('a')
                        if p == 0 {
                            ans += int64(f[cur][j])
                        } else {
                            ans += int64(f[j][cur])
                        }
                    }
                }
            }
            f[int(s[0]) - int('a')][int(s[1]) - 'a'] += 1
        }

        fmt.Println(ans)
    }
}

package main

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

const MOD int64 = 1000000007

var n int

var str []string

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n)

		str = make([]string, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(read, &str[i])
		}

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {
	//ab
	//ac
	//aa
	//ab

	//bd
	//bc

	var cnt int64

	mp := make(map[byte][]byte)

	for i := 0; i < n; i++ {
		mp[str[i][0]] = append(mp[str[i][0]], str[i][1])
	}

	for _ ,v := range mp {
		all := int64(len(v)) * int64(len(v) - 1)/2

		mp2 := make(map[byte]int)

		for j := 0; j < len(v); j++ {
			mp2[v[j]]++
		}

		for _, v2 := range mp2 {
			tmp := int64(v2) * (int64(v2) - 1) /2

			all -= tmp
		}

		cnt += all
	}

	mp = make(map[byte][]byte)

	for i := 0; i < n; i++ {
		mp[str[i][1]] = append(mp[str[i][1]], str[i][0])
	}

	for _ ,v := range mp {
		all := int64(len(v)) * int64(len(v) - 1)/2

		mp2 := make(map[byte]int)

		for j := 0; j < len(v); j++ {
			mp2[v[j]]++
		}

		for _, v2 := range mp2 {
			tmp := int64(v2) * (int64(v2) - 1) /2

			all -= tmp
		}

		cnt += all
	}

	fmt.Println(cnt)
}

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

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n := cin.NextInt()
	cnt := make(map[string]int)
	var ans int64
	for i := 0; i < n; i++ {
		s := cin.Next()
		for t, v := range cnt {
			jm9 := 0
			if s[0] == t[0] {
				jm9++
			}
			if s[1] == t[1] {
				jm9++
			}
			if jm9 == 1 {
				ans += int64(v)
			}
		}
		cnt[s]++
	}
	cout.Println(ans)
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

func (i *scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(i.Next(), 10, 64)
	return v
}

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

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

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

	t, n := 0, 0
	Fscan(in, &t)
	for ; t > 0; t-- {
		Fscan(in, &n)
		cnt1, cnt2 := [11]uint64{}, [11]uint64{}
		vis := make(map[string]uint64)
		ans := uint64(0)
		for i := 1; i <= n; i++ {
			str := ""
			Fscan(in, &str)

			ans += cnt1[str[0]-'a'] - vis[str]
			ans += cnt2[str[1]-'a'] - vis[str]

			cnt1[str[0]-'a']++
			cnt2[str[1]-'a']++
			vis[str]++
		}
		Fprintln(out, ans)
	}
}

package main

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

/*
1
6
ab
cb
db
aa
cc
ef
---
5
=======
1
7
aa
bb
cc
ac
ca
bb
aa
---
6
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n int
	scanf("%d\n", &n)

	strToCnt := make(map[string]int)

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

		strToCnt[s]++
	}

	totalCnt := int64(0)

	strs := make([]string, 0)

	for s := range strToCnt {
		strs = append(strs, s)
	}

	for i, s1 := range strs {
		for _, s2 := range strs[i+1:] {
			if (s1[0] == s2[0] && s1[1] != s2[1]) || (s1[0] != s2[0] && s1[1] == s2[1]) {
				totalCnt += int64(strToCnt[s1]) * int64(strToCnt[s2])
			}
		}
	}

	fmt.Fprintln(writer, totalCnt)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

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

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

	return factors
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func isok(s string) bool {
	b := strings.Count(s, "B")
	rr := strings.Count(s, "R")
	if rr == 0 && b == 0 {
		return true
	} else if rr == 0 || b == 0 {
		return false
	} else {
		return true
	}
}

func slove() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	ss := make([]string, n)
	for i := range ss {
		fmt.Fscan(r, &ss[i])
	}
	pre, last := make(map[byte]int64), make(map[byte]int64)
	cnt := make(map[string]int64)
	var ans int64
	for i := range ss {
		ans += pre[ss[i][0]]
		ans += last[ss[i][1]]
		ans -= 2 * cnt[ss[i]]
		pre[ss[i][0]]++
		last[ss[i][1]]++
		cnt[ss[i]]++
	}
	fmt.Fprintln(w, ans)

}

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

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=0;i<n;i++ {
		slove()
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		m := make([]int64, 200)
		for i := 0; i < n; i++ {
			var s string
			fmt.Fscan(in, &s)
			m[(s[0]-'a')*11+s[1]-'a']++
		}
		var ans int64
		for i := 0; i < 200; i++ {
			for j := i + 1; j < 200; j++ {
				if i%11 == j%11 && i/11 != j/11 {
					ans += m[i] * m[j]
				}
				if i%11 != j%11 && i/11 == j/11 {
					ans += m[i] * m[j]
				}
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

func main_div4_784_E() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	sol = func() {
		var n int
		Fscan(in, &n)
		s := make([]string, n)
		for i := 0; i < n; i++ {
			Fscan(in, &s[i])
		}

		var solo func() int64
		solo = func() int64 {
			var ans int64
			set := make(map[byte]map[byte]int64, 0)
			for i := byte(97); i <= byte(122); i++ {
				for j := 0; j < n; j++ {
					if s[j][1] == i {
						if len(set[i]) == 0 {
							set[i] = make(map[byte]int64, 0)
						}
						set[i][s[j][0]]++
					}
				}
			}
			for i := byte(97); i <= byte(122); i++ {
				child_set := set[i]
				var total int64
				for _, v := range child_set {
					total += v
				}
				for _, v := range child_set {
					ans += v * (total - v)
				}
			}
			return ans
		}
		var res int64
		res += solo()

		for i := 0; i < n; i++ {
			tmp := []byte(s[i])
			tmp[0], tmp[1] = tmp[1], tmp[0]
			s[i] = string(tmp)
		}
		res += solo()
		Fprintln(out, res/2)
	}
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_div4_784_E()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"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(curCase int) {
		var n int
		Fscan(in, &n)
		ans := int64(0)

		cnt := map[string]int{}
		for i := 0; i < n; i++ {
			var s []byte
			Fscan(in, &s)
			for i := byte('a'); i <= 'k'; i++ {
				if s[0] != i {
					t := append([]byte{}, s...)
					t[0] = i
					ans += int64(cnt[string(t)])
				}
				if s[1] != i {
					t := append([]byte{}, s...)
					t[1] = i
					ans += int64(cnt[string(t)])
				}
			}
			cnt[string(s)]++
		}

		Fprintln(out, ans)
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

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

// @Title
// @Description
// @Author
// @Update
package main

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

func fun(in *bufio.Reader) {
        n := 1
        mp := make(map[byte]int64)
        st := make(map[string]int64)
        fmt.Fscan(in, &n)
        var ans int64 = 0
        for i := 0; i < n; i++ {
                s := ""
                fmt.Fscan(in, &s)
                t := s
                if s[0] > s[1] {
                        t = s[1:2] + s[0:1]
                }
                a, b := s[0], s[1]
                ans += mp[a] - st[s]
                if s != t {
                        ans -= st[t]
                }
                if a != b {
                        ans += mp[b] - st[s]
                        if s != t {
                                ans -= st[t]
                        }
                }
                st[s]++
                mp[a]++
                if a != b {
                        mp[b]++
                }
        }
        fmt.Println(ans)
}

func main() {
        t := 1
        fmt.Scan(&t)
        in := bufio.NewReader(os.Stdin)
        for i := 1; i <= t; i++ {
                fun(in)
        }

}

// @Title
// @Description
// @Author
// @Update
package main

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

func fun(in *bufio.Reader) {
        n := 1
        mp := make(map[byte]int64)
        st := make(map[string]int64)
        fmt.Fscan(in, &n)
        var ans int64 = 0
        for i := 0; i < n; i++ {
                s := ""
                fmt.Fscan(in, &s)
                if s[0] > s[1] {
                        t := s[1:2] + s[0:1]
                        s = t
                }
                a, b := s[0], s[1]
                ans += mp[a] - st[s]
                if a != b {
                        ans += mp[b] - st[s]
                }
                st[s]++
                mp[a]++
                if a != b {
                        mp[b]++
                }
        }
        fmt.Println(ans)
}

func main() {
        t := 1
        fmt.Scan(&t)
        in := bufio.NewReader(os.Stdin)
        for i := 1; i <= t; i++ {
                fun(in)
        }

}

package main

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

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

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

	var T int
	var x string
	var n int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)

		ans := 0
		cnt := map[string]int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)

			for a := byte('a'); a <= 'k'; a++ {
				if a != x[0] {
					ans += cnt[string([]byte{a, x[1]})]
				}
			}
			for a := byte('a'); a <= 'k'; a++ {
				if a != x[1] {
					ans += cnt[string([]byte{x[0], a})]
				}
			}

			cnt[x]++
		}

		Fprintln(out, ans)
	}
}

package main

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

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

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

	var T int
	var x string
	var n int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)

		ans := 0
		cnt := map[string]int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)

			for a := byte('a'); a <= 'z'; a++ {
				if a != x[0] {
					ans += cnt[string([]byte{a, x[1]})]
				}
			}
			for a := byte('a'); a <= 'z'; a++ {
				if a != x[1] {
					ans += cnt[string([]byte{x[0], a})]
				}
			}

			cnt[x]++
		}

		Fprintln(out, ans)
	}
}

package main

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

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

func out(x ...interface{}) {
	fmt.Fprint(wr, x...)
}

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

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	T := nextInt()
	for Case := 1; Case <= T; Case++ {
		solve()
	}
}

func solve() {
	n := nextInt()
	mp := make(map[string]int, n)
	res := 0
	for i := 0; i < n; i++ {
		s := next()
		for i := 0; i < 26; i++ {
			if i+int('a') != int(s[0]) {
				ts := fmt.Sprintf("%c%c", (int)('a')+i,s[1])
				res+=mp[ts]
			}
		}
		for i := 0; i < 26; i++ {
			if i+int('a') != int(s[1]) {
				ts := fmt.Sprintf("%c%c",s[0], (int)('a')+i)
				res+=mp[ts]
			}
		}
		mp[s] ++
	}

	fmt.Printf("%d\n", res)
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for ; t > 0; t-- {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		mmid := make(map[uint8]map[uint8]int)
		for i := 'a'; i <= 'k'; i++ {
			mmid[uint8(i)] = make(map[uint8]int)
		}
		var str string
		res := 0

		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s\n", &str)

			for k := 'a'; k <= 'k'; k++ {
				if str[0] == uint8(k) {
					continue
				}
				res += mmid[uint8(k)][str[1]]
			}
			for k := 'a'; k <= 'k'; k++ {
				if str[1] == uint8(k) {
					continue
				}
				res += mmid[str[0]][uint8(k)]
			}
			mmid[str[0]][str[1]]++

		}

		fmt.Fprintln(out, res)
	}
}

package main

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

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

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

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

		m := make(map[string]int)
		for i := 0; i < n; i++ {
			var s string
			fmt.Fscan(in, &s)

			m[s]++
		}

		var tot int
		for k, v := range m {

			for i := 0; i < 26; i++ {
				s1 := fmt.Sprintf("%c%c", k[0], i+'a')
				s2 := fmt.Sprintf("%c%c", i+'a', k[1])

				if s1 != k {
					tot += v * m[s1]
				}

				if s2 != k {
					tot += v * m[s2]
				}
			}
		}
		fmt.Fprintln(out, tot/2)
	}
}


Masha and Grisha like studying sets of positive integers.One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and j are different.Both Masha and Grisha don't like big numbers, so all numbers in A are from 1 to 106, and all numbers in B must also be in the same range.Help Masha to create the set B that satisfies Grisha's requirement.

Input data contains multiple test cases. The first line contains an integer t — the number of test cases (1 ≤ t ≤ 100). Each test case is described in the following way: the first line of the description contains one integer n — the number of elements in A (1 ≤ n ≤ 100). The second line contains n integers ai — the elements of A (1 ≤ ai ≤ 106).

For each test first print the answer:    NO, if Masha's task is impossible to solve, there is no way to create the required set B.  YES, if there is the way to create the required set. In this case the second line must contain n different positive integers bj — elements of B (1 ≤ bj ≤ 106). If there are several possible sets, output any of them.

package main

import (
	"fmt"
)

type Test856 struct {
	len    int
	values []int
}

type Result856 struct {
	answer bool
	array  []int
}

var MaximumCurrent856 = 1000000

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

	tests := []Test856{}
	for i := 0; i < n; i++ {
		var length int
		values := []int{}
		fmt.Scan(&length)
		for j := 0; j < length; j++ {
			var val int
			fmt.Scan(&val)
			values = append(values, val)
		}
		tests = append(tests, Test856{length, values})
	}
	results := Calculate856A(&tests)
	for _, n := range results {
		if !n.answer {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
			var l = len(n.array)
			for i := 0; i < l; i++ {
				fmt.Print(n.array[i])
				if i == l-1 {
					fmt.Println()
				} else {
					fmt.Print(" ")
				}
			}
		}
	}
}

func Calculate856A(tests *[]Test856) []Result856 {
	var result = []Result856{}
	for _, t := range *tests {
		var cur = 0
		var resultArray = []int{}
		var haveResult = true
		var used = make([]bool, 1000000+1)

		for len(resultArray) != t.len {
			cur += 1
			if used[cur] {
				continue
			}
			if cur > MaximumCurrent856 {
				haveResult = false
				break
			}
			used[cur] = true
			saveExcluded(&used, cur, &t)
			resultArray = append(resultArray, cur)
		}
		if haveResult {
			result = append(result, Result856{true, resultArray})
		} else {
			result = append(result, Result856{answer: false})
		}
	}
	return result
}

func saveExcluded(ex *[]bool, k int, t *Test856) {
	for i := 0; i < t.len; i++ {
		newSumm := t.values[i] + k
		for j := 0; j < t.len; j++ {
			excluded := newSumm - t.values[j]
			if excluded > 0 {
				(*ex)[excluded] = true
			}
		}
	}
}

package main

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

type Test856 struct {
	len    int
	values []int
}

type Result856 struct {
	answer bool
	array  []int
}

var MaximumCurrent856 = 1000000

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

	tests := []Test856{}
	for i := 0; i < n; i++ {
		var length int
		values := []int{}
		fmt.Scan(&length)
		for j := 0; j < length; j++ {
			var val int
			fmt.Scan(&val)
			values = append(values, val)
		}
		tests = append(tests, Test856{length, values})
	}
	results := Calculate856A(&tests)
	for _, n := range results {
		if !n.answer {
			fmt.Println(n.answer)
		} else {
			fmt.Println(n.answer)
			fmt.Println(strings.Join(intToStringArray(&n.array), " "))
		}
	}
}

func Calculate856A(tests *[]Test856) []Result856 {
	var result = []Result856{}
	for _, t := range *tests {
		var cur = 0
		var resultArray = []int{}
		var haveResult = true
		var used = map[int]bool{}

		for len(resultArray) != t.len {
			cur += 1
			if cur > MaximumCurrent856 {
				haveResult = false
				break
			}
			newArray := newSummArray(cur, &t)
			if !hasCollision(&used, &newArray) {
				saveUsedArray(&used, &newArray)
				resultArray = append(resultArray, cur)
			}
		}
		if haveResult {
			result = append(result, Result856{true, resultArray})
		} else {
			result = append(result, Result856{answer: false})
		}
	}
	return result
}

func newSummArray(k int, t *Test856) []int {
	var summ = []int{}
	for i := 0; i < t.len; i++ {
		summ = append(summ, t.values[i]+k)
	}
	return summ
}

func saveUsedArray(m *map[int]bool, arr *[]int) {
	for _, n := range *arr {
		(*m)[n] = true
	}
}

func hasCollision(m *map[int]bool, what *[]int) bool {
	for i := 0; i < len(*what); i++ {
		if _, ok := (*m)[(*what)[i]]; ok {
			return true
		}
	}
	return false
}

func intToStringArray(a *[]int) []string {
	b := make([]string, len(*a))
	for i, v := range *a {
		b[i] = strconv.Itoa(v)
	}

	return b
}


It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can carry only one bottle at once each. For both Adil and Bera the process looks as follows:   Choose to stop or to continue to collect bottles.  If the choice was to continue then choose some bottle and walk towards it.  Pick this bottle and walk to the recycling bin.  Go to step 1. Adil and Bera may move independently. They are allowed to pick bottles simultaneously, all bottles may be picked by any of the two, it's allowed that one of them stays still while the other one continues to pick bottles.They want to organize the process such that the total distance they walk (the sum of distance walked by Adil and distance walked by Bera) is minimum possible. Of course, at the end all bottles should lie in the recycling bin.

First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively. The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground. Then follow n lines, each of them contains two integers xi and yi (0 ≤ xi, yi ≤ 109) — position of the i-th bottle. It's guaranteed that positions of Adil, Bera, recycling bin and all bottles are distinct.

Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct if .

NoteConsider the first sample.Adil will use the following path: .Bera will use the following path: .Adil's path will be  units long, while Bera's path will be  units long.

package main

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

type vec struct {
	x, y int
}

func (a vec) sub(b vec) vec { return vec{a.x - b.x, a.y - b.y} }
func (a vec) len() float64  { return math.Hypot(float64(a.x), float64(a.y)) }

// github.com/EndlessCheng/codeforces-go
func Sol671A(reader io.Reader, writer io.Writer) {
	type pair struct {
		d   float64
		idx int
	}
	read := func(in io.Reader) vec {
		var x, y int
		Fscan(in, &x, &y)
		return vec{x, y}
	}
	max := func(a, b float64) float64 {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	pa, pb, bin := read(in), read(in), read(in)
	pa = pa.sub(bin)
	pb = pb.sub(bin)
	var n int
	Fscan(in, &n)
	das := make([]pair, n)
	dbs := make([]pair, n)
	ans := 0.0
	for i := range das {
		p := read(in).sub(bin)
		lenP := p.len()
		ans += lenP
		das[i] = pair{lenP - p.sub(pa).len(), i}
		dbs[i] = pair{lenP - p.sub(pb).len(), i}
	}
	ans *= 2

	sort.Slice(das, func(i, j int) bool { return das[i].d > das[j].d })
	sort.Slice(dbs, func(i, j int) bool { return dbs[i].d > dbs[j].d })
	if n == 1 || das[0].d <= 0 || dbs[0].d <= 0 {
		ans -= max(das[0].d, dbs[0].d)
	} else if das[0].idx == dbs[0].idx {
		sum1 := das[0].d
		sum2 := dbs[0].d
		if dbs[1].d > 0 {
			sum1 += dbs[1].d
		}
		if das[1].d > 0 {
			sum2 += das[1].d
		}
		ans -= max(sum1, sum2)
	} else {
		ans -= das[0].d + dbs[0].d
	}
	Fprintf(out, "%.12f", ans)
}

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

package main

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

func sqr(a int) int64 {
	return int64(a) * int64(a)
}
func dist(ax, ay, bx, by int) float64 {
	return math.Sqrt(float64(sqr(ax-bx) + sqr(ay-by)))
}

const Inf = 1000000001

func main() {
	ax, ay, bx, by, tx, ty, n := getInt(), getInt(), getInt(), getInt(), getInt(), getInt(), getInt()

	var dsum float64
	const ival = -4.0 * Inf * Inf
	var ansa, ansb struct {
		best, next float64
		idx        int
	}
	ansa.best, ansa.next, ansb.best, ansb.next = ival, ival, ival, ival

	for i := 0; i < n; i++ {
		px, py := getInt(), getInt()
		t := dist(tx, ty, px, py)
		a := t - dist(ax, ay, px, py)
		b := t - dist(bx, by, px, py)
		dsum += t

		if a > ansa.best {
			ansa.next = ansa.best
			ansa.best = a
			ansa.idx = i
		} else if a > ansa.next {
			ansa.next = a
		}
		if b > ansb.best {
			ansb.next = ansb.best
			ansb.best = b
			ansb.idx = i
		} else if b > ansb.next {
			ansb.next = b
		}
	}
	dsum *= 2

	a, b := ansa.best, ansb.best
	ans := math.Max(a, b) // only one

	// two
	if ansa.idx != ansb.idx {
		ans = math.Max(ans, a+b)
	} else {
		ans = math.Max(ans, math.Max(a+ansb.next, b+ansa.next))
	}

	fmt.Printf("%.7f\n", dsum-ans)
}

type Input struct {
	*bufio.Scanner
}

var globalInput = wrapStdin()

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func getWord() string {
	globalInput.Scan()
	return globalInput.Text()
}
func getInt() int {
	globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x
}
func getIntOk() (int, bool) {
	ok := globalInput.Scan()
	x, _ := strconv.Atoi(globalInput.Text())
	return x, ok
}
func getNint(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getInt()
	}
	return v
}
func getVint(v []int) bool {
	var ok bool
	for i := 0; i < len(v); i++ {
		v[i], ok = getIntOk()
	}
	return ok
}

package main

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

type point struct {
	x, y float64
}

func dist(a, b point) float64 {
	dx := a.x - b.x
	dy := a.y - b.y
	return math.Sqrt(dx*dx + dy*dy)
}

func main() {
	in := bufio.NewReaderSize(os.Stdin, 2<<16)
	var a, b, t point
	var n int
	fmt.Fscan(in, &a.x, &a.y, &b.x, &b.y, &t.x, &t.y, &n)
	bottles := make([]point, n)
	sum := 0.
	type best struct {
		i   int
		win float64
	}
	update := func(b *[]best, i int, p point) {
		win := dist(bottles[i], t) - dist(bottles[i], p)
		if len(*b) == 0 || (len(*b) == 1 && (*b)[0].win > win) {
			*b = append(*b, best{i, win})
		} else if len(*b) == 1 {
			*b = []best{{i, win}, (*b)[0]}
		} else if win > (*b)[0].win {
			(*b)[1] = (*b)[0]
			(*b)[0] = best{i, win}
		} else if win > (*b)[1].win {
			(*b)[1] = best{i, win}
		}
	}
	var bestA, bestB []best
	for i := range bottles {
		fmt.Fscan(in, &bottles[i].x, &bottles[i].y)
		sum += dist(bottles[i], t)
		update(&bestA, i, a)
		update(&bestB, i, b)
	}

	var wins []float64
	if bestA[0].i == bestB[0].i {
		wins = []float64{bestA[0].win, bestB[0].win}
		if n > 1 {
			wins = append(wins, bestA[0].win+bestB[1].win, bestA[1].win+bestB[0].win)
		}
	} else {
		wins = []float64{bestA[0].win, bestB[0].win, bestA[0].win + bestB[0].win}
	}
	sort.Float64s(wins)

	ans := sum*2 - wins[len(wins)-1]
	fmt.Println(ans)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	for _, b := range in.Bytes() {
		res = res*10 + int64(b-'0')
	}
	return res
}

func dist(ax, ay, bx, by int64) float64 {
	dx := ax - bx
	dy := ay - by
	return math.Sqrt(float64(dx*dx + dy*dy))
}

func main() {
	in.Split(bufio.ScanWords)

	ax := readInt()
	ay := readInt()
	bx := readInt()
	by := readInt()
	tx := readInt()
	ty := readInt()

	ans := 0.
	winA := float64(-1e15)
	winA2 := float64(-1e15)
	winB := float64(-1e15)
	winB2 := float64(-1e15)
	for n := readInt(); n > 0; n-- {
		x := readInt()
		y := readInt()
		d := dist(x, y, tx, ty)
		ans += 2 * d
		wa := d - dist(x, y, ax, ay)
		wb := d - dist(x, y, bx, by)
		if wa > wb {
			if winA < wa {
				winA = wa
				if winB < winB2 {
					winB = winB2
				}
				winB2 = wb
			} else {
				if winB < wb {
					winB = wb
				}
			}
		} else {
			if winB < wb {
				winB = wb
				if winA < winA2 {
					winA = winA2
				}
				winA2 = wa
			} else {
				if winA < wa {
					winA = wa
				}
			}
		}
	}

	if winA > winB {
		winA, winB = winB, winA
	}

	ans -= winB
	if winA > 0 {
		ans -= winA
	}
	fmt.Printf("%.12f", ans)
}


Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9.For instance, Inna can alter number 14545181 like this: 14545181 → 1945181 → 194519 → 19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine.Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task.

The first line of the input contains integer a (1 ≤ a ≤ 10100000). Number a doesn't have any zeroes.

In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263 - 1. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteNotes to the samplesIn the first sample Inna can get the following numbers: 369727 → 99727 → 9997, 369727 → 99727 → 9979.In the second sample, Inna can act like this: 123456789987654321 → 12396789987654321 → 1239678998769321.

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var s string
	var cnt, res int64 = 1, 1
	fmt.Fscan(reader, &s)
	var n int = len(s)
	for i := 1; i < n; i++ {
		if s[i] + s[i - 1] - 2 * '0' == 9 {
			cnt++
		} else {
			if cnt % 2 == 1 {
				res *= cnt / 2 + 1
			}
			cnt = 1
		}
	}
	if cnt % 2 == 1 {
		res *= cnt / 2 + 1
	}
	fmt.Fprintln(writer, res)
}//2020-07-30 23:02:49.469

// Codeforces 374 B Inna nad Nine, train
package main

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

var in *bufio.Reader

func readFive() (int, int, int, int, int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i := 0; i < len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0], a[1], a[2], a[3], a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j := 0; j < n; j++ {
		aa, err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var a string
var ans int64

// readData read data for out problem.
func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading string a
	a,_ = in.ReadString('\n')
}

// solve func solves our problem.
func solve() {
	var n90,nw0 int64
	var n91,nw1 int64
	nw0 = 1
	nw1 = 1
	for i:=1; i<len(a)-1; i++ {
		n92 := n91
		nw2 := nw1
		sm := ((a[i-1]-'0') + (a[i]-'0'))
		if sm==9 {
			n92 = n90+1
			//fmt.Printf("n92,n91 = %d %d\n", n92,n91)
			if n92==n91 {
				nw2 = nw1 + nw0
			} else {
				nw2 = nw0
			}
		}
		//fmt.Printf("i,ai,sm %d %d %d 09w_ %d %d 1_ %d %d N_ %d %d\n",
		//	i,a[i],sm,n90,nw0,n91,nw1,n92,nw2)
		n90 = n91; nw0 = nw1
		n91 = n92; nw1 = nw2;
	}
	ans = nw1
}

// printRes print problem solution in expected format.
func printRes() {
	fmt.Println(ans)
}

func main() {
	readData()
	solve()
	printRes()
}


Everyone knows that agents in Valorant decide, who will play as attackers, and who will play as defenders. To do that Raze and Breach decided to play $$$t$$$ matches of a digit game...In each of $$$t$$$ matches of the digit game, a positive integer is generated. It consists of $$$n$$$ digits. The digits of this integer are numerated from $$$1$$$ to $$$n$$$ from the highest-order digit to the lowest-order digit. After this integer is announced, the match starts.Agents play in turns. Raze starts. In one turn an agent can choose any unmarked digit and mark it. Raze can choose digits on odd positions, but can not choose digits on even positions. Breach can choose digits on even positions, but can not choose digits on odd positions. The match ends, when there is only one unmarked digit left. If the single last digit is odd, then Raze wins, else Breach wins.It can be proved, that before the end of the match (for every initial integer with $$$n$$$ digits) each agent has an ability to make a turn, i.e. there is at least one unmarked digit, that stands on a position of required parity.For each of $$$t$$$ matches find out, which agent wins, if both of them want to win and play optimally.

First line of input contains an integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of matches. The first line of each match description contains an integer $$$n$$$ $$$(1 \le n \le 10^3)$$$  — the number of digits of the generated number. The second line of each match description contains an $$$n$$$-digit positive integer without leading zeros.

For each match print $$$1$$$, if Raze wins, and $$$2$$$, if Breach wins.

NoteIn the first match no one can make a turn, the only digit left is $$$2$$$, it's even, so Breach wins.In the second match the only digit left is $$$3$$$, it's odd, so Raze wins.In the third match Raze can mark the last digit, after that Breach can only mark $$$0$$$. $$$1$$$ will be the last digit left, it's odd, so Raze wins.In the fourth match no matter how Raze plays, Breach can mark $$$9$$$, and in the end there will be digit $$$0$$$. It's even, so Breach wins.

package main

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

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

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

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

var err error

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

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

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

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

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

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

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

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

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

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

const mod = 998244353

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

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

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

func pow(a, b int64) int64 {
	if b == 0 {
		return 1
	}
	res := pow(a, b>>1)
	res = Mult(res, res)
	if b&1 == 1 {
		res = Mult(res, a)
	}
	return res
}

var (
	fact, inv []int64
)

func choose(a, b int) int64 {
	if b < 0 || b > a {
		return 0
	}
	return Mult(fact[a], Mult(inv[b], inv[a-b]))
}

func solve() {
	n := nextInt()
	arr := []byte(next())
	if n%2 == 0 {
		for i := 1; i < n; i += 2 {
			if (arr[i]-'0')%2 == 0 {
				printf("2\n")
				return
			}
		}
		printf("1\n")
		return
	} else {
		for i := 0; i < n; i += 2 {
			if (arr[i]-'0')%2 == 1 {
				printf("1\n")
				return
			}
		}
		printf("2\n")
		return
	}
}

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

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

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

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		s, _ := reader.ReadString('\n')
		res := solve(n, s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

const RAZE = 1
const BREACH = 2

func solve(n int, s string) int {
	var cnt1, cnt2 int

	for i := 0; i < n; i++ {
		x := int(s[i] - '0')
		if i&1 == 0 {
			// (i+1)odd position
			cnt1 += x & 1
		} else {
			// even position
			if x&1 == 0 {
				cnt2++
			}
		}
	}

	if n&1 == 1 {
		if cnt1 > 0 {
			return RAZE
		}
		return BREACH
	}
	// n & 2 == 0
	if cnt2 > 0 {
		return BREACH
	}
	return RAZE
}

package main

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

var reader = bufio.NewReader(os.Stdin)  //use fmt.Fscan
var writer = bufio.NewWriter(os.Stdout) //use fmt.Fprintln

func solve() {
	//solution here
	var n int
	var s string
	fmt.Fscan(reader, &n, &s)
	var hasFirstOdd, hasSecondEven bool
	for k, v := range s {
		if k%2 == 0 {
			if v%2 == 1 {
				hasFirstOdd = true
			}
		} else {
			if v%2 == 0 {
				hasSecondEven = true
			}
		}
	}
	if n%2 == 0 {
		//last goes second
		if hasSecondEven {
			fmt.Fprintln(writer, 2)
		} else {
			fmt.Fprintln(writer, 1)
		}
	} else {
		//last goes first
		if hasFirstOdd {
			fmt.Fprintln(writer, 1)
		} else {
			fmt.Fprintln(writer, 2)
		}
	}
}

func main() {
	var t int
	fmt.Fscan(reader, &t)
	defer writer.Flush()
	for t > 0 {
		solve()
		t--
	}
}

package main

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

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

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var num string
		scan(&num)
//		if n== 1 {
//			if num % 10 == 1 {
//				print(1, "\n")
//			}else{
//				print(2, "\n")
//			}
//		}else
		if n % 2 == 0 {
			var b = false
			for i := 0; i < n; i += 2  {
				if int(num[n-i-1] - '0') % 2 == 0 {
					b = true
					break
				}
			}
			if b {
				print(2, "\n")
			}else{
				print(1, "\n")
			}
		}else{
			var b = false
			for i := 0; i < n; i += 2  {
				if int(num[n-i-1] - '0') % 2 == 1 {
					b = true
					break
				}
			}
			if b {
				print(1, "\n")
			}else{
				print(2, "\n")
			}
		}
	}
}

package main

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

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

func main() {
	defer rw.Flush()
	for tt := rw.NextInt(); tt > 0; tt-- {
		n := rw.NextInt()
		a := rw.Next()
		var win int
		if n%2 == 0 {
			win = 1
			for i := 1; i < n; i += 2 {
				if a[i]%2 == 0 {
					win = 2
				}
			}
		} else {
			win = 2
			for i := 0; i < n; i += 2 {
				if a[i]%2 == 1 {
					win = 1
				}
			}
		}
		rw.Println(win)
	}
}

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

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

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

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

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

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

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

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

package main

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

type game struct {
	oddCount, evenCount int
}

func solve(r *bufio.Reader, w *bufio.Writer) {
	var n int
	fmt.Fscanln(r, &n)
	var dinput string
	fmt.Fscanln(r, &dinput)
	digits := make([]int, n)
	var rg, bg game
	for i := 0; i < n; i++ {
		digits[i] = int(dinput[i]) - 48
		if (i+1)%2 == 0 {
			if digits[i]%2 == 0 {
				bg.evenCount += 1
			} else {
				bg.oddCount += 1
			}
		} else {
			if digits[i]%2 == 0 {
				rg.evenCount += 1
			} else {
				rg.oddCount += 1
			}
		}
	}
	for i := 0; i < n-1; i++ {
		if (i+1)%2 == 1 {
			if rg.evenCount > 0 {
				rg.evenCount -= 1
			} else {
				rg.oddCount -= 1
			}
		} else {
			if bg.oddCount > 0 {
				bg.oddCount -= 1
			} else {
				bg.evenCount -= 1
			}
		}
	}
	var ans int
	if n%2 == 1 {
		if rg.evenCount > 0 {
			ans = 2
		} else {
			ans = 1
		}
	} else {
		if bg.oddCount > 0 {
			ans = 1
		} else {
			ans = 2
		}
	}
	fmt.Fprintln(w, ans)
}

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

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

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

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t >0; t-- {
		n := sint64()
		s := sstring()
		printf("%d\n", sol(n, s))
	}
}

func sol(n int64, s string) int64 {
	if n & 1 == 1 {
		// raze makes last move
		for i := range s {
			if i & 1 == 0 {
				d := s[i] - '0'
				// if digit is odd, raze wins
				if d & 1 == 1 {
					return 1
				}
			}
		}
		return 2
	}
	// breach makes last move
	for i := range s {
		if i & 1 == 1 {
			d := s[i] - '0'
			// if digit is even, breach wins
			if d & 1 == 0 {
				return 2
			}
		}
	}
	return 1
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		s, _ := reader.ReadString('\n')
		res := solve(n, s)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

const RAZE = 1
const BREACH = 2

func solve(n int, s string) int {
	var cnt1, cnt2 int

	for i := 0; i < n; i++ {
		x := int(s[i] - '0')
		if i&1 == 0 {
			// (i+1)odd position
			cnt1 += x & 1
		} else {
			// even position
			if x&1 == 0 {
				cnt2++
			}
		}
	}

	if n&1 == 1 {
		if cnt1 > 0 {
			return RAZE
		}
		return BREACH
	}
	// n & 2 == 0
	if cnt1 > cnt2 {
		return RAZE
	}
	return BREACH
}

package main

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

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

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var num string
		scan(&num)
//		if n== 1 {
//			if num % 10 == 1 {
//				print(1, "\n")
//			}else{
//				print(2, "\n")
//			}
//		}else
		if n % 2 == 0 {
			var b = false
			for i := 0; i < n; i += 2  {
				if int(num[i] - '0') % 2 == 0 {
					b = true
					break
				}
			}
			if b {
				print(2, "\n")
			}else{
				print(1, "\n")
			}
		}else{
			var b = false
			for i := 0; i < n; i += 2  {
				if int(num[i] - '0') % 2 == 1 {
					b = true
					break
				}
			}
			if b {
				print(1, "\n")
			}else{
				print(2, "\n")
			}
		}
	}
}

package main

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

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

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var num int
		scan(&num)
//		if n== 1 {
//			if num % 10 == 1 {
//				print(1, "\n")
//			}else{
//				print(2, "\n")
//			}
//		}else
		if n % 2 == 0 {
			var b = false
			for ; num > 0; num = num / 100  {
				if num % 2 == 0 {
					b = true
					break
				}
			}
			if b {
				print(2, "\n")
			}else{
				print(1, "\n")
			}
		}else{
			var b = false
			for ; num > 0; num = num / 100 {
				if num % 2 == 1 {
					b = true
					break
				}
			}
			if b {
				print(1, "\n")
			}else{
				print(2, "\n")
			}
		}
	}
}