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

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

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


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 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 - (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, 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
	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])
}


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


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

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

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

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