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 s string
		fmt.Fscan(in, &s)

		chars := make([]int, 26)
		var d int
		for _, ch := range s {
			chars[ch-'a']++
			if chars[ch-'a'] == 2 {
				d++
			}
		}

		var t int
		for _, v := range chars {
			if v == 1 {
				t++
			}
		}

		fmt.Fprintln(out, (t/2)+d)
	}
}

package main

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

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func countStr(s, a string) int {
	var ans int
	ans = 0
	for _, l := range s {
		if string(l) == a {
			ans = ans + 1
		}
	}
	return ans
}

func countArrOfStr(arr []string, s string) int {
	var ans int
	ans = 0
	for _, l := range arr {
		if l == s {
			ans = ans + 1
		}
	}
	return ans
}

func isInArray(arr []string, s string) bool {
	var ans bool = false
	for _, l := range arr {
		if l == s {
			ans = true
			break
		}
	}
	return ans
}

func setArrofStr(arr []string) []string {
	var ans []string
	for _, l := range arr {
		if isInArray(ans, l) == false {
			ans = append(ans, l)
		}
	}
	return ans

}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var s string
		fmt.Fscan(input, &s)
		var bir []string
		var kop []string
		for _, letter := range s {
			var c int
			c = countStr(s, string(letter))
			if c == 1 {
				bir = append(bir, string(letter))
			} else {
				kop = append(kop, string(letter))
			}
		}
		fmt.Println(len(setArrofStr(bir))/2 + len(setArrofStr(kop)))

	}
}

package main

import (
	"fmt"
)

func main() {

	var (
		n   int
		str string
	)
	fmt.Scan(&n)
	for n > 0 {
		n--
		fmt.Scan(&str)
		var s [30]int
		ans := 0
		for i := 0; i < len(str); i++ {
			s[int(str[i])-97]++
		}
		for i := 0; i < 26; i++ {
			if s[i] > 2 {
				s[i] = 2
			}
			ans += s[i]
		}
		fmt.Println(ans/2)
	}

}

package main

import "fmt"

func main() {
	var (
		t int
		s string
	)
	fmt.Scanln(&t)
	for i := 0; i < t; i++ {
		fmt.Scanln(&s)
		red, green := make(map[rune]bool), make(map[rune]bool)
		for _, ch:= range s {
			if !red[ch] {
				red[ch] = true
			} else if red[ch] {
				green[ch] = true
			}
		}
		redSize, greenSize := len(red), len(green)
		fmt.Println(greenSize + (redSize - greenSize) / 2)
	}
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func _int() int {
	s := _string()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func _int64() int64 {
	s := _string()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func _string() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		printf("%d\n", sol(_string()))
	}
}

func sol(s string) int {
	cum := 0
	count := map[rune]int{}
	for _, r := range s {
		if count[r] >= 2 {
			continue
		}
		count[r]++
		cum++
	}
	return cum / 2
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

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

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func solve(s string) int {
	count := make(map[byte]int)
	length := 0

	for _, ch := range []byte(s) {
		if count[ch] < 2 {
			length += 1
			count[ch] += 1
		}
	}
	return length / 2
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i += 1 {
		s := stdin.Word()
		fmt.Println(solve(s))
	}
}

package main

import (
	"bufio"
	"bytes"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var s []byte
		Fscan(in, &s)
		ans := 0
		for b := byte('a'); b <= 'z'; b++ {
			c := bytes.Count(s, []byte{b})
			if c > 2 {
				 c = 2
			}
			ans+=c
		}
		if ans&1>0 {
			ans--
		}
		Fprintln(out, ans/2)
	}

	T := 1
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main
import(
    "fmt"
    "sort"
    "strings"
)
func main() {
	var x int
	fmt.Scan(&x)
	for i:=0;i<x;i++{
		var word string
		fmt.Scan(&word)
		list:= strings.Split(word,"")
		sort.Strings(list)
		red:=1
		for j:=1;j<len(list);j++{
			if list[j] != list[j-1] {
				red++
			}
		}
		for j:=0;j<len(list);j++{ // keep singles & doubles
			counter:=1
			for k:=j+1;k<len(list);k++{
				if list[j] == list[k] {
					counter++
				}
				if counter >= 3 {
					counter--
					list = append(list[:k],list[k+1:]...)
					k--
				}
			}
		}
		fmt.Println(len(list)/2)
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, s := 0, ""
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &s)
		o, tot, ones := map[string]int{}, 0, 0
		for j := 0; j < len(s); j++ {
			o[string(s[j])]++
		}
		for _, v := range o {
			if v == 1 {
				ones++
			} else {
				tot++
			}
		}
		fmt.Fprintln(w, tot+(ones/2))
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

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

func (in *CF1551B1) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1551B1) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1551B1
Date: 26/10/21
User: pepradere
URL: https://codeforces.com/problemset/problem/1551/B1
Problem: CF1551B1
**/
func (in *CF1551B1) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		str := in.NextString()
		letters := make([]int, 32)
		colors := ""
		color := "R"
		r, g := 0, 0
		for i := 0; i < len(str); i++ {
			l := str[i]-'a'
			if letters[l] ==0 {
				colors+=color
				if color == "R" {
					r++
					color = "G"
				} else {
					g++
					color = "R"
				}
			} else if letters[l] == 1 {
				colors+=color
				if color == "R" {
					r++
					color = "G"
				} else {
					g++
					color = "R"
				}
			} else {
				colors+="W"
			}
			letters[l]++
		}

		ans := int(math.Min(float64(r), float64(g)))

		fmt.Println(ans)
	}

}

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

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

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	s      string
)

func solve(s string) int {
	var (
		m    = make(map[rune]int)
		v, w int
	)
	for _, x := range s {
		m[x]++
	}
	for i := 'a'; i <= 'z'; i++ {
		if m[i] > 1 {
			v++
		}
		if m[i] == 1 {
			w++
		}
	}
	return v + w/2
}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var s string
		Fscan(in, &s)

		var buckets [26]int

		for _, c := range s {
			buckets[c - 'a']++
		}

		ans := 0
		for _, val := range buckets {
			if val > 2 {
				ans += val - 2
			}
		}
		if (len(s) - ans) & 0x1 != 0 {
			Fprintln(out, (len(s) - ans - 1) >> 1)
		} else {
			Fprintln(out, (len(s) - ans) >> 1)
		}
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var t int
	var s string
	for fmt.Scanln(&t); t > 0; t-- {
		x, y := 0, 0
		mp := make(map[byte]int)
		fmt.Scanln(&s)
		b := []byte(s)
		for _, c := range b {
			mp[c]++
		}
		for _, v := range mp {
			if v >= 2 {
				x++
			} else {
				y++
			}
		}
		fmt.Println(x + y>>1)
	}
}

package main

import (
    "fmt"
)

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

    for i := 0; i < testCases; i++ {
        var input string
        store := make(map[rune]int)
        fmt.Scan(&input)
        for _, v := range input {
            store[v] += 1
        }
        result := 0
        acc := 0
        for _, v := range store {
            if v == 1 {
                result += 1
            } else {
                acc += 1
            }
        }
        result = result / 2
        result += acc
        fmt.Println(result)
    }
}

package main

import "fmt"

func main() {
	var str string
	var sumOfCases int16
	fmt.Scan(&sumOfCases)
	for i := int16(0); i < sumOfCases; i++ {
		litterList := [26]int8{}
		var num int8
		fmt.Scan(&str)
		var length = int8(len(str))
		for _, litter := range str {
			index := litter - 'a'
			litterList[index]++
		}
		for _, n := range litterList {
			if n >= 2 {
				num++
				length=length-n
			}
		}
		fmt.Println(num+length/2)
	}
}

package main

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

func solve(s string)  {
	ma := make(map[string]int)

	for i := range s {
		cur := s[i:(i+1)]
		_, ok := ma[cur]
		if !ok {
			ma[cur] = 1
		} else {
			ma[cur]++
		}
	}
	cnt := 0
	ans := 0
	for _, value := range ma {
		if value == 1 {
			cnt++
		} else {
			ans++
		}
	}
	ans += cnt / 2
	fmt.Println(ans)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	i := 0

	for scanner.Scan() {
		s := scanner.Text()
		if i == 0 {
			i++
			continue
		}
		i++
		if len(s) == 0 {
			break
		}
		solve(s)
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		ARRAY := make([]int, 26)
		l := len(STRING)
		for i := 0; i < l; i++ {
			m := int(STRING[i]) - 97
			ARRAY[m]++
		}
		answer := 0
		b := 0
		for j := 0; j < 26; j++ {
			if ARRAY[j] > 1 {
				answer++
			}
			if ARRAY[j] == 1 {
				b++
			}
		}
		answer = answer + int(b/2)
		fmt.Println(answer)

	}

}

package main
import(
    "fmt"
    "sort"
    "strings"
)
func main() {
	var x int
	fmt.Scan(&x)
	for i:=0;i<x;i++{
		var word string
		fmt.Scan(&word)
		list:= strings.Split(word,"")
		sort.Strings(list)
		red:=1
		for j:=1;j<len(list);j++{
			if list[j] != list[j-1] {
				red++
			}
		}
		if red > len(word)/2 {
			fmt.Println(len(word)/2)
		} else {
			fmt.Println(red)
		}
	}
}


package main

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

func main() {
  reader := bufio.NewReader(os.Stdin)
  var n, last int32
  var cur, sum int64
  fmt.Scan(&n)
  var ans int64 = int64(n+1) * int64(n) / 2
  cor := map[int64]int32{}
  cor[0] = 1
  reader.ReadString('\n')
  input, _ := reader.ReadString('\n')
  inputs := strings.Fields(input)
  for i := int32(1); i <= n; i++ {
    cur, _ = strconv.ParseInt(inputs[i-1], 10, 64)
    sum += cur
    tmp := cor[sum]
    if tmp > last {
      ans -= int64(tmp-last) * int64(n-i+1)
      last = tmp
    }
    cor[sum] = i+1
  }
  fmt.Println(ans)
}

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	nn := []int64{}
	for i := int64(0); i < n; i++ {
		nn = append(nn, reader.NextInt64())
	}
	writer.Printf("%d\n", sol(nn))
}

func genPrefixSum(nn []int64) []int64 {
    ret := make([]int64, len(nn)+1)
    for i := range nn {
        ret[i+1] = nn[i] + ret[i]
    }
    return ret
}

func sol(nn []int64) int64 {
    hs := map[int64]int64{0: 0} // map[s]i
    a := genPrefixSum(nn)
    ans := int64(0)
    hh := int64(-1)
    for i := int64(1); i < int64(len(a)); i++ {
        s := a[i]
        if _, ok := hs[s]; ok {
            hh = max(hh, hs[s])
        }
        ans += i - hh -1
        hs[s] = i
    }
	return ans
}

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

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	nn := []int64{}
	for i := int64(0); i < n; i++ {
		nn = append(nn, reader.NextInt64())
	}
	writer.Printf("%d\n", sol(nn))
}

func sol(nn []int64) int64 {
	currSum := int64(0)
    prevSums := map[int64]int64{0: -1} // map[sum]idx
	ret := int64(0)
	lastZero := int64(-2)
	for i := range nn {
		currSum += nn[i]
		if prevIdx, ok := prevSums[currSum]; ok {
			lastZero = max(lastZero, prevIdx)
		}
		ret -= (lastZero+2)
		ret += int64(i) + 1
		prevSums[currSum] = int64(i)
	}
	return ret
}

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

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	nn := []int64{0}
	for i := int64(0); i < n; i++ {
		nn = append(nn, reader.NextInt64())
	}
	writer.Printf("%d\n", sol(nn))
}

func sol(a []int64) int64 {
    hs := map[int64]int64{0: 0}
    s := int64(0)
    ans := int64(0)
    hh := int64(-1)
    for i := int64(1); i < int64(len(a)); i++ {
        s += a[i]
        if _, ok := hs[s]; ok {
            hh = max(hh, hs[s])
        }
        ans += i - hh -1
        hs[s] = i
    }
	return ans
}

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

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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 main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1010)

	n := NextInt()
	p := make([]int64, n+1)
	pairs := make([][2]int64, n+1)
	pairs[0][0] = 0
	pairs[0][0] = 0
	for i := 1; i <= n; i++ {
		p[i] = p[i-1] + int64(NextInt())
		pairs[i][0] = p[i]
		pairs[i][1] = int64(i)
	}

	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i][0] < pairs[j][0] || pairs[i][0] == pairs[j][0] && pairs[i][1] < pairs[j][1]
	})

	bsearch := func(x int64, i int) int {
		l := 0
		r := n
		res := -1
		for l <= r {
			mid := (l + r) >> 1
			if pairs[mid][0] < x || pairs[mid][0] == x && pairs[mid][1] < int64(i) {
				if pairs[mid][0] == x {
					res = mid
				}
				l = mid + 1
			} else {
				r = mid - 1
			}
		}
		if res == -1 {
			return -1
		}
		return int(pairs[res][1])
	}

	var res int64
	for i, l := 1, 0; i <= n; i++ {
		t := bsearch(p[i], i) + 1
		l = max(l, t)
		res += int64(max(i-l, 0))
	}

	fmt.Fprintln(out, res)

}

/*
URL:
https://codeforces.com/problemset/problem/1333/C
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

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

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	n int
	A []int64
)

func main() {
	n = ReadInt()
	A = ReadInt64Slice(n)

	P := make([]int64, n+1)
	for i := 0; i < n; i++ {
		P[i+1] = P[i] + A[i]
	}

	memo := make(map[int64]int)
	memo[0] = 1
	right := 0
	ans := int64(0)
	for left := 0; left < len(A); left++ {
		for right < len(A) && memo[P[right+1]] == 0 {
			// change condition(right)
			memo[P[right+1]]++

			right++
		}

		// query processing
		ans += int64(right - left)

		// preprocessing before preceding LEFT
		if right == left {
			right++
		} else {
			// change condition(left)
			memo[P[left]]--
		}
	}

	fmt.Println(ans)
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

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

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

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

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

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

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

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

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

	return string(res)
}

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

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

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

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/problemset/problem/1333/C
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

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

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	n int
	A []int64
)

func main() {
	n = ReadInt()
	A = ReadInt64Slice(n)

	P := make([]int64, n+1)
	for i := 0; i < n; i++ {
		P[i+1] = P[i] + A[i]
	}

	memo := make(map[int64]int)
	// memo[0] = 1
	right := 0
	ans := int64(0)
	for left := 0; left < len(P); left++ {
		for right < len(P) && memo[P[right]] == 0 {
			// change condition(right)
			memo[P[right]]++

			right++
		}

		// query processing
		ans += int64(right - left - 1)

		// preprocessing before preceding LEFT
		if right == left {
			right++
		} else {
			// change condition(left)
			memo[P[left]]--
		}
	}

	fmt.Println(ans)
}

// 以下はAC済みの正しい解法
// func main() {
// 	n = ReadInt()
// 	A = ReadInt64Slice(n)

// 	P := make([]int64, n+1)
// 	for i := 0; i < n; i++ {
// 		P[i+1] = P[i] + A[i]
// 	}

// 	memo := make(map[int64]int)
// 	memo[0] = 1
// 	right := 0
// 	ans := int64(0)
// 	for left := 0; left < len(A); left++ {
// 		for right < len(A) && memo[P[right+1]] == 0 {
// 			// change condition(right)
// 			memo[P[right+1]]++

// 			right++
// 		}

// 		// query processing
// 		ans += int64(right - left)

// 		// preprocessing before preceding LEFT
// 		if right == left {
// 			right++
// 		} else {
// 			// change condition(left)
// 			memo[P[left]]--
// 		}
// 	}

// 	fmt.Println(ans)
// }

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

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

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

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

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

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

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

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

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

	return string(res)
}

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

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

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

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)

	var n, d int
	var A [200001]int
	var s int64
	var k uint64
	mp := make(map[int64]int)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	mp[0] = 0
	for i := 1; i <= n; i++ {
		sc.Scan()
		fmt.Sscanf(sc.Text(), "%d", &A[i])
		d++
		s += int64(A[i])
		l, ok := mp[s]
		if ok {
			if d > i-l-1 {
				d = i - l - 1
			}
		}
		mp[s] = i
		k += uint64(d)
	}
	fmt.Fprintln(wr, k)
	wr.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1333C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, l int
	var ans, s int64
	sumP := map[int64]int{0: 0}
	Fscan(in, &n)
	for i := 1; i <= n; i++ {
		Fscan(in, &v)
		s += int64(v)
		if p, ok := sumP[s]; ok && p+1 > l {
			l = p + 1
		}
		ans += int64(i - l)
		sumP[s] = i
	}
	Fprint(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1333C(_r io.Reader, _w io.Writer) {
	ans := int64(0)
	var f func([]int64)
	f = func(a []int64) {
		n := len(a)
		if n == 1 {
			if a[0] != 0 {
				ans++
			}
			return
		}
		m := n >> 1
		f(a[:m])
		f(a[m:])
		sumPos := map[int64]int{}
		s := int64(0)
		maxPos := m
		for i := m - 1; i >= 0 && a[i] != 0; i-- {
			s += a[i]
			if s == 0 || sumPos[s] != 0 {
				break
			}
			sumPos[s] = i
			maxPos = i
		}
		s = 0
		vis := map[int64]bool{}
		for i := m; i < n && a[i] != 0 && maxPos < m; i++ {
			s += a[i]
			if s == 0 || vis[s] {
				break
			}
			vis[s] = true
			if p, ok := sumPos[-s]; ok && p+1 > maxPos {
				maxPos = p + 1
			}
			ans += int64(m - maxPos)
		}
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	f(a)
	Fprint(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1333C(_r io.Reader, _w io.Writer) {
	ans := int64(0)
	var f func([]int64)
	f = func(a []int64) {
		n := len(a)
		if n == 1 {
			if a[0] != 0 {
				ans++
			}
			return
		}
		m := n >> 1
		f(a[:m])
		f(a[m:])
		sumPos := map[int64]int{}
		s := int64(0)
		maxPos := m
		for i := m - 1; i >= 0 && a[i] != 0; i-- {
			s += a[i]
			if s == 0 || sumPos[s] != 0 {
				break
			}
			sumPos[s] = i
			maxPos = i
		}
		s = 0
		vis := map[int64]bool{}
		for i := m; i < n && a[i] != 0; i++ {
			s += a[i]
			if s == 0 || vis[s] {
				break
			}
			vis[s] = true
			if p, ok := sumPos[-s]; ok && p+1 > maxPos {
				maxPos = p + 1
			}
			ans += int64(m - maxPos)
		}
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	f(a)
	Fprint(_w, ans)
}

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

/*
URL:
https://codeforces.com/problemset/problem/1333/C
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

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

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	n int
	A []int64
)

func main() {
	n = ReadInt()
	A = ReadInt64Slice(n)

	P := make([]int64, n+1)
	for i := 0; i < n; i++ {
		P[i+1] = P[i] + A[i]
	}

	memo := make(map[int64]int)
	memo[0] = 1
	right := 0
	ans := 0
	for left := 0; left < len(A); left++ {
		for right < len(A) && memo[P[right+1]] == 0 {
			// change condition(right)
			memo[P[right+1]]++

			right++
		}

		// query processing
		ans += right - left

		// preprocessing before preceding LEFT
		if right == left {
			right++
		} else {
			// change condition(left)
			memo[P[left]]--
		}
	}

	fmt.Println(ans)
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

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

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

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

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

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

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

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

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

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

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

	return string(res)
}

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

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

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

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)

	var n, d int
	var A [200001]int
	var s, k int64
	mp := make(map[int64]int)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	mp[0] = 0
	for i := 1; i <= n; i++ {
		sc.Scan()
		fmt.Sscanf(sc.Text(), "%d", &A[i])
		d++
		s += int64(A[i])
		l, ok := mp[s]
		if ok {
			d = i - l - 1
		}
		mp[s] = i
		k += int64(d)
	}
	fmt.Fprintln(wr, k)
	wr.Flush()
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)

	var n, k, d int
	var A [200001]int
	var s int64
	mp := make(map[int64]int)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	mp[0] = 0
	for i := 1; i <= n; i++ {
		sc.Scan()
		fmt.Sscanf(sc.Text(), "%d", &A[i])
		d++
		s += int64(A[i])
		l, ok := mp[s]
		if ok {
			d = i - l - 1
		}
		mp[s] = i
		k += d
	}
	fmt.Fprintln(wr, k)
	wr.Flush()
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)

	var n, d int
	var A [200001]int
	var s int64
	var k uint64
	mp := make(map[int64]int)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	mp[0] = 0
	for i := 1; i <= n; i++ {
		sc.Scan()
		fmt.Sscanf(sc.Text(), "%d", &A[i])
		d++
		s += int64(A[i])
		l, ok := mp[s]
		if ok {
			d = i - l - 1
		}
		mp[s] = i
		k += uint64(d)
	}
	fmt.Fprintln(wr, k)
	wr.Flush()
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1333C(_r io.Reader, _w io.Writer) {
	ans := int64(0)
	var f func([]int64)
	f = func(a []int64) {
		n := len(a)
		if n == 1 {
			if a[0] != 0 {
				ans++
			}
			return
		}
		m := n >> 1
		f(a[:m])
		f(a[m:])
		sumPos := map[int64]int{}
		s := int64(0)
		maxPos := 0
		for i := m - 1; i >= 0 && a[i] != 0; i-- {
			s += a[i]
			if s == 0 || sumPos[s] != 0 {
				break
			}
			sumPos[s] = i
			maxPos = i
		}
		s = 0
		vis := map[int64]bool{}
		for i := m; i < n && a[i] != 0; i++ {
			s += a[i]
			if s == 0 || vis[s] {
				break
			}
			vis[s] = true
			if p, ok := sumPos[-s]; ok && p+1 > maxPos {
				maxPos = p + 1
			}
			ans += int64(m - maxPos)
		}
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	f(a)
	Fprint(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1333C(_r io.Reader, _w io.Writer) {
	ans := int64(0)
	var f func([]int64)
	f = func(a []int64) {
		n := len(a)
		if n == 1 {
			if a[0] != 0 {
				ans++
			}
			return
		}
		m := n >> 1
		f(a[:m])
		f(a[m:])
		sumPos := map[int64]int{}
		s := int64(0)
		for i := m - 1; i >= 0 && a[i] != 0; i-- {
			s += a[i]
			if sumPos[s] == 0 {
				sumPos[s] = i
			}
		}
		s = 0
		maxPos := 0
		for i := m; i < n && a[i] != 0; i++ {
			s += a[i]
			if p, ok := sumPos[-s]; ok && p+1 > maxPos {
				maxPos = p + 1
			}
			ans += int64(m - maxPos)
		}
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	f(a)
	Fprint(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1333C(_r io.Reader, _w io.Writer) {
	ans := int64(0)
	var f func([]int64)
	f = func(a []int64) {
		n := len(a)
		if n == 1 {
			if a[0] != 0 {
				ans++
			}
			return
		}
		m := n >> 1
		f(a[:m])
		f(a[m:])
		sumPos := map[int64]int{}
		s := int64(0)
		maxPos := 0
		for i := m - 1; i >= 0 && a[i] != 0; i-- {
			s += a[i]
			if s == 0 {
				break
			}
			if sumPos[s] == 0 {
				sumPos[s] = i
			}
			maxPos = i
		}
		s = 0
		for i := m; i < n && a[i] != 0; i++ {
			s += a[i]
			if s == 0 {
				break
			}
			if p, ok := sumPos[-s]; ok && p+1 > maxPos {
				maxPos = p + 1
			}
			ans += int64(m - maxPos)
		}
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	f(a)
	Fprint(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1333C(_r io.Reader, _w io.Writer) {
	ans := int64(0)
	var f func([]int64)
	f = func(a []int64) {
		n := len(a)
		if n == 1 {
			if a[0] != 0 {
				ans++
			}
			return
		}
		m := n >> 1
		f(a[:m])
		f(a[m:])
		sumPos := map[int64]int{}
		s := int64(0)
		maxPos := 0
		for i := m - 1; i >= 0 && a[i] != 0; i-- {
			s += a[i]
			if s == 0 {
				break
			}
			if sumPos[s] == 0 {
				sumPos[s] = i
			}
			maxPos = i
		}
		s = 0
		for i := m; i < n && a[i] != 0; i++ {
			s += a[i]
			if p, ok := sumPos[-s]; ok && p+1 > maxPos {
				maxPos = p + 1
			}
			ans += int64(m - maxPos)
		}
	}

	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	f(a)
	Fprint(_w, ans)
}

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

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	nn := []int64{}
	for i := int64(0); i < n; i++ {
		nn = append(nn, reader.NextInt64())
	}
	writer.Printf("%d\n", sol(nn))
}

func sol(nn []int64) int64 {
	currSum := int64(0)
	prevSums := map[int64]int64{} // map[sum]idx
	ret := int64(0)
	lastZero := int64(-1)
	for i := range nn {
		currSum += nn[i]
        if currSum == 0 {
            lastZero = int64(i)
            prevSums[currSum] = int64(i)
            continue
        }
		if prevIdx, ok := prevSums[currSum]; ok {
			lastZero = max(lastZero, prevIdx+1)
		}
		ret -= (lastZero + 1)
		ret += int64(i) + 1
		prevSums[currSum] = int64(i)
	}
	return ret
}

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

package main

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

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	nn := []int64{}
	for i := int64(0); i < n; i++ {
		nn = append(nn, reader.NextInt64())
	}
	writer.Printf("%d\n", sol(nn))
}

func genPrefixSum(nn []int64) []int64 {
	ret := make([]int64, len(nn)+1)
	for i := range nn {
		ret[i+1] = nn[i] + ret[i]
	}
	return ret
}

func sol(nn []int64) int64 {
	hs := map[int64]int64{0: 0} // map[prefix_sum]index
	a := genPrefixSum(nn)
	ans := int64(0)
	hh := int64(-1)
	for i := int64(1); i < int64(len(a)); i++ {
		s := a[i]
		if _, ok := hs[s]; ok {
			hh = hs[s]
		}
		ans += i - hh - 1
		hs[s] = i
	}
	return ans
}


package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sort.Ints(a)
	for i, j := 0, n-1; i < j; i++ {
		Fprint(out, a[i], a[j], " ")
		j--
	}
	if n&1 > 0 {
		Fprint(out, a[n/2])
	}
}

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

package main

import (
	"fmt"
	"sort"
)

const MAXN = 1006

var arr[] int
var sorted[] int

func main() {
	var N,i,j,x int
	fmt.Scanf("%d\n", &N)
	for i=0; i<N; i++ {
		fmt.Scanf("%d", &x)
		arr = append(arr,x)
		sorted = append(sorted,x)
	}
	sort.Ints(sorted)
	j = 0
	for i=0; i<N; i+=2 {
		arr[i] = sorted[j]
		j++
	}
	if N&1 == 1 {
		i = N-2
	} else {
		i = N-1
	}
	for ;i>=0; i-=2 {
		arr[i] = sorted[j]
		j++
	}
	for i=0; i<N; i++ {
		fmt.Printf("%d ", arr[i])
	}
	fmt.Printf("\n")
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)

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

	sort.Ints(a)

	for i := 1; i+1 < n; i += 2 {
		a[i], a[i+1] = a[i+1], a[i]
	}

	for i := range a {
		print(a[i], " ")
	}
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import (
	"fmt"
	"sort"
)

const MAXN = 1006

var arr[] int
var sorted[] int

func main() {
	var N,i,j,x int
	fmt.Scanf("%d", &N)
	for i=0; i<N; i++ {
		fmt.Scanf("%d", &x)
		arr = append(arr,x)
		sorted = append(sorted,x)
	}
	sort.Ints(sorted)
	j = 0
	for i=0; i<N; i+=2 {
		arr[i] = sorted[j]
		j++
	}
	if N&1 == 1 {
		i = N-2
	} else {
		i = N-1
	}
	for ;i>=0; i-=2 {
		arr[i] = sorted[j]
		j++
	}
	for i=0; i<N; i++ {
		fmt.Printf("%d ", arr[i])
	}
	fmt.Printf("\n")
}

package main

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

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)

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

	sort.Ints(a)

	for i := 1; i+1 < n; i += 2 {
		a[i], a[i+1] = a[i+1], a[i]
	}

	println(a)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }


package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
type hp struct{ sort.IntSlice }

func (h hp) Less(i, j int) bool  { return h.IntSlice[i] > h.IntSlice[j] }
func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }
func (h *hp) push(v int)         { heap.Push(h, v) }
func (h *hp) pop() int           { return heap.Pop(h).(int) }
func (h hp) empty() bool         { return len(h.IntSlice) == 0 }
func (h hp) top() int            { return h.IntSlice[0] }

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		cnt := map[int]int{}
		for _, v := range a {
			cnt[v]++
		}
		vs := make([]int, 0, len(cnt))
		for _, v := range cnt {
			vs = append(vs, v)
		}
		h := &hp{vs}
		heap.Init(h)
		for h.Len() > 1 {
			v, w := h.pop(), h.pop()
			if v == 0 || w == 0 {
				break
			}
			h.push(v - 1)
			h.push(w - 1)
		}
		sum := 0
		for _, v := range vs {
			sum += v
		}
		Fprintln(out, sum)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "\n")
		mp := make(map[int64]int)
		for _, i := range arr {
			mp[i]++
		}
		var max int
		max = 0
		for _, v := range mp {
			if max < v {
				max = v
			}
		}

		if max-(n-max) > 0 {
			fmt.Fprintf(out, "%d\n", max-(n-max))
		} else {
			fmt.Fprintf(out, "%d\n", n%2)
		}
	}
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"sort"

	//"math"
	"os"
)

type hp struct { sort.IntSlice }

func (h hp)  Less(i, j int) bool { return h.IntSlice[i] > h.IntSlice[j] }
func (h *hp) Push(x interface{}) { h.IntSlice = append(h.IntSlice, x.(int)) }
func (h *hp) Pop() interface{} 	 { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }
func (h *hp) push(v int)		 { heap.Push(h, v) }
func (h *hp) pop() int			 { return heap.Pop(h).(int) }
func (h hp)  empty() bool 		 { return len(h.IntSlice) == 0 }
func (h hp)  top() int			 { return h.IntSlice[0] }

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp := make(map[int]int)

		for i := 0; i < n; i++ {
			var num int
			Fscan(in, &num)
			mp[num]++
		}

		var amounts []int
		for _, val := range mp {
			amounts = append(amounts, val)
		}

		h := &hp{amounts}
		heap.Init(h)
		sum := n
		for len(h.IntSlice) > 1 {
			v, w := h.pop(), h.pop()
			if v == 0 || w == 0 {
				break
			}
			h.push(v-1)
			h.push(w-1)
			sum -= 2
		}
		Fprintln(out, sum)
	}
}

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

package main

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

	"container/heap"
	//"math"
	"os"
)

type hp struct{ sort.IntSlice }

func (h hp) Less(i, j int) bool  { return h.IntSlice[i] > h.IntSlice[j] }
func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }
func (h *hp) push(v int)         { heap.Push(h, v) }
func (h *hp) pop() int           { return heap.Pop(h).(int) }
func (h hp) empty() bool         { return len(h.IntSlice) == 0 }
func (h hp) top() int            { return h.IntSlice[0] }

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		mp, nums := make(map[int]int), make([]int, n)

		for i, _ := range nums {
			Fscan(in, &nums[i])
			mp[nums[i]]++
		}

		var amounts []int
		for _, val := range mp {
			amounts = append(amounts, val)
		}

		h := &hp{amounts}
		heap.Init(h)
		sum := n
		for h.Len() > 1 {
			v, w := h.pop(), h.pop()
			if v == 0 || w == 0 {
				break
			}
			h.push(v-1)
			h.push(w-1)
			sum -= 2
		}
		Fprintln(out, sum)
	}
}

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

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt()
		arr := sc.nextInts(N)

		count := make(map[int]int)
		for i := 0; i < N; i++ {
			count[arr[i]]++
		}

		maxCnt := 0
		for _, cnt := range count {
			if cnt > maxCnt {
				maxCnt = cnt
			}
		}
		ans := 0
		if N%2 == 1 {
			ans = 1
		}
		if maxCnt > N-maxCnt {
			ans = maxCnt - (N - maxCnt)
		}
		fmt.Fprintln(wr, ans)
	}

}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"io/ioutil"
	"os"
	"runtime"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64
	b := nextByte()
	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}
	return builder.String()
}

func init() {
	runtime.GOMAXPROCS(1)
	if len(os.Args) > 1 && os.Args[1] == "LOCAL_JUDGE" {
		stdin, _ := os.OpenFile("input.txt", os.O_RDONLY|os.O_CREATE, 0666)
		stdout, _ := os.OpenFile("output.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
		os.Stdin = stdin
		os.Stdout = stdout
	}
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
}

type priorityQueue []int

func (pq priorityQueue) Len() int           { return len(pq) }
func (pq priorityQueue) Less(i, j int) bool { return pq[i] > pq[j] }
func (pq priorityQueue) Swap(i, j int)      { pq[i], pq[j] = pq[j], pq[i] }
func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(int))
}
func (pq *priorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	top := old[n-1]
	*pq = old[0 : n-1]
	return top
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt()
		a := make([]int, n)
		cnt := make(map[int]int)
		for i := 0; i < n; i++ {
			a[i] = ScanInt()
			cnt[a[i]]++
		}
		b := make(priorityQueue, 0)
		for _, value := range cnt {
			b = append(b, value)
		}
		heap.Init(&b)
		ans := n
		for len(b) > 1 {
			x, y := heap.Pop(&b).(int), heap.Pop(&b).(int)
			if x == 0 || y == 0 {
				break
			}
			heap.Push(&b, x-1)
			heap.Push(&b, y-1)
			ans -= 2
		}
		fmt.Println(ans)
	}
	return
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

type MaxHeap []int64

func (h MaxHeap) Len() int {
	return len(h)
}

func (h MaxHeap) Less(il, ir int) bool {
	return h[il] > h[ir]
}

func (h MaxHeap) Swap(il, ir int) {
	h[il], h[ir] = h[ir], h[il]
}

func (h *MaxHeap) Push(x interface{}) {
	*h = append(*h, x.(int64))
}

func (h *MaxHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

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

func sol(n int64, a []int64) int64 {
	freqs := map[int64]int64{}
	for _, num := range a {
		freqs[num]++
	}
	h := &MaxHeap{}
	for _, f := range freqs {
		heap.Push(h, f)
	}
	for h.Len() > 1 {
		f1 := heap.Pop(h).(int64)
		f2 := heap.Pop(h).(int64)
		f1--
		f2--
		if f1 > 0 {
			heap.Push(h, f1)
		}
		if f2 > 0 {
			heap.Push(h, f2)
		}
	}
	if h.Len() == 0 {
		return 0
	}
	return heap.Pop(h).(int64)
}

package main

import (
	"fmt"
	"bufio"
	"os"
	"container/heap"
)

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		h := &IntHeap{}
		heap.Init(h)
		freq := map[int]int{}
		for i:=0;i<n;i++ {
			var x int
			fmt.Fscan(in, &x)
			freq[x]++
		}
		for _, f := range freq {
			heap.Push(h, f)
		}
		rem := n
		for h.Len() > 1 {
			a := heap.Pop(h).(int)
			b := heap.Pop(h).(int)
			a--
			b--
			if a > 0 {
				heap.Push(h, a)
			}
			if b > 0 {
				heap.Push(h, b)
			}
			rem -= 2
		}
		fmt.Println(rem)
	}
}

package main

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

var T int
func main() {
    in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	for Fscan(in, &T); T > 0; T-- {
	    var n int
	    set := make(map[int]int)
	    Fscan(in, &n)
	    var s []int
	    for i := 0; i < n; i++ {
	        var x int
	        Fscan(in, &x)
	        set[x]++
	    }
	    sum := 0
	    for _, value := range(set) {
	        s = append(s, value)
	        sum += value
	    }
	    sort.Slice(s, func(i, j int) bool {
		    return s[i] < s[j]
	    })
	    max := s[len(s) - 1]
	    if max > sum - max {
	        Fprintln(out, 2 * max - sum)
	    } else {
	        Fprintln(out, sum % 2)
	    }
	}
}

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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "\n")
		mp := make(map[int64]int)
		for _, i := range arr {
			mp[i]++
		}
		var max int
		max = 0
		for _, v := range mp {
			if max < v {
				max = v
			}
		}

		if max-(n-max) > 0 {
			fmt.Fprintf(out, "%d\n", max-(n-max))
		} else {
			fmt.Fprintf(out, "%d\n", 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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "\n")
		mp := make(map[int64]int64)
		for _, i := range arr {
			mp[i]++
		}
		var max int64
		max = 0
		for _, v := range mp {
			if max < v {
				max = v
			}
		}

		if max-(int64(n)-max) > 0 {
			fmt.Fprintf(out, "%d\n", max-(int64(n)-max))
		} else {
			fmt.Fprintf(out, "%d\n", 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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		// fmt.Fscanf(in, "\n")
		mp := make(map[int64]int64)
		for _, i := range arr {
			mp[i]++
		}
		var max int64
		max = 0
		for _, v := range mp {
			if max < v {
				max = v
			}
		}

		if max-(int64(n)-max) >= 0 {
			fmt.Fprintf(out, "%d\n", max-(int64(n)-max))
		} else {
			fmt.Fprintf(out, "%d\n", 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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "\n")
		mp := make(map[int64]int64)
		for _, i := range arr {
			mp[i]++
		}
		var max int64
		max = 0
		for _, v := range mp {
			if max < v {
				max = v
			}
		}

		if max-(int64(n)-max) >= 0 {
			fmt.Fprintf(out, "%d\n", max-(int64(n)-max))
		} else {
			fmt.Fprintf(out, "%d\n", 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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "\n")
		mp := make(map[int]int)
		for _, i := range arr {
			mp[i]++
		}
		max := 0
		for _, v := range mp {
			if max < v {
				max = v
			}
		}

		if max-(n-max) >= 0 {
			fmt.Fprintf(out, "%d\n", max-(n-max))
		} else {
			fmt.Fprintf(out, "%d\n", 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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "\n")
		mp := make(map[int]int)
		for _, i := range arr {
			mp[i]++
		}
		max := 0
		// fmt.Println(arr)
		// fmt.Println(mp)
		for _, v := range mp {
			if max < v {
				max = v
			}
		}

		if max-(n-max) > 0 {
			fmt.Fprintf(out, "%d\n", max-(n-max))
		} else {
			fmt.Fprintf(out, "%d\n", 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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscanf(in, "%d\n", &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%d", &arr[i])
		}
		fmt.Fscanf(in, "\n")
		mp := make(map[int]int)
		for _, i := range arr {
			mp[i]++
		}
		max := 0
		fmt.Println(arr)
		fmt.Println(mp)
		for _, v := range mp {
			if max < v {
				max = v
			}
		}

		if max-(n-max) > 0 {
			fmt.Fprintf(out, "%d\n", max-(n-max))
		} else {
			fmt.Fprintf(out, "%d\n", 0)
		}
	}
}

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		nums, bucket := make([]int, n), make(map[int]int)
		var keys []int

		for i := range nums {
			Fscan(in, &nums[i])
			if bucket[nums[i]] == 0 {
				keys = append(keys, nums[i])
			}
			bucket[nums[i]]++
		}

		ans, length := 0, len(keys)
		for i, val := range keys {
			if length == 0 {
				break
			}
			ops := min(length - 1, bucket[val])
			bucket[val] -= ops
			if bucket[val] <= 0 {
				length--
			}
			ans += 2 * ops
			for j, cnt := 0, 0; cnt < ops && j < len(keys); j++ {
				if j == i || bucket[keys[j]] == 0 {
					continue
				}
				cnt++; bucket[keys[j]]--
			}
		}
		ans = n - ans
		Fprintln(out, ans)
	}
}

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

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

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)
		nums, bucket := make([]int, n), make(map[int]int)
		var keys []int

		for i := range nums {
			Fscan(in, &nums[i])
			if bucket[nums[i]] == 0 {
				keys = append(keys, nums[i])
			}
			bucket[nums[i]]++
		}

		ans, length := 0, len(keys)
		for i, val := range keys {
			ops := min(length - 1, bucket[val])
			bucket[val] -= ops
			ans += 2 * ops
			for j, cnt := 0, 0; cnt < ops && j < len(keys); j++ {
				if j == i || bucket[keys[j]] == 0 {
					continue
				}
				cnt++; bucket[keys[j]]--
				if bucket[keys[j]] == 0 {
					length--
				}
			}
		}
		ans = n - ans
		Fprintln(out, ans)
	}
}

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

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

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

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}
func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}
func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt()
		arr := sc.nextInts(N)

		count := make(map[int]int)
		for i := 0; i < N; i++ {
			count[arr[i]]++
		}

		maxCnt := 0
		for _, cnt := range count {
			if cnt > maxCnt {
				maxCnt = cnt
			}
		}
		ans := 0
		if maxCnt > N-maxCnt {
			ans = maxCnt - (N - maxCnt)
		}
		fmt.Fprintln(wr, ans)
	}

}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"sort"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
type hp struct{ sort.IntSlice }

func (h hp) Less(i, j int) bool  { return h.IntSlice[i] > h.IntSlice[j] }
func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }
func (h *hp) push(v int)         { heap.Push(h, v) }
func (h *hp) pop() int           { return heap.Pop(h).(int) }
func (h hp) empty() bool         { return len(h.IntSlice) == 0 }
func (h hp) top() int            { return h.IntSlice[0] }

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		cnt := map[int]int{}
		for _, v := range a {
			cnt[v]++
		}
		vs := make([]int, 0, len(cnt))
		for _, v := range cnt {
			vs = append(vs, v)
		}
		h := &hp{vs}
		heap.Init(h)
		for h.Len() > 1 && h.IntSlice[1] > 0 {
			v, w := h.pop(), h.pop()
			h.push(v - 1)
			h.push(w - 1)
		}
		sum := 0
		for _, v := range h.IntSlice {
			sum += v
		}
		Fprintln(out, sum)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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