You are given a permutation $$$p$$$ of $$$n$$$ integers $$$1$$$, $$$2$$$, ..., $$$n$$$ (a permutation is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once).Let's call some subsegment $$$p[l, r]$$$ of this permutation special if $$$p_l + p_r = \max \limits_{i = l}^{r} p_i$$$. Please calculate the number of special subsegments.

The first line contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$ ($$$1 \le p_i \le n$$$). All these integers are pairwise distinct.

Print the number of special subsegments of the given permutation.

NoteSpecial subsegments in the first example are $$$[1, 5]$$$ and $$$[1, 3]$$$.The only special subsegment in the second example is $$$[1, 3]$$$.

package main

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

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

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

const (
	N int = 2e5+3
)

type BIT struct {
	freq [N]int
}
func (bit *BIT) insert(x int, v int) {
	for x++; x<N; x+=x&-x {
		bit.freq[x] += v
	}
}
func (bit *BIT) query(x int) int {
	res := 0
	for x++; x>0; x-=x&-x {
		res += bit.freq[x]
	}
	return res
}
func (bit *BIT) nth(n int) int {
	x := 1<<30
	for step:=x>>1; step>0; step>>=1 {
		if x-step >= N || bit.freq[x-step] >= n {
			x -= step
		} else {
			n -= bit.freq[x-step]
		}
	}
	return x-1
}

var (
	n int
	nums [N]map[int]bool
	a, s, idx, m [N]int
)

func main() {
	// code GOes here

	scan(&n)

	nums[0] = make(map[int]bool)
	for i:=1; i<=n; i++ {
		scan(&a[i])
		idx[a[i]] = i
		s[i] = a[i]
		nums[0][a[i]] = true
		m[i] = 0
	}
	sort.Sort(sort.Reverse(sort.IntSlice(s[1:n+1])))

	var bit BIT
	bit.insert(0,1)
	bit.insert(n+1,1)

	ans := 0
	id := 1
	for _,v := range s[1:n+1] {
		i := idx[v]
		rank := bit.query(i)
		left := bit.nth(rank)
		right := bit.nth(rank+1)
		bit.insert(i,1)

		nums[id] = make(map[int]bool)
		if i-left < right-i {
			for j:=left+1; j<i; j++ {
				nums[id][a[j]] = true
				nums[m[i]][a[j]] = false
				m[j] = id
			}
			for j:=left+1; j<i; j++ {
				if nums[m[i]][v-a[j]] == true {
					ans++
				}
			}
		} else {
			for j:=i+1; j<right; j++ {
				nums[id][a[j]] = true
				nums[m[i]][a[j]] = false
				m[j] = id
			}
			for j:=i+1; j<right; j++ {
				if nums[m[i]][v-a[j]] == true {
					ans++
				}
			}
		}
		id++
	}

	print(ans, "\n")
	writer.Flush()
	return
}

package main

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

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

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

const (
	N int = 2e5+3
)

type BIT struct {
	freq [N]int
}
func (bit *BIT) insert(x int, v int) {
	for x++; x<N; x+=x&-x {
		bit.freq[x] += v
	}
}
func (bit *BIT) query(x int) int {
	res := 0
	for x++; x>0; x-=x&-x {
		res += bit.freq[x]
	}
	return res
}
func (bit *BIT) nth(n int) int {
	x := 1<<30
	for step:=x>>1; step>0; step>>=1 {
		if x-step >= N || bit.freq[x-step] >= n {
			x -= step
		} else {
			n -= bit.freq[x-step]
		}
	}
	return x-1
}

var (
	n int
	nums [N]map[int]bool
	a, s, idx, m [N]int
)

func main() {
	// code GOes here

	scan(&n)

	nums[0] = make(map[int]bool)
	for i:=1; i<=n; i++ {
		scan(&a[i])
		idx[a[i]] = i
		s[i] = a[i]
		nums[0][a[i]] = true
		m[i] = 0
	}
	sort.Sort(sort.Reverse(sort.IntSlice(s[1:n+1])))

	var bit BIT
	bit.insert(0,1)
	bit.insert(n+1,1)

	ans := 0
	id := 1
	for _,v := range s[1:n+1] {
		i := idx[v]
		rank := bit.query(i)
		left := bit.nth(rank)
		right := bit.nth(rank+1)
		bit.insert(i,1)

		nums[id] = make(map[int]bool)
		if i-left < right-i {
			for j:=left+1; j<i; j++ {
				nums[id][a[j]] = true
				nums[m[i]][a[j]] = false
			}
			for j:=left+1; j<i; j++ {
				if nums[m[i]][v-a[j]] == true {
					ans++
				}
			}
		} else {
			for j:=i+1; j<right; j++ {
				nums[id][a[j]] = true
				nums[m[i]][a[j]] = false
			}
			for j:=i+1; j<right; j++ {
				if nums[m[i]][v-a[j]] == true {
					ans++
				}
			}
		}
		id++
	}

	print(ans, "\n")
	writer.Flush()
	return
}


You are given an integer $$$n$$$ and an array $$$a_1, a_2, \ldots, a_n$$$. You should reorder the elements of the array $$$a$$$ in such way that the sum of $$$\textbf{MEX}$$$ on prefixes ($$$i$$$-th prefix is $$$a_1, a_2, \ldots, a_i$$$) is maximized.Formally, you should find an array $$$b_1, b_2, \ldots, b_n$$$, such that the sets of elements of arrays $$$a$$$ and $$$b$$$ are equal (it is equivalent to array $$$b$$$ can be found as an array $$$a$$$ with some reordering of its elements) and $$$\sum\limits_{i=1}^{n} \textbf{MEX}(b_1, b_2, \ldots, b_i)$$$ is maximized.$$$\textbf{MEX}$$$ of a set of nonnegative integers is the minimal nonnegative integer such that it is not in the set.For example, $$$\textbf{MEX}(\{1, 2, 3\}) = 0$$$, $$$\textbf{MEX}(\{0, 1, 2, 4, 5\}) = 3$$$.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \le n \le 100)$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(0 \le a_i \le 100)$$$.

For each test case print an array $$$b_1, b_2, \ldots, b_n$$$  — the optimal reordering of $$$a_1, a_2, \ldots, a_n$$$, so the sum of $$$\textbf{MEX}$$$ on its prefixes is maximized. If there exist multiple optimal answers you can find any.

package main

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

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

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

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

		unique := []int{}
		rest := []int{}
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			idx := sort.SearchInts(unique, v)
			if idx >= len(unique) {
				unique = append(unique, v)
			} else if unique[idx] != v {
				unique = append(unique[:idx], append([]int{v}, unique[idx:]...)...)
			} else {
				rest = append(rest, v)
			}
		}

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

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

		fmt.Fprintln(out)
	}
}

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)

		tally := make([]int, 101)
		var maxN, maxF int
		for i := 0; i < n; i++ {
			var v int
			fmt.Fscan(in, &v)

			if v > maxN {
				maxN = v
			}

			tally[v]++
			if tally[v] > maxF {
				maxF = tally[v]
			}
		}

		for i := 0; i < maxF; i++ {
			for j := 0; j <= maxN; j++ {
				if tally[j] > 0 {
					fmt.Fprintf(out, "%d ", j)
					tally[j]--
				}
			}
		}
		fmt.Fprintln(out)
	}
}

package main
import (
    "os"
    "fmt"
    "sort"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        a := make([]int, n)
        for i := range a {
            fmt.Fscan(rd, &a[i])
        }
        sort.Ints(a)
        var res []int
        for i := range a {
            if i == 0 || a[i] != a[i - 1] {
                res = append(res, a[i])
            }
        }
        for i := range a {
            if i > 0 && a[i] == a[i - 1] {
                res = append(res, a[i])
            }
        }
        for _, v := range res {
            fmt.Print(v, " ")
        }
        fmt.Println()
    }
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var T, n int
	var num, temp []int
	fmt.Scanf("%d\n", &T)
	temp = make([]int, 107)
	num = make([]int, 107)
	var count int = 0
	for i := 1; i <= T; i++ {
		count = 0
		fmt.Scanf("%d\n", &n)

		for j := 0; j < n; j++ {
			if j != n-1 {
				fmt.Scanf("%d", &num[j])
			} else {
				fmt.Scanf("%d\n", &num[j])
			}
		}
		sort.Ints(num[0:n])
		for j := 0; j < n; j++ {
			if j > 0 && num[j] == num[j-1] {
				temp[count] = num[j]
				count++
			} else {
				fmt.Printf("%d ", num[j])
			}
		}
		for j := 0; j < count; j++ {
			fmt.Printf("%d ", temp[j])
		}
		fmt.Println()
	}
}

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

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n := 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n)
		l, mex, o := 0, -1, map[int]int{}
		for j := 0; j < n; j++ {
			p := 0
			fmt.Fscan(f, &p)
			o[p]++
		}
		for {
			_, ok := o[l]
			if !ok {
				mex = l
				break
			}
			l++
		}
		if mex == -1 {
			mex = n
		}
		for j := 0; j < mex; j++ {
			fmt.Fprint(w, j, " ")
			o[j]--
		}
		for k, v := range o {
			if v > 0 {
				fmt.Fprint(w, strings.Repeat(fmt.Sprintf("%d ", k), v))
			}
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func solve(n int, a []int) string {
	x := make([]int, 101)
	for _, i := range a {
		x[i]++
	}
	k := ""
	for i := 0; i < 101; i++ {
		if x[i] > 0 {
			k += fmt.Sprintf("%d ", i)
			x[i]--
		}
	}
	for i := 0; i < 101; i++ {
		if x[i] > 0 {
			for j := 0; j < x[i]; j++ {
				k += fmt.Sprintf("%d ", i)
			}
		}
	}
	return k
}

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

package main

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

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

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

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

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

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

/**
 Run solve the problem CF1497A
 Date: 21/08/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1497/A
 Problem: CF1497A
**/
func (in *CF1497A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		arr := []int{}
		for i := 0; i < n; i++ {
			num := in.NextInt()
			arr = append(arr, num)
		}
		sort.Ints(arr)
		last := []int{}
		index := 0
		for i := 0; i < n-1; i++ {
			if arr[i] == arr[i+1] {
				num := arr[i]
				last = append(last, num)
				arr[i] = -1
				index++
			}
		}
		sort.Ints(arr)
		for i := index; i < n; i++ {
			fmt.Print(arr[i], " ")
		}
		for i := 0; i < len(last); i++ {
			fmt.Print(last[i], " ")
		}
		fmt.Println()
	}

}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		sort.Ints(a)
		tmp := make([]int, 0)
		fmt.Printf("%d ", a[0])
		for j := 1; j < n; j++ {
			if a[j] != a[j-1] {
				fmt.Printf("%d ", a[j])
			} else {
				tmp = append(tmp, a[j])
			}
		}
		for _, v := range tmp {
			fmt.Printf("%d ", v)
		}
		fmt.Println()
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		count := map[int]int{}
		b := make([]int, 0, n)

		for i := 0; i < n; i++ {
			a := ScanInt()
			count[a]++
		}

		for k := range count {
			b = append(b, k)
		}

		sort.Ints(b)

		for k, v := range count {
			for i := 1; i < v; i++ {
				b = append(b, k)
			}
		}

		fmt.Println(strings.Trim(fmt.Sprint(b), "[]"))
	}
}

package main
import (
	"fmt"
	"bufio"
 	"os"
)

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

func main() {
	defer out.Flush()

	var testc uint64
	fmt.Fscan(in, &testc)
	for ; testc > 0; testc-- {
		var n int
		var counts [101]int
		fmt.Fscan(in, &n)
		for i := 0; i < n; i ++ {
			var d int
			fmt.Fscan(in, &d)
			counts[d]++
		}
		for i := 0; i <= 100; i++ {
			if counts[i] > 0 {
				fmt.Fprintf(out, "%d ", i)
				counts[i] --
			}
		}
		for i := 0; i <= 100; i++ {
			for counts[i] > 0 {
				fmt.Fprintf(out, "%d ", i)
				counts[i]--
			}
		}
		fmt.Fprintf(out, "\n")
	}
}

package main

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

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

func main() {
	defer writer.Flush()
	var testcases int
	fmt.Fscan(reader, &testcases)

	for testcase := 0; testcase < testcases; testcase++ {
		var n int
		fmt.Fscan(reader, &n)
		list := make([]int, n)
		for i := range list {
			fmt.Fscan(reader, &(list[i]))
		}
		sort.Slice(list, func(i, j int) bool { return list[i] < list[j] })

		num := 0
		buf := make([]int, 0)
		for i, v := range list {
			if v == num {
				num++
				buf = append(buf, i)
			}
		}

		relist := make([]int, 0, n)
		for i := range buf {
			relist = append(relist, i)
		}
		cnt := 0
		for i, v := range list {
			if cnt < len(buf) && i == buf[cnt] {
				cnt++
				continue
			}
			relist = append(relist, v)
		}

		s := fmt.Sprint(relist)
		fmt.Fprintln(writer, s[1:len(s)-1])
	}
}

package main
import (
    "fmt"
    "sort"
)
func main() {
    var t, n int
    var a[100] int
    var use[100] bool
    fmt.Scan(&t)
    for j := 1; j <= t; j++ {
        fmt.Scan(&n)
        for i := 0; i < n; i++ {
            fmt.Scan(&a[i])
            use[i] = false
        }
        sort.Ints(a[:n])
        fmt.Printf("%d", a[0])
        use[0] = true
        for i := 1; i < n; i++ {
            if a[i] > a[i - 1] {
                use[i] = true
                fmt.Printf(" %d", a[i])
            }
        }
        for i := 1; i < n; i++ {
            if !use[i] {
                fmt.Printf(" %d", a[i])
            }
        }
        fmt.Println()
    }
}

package main

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

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

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

func yes() {
	outln("YES")
}

func no() {
	outln("NO")
}

func remove_a(slice []int, s int) []int {
	return append(slice[:s], slice[s+1:]...)
}

func remove_s(s []rune, index int) []rune {
	return append(s[0:index], s[index+1:]...)
}

func in(a ...interface{})            { fmt.Fscan(reader, a...) }
func insf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func out(a ...interface{})            { fmt.Fprint(writer, a...) }
func outln(a ...interface{})          { fmt.Fprintln(writer, a...) }
func outf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func main() {
	defer writer.Flush()
	////////////////
	c := 0
	in(&c)
	for c != 0 {
		solve()
		c--
	}
	////////////////
}

func solve() {
	n := 0
	in(&n)
	m := make(map[int]int, 101)
	for i := 0; i < n; i++ {
		t := 0
		in(&t)
		m[t]++
	}
	for {
		if !o(m){
			outln()
			return
		}
	}
}

func o(m map[int]int) bool{
	b := false
	for i := 0; i < 101; i++ {
		if m[i] != 0 {
			out(i, " ")
			m[i]--
			b = true
		}
	}
	return b
}

package main

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

}

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)
		ARRAY := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])

		}
		sort.Ints(ARRAY)
		newARRAY := make([]int, 0)
		fmt.Println(ARRAY[0])
		for i := 1; i < n; i++ {
			if ARRAY[i] != ARRAY[i-1] {
				fmt.Println(ARRAY[i])
			} else {
				newARRAY = append(newARRAY, ARRAY[i])
			}
		}
		k := len(newARRAY)
		for j := 0; j < k; j++ {
			fmt.Println(newARRAY[j])
		}
	}
}

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(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		cnt := map[int]int{}
		for _, v := range a {
			cnt[v]++
		}
		for i := 0; i <= 100; i++ {
			if cnt[i] > 0 {
				cnt[i]--
				Fprint(out, i, " ")
			}
		}
		for i, c := range cnt {
			for;c>0;c--{
				Fprint(out, i, " ")
			}
		}
		Fprintln(out, )
	}

	var t int
	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 (
    "os"
    "fmt"
    "sort"
    "bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
    q := 0
    fmt.Fscan(rd, &q)
    for t := 0; t < q; t++ {
        n := 0
        fmt.Fscan(rd, &n)
        a := make([]int, n)
        for i := range a {
            fmt.Fscan(rd, &a[i])
        }
        sort.Ints(a)
        var res []int
        for i := range a {
            if i == 0 || a[i] != a[i - 1] {
                res = append(res, a[i])
            }
        }
        for i := range a {
            if i > 0 && a[i] == a[i - 1] {
                res = append(res, a[i])
            }
        }
        for _, v := range a {
            fmt.Print(v, " ")
        }
        fmt.Println()
    }
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var T, n int
	var num, temp []int
	fmt.Scanf("%d\n", &T)
	for i := 1; i <= T; i++ {
		fmt.Scanf("%d\n", &n)
		num = make([]int, n)
		temp = make([]int, 0)
		for j := 0; j < n; j++ {
			fmt.Scanf("%d", &num[j])
		}
		sort.Ints(num)
		lenN := len(num)
		for j := 0; j < lenN; j++ {
			if j > 0 && num[j] == num[j-1] {
				temp = append(temp, num[j])
			} else {
				fmt.Printf("%d ", num[j])
			}
		}
		lenT := len(temp)
		for j := 0; j < lenT; j++ {
			fmt.Printf("%d ", temp[j])
		}
		fmt.Println()
	}
}


You are given a square grid with $$$n$$$ rows and $$$n$$$ columns. Each cell contains either $$$0$$$ or $$$1$$$. In an operation, you can select a cell of the grid and flip it (from $$$0 \to 1$$$ or $$$1 \to 0$$$). Find the minimum number of operations you need to obtain a square that remains the same when rotated $$$0^{\circ}$$$, $$$90^{\circ}$$$, $$$180^{\circ}$$$ and $$$270^{\circ}$$$.The picture below shows an example of all rotations of a grid.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the size of the grid. Then $$$n$$$ lines follow, each with $$$n$$$ characters $$$a_{i,j}$$$ ($$$0 \leq a_{i,j} \leq 1$$$) — the number written in each cell.

For each test case output a single integer  — the minimum number of operations needed to make the square look the same rotated $$$0^{\circ}$$$, $$$90^{\circ}$$$, $$$180^{\circ}$$$ and $$$270^{\circ}$$$.

NoteIn the first test case, we can perform one operations to make the grid $$$\begin{matrix}0 & 1 & 0\\ 1 & 1 & \color{red}{1}\\ 0 & 1 & 0\end{matrix}$$$. Now, all rotations of the square are the same.In the second test case, all rotations of the square are already the same, so we don't need any flips.

package main

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

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

func Read[T any]() T{
	var i T
	fmt.Fscan(in, &i)
	return i
}

func ReadArray[T any](N int) []T{
	ans := make([]T, N)
	for i := 0; i < N; i++{
		ans[i] = Read[T]()
	}
	return ans
}

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

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
const N int = 101
func solve() {
	n := Read[int]()
	var arr [N]string

	for i := 0; i < n; i++ {
		arr[i] = Read[string]()
	}

	dive := n / 2
	if n & 1 == 0 {
		dive--
	}

	ans := 0
	for i := 0; i <= dive; i++ {
		var slices [4][]byte

		for j := i; j < n - i; j++ {
			slices[0] = append(slices[0], arr[i][j])
			slices[2] = append(slices[2], arr[n - (i + 1)][n - (j + 1)])

			slices[1] = append(slices[1], arr[j][n - (i + 1)])
			slices[3] = append(slices[3], arr[n - (j + 1)][i])
		}

		// fmt.Fprintln(out, slices)
		tmp_ans := 0

		ln := len(slices[0])
		for j := 0; j < ln - 1; j++ {
			zero := 0
			one := 0

			for k := 0; k < 4; k++ {
				if slices[k][j] == 48 {
					zero++
				} else {
					one++
				}
			}

			tmp_ans += Min(one, zero)
		}
		ans += tmp_ans
	}

	fmt.Fprintln(out, ans)

}
func main(){
	defer out.Flush()
	tt := 1
	tt = Read[int]()
	for tt > 0 {
		solve()
		tt--
	}
}

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)
		b := make([]string, n)
		for i := range b {
			fmt.Fscan(r, &b[i])
		}
		w1 := do(b)
		fmt.Fprintln(w, w1)
	}
}

func do(s []string) int {
	b := make([][]byte, len(s))
	for i := range b {
		b[i] = []byte(s[i])
	}
	n := len(b)
	d := n - 1
	v := make([][]int, 4)
	ans := 0
	for i := 0; i <= n/2; i++ {
		for j := 0; j <= n/2; j++ {
			v[0] = []int{i*2 - d, j*2 - d}
			v[1] = []int{v[0][1], -v[0][0]}
			v[2] = []int{-v[0][0], -v[0][1]}
			v[3] = []int{-v[1][0], -v[1][1]}
			c := 0
			for _, v := range v {
				v[0] = (v[0] + d) / 2
				v[1] = (v[1] + d) / 2
				if b[v[0]][v[1]] == '1' {
					c++
				}
			}
			e := byte('0')
			if c > 2 {
				ans += 4 - c
			} else {
				ans += c
				e = '1'
			}
			for _, v := range v {
				b[v[0]][v[1]] = e
			}
		}
	}
	return ans
}

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)
		grid := make([]string, n)
		for i := 0; i < n; i++ {
			grid[i] = readString(reader)
		}
		res := solve(grid)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	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(grid []string) int {
	n := len(grid)

	var res int

	cnt := make([]int, 2)

	for i := 0; i < n/2; i++ {
		for j := 0; j < n/2; j++ {
			// (i, j) => (u, v)

			for k := 0; k < 2; k++ {
				cnt[k] = 0
			}
			u, v := i, j
			cnt[int(grid[u][v]-'0')]++
			u, v = v, n-1-u
			cnt[int(grid[u][v]-'0')]++
			u, v = v, n-1-u
			cnt[int(grid[u][v]-'0')]++
			u, v = n-1-j, i
			cnt[int(grid[u][v]-'0')]++
			res += 4 - max(cnt[0], cnt[1])
		}
	}

	if n&1 == 1 {
		for r := 0; r < n/2; r++ {
			cnt[0] = 0
			cnt[1] = 0
			cnt[int(grid[r][n/2]-'0')]++
			cnt[int(grid[n-1-r][n/2]-'0')]++
			cnt[int(grid[n/2][r]-'0')]++
			cnt[int(grid[n/2][n-1-r]-'0')]++
			res += 4 - max(cnt[0], cnt[1])
		}
	}

	return res
}

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

package main

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

const mod = 998244353
const mx = int64(1e9 + 7)

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	Fscan(in, &n)
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		var s string
		Fscan(in, &s)
		for j := 0; j < n; j++ {
			arr[i][j] = int(s[j] - '0')
		}
	}
	ans := 0
	for i := 0; i < (n+1)/2; i++ {
		for j := 0; j < n/2; j++ {
			o := arr[i][j] + arr[j][n-1-i] + arr[n-1-i][n-1-j] + arr[n-1-j][i]
			z := 4 - o
			if o <= z {
				ans += o
			} else {
				ans += z
			}
		}
	}
	Fprintln(out, ans)
}

func abs(a int64) int64 {
	if a > 0 {
		return a
	}
	return -a
}
func sum(a, b int64) int64 {
	return (b + a) * (b - a + 1) / 2
}

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

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

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

func ReadInt() int{
	var i int
	fmt.Fscan(in, &i)
	return i
}

func ReadIntArray(N int) []int{
	ans := make([]int, N)
	for i := 0; i < N; i++{
		ans[i] = ReadInt()
	}
	return ans
}

func ReadString() string{
	var s string
	fmt.Fscan(in, &s)
	return s
}

func ReadStringArray(N int) []string{
	ans := make([]string, N)
	for i := 0; i < N; i++{
		ans[i] = ReadString()
	}
	return ans
}

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

func main(){
	defer out.Flush()
	testCases := ReadInt()
	for ; testCases > 0; testCases--{
		N := ReadInt()
		board := ReadStringArray(N)
		tot := 0
		for r := 0; r < (N + 1) / 2; r++{
			for c := 0; c < N / 2; c++{
				ones := int((board[r][c] - '0') +
							(board[c][N - 1 - r] - '0') +
							(board[N - 1 - r][N - 1 - c] - '0') +
							(board[N - 1 - c][r] - '0'))
				tot += Min(ones, 4 - ones)
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(rr, &n)
	grid := make([]string, n)
	for i := range grid {
		fmt.Fscan(rr, &grid[i])
	}
	ans := 0
	for i:=0;i<n/2;i++ {
		for j:=0;j<n/2;j++ {
			cur := int(grid[i][j]) + int(grid[n-j-1][i]) + int(grid[n-i-1][n-j-1]) + int(grid[j][n-i-1])
			cur -= '0' * 4
			ans += min(cur, 4-cur)
		}
	}
	if n % 2 == 1 {
		for i:=0;i<n/2;i++ {
			cur := int(grid[i][n/2]) + int(grid[n-n/2-1][i]) + int(grid[n-i-1][n-n/2-1]) + int(grid[n/2][n-i-1])
			cur -= '0' * 4
			ans += min(cur, 4-cur)
		}
	}

	fmt.Fprintln(ww, ans)
}

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

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([][]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		ans := 0
		for i := 0; i < n/2; i++ {
			for j := 0; j < (n+1)/2; j++ {
				cnt := int(a[i][j]&1 + a[j][n-1-i]&1 + a[n-1-i][n-1-j]&1 + a[n-1-j][i]&1)
				ans += min(cnt, 4-cnt)
			}
		}
		Fprintln(out, ans)
	}
}

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

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

// 00
package main

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

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

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([]string, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		ans := 0

		rows := n / 2
		cols := n / 2
		if n%2 == 1 {
			cols++
		}
		for i := 0; i < rows; i++ {
			for j := 0; j < cols; j++ {
				count := 0
				if a[i][j] == '1' {
					count++
				}
				if a[j][n-1-i] == '1' {
					count++
				}
				if a[n-1-i][n-1-j] == '1' {
					count++
				}
				if a[n-1-j][i] == '1' {
					count++
				}
				ans += min(count, 4-count)
				//				fmt.Println(count, 4-count)
			}
		}

		fmt.Println(ans)
	}
}

package main

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

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

func Read[T any]() T{
	var i T
	fmt.Fscan(in, &i)
	return i
}

func ReadArray[T any](N int) []T{
	ans := make([]T, N)
	for i := 0; i < N; i++{
		ans[i] = Read[T]()
	}
	return ans
}

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

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
const N int = 101
func solve() {
	n := Read[int]()
	var arr [N]string

	for i := 0; i < n; i++ {
		arr[i] = Read[string]()
	}

	dive := n / 2
	if n & 1 == 0 {
		dive--
	}

	ans := 0
	for i := 0; i < dive; i++ {
		var slices [4][]byte

		for j := i; j < n - i; j++ {
			slices[0] = append(slices[0], arr[i][j])
			slices[2] = append(slices[2], arr[n - (i + 1)][n - (j + 1)])

			slices[1] = append(slices[1], arr[j][n - (i + 1)])
			slices[3] = append(slices[3], arr[n - (j + 1)][i])
		}

		tmp_ans := 0

		ln := len(slices[0])
		for j := 0; j < ln - 1; j++ {
			zero := 0
			one := 0

			for k := 0; k < 4; k++ {
				if slices[k][j] == 48 {
					zero++
				} else {
					one++
				}
			}

			tmp_ans += Min(one, zero)
		}
		ans += tmp_ans
	}

	fmt.Fprintln(out, ans)

}
func main(){
	defer out.Flush()
	tt := 1
	tt = Read[int]()
	for tt > 0 {
		solve()
		tt--
	}
}


You are given a sequence $$$a$$$ of length $$$n$$$ consisting of $$$0$$$s and $$$1$$$s.You can perform the following operation on this sequence:   Pick an index $$$i$$$ from $$$1$$$ to $$$n-2$$$ (inclusive).  Change all of $$$a_{i}$$$, $$$a_{i+1}$$$, $$$a_{i+2}$$$ to $$$a_{i} \oplus a_{i+1} \oplus a_{i+2}$$$ simultaneously, where $$$\oplus$$$ denotes the bitwise XOR operation  Find a sequence of at most $$$n$$$ operations that changes all elements of $$$a$$$ to $$$0$$$s or report that it's impossible.We can prove that if there exists a sequence of operations of any length that changes all elements of $$$a$$$ to $$$0$$$s, then there is also such a sequence of length not greater than $$$n$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 2\cdot10^5$$$) — the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i = 0$$$ or $$$a_i = 1$$$) — elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, do the following:    if there is no way of making all the elements of $$$a$$$ equal to $$$0$$$ after performing the above operation some number of times, print "NO".  otherwise, in the first line print "YES", in the second line print $$$k$$$ ($$$0 \le k \le n$$$) — the number of operations that you want to perform on $$$a$$$, and in the third line print a sequence $$$b_1, b_2, \dots, b_k$$$ ($$$1 \le b_i \le n - 2$$$) — the indices on which the operation should be applied.  If there are multiple solutions, you may print any.

NoteIn the first example, the sequence contains only $$$0$$$s so we don't need to change anything.In the second example, we can transform $$$[1, 1, 1, 1, 0]$$$ to $$$[1, 1, 0, 0, 0]$$$ and then to $$$[0, 0, 0, 0, 0]$$$ by performing the operation on the third element of $$$a$$$ and then on the first element of $$$a$$$.In the third example, no matter whether we first perform the operation on the first or on the second element of $$$a$$$ we will get $$$[1, 1, 1, 1]$$$, which cannot be transformed to $$$[0, 0, 0, 0]$$$.

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		x, p := 0, 0
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			x ^= v
			if x == 0 && i&1 == 0 {
				p = i + 1
			}
		}
		if x > 0 || p == 0 {
			Fprintln(out, "NO")
			continue
		}
		Fprintln(out, "YES")
		ans := []int{}
		for i := 1; i < p; i += 2 {
			ans = append(ans, i)
		}
		for i := p + 1; i < n-1; i += 2 {
			ans = append(ans, i)
		}
		Fprintln(out, len(ans)*2)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		for i := len(ans) - 1; i >= 0; i-- {
			Fprint(out, ans[i], " ")
		}
		Fprintln(out)
	}
}

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


Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?You are given a set of digits, your task is to find the maximum integer that you can make from these digits. The made number must be divisible by 2, 3, 5 without a residue. It is permitted to use not all digits from the set, it is forbidden to use leading zeroes.Each digit is allowed to occur in the number the same number of times it occurs in the set.

A single line contains a single integer n (1 ≤ n ≤ 100000) — the number of digits in the set. The second line contains n digits, the digits are separated by a single space.

On a single line print the answer to the problem. If such number does not exist, then you should print -1.

NoteIn the first sample there is only one number you can make — 0. In the second sample the sought number is 5554443330. In the third sample it is impossible to make the required number.

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func diminish(count []int, k int) bool {
	for d := k; d < 10; d += 3 {
		if count[d] > 0 {
			count[d] -= 1
			return true
		}
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	count := make([]int, 10)
	sum := 0
	for i := 0; i < n; i++ {
		x := scanInt(scanner)
		count[x] += 1
		sum += x
	}
	if count[0] == 0 {
		writer.WriteString("-1\n")
		return
	}
	if sum%3 == 1 {
		if !diminish(count, 1) {
			if !diminish(count, 2) || !diminish(count, 2) {
				writer.WriteString("0\n")
				return
			}
		}
	} else if sum%3 == 2 {
		if !diminish(count, 2) {
			if !diminish(count, 1) || !diminish(count, 1) {
				writer.WriteString("0\n")
				return
			}
		}
	}
	max := 0
	for d := 0; d < 10; d++ {
		if count[d] > 0 {
			max = d
		}
	}
	if max == 0 {
		writer.WriteString("0\n")
		return
	}
	for d := 9; d >= 0; d-- {
		for i := 0; i < count[d]; i++ {
			writer.WriteString(fmt.Sprintf("%d", d))
		}
	}
	writer.WriteString("\n")
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func diminish(count []int, k int) bool {
	for d := k; d < 10; d += 3 {
		if count[d] > 0 {
			count[d] -= 1
			return true
		}
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	count := make([]int, 10)
	sum := 0
	for i := 0; i < n; i++ {
		x := scanInt(scanner)
		count[x] += 1
		sum += x
	}
	if count[0] == 0 {
		writer.WriteString("-1\n")
		return
	}
	max := 0
	for d := 0; d < 10; d++ {
		if count[d] > 0 {
			max = d
		}
	}
	if max == 0 {
		writer.WriteString("0\n")
		return
	}
	if sum%3 == 1 {
		if !diminish(count, 1) {
			if !diminish(count, 2) || !diminish(count, 2) {
				writer.WriteString("-1\n")
				return
			}
		}
	} else if sum%3 == 2 {
		if !diminish(count, 2) {
			if !diminish(count, 1) || !diminish(count, 1) {
				writer.WriteString("-1\n")
				return
			}
		}
	}
	for d := 9; d >= 0; d-- {
		for i := 0; i < count[d]; i++ {
			writer.WriteString(fmt.Sprintf("%d", d))
		}
	}
	writer.WriteString("\n")
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func diminish(count []int, k int) bool {
	for d := k; d < 10; d += 3 {
		if count[d] > 0 {
			count[d] -= 1
			return true
		}
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	count := make([]int, 10)
	sum := 0
	for i := 0; i < n; i++ {
		x := scanInt(scanner)
		count[x] += 1
		sum += x
	}
	if count[0] == 0 {
		writer.WriteString("-1\n")
		return
	}
	if sum%3 == 1 {
		if !diminish(count, 1) {
			if !diminish(count, 2) || !diminish(count, 2) {
				writer.WriteString("-1\n")
				return
			}
		}
	} else if sum%3 == 2 {
		if !diminish(count, 2) {
			if !diminish(count, 1) || !diminish(count, 1) {
				writer.WriteString("-1\n")
				return
			}
		}
	}
	for d := 9; d >= 0; d-- {
		for i := 0; i < count[d]; i++ {
			writer.WriteString(fmt.Sprintf("%d", d))
		}
	}
	writer.WriteString("\n")
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func diminish(count []int, k int) bool {
	for d := k; d < 10; d += 3 {
		if count[d] > 0 {
			count[d] -= 1
			return true
		}
	}
	return false
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	count := make([]int, 10)
	sum := 0
	for i := 0; i < n; i++ {
		x := scanInt(scanner)
		count[x] += 1
		sum += x
	}
	if count[0] == 0 {
		writer.WriteString("-1\n")
		return
	}
	max := 0
	for d := 0; d < 10; d++ {
		if count[d] > 0 {
			max = d
		}
	}
	if max == 0 && count[0] != 1 {
		writer.WriteString("-1\n")
		return
	}
	if sum%3 == 1 {
		if !diminish(count, 1) {
			if !diminish(count, 2) || !diminish(count, 2) {
				writer.WriteString("-1\n")
				return
			}
		}
	} else if sum%3 == 2 {
		if !diminish(count, 2) {
			if !diminish(count, 1) || !diminish(count, 1) {
				writer.WriteString("-1\n")
				return
			}
		}
	}
	for d := 9; d >= 0; d-- {
		for i := 0; i < count[d]; i++ {
			writer.WriteString(fmt.Sprintf("%d", d))
		}
	}
	writer.WriteString("\n")
}


Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct positions in the array. Also note that Petya must swap some two integers even if the original array meets all requirements.Array a (the array elements are indexed from 1) consisting of n elements is called sorted if it meets at least one of the following two conditions:  a1 ≤ a2 ≤ ... ≤ an;  a1 ≥ a2 ≥ ... ≥ an. Help Petya find the two required positions to swap or else say that they do not exist.

The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n non-negative space-separated integers a1, a2, ..., an — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109.

If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to n.

NoteIn the first two samples the required pairs obviously don't exist.In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted.

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
	}
	a, b := -1, -1
	for i := 1; i < n; i++ {
		if arr[i-1] == arr[i] {
			continue
		}
		arr[i-1], arr[i] = arr[i], arr[i-1]
		up, down := true, true
		for j := 1; j < n; j++ {
			if arr[j-1] < arr[j] {
				down = false
			}
			if arr[j-1] > arr[j] {
				up = false
			}
		}
		if !up && !down {
			a, b = i-1, i
			break
		}
		arr[i-1], arr[i] = arr[i], arr[i-1]
	}
	if a == -1 && b == -1 {
		writer.WriteString("-1\n")
	} else {
		writer.WriteString(fmt.Sprintf("%d %d\n", a+1, b+1))
	}
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	arr := make([]int, n)
	minI, maxI := 0, 0
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
		if arr[i] < arr[minI] {
			minI = i
		}
		if arr[i] > arr[maxI] {
			maxI = i
		}
	}
	ordered := true
	a, b := -1, -1
	for i := 2; ordered && i < n; i++ {
		if arr[minI] != arr[i-1] {
			arr[i-1], arr[minI] = arr[minI], arr[i-1]
			if arr[i-1] < arr[i-2] && arr[i-1] < arr[i] {
				ordered = false
				a, b = minI, i-1
			}
			arr[i-1], arr[minI] = arr[minI], arr[i-1]
		}
		if arr[maxI] != arr[i-1] {
			arr[i-1], arr[maxI] = arr[maxI], arr[i-1]
			if arr[i-1] > arr[i-2] && arr[i-1] > arr[i] {
				ordered = false
				a, b = maxI, i-1
			}
			arr[i-1], arr[maxI] = arr[maxI], arr[i-1]
		}
	}
	if ordered {
		writer.WriteString("-1\n")
	} else {
		writer.WriteString(fmt.Sprintf("%d %d\n", a+1, b+1))
	}
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
	}
	a, b := -1, -1
	for i := 1; i < n; i++ {
		if arr[i-1] == arr[i] {
			continue
		}
		arr[i-1], arr[i] = arr[i], arr[i-1]
		up, down := true, true
		for j := 1; j < n; j++ {
			if arr[j-1] < arr[j] {
				down = false
			}
			if arr[j-1] > arr[j] {
				up = false
			}
		}
		if !up && !down {
			a, b = i-1, i
		}
		break
	}
	if a == -1 && b == -1 {
		writer.WriteString("-1\n")
	} else {
		writer.WriteString(fmt.Sprintf("%d %d\n", a+1, b+1))
	}
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
	}
	a, b := -1, -1
	for i := 1; i < n; i++ {
		if arr[i-1] == arr[i] {
			continue
		}
		arr[i-1], arr[i] = arr[i], arr[i-1]
		up, down := true, true
		for j := 1; j < n; j++ {
			if arr[j-1] < arr[j] {
				down = false
			}
			if arr[j-1] > arr[j] {
				up = false
			}
		}
		if !up && !down {
			a, b = i-1, i
			break
		}
	}
	if a == -1 && b == -1 {
		writer.WriteString("-1\n")
	} else {
		writer.WriteString(fmt.Sprintf("%d %d\n", a+1, b+1))
	}
}


Local authorities have heard a lot about combinatorial abilities of Ostap Bender so they decided to ask his help in the question of urbanization. There are n people who plan to move to the cities. The wealth of the i of them is equal to ai. Authorities plan to build two cities, first for n1 people and second for n2 people. Of course, each of n candidates can settle in only one of the cities. Thus, first some subset of candidates of size n1 settle in the first city and then some subset of size n2 is chosen among the remaining candidates and the move to the second city. All other candidates receive an official refuse and go back home.To make the statistic of local region look better in the eyes of their bosses, local authorities decided to pick subsets of candidates in such a way that the sum of arithmetic mean of wealth of people in each of the cities is as large as possible. Arithmetic mean of wealth in one city is the sum of wealth ai among all its residents divided by the number of them (n1 or n2 depending on the city). The division should be done in real numbers without any rounding.Please, help authorities find the optimal way to pick residents for two cities.

The first line of the input contains three integers n, n1 and n2 (1 ≤ n, n1, n2 ≤ 100 000, n1 + n2 ≤ n) — the number of candidates who want to move to the cities, the planned number of residents of the first city and the planned number of residents of the second city. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 100 000), the i-th of them is equal to the wealth of the i-th candidate.

Print one real value — the maximum possible sum of arithmetic means of wealth of cities' residents. You 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 .

NoteIn the first sample, one of the optimal solutions is to move candidate 1 to the first city and candidate 2 to the second.In the second sample, the optimal solution is to pick candidates 3 and 4 for the first city, and candidate 2 for the second one. Thus we obtain (a3 + a4) / 2 + a2 = (3 + 2) / 2 + 4 = 6.5

package main

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

func solve() {
    n, n1, n2 := readInt(), readInt(), readInt()
    a := readIntArray(n)
    sort.Sort(sort.Reverse(sort.IntSlice(a)))
    mean := func(l, r int) float64 {
        sum := float64(0)
        for i := l; i < r; i++ {
            sum += float64(a[i])
        }
        return sum / float64(r-l)
    }
    ans := mean(0, n1) + mean(n1, n1+n2)
    if s2 := mean(0, n2) + mean(n2, n1+n2); s2 > ans {
        ans = s2
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

// Math

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

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

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

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, n1, n2 int
	var sum1, sum2 int64
	fmt.Scan(&n, &n1, &n2);
	arr := make([]int, n)
	if n1 > n2 {
		tmp := n1;
		n1 = n2;
		n2 = tmp;
	}

	for i := 0; i < n; i++ {
		fmt.Scan(&(arr[i]))
	}
	sort.Ints(arr)
	for i := 0; i < n1; i++ {
		sum1 += int64(arr[n - 1 - i]);
	}
	for i := n1; i < n1 + n2; i++ {
		sum2 += int64(arr[n - 1 - i]);
	}
	fmt.Println(float64(sum1)/float64(n1) + float64(sum2)/float64(n2))
}

package main

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

func main() {
	var n int
	var c [2]int
	if _, err := fmt.Scanf("%d %d %d\n", &n, &c[0], &c[1]); err != nil {
		return
	}

	w := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		w[i] = a
	}

	merge_sort(w, 0, n-1)
	if c[0] > c[1] {
		c[0], c[1] = c[1], c[0]
	}

	var sum [2]int64
	p := 0
	for i := 0; i < 2; i++ {
		for j := 0; j < c[i]; j++ {
			sum[i] += int64(w[p])
			p++
		}
	}

	mean := float64(sum[0])/float64(c[0]) + float64(sum[1])/float64(c[1])

	fmt.Printf("%.8f\n", mean)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] >= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

import "fmt"
import "sort"

func main() {
	var n, n1, n2 int
	fmt.Scan(&n, &n1, &n2)
	wealth := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&wealth[i])
	}
	if n1 > n2 {
		n1, n2 = n2, n1
	}
	sort.Ints(wealth)
	sum := float64(0)
	for i := n - 1; i >= n-n1; i-- {
		sum += float64(wealth[i])
	}
	ans := sum / float64(n1)
	sum = float64(0)
	for i := n - n1 - 1; i >= n-n2-n1; i-- {
		sum += float64(wealth[i])
	}
	ans += sum / float64(n2)
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"io/ioutil"
	"os"
	"path/filepath"
	"runtime"
	"sort"
	"strings"
)

func main() {
	b, _ := ioutil.ReadAll(os.Stdin)
	if len(b) == 0 {
		test()
	} else {
		solve(bytes.NewReader(b), os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n, n1, n2 int
	fmt.Fscanln(r, &n, &n1, &n2)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &as[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(as)))

	if n1 > n2 {
		n1, n2 = n2, n1
	}

	n1score := float64(0)
	for i := 0; i < n1; i++ {
		n1score += float64(as[i])
	}
	n1score /= float64(n1)

	n2score := float64(0)
	for i := 0; i < n2; i++ {
		n2score += float64(as[i+n1])
	}
	n2score /= float64(n2)

	fmt.Fprintln(w, n1score+n2score)
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `
2 1 1
1 5
`,
			want: `6.00000000`,
		},
		{
			in: `
4 2 1
1 4 2 3
`,
			want: `6.50000000`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(chomp(tt.in)), buf)
		if got, want := chomp(buf.String()), chomp(tt.want); got != want {
			fmt.Printf("%d: got %v, want %v\n", i, got, want)
		}
	}
}

func chomp(s string) string {
	return strings.Trim(s, "\n")
}

func assert(b bool) {
	if !b {
		_, file, line, ok := runtime.Caller(1)
		if ok {
			f, _ := os.Open(file)
			defer f.Close()
			s := bufio.NewScanner(f)
			lnum := 0
			for s.Scan() {
				lnum++
				if lnum == line {
					wd, _ := os.Getwd()
					fname, _ := filepath.Rel(wd, file)
					fmt.Printf("assertion fails: %s:%d: %v\n", fname, line, s.Text())
					break
				}
			}
		}
	}
}

func pow(a, b int) int {
	r := 1
	for i := 0; i < b; i++ {
		r *= a
	}
	return r
}

// Codeforces 735 B Urbanization, uses sort
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
	"sort"
)
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 n,n1,n2 int
var a []int
var maxSum float64

func readData() {
	in = bufio.NewReader(os.Stdin)
	// reading field
	n,n1,n2,_,_ = readFive()
	a = readLineNumbs(n)
}

func solve() {
	ra := sort.Reverse(sort.IntSlice(a))
	sort.Sort(ra)
	if n1>n2 {
		n1,n2 = n2,n1
	}
	// count max sum
	maxSum = 0
	var i int
	var sum1,sum2 float64
	sum1=0
	for i=0; i<n1; i++ {
		sum1 += float64(a[i])
	}
	sum2=0
	for i=0; i<n2; i++ {
		sum2 += float64(a[n1+i])
	}
	maxSum = (sum1/float64(n1)) + (sum2/float64(n2))
}

func printRes() {
	fmt.Println(maxSum)
}

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

package main

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

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

	var f, n, n1 int
	fmt.Fscan(reader, &f, &n, &n1)

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

	sort.Ints(arr)

	fi := sm(arr[f-min(n, n1):])
	se := sm(arr[f-(n+n1) : f-min(n, n1)])

	fmt.Printf("%.8f", fi+se)
}

func sm(arr []int) float64 {
	var count int64
	for _, vl := range arr {
		count += int64(vl)
	}

	return float64(count) / float64(len(arr))
}

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

package main

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

func ave(v []float64) float64 {
	sm := float64(0)
	for i := 0; i < len(v); i++ {
		sm += v[i]
	}
	return float64(sm) / float64(len(v))
}

func main() {
	sc := NewScanner()
	n, n1, n2 := sc.NextInt(), sc.NextInt(), sc.NextInt()
	b := sc.NextInt64Array()
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = float64(b[i])
	}
	if n1 > n2 {
		n1, n2 = n2, n1
	}

	sort.Float64s(a)

	fmt.Println(ave(a[n - n1 - n2:n - n1]) + ave(a[n - n1:]))

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func solve() {
    n, n1, n2 := readInt(), readInt(), readInt()
    a := readIntArray(n)
    sort.Ints(a)
    mean := func(l, r int) float64 {
        sum := float64(0)
        for i := l; i < r; i++ {
            sum += float64(a[i])
        }
        return sum / float64(r-l)
    }
    ans := mean(0, n1) + mean(n1, n1+n2)
    if s2 := mean(0, n2) + mean(n2, n1+n2); s2 > ans {
        ans = s2
    }
    fmt.Println(ans)
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

// Math

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

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

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

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

// Sort

type Ints64 []int64

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

/* Sort tempalte
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

func main() {
	var n int
	var c [2]int
	if _, err := fmt.Scanf("%d %d %d\n", &n, &c[0], &c[1]); err != nil {
		return
	}

	w := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		w[i] = a
	}

	merge_sort(w, 0, n-1)
	if c[0] > c[1] {
		c[0], c[1] = c[1], c[0]
	}

	var sum [2]int
	p := 0
	for i := 0; i < 2; i++ {
		for j := 0; j < c[i]; j++ {
			sum[i] += w[p]
			p++
		}
	}

	mean := float64(sum[0]*c[1]+sum[1]*c[0]) / float64(c[0]*c[1])

	fmt.Printf("%1.8f\n", mean)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] >= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

func main() {
	var n int
	var c [2]int
	if _, err := fmt.Scanf("%d %d %d\n", &n, &c[0], &c[1]); err != nil {
		return
	}

	w := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		w[i] = a
	}

	merge_sort(w, 0, n-1)
	if c[0] > c[1] {
		c[0], c[1] = c[1], c[0]
	}

	var sum [2]int64
	p := 0
	for i := 0; i < 2; i++ {
		for j := 0; j < c[i]; j++ {
			sum[i] += int64(w[p])
			p++
		}
	}

	mean := float64(sum[0]*int64(c[1])+sum[1]*int64(c[0])) / float64(c[0]*c[1])

	fmt.Printf("%1.8f\n", mean)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] >= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

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

	var f, n, n1 int
	fmt.Fscan(reader, &f, &n, &n1)

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

	sort.Ints(arr)

	fi := sm(arr[f-n1:])
	se := sm(arr[f-(n+n1) : f-n1])

	fmt.Printf("%.6f", fi+se)
}

func sm(arr []int) float64 {
	var count int
	for _, vl := range arr {
		count += vl
	}

	return float64(count) / float64(len(arr))
}

package main

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

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

	var f, n, n1 int
	fmt.Fscan(reader, &f, &n, &n1)

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

	sort.Ints(arr)

	fi := sm(arr[f-min(n, n1):])
	se := sm(arr[f-(n+n1) : f-min(n, n1)])

	fmt.Printf("%.8f", fi+se)
}

func sm(arr []int) float64 {
	var count int
	for _, vl := range arr {
		count += vl
	}

	return float64(count) / float64(len(arr))
}

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

package main

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

func ave(v []int) float64 {
	sm := 0
	for i := 0; i < len(v); i++ {
		sm += v[i]
	}
	return float64(sm) / float64(len(v))
}

func main() {
	sc := NewScanner()
	n, n1, n2 := sc.NextInt(), sc.NextInt(), sc.NextInt()
	a := sc.NextIntArray()

	if n1 > n2 {
		n1, n2 = n2, n1
	}

	sort.Ints(a)

	fmt.Println(ave(a[n - n1 - n2:n - n1]) + ave(a[n - n1:]))

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


You are the owner of a harvesting field which can be modeled as an infinite line, whose positions are identified by integers.It will rain for the next $$$n$$$ days. On the $$$i$$$-th day, the rain will be centered at position $$$x_i$$$ and it will have intensity $$$p_i$$$. Due to these rains, some rainfall will accumulate; let $$$a_j$$$ be the amount of rainfall accumulated at integer position $$$j$$$. Initially $$$a_j$$$ is $$$0$$$, and it will increase by $$$\max(0,p_i-|x_i-j|)$$$ after the $$$i$$$-th day's rain.A flood will hit your field if, at any moment, there is a position $$$j$$$ with accumulated rainfall $$$a_j>m$$$.You can use a magical spell to erase exactly one day's rain, i.e., setting $$$p_i=0$$$. For each $$$i$$$ from $$$1$$$ to $$$n$$$, check whether in case of erasing the $$$i$$$-th day's rain there is no flood.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 10^4$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$, $$$1 \leq m \leq 10^9$$$) — the number of rainy days and the maximal accumulated rainfall with no flood occurring. Then $$$n$$$ lines follow. The $$$i$$$-th of these lines contains two integers $$$x_i$$$ and $$$p_i$$$ ($$$1 \leq x_i,p_i \leq 10^9$$$) — the position and intensity of the $$$i$$$-th day's rain. The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, output a binary string $$$s$$$ length of $$$n$$$. The $$$i$$$-th character of $$$s$$$ is 1 if after erasing the $$$i$$$-th day's rain there is no flood, while it is 0, if after erasing the $$$i$$$-th day's rain the flood still happens.

NoteIn the first test case, if we do not use the spell, the accumulated rainfall distribution will be like this:  If we erase the third day's rain, the flood is avoided and the accumulated rainfall distribution looks like this:  In the second test case, since initially the flood will not happen, we can erase any day's rain.In the third test case, there is no way to avoid the flood.

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		X := make([]int, n)
		P := make([]int, n)
		for i := 0; i < n; i++ {
			X[i], P[i] = readTwoNums(reader)
		}
		res := solve(n, X, P, m)
		buf.WriteString(res)
		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, X []int, P []int, m int) string {

	diff := make([]Pair, 0, 3*n)

	for i := 0; i < n; i++ {
		diff = append(diff, Pair{2 * int64(X[i]-P[i]), 1})
		diff = append(diff, Pair{2 * int64(X[i]), -2})
		diff = append(diff, Pair{2 * int64(X[i]+P[i]), 1})
	}

	sort.Slice(diff, func(i, j int) bool {
		return diff[i].first < diff[j].first || diff[i].first == diff[j].first && diff[i].second < diff[j].second
	})

	var a, d int64
	var last int64

	M := 2 * int64(m)

	key := Pair{0, -0x3f3f3f3f3f3f3f3f}

	for _, p := range diff {
		if p.first != last {
			a = a + (p.first-last)*d
			last = p.first
			if a > M {
				key = intercection(key, Pair{p.first, a - M})
			}
		}
		d += p.second
	}

	res := make([]byte, n)
	for i := 0; i < n; i++ {
		cur := Pair{2 * int64(X[i]), 2 * int64(P[i])}
		tmp := intercection(key, cur)
		if tmp == cur {
			res[i] = '1'
		} else {
			res[i] = '0'
		}
	}
	return string(res)
}

func intercection(a, b Pair) Pair {
	x := max(a.first+a.second, b.first+b.second)
	y := max(a.second-a.first, b.second-b.first)
	return Pair{(x - y) / 2, (x + y) / 2}
}

type Pair struct {
	first  int64
	second int64
}

func solve1(n int, X []int, P []int, m int) string {
	rs := make([]RainDay, n)

	for i := 0; i < n; i++ {
		rs[i] = RainDay{X[i], P[i], i}
	}

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

	V := NewSegTree(n)
	arr := make([]int64, n)

	cnt := make([]int, n+1)

	for i := n - 1; i >= 0; i-- {
		cnt[i] += cnt[i+1]
		cur := rs[i]
		j := search(n, func(j int) bool {
			return rs[j].pos >= cur.pos-cur.vol
		})
		V.Update(j, i+1, int64(cur.vol-cur.pos))
		cnt[i]++
		if j > 0 {
			cnt[j-1]--
		}
		arr[i] += int64(cnt[i])*int64(cur.pos) + V.Get(i)
	}

	V.Reset()
	for i := 0; i <= n; i++ {
		cnt[i] = 0
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			cnt[i] += cnt[i-1]
		}
		cur := rs[i]
		j := search(n, func(j int) bool {
			return rs[j].pos > cur.pos+cur.vol
		})
		// (i+1, v-1), (i + 2, v - 2), (i + 3, v - 3)... (j, 0)
		// k - i + v
		// 是在(i + 1, j) 之间 使用 v- i
		V.Update(i, j, int64(cur.vol+cur.pos))
		cnt[i]++
		cnt[j]--

		arr[i] += int64(cnt[i])*int64(-cur.pos) + V.Get(i)
	}

	for i := 0; i < n; i++ {
		arr[i] -= int64(rs[i].vol)
	}

	arr2 := make([]int64, 2*n)
	copy(arr2[n:], arr)

	for i := n - 1; i > 0; i-- {
		arr2[i] = max(arr2[i*2], arr2[i*2+1])
	}

	getMax := func(l, r int) int64 {
		l += n
		r += n
		var res int64

		for l < r {
			if l&1 == 1 {
				res = max(res, arr2[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr2[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	for i := 0; i < n; i++ {
		arr[i] += int64(rs[i].pos)
	}
	// 取消某个i， 相当于从  arr[a...b] 中减去 v - i

	root := BuildTree(arr)

	M := int64(m)

	buf := make([]byte, n)

	for i := 0; i < n; i++ {
		cur := rs[i]

		root.Add(i, i, -2*int64(cur.pos))

		v := cur.vol
		a := search(n, func(j int) bool {
			return rs[j].pos >= cur.pos-v
		})

		b := search(n, func(j int) bool {
			return rs[j].pos > cur.pos+v
		})
		// -(v - (i - j)) = -v + i - j
		root.Add(a, i, -int64(v)+int64(cur.pos))

		if i+1 <= b-1 {
			// -(v - (j - i)) = -(v - j + i) = -v + j - i
			root.Add(i+1, b-1, -int64(v)-int64(cur.pos))
		}

		tmp := root.Get(a, b-1)

		if a > 0 {
			tmp = max(tmp, getMax(0, a))
		}
		if b < n {
			tmp = max(tmp, getMax(b, n))
		}

		if tmp > M {
			buf[cur.id] = '0'
		} else {
			buf[cur.id] = '1'
		}
		// add back
		root.Add(a, i, int64(v)-int64(cur.pos))
		if i+1 <= b-1 {
			root.Add(i+1, b-1, int64(v)+int64(cur.pos))
		}
	}
	return string(buf)
}

type Node struct {
	left  *Node
	right *Node
	begin int
	end   int
	val   int64
	lazy  int64
}

func NewNode(begin, end int) *Node {
	node := new(Node)
	node.begin = begin
	node.end = end
	return node
}

func BuildTree(arr []int64) *Node {
	var build func(l int, r int) *Node

	build = func(l int, r int) *Node {
		node := NewNode(l, r)
		if l == r {
			node.val = arr[l]
			return node
		}
		mid := (l + r) / 2
		node.left = build(l, mid)
		node.right = build(mid+1, r)
		node.val = max(node.left.val, node.right.val)
		return node
	}

	return build(0, len(arr)-1)
}

func (node *Node) push() {
	if node.lazy != 0 {
		if node.left != nil {
			node.left.lazy += node.lazy
			node.left.val += node.lazy
			node.right.lazy += node.lazy
			node.right.val += node.lazy
		}
		node.lazy = 0
	}
}

func (node *Node) Add(l int, r int, v int64) {
	if node.end < l || r < node.begin {
		return
	}
	node.push()
	if l <= node.begin && node.end <= r {
		node.val += v
		node.lazy += v
		return
	}
	node.left.Add(l, r, v)
	node.right.Add(l, r, v)

	node.val = max(node.left.val, node.right.val)
}

func (node *Node) Get(l int, r int) int64 {
	if node.end < l || r < node.begin {
		return 0
	}

	node.push()

	if l <= node.begin && node.end <= r {
		return node.val
	}

	a := node.left.Get(l, r)
	b := node.right.Get(l, r)

	node.val = max(node.left.val, node.right.val)

	return max(a, b)
}

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

type SegTree struct {
	arr []int64
	n   int
}

func NewSegTree(n int) *SegTree {
	arr := make([]int64, 2*n)
	return &SegTree{arr, n}
}

func (t *SegTree) Update(l, r int, v int64) {
	l += t.n
	r += t.n
	for l < r {
		if l&1 == 1 {
			t.arr[l] += v
			l++
		}
		if r&1 == 1 {
			r--
			t.arr[r] += v
		}
		l >>= 1
		r >>= 1
	}
}

func (t *SegTree) Get(p int) int64 {
	var res int64
	p += t.n

	for p > 0 {
		res += t.arr[p]
		p >>= 1
	}
	return res
}

func (t *SegTree) Reset() {
	for i := 0; i < len(t.arr); i++ {
		t.arr[i] = 0
	}
}

type RainDay struct {
	pos int
	vol int
	id  int
}

func search(n int, f func(int) bool) int {
	l, r := 0, n
	for l < r {
		mid := (l + r) / 2
		if f(mid) {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return r
}

package main

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

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

	var buf bytes.Buffer

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		X := make([]int, n)
		P := make([]int, n)
		for i := 0; i < n; i++ {
			X[i], P[i] = readTwoNums(reader)
		}
		res := solve(n, X, P, m)
		buf.WriteString(res)
		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, X []int, P []int, m int) string {
	rs := make([]RainDay, n)

	for i := 0; i < n; i++ {
		rs[i] = RainDay{X[i], P[i], i}
	}

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

	V := NewSegTree(n)
	arr := make([]int64, n)

	cnt := make([]int, n+1)

	for i := n - 1; i >= 0; i-- {
		cnt[i] += cnt[i+1]
		cur := rs[i]
		j := search(n, func(j int) bool {
			return rs[j].pos >= cur.pos-cur.vol
		})
		V.Update(j, i+1, int64(cur.vol-cur.pos))
		cnt[i]++
		if j > 0 {
			cnt[j-1]--
		}
		arr[i] += int64(cnt[i])*int64(cur.pos) + V.Get(i)
	}

	V.Reset()
	for i := 0; i <= n; i++ {
		cnt[i] = 0
	}

	for i := 0; i < n; i++ {
		if i > 0 {
			cnt[i] += cnt[i-1]
		}
		cur := rs[i]
		j := search(n, func(j int) bool {
			return rs[j].pos > cur.pos+cur.vol
		})
		// (i+1, v-1), (i + 2, v - 2), (i + 3, v - 3)... (j, 0)
		// k - i + v
		// 是在(i + 1, j) 之间 使用 v- i
		V.Update(i, j, int64(cur.vol+cur.pos))
		cnt[i]++
		cnt[j]--

		arr[i] += int64(cnt[i])*int64(-cur.pos) + V.Get(i)
	}

	for i := 0; i < n; i++ {
		arr[i] -= int64(rs[i].vol)
	}

	arr2 := make([]int64, 2*n)
	copy(arr2[n:], arr)

	for i := n - 1; i > 0; i-- {
		arr2[i] = max(arr2[i*2], arr2[i*2+1])
	}

	getMax := func(l, r int) int64 {
		l += n
		r += n
		var res int64

		for l < r {
			if l&1 == 1 {
				res = max(res, arr2[l])
				l++
			}
			if r&1 == 1 {
				r--
				res = max(res, arr2[r])
			}
			l >>= 1
			r >>= 1
		}
		return res
	}

	for i := 0; i < n; i++ {
		arr[i] += int64(rs[i].pos)
	}
	// 取消某个i， 相当于从  arr[a...b] 中减去 v - i

	root := BuildTree(arr)

	M := int64(m)

	buf := make([]byte, n)

	for i := 0; i < n; i++ {
		cur := rs[i]

		root.Add(i, i, -2*int64(cur.pos))

		v := cur.vol
		a := search(n, func(j int) bool {
			return rs[j].pos >= cur.pos-v
		})

		b := search(n, func(j int) bool {
			return rs[j].pos > cur.pos+v
		})
		// -(v - (i - j)) = -v + i - j
		root.Add(a, i, -int64(v)+int64(cur.pos))

		if i+1 <= b-1 {
			// -(v - (j - i)) = -(v - j + i) = -v + j - i
			root.Add(i+1, b-1, -int64(v)-int64(cur.pos))
		}

		tmp := root.Get(a, b-1)

		if a > 0 {
			tmp = max(tmp, getMax(0, a))
		}
		if b < n {
			tmp = max(tmp, getMax(b, n))
		}

		if tmp > M {
			buf[cur.id] = '0'
		} else {
			buf[cur.id] = '1'
		}
		// add back
		root.Add(a, i, int64(v)-int64(cur.pos))
		if i+1 <= b-1 {
			root.Add(i+1, b-1, int64(v)+int64(cur.pos))
		}
	}
	return string(buf)
}

type Node struct {
	left  *Node
	right *Node
	begin int
	end   int
	val   int64
	lazy  int64
}

func NewNode(begin, end int) *Node {
	node := new(Node)
	node.begin = begin
	node.end = end
	return node
}

func BuildTree(arr []int64) *Node {
	var build func(l int, r int) *Node

	build = func(l int, r int) *Node {
		node := NewNode(l, r)
		if l == r {
			node.val = arr[l]
			return node
		}
		mid := (l + r) / 2
		node.left = build(l, mid)
		node.right = build(mid+1, r)
		node.val = max(node.left.val, node.right.val)
		return node
	}

	return build(0, len(arr)-1)
}

func (node *Node) push() {
	if node.lazy != 0 {
		if node.left != nil {
			node.left.lazy += node.lazy
			node.left.val += node.lazy
			node.right.lazy += node.lazy
			node.right.val += node.lazy
		}
		node.lazy = 0
	}
}

func (node *Node) Add(l int, r int, v int64) {
	if node.end < l || r < node.begin {
		return
	}
	node.push()
	if l <= node.begin && node.end <= r {
		node.val += v
		node.lazy += v
		return
	}
	node.left.Add(l, r, v)
	node.right.Add(l, r, v)

	node.val = max(node.left.val, node.right.val)
}

func (node *Node) Get(l int, r int) int64 {
	if node.end < l || r < node.begin {
		return 0
	}

	node.push()

	if l <= node.begin && node.end <= r {
		return node.val
	}

	a := node.left.Get(l, r)
	b := node.right.Get(l, r)

	node.val = max(node.left.val, node.right.val)

	return max(a, b)
}

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

type SegTree struct {
	arr []int64
	n   int
}

func NewSegTree(n int) *SegTree {
	arr := make([]int64, 2*n)
	return &SegTree{arr, n}
}

func (t *SegTree) Update(l, r int, v int64) {
	l += t.n
	r += t.n
	for l < r {
		if l&1 == 1 {
			t.arr[l] += v
			l++
		}
		if r&1 == 1 {
			r--
			t.arr[r] += v
		}
		l >>= 1
		r >>= 1
	}
}

func (t *SegTree) Get(p int) int64 {
	var res int64
	p += t.n

	for p > 0 {
		res += t.arr[p]
		p >>= 1
	}
	return res
}

func (t *SegTree) Reset() {
	for i := 0; i < len(t.arr); i++ {
		t.arr[i] = 0
	}
}

type RainDay struct {
	pos int
	vol int
	id  int
}

func search(n int, f func(int) bool) int {
	l, r := 0, n
	for l < r {
		mid := (l + r) / 2
		if f(mid) {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return r
}


While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from $$$a_1, a_2, \ldots, a_n$$$ to $$$-a_1, -a_2, \ldots, -a_n$$$. For some unknown reason, the number of service variables is always an even number.William understands that with his every action he attracts more and more attention from the exchange's security team, so the number of his actions must not exceed $$$5\,000$$$ and after every operation no variable can have an absolute value greater than $$$10^{18}$$$. William can perform actions of two types for two chosen variables with indices $$$i$$$ and $$$j$$$, where $$$i < j$$$:  Perform assignment $$$a_i = a_i + a_j$$$  Perform assignment $$$a_j = a_j - a_i$$$  William wants you to develop a strategy that will get all the internal variables to the desired values.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 20$$$). Description of the test cases follows. The first line of each test case contains a single even integer $$$n$$$ ($$$2 \le n \le 10^3$$$), which is the number of internal variables. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ $$$(1 \le a_i \le 10^9)$$$, which are initial values of internal variables.

For each test case print the answer in the following format: The first line of output must contain the total number of actions $$$k$$$, which the strategy will perform. Note that you do not have to minimize $$$k$$$. The inequality $$$k \le 5\,000$$$ must be satisfied.  Each of the next $$$k$$$ lines must contain actions formatted as "type i j", where "type" is equal to "1" if the strategy needs to perform an assignment of the first type and "2" if the strategy needs to perform an assignment of the second type. Note that $$$i < j$$$ should hold. We can show that an answer always exists.

NoteFor the first sample test case one possible sequence of operations is as follows:  "2 1 2". Values of variables after performing the operation: [1, 0, 1, 1]  "2 1 2". Values of variables after performing the operation: [1, -1, 1, 1]  "2 1 3". Values of variables after performing the operation: [1, -1, 0, 1]  "2 1 3". Values of variables after performing the operation: [1, -1, -1, 1]  "2 1 4". Values of variables after performing the operation: [1, -1, -1, 0]  "2 1 4". Values of variables after performing the operation: [1, -1, -1, -1]  "1 1 2". Values of variables after performing the operation: [0, -1, -1, -1]  "1 1 2". Values of variables after performing the operation: [-1, -1, -1, -1] For the second sample test case one possible sequence of operations is as follows:  "2 1 4". Values of variables after performing the operation: [4, 3, 1, -2]  "1 2 4". Values of variables after performing the operation: [4, 1, 1, -2]  "1 2 4". Values of variables after performing the operation: [4, -1, 1, -2]  "1 2 4". Values of variables after performing the operation: [4, -3, 1, -2]  "1 3 4". Values of variables after performing the operation: [4, -3, -1, -2]  "1 1 2". Values of variables after performing the operation: [1, -3, -1, -2]  "1 1 2". Values of variables after performing the operation: [-2, -3, -1, -2]  "1 1 4". Values of variables after performing the operation: [-4, -3, -1, -2]

package main

import (
	"bufio"
	. "fmt"
	"io"
	//"math"
	"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)

		for i := 0; i < n; i++ {
			var num int
			Fscan(in, &num)
		}
		Fprintln(out, 3 * n)
		table := []int{1,2,1,2,1,2}
		for i := 1; i <= n; i += 2 {
			for _, move := range table {
				Fprintln(out, move, i, i + 1)
			}
		}
	}
}

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(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	//"math"
	"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)

		for i := 0; i < n; i++ {
			var num int
			Fscan(in, &num)
		}
		Fprintln(out, 3 * n)
		table := []int{1, 1, 2, 1, 1, 2}
		for i := 1; i <= n; i += 2 {
			for _, move := range table {
				Fprintln(out, move, i, i + 1)
			}
		}
	}
}

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(num int) int {
	if num < 0 {
		return -num
	}
	return num
}


Fillomino is a classic logic puzzle. (You do not need to know Fillomino in order to solve this problem.) In one classroom in Yunqi town, some volunteers are playing a board game variant of it:Consider an $$$n$$$ by $$$n$$$ chessboard. Its rows are numbered from $$$1$$$ to $$$n$$$ from the top to the bottom. Its columns are numbered from $$$1$$$ to $$$n$$$ from the left to the right. A cell on an intersection of $$$x$$$-th row and $$$y$$$-th column is denoted $$$(x, y)$$$. The main diagonal of the chessboard is cells $$$(x, x)$$$ for all $$$1 \le x \le n$$$.A permutation of $$$\{1, 2, 3, \dots, n\}$$$ is written on the main diagonal of the chessboard. There is exactly one number written on each of the cells. The problem is to partition the cells under and on the main diagonal (there are exactly $$$1+2+ \ldots +n$$$ such cells) into $$$n$$$ connected regions satisfying the following constraints:  Every region should be connected. That means that we can move from any cell of a region to any other cell of the same region visiting only cells of the same region and moving from a cell to an adjacent cell.  The $$$x$$$-th region should contain cell on the main diagonal with number $$$x$$$ for all $$$1\le x\le n$$$.  The number of cells that belong to the $$$x$$$-th region should be equal to $$$x$$$ for all $$$1\le x\le n$$$.  Each cell under and on the main diagonal should belong to exactly one region.

The first line contains a single integer $$$n$$$ ($$$1\le n \le 500$$$) denoting the size of the chessboard. The second line contains $$$n$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_n$$$. $$$p_i$$$ is the number written on cell $$$(i, i)$$$. It is guaranteed that each integer from $$$\{1, \ldots, n\}$$$ appears exactly once in $$$p_1$$$, ..., $$$p_n$$$.

If no solution exists, output $$$-1$$$. Otherwise, output $$$n$$$ lines. The $$$i$$$-th line should contain $$$i$$$ numbers. The $$$j$$$-th number on the $$$i$$$-th line should be $$$x$$$ if cell $$$(i, j)$$$ belongs to the the region with $$$x$$$ cells.

NoteThe solutions to the examples are illustrated in the following pictures:

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 n int
	Fscan(in, &n)
	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, n)
		Fscan(in, &arr[i][i])
	}

	// dir := [][]int{{0, -1}, {-1, 0}}
	for i := 0; i < n; i++ {
		cur := arr[i][i]
		k := cur - 1
		x, y := i, i
		for k > 0 {
			if x >= 0 && x < n && y-1 >= 0 && y-1 <= i && arr[x][y-1] == 0 {
				arr[x][y-1] = cur
				y = y - 1
				k--
				continue
			}

			if x+1 >= 0 && x+1 < n && y >= 0 && y <= i && arr[x+1][y] == 0 {
				arr[x+1][y] = cur
				x = x + 1
				k--
				continue
			}

			Fprintln(out, "-1")
			return
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j <= i; j++ {
			Fprintf(out, "%d ", arr[i][j])
		}
		Fprintln(out)
	}
}

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

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([][]int, n)
	for i := range a {
		a[i] = make([]int, i+1)
		Fscan(in, &a[i][i])
	}
	for i := 1; i < n; i++ {
		f := false
		for j := 0; j+i < n; j++ {
			if a[j+i-1][j] == i {
				f = true
			}
			if f {
				a[j+i][j] = a[j+i][j+1]
			} else {
				a[j+i][j] = a[j+i-1][j]
			}
		}
	}
	for _, r := range a {
		for _, v := range r {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

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

	var n int

	fmt.Fscanf(reader, "%d\n", &n)
	var ans [501][501]int

	for i := 0; i < n; i++ {
		if i < n-1 {
			fmt.Fscanf(reader, "%d ", &ans[i][i])
		} else {
			fmt.Fscanf(reader, "%d\n", &ans[i][i])
		}
	}

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

		x, y := i, i

		for num := ans[i][i] - 1; num > 0; num-- {
			if y > 0 && ans[x][y-1] == 0 {
				ans[x][y-1] = ans[i][i]
				y--
			} else if x+1 < n && ans[x+1][y] == 0 {
				ans[x+1][y] = ans[i][i]
				x++
			} else {
				fmt.Println(-1)
				return
			}
		}
	}

	for i, j := 0, 0; i < n; i++ {
		for j = 0; j < i; j++ {
			fmt.Printf("%d ", ans[i][j])
		}

		fmt.Printf("%d\n", ans[i][j])
	}
}