Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.This time mr. Boosch plans to sign 2k laws. He decided to choose exactly two non-intersecting segments of integers from 1 to n of length k and sign all laws, whose numbers fall into these segments. More formally, mr. Boosch is going to choose two integers a, b (1 ≤ a ≤ b ≤ n - k + 1, b - a ≥ k) and sign all laws with numbers lying in the segments [a; a + k - 1] and [b; b + k - 1] (borders are included).As mr. Boosch chooses the laws to sign, he of course considers the public opinion. Allberland Public Opinion Study Centre (APOSC) conducted opinion polls among the citizens, processed the results into a report and gave it to the president. The report contains the absurdity value for each law, in the public opinion. As mr. Boosch is a real patriot, he is keen on signing the laws with the maximum total absurdity. Help him.

The first line contains two integers n and k (2 ≤ n ≤ 2·105, 0 < 2k ≤ n) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains n integers x1, x2, ..., xn — the absurdity of each law (1 ≤ xi ≤ 109).

Print two integers a, b — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [a; a + k - 1] and [b; b + k - 1]. If there are multiple solutions, print the one with the minimum number a. If there still are multiple solutions, print the one with the minimum b.

NoteIn the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4.

package main

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

func main(){
	var n, k int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	var w [200005]int
	var d [200005]int64
	var b, bb, a int
	var m, z int64
	for i:=1; i<=n; i++ {
		r.Scan()
		w[i], _ = strconv.Atoi(r.Text())
	}
	for i:=1; i<=k; i++ {
		d[1] += int64(w[i])
	}
	for i:=k+1; i<=n; i++ {
		d[i-k+1] = d[i-k]-int64(w[i-k])+int64(w[i])
	}
	for i:=n-2*k+1; i>=1; i-- {
		if int64(m) <= d[i+k] {
			m = d[i+k]
			b = i+k
		}
		if z <= m + d[i] {
			z = m+d[i]
			a = i
			bb = b
		}
	}
	wr.WriteString(strconv.Itoa(a)+" "+strconv.Itoa(bb)+"\n")
	wr.Flush()
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF332B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		v int64
		i int
	}
	const mx = 18
	var st [][mx]pair
	stInit := func(a []int64) {
		n := len(a)
		st = make([][mx]pair, n)
		for i := range st {
			st[i][0] = pair{a[i], i}
		}
		for j := uint(1); 1<<j <= n; j++ {
			for i := 0; i+(1<<j)-1 < n; i++ {
				st0, st1 := st[i][j-1], st[i+(1<<(j-1))][j-1]
				if st0.v >= st1.v {
					st[i][j] = st0
				} else {
					st[i][j] = st1
				}
			}
		}
	}
	stQuery := func(l, r int) pair {
		k := uint(bits.Len(uint(r-l)) - 1)
		st0, st1 := st[l][k], st[r-(1<<k)][k]
		if st0.v >= st1.v {
			return st0
		}
		return st1
	}

	var n, k, ansA, ansB int
	var max int64
	Fscan(in, &n, &k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sumK := make([]int64, n+1-k)
	for _, v := range a[:k] {
		sumK[0] += int64(v)
	}
	for i := k; i < n; i++ {
		sumK[i-k+1] = sumK[i-k] + int64(a[i]-a[i-k])
	}
	stInit(sumK)
	for i, sumA := range sumK[:n-2*k+1] {
		p := stQuery(i+k, n+1-k)
		if sumA+p.v > max {
			max = sumA + p.v
			ansA = i
			ansB = p.i
		}
	}
	Fprint(out, ansA+1, ansB+1)
}

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

// 332B
package main

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

func main() {
	var (
		S, Z                [200006]int64
		a, b, c, f, i, n, k int64
	)
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n, &k)
	a, b, f = 1, k+1, 1
	S[0] = 0
	for i = 1; i <= n; i++ {
		fmt.Fscan(in, &c)
		S[i] = S[i-1] + c
		c = i - k + 1
		if i >= k {
			Z[c] = S[i] - S[c-1]
		}
		if i >= k*2 {
			if Z[c-k] > Z[f] {
				f = c - k
			}
			if Z[f]+Z[c] > Z[a]+Z[b] {
				a = f
				b = c
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", a, b)
	out.Flush()
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

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

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

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

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

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

type STInterface interface {
  Len() int
  Less(i, j int) bool
}

type SparseTable struct {
  l     []int
  table [][]int
  data  STInterface
}

func NewSparseTable(a STInterface) *SparseTable {
  t := &SparseTable{}
  n := a.Len()
  t.data = a
  t.l = make([]int, n+1)
  for i := 2; i <= n; i++ {
    t.l[i] = t.l[i>>1] + 1
  }

  t.table = make([][]int, t.l[n]+1)
  for i := 0; i < t.l[n]+1; i++ {
    t.table[i] = make([]int, n)
  }

  for i := 0; i < n; i++ {
    t.table[0][i] = i
  }

  for k := 1; (1 << uint(k)) <= n; k++ {
    for i := 0; i+(1<<uint(k)) <= n; i++ {
      x := t.table[k-1][i]
      y := t.table[k-1][i+(1<<(uint(k)-1))]
      if a.Less(x, y) {
        t.table[k][i] = x
      } else {
        t.table[k][i] = y
      }
    }
  }
  return t
}

func (t *SparseTable) Query(i, j int) int {
  k := t.l[j-i]
  x := t.table[k][i]
  y := t.table[k][j-(1<<uint(k))+1]
  if t.data.Less(x, y) {
    return x
  }
  return y
}

type mydata []int64

func (m mydata) Len() int { return len(m) }
func (m mydata) Less(i, j int) bool {
  if m[i] > m[j] || (m[i] == m[j] && i < j) {
    return true
  }
  return false
}

func main() {
  n, k := ni32(), ni32()
  x, X, XX := make([]int64, n), make([]int64, n), make([]int64, n)
  for i := 0; i < n; i++ {
    x[i] = ni64()
    X[i] = x[i]
    if i > 0 {
      X[i] += X[i-1]
    }
    XX[i] = X[i]
    if i >= k {
      XX[i] -= X[i-k]
    }
  }
  t := NewSparseTable(mydata(XX))
  a, b, ans := -1, -1, int64(-1)
  for i := k - 1; i < n-k; i++ {
    cur := XX[t.Query(k-1, i)] + XX[t.Query(i+k, n-1)]
    if cur > ans {
      a, b, ans = t.Query(k-1, i), t.Query(i+k, n-1), cur
    }
  }
  pri32(a - k + 2)
  sp()
  pri32(b - k + 2)
  endl()
  w.Flush()
}

package main

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

type Scanner struct {
  r              io.Reader
  split          bufio.SplitFunc
  QueryTokenSize int
  token, buf     []byte
  start, end     int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:              r,
    split:          bufio.ScanWords,
    QueryTokenSize: 16777216,
    buf:            make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.QueryTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.QueryTokenSize {
        newSize = s.QueryTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

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

func next() string { sc.Scan(); return sc.Text() }
func nc() byte     { sc.Scan(); return sc.Text()[0] }

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

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

func pri32(i ...int) {
  for _, ii := range i {
    w.WriteString(strconv.Itoa(ii))
    sp()
  }
}
func pri64(i ...int64) {
  for _, ii := range i {
    w.WriteString(strconv.FormatInt(ii, 10))
    sp()
  }
}
func sp()   { w.WriteByte(' ') }
func endl() { w.WriteByte('\n') }

var XX []int64

type STree []int

func Max(i, j int) int {
  if XX[i] > XX[j] || (XX[i] == XX[j] && i < j) {
    return i
  }
  return j
}

func (t STree) Modify(i, value int) {
  i += len(t) / 2
  t[i] += value
  for ; i > 1; i = i >> 1 {
    t[i>>1] = Max(t[i], t[i^1])
  }
}

func (t STree) Query(aa, bb int) int {
  res := -1
  for a, b := aa+len(t)/2, bb+len(t)/2; a <= b; a, b = (a+1)>>1, (b-1)>>1 {
    if (a & 1) != 0 {
      if res == -1 {
        res = t[a]
      } else {
        res = Max(res, t[a])
      }
    }
    if (b & 1) == 0 {
      if res == -1 {
        res = t[b]
      } else {
        res = Max(res, t[b])
      }
    }
  }
  return res
}

func main() {
  n, k := ni32(), ni32()
  x, X := make([]int64, n), make([]int64, n)
  XX = make([]int64, n)
  for i := 0; i < n; i++ {
    x[i] = ni64()
    X[i] = x[i]
    if i > 0 {
      X[i] += X[i-1]
    }
  }
  for i := k - 1; i < n; i++ {
    XX[i] = X[i]
    if i >= k {
      XX[i] -= X[i-k]
    }
  }
  tree := STree(make([]int, n<<1))
  for i := 0; i < n; i++ {
    tree.Modify(i, i)
  }
  a, b, ans := -1, -1, int64(-1)
  for i := k - 1; i < n-k; i++ {
    a2, b2 := i, tree.Query(i+k, n-1)
    ans2 := XX[a2] + XX[b2]
    if ans < ans2 {
      a, b, ans = a2, b2, ans2
    }
  }
  pri32(a-k+2, b-k+2)
  endl()
  w.Flush()
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

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

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

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

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

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

type SparseTable struct {
  l     []int
  table [][]int
  data  []int64
}

func NewSparseTable(a []int64) *SparseTable {
  t := &SparseTable{}
  n := len(a)
  t.data = make([]int64, n)
  copy(t.data, a)
  t.l = make([]int, n+1)
  for i := 2; i <= n; i++ {
    t.l[i] = t.l[i>>1] + 1
  }

  t.table = make([][]int, t.l[n]+1)
  for i := 0; i < t.l[n]+1; i++ {
    t.table[i] = make([]int, n)
  }

  for i := 0; i < n; i++ {
    t.table[0][i] = i
  }

  for k := 1; (1 << uint(k)) <= n; k++ {
    for i := 0; i+(1<<uint(k)) <= n; i++ {
      x := t.table[k-1][i]
      y := t.table[k-1][i+(1<<(uint(k)-1))]
      if a[x] > a[y] || (a[x] == a[y] && x < y) {
        t.table[k][i] = x
      } else {
        t.table[k][i] = y
      }
    }
  }
  return t
}

func (t *SparseTable) Query(i, j int) int {
  k := t.l[j-i]
  x := t.table[k][i]
  y := t.table[k][j-(1<<uint(k))+1]
  if t.data[x] >= t.data[y] || (t.data[x] == t.data[y] && x < y) {
    return x
  }
  return y
}

func main() {
  n, k := ni32(), ni32()
  x, X, XX := make([]int64, n), make([]int64, n), make([]int64, n)
  for i := 0; i < n; i++ {
    x[i] = ni64()
    X[i] = x[i]
    if i > 0 {
      X[i] += X[i-1]
    }
    XX[i] = X[i]
    if i >= k {
      XX[i] -= X[i-k]
    }
  }
  t := NewSparseTable(XX)
  a, b, ans := -1, -1, int64(-1)
  for i := k - 1; i < n-k; i++ {
    cur := XX[t.Query(k-1, i)] + XX[t.Query(i+k, n-1)]
    if cur > ans {
      a, b, ans = t.Query(k-1, i), t.Query(i+k, n-1), cur
    }
  }
  pri32(a - k + 2)
  sp()
  pri32(b - k + 2)
  endl()
  w.Flush()
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

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

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

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

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

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

func main() {
  n, k := ni32(), ni32()
  x, X, XX := make([]int64, n), make([]int64, n), make([]int64, n)
  for i := 0; i < n; i++ {
    x[i] = ni64()
    X[i] = x[i]
    if i > 0 {
      X[i] += X[i-1]
    }
    XX[i] = X[i]
    if i >= k {
      XX[i] -= X[i-k]
    }
  }
  ml, mr := make([]int, n), make([]int, n)
  mr[n-1] = n - 1
  ml[k-1] = k - 1
  for i := n - 2; i >= k-1; i-- {
    if XX[i] >= XX[mr[i+1]] {
      mr[i] = i
    } else {
      mr[i] = mr[i+1]
    }
  }
  for i := k; i < n-k; i++ {
    if XX[i] > XX[ml[i-1]] {
      ml[i] = i
    } else {
      ml[i] = ml[i-1]
    }
  }
  a, b, ans := -1, -1, int64(-1)
  for i := k - 1; i < n-k; i++ {
    cur := XX[ml[i]] + XX[mr[i+k]]
    if cur > ans {
      a, b, ans = ml[i], mr[i+k], cur
    }
  }
  pri32(a - k + 2)
  sp()
  pri32(b - k + 2)
  endl()
  w.Flush()
}

// 332B-mic
package main

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

func main() {
	var n, k, i, a, b, mx, mx2, tp int64
	z := bufio.NewReader(os.Stdin)
	var mat [2000010]int64
	var pref [2000010]int64
	var sums [2000010]int64
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(z, &mat[i])
	}
	for i = 1; i <= n; i++ {
		pref[i] = pref[i-1] + mat[i-1]
	}
	for i = 0; i < n-k+1; i++ {
		sums[i] = pref[i+k] - pref[i]
	}
	for i = 0; i < n-k+1; i++ {
		if sums[i] > mx {
			mx = sums[i]
			tp = i
		}
		cur := sums[i+k] + mx
		if cur > mx2 {
			mx2 = cur
			a = tp
			b = i + k
		}
	}
	fmt.Print(a + 1)
	fmt.Print(" ")
	fmt.Print(b + 1)
	fmt.Println()
}

package main

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

var sc = NewMyScanner()

type pair struct {
	idx int
	res int64
}

func solve() (int, int) {
	n, k := sc.Int(), sc.Int()
	x := make([]int, n, n+1)
	for i := range x {
		x[i] = sc.Int()
	}
	x = append(x, 0)

	sum := func(b, e int) (s int64) {
		for ; b < e; b++ {
			s += int64(x[b])
		}
		return
	}

	d := make([]pair, n-k+1) // second pairs

	for j, curr, best := n-k, sum(n-k+1, n), (pair{}); j >= k; j-- {
		curr += int64(x[j])
		if curr >= best.res {
			best = pair{j, curr}
		}
		d[j] = best
		curr -= int64(x[j+k-1])
	}

	var best struct {
		idxa, idxb int
		sum        int64
	}
	for i, curr := 0, sum(0, k-1); i+k+k-1 < n; i++ {
		curr += int64(x[i+k-1])
		if t := curr + d[i+k].res; t > best.sum {
			best.sum = t
			best.idxa = i
			best.idxb = d[i+k].idx
		}
		curr -= int64(x[i])
	}

	return best.idxa + 1, best.idxb + 1
}

type MyScanner struct {
	*bufio.Scanner
	justScanned bool
}

func NewMyScanner() *MyScanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &MyScanner{sc, false}
}

func (sc *MyScanner) Has() bool {
	sc.justScanned = true
	return sc.Scan()
}

func (sc *MyScanner) Int() int {
	if !sc.justScanned {
		sc.Scan()
	}
	sc.justScanned = false

	x, _ := strconv.Atoi(sc.Text())
	return x
}

func (sc *MyScanner) Bool() bool {
	if !sc.justScanned {
		sc.Scan()
	}
	sc.justScanned = false

	return sc.Bytes()[0] == byte('1')
}

// sc.justScanned should be false
func (sc *MyScanner) Map2D(r, c int) [][]byte {
	m := make([][]byte, r)
	for y := range m {
		sc.Scan()
		m[y] = append(m[y], sc.Bytes()...)
	}
	return m
}

func main() {
	fmt.Println(solve())
}

package main

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

var sc = NewMyScanner()

type pair struct {
	idx int
	res int64
}

func solve() (int, int) {
	n, k := sc.Int(), sc.Int()
	x := make([]int, n)
	for i := range x {
		x[i] = sc.Int()
	}

	sum := func(b, e int) (s int64) {
		for ; b < e; b++ {
			s += int64(x[b])
		}
		return
	}

	d := make([]pair, n-k+1) // second pairs

	for j, curr, best := n-k, sum(n-k+1, n), (pair{}); j >= k; j-- {
		curr += int64(x[j])
		if curr >= best.res {
			best = pair{j, curr}
		}
		d[j] = best
		curr -= int64(x[j+k-1])
	}

	var best struct {
		idxa, idxb int
		sum        int64
	}
	for i, curr := 0, sum(0, k-1); i+k+k-1 < n; i++ {
		curr += int64(x[i+k-1])
		if t := curr + d[i+k].res; t > best.sum {
			best.sum = t
			best.idxa = i
			best.idxb = d[i+k].idx
		}
		curr -= int64(x[i])
	}

	return best.idxa + 1, best.idxb + 1
}

type MyScanner struct {
	*bufio.Scanner
	justScanned bool
}

func NewMyScanner() *MyScanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &MyScanner{sc, false}
}

func (sc *MyScanner) Has() bool {
	sc.justScanned = true
	return sc.Scan()
}

func (sc *MyScanner) Int() int {
	if !sc.justScanned {
		sc.Scan()
	}
	sc.justScanned = false

	x, _ := strconv.Atoi(sc.Text())
	return x
}

func (sc *MyScanner) Bool() bool {
	if !sc.justScanned {
		sc.Scan()
	}
	sc.justScanned = false

	return sc.Bytes()[0] == byte('1')
}

// sc.justScanned should be false
func (sc *MyScanner) Map2D(r, c int) [][]byte {
	m := make([][]byte, r)
	for y := range m {
		sc.Scan()
		m[y] = append(m[y], sc.Bytes()...)
	}
	return m
}

func main() {
	fmt.Println(solve())
}

package main

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

func main(){
	var n, k int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	var w [200005]int
	var d [200005]int64
	var b, bb, a int
	var m, z int64
	for i:=1; i<=n; i++ {
		r.Scan()
		w[i], _ = strconv.Atoi(r.Text())
	}
	for i:=1; i<=k; i++ {
		d[1] += int64(w[i])
	}
	for i:=k+1; i<=n; i++ {
		d[i-k+1] = d[i-k]-int64(w[i-k]+w[i])
	}
	for i:=n-2*k+1; i>=1; i-- {
		if int64(m) <= d[i+k] {
			m = d[i+k]
			b = i+k
		}
		if z <= m + d[i] {
			z = m+d[i]
			a = i
			bb = b
		}
	}
	wr.WriteString(strconv.Itoa(a)+" "+strconv.Itoa(bb)+"\n")
	wr.Flush()
}

package main

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

func main(){
	var n, k int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	var w [200005]int
	var d [200005]int
	var m, b, bb, a, z int
	for i:=1; i<=n; i++ {
		r.Scan()
		w[i], _ = strconv.Atoi(r.Text())
	}
	for i:=1; i<=k; i++ {
		d[1] += w[i]
	}
	for i:=k+1; i<=n; i++ {
		d[i-k+1] = d[i-k]-w[i-k]+w[i]
	}
	for i:=n-2*k+1; i>=1; i-- {
		if m<=d[i+k] {
			m = d[i+k]
			b = i+k
		}
		if z<=m+d[i] {
			z = m+d[i]
			a = i
			bb = b
		}
	}
	wr.WriteString(strconv.Itoa(a)+" "+strconv.Itoa(bb)+"\n")
	wr.Flush()
}

// 229A
package main

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

var (
	r    [10005][105]int
	a    [10005][105]string
	n, m int
)

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n, &m)
	for j := 0; j < n; j++ {
		h := false
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &a[i][j])
			if a[i][j] == string('1') {
				h = true
			}
		}
		if h == false {
			fmt.Fprintln(out, 3)
			out.Flush()
			return
		}
	}
	for j := 0; j < n; j++ {
		x := m - 1
		t := 1
		for a[x][j] != string('1') {
			t++
			x--
		}
		for i := 0; i < m; i++ {
			if a[i][j] == string('1') {
				t = 0
			}
			r[i][j] = t
			t++
		}
		x = 0
		t = 1
		for a[x][j] != string('1') {
			t++
			x++
		}
		for i := m - 1; i >= 0; i-- {
			if a[i][j] == string('1') {
				t = 0
			}
			r[i][j] = min(r[i][j], t)
			t++
		}
	}
	ans := -1
	for i := 0; i < m; i++ {
		p := 0
		for j := 0; j < n; j++ {
			p += r[i][j]
		}
		if ans == -1 || ans > p {
			ans = p
		}
	}
	fmt.Fprintln(out, ans)
	out.Flush()
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

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

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

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

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

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

var XX []int64

func GetNeutralSTValue() int { return 0 }
func GetNeutralSTDelta() int { return 0 }

func CombineSTValues(value1, value2 int) int {
  v1, v2 := value1, value2
  if XX[v1] > XX[v2] {
    return v1
  } else if XX[v1] == XX[v2] && v1 < v2 {
    return v1
  }

  return v2
}

func CombineSTDeltas(delta1, delta2 int) int {
  return delta1 + delta2
}

func CombineSTValueAndSTDelta(value int, delta int, length int) int {
  return value + delta
}

type SegmentTree struct {
  value  []int
  delta  []int
  length []int
}

func NewSegmentTree(data []int) *SegmentTree {
  tree := new(SegmentTree)
  n := len(data)
  tree.value = make([]int, n*2)
  tree.delta = make([]int, n*2)
  tree.length = make([]int, n*2)
  for i := 0; i < n; i++ {
    tree.value[i+n] = data[i]
  }
  for i := 0; i < n*2; i++ {
    tree.delta[i] = GetNeutralSTDelta()
    tree.length[i] = 1
  }
  for i := n*2 - 1; i > 1; i -= 2 {
    tree.value[i>>1] = CombineSTValues(tree.value[i], tree.value[i^1])
    tree.length[i>>1] = tree.length[i] + tree.length[i^1]
  }
  return tree
}

func (tree *SegmentTree) applySTDelta(i int, delta int) {
  tree.value[i] = CombineSTValueAndSTDelta(tree.value[i], delta, tree.length[i])
  tree.delta[i] = CombineSTDeltas(tree.delta[i], delta)
}

func (tree *SegmentTree) pushSTDelta(i int) {
  d := 0
  for ; i>>uint(d) > 0; d++ {
  }
  for d -= 2; d >= 0; d-- {
    x := i >> uint(d)
    tree.applySTDelta(x, tree.delta[x>>1])
    tree.applySTDelta(x^1, tree.delta[x>>1])
    tree.delta[x>>1] = GetNeutralSTDelta()
  }
}

func (tree *SegmentTree) Modify(a, b int, delta int) {
  a += len(tree.value) >> 1
  b += len(tree.value) >> 1
  tree.pushSTDelta(a)
  tree.pushSTDelta(b)
  ta, tb := -1, -1
  for ; a <= b; a, b = (a+1)>>1, (b-1)>>1 {
    if a&1 != 0 {
      tree.applySTDelta(a, delta)
      if ta == -1 {
        ta = a
      }
    }
    if b&1 == 0 {
      tree.applySTDelta(b, delta)
      if tb == -1 {
        tb = b
      }
    }
  }
  for i := ta; i > 1; i >>= 1 {
    tree.value[i>>1] = CombineSTValues(tree.value[i], tree.value[i^1])
  }
  for i := tb; i > 1; i >>= 1 {
    tree.value[i>>1] = CombineSTValues(tree.value[i], tree.value[i^1])
  }
}

func (tree *SegmentTree) Query(a, b int) int {
  a += len(tree.value) >> 1
  b += len(tree.value) >> 1
  tree.pushSTDelta(a)
  tree.pushSTDelta(b)
  res := GetNeutralSTValue()
  for ; a <= b; a, b = (a+1)>>1, (b-1)>>1 {
    if a&1 != 0 {
      res = CombineSTValues(res, tree.value[a])
    }
    if b&1 == 0 {
      res = CombineSTValues(res, tree.value[b])
    }
  }
  return res
}

func main() {
  n, k := ni32(), ni32()
  x, X := make([]int64, n), make([]int64, n)
  XX = make([]int64, n)
  for i := 0; i < n; i++ {
    x[i] = ni64()
    X[i] = x[i]
    if i > 0 {
      X[i] += X[i-1]
    }
  }
  for i := k - 1; i < n; i++ {
    XX[i] = X[i]
    if i >= k {
      XX[i] -= X[i-k]
    }
  }
  for i := 0; i < n; i++ {
    pri64(XX[i])
    sp()
  }
  endl()
  rang := make([]int, n)
  for i := 0; i < n; i++ {
    rang[i] = i
  }
  tree := NewSegmentTree(rang)
  a, b, ans := -1, -1, int64(-1)
  for i := k - 1; i < n-k; i++ {
    a2, b2 := i, tree.Query(i+k, n-1)
    ans2 := XX[a2] + XX[b2]
    if ans < ans2 {
      a, b, ans = a2, b2, ans2
    }
  }
  pri32(a - k + 2)
  sp()
  pri32(b - k + 2)
  endl()
  w.Flush()
}

package main

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

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token, buf   []byte
  start, end   int
}

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: 16777216,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

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

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

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

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

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

var XX []int64

func GetNeutralSTValue() int { return 0 }
func GetNeutralSTDelta() int { return 0 }

func CombineSTValues(value1, value2 int) int {
  v1, v2 := value1, value2
  if XX[v1] > XX[v2] {
    return v1
  } else if XX[v1] == XX[v2] && v1 < v2 {
    return v1
  }

  return v2
}

func CombineSTDeltas(delta1, delta2 int) int {
  return delta1 + delta2
}

func CombineSTValueAndSTDelta(value int, delta int, length int) int {
  return value + delta
}

type SegmentTree struct {
  value  []int
  delta  []int
  length []int
}

func NewSegmentTree(data []int) *SegmentTree {
  tree := new(SegmentTree)
  n := len(data)
  tree.value = make([]int, n*2)
  tree.delta = make([]int, n*2)
  tree.length = make([]int, n*2)
  for i := 0; i < n; i++ {
    tree.value[i+n] = data[i]
  }
  for i := 0; i < n*2; i++ {
    tree.delta[i] = GetNeutralSTDelta()
    tree.length[i] = 1
  }
  for i := n*2 - 1; i > 1; i -= 2 {
    tree.value[i>>1] = CombineSTValues(tree.value[i], tree.value[i^1])
    tree.length[i>>1] = tree.length[i] + tree.length[i^1]
  }
  return tree
}

func (tree *SegmentTree) applySTDelta(i int, delta int) {
  tree.value[i] = CombineSTValueAndSTDelta(tree.value[i], delta, tree.length[i])
  tree.delta[i] = CombineSTDeltas(tree.delta[i], delta)
}

func (tree *SegmentTree) pushSTDelta(i int) {
  d := 0
  for ; i>>uint(d) > 0; d++ {
  }
  for d -= 2; d >= 0; d-- {
    x := i >> uint(d)
    tree.applySTDelta(x, tree.delta[x>>1])
    tree.applySTDelta(x^1, tree.delta[x>>1])
    tree.delta[x>>1] = GetNeutralSTDelta()
  }
}

func (tree *SegmentTree) Modify(a, b int, delta int) {
  a += len(tree.value) >> 1
  b += len(tree.value) >> 1
  tree.pushSTDelta(a)
  tree.pushSTDelta(b)
  ta, tb := -1, -1
  for ; a <= b; a, b = (a+1)>>1, (b-1)>>1 {
    if a&1 != 0 {
      tree.applySTDelta(a, delta)
      if ta == -1 {
        ta = a
      }
    }
    if b&1 == 0 {
      tree.applySTDelta(b, delta)
      if tb == -1 {
        tb = b
      }
    }
  }
  for i := ta; i > 1; i >>= 1 {
    tree.value[i>>1] = CombineSTValues(tree.value[i], tree.value[i^1])
  }
  for i := tb; i > 1; i >>= 1 {
    tree.value[i>>1] = CombineSTValues(tree.value[i], tree.value[i^1])
  }
}

func (tree *SegmentTree) Query(a, b int) int {
  a += len(tree.value) >> 1
  b += len(tree.value) >> 1
  tree.pushSTDelta(a)
  tree.pushSTDelta(b)
  res := GetNeutralSTValue()
  for ; a <= b; a, b = (a+1)>>1, (b-1)>>1 {
    if a&1 != 0 {
      res = CombineSTValues(res, tree.value[a])
    }
    if b&1 == 0 {
      res = CombineSTValues(res, tree.value[b])
    }
  }
  return res
}

func main() {
  n, k := ni32(), ni32()
  x, X := make([]int64, n), make([]int64, n)
  XX = make([]int64, n)
  for i := 0; i < n; i++ {
    x[i] = ni64()
    X[i] = x[i]
    if i > 0 {
      X[i] += X[i-1]
    }
  }
  for i := k - 1; i < n; i++ {
    XX[i] = X[i]
    if i >= k {
      XX[i] -= X[i-k]
    }
  }
  rang := make([]int, n)
  for i := 0; i < n; i++ {
    rang[i] = i
  }
  tree := NewSegmentTree(rang)
  a, b, ans := -1, -1, int64(-1)
  for i := k - 1; i < n-k; i++ {
    a2, b2 := i, tree.Query(i+k, n-1)
    ans2 := XX[a2] + XX[b2]
    if ans < ans2 {
      a, b, ans = a2, b2, ans2
    }
  }
  pri32(a - k + 2)
  sp()
  pri32(b - k + 2)
  endl()
  w.Flush()
}

// 332B-mic
package main

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

func main() {
	var n, k, i int
	z := bufio.NewReader(os.Stdin)
	var mat [2000010]int
	var pref [2000010]int
	var sums [2000010]int
	fmt.Scan(&n, &k)
	for i = 0; i < n; i++ {
		fmt.Fscan(z, &mat[i])
	}
	for i = 1; i <= n; i++ {
		pref[i] = pref[i-1] + mat[i-1]
	}
	for i = 0; i < n-k+1; i++ {
		sums[i] = pref[i+k] - pref[i]
	}
	mx := 0
	var a, b int
	mx2 := 0
	tp := 0
	for i = 0; i < n-k+1; i++ {
		if sums[i] > mx {
			mx = sums[i]
			tp = i
		}
		cur := sums[i+k] + mx
		if cur > mx2 {
			mx2 = cur
			a = tp
			b = i + k
		}
	}
	fmt.Print(a + 1)
	fmt.Print(" ")
	fmt.Print(b + 1)
	fmt.Println()
}


You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.To cyclically shift a table row one cell to the right means to move the value of each cell, except for the last one, to the right neighboring cell, and to move the value of the last cell to the first cell. A cyclical shift of a row to the left is performed similarly, but in the other direction. For example, if we cyclically shift a row "00110" one cell to the right, we get a row "00011", but if we shift a row "00110" one cell to the left, we get a row "01100".Determine the minimum number of moves needed to make some table column consist only of numbers 1.

The first line contains two space-separated integers: n (1 ≤ n ≤ 100) — the number of rows in the table and m (1 ≤ m ≤ 104) — the number of columns in the table. Then n lines follow, each of them contains m characters "0" or "1": the j-th character of the i-th line describes the contents of the cell in the i-th row and in the j-th column of the table. It is guaranteed that the description of the table contains no other characters besides "0" and "1".

Print a single number: the minimum number of moves needed to get only numbers 1 in some column of the table. If this is impossible, print -1.

NoteIn the first sample one way to achieve the goal with the least number of moves is as follows: cyclically shift the second row to the right once, then shift the third row to the left twice. Then the table column before the last one will contain only 1s.In the second sample one can't shift the rows to get a column containing only 1s.

package main

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

func main() {
    min := func(a,b int) int { if a < b { return a } else { return b } }
    reader := bufio.NewReader(os.Stdin)
    var n,m,ans int
    var d [105][10005]int
    var s string
    fmt.Scan(&n,&m)
    for i := 0; i < n; i++ {
        fmt.Fscan(reader,&s)
        ok, p, cnt := false, 0, 0
        for k, v := range s {
            if v == '1' {
                ok = true
                p = k
                break
            }
        }
        if ok {
            for j := 0; j < m; j++ {
                if s[(p+j)%m] == '1' {
                    cnt = 0
                } else {
                    cnt++
                }
                d[i][(p+j)%m] = cnt
            }
            for j := m; j > 0; j-- {
                if s[(p+j)%m] == '1' {
                    cnt = 0
                } else {
                    cnt++
                }
                d[i][(p+j)%m] = min(d[i][(p+j)%m],cnt)
            }
        } else {
            ans = -1
        }
    }
    if ans != -1 {
        ans = 1000000000
        for j := 0; j < m; j++ {
            tmp := 0
            for i := 0; i < n; i++ {
                tmp += d[i][j]
            }
            ans = min(ans,tmp)
        }
    }
    fmt.Println(ans)
}


Two players play a game.Initially there are $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $$$n - 1$$$ turns are made. The first player makes the first move, then players alternate turns.The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.You want to know what number will be left on the board after $$$n - 1$$$ turns if both players make optimal moves.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of numbers on the board. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^6$$$).

NoteIn the first sample, the first player erases $$$3$$$ and the second erases $$$1$$$. $$$2$$$ is left on the board.In the second sample, $$$2$$$ is left on the board regardless of the actions of the players.

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i, _ := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	fmt.Println(a[n / 2 - (1 - n % 2)])
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var d = make([]int, n)

	for i := 0; i < n; i++ {
		var s int
		fmt.Scan(&s)
		d[i] = s
	}
	sort.Ints(d)

	for i:=0; i< n-1; i++ {
		if i %2 == 1 {
			d = d[1:n-i]
			continue
		}
		d = d[0:n - i -1]
	}

	fmt.Print(d[0])
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	if len(a) % 2 == 0 {
		fmt.Println(a[n/2-1])
		return
	}
	fmt.Println(a[n/2])
	return
}

// A. Game
/*
Two players play a game.

Initially there are 𝑛 integers 𝑎1,𝑎2,…,𝑎𝑛 written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. 𝑛−1 turns are made. The first player makes the first move, then players alternate turns.

The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it.

You want to know what number will be left on the board after 𝑛−1 turns if both players make optimal moves.

Input
The first line contains one integer 𝑛 (1≤𝑛≤1000) — the number of numbers on the board.

The second line contains 𝑛 integers 𝑎1,𝑎2,…,𝑎𝑛 (1≤𝑎𝑖≤106).

Output
Print one number that will be left on the board.

Examples
Input
3
2 1 3

Output
2

Input
3
2 2 2

Output
2

Note
In the first sample, the first player erases 3 and the second erases 1. 2 is left on the board.

In the second sample, 2 is left on the board regardless of the actions of the players.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

	input2, _ := reader.ReadString('\n')
	arr := strings.Split(strings.TrimSpace(input2), " ")

	intArr := []int{}
	for _, v := range arr {
		i, _ := strconv.Atoi(v)
		intArr = append(intArr, i)
	}

	sort.Ints(intArr)

	if n%2 != 0 {
		fmt.Print(intArr[(n-1)/2])
	} else {
		fmt.Print(intArr[(n/2)-1])
	}
}

package main

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

func toArrayInt (str[] string)[] int{
  var arrint[]int
  for _, val := range str {
    j,_ := strconv.Atoi(val)
    arrint = append(arrint, j)
  }
  return arrint
}

func main(){
  var n int
  index := 0
  reader := bufio.NewReader(os.Stdin)
  fmt.Scanf("%d\n", &n)

  input,_ := reader.ReadString('\r')

  s := strings.TrimRight(input, "\n")
  arrs := strings.Fields(s)
  var arr[] int
  arr = toArrayInt(arrs)
  sort.Ints(arr)

  for i := 0 ; i < n-1 ; i++{
    if i % 2 == 0 {
      arr = arr[:len(arr)-1]

    } else{
      copy(arr[index:], arr[index+1:])
      arr[len(arr)-1] = 0
      arr = arr[:len(arr)-1]
    }
  }

    //fmt.Println(arr)
    fmt.Println(strings.Trim(fmt.Sprint(arr), "[]"))

}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scanln(&n)
	lev := make([]int, n)
	for i := range lev {
		fmt.Scan(&lev[i])
	}
	sort.Sort(sort.IntSlice(lev))

	for i := 0; i < n-1; i++ {
		if i%2 == 0 {
			lev = lev[:len(lev)-1]
		} else {
			lev = lev[1:]
		}
	}
	ans := lev[0]
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n)
	var m []int = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&m[i])
	}
	sort.Ints(m)
	if n%2 == 0 {
		k = int(n/2) - 1
	} else {
		k = int(n / 2)
	}
	fmt.Println(m[k])
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	fmt.Println(a[(n-1)/2])
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int64

	fmt.Scan(&n)

	var a, _ = ScanN(n)

	sort.SliceStable(a, func(i, j int) bool {
		return a[i] < a[j]
	})

	if len(a)%2 == 1 {
		fmt.Println(a[len(a)/2])
	} else {
		fmt.Println(a[len(a)/2-1])
	}
}

func ScanN(n int64) ([]int64, error) {
	in := make([]int64, n)
	for i := range in {
		_, err := fmt.Scan(&in[i])
		if err != nil {
			return in[:i], err
		}
	}
	return in, nil
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Scan()
	ss := strings.Split(sc.Text(), " ")
	ns := make([]int, len(ss))
	for i, s := range ss {
		n, _ := strconv.Atoi(s)
		ns[i] = n
	}
	sort.Ints(ns)
	l := len(ns)
	if l%2 == 0 {
		fmt.Println(ns[l/2-1])
		return
	}
	fmt.Println(ns[l/2])
}

package main

import (
	"fmt"
	"sort"
)

func main(){
	var n int
	fmt.Scan(&n)
	a := make([]int,n)
	readN(a,0,n)
	sort.Ints(a)
	var out int
	if n%2==0{
		out = a[(n/2)-1]
	}else {
		out = a[n/2]
	}
	fmt.Println(out)
}

func readN(all []int,i,n int){
	if n==0{
		return
	}
	if m,err := fmt.Scan(&all[i]);m!=1{
		panic(err)
	}
	readN(all,i+1,n-1)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	arr := make([]int, 0, n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		arr = append(arr, a)
	}
	sort.Ints(arr)
	//fmt.Print(arr)
	if n%2 == 1 {
		fmt.Print(arr[n/2])
	} else {
		fmt.Print(arr[n/2-1])
	}
}

package main

import (
	"fmt"
	"sort"
)

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func main() {
	var n int
	fmt.Scan(&n)
	var save = make([]int, n)
	for i := range save {
		fmt.Scan(&save[i])
	}

	sort.Ints(save)
	// fmt.Println(save)
	if len(save)%2 == 0 {
		fmt.Println(save[len(save)/2-1])
	} else {
		fmt.Println(save[len(save)/2])
	}
}

package main

import (
    "fmt"
    "sort"
)

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

    var ns = make([]int, n)
    for i := range ns {
        fmt.Scan(&ns[i])
    }

    sort.Ints(ns)

    if len(ns) % 2 == 0 {
        fmt.Println(ns[len(ns) / 2 - 1])
    } else {
        fmt.Println(ns[len(ns) / 2])
    }
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int64

	fmt.Scanln(&n)

	a := make([]int64, n)

	for i := int64(0); i < n; i++ {
		fmt.Scan(&a[i])
	}

	res := Solve(a)

	fmt.Println(res)
}

func Solve(input []int64) int64 {
	sort.Slice(input, func(i, j int) bool {
		return input[i] < input[j]
	})

	i := len(input) - len(input)/2 - 1

	return input[i]
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	i := 0
	j := 0

	a := []int {}

	var n int

	fmt.Scan(&n)

	for i = 0 ; i < n ; i ++ {
		var here int
		fmt.Scan(&here)
		a = append(a, here)
	}

	sort.Ints(a)

	i = 0
	j = n - 1

	cnt := 0

	for cnt < n - 1 {
		if cnt % 2 == 0 {
			j --
		} else {
			i ++
		}
		cnt ++
	}

	fmt.Println(a[i])
}

package main

import ("fmt"
		"sort"
)

func main(){
	n:=0
	fmt.Scanln(&n)

	num:=make([]int,n)
	for i:=0;i<n;i++{
		fmt.Scanf("%d",&num[i])
	}
	sort.Ints(num)
	if n%2==0 {
		fmt.Println(num[(n/2)-1])
	}else{
		fmt.Println(num[(n/2)])
	}

}

package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scanf("%d", &n)
    var nums = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&nums[i])
    }
    sort.Ints(nums)
    var back, front int
    back = n-1
    front = 0
    var flip bool = true

    for back != front {
        if(flip){
            back = back - 1

        }else {
            front = front + 1
        }
        flip = !flip
    }
    fmt.Printf("%d", nums[back])
}

package main

import (
	"fmt"
  "sort"
)

func main() {
	var n int
  	var res[] int
	fmt.Scanln(&n)
	for i:=0;i<n;i++{
    	var x int
		fmt.Scanf("%d",&x)
    	res=append(res,x)
	}
  	sort.Ints(res)
  	for i:=1;i<n;i++{
    if i%2==0{
      res = res[1:len(res)]
    }else{
      res = res[:len(res)-1]
    }
	}
  	fmt.Print(res[len(res)-1])
}

package main

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

func main() {
	var line string
	var n int
	var tmp int64
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	n, _ = strconv.Atoi(arrStartStrings[0])
	line, _ = reader.ReadString('\n')
	arrStartStrings = strings.Split(strings.TrimSpace(line), " ")
	arr := make([]int, n)
	for i, v := range arrStartStrings {
		tmp, _ = strconv.ParseInt(v, 10, 64)
		arr[i] = int(tmp)
	}
	sort.Ints(arr)
	if n%2==0{
		fmt.Println(arr[n/2-1])
	} else {
		fmt.Println(arr[n/2])
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math/rand"
	"os"
)

const INF  = 1000000001

type Pair struct {
	first, second int
}

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

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func solution(reader io.Reader, writer io.Writer) {
	var n int
	fmt.Fscanf(reader, "%d\n", &n)

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

	a = sort(a)

	fmt.Fprintf(writer, "%d", a[(n - 1) / 2])

}

func main() {

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

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

	solution(reader, writer)
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	var n int
	fmt.Scanf("%d", &n)
	var inp [1001]int
	for i := 0; i < n; i++ {
		fmt.Scan(&inp[i])
	}
	var a []int = inp[0:n]
	sort.Ints(a)

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

}

package main

import (
	"fmt"
	"sort"
)
func main() {
	var num int
	fmt.Scan(&num)
	sl := make([]int, num, num)
	for i := 0; i < num; i++{
		fmt.Scan(&sl[i])
	}
	sort.Ints(sl)
	if num % 2 == 0{
		fmt.Println(sl[num / 2 - 1])
	} else {
		fmt.Println(sl[num / 2])
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i, _ := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)
	fmt.Println(a[n / 2])
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	var d = make([]int, n)

	for i := 0; i < n; i++ {
		var s int
		fmt.Scan(&s)
		d[i] = s
	}
	sort.Ints(d)

	for i:=0; i< n-1; i++ {
		if i %2 == 0 {
			d = d[1:n-i]
			continue
		}
		d = d[0:n - i -1]
	}

	fmt.Print(d[0])
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	lb, _, _ := r.ReadLine()
	l, _ := strconv.Atoi(string(lb))
	nst, _, _ := r.ReadLine()
	ns := strings.Split(string(nst), " ")
	arr := make([]int, 0, l)
	for _, s := range ns {
		n, _ := strconv.Atoi(s)
		arr = append(arr, n)
	}
	sort.Ints(arr)
	if len(arr) % 2 == 0 {
		fmt.Println(arr[len(arr)/2-1])
		return
	}
	fmt.Println(arr[len(arr)/2])
	return
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	lstr, _ := r.ReadString('\n')
	nstr, _ := r.ReadString('\n')
	l, _ := strconv.Atoi(lstr)
	ns := strings.Split(nstr, " ")
	arr := make([]int, l)
	for _, str := range ns {
		n, _ := strconv.Atoi(str)
		arr = append(arr, n)
	}
	sort.Ints(arr)
	for len(arr) >= 3 {
		arr = arr[:len(arr)-1]
		arr = arr[1:len(arr)]
	}
	fmt.Println(arr[0])
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	lstr, _ := r.ReadString('\n')
	lstr = strings.Replace(lstr, "\n", "", -1)
	l, _ := strconv.Atoi(lstr)
	nstr, _ := r.ReadString('\n')
	nstr = strings.Replace(nstr, "\n", "", -1)
	ns := strings.Split(nstr, " ")
	arr := make([]int, 0, l)
	for _, s := range ns {
		n, _ := strconv.Atoi(s)
		arr = append(arr, n)
	}
	sort.Ints(arr)
	for len(arr) >= 3 {
		arr = arr[:len(arr)-1]
		arr = arr[1:len(arr)]
	}
	fmt.Println(arr[0])
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	lb, _, _ := r.ReadLine()
	l, _ := strconv.Atoi(string(lb))
	nst, _, _ := r.ReadLine()
	ns := strings.Split(string(nst), " ")
	arr := make([]int, 0, l)
	for _, s := range ns {
		n, _ := strconv.Atoi(s)
		arr = append(arr, n)
	}
	sort.Ints(arr)
	for len(arr) >= 3 {
		arr = arr[:len(arr)-1]
		arr = arr[1:len(arr)]
	}
	fmt.Println(arr[0])
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	ls, _ := r.ReadString('\n')
	ls = strings.Replace(ls, "\n", "", -1)
	l, _ := strconv.Atoi(ls)
	nst, _ := r.ReadString('\n')
	nst = strings.Replace(nst, "\n", "", -1)
	ns := strings.Split(nst, " ")
	arr := make([]int, 0, l)
	for _, s := range ns {
		n, _ := strconv.Atoi(s)
		arr = append(arr, n)
	}
	sort.Ints(arr)
	for len(arr) >= 3 {
		arr = arr[:len(arr)-1]
		arr = arr[1:len(arr)]
	}
	fmt.Println(arr[0])
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	lb, _, _ := r.ReadLine()
	l, _ := strconv.Atoi(string(lb))
	nst, _, _ := r.ReadLine()
	ns := strings.Split(string(nst), " ")
	arr := make([]int, 0, l)
	for _, s := range ns {
		n, _ := strconv.Atoi(s)
		arr = append(arr, n)
	}
	sort.Ints(arr)
	for len(arr) > 1 {
		arr = arr[:len(arr)-1]
		if len(arr) > 1 {
			arr = arr[1:len(arr)]
		}
	}
	fmt.Println(arr[0])
	return
}

package main

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

func main() {
	var l int
	fmt.Scanf("%d\n", &l)
	var nst string
	fmt.Scanf("%s\n", &nst)
	ns := strings.Split(nst, " ")
	arr := make([]int, 0, l)
	for _, s := range ns {
		n, _ := strconv.Atoi(s)
		arr = append(arr, n)
	}
	sort.Ints(arr)
	for len(arr) >= 3 {
		arr = arr[:len(arr)-1]
		arr = arr[1:len(arr)]
	}
	fmt.Println(arr[0])
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Scan()
	ss := strings.Split(sc.Text(), " ")
	ns := make([]int, len(ss))
	for i, s := range ss {
		n, _ := strconv.Atoi(s)
		ns[i] = n
	}
	sort.Ints(ns)
	l := len(ns)
	fmt.Println(ns)
	if l%2 == 0 {
		fmt.Println(ns[l/2-1])
		return
	}
	fmt.Println(ns[l/2])
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	sc.Scan()
	ss := strings.Split(sc.Text(), " ")
	ns := make([]int, len(ss))
	for i, s := range ss {
		n, _ := strconv.Atoi(s)
		ns[i] = n
	}
	sort.Ints(ns)
	l := len(ns)
	if l%2 == 0 {
		fmt.Println()
		return
	}
	fmt.Println(ns[l/2])
}

package main

import (
	"fmt"
	"sort"
)

func main(){
	var n int
	fmt.Scan(&n)
	a := make([]int,n)
	readN(a,0,n)
	sort.Ints(a)
	fmt.Println(a[len(a)/2])
}

func readN(all []int,i,n int){
	if n==0{
		return
	}
	if m,err := fmt.Scan(&all[i]);m!=1{
		panic(err)
	}
	readN(all,i+1,n-1)
}

package main

import (
	"fmt"
	"sort"
)

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func main() {
	var n int
	fmt.Scan(&n)
	var save = make([]int, n)
	for i := range save {
		fmt.Scan(&save[i])
	}

	sort.Ints(save)
	if len(save)%2 == 0 {
		fmt.Println(save[len(save)/2] - 1)
	} else {
		fmt.Println(save[len(save)/2])
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int64

	fmt.Scanln(&n)

	a := make([]int64, n)

	for i := int64(0); i < n; i++ {
		fmt.Scan(&a[i])
	}

	res := Solve(a)

	fmt.Println(res)
}

func Solve(input []int64) int64 {
	sort.Slice(input, func(i, j int) bool {
		return input[i] < input[j]
	})

	fmt.Println(input)

	i := len(input) - len(input)/2 - 1

	return input[i]
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int64

	fmt.Scanln(&n)

	a := make([]int64, n)

	for i := int64(0); i < n; i++ {
		fmt.Scan(&a[i])
	}

	res := Solve(a)

	fmt.Println(res)
}

func Solve(input []int64) int64 {
	sort.Slice(input, func(i, j int) bool {
		return input[i] < input[j]
	})

	i := len(input) / 2

	return input[i]
}

package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scanf("%d\n", &n)
    var nums = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &nums[i])
    }
    sort.Ints(nums)
    var back, front int
    back = n-1
    front = 0
    var flip bool = true

    for back != front {
        if(flip){
            back = back - 1

        }else {
            front = front + 1
        }
        flip = !flip
    }
    fmt.Println(nums, back, front)
    fmt.Printf("%d", nums[back])
}

package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scanf("%d", &n)
    var nums = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", nums[i])
    }
    sort.Ints(nums)
    var back, front int
    back = n-1
    front = 0
    var flip bool = true

    for back != front {
        if(flip){
            back = back - 1

        }else {
            front = front + 1
        }
        flip = !flip
    }
    fmt.Printf("%d", nums[back])
}

package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scanf("%d", &n)
    var nums = make([]int, n)
    for i := 0; i < n; i++ {
        var num int
        fmt.Scanf("%d", &num)
        nums[i] = num
    }
    sort.Ints(nums)
    var back, front int
    back = n-1
    front = 0
    var flip bool = true

    for back != front {
        if(flip){
            back = back - 1

        }else {
            front = front + 1
        }
        flip = !flip
    }
    fmt.Println(nums, back, front)
    fmt.Printf("%d", nums[back])
}

package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scanf("%d", &n)
    var nums = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &nums[i])
    }
    sort.Ints(nums)
    var back, front int
    back = n-1
    front = 0
    var flip bool = true

    for back != front {
        if(flip){
            back = back - 1

        }else {
            front = front + 1
        }
        flip = !flip
    }
    fmt.Printf("%d", nums[back])
}

package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scanf("%d", &n)
    var nums = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&nums[i])
    }
    sort.Ints(nums)
    var back, front int
    back = n-1
    front = 0
    var flip bool = true

    for back != front {
        if(flip){
            back = back - 1

        }else {
            front = front + 1
        }
        flip = !flip
    }
    fmt.Println(nums, back, front)
    fmt.Printf("%d", nums[back])
}

package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scanf("%d", &n)
    var nums = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", &nums[i])
    }
    sort.Ints(nums)
    var back, front int
    back = n-1
    front = 0
    var flip bool = true

    for back != front {
        if(flip){
            back = back - 1

        }else {
            front = front + 1
        }
        flip = !flip
    }
    fmt.Println(nums, back, front)
    fmt.Printf("%d", nums[back])
}

package main

import "fmt"
import "sort"

func main() {
    var n int
    fmt.Scanf("%d", &n)
    var nums = make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scanf("%d", nums[i])
    }
    sort.Ints(nums)
    var back, front int
    back = n-1
    front = 0
    var flip bool = true

    for back != front {
        if(flip){
            back = back - 1

        }else {
            front = front + 1
        }
        flip = !flip
    }
    fmt.Println(nums, back, front)
    fmt.Printf("%d", nums[back])
}

package main

import (
	"fmt"
  "sort"
)

func main() {
	var n int
  	var res[] int
	fmt.Scanln(&n)
	for i:=0;i<n;i++{
    	var x int
		fmt.Scanf("%d",&x)
    	res=append(res,x)
	}
  	sort.Ints(res)
  	for i:=1;i<n;i++{
    if i%2==1{
      res = res[1:len(res)]
    }else{
      res = res[:len(res)-1]
    }
	}
  	fmt.Print(res[len(res)-1])
}

package main

import (
	"fmt"
  "sort"
)

func main() {
	var n int
  var res[] int
	fmt.Scanf("%d",&n)
	for i:=0;i<n;i++{
    var x int
    fmt.Scanf("%d",&x)
    res=append(res,x)
	}
  sort.Ints(res)
  for i:=1;i<n;i++{
    if i%2==1{
      res = res[1:len(res)]
    }else{
      res = res[:len(res)-1]
    }
	}
  fmt.Print(res[len(res)-1])
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var num int
	fmt.Scan(&num)
	sl := make([]int, num, num)
	for i := 0; i < num; i++{
		fmt.Scan(&sl[i])
	}
	sort.Ints(sl)
	fmt.Println(sl[num / 2])
}


"You must lift the dam. With a lever. I will give it to you.You must block the canal. With a rock. I will not give the rock to you." Danik urgently needs rock and lever! Obviously, the easiest way to get these things is to ask Hermit Lizard for them.Hermit Lizard agreed to give Danik the lever. But to get a stone, Danik needs to solve the following task.You are given a positive integer $$$n$$$, and an array $$$a$$$ of positive integers. The task is to calculate the number of such pairs $$$(i,j)$$$ that $$$i<j$$$ and $$$a_i$$$ $$$\&$$$ $$$a_j \ge a_i \oplus a_j$$$, where $$$\&$$$ denotes the bitwise AND operation, and $$$\oplus$$$ denotes the bitwise XOR operation.Danik has solved this task. But can you solve it?

Each test contains multiple test cases. The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 10$$$) denoting the number of test cases. Description of the test cases follows. The first line of each test case contains one positive integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — length of the array. The second line contains $$$n$$$ positive integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For every test case print one non-negative integer — the answer to the problem.

NoteIn the first test case there is only one pair: $$$(4,7)$$$: for it $$$4$$$ $$$\&$$$ $$$7 = 4$$$, and $$$4 \oplus 7 = 3$$$.In the second test case all pairs are good.In the third test case there are two pairs: $$$(6,5)$$$ and $$$(2,3)$$$.In the fourth test case there are no good pairs.

package main

import (
	"bufio"
	"fmt"
	"log"
	"math/bits"
	"os"
)

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

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

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

func solve() {
	n := nextInt()
	count := make([]int64, 128)
	for i := 0; i < n; i++ {
		count[bits.LeadingZeros(uint(nextInt()))]++
	}

	var res int64 = 0
	for _, v := range count {
		res += v * (v - 1) / 2
	}
	printf("%d\n", res)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "in"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create(name + ".out")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

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

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

	for o := 0; o < t; o++ {
		var (
			n int
			x float64
			a = make([]int, 32)
			ans int64
		)
		fmt.Fscan(in, &n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &x)
			a[int(math.Log2(x))]++
		}
		for i := 0; i < 32; i++ {
			ans += int64(a[i]) * int64(a[i] - 1) / int64(2)
		}
		fmt.Println(ans)

	}

}

package main

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

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

	tc := readNum(reader)
	var buf bytes.Buffer
	for tc > 0 {
		tc--
		n := readNum(reader)
		A := readNNums(reader, n)
		res := solve(n, A)
		buf.WriteString(fmt.Sprintf("%d\n", res))
	}
	fmt.Print(buf.String())
}

func solve(n int, A []int) int64 {
	cnt := make([]int, 30)
	var res int64
	for i := 0; i < n; i++ {
		var p = -1
		num := A[i]
		for j := 0; j < 30 && num > 0; j++ {
			if num&1 == 1 {
				p = j
			}
			num >>= 1
		}
		res += int64(cnt[p])
		cnt[p]++
	}

	return res
}

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

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

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

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

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

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

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

	return i
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for t := in(); t > 0 ; t-- {
		n := in()

		a := make([]int64, n)

		for i := range a {
			a[i] = in()
		}

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

		v := int64(2)

		num := int64(0)

		cnt := int64(0)

		for i := range a {
			if a[i] < v {
				cnt++
			} else {
				num += (cnt * (cnt - 1)) / 2
				cnt = 1
				for a[i] >= v {
					v *= 2
				}
			}
		}

		num += (cnt * (cnt - 1)) / 2

		fmt.Println(num)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		var a []int = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		m := map[int]int{}
		for j := 0; j < n; j++ {
			size := int(math.Log2(float64(a[j])))
			m[size]++
		}
		total := int64(0)
		for _, count := range m {
			total += int64(count) * int64((count - 1)) / 2
		}
		fmt.Println(total)
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

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

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

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

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

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

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

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

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

func sol(n int64, a []int64) int64 {
	bmap := map[int64]int64{}
	ret := int64(0)
	for i := range a {
		bits := countBits(a[i])
		ret += bmap[bits]
		bmap[bits]++
	}
	return ret
}

func countBits(n int64) int64 {
	ret := int64(0)
	for n > 0 {
		ret++
		n >>= 1
	}
	return ret
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		var a []int = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		m := map[int]int{}
		for j := 0; j < n; j++ {
			size := 0
			for ; a[j] > 0; a[j] = a[j] >> 1 {
				size++
			}
			if _, exist := m[size]; exist {
				m[size]++
			} else {
				m[size] = 1
			}
		}
		total := 0
		for _, count := range m {
			total += count * (count - 1) / 2
		}
		fmt.Println(total)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		var a []int = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		m := map[int]int{}
		for j := 0; j < n; j++ {
			size := int(math.Log2(float64(a[j])))
			m[size]++
		}
		total := int64(0)
		for _, count := range m {
			total += int64(count * (count - 1) / 2)
		}
		fmt.Println(total)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		var a []int = make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		m := map[int]int{}
		for j := 0; j < n; j++ {
			size := int(math.Log2(float64(a[j])))
			if _, exist := m[size]; exist {
				m[size]++
			} else {
				m[size] = 1
			}
		}
		total := 0
		for _, count := range m {
			total += count * (count - 1) / 2
		}
		fmt.Println(total)
	}
}


Berland has managed to repel the flatlanders' attack and is now starting the counter attack.Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between cities if and only if there is in fact no road between this pair of cities (we do not know whether is it a clever spy-proof strategy or just saving ink). In other words, if two cities are connected by a road on a flatland map, then there is in fact no road between them. The opposite situation is also true: if two cities are not connected by a road on a flatland map, then in fact, there is a road between them.The berlanders got hold of a flatland map. Now Vasya the Corporal is commissioned by General Touristov to find all such groups of flatland cities, that in each group of cities you can get from any city to any other one, moving along the actual roads. Also the cities from different groups are unreachable from each other, moving along the actual roads. Indeed, destroying such groups one by one is much easier than surrounding all Flatland at once!Help the corporal complete this task and finally become a sergeant! Don't forget that a flatland map shows a road between cities if and only if there is in fact no road between them.

The first line contains two space-separated integers n and m (1 ≤ n ≤ 5·105, 0 ≤ m ≤ 106) — the number of cities and the number of roads marked on the flatland map, correspondingly. Next m lines contain descriptions of the cities on the map. The i-th line contains two integers ai and bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — the numbers of cities that are connected by the i-th road on the flatland map. It is guaranteed that each pair of cities occurs in the input no more than once.

On the first line print number k — the number of groups of cities in Flatland, such that in each group you can get from any city to any other one by flatland roads. At the same time, the cities from different groups should be unreachable by flatland roads. On each of the following k lines first print ti (1 ≤ ti ≤ n) — the number of vertexes in the i-th group. Then print space-separated numbers of cities in the i-th group. The order of printing groups and the order of printing numbers in the groups does not matter. The total sum ti for all k groups must equal n.

NoteIn the first sample there are roads only between pairs of cities 1-4 and 2-3.In the second sample there is no road between cities 1 and 2, but still you can get from one city to the other one through city number 3.

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol190E(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

	n, m := read(), read()
	g := make([][]int, n)
	for ; m > 0; m-- {
		v, w := read()-1, read()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprintln(out, n)
		for i := 1; i <= n; i++ {
			Fprintln(out, 1, i)
		}
		return
	}

	merge0 := func(v int, edges []int) {
		sort.Ints(edges)
		j := 0
		for i := 0; i < n; i++ {
			if i == v {
				continue
			}
			if j == len(edges) || i < edges[j] {
				merge(i, v)
			} else {
				j++
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	vs := map[int]bool{maxDeg0V: true}
	for _, w := range g[maxDeg0V] {
		vs[w] = true
	}
	for v, edges := range g {
		if same(v, maxDeg0V) {
			continue
		}
		cnt := 1
		for _, w := range edges {
			if !vs[w] {
				cnt++
			}
		}
		if cnt < n-len(g[maxDeg0V]) {
			merge(v, maxDeg0V)
		} else {
			merge0(v, edges)
		}
	}

	cnt := map[int][]interface{}{}
	for i := range fa {
		cnt[find(i)] = append(cnt[find(i)], i+1)
	}
	Fprintln(out, len(cnt))
	for _, vs := range cnt {
		Fprint(out, len(vs), " ")
		Fprintln(out, vs...)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol190E(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

	n, m := read(), read()
	g := make([][]int, n)
	for ; m > 0; m-- {
		v, w := read()-1, read()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprintln(out, n)
		for i := 1; i <= n; i++ {
			Fprintln(out, 1, i)
		}
		return
	}

	merge0 := func(v int, edges []int) {
		vs := map[int]bool{v: true}
		for _, w := range edges {
			vs[w] = true
		}
		for i := 0; i < n; i++ {
			if !vs[i] {
				merge(i, v)
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	for v, edges := range g {
		if !same(v, maxDeg0V) {
			merge0(v, edges)
		}
	}

	cnt := map[int][]interface{}{}
	for i := range fa {
		v := find(i)
		cnt[v] = append(cnt[v], i+1)
	}
	Fprintln(out, len(cnt))
	for _, vs := range cnt {
		Fprint(out, len(vs), " ")
		Fprintln(out, vs...)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol190E(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

	n, m := read(), read()
	g := make([][]int, n)
	for ; m > 0; m-- {
		v, w := read()-1, read()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprintln(out, n)
		for i := 1; i <= n; i++ {
			Fprintln(out, 1, i)
		}
		return
	}

	merge0 := func(v int, edges []int) {
		sort.Ints(edges)
		j := 0
		for i := 0; i < n; i++ {
			if i == v {
				continue
			}
			if j == len(edges) || i < edges[j] {
				merge(i, v)
			} else {
				j++
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	vs := map[int]bool{maxDeg0V: true}
	for _, w := range g[maxDeg0V] {
		vs[w] = true
	}
	for v, edges := range g {
		if same(v, maxDeg0V) {
			continue
		}
		cnt := 1
		for _, w := range edges {
			if !vs[w] {
				cnt++
			}
		}
		if cnt < n-len(g[maxDeg0V]) {
			merge(v, maxDeg0V)
		} else {
			merge0(v, edges)
		}
	}

	cnt := map[int][]interface{}{}
	for i := range fa {
		v := find(i)
		cnt[v] = append(cnt[v], i+1)
	}
	Fprintln(out, len(cnt))
	for _, vs := range cnt {
		Fprint(out, len(vs), " ")
		Fprintln(out, vs...)
	}
}

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


Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems.For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem scoring, here is what it means. The maximum point value of the problem depends on the ratio of the number of participants who solved the problem to the total number of round participants. Everyone who made at least one submission is considered to be participating in the round.Pay attention to the range bounds. For example, if 40 people are taking part in the round, and 10 of them solve a particular problem, then the solvers fraction is equal to 1 / 4, and the problem's maximum point value is equal to 1500.If the problem's maximum point value is equal to x, then for each whole minute passed from the beginning of the contest to the moment of the participant's correct submission, the participant loses x / 250 points. For example, if the problem's maximum point value is 2000, and the participant submits a correct solution to it 40 minutes into the round, this participant will be awarded with 2000·(1 - 40 / 250) = 1680 points for this problem.There are n participants in the round, including Vasya and Petya. For each participant and each problem, the number of minutes which passed between the beginning of the contest and the submission of this participant to this problem is known. It's also possible that this participant made no submissions to this problem.With two seconds until the end of the round, all participants' submissions have passed pretests, and not a single hack attempt has been made. Vasya believes that no more submissions or hack attempts will be made in the remaining two seconds, and every submission will pass the system testing.Unfortunately, Vasya is a cheater. He has registered 109 + 7 new accounts for the round. Now Vasya can submit any of his solutions from these new accounts in order to change the maximum point values of the problems. Vasya can also submit any wrong solutions to any problems. Note that Vasya can not submit correct solutions to the problems he hasn't solved.Vasya seeks to score strictly more points than Petya in the current round. Vasya has already prepared the scripts which allow to obfuscate his solutions and submit them into the system from any of the new accounts in just fractions of seconds. However, Vasya doesn't want to make his cheating too obvious, so he wants to achieve his goal while making submissions from the smallest possible number of new accounts.Find the smallest number of new accounts Vasya needs in order to beat Petya (provided that Vasya's assumptions are correct), or report that Vasya can't achieve his goal.

The first line contains a single integer n (2 ≤ n ≤ 120) — the number of round participants, including Vasya and Petya. Each of the next n lines contains five integers ai, 1, ai, 2..., ai, 5 ( - 1 ≤ ai, j ≤ 119) — the number of minutes passed between the beginning of the round and the submission of problem j by participant i, or -1 if participant i hasn't solved problem j. It is guaranteed that each participant has made at least one successful submission. Vasya is listed as participant number 1, Petya is listed as participant number 2, all the other participants are listed in no particular order.

Output a single integer — the number of new accounts Vasya needs to beat Petya, or -1 if Vasya can't achieve his goal.

NoteIn the first example, Vasya's optimal strategy is to submit the solutions to the last three problems from two new accounts. In this case the first two problems will have the maximum point value of 1000, while the last three problems will have the maximum point value of 500. Vasya's score will be equal to 980 + 940 + 420 + 360 + 270 = 2970 points, while Petya will score just 800 + 820 + 420 + 440 + 470 = 2950 points.In the second example, Vasya has to make a single unsuccessful submission to any problem from two new accounts, and a single successful submission to the first problem from the third new account. In this case, the maximum point values of the problems will be equal to 500, 1500, 1000, 1500, 3000. Vasya will score 2370 points, while Petya will score just 2294 points.In the third example, Vasya can achieve his goal by submitting the solutions to the first four problems from 27 new accounts. The maximum point values of the problems will be equal to 500, 500, 500, 500, 2000. Thanks to the high cost of the fifth problem, Vasya will manage to beat Petya who solved the first four problems very quickly, but couldn't solve the fifth one.

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	mul := int64(1)
	for _, b := range in.Bytes() {
		if b == '-' {
			mul *= -1
			continue
		}
		res = res*10 + int64(b-'0')
	}
	return mul * res
}

const accounts = 1000000007

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	a := make([][5]int64, n)
	var solved [5]int64
	for i := range a {
		for j := range a[i] {
			a[i][j] = readInt()
			if a[i][j] != -1 {
				solved[j]++
			}
		}
	}

	check := func(subm int) bool {
		sub := int64(subm)
		solved := solved
		tot := n + sub
		for i := range a[0] {
			if a[1][i] != -1 && a[0][i] != -1 && a[0][i] > a[1][i] {
				solved[i] += sub
			}
		}
		score := func(t [5]int64) int64 {
			res := int64(0)
			for i := range t {
				if t[i] == -1 {
					continue
				}
				max := int64(3000)
				switch {
				case solved[i]*2 > tot:
					max = 500
				case solved[i]*4 > tot:
					max = 1000
				case solved[i]*8 > tot:
					max = 1500
				case solved[i]*16 > tot:
					max = 2000
				case solved[i]*32 > tot:
					max = 2500
				}
				res += max - max/250*t[i]
			}
			return res
		}
		return score(a[0]) > score(a[1])
	}
	for res := 0; res < 5000; res++ {
		if check(res) {
			fmt.Println(res)
			return
		}
	}
	fmt.Println(-1)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	mul := int64(1)
	for _, b := range in.Bytes() {
		if b == '-' {
			mul *= -1
			continue
		}
		res = res*10 + int64(b-'0')
	}
	return mul * res
}

const accounts = 1000000007

func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	a := make([][5]int64, n)
	var solved [5]int64
	for i := range a {
		for j := range a[i] {
			a[i][j] = readInt()
			if a[i][j] != -1 {
				solved[j]++
			}
		}
	}

	res := sort.Search(accounts+1, func(subm int) bool {
		sub := int64(subm)
		solved := solved
		tot := n + sub
		for i := range a[0] {
			if a[1][i] != -1 && a[0][i] != -1 && a[0][i] > a[1][i] {
				solved[i] += sub
			}
		}
		score := func(t [5]int64) int64 {
			res := int64(0)
			for i := range t {
				if t[i] == -1 {
					continue
				}
				max := int64(3000)
				switch {
				case solved[i]*2 > tot:
					max = 500
				case solved[i]*4 > tot:
					max = 1000
				case solved[i]*8 > tot:
					max = 1500
				case solved[i]*16 > tot:
					max = 2000
				case solved[i]*32 > tot:
					max = 2500
				}
				res += max - max/250*t[i]
			}
			return res
		}
		return score(a[0]) > score(a[1])
	})
	if res > accounts {
		fmt.Println(-1)
		return
	}
	fmt.Println(res)
}


Mainak has two positive integers $$$n$$$ and $$$m$$$.Mainak finds a sequence $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers interesting, if for all integers $$$i$$$ ($$$1 \le i \le n$$$), the bitwise XOR of all elements in $$$a$$$ which are strictly less than $$$a_i$$$ is $$$0$$$. Formally if $$$p_i$$$ is the bitwise XOR of all elements in $$$a$$$ which are strictly less than $$$a_i$$$, then $$$a$$$ is an interesting sequence if $$$p_1 = p_2 = \ldots = p_n = 0$$$.For example, sequences $$$[1,3,2,3,1,2,3]$$$, $$$[4,4,4,4]$$$, $$$[25]$$$ are interesting, whereas $$$[1,2,3,4]$$$ ($$$p_2 = 1 \ne 0$$$), $$$[4,1,1,2,4]$$$ ($$$p_1 = 1 \oplus 1 \oplus 2 = 2 \ne 0$$$), $$$[29,30,30]$$$ ($$$p_2 = 29 \ne 0$$$) aren't interesting.Here $$$a \oplus b$$$ denotes bitwise XOR of integers $$$a$$$ and $$$b$$$.Find any interesting sequence $$$a_1, a_2, \ldots, a_n$$$ (or report that there exists no such sequence) such that the sum of the elements in the sequence $$$a$$$ is equal to $$$m$$$, i.e. $$$a_1 + a_2 \ldots + a_n = m$$$.As a reminder, the bitwise XOR of an empty sequence is considered to be $$$0$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line and the only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le m \le 10^9$$$) — the length of the sequence and the sum of the elements. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, if there exists some interesting sequence, output "Yes" on the first line, otherwise output "No". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer). If the answer is "Yes", output $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i \ge 1$$$), forming an interesting sequence such that $$$a_1 + a_2 \ldots + a_n = m$$$. If there are multiple solutions, output any.

Note In the first test case, $$$[3]$$$ is the only interesting sequence of length $$$1$$$ having sum $$$3$$$. In the third test case, there is no sequence of length $$$2$$$ having sum of elements equal to $$$1$$$, so there is no such interesting sequence. In the fourth test case, $$$p_1 = p_2 = p_3 = 0$$$, because bitwise XOR of an empty sequence is $$$0$$$.

package main

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

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

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

		y, z := n, m
		if n > m {
			fmt.Fprintln(out, "No")
			continue
		}

		bb := make([]int, n)
		var tot int
		var idx int
		for n > 2 {
			if m/n*n == m {
				break
			}
			bb[idx], bb[idx+1] = 1, 1
			n -= 2
			m -= 2
			tot += 2
			idx += 2
		}

		for i := idx; i < y; i++ {
			bb[i] = m / n
			tot += m / n
		}

		if tot != z {
			fmt.Fprintln(out, "No")
		} else {
			fmt.Fprintln(out, "Yes")
			for _, v := range bb {
				fmt.Fprintf(out, "%d ", v)
			}
			fmt.Fprintln(out)
		}
	}
}


Monocarp is playing a computer game once again. He is a wizard apprentice, who only knows a single spell. Luckily, this spell can damage the monsters.The level he's currently on contains $$$n$$$ monsters. The $$$i$$$-th of them appears $$$k_i$$$ seconds after the start of the level and has $$$h_i$$$ health points. As an additional constraint, $$$h_i \le k_i$$$ for all $$$1 \le i \le n$$$. All $$$k_i$$$ are different.Monocarp can cast the spell at moments which are positive integer amounts of second after the start of the level: $$$1, 2, 3, \dots$$$ The damage of the spell is calculated as follows. If he didn't cast the spell at the previous second, the damage is $$$1$$$. Otherwise, let the damage at the previous second be $$$x$$$. Then he can choose the damage to be either $$$x + 1$$$ or $$$1$$$. A spell uses mana: casting a spell with damage $$$x$$$ uses $$$x$$$ mana. Mana doesn't regenerate.To kill the $$$i$$$-th monster, Monocarp has to cast a spell with damage at least $$$h_i$$$ at the exact moment the monster appears, which is $$$k_i$$$.Note that Monocarp can cast the spell even when there is no monster at the current second.The mana amount required to cast the spells is the sum of mana usages for all cast spells. Calculate the least amount of mana required for Monocarp to kill all monsters.It can be shown that it's always possible to kill all monsters under the constraints of the problem.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of monsters in the level. The second line of the testcase contains $$$n$$$ integers $$$k_1 < k_2 < \dots < k_n$$$ ($$$1 \le k_i \le 10^9$$$) — the number of second from the start the $$$i$$$-th monster appears at. All $$$k_i$$$ are different, $$$k_i$$$ are provided in the increasing order. The third line of the testcase contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$ ($$$1 \le h_i \le k_i \le 10^9$$$) — the health of the $$$i$$$-th monster. The sum of $$$n$$$ over all testcases doesn't exceed $$$10^4$$$.

For each testcase, print a single integer — the least amount of mana required for Monocarp to kill all monsters.

NoteIn the first testcase of the example, Monocarp can cast spells $$$3, 4, 5$$$ and $$$6$$$ seconds from the start with damages $$$1, 2, 3$$$ and $$$4$$$, respectively. The damage dealt at $$$6$$$ seconds is $$$4$$$, which is indeed greater than or equal to the health of the monster that appears.In the second testcase of the example, Monocarp can cast spells $$$3, 4$$$ and $$$5$$$ seconds from the start with damages $$$1, 2$$$ and $$$3$$$, respectively.In the third testcase of the example, Monocarp can cast spells $$$4, 5, 7, 8$$$ and $$$9$$$ seconds from the start with damages $$$1, 2, 1, 1$$$ and $$$2$$$, respectively.

package main

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

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

func accSum(n int) int64 {
	return int64(n) * int64(n+1) / 2
}

func rangeSum(fr, to int) int64 {
	return accSum(to) - accSum(fr-1)
}

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

func calculate(dmg, t, h0, h1 int) (int64, int) {
	if t >= h1 {
		return rangeSum(1, h1), h1
	}
	return rangeSum(dmg+1, dmg+t), dmg + t
}

func solveCase() {
	var n int
	fmt.Fscan(in, &n)
	n++
	var time []int = make([]int, n)
	var health []int = make([]int, n)
	for i := 1; i < n; i++ {
		fmt.Fscan(in, &time[i])
	}
	for i := 1; i < n; i++ {
		fmt.Fscan(in, &health[i])
	}
	for i := n - 1; i >= 1; i-- {
		if health[i] > health[i-1]+(time[i]-time[i-1]) {
			health[i-1] = health[i] - (time[i] - time[i-1])
		}
	}
	var ans int64 = 0
	var dmg = 0
	for i := 0; i+1 < n; i++ {
		var toAdd int64
		toAdd, dmg = calculate(dmg, time[i+1]-time[i], health[i], health[i+1])
		ans += toAdd
	}
	fmt.Fprintf(out, "%d\n", ans)
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		solveCase()
	}
	out.Flush()
}

package main

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

var a []int
var b []int
var l int

func minMagic() int64 {
	var mm int64
	var p int64
	var c int
	var prev = a[l-1]
	for i := l - 1; i >= 0; i-- {
		k := a[i]
		h := b[i]
		c -= prev - k
		if c <= 0 {
			mm += (p * (p + 1)) / 2
			p = 0
			c = 0
		}
		if h > c {
			p += int64(h - c)
			c += h - c
		}
		prev = a[i]
	}
	mm += (p * (p + 1)) / 2
	return mm
}

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

	a = make([]int, 105)
	b = make([]int, 105)
	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		fmt.Fscan(in, &l)
		for j := 0; j < l; j++ {
			fmt.Fscan(in, &a[j])
		}
		for j := 0; j < l; j++ {
			fmt.Fscan(in, &b[j])
		}
		fmt.Fprintln(out, minMagic())
	}
	out.Flush()
}

package main

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

var in = bufio.NewReader(os.Stdin)

type elem struct {
	pos, value int
}

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

func solve() {
	var n int
	fmt.Fscan(in, &n)

	k := make([]int, n)
	for i := range k {
		fmt.Fscan(in, &k[i])
	}
	h := make([]int, n)
	for i := range h {
		fmt.Fscan(in, &h[i])
	}

	var stack []elem
	for i := 0; i < n; i++ {
		goalI := h[i]
		startI := k[i] - goalI + 1
		for len(stack) > 0 && stack[len(stack)-1].pos >= startI {
			last := stack[len(stack)-1]
			goalI = max(goalI, last.value+k[i]-last.pos)
			startI = k[i] - goalI + 1
			stack = stack[:len(stack)-1]
		}
		stack = append(stack, elem{pos: k[i], value: goalI})
	}

	var result int64 = 0
	for _, e := range stack {
		v := int64(e.value)
		result += (v + 1) * v / 2
	}
	fmt.Println(result)
}

func main() {
	var t int
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

const mod = 998244353
const mx = 3000

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in,&n)
	ks := make([]int64,n)
	hs := make([]int64,n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in,&ks[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in,&hs[i])
	}
	for i := n - 2;i >= 0;i--{
		hs[i] = max(hs[i],hs[i + 1] - (ks[i + 1] - ks[i]))
	}
	ans := sum(1,hs[0])
	P := hs[0]
	for i := 1;i < n;i++{
		if hs[i] <= ks[i] - ks[i - 1]{
			ans += sum(1,hs[i])
			P = hs[i]
		}else{
			ans += sum(P + 1, P + ks[i] - ks[i - 1])
			P += ks[i] - ks[i - 1]
		}
	}
	fmt.Fprintln(out,ans)
}
func sum(a,b int64)int64{
	return (b + a) * (b - a + 1) / 2
}

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

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

package main

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

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

func accSum(n int) int64 {
	return int64(n) * int64(n+1) / 2
}

func rangeSum(fr, to int) int64 {
	return accSum(to) - accSum(fr-1)
}

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

func calculate(dmg, t, h0, h1 int) (int64, int) {
	if t >= h1 {
		return rangeSum(1, h1), h1
	}
	return rangeSum(dmg+1, dmg+t), dmg + t
}

func solveCase() {
	var n int
	fmt.Fscan(in, &n)
	n++
	var time []int = make([]int, n)
	var health []int = make([]int, n)
	for i := 1; i < n; i++ {
		fmt.Fscan(in, &time[i])
	}
	for i := 1; i < n; i++ {
		fmt.Fscan(in, &health[i])
	}
	var ans int64 = 0
	var dmg = 0
	for i := 0; i+1 < n; i++ {
		var toAdd int64
		toAdd, dmg = calculate(dmg, time[i+1]-time[i], health[i], health[i+1])
		ans += toAdd
	}
	fmt.Fprintf(out, "%d\n", ans)
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		solveCase()
	}
	out.Flush()
}

package main

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

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

func accSum(n int) int64 {
	return int64(n) * int64(n+1) / 2
}

func rangeSum(fr, to int) int64 {
	return accSum(to) - accSum(fr-1)
}

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

func calculate(dmg, t, h0, h1 int) (int64, int) {
	if t >= h1 {
		return rangeSum(1, h1), h1
	}
	return rangeSum(dmg+1, dmg+t), dmg + 1
}

func solveCase() {
	var n int
	fmt.Fscan(in, &n)
	n++
	var time []int = make([]int, n)
	var health []int = make([]int, n)
	for i := 1; i < n; i++ {
		fmt.Fscan(in, &time[i])
	}
	for i := 1; i < n; i++ {
		fmt.Fscan(in, &health[i])
	}
	var ans int64 = 0
	var dmg = 0
	for i := 0; i+1 < n; i++ {
		var toAdd int64
		toAdd, dmg = calculate(dmg, time[i+1]-time[i], health[i], health[i+1])
		ans += toAdd
	}
	fmt.Fprintf(out, "%d\n", ans)
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		solveCase()
	}
	out.Flush()
}