You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length $$$n$$$, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move any sheep one square to the left or one square to the right, if the corresponding square exists and is empty. The game ends as soon as the sheep are lined up, that is, there should be no empty cells between any sheep.For example, if $$$n=6$$$ and the level is described by the string "**.*..", then the following game scenario is possible:   the sheep at the $$$4$$$ position moves to the right, the state of the level: "**..*.";  the sheep at the $$$2$$$ position moves to the right, the state of the level: "*.*.*.";  the sheep at the $$$1$$$ position moves to the right, the state of the level: ".**.*.";  the sheep at the $$$3$$$ position moves to the right, the state of the level: ".*.**.";  the sheep at the $$$2$$$ position moves to the right, the state of the level: "..***.";  the sheep are lined up and the game ends. For a given level, determine the minimum number of moves you need to make to complete the level.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^6$$$). The second line of each test case contains a string of length $$$n$$$, consisting of the characters '.' (empty space) and '*' (sheep) — the description of the level. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$.

For each test case output the minimum number of moves you need to make to complete the level.

package main

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

func ReadInt() int {
	var i int
	_, err := fmt.Scanf("%d", &i)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadByte() byte {
	return ReadBytes(1)[0]
}

func ReadNL() byte {
	var nl byte
	for nl != 0x0a {
		nl = ReadByte()
	}
	return nl
}

func ReadBytes(n int) []byte {
	p := make([]byte, n)
	_, err := io.ReadFull(os.Stdin, p)
	if err != nil {
		panic(err)
	}
	return p
}

func main() {
	total := ReadInt()
	for i := 0; i < total; i++ {
		ReadNL()
		l := ReadInt()
		ReadNL()
		line := ReadBytes(l)
		var sheeps int
		for _, s := range line {
			if s == 42 {
				sheeps += 1
			}
		}
		var sum int
		var median int
		for i, s := range line {
			if s == 42 {
				if sum >= sheeps/2 {
					median = i
					break
				} else {
					sum++
				}
			}
		}

		var total int64

		var beg int
		var end int

		for i, s := range line {
			if s == 42 {
				if i < median {
					total += int64(median - i)
					total -= int64(sum - beg)
					beg++
				} else if i > median {
					total += int64(i - median)
					total -= int64(end + 1)
					end++
				}
			}
		}

		fmt.Println(total)

	}
}

package main

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

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

	var t, n int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		sheepCnt := 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				sheepCnt++
			}
		}
		if sheepCnt == 0 || sheepCnt == n {
			fmt.Println(0)
		} else {
			cnt := calc(s, (sheepCnt+1)/2)
			if sheepCnt%2 == 0 {
				cnt2 := calc(s, sheepCnt/2+1)
				if cnt2 < cnt {
					cnt = cnt2
				}
			}
			fmt.Println(cnt)
		}
	}
}

func calc(s string, centerSheep int) int64 {
	var center int
	for i, j := 0, 0; i < len(s) && j < centerSheep; i++ {
		if s[i] == '*' {
			j++
			center = i
		}
	}
	var cnt int64
	for i, j := 0, 0; i < len(s); i++ {
		if s[i] == '*' {
			j++
			cnt += abs(center + (j - centerSheep) - i)
		}
	}
	return cnt
}

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

package main

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

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

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

	for k := 0; k < t; k++ {
		var n int
		var cc string
		fmt.Fscanln(in, &n)
		fmt.Fscanf(in, "%s\n", &cc)

		arr := make([]bool, n)

		for i, c := range cc {
			if c == '*' {
				arr[i] = true
			}
		}

		prefixCnt := make([]int64, n)
		prefixSum := make([]int64, n)

		if arr[0] == true {
			prefixCnt[0] = 1
		}

		for i := 1; i < n; i++ {
			prefixCnt[i] = prefixCnt[i-1]
			prefixSum[i] = prefixSum[i-1]
			if arr[i] == true {
				prefixCnt[i]++
			} else {
				prefixSum[i] += prefixCnt[i-1]
			}
		}

		suffixCnt := make([]int64, n)
		suffixSum := make([]int64, n)

		if arr[n-1] == true {
			suffixCnt[n-1] = 1
		}

		for i := n - 2; i >= 0; i-- {
			suffixCnt[i] = suffixCnt[i+1]
			suffixSum[i] = suffixSum[i+1]
			if arr[i] == true {
				suffixCnt[i]++
			} else {
				suffixSum[i] += suffixCnt[i+1]
			}
		}

		ans := float64(suffixSum[0])

		for i := 1; i < n; i++ {
			version := prefixSum[i-1] + suffixSum[i]
			ans = math.Min(ans, float64(version))
		}

		ans = math.Min(ans, float64(prefixSum[n-1]))

		fmt.Println(int64(ans))
	}
}

package main

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

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

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

		var positions []int
		for i, c := range s {
			if c == '*' {
				positions = append(positions, i)
			}
		}

		mid := len(positions) / 2
		ans := int64(0)
		for i, val := range positions {
			ans += int64(abs(positions[mid] - val) - abs(mid - i))
		}
		Fprintln(out, ans)
	}
}

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

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

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
}

package main

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

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

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

		empty, vec := 0, []int{}
		for _, c := range s {
			if c == '.' {
				empty++
			} else {
				vec = append(vec, empty)
			}
		}

		mid := (len(vec)  - 1) / 2
		var ans int64
		for _, val := range vec {
			ans += int64(abs(val - vec[mid]))
		}
		Fprintln(out, ans)
	}
}

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

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

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
}

package main

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

const (
	MOD int = int(1e9 + 7)
)

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

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

	for q := 0; q < t; q++ {
		var l int
		fmt.Fscan(_r, &l)
		var line []byte
		var sheep []int
		var numSheep int = 0
		fmt.Fscan(_r, &line)
		for i := 0; i < l; i++ {
			if line[i] == '*' {
				sheep = append(sheep, i-numSheep)
				numSheep++
			}
		}

		var ans int64 = 0

		if numSheep != 0 {
			mean := sheep[numSheep/2]
			for i := 0; i < numSheep; i++ {
				ans += int64(AbsInt(sheep[i] - mean))
			}
		}

		fmt.Fprintf(_w, "%d\n", ans)
	}
}

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

package main

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

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

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

func min_moves(str string) int64 {
    var sheep_num int64 = 0
    for _, c := range str {
        if c == '*' {
            sheep_num++
        }
    }
    var sheeps_num_left int64 = 0
    var ans int64 = 0
    for _, c := range str {
        if c == '*' {
            sheeps_num_left++
        } else {
            ans += min64(sheeps_num_left, sheep_num - sheeps_num_left)
        }
    }
    return ans
}

func main() {
    defer writer.Flush()

    var n_tasks int
    scan(&n_tasks)
    for i := 0; i < n_tasks; i++ {
        var strlen int
        scan(&strlen)
        var str string
        scan(&str)
        printf("%d\n", min_moves(str))
    }
}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanString(s *string) { fmt.Fscanln(reader, s) }

var arr [200007]int

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

// return 1 + ... + x
func pa(x int) int64 {
	return int64(x) * (int64(x) + 1)/2
}

func test_case() {
	var n int
	var str string

	scanf("%d\n", &n)
	scanString(&str)

	cnt := 0
	for i := 0; i < n; i++ {
		if str[i] == '*' {
			cnt++
		}
	}

	pos := -1
	cur := 0
	for i := 0; i < n; i++ {
		if str[i] == '*' {
			cur++
			if 2 * cur >= cnt {
				pos = i
				break
			}
		}
	}

	if pos == -1 {
		println(0)
		return
	}

	var tot int64 = 0
	for i := 0; i < n; i++ {
		if str[i] == '*' {
			tot += int64(abs(pos - i))
		}
	}

	if cnt%2 == 1 {
		tot -= 2 * pa(cnt/2)
	} else {
		tot -= pa(cnt/2) + pa(cnt/2 - 1)
	}

	println(tot)
}

func main() {
	defer writer.Flush()
	var t int

	scanf("%d\n", &t)
	for t > 0 {
		test_case()
		t--
	}

}

package main

import (
	"bufio"
	"fmt"
	"math"

	//"math"
	"os"
	"strconv"
	//"strings"
)

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(pk)
	for oi := 0; oi < k; oi++ {
		_, err := Readln(reader)
		if err != nil {
			return
		}
		//n, _ := strconv.Atoi(pfl)
		psl,_ :=Readln(reader)
		sheep := make([] int, 0)
		for i:= range psl {
			if psl[i] == '*' {
				sheep = append(sheep, i)
			}
		}
		if len(sheep) < 2 {
			fmt.Println(0)
			continue
		}
		// The median sheep would not make moves?

		median := int(math.Floor(float64(len(sheep))/float64(2)))
		//fmt.Println(median)
		//fmt.Println(sheep)
		res := int64(0)
		for i,v:= range sheep {
			t := int64(v - sheep[median] + median - i)
			if t>0{

				res+=t
			} else  {
				res-=t
			}
		}
		fmt.Println(res)

	}

}

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanString(s *string)              { fmt.Fscanln(reader, s) }

func abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}
func pa(x int) int64 {
	return int64(x) * (int64(x) + 1) / 2
}
func test_case() {
	var n int
	var str string
	scanf("%d\n", &n)
	scanf("%s\n", &str)
	cnt := 0
	for _, x := range str {
		if x == '*' {
			cnt++
		}
	}
	pos := -1
	cur := 0
	for i, x := range str {
		if x == '*' {
			cur++
			if 2*cur >= cnt {
				pos = i
				break
			}
		}
	}
	if pos == -1 {
		println(0)
		return
	}

	var ans int64 = 0
	for i := 0; i < n; i++ {
		if str[i] == '*' {
			ans += int64(abs(i - pos))
		}
	}
	if cnt%2 == 1 {
		ans -= 2 * pa(cnt/2)
	} else {
		ans -= pa(cnt/2) + pa(cnt/2-1)
	}
	println(ans)
}
func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for t > 0 {
		test_case()
		t--
	}
}

package main

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

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

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

	var t int

	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		var n int
		var s string
		fmt.Fscanf(reader, "%d\n%s\n", &n, &s)

		var ans, cur, sum int64

		for i := 0; i < n; i++ {
			if s[i] == '*' {
				sum++
			}
		}

		for i := 0; i < n; i++ {
			if s[i] == '*' {
				cur++
			} else {
				ans += min(cur, sum-cur)
			}
		}

		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"bytes"
	. "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(Case int) {
		var n int
		var s []byte
		Fscan(in, &n, &s)
		c := bytes.Count(s, []byte{'*'})
		if c <= 1 {
			Fprintln(out, 0)
			return
		}
		mid := 0
		tmp := 0
		for i, b := range s {
			if b == '*' {
				tmp++
				if tmp == (c+1)/2 {
					mid = i
					break
				}
			}
		}
		cc := 0
		ans := int64(0)
		for i := mid-1; i >= 0; i-- {
			if s[i] == '.' {
				cc++
			} else {
				ans+=int64(cc)
			}
		}
		cc=0
		for i := mid+1; i <n; i++ {
			if s[i] == '.' {
				cc++
			} else {
				ans+=int64(cc)
			}
		}
		Fprintln(out, ans)
	}

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

package main

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

func ReadInt() int {
	var i int
	_, err := fmt.Scanf("%d", &i)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadByte() byte {
	return ReadBytes(1)[0]
}

func ReadNL() byte {
	var nl byte
	for nl != 0x0a {
		nl = ReadByte()
	}
	return nl
}

func ReadBytes(n int) []byte {
	p := make([]byte, n)
	_, err := io.ReadFull(os.Stdin, p)
	if err != nil {
		panic(err)
	}
	return p
}

func main() {
	total := ReadInt()
	for i := 0; i < total; i++ {
		ReadNL()
		l := ReadInt()
		ReadNL()
		line := ReadBytes(l)
		var sheeps int
		for _, s := range line {
			if s == 42 {
				sheeps += 1
			}
		}
		var sum int
		var median int
		for i, s := range line {
			if s == 42 {
				if sum >= sheeps/2 {
					median = i
					break
				} else {
					sum++
				}
			}
		}

		var total int

		var beg int
		var end int

		for i, s := range line {
			if s == 42 {
				if i < median {
					total += median - i
					total -= sum - beg
					beg++
				} else if i > median {
					total += i - median
					total -= end + 1
					end++
				}
			}
		}

		fmt.Println(total)

	}
}

package main

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

func ReadInt() int {
	var i int
	_, err := fmt.Scanf("%d", &i)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadByte() byte {
	return ReadBytes(1)[0]
}

func ReadNL() byte {
	var nl byte
	for nl != 0x0a {
		nl = ReadByte()
	}
	return nl
}

func ReadBytes(n int) []byte {
	p := make([]byte, n)
	_, err := io.ReadFull(os.Stdin, p)
	if err != nil {
		panic(err)
	}
	return p
}

func main() {
	total := ReadInt()
	for i := 0; i < total; i++ {
		ReadNL()
		l := ReadInt()
		ReadNL()
		line := ReadBytes(l)
		var sheeps int
		for _, s := range line {
			if s == 42 {
				sheeps += 1
			}
		}
		var sum int
		var median int
		for i, s := range line {
			if s == 42 {
				if sum >= sheeps/2 {
					median = i
					break
				} else {
					sum++
				}
			}
		}

		var total int

		for i, s := range line {
			if s == 42 {
				if i < median {
					total += median - i
				} else if i > median {
					total += i - median
				}
			}
		}

		total -= (sum)*(sum+1)/2 + (sheeps-sum-1)*(sheeps-sum)/2

		fmt.Println(total)

	}
}

package main

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

func ReadInt() int {
	var i int
	_, err := fmt.Scanf("%d", &i)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadByte() byte {
	return ReadBytes(1)[0]
}

func ReadNL() byte {
	var nl byte
	for nl != 0x0a {
		nl = ReadByte()
	}
	return nl
}

func ReadBytes(n int) []byte {
	p := make([]byte, n)
	_, err := io.ReadFull(os.Stdin, p)
	if err != nil {
		panic(err)
	}
	return p
}

func main() {
	total := ReadInt()
	for i := 0; i < total; i++ {
		ReadNL()
		l := ReadInt()
		ReadNL()
		line := ReadBytes(l)
		var sheeps int
		for _, s := range line {
			if s == 42 {
				sheeps += 1
			}
		}
		var sum int
		var median int
		for i, s := range line {
			if s == 42 {
				if sum >= sheeps/2 {
					median = i
					break
				} else {
					sum++
				}
			}
		}

		var total int

		for i, s := range line {
			if s == 42 {
				if i < median {
					total += median - i
				} else if i > median {
					total += i - median
				}
			}

			if i < median && i >= median-sum {
				total += median - i
			} else if i > median && i <= median+(sheeps-sum-1) {
				total -= i - median
			}
		}

		fmt.Println(total)

	}
}

package main

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

func ReadInt() int {
	var i int
	_, err := fmt.Scanf("%d", &i)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadByte() byte {
	return ReadBytes(1)[0]
}

func ReadNL() byte {
	var nl byte
	for nl != 0x0a {
		nl = ReadByte()
	}
	return nl
}

func ReadBytes(n int) []byte {
	p := make([]byte, n)
	_, err := io.ReadFull(os.Stdin, p)
	if err != nil {
		panic(err)
	}
	return p
}

func main() {
	total := ReadInt()
	for i := 0; i < total; i++ {
		ReadNL()
		l := ReadInt()
		ReadNL()
		line := ReadBytes(l)
		var sheeps int
		for _, s := range line {
			if s == 42 {
				sheeps += 1
			}
		}
		var sum int
		var median int
		for i, s := range line {
			if s == 42 {
				if sum >= sheeps/2 {
					median = i
					break
				} else {
					sum++
				}
			}
		}

		var total int

		for i, s := range line {
			if s == 42 {
				if i < median {
					total += median - i
				} else if i > median {
					total += i - median
				}
			}

			if i < median && i >= median-sum {
				total -= median - i
			} else if i > median && i <= median+(sheeps-sum-1) {
				total -= i - median
			}
		}

		fmt.Println(total)

	}
}

package main

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

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

	var t, n int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		sheepCnt := 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				sheepCnt++
			}
		}
		if sheepCnt == 0 || sheepCnt == n {
			fmt.Println(0)
		} else {
			cnt := calc(s, (sheepCnt+1)/2)
			if sheepCnt%2 == 0 {
				cnt2 := calc(s, sheepCnt/2+1)
				if cnt2 < cnt {
					cnt = cnt2
				}
			}
			fmt.Println(cnt)
		}
	}
}

func calc(s string, centerSheep int) int {
	var center int
	for i, j := 0, 0; i < len(s) && j < centerSheep; i++ {
		if s[i] == '*' {
			j++
			center = i
		}
	}
	cnt := 0
	for i, j := 0, 0; i < len(s); i++ {
		if s[i] == '*' {
			j++
			cnt += abs(center + (j - centerSheep) - i)
		}
	}
	return cnt
}

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

package main

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

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

	var t, n int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		sheepCnt := 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				sheepCnt++
			}
		}
		if sheepCnt == 1 || sheepCnt == n {
			fmt.Println(0)
		} else {
			cnt := calc(s, (sheepCnt+1)/2)
			if sheepCnt%2 == 0 {
				cnt2 := calc(s, sheepCnt/2+1)
				if cnt2 < cnt {
					cnt = cnt2
				}
			}
			fmt.Println(cnt)
		}
	}
}

func calc(s string, centerSheep int) int {
	var center int
	for i, j := 0, 0; i < len(s) && j < centerSheep; i++ {
		if s[i] == '*' {
			j++
			center = i
		}
	}
	cnt := 0
	for i, j := 0, 0; i < len(s); i++ {
		if s[i] == '*' {
			j++
			cnt += abs(center + (j - centerSheep) - i)
		}
	}
	return cnt
}

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

package main

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

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

	var t, n int
	var s string
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &s)
		sheepCnt := 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				sheepCnt++
			}
		}
		if sheepCnt == 1 || sheepCnt == n {
			fmt.Println(0)
		} else {
			cnt := calc(s, (sheepCnt+1)/2)
			if sheepCnt%2 == 0 {
				cnt2 := calc(s, sheepCnt/2+1)
				if cnt2 > cnt {
					cnt = cnt2
				}
			}
			fmt.Println(cnt)
		}
	}
}

func calc(s string, centerSheep int) int {
	var center int
	for i, j := 0, 0; i < len(s) && j < centerSheep; i++ {
		if s[i] == '*' {
			j++
			center = i
		}
	}
	cnt := 0
	for i, j := 0, 0; i < len(s); i++ {
		if s[i] == '*' {
			j++
			cnt += abs(center + (j - centerSheep) - i)
		}
	}
	return cnt
}

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

package main

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

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

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

	for k := 0; k < t; k++ {
		var n int
		var cc string
		fmt.Fscanln(in, &n)
		fmt.Fscanf(in, "%s\n", &cc)

		arr := make([]bool, n)

		for i, c := range cc {
			if c == '*' {
				arr[i] = true
			}
		}

		prefixCnt := make([]int, n)
		prefixSum := make([]int, n)

		if arr[0] == true {
			prefixCnt[0] = 1
		}

		for i := 1; i < n; i++ {
			prefixCnt[i] = prefixCnt[i-1]
			prefixSum[i] = prefixSum[i-1]
			if arr[i] == true {
				prefixCnt[i]++
			} else {
				prefixSum[i] += prefixCnt[i-1]
			}
		}

		suffixCnt := make([]int, n)
		suffixSum := make([]int, n)

		if arr[n-1] == true {
			suffixCnt[n-1] = 1
		}

		for i := n - 2; i >= 0; i-- {
			suffixCnt[i] = suffixCnt[i+1]
			suffixSum[i] = suffixSum[i+1]
			if arr[i] == true {
				suffixCnt[i]++
			} else {
				suffixSum[i] += suffixCnt[i+1]
			}
		}

		ans := float64(suffixSum[0])

		for i := 1; i < n; i++ {
			version := prefixSum[i-1] + suffixSum[i]
			ans = math.Min(ans, float64(version))
		}

		ans = math.Min(ans, float64(prefixSum[n-1]))

		fmt.Println(int64(ans))
	}
}

package main

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

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

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

	for k := 0; k < t; k++ {
		var n int
		var cc string
		fmt.Fscanln(in, &n)
		fmt.Fscanf(in, "%s\n", &cc)

		arr := make([]bool, n)

		for i, c := range cc {
			if c == '*' {
				arr[i] = true
			}
		}

		prefixCnt := make([]int, n)
		prefixSum := make([]int, n)

		if arr[0] == true {
			prefixCnt[0] = 1
		}

		for i := 1; i < n; i++ {
			prefixCnt[i] = prefixCnt[i-1]
			prefixSum[i] = prefixSum[i-1]
			if arr[i] == true {
				prefixCnt[i]++
			} else {
				prefixSum[i] += prefixCnt[i-1]
			}
		}

		suffixCnt := make([]int, n)
		suffixSum := make([]int, n)

		if arr[n-1] == true {
			suffixCnt[n-1] = 1
		}

		for i := n - 2; i >= 0; i-- {
			suffixCnt[i] = suffixCnt[i+1]
			suffixSum[i] = suffixSum[i+1]
			if arr[i] == true {
				suffixCnt[i]++
			} else {
				suffixSum[i] += suffixCnt[i+1]
			}
		}

		ans := float64(suffixSum[0])

		for i := 1; i < n; i++ {
			version := prefixSum[i-1] + suffixSum[i]
			ans = math.Min(ans, float64(version))
		}

		fmt.Println(int64(ans))
	}
}

package main

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

const (
	MOD int = int(1e9 + 7)
)

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

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

	for q := 0; q < t; q++ {
		var l int
		fmt.Fscan(_r, &l)
		var line []byte
		var sheep []int
		var numSheep int = 0
		fmt.Fscan(_r, &line)
		for i := 0; i < l; i++ {
			if line[i] == '*' {
				sheep = append(sheep, i-numSheep)
				numSheep++
			}
		}

		var ans int = 0

		if numSheep != 0 {
			mean := sheep[numSheep/2]
			for i := 0; i < numSheep; i++ {
				ans += AbsInt(sheep[i] - mean)
			}
		}

		fmt.Fprintf(_w, "%d\n", ans)
	}
}

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

package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func scanString(s *string) { fmt.Fscanln(reader, s) }

var arr [200007]int

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

// return 1 + ... + x
func pa(x int) int64 {
	return int64(x) * (int64(x) + 1)/2
}

func test_case() {
	var n int
	var str string

	scanf("%d\n", &n)
	scanString(&str)

	cnt := 0
	for i := 0; i < n; i++ {
		if str[i] == '*' {
			cnt++
		}
	}

	pos := -1
	cur := 0
	for i := 0; i < n; i++ {
		if str[i] == '*' {
			cur++
			if 2 * cur >= cnt {
				pos = i
				break
			}
		}
	}

	if pos == -1 {
		println(0)
		return
	}

	println("pos", pos)

	var tot int64 = 0
	for i := 0; i < n; i++ {
		if str[i] == '*' {
			tot += int64(abs(pos - i))
		}
	}

	if cnt%2 == 1 {
		tot -= 2 * pa(cnt/2)
	} else {
		tot -= pa(cnt/2) + pa(cnt/2 - 1)
	}

	println(tot)
}

func main() {
	defer writer.Flush()
	var t int

	scanf("%d\n", &t)
	for t > 0 {
		test_case()
		t--
	}

}


It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they have evaluated its difficulty. Also animals decided to do the tasks in order of their difficulty. Unfortunately, some tasks can have the same difficulty, so the order in which one can perform the tasks may vary.Menshykov, Uslada and Horace ask you to deal with this nuisance and come up with individual plans for each of them. The plan is a sequence describing the order in which an animal should do all the n tasks. Besides, each of them wants to have its own unique plan. Therefore three plans must form three different sequences. You are to find the required plans, or otherwise deliver the sad news to them by stating that it is impossible to come up with three distinct plans for the given tasks.

The first line contains integer n (1 ≤ n ≤ 2000) — the number of tasks. The second line contains n integers h1, h2, ..., hn (1 ≤ hi ≤ 2000), where hi is the difficulty of the i-th task. The larger number hi is, the more difficult the i-th task is.

In the first line print "YES" (without the quotes), if it is possible to come up with three distinct plans of doing the tasks. Otherwise print in the first line "NO" (without the quotes). If three desired plans do exist, print in the second line n distinct integers that represent the numbers of the tasks in the order they are done according to the first plan. In the third and fourth line print two remaining plans in the same form. If there are multiple possible answers, you can print any of them.

NoteIn the first sample the difficulty of the tasks sets one limit: tasks 1 and 4 must be done before tasks 2 and 3. That gives the total of four possible sequences of doing tasks : [1, 4, 2, 3], [4, 1, 2, 3], [1, 4, 3, 2], [4, 1, 3, 2]. You can print any three of them in the answer.In the second sample there are only two sequences of tasks that meet the conditions — [3, 1, 2, 4, 5] and [3, 1, 4, 2, 5]. Consequently, it is impossible to make three distinct sequences of tasks.

package main

import (
	"fmt"
	"sort"
)

type Work struct {
	Complexity int
	Index int
}

type ByComplexity []Work

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

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]Work, n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		a[i] = Work{x, i+1}
	}
	sort.Sort(ByComplexity(a))
	ret := make([][]int, 3)
	ret[0] = make([]int, n)
	ret[1] = make([]int, n)
	ret[2] = make([]int, n)

	first := 0
	splitted := false
	part_splitted := false
	for first < n {
		next := first + 1
		for next < n && a[next].Complexity == a[first].Complexity {
			next++
		}

		if next - first > 2 {
			splitted = true
			ret[0][first] = a[first].Index
			ret[0][first+1] = a[first+1].Index
			ret[0][first+2] = a[first+2].Index

			ret[1][first] = a[first+1].Index
			ret[1][first+1] = a[first].Index
			ret[1][first+2] = a[first+2].Index

			ret[2][first] = a[first+2].Index
			ret[2][first+1] = a[first+1].Index
			ret[2][first+2] = a[first].Index
			for i := first + 3; i < next; i++ {
				ret[0][i] = a[i].Index
				ret[1][i] = a[i].Index
				ret[2][i] = a[i].Index
			}
		} else if next - first == 2 {
			if part_splitted {
				splitted = true
				ret[0][first] = a[first].Index
				ret[0][first+1] = a[first+1].Index

				ret[1][first] = a[first+1].Index
				ret[1][first+1] = a[first].Index

				ret[2][first] = a[first].Index
				ret[2][first+1] = a[first+1].Index
			} else {
				part_splitted = true
				ret[0][first] = a[first].Index
				ret[0][first+1] = a[first+1].Index

				ret[1][first] = a[first].Index
				ret[1][first+1] = a[first+1].Index

				ret[2][first] = a[first+1].Index
				ret[2][first+1] = a[first].Index
			}
		} else {
			ret[0][first] = a[first].Index
			ret[1][first] = a[first].Index
			ret[2][first] = a[first].Index
		}

		first = next
	}

	if splitted {
		fmt.Println("YES")
		for i := 0; i < 3; i++ {
			for j := 0; j < n; j++ {
				fmt.Print(ret[i][j], " ")
			}
			fmt.Println()
		}
	} else {
		fmt.Println("NO")
	}
}

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)

	n := nextInt()
	a1, a2, atemp := make([]int, n), make([]int, n), make([]int, n)
	pos1, pos2 := 0, 0

	for i := 0; i < n; i++ {
		a1[i] = nextInt()
	}

	copy(atemp, a1)

	for i := 0; i < n; i++ {
		pos := 0

		for j := 0; j < n; j++ {
			if a1[j] != 0 {
				pos = j
				break
			}
		}

		for j := pos; j < n; j++ {
			if a1[j] != 0 && a1[j] < a1[pos] {
				pos = j
			}
		}

		a2[i] = pos
		a1[pos] = 0
	}

	i := 0
	a1 = atemp

	for ; i < n - 1; i++ {
		if a1[a2[i]] == a1[a2[i + 1]] {
			pos1 = i
			i++
			break
		}
	}

	for ; i < n - 1; i++ {
		if a1[a2[i]] == a1[a2[i + 1]] {
			pos2 = i
			break
		}
	}

	if pos2 == 0 {
		 println("NO")
	} else {
		println("YES")
		printSlice(a2)
		a2[pos1], a2[pos1 + 1] = a2[pos1 + 1], a2[pos1]
		printSlice(a2)
		a2[pos2], a2[pos2 + 1] = a2[pos2 + 1], a2[pos2]
		printSlice(a2)
	}

	// println(a2, a1, pos1, pos2)
}

func printSlice(a []int) {
	for i := 0; i < len(a); i++ {
		print(a[i] + 1, " ")
	}
	print("\n")
}

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

//https://codeforces.com/problemset/problem/471/b
//http://bigocoder.com/courses/BLUE20/BLUE20_LEC18/BLUE_LEC18P01/statement
package main

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

type node struct {
	p int
	i int
}

func solve(arr []node, cache map[int]int) [][]node {
	result := make([][]node, 3)
	sort.Slice(arr, func(i, j int) bool { return arr[i].p < arr[j].p })

	for i := range result {
		result[i] = make([]node, len(arr))
	}
	copy(result[0], arr)
	j := 1

	for i := range arr {
		if cache[arr[i].p] > 1 {
			temp := arr[i]
			arr[i] = arr[i+1]
			arr[i+1] = temp
			cache[arr[i].p]--
			copy(result[j], arr)
			j++
			if j == 3 {
				break
			}
		}
	}

	return result
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, p, dupeNumber int
	var isHaveEnoughDuplicate bool
	fmt.Fscanf(r, "%d\n", &n)
	arr := make([]node, n)
	cache := make(map[int]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &p)
		arr[i] = node{p, i + 1}
		cache[arr[i].p]++
	}

	for _, v := range cache {
		if v > 2 {
			isHaveEnoughDuplicate = true
			break
		}
		if v > 1 {
			dupeNumber++
		}
		if dupeNumber >= 2 {
			break
		}
	}

	if isHaveEnoughDuplicate || dupeNumber >= 2 {
		fmt.Fprintf(os.Stdout, "%s\n", "YES")
		res := solve(arr, cache)
		for i := range res {
			for j := range res[i] {
				fmt.Fprintf(os.Stdout, "%d ", res[i][j].i)
			}
			fmt.Fprintln(os.Stdout)
		}
	} else {
		fmt.Fprintf(os.Stdout, "%s\n", "NO")
	}
}

package main

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

type node struct {
	p int
	i int
}

func solve(arr []node, cache map[int]int) [][]node {
	j := 1
	result := make([][]node, 3)
	sort.Slice(arr, func(i, j int) bool { return arr[i].p < arr[j].p })

	for i := range result {
		result[i] = make([]node, len(arr))
	}
	copy(result[0], arr)

	for i := range arr {
		if cache[arr[i].p] > 1 {
			swap(arr, i, j)
			cache[arr[i].p]--
			copy(result[j], arr)
			j++
			if j == 3 {
				break
			}
		}
	}

	return result
}

func swap(arr []node, i int, j int) {
	temp := arr[i]
	arr[i] = arr[i+1]
	arr[i+1] = temp
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, p, dupeNumber int
	var isHaveEnoughDuplicate bool
	fmt.Fscanf(r, "%d\n", &n)
	arr := make([]node, n)
	cache := make(map[int]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &p)
		arr[i] = node{p, i + 1}
		cache[arr[i].p]++
	}

	for _, value := range cache {
		if value > 2 {
			isHaveEnoughDuplicate = true
			//to have 3 distinct result, we need at least 3 duplicate numbers or 2 pairs of dupe numbers
			break
		}
		if value > 1 {
			dupeNumber++
		}
		if dupeNumber >= 2 {
			break
		}
	}

	if isHaveEnoughDuplicate || dupeNumber >= 2 {
		fmt.Fprintf(os.Stdout, "%s\n", "YES")
		res := solve(arr, cache)
		for i := range res {
			for j := range res[i] {
				fmt.Fprintf(os.Stdout, "%d ", res[i][j].i)
			}
			fmt.Fprintln(os.Stdout)
		}
	} else {
		fmt.Fprintf(os.Stdout, "%s\n", "NO")
	}
}

package main

import (
    "fmt"
    "sort"
)

type Pair struct {
    index, value int
}

type ByValue []Pair

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

func main() {
    var n, a int
    fmt.Scan(&n)
    arr := make([]Pair, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        arr[i] = Pair{index: i + 1, value: a}
    }
    sort.Sort(ByValue(arr))

    pos := make([]Pair, 0)
    for i := 1; i < n; i++ {
        if arr[i].value == arr[i-1].value {
            pos = append(pos, Pair{i, i - 1})
        }
    }
    if len(pos) < 2 {
        fmt.Println("NO")
    } else {
        fmt.Println("YES")
        for _, v := range arr {
            fmt.Printf("%d ", v.index)
        }
        fmt.Println()

        arr[pos[0].index], arr[pos[0].value] = arr[pos[0].value], arr[pos[0].index]
        for _, v := range arr {
            fmt.Printf("%d ", v.index)
        }
        fmt.Println()

        arr[pos[1].index], arr[pos[1].value] = arr[pos[1].value], arr[pos[1].index]
        for _, v := range arr {
            fmt.Printf("%d ", v.index)
        }
        fmt.Println()
    }
}

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)

	n := nextInt()
	a1, a2, atemp := make([]int, n), make([]int, n), make([]int, n)
	pos1, pos2 := 0, 0

	for i := 0; i < n; i++ {
		a1[i] = nextInt()
	}

	copy(atemp, a1)

	for i := 0; i < n; i++ {
		pos := 0

		for j := 0; j < n; j++ {
			if a1[j] != 0 {
				pos = j
				break
			}
		}

		for j := pos; j < n; j++ {
			if a1[j] != 0 && a1[j] < a1[pos] {
				pos = j
			}
		}

		a2[i] = pos
		a1[pos] = 0
	}

	i := 0
	a1 = atemp

	for ; i < n - 1; i++ {
		if a1[a2[i]] == a1[a2[i + 1]] {
			pos1 = i
			i += 2
			break
		}
	}

	for ; i < n - 1; i++ {
		if a1[a2[i]] == a1[a2[i + 1]] {
			pos2 = i
			break
		}
	}

	if pos2 == 0 {
		 println("NO")
	} else {
		println("YES")
		printSlice(a2)
		a2[pos1], a2[pos1 + 1] = a2[pos1 + 1], a2[pos1]
		printSlice(a2)
		a2[pos2], a2[pos2 + 1] = a2[pos2 + 1], a2[pos2]
		printSlice(a2)
	}

	// println(a2, a1, pos1, pos2)
}

func printSlice(a []int) {
	for i := 0; i < len(a); i++ {
		print(a[i] + 1, " ")
	}
	print("\n")
}

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


A lighthouse keeper Peter commands an army of $$$n$$$ battle lemmings. He ordered his army to stand in a line and numbered the lemmings from $$$1$$$ to $$$n$$$ from left to right. Some of the lemmings hold shields. Each lemming cannot hold more than one shield.The more protected Peter's army is, the better. To calculate the protection of the army, he finds the number of protected pairs of lemmings, that is such pairs that both lemmings in the pair don't hold a shield, but there is a lemming with a shield between them.Now it's time to prepare for defence and increase the protection of the army. To do this, Peter can give orders. He chooses a lemming with a shield and gives him one of the two orders:   give the shield to the left neighbor if it exists and doesn't have a shield;  give the shield to the right neighbor if it exists and doesn't have a shield. In one second Peter can give exactly one order.It's not clear how much time Peter has before the defence. So he decided to determine the maximal value of army protection for each $$$k$$$ from $$$0$$$ to $$$\frac{n(n-1)}2$$$, if he gives no more that $$$k$$$ orders. Help Peter to calculate it!

First line contains a single integer $$$n$$$ ($$$1 \le n \le 80$$$), the number of lemmings in Peter's army. Second line contains $$$n$$$ integers $$$a_i$$$ ($$$0 \le a_i \le 1$$$). If $$$a_i = 1$$$, then the $$$i$$$-th lemming has a shield, otherwise $$$a_i = 0$$$.

Print $$$\frac{n(n-1)}2 + 1$$$ numbers, the greatest possible protection after no more than $$$0, 1, \dots, \frac{n(n-1)}2$$$ orders.

NoteConsider the first example.The protection is initially equal to zero, because for each pair of lemmings without shields there is no lemmings with shield.In one second Peter can order the first lemming give his shield to the right neighbor. In this case, the protection is two, as there are two protected pairs of lemmings, $$$(1, 3)$$$ and $$$(1, 4)$$$.In two seconds Peter can act in the following way. First, he orders the fifth lemming to give a shield to the left neighbor. Then, he orders the first lemming to give a shield to the right neighbor. In this case Peter has three protected pairs of lemmings — $$$(1, 3)$$$, $$$(1, 5)$$$ and $$$(3, 5)$$$.You can make sure that it's impossible to give orders in such a way that the protection becomes greater than three.

package main

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

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

	n := readNum(reader)

	A := readNNums(reader, n)

	res := solve(n, A)

	var buf bytes.Buffer

	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	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 MX = 103

const dx, dy, dz = MX + 1, MX + 1, MX*(MX+1)/2 + 1

var dp [dx][dy][dz]int

const INF = 100000000

func init() {
	for i := 0; i < dx; i++ {
		for j := 0; j < dy; j++ {
			for k := 0; k < dz; k++ {
				dp[i][j][k] = INF
			}
		}
	}
}

func solve(n int, A []int) []int {
	gg := make([]int, 0, n/2)

	for i := 0; i <= n; i++ {
		j := i
		for i < n && A[i] == 0 {
			i++
		}
		gg = append(gg, i-j)
	}

	p := make([]int, len(gg))
	p[0] = gg[0]
	for i := 1; i < len(gg); i++ {
		p[i] = gg[i] + p[i-1]
	}
	dp[0][0][0] = 0

	k := len(gg)
	l := p[len(p)-1]

	N := n * (n - 1) / 2

	for i := 0; i < k; i++ {
		for j := 0; j <= l; j++ {
			for s := 0; s <= N; s++ {
				if dp[i][j][s] == INF {
					continue
				}
				for q := j; q <= l; q++ {
					min(&dp[i+1][q][s+abs(q-p[i])], dp[i][j][s]+(q-j)*(q-j))
				}
			}
		}
	}

	res := make([]int, 0, N+1)
	cur := INF
	for s := 0; s <= N; s++ {
		min(&cur, dp[k][l][s])
		val := l*l - cur
		res = append(res, val/2)
	}
	return res
}

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

func min(a *int, b int) {
	if *a > b {
		*a = b
	}
}

package main

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

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

	n := readNum(reader)

	A := readNNums(reader, n)

	res := solve(n, A)

	var buf bytes.Buffer

	for i := 0; i < len(res); i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	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 MX = 81

const dx, dy, dz = MX + 1, MX + 1, MX*(MX+1)/2 + 1

var dp [dx][dy][dz]int

const INF = 100000000

func init() {
	for i := 0; i < dx; i++ {
		for j := 0; j < dy; j++ {
			for k := 0; k < dz; k++ {
				dp[i][j][k] = INF
			}
		}
	}
}

func solve(n int, A []int) []int {
	gg := make([]int, 0, n/2)

	for i := 0; i <= n; i++ {
		j := i
		for i < n && A[i] == 0 {
			i++
		}
		gg = append(gg, i-j)
	}

	p := make([]int, len(gg))
	p[0] = gg[0]
	for i := 1; i < len(gg); i++ {
		p[i] = gg[i] + p[i-1]
	}
	dp[0][0][0] = 0

	k := len(gg)
	l := p[len(p)-1]

	N := n * (n - 1) / 2

	for i := 0; i < k; i++ {
		for j := 0; j <= l; j++ {
			for s := 0; s <= N; s++ {
				if dp[i][j][s] == INF {
					continue
				}
				for q := j; q <= l; q++ {
					min(&dp[i+1][q][s+abs(q-p[i])], dp[i][j][s]+(q-j)*(q-j))
				}
			}
		}
	}

	res := make([]int, 0, N+1)
	cur := INF
	for s := 0; s <= N; s++ {
		min(&cur, dp[k][l][s])
		val := l*l - cur
		res = append(res, val/2)
	}
	return res
}

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

func min(a *int, b int) {
	if *a > b {
		*a = b
	}
}


Even a cat has things it can do that AI cannot.— Fei-Fei LiYou are given $$$m$$$ arrays of positive integers. Each array is of even length.You need to split all these integers into two equal multisets $$$L$$$ and $$$R$$$, that is, each element of each array should go into one of two multisets (but not both). Additionally, for each of the $$$m$$$ arrays, exactly half of its elements should go into $$$L$$$, and the rest should go into $$$R$$$.Give an example of such a division or determine that no such division exists.

The first line contains an integer $$$m$$$ ($$$1 \le m \le 10 ^ 5$$$) — the number of arrays. The next $$$2 \cdot m$$$ lines contain descriptions of the arrays. For each array, the first line contains an even integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10 ^ 5$$$) — the length of the array. The second line consists of $$$n$$$ space-separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10 ^ 9$$$) — array elements. It is guaranteed that the sum of $$$n$$$ over all arrays does not exceed $$$2 \cdot 10^5$$$.

If the answer exists, print "YES", and then print $$$m$$$ lines. On each line, for each element, print the letter "L" or "R" (capitalized, without spaces), depending on which multiset the element should go into. If there is no answer, print "NO" on the only line.

NoteIn the first array, we add the first element to $$$R$$$ and the second to $$$L$$$. Now $$$L = \{2\}$$$, and $$$R = \{1\}$$$.In the second array, we add the first and third elements to $$$L$$$ and the rest to $$$R$$$. Now $$$L = \{1, 2, 3\}$$$ and $$$R = \{1, 2, 3\}$$$.In the third array, we add elements 2, 3, and 6 to $$$L$$$, and others — to $$$R$$$. As a result, $$$L = R = \{1, 1, 2, 2, 3, 3\}$$$.

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

const TAM = int(2e5 + 10)

var a [TAM]int
var ans [TAM]byte
var start []int
var end []int
var graph [TAM][]int
var order [TAM]int

func addEdge(a, b int) {
	graph[a] = append(graph[a], b)
	graph[b] = append(graph[b], a)
}

func impossible() {
	printf("NO\n")
	flush()
	os.Exit(0)
}

var colors []byte = []byte{'L', 'R'}

func fill(start int) bool {
	i := start
	c := 1
	ans[i] = colors[0]
	for j := graph[i][0]; j != start; {
		ans[j] = colors[c]
		if graph[j][0] == i {
			i = j
			j = graph[i][1]
		} else {
			i = j
			j = graph[i][0]
		}
		c ^= 1
	}
	return true
}

func main() {
	defer flush()
	var nArrays int
	scan(&nArrays)
	start = make([]int, nArrays)
	end = make([]int, nArrays)

	last := make(map[int]int, nArrays)
	for arrIndex := 0; arrIndex < nArrays; arrIndex++ {
		if arrIndex > 0 {
			start[arrIndex] = end[arrIndex-1]
		}
		var sz int
		scan(&sz)
		end[arrIndex] = start[arrIndex] + sz
		for i := 0; i < sz; i++ {
			scan(&a[start[arrIndex]+i])
			order[i] = start[arrIndex] + i
		}
		sort.Slice(order[:sz], func(i, j int) bool {
			return a[order[i]] < a[order[j]]
		})

		lastI := -1
		for orderIndex := 0; orderIndex < sz; orderIndex++ {
			if orderIndex+1 < sz && a[order[orderIndex+1]] == a[order[orderIndex]] {
				ans[order[orderIndex+1]] = 'L'
				ans[order[orderIndex]] = 'R'
				orderIndex++
			} else {
				i := order[orderIndex]
				x := a[i]
				j, found := last[x]
				if found {
					delete(last, x)
					addEdge(i, j)
				} else {
					last[x] = i
				}

				if lastI != -1 {
					addEdge(lastI, i)
					lastI = -1
				} else {
					lastI = i
				}
			}
		}

		assert(lastI == -1)
	}

	if len(last) > 1 {
		impossible()
	}

	for i := 0; i < end[nArrays-1]; i++ {
		if ans[i] == 0 {
			fill(i)
		}
	}

	printf("YES\n")
	for i := 0; i < nArrays; i++ {
		printf("%s\n", ans[start[i]:end[i]])
	}
}

package main

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

const MOD int64 = 1000000007

var m int

var a [][]int

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

	fmt.Fscan(read, &m)

	a = make([][]int, m)

	for j := 0; j < m; j++ {
		var n int
		fmt.Fscan(read, &n)

		a[j] = make([]int, n)

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

	solve()

}

type pair struct {
	v int
	idx []int
}

func solve()  {

	var res [][]int

	res = make([][]int, m)

	for i := 0; i < m; i++ {
		res[i] = make([]int, len(a[i]))

		for j := 0; j < len(res[i]); j++ {
			res[i][j] = -1
		}
	}

	check := make(map[int]int)

	//for each num -> rows where that number is present in odd quantity
	rows := make(map[int]map[int]bool)
	//nums with odd count in each row
	odds := make([]map[int]int, m)

	for i := 0; i < m; i++ {
		mp1 := make(map[int]int)
		mp2 := make(map[int]int)

		for j := 0; j < len(a[i]); j++ {
			mp1[a[i][j]]++
			mp2[a[i][j]] = j
			check[a[i][j]]++
		}

		for k, v := range mp1 {
			if v % 2 == 1 {
				if odds[i] == nil {
					odds[i] = make(map[int]int)
				}
				odds[i][k] = mp2[k]

				if rows[k] == nil {
					rows[k] = make(map[int]bool)
				}

				rows[k][i] = true
			}
		}
	}

	for _, v := range check {
		if v % 2 == 1 {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

	for i := 0; i < m; i++ {
		mp := odds[i]
		in := 0

		for len(mp) > 0 {
			if len(mp) < 2 {
				panic("len must be even")
			}

			var key1 int
			var v1 int
			var key2 int
			var v2 int

			for k, v := range mp {
				if res[i][v] != -1 {
					continue
				}
				key1 = k
				break
			}
			v1 = mp[key1]
			delete(mp, key1)

			res[i][v1] = in
			in = in ^ 1

			for k, v := range mp {
				if res[i][v] != -1 {
					continue
				}
				key2 = k
				break
			}

			v2 = mp[key2]
			delete(mp, key2)

			res[i][v2] = in
			in = in ^ 1

			delete(rows[key1], i)
			delete(rows[key2], i)

			rec(key2, &rows, &odds, in, &res)
		}
	}

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

		for j := 0; j < len(a[i]); j++ {
			mp[a[i][j]] = append(mp[a[i][j]], j)
		}

		in := 0

		for _, v := range mp{
			for p := 0; p < len(v); p++ {
				if res[i][v[p]] != -1 {
					continue
				}
				res[i][v[p]] = in

				in = in ^ 1
			}
		}
	}

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

		for j := 0; j < len(res[i]); j++ {
			if res[i][j] == 0 {
				fmt.Print("L")
			} else if res[i][j] == 1 {
				fmt.Print("R")
			} else {
				panic("incorrect")
			}
		}
		fmt.Println()
	}
}

func rec(key int, rows *map[int]map[int]bool, odds *[]map[int]int, cur int, res *[][]int) {

	if len((*rows)[key]) == 0 {
		return
	}

	var next int

	for k, _ := range (*rows)[key] {
		next = k
		break
	}

	delete((*rows)[key], next)

	idx := (*odds)[next][key]

	(*res)[next][idx] = cur
	cur = cur ^ 1

	delete((*odds)[next], key)

	var _k int
	var _v int
	for k, v := range (*odds)[next] {
		_k = k
		_v = v
		break
	}

	delete((*odds)[next], _k)

	(*res)[next][_v] = cur
	cur = cur ^ 1

	delete((*rows)[_k], next)

	rec(_k, rows, odds, cur, res)
}

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

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

const TAM = int(2e5 + 10)

var a [TAM]int
var ans [TAM]byte
var start []int
var end []int
var graph [TAM][]int

func addEdge(a, b int) {
	graph[a] = append(graph[a], b)
	graph[b] = append(graph[b], a)
}

func impossible() {
	printf("NO\n")
	flush()
	os.Exit(0)
}

func rec(i int, c byte) bool {
	if ans[i] != '.' {
		return ans[i] == c
	}
	ans[i] = c
	if c == 'L' {
		c = 'R'
	} else {
		c = 'L'
	}
	for _, j := range graph[i] {
		if !rec(j, c) {
			return false
		}
	}
	return true
}

func main() {
	defer flush()
	var n int
	scan(&n)
	start = make([]int, n)
	end = make([]int, n)

	last := make(map[int]int, n)
	for arrIndex := 0; arrIndex < n; arrIndex++ {
		if arrIndex > 0 {
			start[arrIndex] = end[arrIndex-1]
		}
		scan(&end[arrIndex])
		end[arrIndex] += start[arrIndex]
		lastInArray := make(map[int]int, n)
		for i := start[arrIndex]; i < end[arrIndex]; i++ {
			ans[i] = '.'
			scan(&a[i])
			j, found := lastInArray[a[i]]
			if found {
				ans[j] = 'L'
				ans[i] = 'R'
				delete(lastInArray, a[i])
			} else {
				lastInArray[a[i]] = i
			}
		}
		lastI := -1
		for x, i := range lastInArray {
			j, found := last[x]
			if found {
				delete(last, x)
				addEdge(i, j)
			} else {
				last[x] = i
			}

			if lastI != -1 {
				addEdge(lastI, i)
				lastI = -1
			} else {
				lastI = i
			}
		}

		assert(lastI == -1)
	}

	if len(last) > 1 {
		impossible()
	}

	for i := 0; i < end[n-1]; i++ {
		if ans[i] == '.' {
			if !rec(i, 'L') {
				impossible()
			}
		}
	}

	for i := 0; i < n; i++ {
		printf("%s\n", ans[start[i]:end[i]])
	}
}


I wonder, does the falling rain Forever yearn for it's disdain?Effluvium of the MindYou are given a positive integer $$$n$$$.Find any permutation $$$p$$$ of length $$$n$$$ such that the sum $$$\operatorname{lcm}(1,p_1) + \operatorname{lcm}(2, p_2) + \ldots + \operatorname{lcm}(n, p_n)$$$ is as large as possible. Here $$$\operatorname{lcm}(x, y)$$$ denotes the least common multiple (LCM) of integers $$$x$$$ and $$$y$$$.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1\,000$$$). Description of the test cases follows. The only line for each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, $$$\ldots$$$, $$$p_n$$$ — the permutation with the maximum possible value of $$$\operatorname{lcm}(1,p_1) + \operatorname{lcm}(2, p_2) + \ldots + \operatorname{lcm}(n, p_n)$$$. If there are multiple answers, print any of them.

NoteFor $$$n = 1$$$, there is only one permutation, so the answer is $$$[1]$$$.For $$$n = 2$$$, there are two permutations:   $$$[1, 2]$$$ — the sum is $$$\operatorname{lcm}(1,1) + \operatorname{lcm}(2, 2) = 1 + 2 = 3$$$.  $$$[2, 1]$$$ — the sum is $$$\operatorname{lcm}(1,2) + \operatorname{lcm}(2, 1) = 2 + 2 = 4$$$.

package main

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

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

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

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

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

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

/**
Run solve the problem CF1712A
Date: 8/20/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1712/B
Problem: CF1712A
**/
func (in *CF1712A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		if n == 1 {
			fmt.Println(1)
		} else if n >= 2 {
			if n%2 == 0 {
				for i := 1; i <= n; i += 2 {
					fmt.Print(i+1, i, " ")
				}
			} else {
				fmt.Print(1, " ")
				for i := 3; i <= n; i += 2 {
					fmt.Print(i, i-1, " ")
				}
			}
			fmt.Println()
		}
	}
}

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

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

package main

import "fmt"

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}
func lcm(x, y int) int {
	return x / gcd(x, y) * y
}
func main() {
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Scan(&n)
		if n%2 == 0 {
			for i := 1; i <= n; i++ {
				if i%2 == 0 {
					fmt.Printf("%v ", i-1)
				} else {
					fmt.Printf("%v ", i+1)
				}
			}
			fmt.Println("")
		} else {
			fmt.Printf("%v ", 1)
			for i := 2; i <= n; i++ {
				if i%2 == 0 {
					fmt.Printf("%v ", i+1)
				} else {
					fmt.Printf("%v ", i-1)
				}
			}
			fmt.Println("")
		}
	}

}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	arr := make([]int, n)
	for i := range arr {
		arr[i] = i + 1
	}
	for i := n - 1; i > 0; i -= 2 {
		arr[i], arr[i-1] = arr[i-1], arr[i]
	}
	for i := range arr {
		fmt.Fprint(out, arr[i], " ")
	}
	fmt.Fprintln(out)
}

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

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

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for j:=0;j<t;j++{
		var n int
		fmt.Fscan(in,&n)
		list:= make([]int,n)
		for k:=1;k<=n;k++{
			list[k-1]=k
		}
		for k:=n-2;k>=0;k-=2{
			list[k],list[k+1] = list[k+1],list[k]
		}
		for k:=0;k<n;k++{
			fmt.Fprintf(out,"%v ",list[k])
		}
		fmt.Fprintln(out,)

	}
}

package main

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

func readLine() string {
	s, err := in.ReadString('\n')
	if err != nil {
		panic(err)
	}
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return s
}

func readLines(n int) []string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = readLine()
	}
	return res
}

func readInt() int {
	n, err := strconv.ParseInt(readLine(), 10, 32)
	if err != nil {
		panic(err)
	}
	return int(n)
}

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

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

func readUint() uint64 {
	n, err := strconv.ParseUint(readLine(), 10, 64)
	if err != nil {
		panic(err)
	}
	return n
}

func readInts(n int) []int {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	arr := make([]int, n)
	for k, a := range as {
		x, _ := strconv.ParseInt(a, 10, 64)
		arr[k] = int(x)
	}
	return arr
}

func readStrings(n int) []string {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	return as
}

func arr(n, m int) [][]int {
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	return a
}

const MAXN int = 1e5 + 7

var in = bufio.NewReader(os.Stdin)
var a [MAXN]int

func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, n, i int
	var ch byte
	t = readInt()
	for ; t != 0; t-- {
		n = readInt()
		for i = n; i > 0; i -= 2 {
			if i >= 2 {
				a[i] = i - 1
				a[i-1] = i
			} else {
				a[i] = i
			}
		}
		for i = 1; i <= n; i++ {
			if i == n {
				ch = '\n'
			} else {

				ch = ' '
			}
			fmt.Fprintf(out, "%d%c", a[i], ch)
		}
	}
}

package main

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

func main() {
	woefulPermutationRead()
}

func woefulPermutationRead() {
	in := bufio.NewReader(os.Stdin)
	var t int

	fmt.Fscan(in, &t)

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

		// solve
		res := woefulPermutation(n)
		fmt.Print(res[0])
		for j := 1; j < n; j++ {
			fmt.Printf(" %d", res[j])
		}
		fmt.Println()
	}
}

func woefulPermutation(n int) []int {
	res := make([]int, n)
	for i := n - 1; i > 0; i -= 2 {
		res[i] = i
		res[i-1] = i + 1
	}
	if res[0] == 0 {
		res[0] = 1
	}
	return 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)

		aa := make([]int, n)
		if n%2 == 0 {
			for i := 0; i < n; i += 2 {
				aa[i] = i + 2
			}
			for i := 1; i < n; i += 2 {
				aa[i] = i
			}
		} else {
			aa[0] = 1
			for i := 1; i < n; i += 2 {
				aa[i] = i + 2
			}
			for i := 2; i < n; i += 2 {
				aa[i] = i
			}
		}

		for _, v := range aa {
			fmt.Fprintf(out, "%d ", v)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	a := make([]int, n)
	i := n - 2
	for i >= 0 {
		a[i] = i + 2
		a[i+1] = i + 1
		i -= 2
	}
	if a[0] == 0 {
		a[0] = 1
	}
	for _, x := range a {
		fmt.Fprintf(out, "%d ", x)
	}
	fmt.Fprintln(out)
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		n := readInt(input)
		solve(n)
	}
}

func solve(n int) {
	arr := []int{}
	for i := 1; i <= n; i++ {
		arr = append(arr, i)
	}
	for i := n - 1; i > 0; i -= 2 {
		arr[i], arr[i-1] = arr[i-1], arr[i]
	}
	for i := 0; i < n; i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

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 readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n := readNum(reader)
		P := solve(n)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", P[i]))
		}
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

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

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func solve(n int) []int {
	// lcm(1, pi)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = i + 1
	}
	for i := n - 1; i > 0; i -= 2 {
		p[i], p[i-1] = p[i-1], p[i]
	}
	return p
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	var n int
	scan(&n)
	if n%2 == 1 {
		printf("1 ")
		for i := 2; i <= n; i += 2 {
			printf("%d %d ", i+1, i)
		}
		printf("\n")
	} else {
		for i := 2; i <= n; i += 2 {
			printf("%d %d ", i, i-1)
		}
		printf("\n")
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var n int
		fmt.Fscan(r, &n)
		w1 := do(n)
		for _, v := range w1 {
			fmt.Fprint(w, v, " ")
		}
		fmt.Fprintln(w)
	}
}

func do(n int) []int {
	a := make([]int, n)
	a[0] = 1
	for i := n - 2; i >= 0; i -= 2 {
		a[i] = i + 2
		a[i+1] = i + 1
	}
	return a
}

package main

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

var bufferedStdin = bufio.NewReader(os.Stdin)
var bufferedStdout = bufio.NewWriter(os.Stdout)

func read(value ...interface{}) {
	_, _ = fmt.Fscan(bufferedStdin, value...)
}

func printf(format string, value ...interface{}) {
	_, _ = fmt.Fprintf(bufferedStdout, format, value...)
}

func printfErr(format string, value ...interface{}) {
	_, _ = fmt.Fprintf(os.Stderr, format, value...)
}

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

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

func findElementIds(array []int, f func(int) bool) []int {
	var result = make([]int, 0)
	for i := 0; i < len(array); i++ {
		if f(array[i]) {
			result = append(result, i)
		}
	}
	return result
}

func reduce(array []int, defaultValue int, f func(int, int) int) int {
	for i := 0; i < len(array); i++ {
		defaultValue = f(defaultValue, array[i])
	}
	return defaultValue
}

func solve(test int) {
	var n int
	read(&n)
	var start = 1
	if n % 2 == 1 {
		printf("1")
		start = 2
	}
	for i := start; i <= n; i += 2 {
		printf(" %d %d", i + 1, i)
	}
	printf("\n")
}

func main() {
	var t = 1
	_, _ = fmt.Fscan(bufferedStdin, &t)
	for i := 0; i < t; i++ {
		solve(i + 1)
	}
	_ = bufferedStdout.Flush()
}

package main

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

var (
	reader bufio.Reader
	writer bufio.Writer
)

func solve() {
	var n int
	scan(&n)

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

	for i := n - 1; i >= 1; i -= 2 {
		a[i - 1], a[i] = a[i], a[i - 1]
	}

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

func main() {
	inp, err := os.Open("in.txt")
	if err == nil {
		os.Stdin = inp
		outp, _ := os.Create("out.txt")
		os.Stdout = outp
		defer outp.Close()
		defer inp.Close()
	}
	reader = *bufio.NewReader(os.Stdin)
	writer = *bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	T = 1
	scan(&T)

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

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(&reader, a...)
}

func printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(&writer, format, a...)
}

package main

import (
	"fmt"
)

func solve() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, n)
	for i := n - 2; i >= 0; i -= 2 {
		arr[i] = i + 2
		arr[i+1] = i + 1
	}
	if n%2 == 1 {
		arr[0] = 1
	}
	for _, v := range arr {
		fmt.Printf("%d ", v)
	}
	fmt.Println()
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}

}

package main

import "fmt"

func main() {

	t := 0
	if _, err := fmt.Scan(&t); err != nil {
		return
	}
	for ; t > 0; t-- {
		n := 0
		if _, err := fmt.Scan(&n); err != nil {
			return
		}
		i := 1
		if n%2 == 1 {
			fmt.Print(i, " ")
			i++
		}
		for ; i <= n; i++ {
			if i < n {
				fmt.Print(i+1, " ", i, " ")
				i++
			} else {
				fmt.Print(i)
			}
		}
	}

}

// 00
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 1; i <= n; i++ {
			a[i-1] = i
		}
		for i := n - 1; i > 0; i -= 2 {
			a[i], a[i-1] = a[i-1], a[i]
		}
		for i := 0; i < n; i++ {
			fmt.Print(a[i])
			if i != n-1 {
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

package main

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

func A1() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int

		Fscan(in, &n)
		if n&1 == 1 {
			Fprint(out, 1, " ")
			for i := 2; i <= n; i += 2 {
				Fprint(out, i+1, i, " ")
			}
			Fprintln(out)
		} else {
			for i := 1; i <= n; i += 2 {
				Fprint(out, i+1, i, " ")
			}
			Fprintln(out)
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }

package main

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

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

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

// func maxSquare(a int) int {
// 	tmp := int(math.Sqrt(float64(a)))
// 	if tmp*tmp == a {
// 		return tmp * tmp
// 	} else {
// 		return (tmp + 1) * (tmp + 1)
// 	}
// }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		if n%2 == 0 {
			for i := 1; i < n; i += 2 {
				fmt.Fprintf(out, "%d %d ", i+1, i)
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintf(out, "%d ", 1)
			for i := 2; i < n; i += 2 {
				fmt.Fprintf(out, "%d %d ", i+1, i)
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1712A
Date: 8/20/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1712/B
Problem: CF1712A
**/
func (in *CF1712A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		if n == 1 {
			fmt.Println(1)
		} else if n >= 2 {
			for i := 1; i <= n; i += 2 {
				fmt.Print(i+1, i, " ")
			}
			fmt.Println()
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1712A
Date: 8/20/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1712/B
Problem: CF1712A
**/
func (in *CF1712A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		arr := make([]bool, n+1)
		if n == 1 {
			fmt.Println(1)
		} else if n >= 2 {
			fmt.Print(2, 1, " ")
			arr[2] = true
			arr[1] = true

			for i := 3; i < n; i++ {
				for j := 3; j < len(arr); j++ {
					if i%j != 0 && !arr[j] {
						fmt.Print(j, " ")
						arr[j] = true
					}
				}
			}
			fmt.Println()
		}
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1712A
Date: 8/20/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1712/B
Problem: CF1712A
**/
func (in *CF1712A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()

		if n == 1 {
			fmt.Print(1)
		}

		if n >= 2 {
			fmt.Print(2, 1)
		}
		for i := n; i >= 3; i-- {
			fmt.Print(i, " ")
		}
		fmt.Println()
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1712A
Date: 8/20/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1712/B
Problem: CF1712A
**/
func (in *CF1712A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		for i := 1; i <= n; i++ {
			fmt.Print(i, " ")
		}
		fmt.Println()
	}
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1712A
Date: 8/20/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1712/B
Problem: CF1712A
**/
func (in *CF1712A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		for i := n; i > 0; i-- {
			fmt.Print(i, " ")
		}
		fmt.Println()
	}
}

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

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

package main

import "fmt"

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}
func lcm(x, y int) int {
	return x / gcd(x, y) * y
}
func main() {
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Scan(&n)
		for i := 0; i < n; i++ {
			fmt.Printf("%v ", (i-1+n)%n+1)
		}
		fmt.Println("")
	}

}

package main

import "fmt"

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}
func lcm(x, y int) int {
	return x / gcd(x, y) * y
}
func main() {
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Scan(&n)
		for i := 1; i <= n; i++ {
			fmt.Printf("%v ", (i)%n+1)
		}
		fmt.Println("")
	}

}

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	fmt.Fprint(out, n, " ")
	for i := 1; i < n; i++ {
		fmt.Fprint(out, i, " ")
	}
	fmt.Fprintln(out)
}

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

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

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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

package main

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

const cf = true

func solve() {
	var n int
	fmt.Fscan(in, &n)
	for i := 2; i <= n; i++ {
		fmt.Fprint(out, i, " ")
	}
	fmt.Fprintln(out, "1 ")
}

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

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

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

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

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

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

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

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

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

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

var exists = struct{}{}

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

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

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

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

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

type Ordered interface {
	Integer | Float | ~string
}

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

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

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

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

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

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for j:=0;j<t;j++{
		var n int
		fmt.Fscan(in,&n)
		for k:=1;k<=n;k+=2{
			fmt.Fprintf(out,"%v %v ",k+1,k)
		}
		fmt.Fprintln(out,)
	}
}

package main

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

func readLine() string {
	s, err := in.ReadString('\n')
	if err != nil {
		panic(err)
	}
	s = strings.ReplaceAll(s, "\n", "")
	s = strings.ReplaceAll(s, "\r", "")
	return s
}

func readLines(n int) []string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = readLine()
	}
	return res
}

func readInt() int {
	n, err := strconv.ParseInt(readLine(), 10, 32)
	if err != nil {
		panic(err)
	}
	return int(n)
}

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

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

func readUint() uint64 {
	n, err := strconv.ParseUint(readLine(), 10, 64)
	if err != nil {
		panic(err)
	}
	return n
}

func readInts(n int) []int {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	arr := make([]int, n)
	for k, a := range as {
		x, _ := strconv.ParseInt(a, 10, 64)
		arr[k] = int(x)
	}
	return arr
}

func readStrings(n int) []string {
	s := readLine()
	as := strings.SplitN(s, " ", n)
	if len(as) != n {
		panic("invalid len")
	}
	return as
}

func arr(n, m int) [][]int {
	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
	}
	return a
}

var in = bufio.NewReader(os.Stdin)

func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t, n, temp int
	var ch byte
	t = readInt()
	for ; t != 0; t-- {
		n = readInt()
		for i := 1; i <= n; i++ {
			if i == n {
				ch = '\n'
			} else {
				ch = ' '
			}
			if i == 1 {
				temp = n
			} else {
				temp = i - 1
			}
			fmt.Fprintf(out, "%d%c", temp, ch)
		}
	}
}

package main

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

func main() {
	woefulPermutationRead()
}

func woefulPermutationRead() {
	in := bufio.NewReader(os.Stdin)
	var t int

	fmt.Fscan(in, &t)

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

		// solve
		res := woefulPermutation(n)
		fmt.Print(res[0])
		for j := 1; j < n; j++ {
			fmt.Printf(" %d", res[j])
		}
	}
}

func woefulPermutation(n int) []int {
	res := make([]int, n)
	for i := n - 1; i > 0; i -= 2 {
		res[i] = i
		res[i-1] = i + 1
	}
	if res[0] == 0 {
		res[0] = 1
	}
	return 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)

		for i := n; i >= 1; i-- {
			fmt.Fprintf(out, "%d ", i)
		}
		fmt.Fprintln(out)
	}
}

package main

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

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

func main() {
	defer out.Flush()

	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	fmt.Fprintf(out, "%d ", n)
	for i := 1; i < n; i++ {
		fmt.Fprintf(out, "%d ", i)
	}
	fmt.Fprintln(out)
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		n := readInt(input)
		for i := 2; i <= n; i++ {
			fmt.Print(i, " ")
		}
		fmt.Println(1)
	}
}

func solve(n int) int {
	return -1
}

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 readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return int64(n)
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}