Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.

The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.

If it is impossible to drink n cups of tea, print "NO" (without quotes). Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black. If there are multiple answers, print any of them.

package main

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

func main() {
	var n, k, a, b int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &k, &a, &b)

	ans := ""
	rowa, rowb := 0, 0
	for i := 0; i < n; i++ {
		if a > b {
			if rowa < k {
				ans += "G"
				rowb = 0
				rowa++
				a--
			} else {
				ans += "B"
				rowb++
				b--
				rowa = 0
			}
		} else {
			if rowb < k {
				ans += "B"
				rowa = 0
				rowb++
				b--
			} else {
				ans += "G"
				rowa++
				a--
				rowb = 0
			}
		}
		if rowa > k || rowb > k || a < 0 || b < 0 {
			fmt.Println("NO")
			goto halt
		}
	}
	fmt.Println(ans)
halt:
}


You are given two polynomials:  P(x) = a0·xn + a1·xn - 1 + ... + an - 1·x + an and  Q(x) = b0·xm + b1·xm - 1 + ... + bm - 1·x + bm.  Calculate limit .

The first line contains two space-separated integers n and m (0 ≤ n, m ≤ 100) — degrees of polynomials P(x) and Q(x) correspondingly. The second line contains n + 1 space-separated integers — the factors of polynomial P(x): a0, a1, ..., an - 1, an ( - 100 ≤ ai ≤ 100, a0 ≠ 0). The third line contains m + 1 space-separated integers — the factors of polynomial Q(x): b0, b1, ..., bm - 1, bm ( - 100 ≤ bi ≤ 100, b0 ≠ 0).

If the limit equals  + ∞, print "Infinity" (without quotes). If the limit equals  - ∞, print "-Infinity" (without the quotes). If the value of the limit equals zero, print "0/1" (without the quotes). Otherwise, print an irreducible fraction — the value of limit , in the format "p/q" (without the quotes), where p is the — numerator, q (q > 0) is the denominator of the fraction.

NoteLet's consider all samples:           You can learn more about the definition and properties of limits if you follow the link: http://en.wikipedia.org/wiki/Limit_of_a_function

package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, m := scanInt(scanner), scanInt(scanner)
	cn, cm := make([]int, n+1), make([]int, m+1)
	for i := 0; i <= n; i++ {
		cn[i] = scanInt(scanner)
	}
	for i := 0; i <= m; i++ {
		cm[i] = scanInt(scanner)
	}
	if (n > m) {
		if cn[0]*cm[0] < 0 {
			writer.WriteString("-")
		}
		writer.WriteString("Infinity")
	} else if (n < m) {
		writer.WriteString("0/1")
	} else {
		if cn[0]*cm[0] < 0 {
			writer.WriteString("-")
		}
		if (cn[0] < 0) {
			cn[0] *= -1
		}
		if (cm[0] < 0) {
			cm[0] *= -1
		}
		a, b := cn[0], cm[0]
		for b != 0 {
			a, b = b, a%b
		}
		cn[0] /= a
		cm[0] /= a
		writer.WriteString(fmt.Sprintf("%d/%d", cn[0], cm[0]))
	}
	writer.WriteString("\n")
}


You are given a prime number $$$p$$$, $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$, and an integer $$$k$$$. Find the number of pairs of indexes $$$(i, j)$$$ ($$$1 \le i < j \le n$$$) for which $$$(a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p$$$.

The first line contains integers $$$n, p, k$$$ ($$$2 \le n \le 3 \cdot 10^5$$$, $$$2 \le p \le 10^9$$$, $$$0 \le k \le p-1$$$). $$$p$$$ is guaranteed to be prime. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le p-1$$$). It is guaranteed that all elements are different.

Output a single integer — answer to the problem.

package main
import "fmt"
import "os"
import "bufio"
import "sort"

var input *bufio.Reader

func pow(x, p int64) int64{
    return (x*x%p)*(x*x%p)%p
}

type arrs []int64
func (arr arrs) Len() int {
    return len(arr)
}

func (arr arrs) Less(i, j int) bool {
    return arr[i] < arr[j]
}

func (arr arrs) Swap(i, j int) {
    arr[i], arr[j] = arr[j], arr[i]
}

func main(){
    input = bufio.NewReader(os.Stdin)
    var n int
    var p, k int64
    fmt.Fscanf(input, "%d%d%d\n", &n, &p, &k)
    arr := make(arrs, n)
    for i:=0; i<n; i++ {
        fmt.Fscanf(input, "%d", &arr[i])
        arr[i] = pow(arr[i], p) - k*arr[i]
        arr[i] %= p
        arr[i] += p
        arr[i] %= p
    }
    sort.Sort(arr)
    ans := int64(0)
    for i:=0; i<n; {
        j := i
        for ; j<n; j++ {
            if arr[j]!=arr[i] {
                break
            }
        }
        ans+=int64(j-i)*int64(j-i-1);
        i=j
    }
    fmt.Println(ans/2)
}

package main
import "fmt"
import "os"
import "bufio"
import "sort"

var input *bufio.Reader

func pow(x, p int64) int64{
    return x*x%p*x%p*x%p
}

type arrs []int64
func (arr arrs) Len() int {
    return len(arr)
}

func (arr arrs) Less(i, j int) bool {
    return arr[i] < arr[j]
}

func (arr arrs) Swap(i, j int) {
    arr[i], arr[j] = arr[j], arr[i]
}

func main(){
    input = bufio.NewReader(os.Stdin)
    var n int
    var p, k int64
    fmt.Fscanf(input, "%d%d%d\n", &n, &p, &k)
    arr := make(arrs, n)
    for i:=0; i<n; i++ {
        fmt.Fscanf(input, "%d", &arr[i])
        arr[i] = ((pow(arr[i], p)-k*arr[i])%p+p)%p;
    }
    sort.Sort(arr)
    ans := int64(0)
    for i:=0; i<n; i++ {
        j := i
        for ; j<n; j++ {
            if arr[j]!=arr[i] {
                break
            }
        }
        ans+=int64(j-i)*int64(j-i-1);
    }
    fmt.Println(ans/2)
}

package main
import "fmt"
import "os"
import "bufio"
import "sort"

var input *bufio.Reader

func pow(x, p int64) int64{
    return (x*x%p)*(x*x%p)%p
}

type arrs []int64
func (arr arrs) Len() int {
    return len(arr)
}

func (arr arrs) Less(i, j int) bool {
    return arr[i] < arr[j]
}

func (arr arrs) Swap(i, j int) {
    arr[i], arr[j] = arr[j], arr[i]
}

func main(){
    input = bufio.NewReader(os.Stdin)
    var n int
    var p, k int64
    fmt.Fscanf(input, "%d%d%d\n", &n, &p, &k)
    arr := make(arrs, n)
    for i:=0; i<n; i++ {
        fmt.Fscanf(input, "%d", &arr[i])
        arr[i] = pow(arr[i], p) - k*arr[i]
        arr[i] %= p
        arr[i] += p
        arr[i] %= p
    }
    sort.Sort(arr)
    ans := int64(0)
    for i:=0; i<n; i++ {
        j := i
        for ; j<n; j++ {
            if arr[j]!=arr[i] {
                break
            }
        }
        ans+=int64(j-i)*int64(j-i-1);
        i=j
    }
    fmt.Println(ans/2)
}


You have an array $$$a$$$ consisting of $$$n$$$ distinct positive integers, numbered from $$$1$$$ to $$$n$$$. Define $$$p_k$$$ as $$$$$$p_k = \sum_{1 \le i, j \le k} a_i \bmod a_j,$$$$$$ where $$$x \bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$. You have to find and print $$$p_1, p_2, \ldots, p_n$$$.

The first line contains $$$n$$$ — the length of the array ($$$2 \le n \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ space-separated distinct integers $$$a_1, \ldots, a_n$$$ ($$$1 \le a_i \le 3 \cdot 10^5$$$, $$$a_i \neq a_j$$$ if $$$i \neq j$$$).

Print $$$n$$$ integers $$$p_1, p_2, \ldots, p_n$$$.

package main
import "fmt"
import "bufio"
import "os"

var n int
var a[200005] int
var tree[300005] int
var tree2[300005] int

func update(x, y int){
  for x <= 300000 {
    tree[x] += y
    x += (x & -x)
  }
}

func get(x int) int{
  var res = 0
  for x >= 1 {
    res += tree[x]
    x -= (x & -x)
  }
  return res
}

func update2(x, y int){
  for x <= 300000 {
    tree2[x] += y
    x += (x & -x)
  }
}

func get2(x int) int{
  var res = 0
  for x >= 1 {
    res += tree2[x]
    x -= (x & -x)
  }
  return res
}

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

func solve(){
  var ans = 0
  var sum = 0
  for i := 1; i <= n; i++ {
    ans += a[i] * (i - 1) + sum - get2(a[i])
    sum += a[i]
    for j := a[i]; j <= 300000; j += a[i] {
      var num = get(min(300000, j + a[i] - 1)) - get(j - 1)
      ans -= num * j
      update2(j, a[i])
    }
    update(a[i], 1)
    fmt.Print(ans, " ")
  }
}

func main(){
  in := bufio.NewReader(os.Stdin)
  fmt.Fscan(in, &n);
  for i := 1; i <= n; i++ {
    fmt.Fscan(in, &a[i])
  }
  solve()
}

package main

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

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

func Read() int {
	in.Scan()
	r := 0
	for _, v := range in.Bytes() {
		r = r*10 + int(v-'0')
	}
	return r
}

func init() {
	const MaxInt = int(^uint(0) >> 1)
	in.Buffer(make([]byte, 1<<12), MaxInt)
	in.Split(bufio.ScanWords)
}

const N = 300300

var tr [3][N]int64

func add(tr []int64, p, x int) {
	for p < N {
		tr[p] += int64(x)
		p |= p + 1
	}
}

func get(tr []int64, p int) int64 {
	r := int64(0)
	for p >= 0 {
		r += int64(tr[p])
		p = p&(p+1) - 1
	}
	return r
}

func sum(tr []int64, l, r int) int64 {
	return get(tr, r) - get(tr, l-1)
}

func main() {
	defer out.Flush()
	n := Read()
	s := int64(0)
	for i := 0; i < n; i++ {
		x := Read()
		k := get(tr[0][:], x)
		s += (int64(i) - k) * int64(x)
		s += get(tr[1][:], x)
		s += k*int64(x) - get(tr[2][:], x)
		for j := x; j < N; j += x {
			r := j + x
			if r >= N {
				r = N - 1
			}
			s += sum(tr[1][:], j, r-1) - sum(tr[0][:], j, r-1)*int64(j)
			add(tr[2][:], j, j)
			add(tr[2][:], r, -j)
		}
		add(tr[0][:], x, 1)
		add(tr[1][:], x, x)
		Fprint(out, s, " ")
	}
	Fprintln(out)
}


There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.New parliament assembly hall is a rectangle consisting of a × b chairs — a rows of b chairs each. Two chairs are considered neighbouring if they share as side. For example, chair number 5 in row number 2 is neighbouring to chairs number 4 and 6 in this row and chairs with number 5 in rows 1 and 3. Thus, chairs have four neighbours in general, except for the chairs on the border of the hallWe know that if two parliamentarians from one political party (that is two Democrats or two Republicans) seat nearby they spent all time discussing internal party issues.Write the program that given the number of parliamentarians and the sizes of the hall determine if there is a way to find a seat for any parliamentarian, such that no two members of the same party share neighbouring seats.

The first line of the input contains three integers n, a and b (1 ≤ n ≤ 10 000, 1 ≤ a, b ≤ 100) — the number of parliamentarians, the number of rows in the assembly hall and the number of seats in each row, respectively.

If there is no way to assigns seats to parliamentarians in a proper way print -1. Otherwise print the solution in a lines, each containing b integers. The j-th integer of the i-th line should be equal to the index of parliamentarian occupying this seat, or 0 if this seat should remain empty. If there are multiple possible solution, you may print any of them.

NoteIn the first sample there are many other possible solutions. For example, 3 20 1and 2 13 0The following assignment 3 21 0is incorrect, because parliamentarians 1 and 3 are both from Democrats party but will occupy neighbouring seats.

package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scanf("%d%d%d", &n, &a, &b)
	if n > a*b {
		fmt.Printf("-1")
		return
	}
	num := 1
	for i := 1; i <= a; i++ {
		if i%2 == 1 {
			for j := 1; j <= b; j++ {
				if num > n {
					fmt.Printf("0 ")
				} else {
					fmt.Printf("%d ", num)
					num++
				}
			}
		} else {
			if num+b-1 <= n {
				num += b - 1
				for j := 1; j <= b; j++ {
					fmt.Printf("%d ", num+1-j)
				}
				num++
			} else {
				t := num + b - 1 - n
				for j := 0; j < t; j++ {
					fmt.Printf("0 ")
				}
				num = num + b - 1 - t
				for j := 0; j < b-t; j++ {
					fmt.Printf("%d ", num-j)
				}
				num++
			}
		}
		fmt.Println()
	}
}

package main

import "fmt"

func main() {
    var n, a, b int
    fmt.Scanf("%d %d %d\n", &n, &a, &b)
    //fmt.Printf("input: n=%d a=%d b=%d\n", n, a, b)
    if n > a*b {
        fmt.Printf("-1")
        return
    }
    var q []int = make([]int, a*b)
    current := 1
    for i := 0; i < a; i += 2 {
        for j := 0; j < b; j++ {
            q[b*i+j] = current
            current += 1
        }
        if i+1 < a {
            for j := b-1; j >= 0; j-- {
                q[b*(i+1)+j] = current
                current += 1
            }
        }
    }
    if current < n {
        fmt.Printf("-1")
        return
    }
    for i := 0; i < a; i++ {
        for j := 0; j < b; j++ {
            if q[b*i+j] <= n {
                fmt.Printf("%d ", q[b*i+j])
            } else {
                fmt.Printf("0 ")
            }
        }
        fmt.Println()
    }
}

package main

import "fmt"

func main() {
    var n, a, b int
    fmt.Scanf("%d %d %d\n", &n, &a, &b)
    //fmt.Printf("input: n=%d a=%d b=%d\n", n, a, b)
    if n > a*b {
        fmt.Printf("-1")
        return
    }
    var q []int = make([]int, a*b)
    current := 1
    for i := 0; i < a; i += 2 {
        for j := 0; j < b; j++ {
            q[b*i+j] = current
            current += 1
        }
        if i+1 < a {
            for j := b-1; j >= 0; j-- {
                q[b*(i+1)+j] = current
                current += 1
            }
        }
    }

    for i := 0; i < a; i++ {
        for j := 0; j < b; j++ {
            if q[b*i+j] <= n {
                fmt.Printf("%d ", q[b*i+j])
            } else {
                fmt.Printf("0 ")
            }
        }
        fmt.Println()
    }
}

package main

import (
	"fmt"
)

func main() {
	defer func() {
		r := recover()
		if r != nil {
			fmt.Println(-1)
		}
	}()

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

package main
import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	place := make([][]int, a)
	for i := range place{
		place[i] = make([]int, b)
	}
	maxeven := (n/2)*2

	if a*b < n {
		fmt.Printf("%d",-1)
	}else{
		count := 1
		for i := 0; (i < a)&&(count <= n); i+=2{
			for j := 0; (j < b)&&(count <= n); j+=2 {
				place[i][j] = count
				count += 2
			}
		}
		for i := 1; (i < b)&&(count <= n); i+=2{
			for j := 1; (j < a)&&(count <= n); j+=2 {
				place[j][i] = count
				count += 2
			}
		}
		count = 2
		for i := 0; (i < a)&&(count <= maxeven); i+=2{
			for j := 1; (j < b)&&(count <= maxeven); j+=2 {
				place[i][j] = count
				count += 2
			}
		}
		for i := 0; (i < b)&&(count <= maxeven); i+=2{
			for j := 1; (j < a)&&(count <= maxeven); j+=2 {
				place[j][i] = count
				count += 2
			}
		}
		for _ ,r:= range place{
			for _, m := range r{
				fmt.Printf("%d ", m)
			}
			fmt.Printf("\n")
		}
	}
}

package main

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

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

func ReadString(scanner *bufio.Scanner) string {
  scanner.Scan()
  ans := scanner.Text()
  return ans
}

func PrintInt(writer *bufio.Writer, value int) {
  writer.WriteString(strconv.Itoa(value))
  writer.WriteByte(' ')
}

func PrintInts(writer *bufio.Writer, ints ...int) {
  for _, value := range ints {
    writer.WriteString(strconv.Itoa(value))
    writer.WriteByte(' ')
  }
  writer.WriteByte('\n')
}

func main() {
  // fi, err := os.Open("./input.txt")
  // if err != nil {
  //   fmt.Println("Can open file.")
  //   return
  // }

  // defer fi.Close()
  var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
  var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()
  scanner.Split(bufio.ScanWords)

  var n, a, b int = ReadInt32(scanner), ReadInt32(scanner), ReadInt32(scanner)
  if a * b < n {
    PrintInts(writer, -1)
    return
  }

  for i := 0; i < a; i++ {
    md := i % 2
    k := n - i * b - md * (b-1)
    for j := 0; j < b; j++ {
      if k < 0 {
        PrintInt(writer, 0)
      } else {
        PrintInt(writer, k)
      }
      if md == 0 {
        k--
      } else {
        k++
      }
    }
    writer.WriteByte('\n')
  }
  // writer.WriteByte('\n')
}

package main

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

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)

	var n, a, b int = readInt(), readInt(), readInt()
	f := func(x int) int {
		return x/2 + x%2
	}
	pplh, plch := f(n), f(a*b)
	if pplh > plch {
		printInts(-1)
		println()
	} else if b%2 == 1 {
		for i, k := 0, 1; i < a; i++ {
			for j := 0; j < b; j++ {
				if k <= n {
					printInts(k)
					k++
				} else {
					printInts(0)
				}
			}
			println()
		}
	} else {
		is := true
		var m, off int
		for i, k := 0, 1; i < a; i++ {
			if is {
				m, off = i*b+1, 1
			} else {
				m, off = (i+1)*b, -1
			}
			for j := 0; j < b; j++ {
				if k > n || m > n {
					printInts(0)
					m--
				} else {
					printInts(m)
					m += off
					k++
				}
			}
			is = !is
			println()
		}
	}
}

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

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

func readInt64() int64 {
	sc.Scan()
	ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return ans
}

func printInts(ints ...int) {
	for _, v := range ints {
		wr.WriteString(strconv.Itoa(v))
		wr.WriteByte(' ')
	}
}
func printInt64s(ints ...int64) {
	for _, v := range ints {
		wr.WriteString(strconv.FormatInt(v, 10))
		wr.WriteByte(' ')
	}
}

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

func println() {
	wr.WriteByte('\n')
}

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 n, a, b int

func solve() {
	if a*b < n {
		Println(-1)
	} else {
		cur := 1
		for i := 0; i < a; i++ {
			for j := 0; j < b; j++ {
				if j > 0 {
					Print(" ")
				}
				if cur <= n {
					Print(cur)
				} else {
					Print(0)
				}
				if b&1 == 0 && i&1 == 1 {
					cur--
				} else {
					cur++
				}
			}
			if b&1 == 0 {
				cur += b
				if i&1 == 1 {
					cur++
				} else {
					cur--
				}
			}
			Println()
		}
	}
	return
}

func main() {
	defer out.Flush()
	for Scan(&n, &a, &b) != io.EOF {
		solve()
	}
	return
}

package main

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

func main() {
	get := wrapStdin()
	n, a, b := get.Int(), get.Int(), get.Int()

	if a*b < n {
		fmt.Println(-1)
		return
	}

	g := func(b int) func() int {
		return func() int {
			t := b
			b += 2
			if t > n {
				t = 0
			}
			return t
		}
	}
	ev, od := g(2), g(1)

	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			var x int
			if (i^j)&1 == 0 {
				x = od()
			} else {
				x = ev()
			}
			fmt.Printf("%d ", x)
		}
		fmt.Printf("\n")
	}
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}

package main

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

func main() {
	get := wrapStdin()
	n, a, b := get.Int(), get.Int(), get.Int()

	if a*b < n {
		fmt.Println(-1)
		fmt.Fprintln(os.Stderr, runtime.GOMAXPROCS(0))
		return
	}

	g := func(b int) func() int {
		return func() int {
			t := b
			b += 2
			if t > n {
				t = 0
			}
			return t
		}
	}
	ev, od := g(2), g(1)

	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			var x int
			if (i^j)&1 == 0 {
				x = od()
			} else {
				x = ev()
			}
			fmt.Printf("%d ", x)
		}
		fmt.Printf("\n")
	}
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}

package main

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

var (
	n, a, b int
	field   [][]int
)

func main() {
	defer out.Flush()
	fmt.Fscan(in, &n, &a, &b)
	for first := 0; first <= 1; first++ {
		field = make([][]int, a)
		for i := range field {
			field[i] = make([]int, b)
		}
		switch first {
		case 0:
			put(2)
			put(1)
		case 1:
			put(1)
			put(2)
		}
		if check() {
			for i := range field {
				for j := range field[i] {
					if j != 0 {
						fmt.Fprint(out, " ")
					}
					fmt.Fprint(out, field[i][j])
				}
				fmt.Fprintln(out)
			}
			return
		}
	}
	fmt.Fprintln(out, -1)
}

func eq(a, b int) bool {
	if a == 0 || b == 0 {
		return false
	}
	return a%2 == b%2
}

func canPut(i, j, x int) bool {
	if field[i][j] != 0 {
		return false
	}
	if i-1 >= 0 && eq(field[i-1][j], x) {
		return false
	}
	if j-1 >= 0 && eq(field[i][j-1], x) {
		return false
	}
	if i+1 < a && eq(field[i+1][j], x) {
		return false
	}
	if j+1 < b && eq(field[i][j+1], x) {
		return false
	}
	return true
}

func put(first int) {
	next := first
	for i := 0; i < a && next <= n; i++ {
		for j := 0; j < b && next <= n; j++ {
			if canPut(i, j, next) {
				field[i][j] = next
				next += 2
			}
		}
	}
}

func check() bool {
	seen := make([]bool, n)
	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			if field[i][j] != 0 {
				seen[field[i][j]-1] = true
			}
		}
	}
	for i := range seen {
		if !seen[i] {
			return false
		}
	}
	return true
}

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

package main

import "fmt"

func main() {
    var n, a, b int
    fmt.Scanf("%d %d %d\n", &n, &a, &b)
    //fmt.Printf("input: n=%d a=%d b=%d\n", n, a, b)
    if n > a*b {
        fmt.Printf("-1")
        return
    }
    for i := 0; i < a; i++ {
        for j := 0; j < b; j++ {
            if b*i+j < n {
                fmt.Printf("%d ", b*i + j + 1)
            } else {
                fmt.Printf("0 ")
            }
        }
        fmt.Println()
    }

}

package main

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

func main() {
	get := wrapStdin()
	n, a, b := get.Int(), get.Int(), get.Int()

	if a*b < n {
		fmt.Println(-runtime.GOMAXPROCS(0))
		return
	}

	g := func(b int) func() int {
		return func() int {
			t := b
			b += 2
			if t > n {
				t = 0
			}
			return t
		}
	}
	ev, od := g(2), g(1)

	for i := 0; i < a; i++ {
		for j := 0; j < b; j++ {
			var x int
			if (i^j)&1 == 0 {
				x = od()
			} else {
				x = ev()
			}
			fmt.Printf("%d ", x)
		}
		fmt.Printf("\n")
	}
}

type Input struct {
	*bufio.Scanner
}

func wrapStdin() Input {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return Input{Scanner: sc}
}
func (in Input) Int() int {
	in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x
}
func (in Input) IntOk() (int, bool) {
	ok := in.Scan()
	x, _ := strconv.Atoi(in.Text())
	return x, ok
}


Reminder: the median of the array $$$[a_1, a_2, \dots, a_{2k+1}]$$$ of odd number of elements is defined as follows: let $$$[b_1, b_2, \dots, b_{2k+1}]$$$ be the elements of the array in the sorted order. Then median of this array is equal to $$$b_{k+1}$$$.There are $$$2n$$$ students, the $$$i$$$-th student has skill level $$$a_i$$$. It's not guaranteed that all skill levels are distinct.Let's define skill level of a class as the median of skill levels of students of the class.As a principal of the school, you would like to assign each student to one of the $$$2$$$ classes such that each class has odd number of students (not divisible by $$$2$$$). The number of students in the classes may be equal or different, by your choice. Every student has to be assigned to exactly one class. Among such partitions, you want to choose one in which the absolute difference between skill levels of the classes is minimized.What is the minimum possible absolute difference you can achieve?

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of students halved. The second line of each test case contains $$$2n$$$ integers $$$a_1, a_2, \dots, a_{2 n}$$$ ($$$1 \le a_i \le 10^9$$$) — skill levels of students. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, output a single integer, the minimum possible absolute difference between skill levels of two classes of odd sizes.

NoteIn the first test, there is only one way to partition students — one in each class. The absolute difference of the skill levels will be $$$|1 - 1| = 0$$$.In the second test, one of the possible partitions is to make the first class of students with skill levels $$$[6, 4, 2]$$$, so that the skill level of the first class will be $$$4$$$, and second with $$$[5, 1, 3]$$$, so that the skill level of the second class will be $$$3$$$. Absolute difference will be $$$|4 - 3| = 1$$$.Note that you can't assign like $$$[2, 3]$$$, $$$[6, 5, 4, 1]$$$ or $$$[]$$$, $$$[6, 5, 4, 1, 2, 3]$$$ because classes have even number of students.$$$[2]$$$, $$$[1, 3, 4]$$$ is also not possible because students with skills $$$5$$$ and $$$6$$$ aren't assigned to a class.In the third test you can assign the students in the following way: $$$[3, 4, 13, 13, 20], [2, 5, 8, 16, 17]$$$ or $$$[3, 8, 17], [2, 4, 5, 13, 13, 16, 20]$$$. Both divisions give minimal possible absolute difference.

package main

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

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

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	in := scanInt()
	for t := 0; t < in; t++ {
		n := scanInt()
		a := scanInts(n*2)

		sort.Ints(a)

		fmt.Println(a[n]-a[n-1])

	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    capacity := 5000 * 1024
    scanner.Buffer(make([]byte, capacity), capacity)
    scanner.Scan()
    line := scanner.Text()
    t, _ := strconv.Atoi(line)
    for i := 0; i < t; i++ {
        scanner.Scan()
        line = scanner.Text()
        parts := strings.Split(line, " ")
        n, _ := strconv.Atoi(parts[0])

        scanner.Scan()
        line = scanner.Text()
        //~ fmt.Println(scanner.Text())
        parts = strings.Split(line, " ")
        a := make([]int, 2 * n)
        //~ fmt.Println(line)
        //~ fmt.Println(parts)
        for j := 0; j < 2 * n; j++ {
            //~ fmt.Println(j, len(a), len(parts))
            a[j], _ = strconv.Atoi(parts[j]);
        }
        sort.Ints(a);
        //~ fmt.Println(a);
        v1, v2 := a[n - 1], a[n]
        var abs_diff int
        if v1 < v2 {
            abs_diff = v2 - v1
        } else {
            abs_diff = v1 - v2
        }
        fmt.Println(abs_diff)
    }
}

package main

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

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

func scanf(p string, vars ...interface{}) {
	fmt.Fscanf(reader, p, vars...)
}

func printf(p string, vars ...interface{}) {
	fmt.Fprintf(writer, p, vars...)
}

func main() {
	defer writer.Flush()

	var ts int
	scanf("%d\n", &ts)

	for t := 0; t < ts; t++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		sort.Ints(a)

		printf("%d\n", a[n]-a[n-1])
	}
}

package main

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

func main() {
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Buffer(make([]byte, 10000), 1000000)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	r.Scan()
	t, _ := strconv.Atoi(r.Text())
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		r.Scan()
		n, _ := strconv.Atoi(r.Text())
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			r.Scan()
			a[j], _ = strconv.Atoi(r.Text())
		}
		sort.Ints(a)
		ans[i] = fmt.Sprint(a[n] - a[n-1])

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(r, &a[j])
		}
		sort.Ints(a)
		ans[i] = fmt.Sprint(a[n] - a[n-1])

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

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

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

func abs(a int) int { if a<0 { return -a }; return a }
func min(a,b int) int { if a<b { return a }; return b }
func max(a,b int) int { if a>b { return a }; return b }

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	in := scanInt()
	for t := 0; t < in; t++ {
		n := scanInt()
		a := scanInts(n*2)

		sort.Ints(a)

		fmt.Println(a[n]-a[n-1])
		fmt.Println(a)

	}
}

package main

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

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

func scanf(p string, vars ...interface{}) {
	fmt.Fscanf(reader, p, vars...)
}

func printf(p string, vars ...interface{}) {
	fmt.Fprintf(writer, p, vars...)
}

func main() {
	defer writer.Flush()

	var ts int
	scanf("%d\n", &ts)

	for t := 0; t < ts; t++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		sort.Ints(a)

		if n%2 == 0 {
			printf("%d\n", a[n-1]-a[n-2])
		} else {
			printf("%d\n", a[n]-a[n-1])
		}
	}
}

package main

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

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

func scanf(p string, vars ...interface{}) {
	fmt.Fscanf(reader, p, vars...)
}

func printf(p string, vars ...interface{}) {
	fmt.Fprintf(writer, p, vars...)
}

func main() {
	defer writer.Flush()

	var ts int
	scanf("%d\n", &ts)

	for t := 0; t < ts; t++ {
		var n int
		scanf("%d\n", &n)

		a := make([]int, 2*n)
		for i := 0; i < 2*n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		sort.Ints(a)

		if n%2 == 0 {
			printf("%d\n", a[n]-a[n-2])
		} else {
			printf("%d\n", a[n]-a[n-1])
		}
	}
}

package main

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

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

func scanf(p string, vars ...interface{}) {
	fmt.Fscanf(reader, p, vars...)
}

func printf(p string, vars ...interface{}) {
	fmt.Fprintf(writer, p, vars...)
}

func main() {
	defer writer.Flush()

	var tests int
	scanf("%d\n", &tests)

	for t := 0; t < tests; t++ {
		var n int
		scanf("%d\n", &n)

		sum := 0
		count := 0
		for i := 0; i < n; i++ {
			var a int
			scanf("%d", &a)
			if a == 0 {
				a++
				count++
			}
			sum += a
		}

		if sum == 0 {
			count++
		}

		scanf("\n")

		printf("%d\n", count)
	}
}

package main

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

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

	t, _ := strconv.Atoi(r.Text())
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		n, _ := strconv.Atoi(r.Text())
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			a[j], _ = strconv.Atoi(r.Text())
		}
		sort.Ints(a)
		ans[i] = fmt.Sprint(a[n] - a[n-1])

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(r, &a[j])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		var x, y int
		var b, c int
		for _, e := range a {
			if x > y {
				y += e
				c++
			} else {
				x += e
				b++
			}
		}
		if b%2 != 0 {
			ans[i] = fmt.Sprint(int(math.Abs(float64(x - y))))
		} else {
			ans[i] = fmt.Sprint(int(math.Abs(float64(x-y))) + 2*a[len(a)-1])
		}

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(r, &n)
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			fmt.Fscan(r, &a[j])
		}
		sort.Sort(sort.Reverse(sort.IntSlice(a)))
		var x, y int
		var b, c int
		for _, e := range a {
			if x > y {
				y += e
				c++
			} else {
				x += e
				b++
			}
		}
		abs := int(math.Abs(float64(x - y)))
		if b%2 != 0 {
			ans[i] = fmt.Sprint(abs)
		}
		// else {
		//	ans[i] = fmt.Sprint(abs + 2*a[len(a)-1])
		//}

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}

package main

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

func main() {
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Buffer(make([]byte, 10000), 1000000)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	t, _ := strconv.Atoi(r.Text())
	ans := make([]string, t)
	for i := 0; i < t; i++ {
		n, _ := strconv.Atoi(r.Text())
		a := make([]int, 2*n)
		for j := 0; j < 2*n; j++ {
			a[j], _ = strconv.Atoi(r.Text())
		}
		sort.Ints(a)
		ans[i] = fmt.Sprint(a[n] - a[n-1])

	}
	fmt.Fprintln(w, strings.Join(ans, "\n"))
}


Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every feature — color, number, shape, and shading — the three cards must display that feature as either all the same, or pairwise different. The picture below shows how sets look.Polina came up with a new game called "Hyperset". In her game, there are $$$n$$$ cards with $$$k$$$ features, each feature has three possible values: "S", "E", or "T". The original "Set" game can be viewed as "Hyperset" with $$$k = 4$$$.Similarly to the original game, three cards form a set, if all features are the same for all cards or are pairwise different. The goal of the game is to compute the number of ways to choose three cards that form a set.Unfortunately, winter holidays have come to an end, and it's time for Polina to go to school. Help Polina find the number of sets among the cards lying on the table.

The first line of each test contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 1500$$$, $$$1 \le k \le 30$$$) — number of cards and number of features. Each of the following $$$n$$$ lines contains a card description: a string consisting of $$$k$$$ letters "S", "E", "T". The $$$i$$$-th character of this string decribes the $$$i$$$-th feature of that card. All cards are distinct.

Output a single integer — the number of ways to choose three cards that form a set.

NoteIn the third example test, these two triples of cards are sets:  "SETT", "TEST", "EEET"  "TEST", "ESTE", "STES"

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		a := make([]string, n)
		for i := 0; i < n; i++ {
			s := ""
			fmt.Fscanf(in, "%s\n", &s)
			a[i] = s
		}
		sort.Strings(a)
		//fmt.Println(a)
		posFrom := make(map[string]int)
		posTo := make(map[string]int)
		posFrom[a[0]] = 0
		for i := 1; i < n; i++ {
			if a[i] != a[i-1] {
				posFrom[a[i]] = i
			}
			posTo[a[i]] = i
		}
		//fmt.Println(posFrom, posTo)
		ans := 0
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				desiredBytes := []byte{}
				for k := 0; k < m; k++ {
					//fmt.Println(i, j, k)
					if a[i][k] == a[j][k] {
						desiredBytes = append(desiredBytes, a[i][k])
					} else {
						if 'S' != a[i][k] && 'S' != a[j][k] {
							desiredBytes = append(desiredBytes, 'S')
						} else if 'E' != a[i][k] && 'E' != a[j][k] {
							desiredBytes = append(desiredBytes, 'E')
						} else {
							desiredBytes = append(desiredBytes, 'T')
						}
					}
				}
				s := string(desiredBytes)
				//fmt.Println(s, posFrom[s], posTo[s])
				if from, ok := posFrom[s]; ok {
					to := posTo[s]
					if from <= j {
						from = j + 1
					}
					if to >= from {
						ans += to - from + 1
					}
				}
			}
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

func same(s string, ss string) bool {
	a := make([]int, 26)
	for i := 0; i < len(s); i++ {
		b := int(s[i] - 'a')
		a[b]++
	}
	for i := 0; i < len(ss); i++ {
		b := int(ss[i] - 'a')
		a[b]--
		if a[b] == -1 {
			return false
		}
	}
	for i := 0; i < 26; i++ {
		if a[i] != 0 {
			return false
		}
	}
	return true
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

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

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcdll(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcdll(b, a%b)
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	K := readi()

	card := make([]string, n)
	s := make(map[string]int)
	for i := range card {
		card[i] = reads()
		s[card[i]] = 1
	}

	var ans int
	m := map[byte]int{'S': 0, 'E': 1, 'T': 2}
	rm := []byte{'S', 'E', 'T'}
	for i := range card {
		for j := i + 1; j < n; j++ {
			if i == j {
				continue
			}
			var t []byte
			for k := 0; k < K; k++ {
				var v byte
				if card[i][k] == card[j][k] {
					v = card[i][k]
				} else {
					v = rm[3-m[card[i][k]]-m[card[j][k]]]
				}
				t = append(t, v)
			}
			ans += s[string(t)]
		}
	}
	println(ans / 3)

}

package main

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

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

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

const options = "SET"

func main() {
  defer writer.Flush()
  var n, k int
  scanf("%d %d\n", &n, &k)
  card := make([]string, n)
  for i := range card {
    scanf("%s\n", &card[i])
  }
  solve(card)
}

func solve(card []string) {
  res := 0
  all := map[string]bool{}
  for _, c := range card {
    all[c] = true
  }
  for i := range card {
    for j := i + 1; j < len(card); j ++ {
      ci, cj := card[i], card[j]
      new := ""
      for k := range ci {
        if ci[k] == cj[k] {
          new += string(ci[k])
        } else {
          for x := range options {
            if ci[k] != options[x] && cj[k] != options[x] {
                new += string(options[x])
                break
            }
          }
        }
      }
      if all[new] {
        res ++
      }
    }
  }
  printf("%d", res / 3)
}

package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	var a []string
	var mp map[string]bool = make(map[string]bool)
	var s string
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		a = append(a, s)
		mp[s] = true
	}
	var card []byte = make([]byte, k)
	var ans int = 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			for q := 0; q < k; q++ {
				if a[i][q] == a[j][q] {
					card[q] = a[i][q]
				} else if a[i][q] == 'S' {
					card[q] = byte(int('E') + int('T') - int(a[j][q]))
				} else if a[i][q] == 'E' {
					card[q] = byte(int('S') + int('T') - int(a[j][q]))
				} else if a[i][q] == 'T' {
					card[q] = byte(int('S') + int('E') - int(a[j][q]))
				}
			}
			if _, ok := mp[string(card)]; ok {
				ans++
			}
		}
	}
	fmt.Print(ans / 3)
}

package main

import "fmt"

type Q struct{}

func main() {
	var n, k int
	var card string
	replacement := map[string]byte{"SE": 'T', "ES": 'T', "ET": 'S', "TE": 'S', "ST": 'E', "TS": 'E'}
	fmt.Scanf("%d %d\n", &n, &k)

	cardsMap := make(map[string]struct{})
	keys := make([]string, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%s\n", &card)
		cardsMap[card] = Q{}
		keys[i] = card
	}

	count := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			cardNeeded := make([]byte, k, k)
			for l := 0; l < k; l++ {
				if keys[i][l] == keys[j][l] {
					cardNeeded[l] = keys[i][l]
				} else {
					cardNeeded[l] = replacement[string(keys[i][l])+string(keys[j][l])]
				}
			}
			if _, present := cardsMap[string(cardNeeded)]; present {
				count++
			}
		}
	}
	fmt.Printf("%d\n", count/3)
}

// ref: https://codeforces.com/contest/1287/submission/68254686 by
// https://codeforces.com/profile/shirakami.rin

package main

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

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

	count := make(map[string]int)
	var numCards, numFeatures, ans int
	fmt.Fscanf(reader, "%d %d\n", &numCards, &numFeatures)
	cards := make([]string, numCards)
	for i := 1; i <= numCards; i++ {
		fmt.Fscanf(reader, "%s\n", &cards[i-1])
	}
	for i := 0; i < numCards; i++ {
		for j := i + 1; j < numCards; j++ {
			card := ""
			for feature := 0; feature < numFeatures; feature++ {
				if cards[i][feature] == cards[j][feature] {
					card += string(cards[i][feature])
				} else {
					if (cards[i][feature] != 'S') && (cards[j][feature] != 'S') {
						card += "S"
					} else if (cards[i][feature] != 'E') && (cards[j][feature] != 'E') {
						card += "E"
					} else if (cards[i][feature] != 'T') && (cards[j][feature] != 'T') {
						card += "T"
					}
				}
			}
			if val, ok := count[card]; ok {
				//fmt.Fprintln(writer, card, val, ans)
				ans += val
			}
			//fmt.Fprintln(writer, "i :", i, "j: ", j, card)
			//fmt.Fprintln(writer)
		}
		count[cards[i]] += 1
	}
	fmt.Fprintln(writer, ans)
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

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

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

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

func gcdll(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcdll(b, a%b)
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	K := readi()

	card := make([][]int, n)
	s := make(map[string]bool)
	for i := range card {
		c := readb()
		s[string(c)] = true
		for j := range c {
			var r int
			switch c[j] {
			case 'S':
				r = 0
			case 'E':
				r = 1
			case 'T':
				r = 2
			}
			card[i] = append(card[i], r)
		}
	}

	m := make([][3]map[int]bool, K)
	for i := range m {
		for j := range m[i] {
			m[i][j] = make(map[int]bool)
		}
	}
	for i := range card {
		for j, v := range card[i] {
			m[j][v][i] = true
		}
	}

	var ans1, ans2 int
	tag := []byte{'S', 'E', 'T'}
	for i := range card {
		for j := range card {
			if i == j {
				continue
			}
			//eprintln(card[i])
			//eprintln(card[j])
			differ := true
			var cnt int
			for k := 0; k < K; k++ {
				if card[i][k] == card[j][k] {
					differ = false
					v := card[i][k]
					cnt = max(cnt, len(m[k][v]))
					//eprintln(k, len(m[k][v]))
				}
			}
			//eprintln(cnt, max(0, cnt-2))
			ans1 += max(0, cnt-2)
			if differ {
				var t []byte
				for k := 0; k < K; k++ {
					t = append(t, tag[3-card[i][k]-card[j][k]])
				}
				if s[string(t)] {
					//eprintln("found", string(t))
					ans2++
				}
			}
		}
	}
	//eprintln(ans1/6, ans2/6)
	println(ans1/6 + ans2/6)

}