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 (
	"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"

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)

}


package main

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

func main() {
	var n, tmp, fcolsum, xcolsum int64
	var zi, zj int64

	in := bufio.NewReaderSize(os.Stdin, 1024*1024)
	fmt.Fscan(in, &n)

	if n == 1 {
		fmt.Println(1)
		return
	}

	mass := make([][]int64, n)
	for i := int64(0); i < n; i++ {
		mass[i] = make([]int64, n)

		sum := int64(0)
		zero := false

		for j := int64(0); j < n; j++ {
			fmt.Fscan(in, &tmp)
			mass[i][j] = tmp

			if !zero {
				zero = (tmp == 0)

				if zero {
					zi, zj = i, j
				}
			}

			sum = sum + tmp
		}

		if zero {
			xcolsum = sum
		} else {
			if fcolsum == 0 {
				fcolsum = sum
			} else {
				if fcolsum != sum {
					fmt.Println(-1)
					return
				}
			}
		}
	}

	mass[zi][zj] = fcolsum - xcolsum
	if mass[zi][zj] <= 0 {
		fmt.Println(-1)
		return
	}

	// rows
	for i := int64(0); i < n; i++ {
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			sum = sum + mass[j][i]
		}

		if fcolsum != sum {
			fmt.Println(-1)
			return
		}
	}

	// diag 1 & diag 2
	sum := int64(0)
	sum2 := int64(0)
	for i := int64(0); i < n; i++ {
		sum = sum + mass[i][i]
		sum2 = sum2 + mass[i][n - i - 1]
	}

	if fcolsum != sum || fcolsum != sum2 {
		fmt.Println(-1)
		return
	}

	fmt.Println(mass[zi][zj])
}

package main

import "fmt"
import "bufio"
import "os"

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

	var n int
	fmt.Fscanf(buf, "%d\n", &n)

	a := make([][]int64, n)
	var iz, jz int

	for i := 0; i < n; i++ {
		a[i] = make([]int64, n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(buf, "%d\n", &a[i][j])
			if a[i][j] == 0 {
				iz = i
				jz = j
			}
		}
	}

	sum := int64(0)

	if n == 1 {
		a[iz][jz] = 1
		sum = 1
	} else {
		k := 0
		for k == iz {
			k++
		}
		sumz := int64(0)
		for j := 0; j < n; j++ {
			sum += a[k][j]
			sumz += a[iz][j]
		}
		a[iz][jz] = sum - sumz
	}

	found := (a[iz][jz] >= 1)

	sd1 := int64(0)
	sd2 := int64(0)

	for i := 0; i < n; i++ {
		srow := int64(0)
		scol := int64(0)
		for j := 0; j < n; j++ {
			srow += a[i][j]
			scol += a[j][i]
		}
		if (srow != sum) || (scol != sum) {
			found = false
			break
		}
		sd1 += a[i][i]
		sd2 += a[i][n-1-i]
	}

	if (sd1 != sum) || (sd2 != sum) {
		found = false
	}

	if found {
		fmt.Println(a[iz][jz])
	} else {
		fmt.Println(-1)
	}
}

package main

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

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

	if n == 1 {
		var trash int
		if _, err := fmt.Scanf("%d\n", &trash); err != nil {
			return
		}
		fmt.Println(1)
		return
	}

	array := make([][]int64, n+1)
	array[n] = make([]int64, n+1)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	e := [2]int{-1, -1}
	diagonal := [2]int64{0, 0}
	target := int64(-1)
	met_zero := false

	for i := 0; i < n; i++ {
		array[i] = make([]int64, n+1)
		r_sum := int64(0)
		for j := 0; j < n && scanner.Scan(); j++ {
			in, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			a := int64(in)
			array[i][j] = a
			r_sum += a
			array[n][j] += a

			if i == j {
				diagonal[0] += a
			}
			if i+j == n-1 {
				diagonal[1] += a
			}
			if a == 0 {
				e[0] = i
				e[1] = j
				met_zero = true
			}
		}
		array[i][n] = r_sum
		if target < 0 && !met_zero {
			target = r_sum
		}
		if met_zero {
			met_zero = false
		}
	}

	magic := target - array[n][e[1]]
	if target != array[e[0]][n]+magic {
		fmt.Println(-1)
		return
	}

	if e[0] != e[1] {
		if diagonal[0] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[0]+magic != target {
		fmt.Println(-1)
		return
	}
	if e[0]+e[1] != n-1 {
		if diagonal[1] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[1]+magic != target {
		fmt.Println(-1)
		return
	}

	check_ok := true
	for i := 0; i < n; i++ {
		if i != e[0] {
			if array[i][n] != target {
				check_ok = false
				break
			}
		}
		if i != e[1] {
			if array[n][i] != target {
				check_ok = false
				break
			}
		}
	}

	if !check_ok || magic <= 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(magic)
	}
}

// Codeforces 711 B
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

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

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

var n,ii,jj int
var sm,val,sum,altSum int64
var aa [][]int
var ok bool

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading n
    n,_,_,_,_ = readFive()
    aa = make([][]int, n)
    for i:=0; i<n; i++ {
        aa[i] = make([]int, n)
        aaa := readLineNumbs(n)
        for j:=0; j<n; j++ {
            aa[i][j] = aaa[j]
            if aa[i][j]==0 {
                ii = i
                jj = j
            }
        }
    }
}

func checkSum(sm int64, alt bool) {
    if !ok {
        return
    }
    if alt {
        if altSum==-1 {
            altSum = sm
        } else {
            if altSum != sm {
                ok = false
            }
        }
    } else {
        if sum==-1 {
            sum = sm
        } else {
            if sum != sm {
                ok = false
            }
        }
    }
}

func solve() {
    sum = -1
    altSum = -1
    ok = true
    // rows
    for i:=0; i<n; i++ {
        sm = 0
        for j:=0; j<n; j++ {
            sm += int64(aa[i][j])
        }
        alt := (i==ii)
        checkSum(sm, alt)
    }
    // columns
    for j:=0; j<n; j++ {
        sm = 0
        for i:=0; i<n; i++ {
            sm += int64(aa[i][j])
        }
        alt := (j==jj)
        checkSum(sm, alt)
    }
    // main diagonal
    sm = 0
    for i:=0; i<n; i++ {
        sm += int64(aa[i][i])
    }
    alt := (ii==jj)
    checkSum(sm, alt)
    // other diagonal
    sm = 0
    for i:=0; i<n; i++ {
        sm += int64(aa[i][n-i-1])
    }
    alt = (ii==(n-jj-1))
    checkSum(sm, alt)
}

func printRes() {
    if n==1 {
        val = 1
    } else if ok && (sum > altSum) {
        val = sum - altSum
    } else {
        val = -1
    }
    fmt.Println(val)
}

func main() {
 	readData()

    solve()
    printRes()
}

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	if N == 1 {
		fmt.Println(1)
		return
	}

	A := make([][]int64, N)
	sm := make([]int64, 2 * N + 2)
	zCheck := make([]bool, 2 * N + 2)
	for i := 0; i < N; i++ {
		A[i] = in.NextInt64Array()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zCheck[i] = true
			}
			sm[i] += A[i][j]
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if A[j][i] == 0 {
				zCheck[i + N] = true
			}
			sm[i + N] += A[j][i]
		}
	}

	for i := 0; i < N; i++ {
		if A[i][i] == 0 {
			zCheck[2 * N ] = true
		}
		sm[2 * N] += A[i][i]
	}

	for i := 0; i < N; i++ {
		if A[i][N - i - 1] == 0 {
			zCheck[2 * N + 1 ] = true
		}

		sm[2 * N + 1] += A[i][N - i - 1]
	}

	mp := map[int64]struct{}{}
	for i := 0; i < len(sm); i++ {
		mp[sm[i]] = struct{}{}
	}

	if len(mp) != 2 {
		fmt.Println(-1)
		return
	}

	amn := int64(-1)
	amx := int64(0)
	for i := 0; i < len(sm); i++ {
		if !zCheck[i] {
			if amn == -1 || amn > sm[i] {
				amn = sm[i]
			}
			if amx < sm[i] {
				amx = sm[i]
			}
		}
	}
	//fmt.Printf("%+v", sm)
	//println(amn, amx)
	if amn != amx {
		fmt.Println(-1)
		return
	}

	mn := int64(-1)
	mx := int64(0)
	for i := 0; i < len(sm); i++ {
		if zCheck[i] {
			if mn == -1 || mn > sm[i] {
				mn = sm[i]
			}
			if mx < sm[i] {
				mx = sm[i]
			}
		}
	}
	if mn != mx || amn <= mn {
		fmt.Println(-1)
		return
	}
	fmt.Println(amn - mn)
	return

}

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}

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

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

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

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

	return result
}

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

	return mp
}

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

package main

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

func checkDigonal(A [][]int64, csum int64) bool {
	var sum1, sum2 int64
	N := len(A)
	for i := 0; i < N; i++ {
		sum1 += A[i][i]
		sum2 += A[N-1-i][i]
	}
	if sum1 == sum2 && sum1 == csum {
		return true
	}
	return false
}

func checkCol(A [][]int64, csum int64) bool {
	N := len(A)

	for j := 0; j < N; j++ {
		var sum int64
		for i := 0; i < N; i++ {
			sum += A[i][j]
		}

		if sum != csum {
			return false
		}
	}
	return true
}

func checkRow(A [][]int64, csum int64) bool {
	N := len(A)

	for i := 0; i < N; i++ {
		var sum int64
		for j := 0; j < N; j++ {
			sum += A[i][j]
		}
		if sum != csum {
			return false
		}
	}
	return true
}

func main() {
	fsc := NewFastScanner()
	N := fsc.NextInt()
	var ei, ej int
	A := make([][]int64, N)
	for i := 0; i < N; i++ {
		A[i] = make([]int64, N)
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			a := fsc.NextInt64()
			if a == 0 {
				ei = i
				ej = j
			}
			A[i][j] = a
		}
	}
	//row
	var ci int
	ci = -1
	for i := 0; i < N; i++ {
		if i != ei {
			ci = i
			break
		}
	}
	var csum int64
	if ci == -1 {
		fmt.Println(114514)
		os.Exit(0)
	} else {

		csum = 0
		for j := 0; j < N; j++ {
			csum += A[ci][j]
		}
		var esum int64
		esum = 0
		for j := 0; j < N; j++ {
			esum += A[ei][j]
		}
		if csum-esum < 1 {
			fmt.Println(-1)
			os.Exit(0)
		}
		A[ei][ej] = csum - esum
	}

	if checkCol(A, csum) && checkRow(A, csum) && checkDigonal(A, csum) {
		fmt.Println(A[ei][ej])
	} else {
		fmt.Println(-1)
	}
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 2028)
	return &FastScanner{r: rdr}
}

func (s *FastScanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}

func (s *FastScanner) NextInt() int {
	val, err := strconv.Atoi(s.Next())
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) NextInt64() int64 {
	val, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return val
}
func (s *FastScanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}

func (s *FastScanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, err := s.r.ReadLine()
		if err != nil {
			panic(err.Error())
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

import "fmt"

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

	a := make([][]int64, n)
	var iz, jz int

	for i := 0; i < n; i++ {
		a[i] = make([]int64, n)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[i][j])
			if a[i][j] == 0 {
				iz = i
				jz = j
			}
		}
	}

	sum := int64(0)

	if n == 1 {
		a[iz][jz] = 1
		sum = 1
	} else {
		k := 0
		for k == iz {
			k++
		}
		sumz := int64(0)
		for j := 0; j < n; j++ {
			sum += a[k][j]
			sumz += a[iz][j]
		}
		a[iz][jz] = sum - sumz
	}

	found := true

	sd1 := int64(0)
	sd2 := int64(0)

	for i := 0; i < n; i++ {
		srow := int64(0)
		scol := int64(0)
		for j := 0; j < n; j++ {
			srow += a[i][j]
			scol += a[j][i]
		}
		if (srow != sum) || (scol != sum) {
			found = false
			break
		}
		sd1 += a[i][i]
		sd2 += a[i][n-1-i]
	}

	if (sd1 != sum) || (sd2 != sum) {
		found = false
	}

	if found {
		fmt.Println(a[iz][jz])
	} else {
		fmt.Println(-1)
	}
}

package main

import "fmt"

func main() {
	var n, tmp, fcolsum, xcolsum int64
	var zi, zj int64
	fmt.Scanln(&n)

	mass := make([][]int64, n)

	for i := int64(0); i < n; i++ {
		mass[i] = make([]int64, n)

		sum := int64(0)
		zero := false

		for j := int64(0); j < n; j++ {
			fmt.Scan(&tmp)
			mass[i][j] = tmp

			if !zero {
				zero = (tmp == 0)

				if zero {
					zi, zj = i, j
				}
			}

			sum = sum + tmp
		}

		if zero {
			xcolsum = sum
		} else {
			if fcolsum != 0 && fcolsum != sum {
				fmt.Println(-1)
				return
			}
			fcolsum = sum
		}
	}

	mass[zi][zj] = fcolsum - xcolsum

	// rows
	for i := int64(0); i < n; i++ {
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			sum = sum + mass[i][j]
		}

		if fcolsum != sum {
			fmt.Println(-1)
			return
		}
	}

	// diag 1
	sum := int64(0)
	for i := int64(0); i < n; i++ {
		sum = sum + mass[i][i]
	}

	if fcolsum != sum {
		fmt.Println(-1)
		return
	}

	// diag 2
	sum = int64(0)
	for i := int64(0); i < n; i++ {
		sum = sum + mass[i][n - i - 1]
	}

	if fcolsum != sum {
		fmt.Println(-1)
		return
	}

	fmt.Println(mass[zi][zj])
}

package main

import "fmt"

func main() {
	var n, tmp, fcolsum, xcolsum int64
	var zi, zj int64
	fmt.Scanln(&n)

	if n == 1 {
		fmt.Println(1)
		return
	}

	mass := make([][]int64, n)

	for i := int64(0); i < n; i++ {
		mass[i] = make([]int64, n)

		sum := int64(0)
		zero := false

		for j := int64(0); j < n; j++ {
			fmt.Scan(&tmp)
			mass[i][j] = tmp

			if !zero {
				zero = (tmp == 0)

				if zero {
					zi, zj = i, j
				}
			}

			sum = sum + tmp
		}

		if zero {
			xcolsum = sum
		} else {
			if fcolsum != 0 && fcolsum != sum {
				fmt.Println(-1)
				return
			}
			fcolsum = sum
		}
	}

	mass[zi][zj] = fcolsum - xcolsum

	// filds
	for i := int64(0); i < n; i++ {
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			sum = sum + mass[i][j]
		}

		if fcolsum != sum {
			fmt.Println(-1)
			return
		}
	}

	// rows
	for i := int64(0); i < n; i++ {
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			sum = sum + mass[j][i]
		}

		if fcolsum != sum {
			fmt.Println(-1)
			return
		}
	}

	// diag 1
	sum := int64(0)
	for i := int64(0); i < n; i++ {
		sum = sum + mass[i][i]
	}

	if fcolsum != sum {
		fmt.Println(-1)
		return
	}

	// diag 2
	sum = int64(0)
	for i := int64(0); i < n; i++ {
		sum = sum + mass[i][n - i - 1]
	}

	if fcolsum != sum {
		fmt.Println(-1)
		return
	}

	fmt.Println(mass[zi][zj])
}

package main

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

func main() {
	var n, tmp, fcolsum, xcolsum int64
	var zi, zj int64

	in := bufio.NewReaderSize(os.Stdin, 1024*1024)
	fmt.Fscan(in, &n)

	if n == 1 {
		fmt.Println(1)
		return
	}

	mass := make([][]int64, n)
	for i := int64(0); i < n; i++ {
		mass[i] = make([]int64, n)

		sum := int64(0)
		zero := false

		for j := int64(0); j < n; j++ {
			fmt.Fscan(in, &tmp)
			mass[i][j] = tmp

			if !zero {
				zero = (tmp == 0)

				if zero {
					zi, zj = i, j
				}
			}

			sum = sum + tmp
		}

		if zero {
			xcolsum = sum
		} else {
			if fcolsum != 0 && fcolsum != sum {
				fmt.Println(-1)
				return
			}
			fcolsum = sum
		}
	}

	mass[zi][zj] = fcolsum - xcolsum
	if mass[zi][zj] == 0 {
		fmt.Println(-1)
		return
	}

	// rows
	for i := int64(0); i < n; i++ {
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			sum = sum + mass[j][i]
		}

		if fcolsum != sum {
			fmt.Println(-1)
			return
		}
	}

	// diag 1 & diag 2
	sum := int64(0)
	sum2 := int64(0)
	for i := int64(0); i < n; i++ {
		sum = sum + mass[i][i]
		sum2 = sum2 + mass[i][n - i - 1]
	}

	if fcolsum != sum || fcolsum != sum2 {
		fmt.Println(-1)
		return
	}

	fmt.Println(mass[zi][zj])
}

package main

import "fmt"

func main() {
	var n, tmp, fcolsum, xcolsum int64
	var zi, zj int64
	fmt.Scanln(&n)

	mass := make([][]int64, n)

	for i := int64(0); i < n; i++ {
		mass[i] = make([]int64, n)

		sum := int64(0)
		zero := false

		for j := int64(0); j < n; j++ {
			fmt.Scan(&tmp)
			mass[i][j] = tmp

			if !zero {
				zero = (tmp == 0)

				if zero {
					zi, zj = i, j
				}
			}

			sum = sum + tmp
		}

		if zero {
			xcolsum = sum
		} else {
			if fcolsum != 0 && fcolsum != sum {
				fmt.Println(-1)
				return
			}
			fcolsum = sum
		}
	}

	mass[zi][zj] = fcolsum - xcolsum

	// filds
	for i := int64(0); i < n; i++ {
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			sum = sum + mass[i][j]
		}

		if fcolsum != sum {
			fmt.Println(-1)
			return
		}
	}

	// rows
	for i := int64(0); i < n; i++ {
		sum := int64(0)
		for j := int64(0); j < n; j++ {
			sum = sum + mass[j][i]
		}

		if fcolsum != sum {
			fmt.Println(-1)
			return
		}
	}

	// diag 1
	sum := int64(0)
	for i := int64(0); i < n; i++ {
		sum = sum + mass[i][i]
	}

	if fcolsum != sum {
		fmt.Println(-1)
		return
	}

	// diag 2
	sum = int64(0)
	for i := int64(0); i < n; i++ {
		sum = sum + mass[i][n - i - 1]
	}

	if fcolsum != sum {
		fmt.Println(-1)
		return
	}

	fmt.Println(mass[zi][zj])
}

package main

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

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

	if n == 1 {
		var trash int
		if _, err := fmt.Scanf("%d\n", &trash); err != nil {
			return
		}
		fmt.Println(1)
		return
	}

	array := make([][]int, n+1)
	array[n] = make([]int, n+1)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	e := [2]int{-1, -1}
	diagonal := [2]int{0, 0}
	target := -1
	met_zero := false

	for i := 0; i < n; i++ {
		array[i] = make([]int, n+1)
		r_sum := 0
		for j := 0; j < n && scanner.Scan(); j++ {
			a, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			array[i][j] = a
			r_sum += a
			array[n][j] += a

			if i == j {
				diagonal[0] += a
			}
			if i+j == n-1 {
				diagonal[1] += a
			}
			if a == 0 {
				e[0] = i
				e[1] = j
				met_zero = true
			}
		}
		array[i][n] = r_sum
		if target < 0 && !met_zero {
			target = r_sum
		}
		if met_zero {
			met_zero = false
		}
	}

	magic := target - array[n][e[1]]
	if target != array[e[0]][n]+magic {
		fmt.Println(-1)
		return
	}

	if e[0] != e[1] {
		if diagonal[0] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[0]+magic != target {
		fmt.Println(-1)
		return
	}
	if e[0]+e[1] != n-1 {
		if diagonal[1] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[1]+magic != target {
		fmt.Println(-1)
		return
	}

	check_ok := true
	for i := 0; i < n; i++ {
		if i != e[0] {
			if array[i][n] != target {
				check_ok = false
				break
			}
		}
		if i != e[1] {
			if array[n][i] != target {
				check_ok = false
				break
			}
		}
	}

	if !check_ok || magic == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(magic)
	}
}

package main

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

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

	if n == 1 {
		var trash int
		if _, err := fmt.Scanf("%d\n", &trash); err != nil {
			return
		}
		fmt.Println(1)
		return
	}

	array := make([][]int64, n+1)
	array[n] = make([]int64, n+1)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	e := [2]int{-1, -1}
	diagonal := [2]int64{0, 0}
	target := int64(-1)
	met_zero := false

	for i := 0; i < n; i++ {
		array[i] = make([]int64, n+1)
		r_sum := int64(0)
		for j := 0; j < n && scanner.Scan(); j++ {
			in, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			a := int64(in)
			array[i][j] = a
			r_sum += a
			array[n][j] += a

			if i == j {
				diagonal[0] += a
			}
			if i+j == n-1 {
				diagonal[1] += a
			}
			if a == 0 {
				e[0] = i
				e[1] = j
				met_zero = true
			}
		}
		array[i][n] = r_sum
		if target < 0 && !met_zero {
			target = r_sum
		}
		if met_zero {
			met_zero = false
		}
	}

	magic := target - array[n][e[1]]
	if target != array[e[0]][n]+magic {
		fmt.Println(-1)
		return
	}

	if e[0] != e[1] {
		if diagonal[0] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[0]+magic != target {
		fmt.Println(-1)
		return
	}
	if e[0]+e[1] != n-1 {
		if diagonal[1] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[1]+magic != target {
		fmt.Println(-1)
		return
	}

	check_ok := true
	for i := 0; i < n; i++ {
		if i != e[0] {
			if array[i][n] != target {
				check_ok = false
				break
			}
		}
		if i != e[1] {
			if array[n][i] != target {
				check_ok = false
				break
			}
		}
	}

	if !check_ok || magic == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(magic)
	}
}

package main

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

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

	if n == 1 {
		var trash int
		if _, err := fmt.Scanf("%d\n", &trash); err != nil {
			return
		}
		fmt.Println(1)
		return
	}

	array := make([][]int, n+1)
	array[n] = make([]int, n+1)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	e := [2]int{-1, -1}
	diagonal := [2]int{0, 0}
	target := -1
	met_zero := false

	for i := 0; i < n; i++ {
		array[i] = make([]int, n+1)
		r_sum := 0
		for j := 0; j < n && scanner.Scan(); j++ {
			a, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			array[i][j] = a
			r_sum += a
			array[n][j] += a

			if i == j {
				diagonal[0] += a
			}
			if i+j == n-1 {
				diagonal[1] += a
			}
			if a == 0 {
				e[0] = i
				e[1] = j
				met_zero = true
			}
		}
		array[i][n] = r_sum
		if target < 0 && !met_zero {
			target = r_sum
		}
		if met_zero {
			met_zero = false
		}
	}

	magic := target - array[n][e[1]]
	if target != array[e[0]][n]+magic {
		fmt.Println(-1)
		return
	}

	if e[0] != e[1] {
		if diagonal[0] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[0]+magic != target {
		fmt.Println(-1)
		return
	}
	if e[0]+e[1] != n-1 {
		if diagonal[1] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[1]+magic != target {
		fmt.Println(-1)
		return
	}

	check_ok := true
	for i := 0; i < n; i++ {
		if i != e[0] {
			if array[i][n] != target {
				check_ok = false
				break
			}
		}
		if i != e[1] {
			if array[n][i] != target {
				check_ok = false
				break
			}
		}
	}

	if !check_ok {
		fmt.Println(-1)
	} else {
		fmt.Println(magic)
	}
}

package main

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

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

	array := make([][]int, n+1)
	array[n] = make([]int, n+1)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	e := [2]int{-1, -1}
	diagonal := [2]int{0, 0}
	target := -1
	met_zero := false

	for i := 0; i < n; i++ {
		array[i] = make([]int, n+1)
		r_sum := 0
		for j := 0; j < n && scanner.Scan(); j++ {
			a, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			array[i][j] = a
			r_sum += a
			array[n][j] += a

			if i == j {
				diagonal[0] += a
			}
			if i+j == n-1 {
				diagonal[1] += a
			}
			if a == 0 {
				e[0] = i
				e[1] = j
				met_zero = true
			}
		}
		array[i][n] = r_sum
		if target < 0 && !met_zero {
			target = r_sum
		}
		if met_zero {
			met_zero = false
		}
	}

	magic := target - array[n][e[1]]
	if target != array[e[0]][n]+magic {
		fmt.Println(-1)
		return
	}

	if e[0] != e[1] {
		if diagonal[0] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[0]+magic != target {
		fmt.Println(-1)
		return
	}
	if e[0]+e[1] != n-1 {
		if diagonal[1] != target {
			fmt.Println(-1)
			return
		}
	} else if diagonal[1]+magic != target {
		fmt.Println(-1)
		return
	}

	check_ok := true
	for i := 0; i < n; i++ {
		if i != e[0] {
			if array[i][n] != target {
				check_ok = false
				break
			}
		}
		if i != e[1] {
			if array[n][i] != target {
				check_ok = false
				break
			}
		}
	}

	if !check_ok {
		fmt.Println(-1)
	} else {
		fmt.Println(magic)
	}
}

// Codeforces 711 B
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

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

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

var n,ii,jj int
var val,sum,altSum int
var aa [][]int
var ok bool

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading n
    n,_,_,_,_ = readFive()
    aa = make([][]int, n)
    for i:=0; i<n; i++ {
        aa[i] = make([]int, n)
        aaa := readLineNumbs(n)
        for j:=0; j<n; j++ {
            aa[i][j] = aaa[j]
            if aa[i][j]==0 {
                ii = i
                jj = j
            }
        }
    }
}

func checkSum(sm int, alt bool) {
    if !ok {
        return
    }
    if alt {
        if altSum==-1 {
            altSum = sm
        } else {
            if altSum != sm {
                ok = false
            }
        }
    } else {
        if sum==-1 {
            sum = sm
        } else {
            if sum != sm {
                ok = false
            }
        }
    }
}

func solve() {
    sum = -1
    altSum = -1
    ok = true
    // rows
    for i:=0; i<n; i++ {
        sm := 0
        for j:=0; j<n; j++ {
            sm += aa[i][j]
        }
        alt := (i==ii)
        checkSum(sm, alt)
    }
    // columns
    for j:=0; j<n; j++ {
        sm := 0
        for i:=0; i<n; i++ {
            sm += aa[i][j]
        }
        alt := (j==jj)
        checkSum(sm, alt)
    }
    // main diagonal
    sm := 0
    for i:=0; i<n; i++ {
        sm += aa[i][i]
    }
    alt := (ii==jj)
    checkSum(sm, alt)
    // other diagonal
    sm = 0
    for i:=0; i<n; i++ {
        sm += aa[i][n-i-1]
    }
    alt = (ii==(n-jj-1))
    checkSum(sm, alt)
}

func printRes() {
    if n==1 {
        val = 1
    } else if ok && (sum > altSum) {
        val = sum - altSum
    } else {
        val = -1
    }
    fmt.Println(val)
}

func main() {
 	readData()

    solve()
    printRes()
}

// Codeforces 711 B
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
	"strconv"
)
var in *bufio.Reader

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

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

var n,ii,jj int
var val,sum,altSum int
var aa [][]int
var ok bool

func readData() {
 	in = bufio.NewReader(os.Stdin)
	// reading n
    n,_,_,_,_ = readFive()
    aa = make([][]int, n)
    for i:=0; i<n; i++ {
        aa[i] = make([]int, n)
        aaa := readLineNumbs(n)
        for j:=0; j<n; j++ {
            aa[i][j] = aaa[j]
            if aa[i][j]==0 {
                ii = i
                jj = j
            }
        }
    }
}

func checkSum(sm int, alt bool) {
    if !ok {
        return
    }
    if alt {
        if altSum==-1 {
            altSum = sm
        } else {
            if altSum != sm {
                ok = false
            }
        }
    } else {
        if sum==-1 {
            sum = sm
        } else {
            if sum != sm {
                ok = false
            }
        }
    }
}

func solve() {
    sum = -1
    altSum = -1
    ok = true
    // rows
    for i:=0; i<n; i++ {
        sm := 0
        for j:=0; j<n; j++ {
            sm += aa[i][j]
        }
        alt := (i==ii)
        checkSum(sm, alt)
    }
    // columns
    for j:=0; j<n; j++ {
        sm := 0
        for i:=0; i<n; i++ {
            sm += aa[i][j]
        }
        alt := (j==jj)
        checkSum(sm, alt)
    }
    // main diagonal
    sm := 0
    for i:=0; i<n; i++ {
        sm += aa[i][i]
    }
    alt := (ii==jj)
    checkSum(sm, alt)
    // other diagonal
    sm = 0
    for i:=0; i<n; i++ {
        sm += aa[i][n-i-1]
    }
    alt = (ii==(n-jj-1))
    checkSum(sm, alt)
}

func printRes() {
    if n==1 {
        val = 1
    } else if ok {
        val = sum - altSum
    } else {
        val = -1
    }
    fmt.Println(val)
}

func main() {
 	readData()

    solve()
    printRes()
}

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	A := make([][]int, N)
	zero := 0
	sm := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = in.NextIntArray()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zero = i
			}
			sm[i] += A[i][j]
		}
	}
	if N == 1 {
		fmt.Println(1)
		return
	}
	B := 1
	if zero == 1 {
		B = 0
	}

	if N == 2 {
		if sm[B] - sm[zero] > 0 {
			fmt.Println(sm[B] - sm[zero])
			return
		} else {
			fmt.Println(-1)
			return
		}
	}
	mp := map[int]struct{}{}
	for i := 0; i < N; i++ {
		mp[sm[i]] = struct{}{}
	}
	if len(mp) != 1 {
		fmt.Println(-1)
		return
	}

	fmt.Println(sm[B] - sm[zero])
	return

}

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

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

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

	return result
}

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

	return mp
}

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

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	A := make([][]int64, N)
	zeroColumn := 0
	zeroRow := 0
	sm := make([]int64, 2 * N + 2)
	for i := 0; i < N; i++ {
		A[i] = in.NextInt64Array()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zeroColumn = i
				zeroRow = j
			}
			sm[i] += A[i][j]
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			sm[i + N] += A[j][i]
		}
	}

	cross := int64(0)
	for i := 0; i < N; i++ {
		cross += A[i][i]
	}
	sm = append(sm, cross)
	for i := 0; i < N; i++ {
		cross += A[i][N - i - 1]
	}
	sm = append(sm, cross)
	for i := 0; i < N; i++ {
		cross += A[N - i - 1][i]
	}
	sm = append(sm, cross)

	s1 := int64(0)
	for i := 0; i < N; i++ {
		s1 += A[i][zeroRow]
	}

	s2 := int64(0)
	for i := 0; i < N; i++ {
		s2 += A[zeroColumn][i]
	}

	if s1 != s2 || cross != 0 && (s1 != cross || s2 != cross) {
		fmt.Println(-1)
		return
	}

	if N == 1 {
		fmt.Println(1)
		return
	}

	B := -1
	mn := sm[0]
	mx := int64(0)
	mp := map[int64]struct{}{}
	for i := 0; i < N; i++ {
		mp[sm[i]] = struct{}{}
		mn = min(mn, sm[i])
		if mx < sm[i] {
			B = i
		}
		mx = max(mx, sm[i])
	}
	if len(mp) != 2 || mn != sm[zeroColumn] {
		fmt.Println(-1)
		return
	}
	if sm[B] - sm[zeroColumn] > 0 {
		fmt.Println(sm[B] - sm[zeroColumn])
		return
	}
	fmt.Println(-1)
	return

}

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}

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

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

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

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

	return result
}

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

	return mp
}

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

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

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	if N == 1 {
		fmt.Println(1)
		return
	}

	A := make([][]int64, N)
	sm := make([]int64, 2 * N + 2)
	zCheck := make([]bool, 2 * N + 2)
	for i := 0; i < N; i++ {
		A[i] = in.NextInt64Array()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zCheck[i] = true
			}
			sm[i] += A[i][j]
		}
	}
	for j := 0; j < N; j++ {
		for i := 0; i < N; i++ {
			if A[j][i] == 0 {
				zCheck[j + N] = true
			}
			sm[j + N] += A[j][i]
		}
	}

	for i := 0; i < N; i++ {
		if A[i][i] == 0 {
			zCheck[2 * N ] = true
		}
		sm[2 * N] += A[i][i]
	}

	for i := 0; i < N; i++ {
		if A[i][N - i - 1] == 0 {
			zCheck[2 * N + 1 ] = true
		}

		sm[2 * N + 1] += A[i][N - i - 1]
	}

	mp := map[int64]struct{}{}
	for i := 0; i < len(sm); i++ {
		mp[sm[i]] = struct{}{}
	}

	if len(mp) != 2 {
		fmt.Println(-1)
		return
	}

	amn := int64(-1)
	amx := int64(0)
	for i := 0; i < len(sm); i++ {
		if !zCheck[i] {
			if amn == -1 || amn > sm[i] {
				amn = sm[i]
			}
			if amx < sm[i] {
				amx = sm[i]
			}
		}
	}
	if amn != amx {
		fmt.Println(-1)
		return
	}

	mn := int64(-1)
	mx := int64(0)
	for i := 0; i < len(sm); i++ {
		if zCheck[i] {
			if mn == -1 || mn > sm[i] {
				mn = sm[i]
			}
			if mx < sm[i] {
				mx = sm[i]
			}
		}
	}
	if mn != mx || amn <= mn {
		fmt.Println(-1)
		return
	}
	fmt.Println(amn - mn)
	return

}

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}

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

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

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

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

	return result
}

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

	return mp
}

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

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	A := make([][]int64, N)
	zeroColumn := 0
	zeroRow := 0
	sm := make([]int64, 2 * N)
	for i := 0; i < N; i++ {
		A[i] = in.NextInt64Array()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zeroColumn = i
				zeroRow = j
			}
			sm[i] += A[i][j]
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			sm[i + N] += A[j][i]
		}
	}

	cross := int64(0)
	if zeroColumn == zeroRow {
		for i := 0; i < N; i++ {
			cross += A[i][i]
		}
		sm = append(sm, cross)
	} else if zeroColumn + zeroRow == N - 1 {
		if zeroColumn < zeroColumn {
			for i := 0; i < N; i++ {
				cross += A[i][N - i - 1]
			}
			sm = append(sm, cross)
		} else {
			for i := 0; i < N; i++ {
				cross += A[N - i - 1][i]
			}
			sm = append(sm, cross)
		}
	}

	s1 := int64(0)
	for i := 0; i < N; i++ {
		s1 += A[i][zeroRow]
	}

	s2 := int64(0)
	for i := 0; i < N; i++ {
		s2 += A[zeroColumn][i]
	}

	if s1 != s2 || cross != 0 && (s1 != cross || s2 != cross) {
		fmt.Println(-1)
		return
	}

	if N == 1 {
		fmt.Println(1)
		return
	}

	B := -1
	mn := sm[0]
	mx := int64(0)
	mp := map[int64]struct{}{}
	for i := 0; i < N; i++ {
		mp[sm[i]] = struct{}{}
		mn = min(mn, sm[i])
		if mx < sm[i] {
			B = i
		}
		mx = max(mx, sm[i])
	}
	if len(mp) != 2 || mn != sm[zeroColumn] {
		fmt.Println(-1)
		return
	}

	if sm[B] - sm[zeroColumn] > 0 {
		fmt.Println(sm[B] - sm[zeroColumn])
		return
	}
	fmt.Println(-1)
	return

}

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}

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

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

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

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

	return result
}

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

	return mp
}

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

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

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	A := make([][]int, N)
	zero := 0
	sm := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = in.NextIntArray()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zero = i
			}
			sm[i] += A[i][j]
		}
	}
	if N == 1 {
		fmt.Println(1)
		return
	}

	if N == 2 {
		B := 1
		if zero == 1 {
			B = 0
		}

		if sm[B] - sm[zero] > 0 {
			fmt.Println(sm[B] - sm[zero])
			return
		} else {
			fmt.Println(-1)
			return
		}
	}
	B := 0
	mn := sm[0]
	mx := 0
	mp := map[int]struct{}{}
	for i := 0; i < N; i++ {
		mp[sm[i]] = struct{}{}
		mn = min(mn, sm[i])
		if mx < sm[i] {
			B = i
		}
		mx = max(mx, sm[i])
	}
	if len(mp) != 2 || mn != sm[zero] {
		fmt.Println(-1)
		return
	}

	if sm[B] - sm[zero] > 0 {
		fmt.Println(sm[B] - sm[zero])
		return
	}
	fmt.Println(-1)
	return

}

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

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

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

	return result
}

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

	return mp
}

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

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

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	A := make([][]int, N)
	zero := 0
	sm := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = in.NextIntArray()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zero = i
			}
			sm[i] += A[i][j]
		}
	}
	if N == 1 {
		fmt.Println(1)
		return
	}
	B := 1
	if zero == 1 {
		B = 0
	}

	if N == 2 {
		if sm[B] - sm[zero] > 0 {
			fmt.Println(sm[B] - sm[zero])
			return
		} else {
			fmt.Println(-1)
			return
		}
	}
	if sm[0] != sm[1] && sm[1] != sm[2] && sm[0] != sm[2] {
		fmt.Println(-1)
		return
	}

	fmt.Println(sm[B] - sm[zero])
	return

}

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

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

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

	return result
}

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

	return mp
}

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

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	A := make([][]int, N)
	zero := 0
	sm := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = in.NextIntArray()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zero = i
			}
			sm[i] += A[i][j]
		}
	}
	if N == 1 {
		fmt.Println(1)
		return
	}
	B := 1
	if zero == 1 {
		B = 0
	}

	if N == 2 {
		if sm[B] - sm[zero] > 0 {
			fmt.Println(sm[B] - sm[zero])
			return
		} else {
			fmt.Println(-1)
			return
		}
	}
	mp := map[int]struct{}{}
	for i := 0; i < N; i++ {
		mp[sm[i]] = struct{}{}
	}
	if len(mp) != 2 {
		fmt.Println(-1)
		return
	}

	if sm[B] - sm[zero] > 0 {
		fmt.Println(sm[B] - sm[zero])
		return
	}
	fmt.Println(-1)
	return

}

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

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

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

	return result
}

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

	return mp
}

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

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	A := make([][]int, N)
	zero := 0
	sm := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = in.NextIntArray()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zero = i
			}
			sm[i] += A[i][j]
		}
	}
	if N == 1 {
		fmt.Println(1)
		return
	}

	if N == 2 {
		B := 1
		if zero == 1 {
			B = 0
		}

		if sm[B] - sm[zero] > 0 {
			fmt.Println(sm[B] - sm[zero])
			return
		} else {
			fmt.Println(-1)
			return
		}
	}
	B := -1
	mn := sm[0]
	mx := 0
	mp := map[int]struct{}{}
	for i := 0; i < N; i++ {
		mn = min(mn, sm[i])
		mx = max(mx, sm[i])
	}
	if len(mp) != 2 || mn != sm[zero] {
		fmt.Println(-1)
		return
	}

	if sm[B] - sm[zero] > 0 {
		fmt.Println(sm[B] - sm[zero])
		return
	}
	fmt.Println(-1)
	return

}

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

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

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

	return result
}

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

	return mp
}

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

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

package main

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

type TupleInt struct {
	first  int
	second int
	third  int
}

func main() {
	in := NewScanner()
	N := in.NextInt()
	A := make([][]int64, N)
	zeroColumn := 0
	zeroRow := 0
	sm := make([]int64, 2 * N)
	for i := 0; i < N; i++ {
		A[i] = in.NextInt64Array()
		for j := 0; j < N; j++ {
			if A[i][j] == 0 {
				zeroColumn = i
				zeroRow = j
			}
			sm[i] += A[i][j]
		}
	}
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			sm[i + N] += A[j][i]
		}
	}

	cross1 := int64(0)
	for i := 0; i < N; i++ {
		cross1 += A[i][i]
	}
	sm = append(sm, cross1)

	cross2 := int64(0)
	for i := 0; i < N; i++ {
		cross2 += A[i][N - i - 1]
	}
	sm = append(sm, cross2)

	s1 := int64(0)
	for i := 0; i < N; i++ {
		s1 += A[i][zeroRow]
	}

	s2 := int64(0)
	for i := 0; i < N; i++ {
		s2 += A[zeroColumn][i]
	}
	h := []int64{s1, s2, cross1, cross2}
	amn := h[0]
	amx := h[0]
	for i := 0; i < 4; i++ {
		if amn > h[i] {
			amn = h[i]
		}
		if amx < h[i] {
			amx = h[i]
		}
	}
	//if amn != amx {
	//	fmt.Println(-1)
	//	return
	//}
	if N == 1 {
		fmt.Println(1)
		return
	}

	B := -1
	mn := sm[0]
	mx := int64(0)
	mp := map[int64]struct{}{}
	for i := 0; i < len(sm); i++ {
		mp[sm[i]] = struct{}{}
		mn = min(mn, sm[i])
		if mx < sm[i] {
			B = i
		}
		mx = max(mx, sm[i])
	}
	if len(mp) != 2 || mn != sm[zeroColumn] {
		fmt.Println(-1)
		return
	}
	if sm[B] - sm[zeroColumn] > 0 {
		fmt.Println(sm[B] - sm[zeroColumn])
		return
	}
	fmt.Println(-1)
	return

}

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}

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

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

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

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

	return result
}

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

	return mp
}

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

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


package main

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

/* solution */

func solve() {
	n := readInt()
	f := 1
	for i := 0; i < n; i++ {
		v := readInt()
		if v%2 != 0 {
			v += f
			f = -f
		}
		printInt(v / 2)
	}
}

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

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

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

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

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

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}

	cnt := 0
	b := make([]int, n)
	for i, ai := range a {
		if ai&1 == 1 {
			cnt++
			if cnt&1 == 1 {
				b[i] = (ai + 1) / 2
			} else {
				b[i] = (ai - 1) / 2
			}
		} else {
			b[i] = ai / 2
		}
	}
	for _, bi := range b {
		Fprintln(out, bi)
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var n, a int
	fmt.Scanf("%d\n", &n)

	b := make([]int, n)
	cnt := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d\n", &a)
		if a%2 == 0 {
			b[i] = a / 2
		} else {
			cnt++
			if cnt%2 == 0 {
				b[i] = (a + 1) / 2
			} else {
				b[i] = (a - 1) / 2
			}
		}
	}

	// output
	for i := 0; i < n; i++ {
		fmt.Println(b[i])
	}
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	arr := make([]int, n)
	odd := 0
	for i := range arr {
		Fscan(in, &arr[i])
		if arr[i]&1 == 1 {
			odd++
		}
	}

	b := make([]int, n)
	sum := 0
	flag1, flag2 := 0, 0
	for i, ai := range arr {
		b[i] = ai / 2
		if ai&1 == 1 {
			if b[i] > 0 {
				if flag1&1 == 1 {
					b[i]++
				}
				flag1++
			} else {
				if flag2&1 == 1 {
					b[i]--
				}
				flag2++
			}
		}
		sum += b[i]
	}

	//Fprintln(out, sum)

	for _, bi := range b {
		Fprintln(out, bi)
	}
}

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

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	arr := make([]int, n)
	odd := 0
	for i := range arr {
		Fscan(in, &arr[i])
		if arr[i]&1 == 1 {
			odd++
		}
	}

	b := make([]int, n)
	sum := 0

	for i, ai := range arr {
		b[i] = ai / 2
		sum += b[i]
	}

	for i,ai := range arr {
		if ai&1 == 1 {
			if sum < 0 && b[i] > 0 {
				b[i]++
				sum++
			} else if sum > 0 && b[i] < 0 {
				b[i]--
				sum--
			}
			if sum == 0 {
				break
			}
		}
	}

	//Fprintln(out, sum)

	for _, bi := range b {
		Fprintln(out, bi)
	}
}

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

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	Fscan(in, &n)
	arr := make([]int, n)
	odd := 0
	for i := range arr {
		Fscan(in, &arr[i])
		if arr[i]&1 == 1 {
			odd++
		}
	}

	b := make([]int, n)
	sum := 0
	flag :=0
	for i, ai := range arr {
		b[i] = ai / 2
		if ai&1 == 1 {
			if flag & 1 == 1 {
				if b[i]>0 {
					b[i]++

				} else {
						b[i]--
				}
			}
		}
		flag++
		sum += b[i]
	}

	//Fprintln(out, sum)

	for _, bi := range b {
		Fprintln(out, bi)
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var n, a int
	fmt.Scanf("%d", &n)

	b := make([]int, n)
	cnt := 0

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
		if a%2 == 0 {
			b[i] = a / 2
		} else {
			cnt++
			if cnt%2 == 0 {
				b[i] = (a + 1) / 2
			} else {
				b[i] = (a - 1) / 2
			}
		}
	}

	// output
	for i := 0; i < n; i++ {
		fmt.Println(b[i])
	}
}


package main

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

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

func scanInt() int {
	sc.Scan(); a,_ := strconv.Atoi(sc.Text()); return a
}

func scanInt64() int64 {
	sc.Scan(); a,_ := strconv.ParseInt(sc.Text(),10,64); return a
}

func scanFloat64() float64 {
	sc.Scan(); a,_ := strconv.ParseFloat(sc.Text(),64); return a
}

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

func scanString() string {
	sc.Scan(); return sc.Text()
}

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e); if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr); wr.Flush()
}

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()
		m := scanInt()
		k := scanInt()
		a := scanInts(n)

		ans := 0

		l := 0
		ma := min(k,m-1)
		for l < ma+1 {
			r := ma-l
			// fmt.Println(l,n-r)
			arr := a[l:n-r]
			mi := 1 << 31 -1
			for i := 0; i < len(arr)-(n-m); i++ {
				mi = min(mi,max(arr[i],arr[i+n-m]))
			}

			ans = max(ans, mi)
			// fmt.Println(arr,mi)
			l++
		}

		fmt.Println(ans)
	}
}

package main

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

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m, k int
		fmt.Fscanf(reader, "%d %d %d\n", &n, &m, &k)
		vals := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscanf(reader, "%d", &vals[j])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%d\n", findBestValue(vals, m, k))
	}
	writer.Flush()
}

func findBestValue(vals []int, m int, k int) int {
	n := len(vals)

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

	for len := n - m + 1; len <= n; len++ {
		for i := 0; i+len <= n; i++ {
			j := i + len - 1
			if len == n-m+1 {
				dp[i][j] = max(vals[i], vals[j])
			} else {
				if k > n-len {
					dp[i][j] = max(dp[i+1][j], dp[i][j-1])
				} else {
					dp[i][j] = min(dp[i+1][j], dp[i][j-1])
				}
			}
		}
	}

	return dp[0][n-1]
}

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

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

package main

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

func run(_r io.Reader, _w io.Writer) {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func() (ans int) {
		var n, kth, fix int
		Fscan(in, &n, &kth, &fix)
		fix = min(fix, kth-1)
		kth-- // todo
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		dp := make([][]int, n)
		for i := range dp {
			dp[i] = make([]int, n)
			for j := range dp[i] {
				dp[i][j] = -1
			}
		}

		minLen := n - kth

		kth -= fix

		var f func(int, int) int
		f = func(l, r int) (_ans int) {
			if l + minLen-1 ==r {
				return max(a[l],a[r])
			}

			//if l > r {
			//	return 0
			//}
			if dp[l][r] != -1 {
				return dp[l][r]
			}
			defer func() { dp[l][r] = _ans }()

			f1 := f(l,r-1)
			f2 := f(l+1,r)

			return min(f1,f2)
		}

		for i := 0; i <= fix; i++ {
			fAns :=  f(i, i+n-fix-1)
			ans = max(ans,fAns)
		}

		return
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		_ans := solve()
		Fprintln(out, _ans)
	}
}

func main() {
	//debug.SetGCPercent(-1)
	run(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"runtime/debug"
)

func run(_r io.Reader, _w io.Writer) {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func() (ans int) {
		var n, kth, fix int
		Fscan(in, &n, &kth, &fix)
		fix = min(fix, kth-1)
		kth-- // todo
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		dp := make([][]int, n)
		for i := range dp {
			dp[i] = make([]int, n)
			for j := range dp[i] {
				dp[i][j] = -1
			}
		}

		minLen := n - kth

		kth -= fix

		var f func(int, int) int
		f = func(l, r int) (_ans int) {
			if l + minLen-1 ==r {
				return max(a[l],a[r])
			}

			//if l > r {
			//	return 0
			//}
			if dp[l][r] != -1 {
				return dp[l][r]
			}
			defer func() { dp[l][r] = _ans }()

			f1 := f(l,r-1)
			f2 := f(l+1,r)

			return min(f1,f2)
		}

		for i := 0; i <= fix; i++ {
			fAns :=  f(i, i+n-fix-1)
			ans = max(ans,fAns)
		}

		return
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		_ans := solve()
		Fprintln(out, _ans)
	}
}

func main() {
	debug.SetGCPercent(-1)
	run(os.Stdin, os.Stdout) }

package main

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

func run(_r io.Reader, _w io.Writer) {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func() (ans int) {
		var n, kth, fix int
		Fscan(in, &n, &kth, &fix)
		fix = min(fix, kth-1)
		kth-- // todo
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		dp := make([][]int, n)
		for i := range dp {
			dp[i] = make([]int, n)
			for j := range dp[i] {
				dp[i][j] = -1
			}
		}

		minLen := n - kth

		kth -= fix

		var f func(int, int) int
		f = func(l, r int) (_ans int) {
			if l + minLen-1 ==r {
				return max(a[l],a[r])
			}

			//if l > r {
			//	return 0
			//}
			if dp[l][r] != -1 {
				return dp[l][r]
			}
			defer func() { dp[l][r] = _ans }()

			f1 := f(l,r-1)
			f2 := f(l+1,r)

			return min(f1,f2)
		}

		for i := 0; i <= fix; i++ {
			fAns :=  f(i, i+n-fix-1)
			ans = max(ans,fAns)
		}

		return
	}

	var t int
	Fscan(in, &t)
	for _case := 1; _case <= t; _case++ {
		_ans := solve()
		Fprintln(out, _ans)
	}
}

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

package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

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

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

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

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

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

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

	in := scanInt()

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

		l, r := 0, n-m
		arr := make([]int, 0)

		for r < n {
			arr = append(arr, max(a[l],a[r]))
			l++
			r++
		}

		l,r = 0, len(arr)-1
		for i := 0; i < min(k,m-1); i++ {
			if arr[l] < arr[r] {
				l++
			} else {
				r--
			}
		}
		for i := 0; i < max(0,m-1-k); i++ {
			if arr[l] > arr[r] {
				l++
			} else {
				r--
			}
		}
		// fmt.Println(arr)

		fmt.Println(max(arr[l],arr[r]))
	}

}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}

package main

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

//•*¨*•.¸¸♪I/O•*¨*•.¸¸♪

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

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

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

func scanFloat64() float64 {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return float64(a)
}

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

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

func printInts(a ...int) {
	for i, e := range a {
		fmt.Fprint(wr, e)
		if i != len(a)-1 { fmt.Fprint(wr, " ") }
	}
	fmt.Fprintln(wr)
	wr.Flush()
}

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

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

	in := scanInt()

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

		l, r := 0, n-m
		arr := make([]int, 0)

		for r < n {
			arr = append(arr, max(a[l],a[r]))
			l++
			r++
		}

		sort.Ints(arr)
		fmt.Println(arr[min(k,m-1)])

	}

}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] { res = a[i] }
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] { res = a[i] }
	}
	return res
}