Formula One championship consists of series of races called Grand Prix. After every race drivers receive points according to their final position. Only the top 10 drivers receive points in the following order 25, 18, 15, 12, 10, 8, 6, 4, 2, 1. At the conclusion of the championship the driver with most points is the champion. If there is a tie, champion is the one with most wins (i.e. first places). If a tie still exists, it is chosen the one with most second places, and so on, until there are no more place to use for compare. Last year another scoring system was proposed but rejected. In it the champion is the one with most wins. If there is tie, champion is the one with most points. If a tie still exists it is proceeded the same way as in the original scoring system, that is comparing number of second, third, forth, and so on, places.You are given the result of all races during the season and you are to determine the champion according to both scoring systems. It is guaranteed, that both systems will produce unique champion.

The first line contain integer t (1 ≤ t ≤ 20), where t is the number of races. After that all races are described one by one. Every race description start with an integer n (1 ≤ n ≤ 50) on a line of itself, where n is the number of clasified drivers in the given race. After that n lines follow with the classification for the race, each containing the name of a driver. The names of drivers are given in order from the first to the last place. The name of the driver consists of lowercase and uppercase English letters and has length at most 50 characters. Comparing of names should be case-sensetive.

Your output should contain exactly two line. On the first line is the name of the champion according to the original rule, and on the second line the name of the champion according to the alternative rule.

3
3
Hamilton
Vettel
Webber
2
Webber
Vettel
2
Hamilton
Vettel

2
7
Prost
Surtees
Nakajima
Schumacher
Button
DeLaRosa
Buemi
8
Alonso
Prost
NinoFarina
JimClark
DeLaRosa
Nakajima
Patrese
Surtees

NoteIt is not guaranteed that the same drivers participate in all races. For the championship consider every driver that has participated in at least one race. The total number of drivers during the whole season is not more then 50.

package main

import (
	"fmt"
	"io/ioutil"
	"bytes"
	"os"
	"sort"
)

type F1 struct {
	Name string
	Rank [50]int
}

func (this *F1) GetScore() int {
	sum := 0
	for i := 0;i < 10;i ++ {
		sum += points[i] * this.Rank[i]
	}
	return sum
}
func CompareRank(a, b *F1) int {
	for i := 0;i < 50;i ++ {
		if a.Rank[i] > b.Rank[i] {
			return 1
		} else if a.Rank[i] < b.Rank[i]{
			return -1
		}
	}
	return 0
}

type RankList []*F1

func (this RankList) Len() int { return len(this)}
func (this RankList) Swap(i, j int) { this[i], this[j] = this[j], this[i] }

type SortByOriginal struct { RankList }
type SortByAlternative struct { RankList }

var points = [10]int{25, 18, 15, 12, 10, 8, 6, 4, 2, 1}

func (this SortByOriginal) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	si, sj := fi.GetScore(), fj.GetScore()
	return si > sj || (si == sj && CompareRank(fi, fj) == 1)
}

func (this SortByAlternative) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	rank := CompareRank(fi, fj)
	si, sj := fi.GetScore(), fj.GetScore()
	return fi.Rank[0] > fj.Rank[0] ||
			(fi.Rank[0] == fj.Rank[0] && si > sj) ||
			(fi.Rank[0] == fj.Rank[0] && si == sj && rank == 1)
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	var name string
	rankList := make([]*F1, 0, 100)
	rankMap := map[string]*F1{}
	for i := 0;i < t;i ++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		for j := 0;j < n;j ++ {
			fmt.Fscanf(reader, "%s\n", &name)
			_, ok := rankMap[name]
			if !ok {
				f1 := &F1 {Name : name}
				rankMap[name] = f1
				rankList = append(rankList, f1)
			}
			rankMap[name].Rank[j] ++
		}
	}
	sort.Sort(SortByOriginal{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
	sort.Sort(SortByAlternative{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Driver struct {
  Name string
  Points int
  Places map[int]int
  MaxPlace int
}

var drivers = map[string]*Driver{}

type OldList []*Driver
type NewList []*Driver
func (list OldList) Len() int {
  return len(list)
}
func (list OldList) Swap(i, j int) {
  list[i], list[j] = list[j], list[i]
}
func (list NewList) Len() int {
  return len(list)
}
func (list NewList) Swap(i, j int) {
  list[i], list[j] = list[j], list[i]
}

func (list OldList) Less(i, j int) bool {
  a, b := list[i], list[j]
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return comparePlaces(a, b)
}
func (list NewList) Less(i, j int) bool {
  a, b := list[i], list[j]
  if a.Places[1] != b.Places[1] {
    return a.Places[1] > b.Places[1]
  }
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return comparePlaces(a, b)
}
func comparePlaces(a, b *Driver) bool {
  for p := 1; p <= a.MaxPlace || p <= b.MaxPlace; p++ {
    placesA := a.Places[p]
    placesB := b.Places[p]
    if placesA != placesB {
      return placesA > placesB
    }
  }
  return true
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  points := map[int]int{ 1: 25, 2: 18, 3: 15, 4: 12, 5: 10,
      6: 8, 7: 6, 8: 4, 9: 2, 10: 1 }

  t := getI()
  for ti := 0; ti < t; ti++ {
    n := getI()
    for ni := 0; ni < n; ni++ {
      name := getS()
      place := ni+1
      driver, found := drivers[name]
      if !found {
        driver = &Driver{ name, 0, map[int]int{}, 0 }
        drivers[name] = driver
      }
      driver.Points += points[place]
      driver.Places[place] += 1
      if place > driver.MaxPlace {
        driver.MaxPlace = place
      }
    }
  }
  oldList, newList := []*Driver{}, []*Driver{}
  for _, driver := range drivers {
    oldList = append(oldList, driver)
    newList = append(newList, driver)
  }
  sort.Sort(OldList(oldList))
  sort.Sort(NewList(newList))
  writer.WriteString(fmt.Sprintf("%s\n", oldList[0].Name))
  writer.WriteString(fmt.Sprintf("%s\n", newList[0].Name))
}

package main

import (
	"fmt"
	"io/ioutil"
	"bytes"
	"os"
	"sort"
)

type F1 struct {
	Name string
	Rank [50]int
}

func (this *F1) GetScore() int {
	sum := 0
	for i := 0;i < 10;i ++ {
		sum += points[i] * this.Rank[i]
	}
	return sum
}
func CompareRank(a, b *F1) int {
	for i := 0;i < 50;i ++ {
		if a.Rank[i] > b.Rank[i] {
			return 1
		} else if a.Rank[i] < b.Rank[i]{
			return -1
		}
	}
	return 0
}

type RankList []*F1

func (this RankList) Len() int { return len(this)}
func (this RankList) Swap(i, j int) { this[i], this[j] = this[j], this[i] }

type SortByOriginal struct { RankList }
type SortByAlternative struct { RankList }

var points = [10]int{25, 18, 15, 12, 10, 8, 6, 4, 2, 1}

func (this SortByOriginal) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	si, sj := fi.GetScore(), fj.GetScore()
	return si > sj || (si == sj && CompareRank(fi, fj) == 1)
}

func (this SortByAlternative) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	rank := CompareRank(fi, fj)
	return rank == 1 || (rank == 0 && fi.GetScore() > fj.GetScore())
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	var name string
	rankList := make([]*F1, 0, 100)
	rankMap := map[string]*F1{}
	for i := 0;i < t;i ++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		for j := 0;j < n;j ++ {
			fmt.Fscanf(reader, "%s\n", &name)
			_, ok := rankMap[name]
			if !ok {
				f1 := &F1 {Name : name}
				rankMap[name] = f1
				rankList = append(rankList, f1)
			}
			rankMap[name].Rank[j] ++
		}
	}
	sort.Sort(SortByOriginal{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
	sort.Sort(SortByAlternative{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
}

package main

import (
	"fmt"
	"io/ioutil"
	"bytes"
	"os"
	"sort"
)

type F1 struct {
	Name string
	Rank [50]int
}

func (this *F1) GetScore() int {
	sum := 0
	for i := 0;i < 10;i ++ {
		sum += points[i] * this.Rank[i]
	}
	return sum
}
func CompareRank(a, b *F1) int {
	for i := 0;i < 50;i ++ {
		if a.Rank[i] > b.Rank[i] {
			return 1
		} else if a.Rank[i] < b.Rank[i]{
			return -1
		}
	}
	return 0
}

type RankList []*F1

func (this RankList) Len() int { return len(this)}
func (this RankList) Swap(i, j int) { this[i], this[j] = this[j], this[i] }

type SortByOriginal struct { RankList }
type SortByAlternative struct { RankList }

var points = [10]int{25, 18, 15, 12, 10, 8, 6, 4, 2, 1}

func (this SortByOriginal) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	si, sj := fi.GetScore(), fj.GetScore()
	return si > sj || (si == sj && CompareRank(fi, fj) == 1)
}

func (this SortByAlternative) Less(i, j int) bool {
	fi, fj := this.RankList[i], this.RankList[j]
	rank := CompareRank(fi, fj)
	return rank == 1 || (rank == 0 && fi.GetScore() > fj.GetScore())
}

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	var name string
	rankList := make([]*F1, 0, 100)
	rankMap := map[string]*F1{}
	for i := 0;i < t;i ++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		for j := 0;j < n;j ++ {
			fmt.Fscanf(reader, "%s\n", &name)
			_, ok := rankMap[name]
			if !ok {
				f1 := &F1 {Name : name}
				rankMap[name] = f1
				rankList = append(rankList, f1)
			}
			rankMap[name].Rank[i] ++
		}
	}
	sort.Sort(SortByOriginal{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
	sort.Sort(SortByAlternative{RankList(rankList)})
	fmt.Printf("%s\n", rankList[0].Name)
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Driver struct {
  Name string
  Points int
  Places map[int]int
}

var drivers = map[string]*Driver{}

type OldList []*Driver
type NewList []*Driver
func (list OldList) Len() int {
  return len(list)
}
func (list OldList) Swap(i, j int) {
  list[i], list[j] = list[j], list[i]
}
func (list NewList) Len() int {
  return len(list)
}
func (list NewList) Swap(i, j int) {
  list[i], list[j] = list[j], list[i]
}

func (list OldList) Less(i, j int) bool {
  a, b := list[i], list[j]
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return comparePlaces(a, b)
}
func (list NewList) Less(i, j int) bool {
  a, b := list[i], list[j]
  if a.Places[1] != b.Places[1] {
    return a.Places[1] > b.Places[1]
  }
  if a.Points != b.Points {
    return a.Points > b.Points
  }
  return comparePlaces(a, b)
}
func comparePlaces(a, b *Driver) bool {
  for p := 1; ; p++ {
    placesA, foundA := a.Places[p]
    placesB, foundB := b.Places[p]
    if !foundA && !foundB && p > 10 {
      break
    }
    if placesA != placesB {
      return placesA > placesB
    }
  }
  return true
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  points := map[int]int{ 1: 25, 2: 18, 3: 15, 4: 12, 5: 10,
      6: 8, 7: 6, 8: 4, 9: 2, 10: 1 }

  t := getI()
  for ti := 0; ti < t; ti++ {
    n := getI()
    for ni := 0; ni < n; ni++ {
      name := getS()
      place := ni+1
      driver, found := drivers[name]
      if !found {
        driver = &Driver{ name, 0, map[int]int{} }
        drivers[name] = driver
      }
      driver.Points += points[place]
      driver.Places[place] += 1
    }
  }
  oldList, newList := []*Driver{}, []*Driver{}
  for _, driver := range drivers {
    oldList = append(oldList, driver)
    newList = append(newList, driver)
  }
  sort.Sort(OldList(oldList))
  sort.Sort(NewList(newList))
  writer.WriteString(fmt.Sprintf("%s\n", oldList[0].Name))
  writer.WriteString(fmt.Sprintf("%s\n", newList[0].Name))
}


Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are $$$n$$$ types of resources, numbered $$$1$$$ through $$$n$$$. Bob needs at least $$$a_i$$$ pieces of the $$$i$$$-th resource to build the spaceship. The number $$$a_i$$$ is called the goal for resource $$$i$$$.Each resource takes $$$1$$$ turn to produce and in each turn only one resource can be produced. However, there are certain milestones that speed up production. Every milestone is a triple $$$(s_j, t_j, u_j)$$$, meaning that as soon as Bob has $$$t_j$$$ units of the resource $$$s_j$$$, he receives one unit of the resource $$$u_j$$$ for free, without him needing to spend a turn. It is possible that getting this free resource allows Bob to claim reward for another milestone. This way, he can obtain a large number of resources in a single turn.The game is constructed in such a way that there are never two milestones that have the same $$$s_j$$$ and $$$t_j$$$, that is, the award for reaching $$$t_j$$$ units of resource $$$s_j$$$ is at most one additional resource.A bonus is never awarded for $$$0$$$ of any resource, neither for reaching the goal $$$a_i$$$ nor for going past the goal — formally, for every milestone $$$0 < t_j < a_{s_j}$$$.A bonus for reaching certain amount of a resource can be the resource itself, that is, $$$s_j = u_j$$$.Initially there are no milestones. You are to process $$$q$$$ updates, each of which adds, removes or modifies a milestone. After every update, output the minimum number of turns needed to finish the game, that is, to accumulate at least $$$a_i$$$ of $$$i$$$-th resource for each $$$i \in [1, n]$$$.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of types of resources. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$), the $$$i$$$-th of which is the goal for the $$$i$$$-th resource. The third line contains a single integer $$$q$$$ ($$$1 \leq q \leq 10^5$$$) — the number of updates to the game milestones. Then $$$q$$$ lines follow, the $$$j$$$-th of which contains three space separated integers $$$s_j$$$, $$$t_j$$$, $$$u_j$$$ ($$$1 \leq s_j \leq n$$$, $$$1 \leq t_j < a_{s_j}$$$, $$$0 \leq u_j \leq n$$$). For each triple, perform the following actions:    First, if there is already a milestone for obtaining $$$t_j$$$ units of resource $$$s_j$$$, it is removed.  If $$$u_j = 0$$$, no new milestone is added.  If $$$u_j \neq 0$$$, add the following milestone: "For reaching $$$t_j$$$ units of resource $$$s_j$$$, gain one free piece of $$$u_j$$$."  Output the minimum number of turns needed to win the game.

Output $$$q$$$ lines, each consisting of a single integer, the $$$i$$$-th represents the answer after the $$$i$$$-th update.

NoteAfter the first update, the optimal strategy is as follows. First produce $$$2$$$ once, which gives a free resource $$$1$$$. Then, produce $$$2$$$ twice and $$$1$$$ once, for a total of four turns.After the second update, the optimal strategy is to produce $$$2$$$ three times — the first two times a single unit of resource $$$1$$$ is also granted.After the third update, the game is won as follows.   First produce $$$2$$$ once. This gives a free unit of $$$1$$$. This gives additional bonus of resource $$$1$$$. After the first turn, the number of resources is thus $$$[2, 1]$$$.  Next, produce resource $$$2$$$ again, which gives another unit of $$$1$$$.  After this, produce one more unit of $$$2$$$. The final count of resources is $$$[3, 3]$$$, and three turns are needed to reach this situation. Notice that we have more of resource $$$1$$$ than its goal, which is of no use.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	a := make([]int64, n+1)
	bonus := make([]int64, n+1)
	ans := int64(0)
	for i := 1; i <= n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
		ans += a[i]
	}
	fmt.Fscanf(in, "\n")
	m := 0
	fmt.Fscanf(in, "%d\n", &m)
	f := make(map[int64]int)

	for i := 0; i < m; i++ {
		o, p, q := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &o, &p, &q)
		id := getID(o, p)
		cur := f[id]
		if cur != 0 {
			bonus[cur]--
			if bonus[cur] < a[cur] {
				ans++
			}
		}
		f[id] = q
		if q != 0 {
			bonus[q]++
			if bonus[q] <= a[q] {
				ans--
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
}

func getID(a, b int) int64 {
	return int64(a)*(10000000000) + int64(b)
}


There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue. The i-th walrus has the age equal to ai.The i-th walrus becomes displeased if there's a younger walrus standing in front of him, that is, if exists such j (i < j), that ai > aj. The displeasure of the i-th walrus is equal to the number of walruses between him and the furthest walrus ahead of him, which is younger than the i-th one. That is, the further that young walrus stands from him, the stronger the displeasure is.The airport manager asked you to count for each of n walruses in the queue his displeasure.

The first line contains an integer n (2 ≤ n ≤ 105) — the number of walruses in the queue. The second line contains integers ai (1 ≤ ai ≤ 109). Note that some walruses can have the same age but for the displeasure to emerge the walrus that is closer to the head of the queue needs to be strictly younger than the other one.

Print n numbers: if the i-th walrus is pleased with everything, print "-1" (without the quotes). Otherwise, print the i-th walrus's displeasure: the number of other walruses that stand between him and the furthest from him younger walrus.

package main

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

var w *bufio.Writer

var sc *bufio.Scanner

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

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

func main() {

	w = bufio.NewWriter(os.Stdout)
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

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

	//coords compression
	tosort, age, ans := make([]int, n, n), make([]int, n, n), make([]int, n, n)
	for i := 0; i < n; i++ {
		ans[i] = -1
	}
	copy(tosort, walruses)
	sort.Ints(tosort)
	for i := 0; i < n; i++ {
		age[i] = sort.Search(n, func(j int) bool { return tosort[j] >= walruses[i] })
	}

	//Fenwick tree for minimum
	t := make([]int, n)
	for i := 0; i < n; i++ {
		t[i] = math.MaxInt32
	}

	min := func(r int) int {
		res := math.MaxInt32
		for ; r >= 0; r = (r & (r + 1)) - 1 {
			if res > t[r] {
				res = t[r]
			}
		}
		return res
	}

	upd := func(i int, val int) {
		for ; i < n; i = (i | (i + 1)) {
			if t[i] > val {
				t[i] = val
			}
		}
	}

	for i := 0; i < n; i++ {
		if age[i] > 0 {
			j := min(age[i] - 1)
			if j < i {
				ans[n-i-1] = i - j - 1
			}
		}
		upd(age[i], i)
	}
	for _, j := range ans {
		w.WriteString(strconv.Itoa(j))
		w.WriteByte(' ')
	}
	w.Flush()
}


This is an interactive problem.Alice and Bob are playing a game. There is $$$n\times n$$$ grid, initially empty. We refer to the cell in row $$$i$$$ and column $$$j$$$ by $$$(i, j)$$$ for $$$1\le i, j\le n$$$. There is an infinite supply of tokens that come in $$$3$$$ colors labelled $$$1$$$, $$$2$$$, and $$$3$$$.The game proceeds with turns as follows. Each turn begins with Alice naming one of the three colors, let's call it $$$a$$$. Then, Bob chooses a color $$$b\ne a$$$, chooses an empty cell, and places a token of color $$$b$$$ on that cell.We say that there is a conflict if there exist two adjacent cells containing tokens of the same color. Two cells are considered adjacent if they share a common edge.If at any moment there is a conflict, Alice wins. Otherwise, if $$$n^2$$$ turns are completed (so that the grid becomes full) without any conflicts, Bob wins.We have a proof that Bob has a winning strategy. Play the game as Bob and win.The interactor is adaptive. That is, Alice's color choices can depend on Bob's previous moves.

NoteThe final grid from the sample is pictured below. Bob wins because there are no two adjacent cells with tokens of the same color. $$$$$$\begin{matrix}2&3\\3&1\end{matrix}$$$$$$The sample is only given to demonstrate the input and output format. It is not guaranteed to represent an optimal strategy for Bob or the real behavior of the interactor.

package main
import ."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, a, i, p int
	Scan(&n)
	for q, m := 1, n*n; i < m; i++ {
		if Scan(&a); q >= m || a > 1 && p < m {
			Println((7-a)/3, p/n+1, p/n&(n&1^1)+1+p%n)
			p += 2
		} else {
			Println((11-a)/3, q/n+1, q/n&(n&1^1)^1+q%n)
			q += 2
		}
	}
}

package main
import ."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, a, i, p int
	Scan(&n)
	for q, m := 1, n*n; i < m; i++ {
		if Scan(&a); q >= m || a > 1 && p < m {
			c := p%n + 1
			if n&1 == 0 && p/n&1 > 0 {
				c++
			}
			Println((7-a)/3, p/n+1, c)
			p += 2
		} else {
			c := q%n + 1
			if n&1 == 0 && q/n&1 > 0 {
				c--
			}
			Println((11-a)/3, q/n+1, c)
			q += 2
		}
	}
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func CF1503B() {
	var n, a int
	Scan(&n)
	for i, p, q, m := 0, 0, 1, n*n; i < m; i++ {
		Scan(&a)
		if q >= m || a > 1 && p < m {
			c := p%n + 1
			if n&1 == 0 && p/n&1 > 0 {
				c++
			}
			if a == 1 {
				Println(3, p/n+1, c)
			} else {
				Println(1, p/n+1, c)
			}
			p += 2
		} else {
			c := q%n + 1
			if n&1 == 0 && q/n&1 > 0 {
				c--
			}
			if a == 2 {
				Println(3, q/n+1, c)
			} else {
				Println(2, q/n+1, c)
			}
			q += 2
		}
	}
}

func main() { CF1503B() }

package main

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

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

	n := readNum(reader)
	a := readNum(reader)

	ask := func(b int, i int, j int, times int) int {
		fmt.Printf("%d %d %d\n", b, i, j)
		if times == n*n {
			return 0
		}
		return readNum(reader)
	}

	solve(n, a, ask)

}

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, a int, ask func(b int, i int, j int, times int) int) {
	// if n is even
	// 第一步在1，1处输出b(not a), 如果反馈不是b，可以在紧邻位置输出a
	// 对于位置（i，j), 它被top 和 left控制
	// 如果 top == left, 则没有问题
	que := make([][]Pair, 2)
	for i := 0; i < 2; i++ {
		que[i] = make([]Pair, 0, n*n/2)
	}
	grid := make([][]int, n+1)
	for i := 1; i <= n; i++ {
		grid[i] = make([]int, n+1)
		for j := 1; j <= n; j++ {
			k := (i + j) % 2
			que[k] = append(que[k], Pair{i, j})
		}
	}
	times := 1
	for len(que[0]) > 0 || len(que[1]) > 0 {
		if a == 1 {
			// put 2
			if len(que[0]) > 0 {
				b := 2
				cur := que[0][len(que[0])-1]
				a = ask(b, cur.first, cur.second, times)
				que[0] = que[0][:len(que[0])-1]
			} else {
				b := 3
				cur := que[1][len(que[1])-1]
				a = ask(b, cur.first, cur.second, times)
				que[1] = que[1][:len(que[1])-1]
			}
		} else if a == 2 {
			if len(que[1]) > 0 {
				b := 1
				cur := que[1][len(que[1])-1]
				a = ask(b, cur.first, cur.second, times)
				que[1] = que[1][:len(que[1])-1]
			} else {
				b := 3
				cur := que[0][len(que[0])-1]
				a = ask(b, cur.first, cur.second, times)
				que[0] = que[0][:len(que[0])-1]
			}
		} else {
			if len(que[0]) > 0 {
				b := 2
				cur := que[0][len(que[0])-1]
				a = ask(b, cur.first, cur.second, times)
				que[0] = que[0][:len(que[0])-1]
			} else {
				b := 1
				cur := que[1][len(que[1])-1]
				a = ask(b, cur.first, cur.second, times)
				que[1] = que[1][:len(que[1])-1]
			}
		}
		times++
	}

}

type Pair struct {
	first  int
	second int
}

package main
import ."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, a, i, p int
	Scan(&n)
	for q, m := 1, n*n; i < m; i++ {
		if Scan(&a); q >= m || a > 1 && p < m {
			Println((7-a)/3, p/n+1, p%n+1+p/n&(n&1^1))
			p += 2
		} else {
			Println((11-a)/3, q/n+1, q%n+q/n&(n&1^1)^1)
			q += 2
		}
	}
}

package main
import ."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var n, a, i, p int
	Scan(&n)
	for q, m := 1, n*n; i < m; i++ {
		if Scan(&a); q >= m || a > 1 && p < m {
			c := p%n + 1
			if n&1 == 0 && p/n&1 > 0 {
				c++
			}
			Println((4-a)/3*2+1, p/n+1, c)
			p += 2
		} else {
			c := q%n + 1
			if n&1 == 0 && q/n&1 > 0 {
				c--
			}
			Println((5-a)/3*2+1, q/n+1, c)
			q += 2
		}
	}
}

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func CF1503B() {
	var n, a int
	Scan(&n)
	for i, p, q, m := 0, 0, 1, n*n; i < m; i++ {
		Scan(&a)
		if q >= m || a > 1 && p < m {
			c := p%n + 1
			if n&1 == 0 && p/n&1 > 0 {
				c++
			}
			if a == 1 {
				Println(3, p/n+1, c)
			} else {
				Println(1, p/n+1, c)
			}
			p += 2
		} else {
			c := q%n + 1
			if n&1 == 0 && q/n&1 > 0 {
				c--
			}
			if a == 1 {
				Println(2, q/n+1, c)
			} else {
				Println(3, q/n+1, c)
			}
			q += 2
		}
	}
}

func main() { CF1503B() }


You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then you try to turn a into b using two types of operations:  Write parity(a) to the end of a. For example, .  Remove the first character of a. For example, . You cannot perform this operation if a is empty. You can use as many operations as you want. The problem is, is it possible to turn a into b?The parity of a 01-string is 1 if there is an odd number of "1"s in the string, and 0 otherwise.

The first line contains the string a and the second line contains the string b (1 ≤ |a|, |b| ≤ 1000). Both strings contain only the characters "0" and "1". Here |x| denotes the length of the string x.

Print "YES" (without quotes) if it is possible to turn a into b, and "NO" (without quotes) otherwise.

NoteIn the first sample, the steps are as follows: 01011 → 1011 → 011 → 0110

package main

import "os"
import "bufio"
//import "strconv"

func main(){
	var a, b string
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	a = r.Text()
	r.Scan()
	b = r.Text()
	counta, countb := 0, 0
	for i:=0; i<len(a); i++ {
		if string(a[i]) == "1" {
			counta += 1
		}
	}
	for j:=0; j<len(b); j++ {
		if string(b[j]) == "1" {
			countb += 1
		}
	}
	if counta % 2 == 0 {
		if countb <= counta {
			w.WriteString("YES\n")
		} else {
			w.WriteString("NO\n")
		}
	} else {
		if countb <= counta+1 {
			w.WriteString("YES\n")
		} else {
			w.WriteString("NO\n")
		}
	}
	w.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF297A(in io.Reader, out io.Writer) {
	var s, t string
	Fscan(in, &s, &t)
	if (strings.Count(s, "1")+1)/2*2 >= strings.Count(t, "1") {
		Fprint(out, "YES")
	} else {
		Fprint(out, "NO")
	}
}

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

package main

import (
	. "fmt"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var s, t string
	Scan(&s, &t)
	if (strings.Count(s, "1")+1)/2*2 >= strings.Count(t, "1") {
		Print("YES")
	} else {
		Print("NO")
	}
}

package main

import "fmt"

func main() {
	a, b := "", ""
	fmt.Scanf("%s\n%s\n", &a, &b)

	na := 0
	for _, c := range a {
		if string(c) == "1" {
			na++
		}
	}
	if na%2 == 1 {
		na++
	}
	for _, c := range b {
		if string(c) == "1" {
			na--
		}
		if na < 0 {
			break
		}
	}
	if na < 0 {
		fmt.Printf("NO\n")
	} else {
		fmt.Printf("YES\n")
	}
}

// 297A
package main

import (
	"fmt"
)

func main() {
	var a, b string
	var n, m, i int
	a1, b1 := 0, 0
	fmt.Scan(&a, &b)
	n, m = len(a), len(b)
	for i = 0; i < n; i++ {
		if a[i] == '1' {
			a1++
		}
	}
	for i = 0; i < m; i++ {
		if b[i] == '1' {
			b1++
		}
	}
	if a1%2 == 1 {
		a1++
	}
	if a1 >= b1 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

// 297A-mic
package main

import (
	"fmt"
)

func main() {
	var a, b string
	fmt.Scan(&a, &b)
	var n1, n2 int
	for i := 0; i < len(a); i++ {
		if a[i] == '1' {
			n1++
		}
	}
	for i := 0; i < len(b); i++ {
		if b[i] == '1' {
			n2++
		}
	}
	if n1+(n1%2) >= n2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/297/A

package main

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

func getOneCount(s string) int {
	ones := 0
	for _, char := range s {
		if string(char) == "1" {
			ones += 1
		}
	}
	return ones
}

func Solve(a string, b string) string {
	aOneCount, bOneCount := getOneCount(a), getOneCount(b)
	if aOneCount%2 == 0 && aOneCount >= bOneCount {
		return "YES"
	}
	if aOneCount%2 == 1 && aOneCount+1 >= bOneCount {
		return "YES"
	}
	return "NO"
}

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

	var a, b string
	fmt.Fscanf(reader, "%s\n%s\n", &a, &b)

	fmt.Fprintf(writer, "%s\n", Solve(a, b))
}

package main

import "fmt"

func main() {
	a, b := "", ""
	fmt.Scanf("%s\n%s\n", &a, &b)

	na := 0
	for _, c := range a {
		if string(c) == "1" {
			na++
		}
	}
	for _, c := range b {
		if string(c) == "1" {
			na--
		}
		if na < 0 {
			break
		}
	}
	if na < 0 {
		fmt.Printf("NO\n")
	} else {
		fmt.Printf("YES\n")
	}
}

// 297A-mic
package main

import (
	"fmt"
)

func main() {
	var a, b string
	fmt.Scan(&a, &b)
	var n1, n2, i int
	for i = 0; i < len(a); i++ {
		n1 += int(a[i] - '0')
	}
	for i = 0; i < len(b); i++ {
		n2 += int(b[i] - '0')
	}
	if n1+n2%2 > n2 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Ivan wants to write a letter to his friend. The letter is a string s consisting of lowercase Latin letters.Unfortunately, when Ivan started writing the letter, he realised that it is very long and writing the whole letter may take extremely long time. So he wants to write the compressed version of string s instead of the string itself.The compressed version of string s is a sequence of strings c1, s1, c2, s2, ..., ck, sk, where ci is the decimal representation of number ai (without any leading zeroes) and si is some string consisting of lowercase Latin letters. If Ivan writes string s1 exactly a1 times, then string s2 exactly a2 times, and so on, the result will be string s.The length of a compressed version is |c1| + |s1| + |c2| + |s2|... |ck| + |sk|. Among all compressed versions Ivan wants to choose a version such that its length is minimum possible. Help Ivan to determine minimum possible length.

The only line of input contains one string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 8000).

Output one integer number — the minimum possible length of a compressed version of s.

NoteIn the first example Ivan will choose this compressed version: c1 is 10, s1 is a.In the second example Ivan will choose this compressed version: c1 is 1, s1 is abcab.In the third example Ivan will choose this compressed version: c1 is 2, s1 is c, c2 is 1, s2 is z, c3 is 4, s3 is ab.

package main

import (
	"fmt"
)

var dp1 [8001][8000]int
var dp2 [8000]int

func main() {
	var s string
	fmt.Scanf("%s", &s)
	b := []byte(s)
	n := len(b)

	for i := 1; i < n; i++ {
		failure := -1
		dp1[i][i-1] = 1
		for j := 0; j < n; j++ {
			if i+j > n-1 {
				break
			}
			if b[j] != b[i+j] {
				failure = j + 2*i - 1
			}
			if i+j > failure {
				dp1[i][i+j] = dp1[i][j] + 1
			} else {
				dp1[i][i+j] = 1
			}
		}
	}

	for i := 0; i < n; i++ {
		dp2[i] = i + 2
		for j := 1; j <= i+1; j++ {
			digit := 1
			for k := 1; k <= dp1[j][i]; k++ {
				if k == 10 || k == 100 || k == 1000 {
					digit++
				}
				var tmp int
				if i-k*j < 0 {
					tmp = digit + j
				} else {
					tmp = dp2[i-k*j] + digit + j
				}
				if tmp < dp2[i] {
					dp2[i] = tmp
				}
			}
		}
	}
	fmt.Printf("%d", dp2[n-1])
}


You are given a string s consisting of n lowercase Latin letters. Some indices in this string are marked as forbidden.You want to find a string a such that the value of |a|·f(a) is maximum possible, where f(a) is the number of occurences of a in s such that these occurences end in non-forbidden indices. So, for example, if s is aaaa, a is aa and index 3 is forbidden, then f(a) = 2 because there are three occurences of a in s (starting in indices 1, 2 and 3), but one of them (starting in index 2) ends in a forbidden index.Calculate the maximum possible value of |a|·f(a) you can get.

The first line contains an integer number n (1 ≤ n ≤ 200000) — the length of s. The second line contains a string s, consisting of n lowercase Latin letters. The third line contains a string t, consisting of n characters 0 and 1. If i-th character in t is 1, then i is a forbidden index (otherwise i is not forbidden).

Print the maximum possible value of |a|·f(a).

package main

import (
	"bufio"
	. "fmt"
	"index/suffixarray"
	"io"
	"os"
	"reflect"
	"unsafe"
)

// github.com/EndlessCheng/codeforces-go
func CF873F(_r io.Reader, _w io.Writer) {
	var n int
	var s, forbidden []byte
	Fscan(bufio.NewReader(_r), &n, &s, &forbidden)
	for i, j := 0, n-1; i < j; i++ {
		s[i], s[j] = s[j], s[i]
		forbidden[i], forbidden[j] = forbidden[j], forbidden[i]
		j--
	}

	sa := *(*[]int32)(unsafe.Pointer(reflect.ValueOf(suffixarray.New(s)).Elem().FieldByName("sa").Field(0).UnsafeAddr()))
	rank := make([]int, n)
	for i := range rank {
		rank[sa[i]] = i
	}
	height := make([]int, n)
	h := 0
	for i, sai := range rank {
		if h > 0 {
			h--
		}
		if sai > 0 {
			for j := int(sa[sai-1]); i+h < n && j+h < n && s[i+h] == s[j+h]; h++ {
			}
		}
		height[sai] = h
	}
	type pair struct{ v, i int }
	posL := make([]int, n)
	stack := []pair{{-1, -1}}
	for i, v := range height {
		for {
			if top := stack[len(stack)-1]; top.v < v {
				posL[i] = top.i
				break
			}
			stack = stack[:len(stack)-1]
		}
		stack = append(stack, pair{v, i})
	}
	posR := make([]int, n)
	stack = []pair{{-1, n}}
	for i := n - 1; i >= 0; i-- {
		v := height[i]
		for {
			if top := stack[len(stack)-1]; top.v < v {
				posR[i] = top.i
				break
			}
			stack = stack[:len(stack)-1]
		}
		stack = append(stack, pair{v, i})
	}

	ans := int64(0)
	for i, v := range forbidden {
		if v == '0' {
			ans = int64(n - i)
			break
		}
	}
	prefixSum := make([]int, n+1)
	for i, p := range sa {
		prefixSum[i+1] = prefixSum[i] + int('1'-forbidden[p])
	}
	for i, h := range height {
		if h > 0 {
			if v := int64(h) * int64(prefixSum[posR[i]]-prefixSum[posL[i]]); v > ans {
				ans = v
			}
		}
	}
	Fprint(_w, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"index/suffixarray"
	"os"
	"reflect"
	"unsafe"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	var n int
	var s, forbidden []byte
	Fscan(bufio.NewReader(os.Stdin), &n, &s, &forbidden)
	for i, j := 0, n-1; i < j; {
		s[i], s[j] = s[j], s[i]
		forbidden[i], forbidden[j] = forbidden[j], forbidden[i]
		i++
		j--
	}

	sa := *(*[]int32)(unsafe.Pointer(reflect.ValueOf(suffixarray.New(s)).Elem().FieldByName("sa").Field(0).UnsafeAddr()))
	rank := make([]int, n)
	for i := range rank {
		rank[sa[i]] = i
	}
	height := make([]int, n)
	h := 0
	for i, sai := range rank {
		if h > 0 {
			h--
		}
		if sai > 0 {
			for j := int(sa[sai-1]); i+h < n && j+h < n && s[i+h] == s[j+h]; h++ {
			}
		}
		height[sai] = h
	}
	type pair struct{ v, i int }
	posL := make([]int, n)
	stack := []pair{{-1, -1}}
	for i, v := range height {
		for {
			if top := stack[len(stack)-1]; top.v < v {
				posL[i] = top.i
				break
			}
			stack = stack[:len(stack)-1]
		}
		stack = append(stack, pair{v, i})
	}
	posR := make([]int, n)
	stack = []pair{{-1, n}}
	for i := n - 1; i >= 0; i-- {
		v := height[i]
		for {
			if top := stack[len(stack)-1]; top.v < v {
				posR[i] = top.i
				break
			}
			stack = stack[:len(stack)-1]
		}
		stack = append(stack, pair{v, i})
	}

	ans := int64(0)
	for i, v := range forbidden {
		if v == '0' {
			ans = int64(n - i)
			break
		}
	}
	prefixSum := make([]int, n+1)
	for i, p := range sa {
		prefixSum[i+1] = prefixSum[i] + int('1'-forbidden[p])
	}
	for i, h := range height {
		if h > 0 {
			if v := int64(h) * int64(prefixSum[posR[i]]-prefixSum[posL[i]]); v > ans {
				ans = v
			}
		}
	}
	Print(ans)
}

package main

import (
	"bufio"
	. "fmt"
	"index/suffixarray"
	"io"
	"os"
	"reflect"
	"unsafe"
)

// github.com/EndlessCheng/codeforces-go
func CF873F(_r io.Reader, _w io.Writer) {
	var n int
	var s, forbidden []byte
	Fscan(bufio.NewReader(_r), &n, &s, &forbidden)

	for i, j := 0, n-1; i < j; i++ {
		s[i], s[j] = s[j], s[i]
		forbidden[i], forbidden[j] = forbidden[j], forbidden[i]
		j--
	}
	ans := int64(0)
	prefixSum := make([]int, n+1)
	for i, v := range forbidden {
		if ans == 0 && v == '0' {
			ans = int64(n - i)
		}
		prefixSum[i+1] = prefixSum[i] + int(v-'0')
	}

	sa := *(*[]int32)(unsafe.Pointer(reflect.ValueOf(suffixarray.New(s)).Elem().FieldByName("sa").Field(0).UnsafeAddr()))
	rank := make([]int, n)
	for i := range rank {
		rank[sa[i]] = i
	}
	height := make([]int, n)
	h := 0
	for i, sai := range rank {
		if h > 0 {
			h--
		}
		if sai > 0 {
			for j := int(sa[sai-1]); i+h < n && j+h < n && s[i+h] == s[j+h]; h++ {
			}
		}
		height[sai] = h
	}

	type pair struct{ v, i int }
	posL := make([]int, n)
	stack := []pair{{-1, -1}}
	for i, v := range height {
		for {
			if top := stack[len(stack)-1]; top.v < v {
				posL[i] = top.i
				break
			}
			stack = stack[:len(stack)-1]
		}
		stack = append(stack, pair{v, i})
	}
	posR := make([]int, n)
	stack = []pair{{-1, n}}
	for i := n - 1; i >= 0; i-- {
		v := height[i]
		for {
			if top := stack[len(stack)-1]; top.v < v {
				posR[i] = top.i
				break
			}
			stack = stack[:len(stack)-1]
		}
		stack = append(stack, pair{v, i})
	}

	for i, h := range height {
		if h > 0 {
			if v := int64(h) * int64(posR[i]-posL[i]-(prefixSum[posR[i]]-prefixSum[posL[i]])); v > ans {
				ans = v
			}
		}
	}
	Fprint(_w, ans)
}

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


There are $$$n$$$ pillars aligned in a row and numbered from $$$1$$$ to $$$n$$$.Initially each pillar contains exactly one disk. The $$$i$$$-th pillar contains a disk having radius $$$a_i$$$.You can move these disks from one pillar to another. You can take a disk from pillar $$$i$$$ and place it on top of pillar $$$j$$$ if all these conditions are met:  there is no other pillar between pillars $$$i$$$ and $$$j$$$. Formally, it means that $$$|i - j| = 1$$$;  pillar $$$i$$$ contains exactly one disk;  either pillar $$$j$$$ contains no disks, or the topmost disk on pillar $$$j$$$ has radius strictly greater than the radius of the disk you move. When you place a disk on a pillar that already has some disks on it, you put the new disk on top of previously placed disks, so the new disk will be used to check the third condition if you try to place another disk on the same pillar.You may take any disk and place it on other pillar any number of times, provided that every time you do it, all three aforementioned conditions are met. Now you wonder, is it possible to place all $$$n$$$ disks on the same pillar simultaneously?

The first line contains one integer $$$n$$$ ($$$3 \le n \le 2 \cdot 10^5$$$) — the number of pillars. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_i$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the radius of the disk initially placed on the $$$i$$$-th pillar. All numbers $$$a_i$$$ are distinct.

Print YES if it is possible to place all the disks on the same pillar simultaneously, and NO otherwise. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).

NoteIn the first case it is possible to place all disks on pillar $$$3$$$ using the following sequence of actions:  take the disk with radius $$$3$$$ from pillar $$$2$$$ and place it on top of pillar $$$3$$$;  take the disk with radius $$$1$$$ from pillar $$$1$$$ and place it on top of pillar $$$2$$$;  take the disk with radius $$$2$$$ from pillar $$$4$$$ and place it on top of pillar $$$3$$$;  take the disk with radius $$$1$$$ from pillar $$$2$$$ and place it on top of pillar $$$3$$$.

package main

import (
	"bufio"
	"container/list"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {

	n := readInt()
	l := list.New()

	var max *list.Element
	for i := 0; i < n; i++ {
		e := l.PushBack(readInt())
		if max == nil || max.Value.(int) < e.Value.(int) {
			max = e
		}
	}

	for max.Next() != nil || max.Prev() != nil {
		old := max
		if max.Next() != nil && max.Next().Value.(int) == max.Value.(int)-1 {
			max = max.Next()
		} else if max.Prev() != nil && max.Prev().Value.(int) == max.Value.(int)-1 {
			max = max.Prev()
		} else {
			print("NO")
			return
		}
		l.Remove(old)
	}

	print("YES")

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)
	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	total, _ := strconv.Atoi(scanner.Text())
	arr := make([]int, 0, total)
	for scanner.Scan() {
		e, _ := strconv.Atoi(scanner.Text())
		arr = append(arr, e)
	}
	max := 0
	i := 0
	for ; i < len(arr); i++ {
		v := arr[i]
		if v > max {
			max = v
		} else {
			break
		}
	}
	for ; i < len(arr); i++ {
		v1 := arr[i-1]
		v2 := arr[i]
		if v2 > v1 {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := PrintlnInts(X...)

/*******************************************************************/

func main() {
	n := ReadInt()
	a := ReadIntSlice(n)
	for i, j, k := 0, 1, 2; k < n; {
		if a[i] >= a[j] && a[j] <= a[k] {
			fmt.Println("NO")
			return
		}
		i++
		j++
		k++
	}
	fmt.Println("YES")
}

/*********** Math ***********/
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return readInt()
}
func ReadInt2() (int, int) {
	return readInt(), readInt()
}
func ReadInt3() (int, int, int) {
	return readInt(), readInt(), readInt()
}
func ReadInt4() (int, int, int, int) {
	return readInt(), readInt(), readInt(), readInt()
}

func readInt_64() int64 {
	return readIntNbits(64)
}

func ReadInt2_64() (int64, int64) {
	return readInt_64(), readInt_64()
}

func ReadInt3_64() (int64, int64, int64) {
	return readInt_64(), readInt_64(), readInt_64()
}

func readInt() int {
	return int(readIntNbits(32))
}

func readIntNbits(n int) int64 {
	i, err := strconv.ParseInt(ReadString(), 0, n)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

// PrintIntsLine returns integers string delimited by a space.
func PrintlnInts(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	var num int

	_, err := fmt.Fscanf(input, "%d\n", &num)
	if err != nil {
	}

	var pillar = make([]int, num)
	var index, max int

	for i := 0; i < num; i++ {
		_, err := fmt.Fscanf(input, "%v", &pillar[i])
		if pillar[i] > max {
			max = pillar[i]
			index = i
		}
		if err != nil {
		}
	}

	for i, j := 1, 1; ; {
		left := 0
		right := 0
		if index-i >= 0 {
			left = pillar[index-i]
		}
		if index+j < num {
			right = pillar[index+j]
		}
		if index-i < 0 && index+j >= num {
			break
		}

		if left < max && left >= right {
			max = left
			i++
			continue
		}
		if right < max && right > left {
			max = right
			j++
			continue
		}
		fmt.Println("NO")
		return
	}
	fmt.Println("YES")

}

package main

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

func main() {

	//stdin, err := os.Open("test.txt")
	//if err != nil {
	///	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var n, c, p, f int

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

	a := make([]int, n, n)
	m := make(map[int]bool)

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

		fmt.Fscanf(reader, "%d", &a[i])
		m[a[i]] = true
		if i > 0 {
			c = a[i] - a[i-1]
			if i == 0 {
				p = c
			}
			if (p > 0 && c < 0) || (p < 0 && c > 0) || (p == 0 && c < 0) || (p < 0 && c == 0) {
				//fmt.Println("+")
				f++
			}
			//fmt.Println(p, c)
			p = c
		}
	}

	if (f == 1 || f == 0) && len(m) == n {
		fmt.Fprintf(writer, "YES\n")
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

	writer.Flush()
}

// Author: sighduck
// URL: https://codeforces.com/contest/1197/problem/B

package main

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

func Solve(n int, a []int) string {
	maxIndex := -1
	maxElem := 0
	for i, elem := range a {
		if elem > maxElem {
			maxIndex = i
			maxElem = elem
		}
	}
	for i := 0; i < maxIndex; i++ {
		if !(a[i] < a[i+1]) {
			return "NO"
		}
	}
	for i := n - 1; i > maxIndex; i-- {
		if !(a[i] < a[i-1]) {
			return "NO"
		}
	}
	return "YES"
}

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

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

	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}

package main

import (
	"fmt"
)

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

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

func abs (a, b int) int {
	return max (a, b) - min (a, b)
}

const N = 2 * 1e5 + 5

func main () {

	var x[N] int
	var n int

	fmt.Scanf("%d", &n)

	var a int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		x[a] = i + 1
	}

	var left, right int
	left = 1
	right = 1
	for i := n - 1; i >= 1; i-- {
		if x[i] < x[n] {
			if abs (x[i], x[n]) <= left {
				left++
			} else {
				fmt.Println("NO")
				return
			}
		}

		if x[i] > x[n] {
			if abs (x[i], x[n]) <= right {
				right++
			} else {
				fmt.Println("NO")
				return
			}
		}
	}

	fmt.Println("YES")

}

package main

import "fmt"

func main() {
	var num int

	_, err := fmt.Scan(&num)
	if err != nil {
	}

	var pillar = make([]int, num)
	var index, max int

	for i := 0; i < num; i++ {
		_, err := fmt.Scan(&pillar[i])
		if pillar[i] > max {
			max = pillar[i]
			index = i
		}
		if err != nil {
		}
	}

	for i, j := 1, 1; ; {
		left := 0
		right := 0
		if index-i >= 0 {
			left = pillar[index-i]
		}
		if index+j < num {
			right = pillar[index+j]
		}
		if index-i < 0 && index+j >= num {
			break
		}

		if left < max && left >= right {
			max = left
			i++
			continue
		}
		if right < max && right > left {
			max = right
			j++
			continue
		}
		fmt.Println("NO")
		break
	}
	fmt.Println("YES")

}

package main

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

func main() {

	//stdin, err := os.Open("test.txt")
	//if err != nil {
	///	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var n, c, p, f int

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

	a := make([]int, n, n)
	m := make(map[int]bool)

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

		fmt.Fscanf(reader, "%d", &a[i])
		m[a[i]] = true
		if i > 0 {
			c = a[i] - a[i-1]
			if i == 0 {
				p = c
			}
			if (p > 0 && c < 0) || (p < 0 && c > 0) || (p == 0 && c < 0) || (p < 0 && c == 0) {
				//fmt.Println("+")
				f++
			}
			//fmt.Println(p, c)
			p = c
		}
	}

	if f == 1 && len(m) == n {
		fmt.Fprintf(writer, "YES\n")
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

	writer.Flush()
}

package main

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

func main() {

	//stdin, err := os.Open("test.txt")
	//if err != nil {
	///	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("test.txt")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)

	var n, c, p, f int

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

	a := make([]int, n, n)
	m := make(map[int]bool)

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

		fmt.Fscanf(reader, "%d", &a[i])
		m[a[i]] = true
		if i > 0 {
			c = a[i] - a[i-1]
			if i == 0 {
				p = c
			}
			if (p > 0 && c < 0) || (p < 0 && c > 0) {
				f++
			}
			p = c
		}
	}

	if f == 1 && len(m) == n {
		fmt.Fprintf(writer, "YES\n")
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

	writer.Flush()
}


Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if   the sequence consists of at least two elements  f0 and f1 are arbitrary  fn + 2 = fn + 1 + fn for all n ≥ 0. You are given some sequence of integers a1, a2, ..., an. Your task is rearrange elements of this sequence in such a way that its longest possible prefix is Fibonacci-ish sequence.

The first line of the input contains a single integer n (2 ≤ n ≤ 1000) — the length of the sequence ai. The second line contains n integers a1, a2, ..., an (|ai| ≤ 109).

Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement.

NoteIn the first sample, if we rearrange elements of the sequence as  - 1, 2, 1, the whole sequence ai would be Fibonacci-ish.In the second sample, the optimal way to rearrange elements is , , , , 28.

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func lengthOfFib(frequency map[int]int, f1 int, f2 int) int {

	if f1 == 0 && f2 == 0 {
		return frequency[0] + 2
	}

	length := 2

	if frequency[f1+f2] > 0 {
		frequency[f1+f2]--
		length = 1 + lengthOfFib(frequency, f2, f1+f2)
		frequency[f1+f2]++
	}

	return length
}

func main() {

	var (
		n         int
		max       int
		numbers   []int
		frequency map[int]int
	)

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

	numbers = make([]int, n)
	frequency = make(map[int]int)

	for i := 0; i < n; i++ {
		fmt.Fscanf(stdin, "%d", &numbers[i])
		frequency[numbers[i]]++
	}

    sort.Ints(numbers)

	max = 0
	for i := 0; i < n; i++ {
        if i > 0 && numbers[i - 1] == numbers[i] {
            continue
        }
		frequency[numbers[i]]--
		for j := 0; j < n; j++ {

			if i == j {
				continue
			}
            if j > 0 && j - 1 != i && numbers[j - 1] == numbers[j] {
                continue
            }

			frequency[numbers[j]]--
			length := lengthOfFib(frequency, numbers[i], numbers[j])

			if length > max {
				max = length
			}
            frequency[numbers[j]]++
		}
        frequency[numbers[i]]++
	}

	fmt.Fprintf(stdout, "%d\n", max)

	stdout.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF633D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	cnt := map[int]int{}
	var n, v, ans int
	Fscan(in, &n)
	a := []int{}
	for ; n > 0; n-- {
		Fscan(in, &v)
		cnt[v]++
		if v != 0 {
			a = append(a, v)
		}
	}
	if c := cnt[0]; c > 0 {
		ans = c
		a = append(a, 0)
	}
	for i, v := range a {
		for _, w := range a[i+1:] {
			c := 2
			mp := map[int]int{v: 1}
			mp[w]++
			for x, y := v, w; mp[x+y] < cnt[x+y]; x, y = y, x+y {
				mp[x+y]++
				c++
			}
			for x, y := w, v; mp[x-y] < cnt[x-y]; x, y = y, x-y {
				mp[x-y]++
				c++
			}
			if c > ans {
				ans = c
			}
		}
	}
	Fprint(out, ans)
}

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

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func lengthOfFib(frequency map[int]int, f1 int, f2 int) int {

	if f1 == 0 && f2 == 0 {
		return frequency[0] + 2
	}

	length := 2

	if frequency[f1+f2] > 0 {
		frequency[f1+f2]--
		length = 1 + lengthOfFib(frequency, f2, f1+f2)
		frequency[f1+f2]++
	}

	return length
}

func main() {

	var (
		n         int
		max       int
		numbers   []int
		frequency map[int]int
	)

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

	numbers = make([]int, n)
	frequency = make(map[int]int)

	for i := 0; i < n; i++ {
		fmt.Fscanf(stdin, "%d", &numbers[i])
		frequency[numbers[i]]++
	}

    sort.Ints(numbers)

	max = 0
	for i := 0; i < n; i++ {
        if i > 0 && numbers[i - 1] == numbers[i] {
            continue
        }
		frequency[numbers[i]]--
		for j := 0; j < n; j++ {

			if i == j {
				continue
			}
            if j > 0 && numbers[j - 1] == numbers[j] {
                continue
            }

			frequency[numbers[j]]--
			length := lengthOfFib(frequency, numbers[i], numbers[j])

			if length > max {
				max = length
			}
            frequency[numbers[j]]++
		}
        frequency[numbers[i]]++
	}

	fmt.Fprintf(stdout, "%d\n", max)

	stdout.Flush()
}


A median of an array of integers of length $$$n$$$ is the number standing on the $$$\lceil {\frac{n}{2}} \rceil$$$ (rounding up) position in the non-decreasing ordering of its elements. Positions are numbered starting with $$$1$$$. For example, a median of the array $$$[2, 6, 4, 1, 3, 5]$$$ is equal to $$$3$$$. There exist some other definitions of the median, but in this problem, we will use the described one.Given two integers $$$n$$$ and $$$k$$$ and non-decreasing array of $$$nk$$$ integers. Divide all numbers into $$$k$$$ arrays of size $$$n$$$, such that each number belongs to exactly one array.You want the sum of medians of all $$$k$$$ arrays to be the maximum possible. Find this maximum possible sum.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of test cases. The first line of the description of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \leq n, k \leq 1000$$$). The second line of the description of each test case contains $$$nk$$$ integers $$$a_1, a_2, \ldots, a_{nk}$$$ ($$$0 \leq a_i \leq 10^9$$$) — given array. It is guaranteed that the array is non-decreasing: $$$a_1 \leq a_2 \leq \ldots \leq a_{nk}$$$. It is guaranteed that the sum of $$$nk$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case print a single integer — the maximum possible sum of medians of all $$$k$$$ arrays.

package main

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

func solve(in *bufio.Reader, out *bufio.Writer) {
    var n, k int
    fmt.Fscan(in, &n, &k)
    var arr = make([]int, n * k)
    for i := range arr {
        fmt.Fscan(in, &arr[len(arr) - i - 1])
    }
    n = n / 2 + 1
    var ans int64 = 0;
    for i := 1; i <= k; i++ {
        ans += int64(arr[i * n - 1])
    }
    fmt.Fprintln(out, ans)
}

func main() {
    var n int
    var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
    defer out.Flush()
    fmt.Fscan(in, &n)
    for ;n > 0; n-- {
        solve(in, out)
    }
}

package main

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

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

	var T, n, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		a := make([]int, n*k)
		for i := range a {
			Fscan(in, &a[i])
		}
		s := int64(0)
		for i, c := n*k, 0; c < k; c++ {
			i -= n/2 + 1
			s += int64(a[i])
		}
		Fprintln(out, s)
	}
}

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

package main

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

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

	var T, n, k int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k)
		a := make([]int, n*k)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		s := int64(0)
		for i, c := n*k, 0; c < k; c++ {
			i -= n/2 + 1
			s += int64(a[i])
		}
		Fprintln(out, s)
	}
}

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

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, k, a int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		sum := int64(0)
		offset := n/2 + 1
		nextMedian := (n-offset)*k + 1

		for i := 1; i <= n*k; i++ {
			fmt.Fscan(in, &a)
			if i == nextMedian {
				sum += int64(a)
				nextMedian += offset
			}
		}
		fmt.Println(sum)
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n, k := sint64(), sint64()
		a := make([]int64, n*k)
		for i := range a {
			a[i] = sint64()
		}
		printf("%d\n", sol(n, k, a))
	}
}

func sol(n, k int64, a []int64) int64 {
	sort.Slice(a, func(il, ir int) bool {
		return a[il] < a[ir]
	})
	var (
		start int64
		jump int64
	)
	if n&1 == 0 {
		p := (n / 2) - 1
		start = p * k
		jump = n - p
	} else {
		p := n / 2
		start = p * k
		jump = n - p
	}
	ret := int64(0)
	for i := start; i < n*k; i += jump {
		ret += a[i]
	}
	return ret
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, k, a int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k)
		sum := 0
		offset := n/2 + 1
		nextMedian := (n-offset)*k + 1

		for i := 1; i <= n*k; i++ {
			fmt.Fscan(in, &a)
			if i == nextMedian {
				sum += a
				nextMedian += offset
			}
		}
		fmt.Println(sum)
	}
}


Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.

The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line contains n space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive.

Print the maximum possible even sum that can be obtained if we use some of the given integers.

NoteIn the first sample, we can simply take all three integers for a total sum of 6.In the second sample Wet Shark should take any four out of five integers 999 999 999.

package main

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

func main() {
    var n, i int
    var sum, a, minodd int64
    fmt.Scan(&n)

    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    minodd = 1e9
    for i = 0; i < n; i++ {
        bs.Scan()
        a, _ = strconv.ParseInt(bs.Text(), 10, 64)
        if a % 2 == 0 {
            sum += a
        } else {
            if minodd > a {
                if minodd != 1e9 {
                    sum += minodd
                }
                minodd = a
            } else {
                sum += a
            }
        }
    }

    if sum % 2 != 0 {
        sum += minodd
    }

    fmt.Println(sum)
}

package main

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

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

	var line string
	scanner := bufio.NewScanner(os.Stdin)

	buf := make([]byte, 0, 64*1024)
	scanner.Buffer(buf, 2048*1024)

	if scanner.Scan() {
		line = scanner.Text()
	}

	integers := strings.Split(line, " ")

	var sum, minOdd uint64
	sum = 0
	minOdd = 10000000001
	for i := 0; i < n; i++ {
		integer, _ := strconv.ParseUint(integers[i], 10, 64)
		sum += integer
		if integer%2 == 1 && integer < minOdd {
			minOdd = integer
		}
	}

	if sum%2 == 0 {
		fmt.Println(sum)
	} else {
		fmt.Println(sum - minOdd)
	}
}


Given the integer $$$n$$$ — the number of available blocks. You must use all blocks to build a pedestal. The pedestal consists of $$$3$$$ platforms for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places respectively. The platform for the $$$1$$$-st place must be strictly higher than for the $$$2$$$-nd place, and the platform for the $$$2$$$-nd place must be strictly higher than for the $$$3$$$-rd place. Also, the height of each platform must be greater than zero (that is, each platform must contain at least one block).    Example pedestal of $$$n=11$$$ blocks: second place height equals $$$4$$$ blocks, first place height equals $$$5$$$ blocks, third place height equals $$$2$$$ blocks.Among all possible pedestals of $$$n$$$ blocks, deduce one such that the platform height for the $$$1$$$-st place minimum as possible. If there are several of them, output any of them.

The first line of input data contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case contains a single integer $$$n$$$ ($$$6 \le n \le 10^5$$$) — the total number of blocks for the pedestal. All $$$n$$$ blocks must be used. It is guaranteed that the sum of $$$n$$$ values over all test cases does not exceed $$$10^6$$$.

For each test case, output $$$3$$$ numbers $$$h_2, h_1, h_3$$$ — the platform heights for $$$2$$$-nd, $$$1$$$-st and $$$3$$$-rd places on a pedestal consisting of $$$n$$$ blocks ($$$h_1+h_2+h_3=n$$$, $$$0 < h_3 < h_2 < h_1$$$).  Among all possible pedestals, output the one for which the value of $$$h_1$$$ minimal. If there are several of them, output any of them.

NoteIn the first test case we can not get the height of the platform for the first place less than $$$5$$$, because if the height of the platform for the first place is not more than $$$4$$$, then we can use at most $$$4 + 3 + 2 = 9$$$ blocks. And we should use $$$11 = 4 + 5 + 2$$$ blocks. Therefore, the answer 4 5 2 fits. In the second set, the only suitable answer is: 2 3 1.

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		t := N / 3
		if N%3 == 0 {
			fmt.Fprintln(out, t, t+1, t-1)
		} else if N%3 == 1 {
			fmt.Fprintln(out, t, t+2, t-1)
		} else {
			fmt.Fprintln(out, t+1, t+2, t-1)
		}
	}
}

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

package main

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

func run(_r io.Reader, _w io.Writer){
    in := bufio.NewScanner(_r)
    out := bufio.NewWriter(_w)
    defer out.Flush()
    in.Split(bufio.ScanWords)
    read := func() (x int) {
        in.Scan()
        for _, v := range in.Bytes() {
            x = x*10 + int(v & 15)
        }
        return
    }
    for t := read(); t > 0; t-- {
        n := read() - 6
        tmp := n % 3
        n /= 3
        switch tmp {
            case 1:
                Fprintln(out, n+2, n+4, n+1)
            case 2:
                Fprintln(out, n+3, n+4, n+1)
            default:
                Fprintln(out, n+2, n+3, n+1)
        }
    }
}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		if n%3 == 0 {
			fmt.Println(n/3, n/3+1, n/3-1)
		} else if n%3 == 1 {
			fmt.Println(n/3, n/3+2, n/3-1)
		} else {
			fmt.Println(n/3+1, n/3+2, n/3-1)
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		if n%3 == 0 {
			fmt.Println(n/3, n/3+1, n/3-1)
		} else if n == 7 {
			fmt.Println(2, 4, 1)
		} else if n%3 == 1 {
			fmt.Println(n/3, n/3+2, n/3-1)
		} else {
			fmt.Println(n/3+1, n/3+2, n/3-1)
		}
	}
}

package main

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

const (
	MaxInt32 = 1 << 31 - 1
)

func main(){
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for tc := 0; tc < t; tc++ {
		var n int
		fmt.Fscan(cin, &n)
		h2, h1, h3 := n / 3, n / 3, n /3
		if n % 3 == 0 {
			h1 += 1
			h3 -= 1
		}else {
			r := n % 3
			h1 += r
			h2 += 1
			h3 -= 1
			if h1 == h2 {
				h1 += 1
				h2 -= 1
			}
		}

		fmt.Printf("%d %d %d\n", h2, h1, h3)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		if n%3 == 0 {
			fmt.Fprintln(out, n/3, n/3+1, n/3-1)
		} else if n%3 == 1 {
			fmt.Fprintln(out, n/3, n/3+2, n/3-1)
		} else {
			fmt.Fprintln(out, n/3+1, n/3+2, n/3-1)
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1690A
Date: 8/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1690/A
Problem: CF1690A
**/
func (in *CF1690A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		a, b, c := 2, n-3, 1
		for i := b; i >= 0; i-- {
			if i-1 > 0 && n-i-(i-1) > 0 && n-i-(i-1) < i-1 {
				a = i - 1
				b = i
				c = n - i - (i - 1)
			}
		}
		fmt.Println(a, b, c)
	}
}

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

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

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)

		var h1, h2, h3 int
		h2 = n / 3
		h3 = h2 - 1
		if n%3 == 0 {
			h1 = h2 + 1
		} else if n%3 == 1 {
			h1 = h2 + 2
		} else {
			h1 = h2 + 2
			h2++
		}
		fmt.Fprintln(out, h2, h1, h3)
	}
}

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)

		h3 := n / 3
		h2 := (n - h3) / 2
		h1 := n - h2 - h3
		if h1 == h2 {
			h1++
			h3--
		}

		if h2 == h3 {
			h1++
			h3--
		}

		fmt.Fprintln(out, h2, h1, h3)
	}
}

package main

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

func A1() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		if n%3 == 0 {
			Fprintln(out, n/3, n/3+1, n/3-1)
		} else if n%3 == 1 {
			Fprintln(out, n/3, n/3+2, n/3-1)
		} else if n%3 == 2 {
			Fprintln(out, n/3+1, n/3+2, n/3-1)
		}

	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		if n%3 == 0 {
			fmt.Println((n/3),(n/3)+1,(n/3)-1)
		} else if n%3 == 1 {
			fmt.Println((n/3),(n/3)+2,(n/3)-1)
		} else {
			fmt.Println((n/3)+1,(n/3)+2,(n/3)-1)
		}
	}
}

package main

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

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

func solve(n int) string {
	var x, y, z = 2 + (n-6)/3, 3 + (n-6)/3, 1 + (n-6)/3
	if n%3 == 1 {
		y++
	}
	if n%3 == 2 {
		x++
		y++
	}
	return fmt.Sprintf("%d %d %d", x, y, z)
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		fmt.Println(solve(n))
	}
}

package main

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

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}
func solve() {
	n := 0
	scan(&n)
	hmin := int((n - 3) / 3)
	// printf("%dabc\n", hmin)
	for ; ; hmin++ {
		h1 := hmin
		h2 := hmin - 1
		for ; h2 > 1; h2-- {
			h3 := n - (h1 + h2)
			if h2 > h3 && h3 > 0 {
				printf("%d %d %d\n", h2, h1, h3)
				return
			}
		}
	}
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	// printf("a")
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for ii := 0; ii < t; ii++ {
		n := 0
		fmt.Fscan(in, &n)
		l, h := 0, n
		for l < h {
			one := (l + h) / 2
			two := (n-one)/2 + 1
			if two >= one {
				l = one + 1
			} else {
				h = one
			}
		}
		s := (n-l)/2 + 1
		fmt.Fprintln(out, s, l, n-s-l)
	}

}

package main

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

/*

 */

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

	h1 := n/3 + 1
	h2 := h1 - 1
	h3 := h2 - 1

	rem := n - h1 - h2 - h3

	if rem == 1 {
		h1++
	} else if rem == 2 {
		h1++
		h2++
	}

	fmt.Fprintln(writer, h2, h1, h3)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

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

	return minNumIdx
}

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

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

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

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

	return factors
}

package main

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

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

func slove() {
	var n int
	fmt.Fscan(r, &n)
	if n % 3 == 0 {
		fmt.Fprintln(w, n/3, n/3+1, n/3-1)
	} else if n % 3 == 1 {
		fmt.Fprintln(w, n/3, n/3+2, n/3-1)
	} else {
		fmt.Fprintln(w, n/3+1, n/3+2, n/3-1)
	}
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		t := N / 3
		if N%3 == 0 {
			fmt.Fprintln(out, t, t+1, t-1)
		} else if N%3 == 1 {
			fmt.Fprintln(out, t-1, t+1, t-2)
		} else {
			fmt.Fprintln(out, t+1, t+2, t-1)
		}
	}
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		t := N / 3
		if N%3 == 0 {
			fmt.Fprintln(out, t, t+1, t-1)
		} else if N%3 == 1 {
			fmt.Fprintln(out, t+1, t+2, t-2)
		} else {
			fmt.Fprintln(out, t+1, t+2, t-1)
		}
	}
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		N /= 3
		if N%3 == 0 {
			fmt.Fprintln(out, N, N+1, N-1)
		} else if N%3 == 1 {
			fmt.Fprintln(out, N+1, N+2, N-2)
		} else {
			fmt.Fprintln(out, N+1, N+2, N-1)
		}
	}
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		N /= 3
		if N%3 == 0 {
			fmt.Fprintln(out, N, N+1, N-1)
		} else if N%3 == 1 {
			fmt.Fprintln(out, N, N+2, N-1)
		} else {
			fmt.Fprintln(out, N+1, N+2, N-1)
		}
	}
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		N--
		if N%2 == 0 {
			fmt.Fprintln(out, N/2-1, N/2+1, 1)
		} else {
			fmt.Fprintln(out, (N-1)/2, (N+1)/2, 1)
		}
	}
}

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

package main

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

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

	var T, N int
	for fmt.Fscan(in, &T); T > 0; T-- {
		fmt.Fscan(in, &N)
		N--
		if N%2 == 0 {
			fmt.Fprintln(out, N-1, N+1, 1)
		} else {
			fmt.Fprintln(out, (N-1)/2, (N+1)/2, 1)
		}
	}
}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		if n%3 == 0 {
			fmt.Println(n/3, n/3+1, n/3-1)
		} else if n%3 == 1 {
			fmt.Println(n/3, n/3+2, n/3-1)
		} else {
			fmt.Println(n/3, +1, n/3+2, n/3-1)
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Scan(&n)
		if n%3 == 0 {
			fmt.Println(n/3, n/3+1, n/3-1)
		} else if n == 7 {
			fmt.Println(2, 4, 1)
		} else if n%3 == 1 {
			fmt.Println(n/3, n/3+2, n/3-1)
		} else {
			fmt.Println(n/3+1, n/3+2, n/3-1)
		}
	}
}

package main

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

const (
	MaxInt32 = 1 << 31 - 1
)

func main(){
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for tc := 0; tc < t; tc++ {
		var n int
		fmt.Fscan(cin, &n)
		a, b, c := 2, n - 3, 1
		fmt.Printf("%d %d %d\n", a, b, c)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		fmt.Fprintln(out, n/3, n-n/3*2+1, n/3-1)
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1690A
Date: 8/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1690/A
Problem: CF1690A
**/
func (in *CF1690A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		fmt.Println("2", n-3, 1)
	}
}

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

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

package main

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

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

		Fprintln(out, 2, n-3, 1)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}
func main() { A1() }


You are given string s consists of opening and closing brackets of four kinds <>, {}, [], (). There are two types of brackets: opening and closing. You can replace any bracket by another of the same type. For example, you can replace < by the bracket {, but you can't replace it by ) or >.The following definition of a regular bracket sequence is well-known, so you can be familiar with it.Let's define a regular bracket sequence (RBS). Empty string is RBS. Let s1 and s2 be a RBS then the strings <s1>s2, {s1}s2, [s1]s2, (s1)s2 are also RBS.For example the string "[[(){}]<>]" is RBS, but the strings "[)()" and "][()()" are not.Determine the least number of replaces to make the string s RBS.

The only line contains a non empty string s, consisting of only opening and closing brackets of four kinds. The length of s does not exceed 106.

If it's impossible to get RBS from s print Impossible. Otherwise print the least number of replaces needed to get RBS from s.

package main

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

/*
    You are given string s consists of opening and closing brackets of four kinds <>, {}, [], ().
    There are two types of brackets: opening and closing. You can replace any bracket by another of the same type.
    For example, you can replace < by the bracket {, but you can't replace it by ) or >.

    Determine the least number of replaces to make the string s regular braket sequence.
*/

type BracketStack struct {
    Brackets []byte
    Size int
}

func (s *BracketStack) Push(value byte) {
    s.Brackets = append(s.Brackets, value)
    s.Size += 1
}

func (s *BracketStack) Pop() (value byte) {
    if s.Size > 0 {
        value = s.Brackets[s.Size-1]
        s.Brackets = s.Brackets[0:s.Size-1]
        s.Size -= 1
        return value
    }
    return 'n'
}

func main() {
    stin := bufio.NewReader(os.Stdin)
    var s string
    fmt.Fscanln(stin, &s)
    //fmt.Printf("%s\n", s)
    sl := len(s)
    q := BracketStack{Brackets:make([]byte, 0), Size:0}
    answer := 0
    for i := 0; i < sl; i++ {
        if s[i] == '{' || s[i] == '<' || s[i] == '(' || s[i] == '[' {
            q.Push(s[i])
        } else {
            if q.Size == 0 {
                fmt.Printf("Impossible")
                return
            } else {
                currentTop := q.Brackets[q.Size-1]
                if (s[i] == '}' && currentTop == '{') ||
                   (s[i] == '>' && currentTop == '<') ||
                   (s[i] == ')' && currentTop == '(') ||
                   (s[i] == ']' && currentTop == '[') {
                    q.Pop()
                } else {
                    q.Pop()
                    answer += 1
                }
            }
        }
    }
    if q.Size == 0 {
        fmt.Printf("%d", answer)
    } else {
        fmt.Printf("Impossible")
    }
}

package main

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

func Abs(x int) int {
	switch {
	case x < 0:
		return -x
	case x == 0:
		return 0
	}
	return x
}

func Scan(args ...interface{}) (e error)             { _, e = fmt.Fscan(in, args...); return }
func Scanf(ft string, args ...interface{}) (e error) { _, e = fmt.Fscanf(in, ft, args...); return }
func Scanln(args ...interface{}) (e error)           { _, e = fmt.Fscanln(in, args...); return }
func Print(args ...interface{})                      { out.WriteString(fmt.Sprint(args...)) }
func Printf(ft string, args ...interface{})          { out.WriteString(fmt.Sprintf(ft, args...)) }
func Println(args ...interface{})                    { out.WriteString(fmt.Sprintln(args...)) }

var (
	dataIn = "data.in"
	in     = bufio.NewReader(os.Stdin)
	//in, _ = os.Open(dataIn)
	out   = bufio.NewWriter(os.Stdout)
)

var bat string

func solve() {
	stack := make([]rune, len(bat))
	top := 0
	cnt := 0
	for _, char := range bat {
		switch char {
		case '<', '{', '[', '(':
			stack[top] = char
			top++
		case '>', '}', ']', ')':
			if top == 0 {
				cnt = -1
				break
			} else {
				if Abs(int(char-stack[top-1])) > 2 {
					cnt++
				}
				top--
			}
		}
	}
	if top > 0 || cnt == -1 {
		Println("Impossible")
	} else {
		Println(cnt)
	}
}

func main() {
	defer out.Flush()
	for Scan(&bat) != io.EOF {
		solve()
	}
	return
}

package main

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

func check(seq string) bool {
	open := 0
	for _, v := range seq {
		if v == '<' || v == '{' || v == '[' || v == '(' {
			open++
		} else {
			open--
			if open < 0 {
				return false
			}
		}
	}
	return open == 0
}

func pair(c rune) rune {
	switch c {
	case '<':
		return '>'
	case '{':
		return '}'
	case '[':
		return ']'
	case '(':
		return ')'
	default:
		panic("no way")
	}
}

func solve(seq string) int {
	ans := 0
	stack := []rune{}
	for _, v := range seq {
		if v == '<' || v == '{' || v == '[' || v == '(' {
			stack = append(stack, pair(v))
		} else {
			if v != stack[len(stack)-1] {
				ans++
			}
			stack = stack[:len(stack)-1]
		}
	}
	return ans
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var seq string
	fmt.Fscanln(in, &seq)
	if !check(seq) {
		fmt.Println("Impossible")
	} else {
		fmt.Println(solve(seq))
	}
}

package main

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

/*
    You are given string s consists of opening and closing brackets of four kinds <>, {}, [], ().
    There are two types of brackets: opening and closing. You can replace any bracket by another of the same type.
    For example, you can replace < by the bracket {, but you can't replace it by ) or >.

    Determine the least number of replaces to make the string s regular braket sequence.
*/

type BracketStack struct {
    Brackets []byte
    Size int
}

func (s *BracketStack) Push(value byte) {
    s.Brackets = append(s.Brackets, value)
    s.Size += 1
}

func (s *BracketStack) Pop() (value byte) {
    if s.Size > 0 {
        value = s.Brackets[s.Size-1]
        s.Brackets = s.Brackets[0:s.Size-1]
        s.Size -= 1
        return value
    }
    return 'n'
}

func main() {
    stin := bufio.NewReader(os.Stdin)
    var s string
    fmt.Fscanln(stin, &s)
    //fmt.Printf("%s\n", s)
    sl := len(s)
    q := BracketStack{Brackets:make([]byte, 0), Size:0}
    answer := 0
    for i := 0; i < sl; i++ {
        if s[i] == '{' || s[i] == '<' || s[i] == '(' || s[i] == '[' {
            q.Push(s[i])
        } else {
            if q.Size == 0 {
                fmt.Printf("Impossible")
                return
            } else {
                currentTop := q.Brackets[q.Size-1]
                if (s[i] == '}' && currentTop == '{') ||
                   (s[i] == '>' && currentTop == '<') ||
                   (s[i] == ')' && currentTop == '(') ||
                   (s[i] == ']' && currentTop == '[') {
                    q.Pop()
                } else {
                    answer += 1
                }
            }
        }
    }
    if q.Size == 0 {
        fmt.Printf("%d", answer)
    } else {
        fmt.Printf("Impossible")
    }
}

package main

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

/*
    You are given string s consists of opening and closing brackets of four kinds <>, {}, [], ().
    There are two types of brackets: opening and closing. You can replace any bracket by another of the same type.
    For example, you can replace < by the bracket {, but you can't replace it by ) or >.

    Determine the least number of replaces to make the string s regular braket sequence.
*/

type BracketStack struct {
    Brackets []byte
    Size int
}

func (s *BracketStack) Push(value byte) {
    s.Brackets = append(s.Brackets, value)
    s.Size += 1
}

func (s *BracketStack) Pop() (value byte) {
    if s.Size > 0 {
        value = s.Brackets[s.Size-1]
        s.Brackets = s.Brackets[0:s.Size-1]
        s.Size -= 1
        return value
    }
    return 'n'
}

func main() {
    stin := bufio.NewReader(os.Stdin)
    var s string
    fmt.Fscanln(stin, &s)
    //fmt.Printf("%s\n", s)
    sl := len(s)
    q := BracketStack{Brackets:make([]byte, 0), Size:0}
    answer := 0
    for i := 0; i < sl; i++ {
        if s[i] == '{' || s[i] == '<' || s[i] == '(' || s[i] == '[' {
            q.Push(s[i])
        } else {
            if q.Size == 0 {
                fmt.Printf("Impossible")
                return
            } else {
                currentTop := q.Brackets[q.Size-1]
                if (s[i] == '}' && currentTop == '{') ||
                   (s[i] == '>' && currentTop == '<') ||
                   (s[i] == ')' && currentTop == '(') ||
                   (s[i] == ']' && currentTop == '[') {
                    q.Pop()
                } else {
                    answer += 1
                }
            }
        }
    }
    fmt.Printf("%d", answer)
}