package main

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

func A4() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		var ans byte
		for i := 0; i < n; i++ {
			var s, t string
			Fscan(in, &s, &t)
			for j := 0; j < len(s); j++ {
				ans ^= s[j]
			}
			for j := 0; j < len(t); j++ {
				ans ^= t[j]
			}
		}
		var fin string
		Fscan(in, &fin)
		for j := 0; j < len(fin); j++ {
			ans ^= fin[j]
		}
		Fprintln(out, string(ans))
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A4() }

package main

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

func Solve(reader *bufio.Reader, testCaseIdx int) {
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscanln(reader, &n)
	f := make(map [rune]int)
	for k := 0; k < 2 * n + 1; k++ {
		var s string
		fmt.Fscanln(reader, &s)
		for _, ch := range s {
			f[ch]++
		}
	}

	for ch, cnt := range f {
		if cnt % 2 == 1 {
			fmt.Fprintf(writer, "%c\n", ch)
			return
		}
	}
}

func main() {
	var testCaseCount int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(reader, t)
	}
}

package main

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

func Solve(reader *bufio.Reader, testCaseIdx int) {
	var n int
	fmt.Fscanln(reader, &n)
	f := make(map [rune]int)
	for k := 0; k < 2 * n + 1; k++ {
		var s string
		fmt.Fscanln(reader, &s)
		for _, ch := range s {
			f[ch]++
		}
	}

	for ch, cnt := range f {
		if cnt % 2 == 1 {
			fmt.Printf("%c\n", ch)
			return
		}
	}
}

func main() {
	var testCaseCount int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscanln(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(reader, t)
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)
		m := make([]int64, 26)
		for i := 0; i < n*2+1; i++ {
			var s string
			fmt.Fscan(in, &s)
			for _, ch := range s {
				m[ch-'a']++
			}
		}

		g := 0
		for i, v := range m {
			if v%2 != 0 {
				g = i
				break
			}
		}
		fmt.Fprintln(out, string(rune(g)+'a'))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
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 }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); sb := ia(26)
		for i:=0;i<=2*N;i++ { s := gs(); for _,c := range s { sb[int(c-'a')]++ } }
		anschar := 'a'; for i:=0;i<26;i++ { if sb[i] % 2 == 1 { anschar = 'a' + rune(i) } }
		ans := string([]rune{anschar})
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	t := make([]string, 2 * n)
	for i := range t {
		fmt.Fscan(r, &t[i])
	}
	var s string
	fmt.Fscan(r, &s)
	m := map[byte]int{}
	for i := range t {
		for tt := range t[i] {
			m[t[i][tt]]++
		}
	}
	for ss := range s {
		m[s[ss]]++
	}
	for k, v := range m {
		if v % 2 == 1 {
			fmt.Fprintln(w, string(k))
			return
		}
	}
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

import (
	"fmt"
)

func Solve(testCaseIdx int) {
	var n int
	fmt.Scanf("%d", &n)
	f := make(map [rune]int)
	for k := 0; k < 2 * n + 1; k++ {
		var s string
		fmt.Scanf("%s", &s)
		for _, ch := range s {
			f[ch]++
		}
	}

	for ch, cnt := range f {
		if cnt % 2 == 1 {
			fmt.Printf("%c\n", ch)
			return
		}
	}
}

func main() {
	var testCaseCount int
	fmt.Scanf("%d", &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t)
	}
}

package main

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

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

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

		arr := make([]string, n*2)
		chs := make([]int, 26)
		for i := 0; i < n*2; i++ {
			fmt.Fscan(in, &arr[i])
			if len(arr[i]) == 1 {
				chs[arr[i][0]-'a']++
			}
		}
		sort.Slice(arr, func(i, j int) bool {
			if len(arr[i]) == len(arr[j]) {
				return arr[i] < arr[j]
			}
			return len(arr[i]) < len(arr[j])
		})
		var z string
		fmt.Fscan(in, &z)

		g := "0"
		for i := range chs {
			if chs[i] == 0 {
				continue
			}
			ch := rune(i + 'a')

			var c0, c1 int
			if strings.HasPrefix(z, string(ch)) {
				c0++
			}

			if strings.HasSuffix(z, string(ch)) {
				c1++
			}

			for _, s2 := range arr {
				if strings.HasPrefix(s2, string(ch)) {
					c0++
				}
				if strings.HasSuffix(s2, string(ch)) {
					c1++
				}
			}

			if c0 > n || c1 > n || c0+c1 == 2 {
				g = string(ch)
			}
		}
		fmt.Fprintln(out, g)
	}
}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; i < n; i++ {
		a := ""
		b := ""
		fmt.Fscanf(in, "%s\n", &a)
		fmt.Fscanf(in, "%s\n", &b)
		o := 0
		p := 0
		ok := true
		for o < len(a) {
			cur := a[o]
			cnt := 1
			for o+1 < len(a) && a[o+1] == a[o] {
				o++
				cnt++
			}
			cntb := 0
			for p < len(b) && b[p] == cur {
				p++
				cntb++
			}
			if cntb < cnt {
				fmt.Fprintf(out, "NO\n")
				ok = false
				break
			}
			o++
		}
		if ok {
			if p != len(b) {
				fmt.Fprintf(out, "NO\n")
			} else {
				fmt.Fprintf(out, "YES\n")
			}
		}
	}
	return
}
func minstep(a, b byte) int {
	return min(int(a-b+26)%26, int(b-a+26)%26)
}

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

package main

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

func main() {

	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)

	var d, cnt, index int
	var st, st1 string

	fmt.Fscanln(scr, &d)

	for d > 0 {
		fmt.Fscanln(scr, &st)
		fmt.Fscanln(scr, &st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if index < len(a) && a[index] == y {
				index++
				b = append(b, y)
			} else if len(b) >= 1 && y == b[len(b)-1] {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Fprintln(ocr, "NO")
		} else if string(a) == string(b) {
			fmt.Fprintln(ocr, "YES")
		} else {
			fmt.Fprintln(ocr, "NO")
		}

		ocr.Flush()

		cnt = 0
		index = 0

		d--
	}
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1185/B

package main

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

type Group struct {
	letter string
	count  int
}

func createGroupList(a string) []Group {
	var answer []Group
	for i := 0; i < len(a); i++ {
		if i == 0 {
			answer = append(answer, Group{letter: string(a[i]), count: 1})
		} else if string(a[i]) != answer[len(answer)-1].letter {
			answer = append(answer, Group{letter: string(a[i]), count: 1})
		} else {
			answer[len(answer)-1].count += 1
		}
	}
	return answer
}

func Solve(a string, b string) string {
	aGroupList := createGroupList(a)
	bGroupList := createGroupList(b)
	if len(aGroupList) != len(bGroupList) {
		return "NO"
	}
	for i := 0; i < len(aGroupList); i++ {
		if (aGroupList[i].count > bGroupList[i].count) || (aGroupList[i].letter != bGroupList[i].letter) {
			return "NO"
		}
	}
	return "YES"
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	var a string
	var b string
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n%s\n", &a, &b)
		fmt.Fprintf(writer, "%s\n", Solve(a, b))
	}
}

package main

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

var DEBUG = false
var reader *bufio.Reader
var writer *bufio.Writer
var f = os.Stdin

func Scanf(format string, a ...interface{}) {
	fmt.Fscanf(reader, format, a...)
}

func Printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

func calc(s, t string) string {
	idx1, idx2, cnt1, cnt2 := 0, 0, 0, 0
	for idx1 < len(s) && idx2 < len(t) {
		c := s[idx1]
		cnt1, cnt2 = 0, 0
		if s[idx1] != t[idx2] {
			return "NO"
		}
		for idx1+cnt1 < len(s) && s[idx1+cnt1] == c {
			cnt1++
		}
		for idx2+cnt2 < len(t) && t[idx2+cnt2] == c {
			cnt2++
		}
		if cnt2 < cnt1 {
			return "NO"
		}
		idx1 += cnt1
		idx2 += cnt2
	}
	if idx2 < len(t) || idx1 < len(s) {
		return "NO"
	}
	return "YES"
}

func main() {
	if DEBUG {
		f, _ = os.Open("input")
	}
	var n int
	var s, t string
	reader = bufio.NewReader(f)
	writer = bufio.NewWriter(os.Stdout)
	Scanf("%d\n", &n)
	for ; n > 0; n-- {
		Scanf("%s\n%s\n", &s, &t)
		Printf("%s\n", calc(s, t))
	}
	writer.Flush()
}

package main

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

var DEBUG = true
var reader *bufio.Reader
var writer *bufio.Writer
var f = os.Stdin

func Scanf(format string, a ...interface{}) {
	fmt.Fscanf(reader, format, a...)
}

func Printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

func calc(s, t string) string {
	idx1, idx2, cnt1, cnt2 := 0, 0, 0, 0
	for idx1 < len(s) && idx2 < len(t) {
		c := s[idx1]
		cnt1, cnt2 = 0, 0
		if s[idx1] != t[idx2] {
			return "NO"
		}
		for idx1+cnt1 < len(s) && s[idx1+cnt1] == c {
			cnt1++
		}
		for idx2+cnt2 < len(t) && t[idx2+cnt2] == c {
			cnt2++
		}
		if cnt2 < cnt1 {
			return "NO"
		}
		idx1 += cnt1
		idx2 += cnt2
	}
	if idx2 < len(t) || idx1 < len(s) {
		return "NO"
	}
	return "YES"
}

func main() {
	if DEBUG {
		f, _ = os.Open("input")
	}
	var n int
	var s, t string
	reader = bufio.NewReader(f)
	writer = bufio.NewWriter(os.Stdout)
	Scanf("%d\n", &n)
	for ; n > 0; n-- {
		Scanf("%s\n%s\n", &s, &t)
		Printf("%s\n", calc(s, t))
	}
	writer.Flush()
}

package main

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

var DEBUG = true
var reader *bufio.Reader
var writer *bufio.Writer
var f = os.Stdin

func Scanf(format string, a ...interface{}) {
	fmt.Fscanf(reader, format, a...)
}

func Printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

func calc(s, t string) string {
	idx1, idx2, cnt1, cnt2 := 0, 0, 0, 0
	for idx1 < len(s) {
		c := s[idx1]
		cnt1, cnt2 = 0, 0
		if s[idx1] != t[idx2] {
			return "NO"
		}
		for idx1+cnt1 < len(s) && s[idx1+cnt1] == c {
			cnt1++
		}
		for idx2+cnt2 < len(t) && t[idx2+cnt2] == c {
			cnt2++
		}
		if cnt2 < cnt1 {
			return "NO"
		}
		idx1 += cnt1
		idx2 += cnt2
	}
	if idx2 < len(t) {
		return "NO"
	}
	return "YES"
}

func main() {
	if DEBUG {
		f, _ = os.Open("input")
	}
	var n int
	var s, t string
	reader = bufio.NewReader(f)
	writer = bufio.NewWriter(os.Stdout)
	Scanf("%d\n", &n)
	for ; n > 0; n-- {
		Scanf("%s\n%s\n", &s, &t)
		Printf("%s\n", calc(s, t))
	}
	writer.Flush()
}

package main

import (
	"fmt"
)

func main() {
	var d, cnt, index int
	var st, st1 string
	fmt.Scanln(&d)

	for d > 0 {
		fmt.Scanln(&st)
		fmt.Scanln(&st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if index < len(a) && a[index] == y {
				index++
				b = append(b, y)
			} else if len(b) >= 1 && y == b[len(b)-1] {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
		cnt = 0
		index = 0

		d--
	}
}

package main

import (
	"fmt"
)

func main() {
	var d, cnt, index int
	var st, st1 string
	fmt.Scanln(&d)

	for d > 0 {
		fmt.Scanln(&st)
		fmt.Scanln(&st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if len(b) > len(a) {
				cnt = 5
				break
			}
			if (index <= len(a)-1) && (a[index] == y) {
				b = append(b, y)
				index++
				continue
			} else if (len(b) > 1) && (y == b[len(b)-1]) {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
		cnt = 0
		index = 0

		d--
	}
}

package main

import (
	"fmt"
)

func main() {
	var d, cnt, index int
	var st, st1 string
	fmt.Scanln(&d)

	for d > 0 {
		fmt.Scanln(&st)
		fmt.Scanln(&st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}

		for _, y := range st1 {
			if len(b) > len(a) {
				cnt = 5
				break
			}
			if (index <= len(a)-1) && (a[index] == y) {
				b = append(b, y)
				index++
				continue
			} else if (len(b) > 1) && (y == b[len(b)-1]) {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Println("NO")
		} else if string(b) == string(a) {
			fmt.Println("YES")
		}
		cnt = 0
		index = 0

		d--
	}
}

package main

import (
	"fmt"
)

func main() {
	var d, cnt, index int
	var st, st1 string
	fmt.Scanln(&d)

	for d > 0 {
		fmt.Scanln(&st)
		fmt.Scanln(&st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if index < len(a) && a[index] == y {
				index++
				b = append(b, y)
			} else if len(b) > 1 && y == b[len(b)-1] {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Println("NO")
		} else {
			fmt.Println("YES")
		}
		cnt = 0
		index = 0

		d--
	}
}

package main

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

func main() {

	scr := bufio.NewReader(os.Stdin)
	ocr := bufio.NewWriter(os.Stdout)

	var d, cnt, index int
	var st, st1 string
	fmt.Fscanln(scr, &d)

	for d > 0 {
		fmt.Fscanln(scr, &st)
		fmt.Fscanln(scr, &st1)
		a := make([]rune, 0)
		b := make([]rune, 0)

		for _, y := range st {
			a = append(a, y)
		}
		if len(st) > len(st1) {
			cnt = 5
		}

		for _, y := range st1 {
			if index < len(a) && a[index] == y {
				index++
				b = append(b, y)
			} else if len(b) >= 1 && y == b[len(b)-1] {
				continue
			} else {
				cnt = 5
				break
			}
		}

		if cnt == 5 {
			fmt.Fprintln(ocr, "NO")
		} else if string(a) == string(b) {
			fmt.Fprintln(ocr, "YES")
		} else {
			fmt.Fprintln(ocr, "NO")
		}

		cnt = 0
		index = 0

		d--
	}
}


package main

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

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var n, m int
	fmt.Fscan(reader, &n, &m)
	f := make([]int, n)
	ff := make([]int, n)
	mx := 0
	for k := 0; k < m; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		ak--
		f[ak]++
		if f[ak] > mx {
			mx = f[ak]
		}
	}

	sort.Ints(f)

	l := 1
	r := mx

	for l < r {
		mid := (l + r) / 2
		copy(ff, f)
		k := 0
		ok := true
		for j := n - 1; j >= 0; j-- {
			for k < j && ff[j] > mid {
				if ff[k] + 2 > mid {
					k++
					continue
				}
				ff[j]--
				ff[k] += 2
			}
			ok = ok && ff[j] <= mid
		}

		if ok {
			r = mid
		} else {
			l = mid + 1
		}
	}

	fmt.Fprintln(writer, r)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var n, m int
	fmt.Fscan(reader, &n, &m)
	f := make([]int, n)
	mx := 0
	for k := 0; k < m; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		ak--
		f[ak]++
		if f[ak] > mx {
			mx = f[ak]
		}
	}

	l := 1
	r := mx

	for l < r {
		mid := (l + r) / 2

		delta := int64(0)
		for k := 0; k < n; k++ {
			if f[k] >= mid {
				delta += int64(f[k] - mid)
			} else {
				delta -= int64(mid - f[k]) / 2
			}
		}

		if delta <= 0 {
			r = mid
		} else {
			l = mid + 1
		}
	}

	fmt.Fprintln(writer, r)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}

package main

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

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

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

	var T int
	var n int
	var m int
	var x int

	for Fscan(in, &T); T > 0; T-- {

		Fscan(in, &n)
		Fscan(in, &m)

		a := make([]int, m)
		d := make([]int, n)
		for i := 0; i < m; i++ {
			Fscan(in, &x)
			a[i] = x
			d[x-1]++
		}
		sort.Ints(d)
		for i := 0; i < len(d)/2; i++ {
			d[i], d[len(d)-1-i] = d[len(d)-1-i], d[i]
		}

		ans := sort.Search(m*2, func(f int) bool {
			t := 0
			for _, v := range d {
				if v >= f {
					t += v - f
				} else {
					t -= (f - v) / 2
				}
				if t <= 0 {
					break
				}
			}
			return t <= 0
		})

		Fprintln(out, ans)
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if v, ok := good[i]; !ok {
			totalTask += (time / 2)
		} else {
			if time <= v {
				totalTask += time
			} else {
				totalTask += (v + (time-v)/2)
			}
		}
		if totalTask >= m {
			return true
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

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

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

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

		aa := make([]int, m)
		bb := make([]int, n)
		for i := 0; i < m; i++ {
			var v int
			fmt.Fscan(in, &v)
			aa[i] = v
			bb[v-1]++
		}
		sort.Slice(bb, func(i, j int) bool {
			return bb[i] > bb[j]
		})

		resp := sort.Search(m*2, func(i int) bool {
			t := 0
			for _, v := range bb {
				if v >= i {
					t += v - i
				} else {
					t -= (i - v) / 2
				}
				if t <= 0 {
					break
				}
			}
			return t <= 0
		})
		fmt.Fprintln(out, resp)
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	worker := make([]int, n)
	for i:=0;i<m;i++ {
		var w int
		fmt.Fscan(rr, &w)
		worker[w-1]++
	}
	fmt.Fprintln(ww, sort.Search(2*m+1, func(t int) bool {
		var ans int64
		for i := range worker {
			remain := int64(t - worker[i])
			if remain >= 0 {
				ans += remain/2
			} else {
				ans += remain
			}
		}
		return ans >= 0
	}))
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if v, ok := good[i]; !ok {
			totalTask += (time / 2)
		} else {
			if time <= v {
				totalTask += time
			} else {
				totalTask += (v + (time-v)/2)
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if v, ok := good[i]; !ok {
			totalTask = totalTask + (time / 2)
		} else {
			if time <= v {
				totalTask += time
			} else {
				totalTask += v + (time-v)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if v, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			if time <= v {
				totalTask += time
			} else {
				totalTask += v + (time-v)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

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

	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

func possible(n int, m int, good map[int]int, time int) bool {
	totalTask := 0

	for _, v := range good {
		if time <= v {
			totalTask += time
		} else {
			totalTask += v + (time-v)/2
		}
	}
	totalTask += (time / 2) * (n - len(good))

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

func main() {
	inp := bufio.NewReader(os.Stdin)
	var test int
	fmt.Fscanln(inp, &test)

	for test > 0 {
		test--

		var n, m int
		fmt.Fscanln(inp, &n, &m)
		good := map[int]int{}

		for i := 0; i < m; i++ {
			var work int
			if i == m-1 {
				fmt.Fscanf(inp, "%d\n", &work)
			} else {
				fmt.Fscanf(inp, "%d", &work)
			}
			if _, ok := good[work]; !ok {
				good[work] = 0
			}
			good[work]++
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

import (
	"fmt"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

func main() {
	var test int
	fmt.Scanln(&test)

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var work int
			fmt.Scan(&work)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

import (
	"fmt"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

func main() {
	var test int
	fmt.Scanln(&test)
	res := []int{}

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var work int
			fmt.Scan(&work)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		res = append(res, solve(n, m, good))
	}

	for _, v := range res {
		fmt.Println(v)
	}
}

package main

import (
	"fmt"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	fmt.Println(n, m, good)
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

func main() {
	var test int
	fmt.Scanln(&test)

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var work int
			fmt.Scanf("%d", &work)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

import (
	"fmt"
	"strconv"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	fmt.Println(n, m, good)
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

func main() {
	var test int
	fmt.Scanln(&test)

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var tmp string
			fmt.Scan(&tmp)
			work, _ := strconv.Atoi(tmp)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

import (
	"fmt"
	"strconv"
)

func possible(n int, m int, good map[int][]int, time int) bool {
	totalTask := 0

	for i := 1; i <= n; i++ {
		if _, ok := good[i]; !ok {
			totalTask += time / 2
		} else {
			best := len(good[i])
			if time <= best {
				totalTask += time
			} else {
				totalTask += best + (time-best)/2
			}
		}
	}

	if totalTask >= m {
		return true
	}
	return false
}

func solve(n int, m int, good map[int][]int) int {
	left := 0
	right := 2 * m
	res := right

	for left <= right {
		mid := left + (right-left)/2

		if possible(n, m, good, mid) {
			res = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}

	return res
}

func main() {
	var test int
	fmt.Scanln(&test)

	for test > 0 {
		test--

		var n, m int
		fmt.Scanln(&n, &m)
		good := map[int][]int{}

		for i := 0; i < m; i++ {
			var tmp string
			fmt.Scan(&tmp)
			work, _ := strconv.Atoi(tmp)
			if _, ok := good[work]; !ok {
				good[work] = []int{}
			}
			good[work] = append(good[work], i)
		}

		fmt.Println(solve(n, m, good))
	}
}

package main

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

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

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

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

		mm := make(map[int]int, n)
		for i := 0; i < m; i++ {
			var v int
			fmt.Fscan(in, &v)
			mm[v]++
		}

		var tot int
		var idle int
		for m > 0 {
			size := len(mm)
			for k := range mm {
				d := min(mm[k]-1, idle)
				mm[k] -= 1 + d
				m -= 1 + d
				idle -= d
				if mm[k] == 0 {
					delete(mm, k)
				}
			}
			idle = n - size
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		mm := make(map[int]int, n)
		for i := 0; i < m; i++ {
			var v int
			fmt.Fscan(in, &v)
			mm[v]++
		}

		var tot int
		var idle int
		for m > 0 {
			size := len(mm)
			for k := range mm {
				d := min(mm[k]-1, idle)
				mm[k] -= 1 + d
				m -= 1 + d

				if mm[k] == 0 {
					delete(mm, k)
				}
			}
			idle = n - size
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		mm := make(map[int]int, n)
		for i := 0; i < m; i++ {
			var v int
			fmt.Fscan(in, &v)
			mm[v]++
		}

		var tot int
		var idle int
		for m > 0 {
			size := len(mm)
			for k := range mm {
				d := min(mm[k]-1, idle)
				mm[k] -= 1 + d
				m -= 1 + d

				if mm[k] == 0 {
					delete(mm, k)
				}
			}
			idle = size
			tot++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		mm := make(map[int]int, n)
		for i := 0; i < m; i++ {
			var v int
			fmt.Fscan(in, &v)
			mm[v]++
		}

		var tot int
		for m > 0 {
			var idle int
			for i := 1; i <= n; i++ {
				if mm[i] <= 0 {
					idle++
				}
			}

			var f bool
			for i := 1; i <= n; i++ {
				if idle > 0 && mm[i] > 2 {
					d := min(mm[i]-2, idle)
					idle -= d
					mm[i] -= 2 + d
					f = true
					m -= 2 + d
				} else if (idle > 0 || f) && mm[i] == 2 {
					mm[i] -= 2
					m -= 2
					f = true
				} else if mm[i] > 0 {
					mm[i]--
					m--
				}
			}
			tot++
			if f {
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		mm := make(map[int]int, n)
		for i := 0; i < m; i++ {
			var v int
			fmt.Fscan(in, &v)
			mm[v]++
		}

		var tot int
		for m > 0 {
			var idle int
			for i := 1; i <= n; i++ {
				if mm[i] <= 0 {
					idle++
				}
			}

			var f bool
			for i := 1; i <= n; i++ {
				if idle > 0 && mm[i] > 2 {
					d := min(mm[i]-2, idle)
					idle -= d
					mm[i] -= 2 + d
					f = true
					m -= 2 + d
				} else if idle > 0 && mm[i] == 2 {
					mm[i] -= 2
					m -= 2
					f = true
				} else if mm[i] > 0 {
					mm[i]--
					m--
				}
			}
			tot++
			if f {
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

		mm := make(map[int]int, n)
		for i := 0; i < m; i++ {
			var v int
			fmt.Fscan(in, &v)
			mm[v]++
		}

		var tot int
		for m > 0 {
			var idle int
			for i := 1; i <= n; i++ {
				if mm[i] <= 0 {
					idle++
				}
			}

			var f bool
			for i := 1; i <= n; i++ {
				if idle > 0 && mm[i] > 2 {
					idle--
					mm[i] -= 3
					f = true
					m -= 3
				} else if idle > 0 && mm[i] == 2 {
					mm[i] -= 2
					m -= 2
					f = true
				} else if mm[i] > 0 {
					mm[i]--
					m--
				}
			}
			tot++
			if f {
				tot++
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	worker := make([]int, n)
	for i:=0;i<m;i++ {
		var w int
		fmt.Fscan(rr, &w)
		worker[w-1]++
	}
	fmt.Fprintln(ww, sort.Search(2*m+1, func(t int) bool {
		ans := 0
		for i := range worker {
			remain := t - worker[i]
			if remain >= 0 {
				ans += remain/2
			} else {
				ans += remain
			}
		}
		return ans >= 0
	}))
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	worker := make([]int, n)
	for i:=0;i<m;i++ {
		var w int
		fmt.Fscan(rr, &w)
		worker[w-1]++
	}
	fmt.Fprintln(ww, sort.Search(m+1, func(t int) bool {
		ans := 0
		for i := range worker {
			remain := t - worker[i]
			if remain >= 0 {
				ans += remain/2
			} else {
				ans += remain
			}
		}
		return ans >= 0
	}))
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

var rr = bufio.NewReader(os.Stdin)
var ww = bufio.NewWriter(os.Stdout)

func slove() {
	var n, m int
	fmt.Fscan(rr, &n, &m)
	worker := make([]int, n)
	for i:=0;i<m;i++ {
		var w int
		fmt.Fscan(rr, &w)
		worker[w-1]++
	}
	fmt.Fprintln(ww, sort.Search(2e5+1, func(t int) bool {
		ans := 0
		for i := range worker {
			remain := t - worker[i]
			if remain >= 0 {
				ans += remain/2
			} else {
				ans += remain
			}
		}
		return ans >= 0
	}))
}

func main() {
	defer ww.Flush()
	var n int
	fmt.Fscan(rr, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

func Solve(testCaseIdx int, reader io.Reader, writer io.Writer) {
	var n, m int
	fmt.Fscan(reader, &n, &m)
	f := make([]int, n)
	mx := 0
	for k := 0; k < m; k++ {
		var ak int
		fmt.Fscan(reader, &ak)
		ak--
		f[ak]++
		if f[ak] > mx {
			mx = f[ak]
		}
	}

	sort.Ints(f)

	l := 1
	r := mx

	for l < r {
		mid := (l + r) / 2

		delta := 0
		for k := 0; k < n; k++ {
			if f[k] >= mid {
				delta += f[k] - mid
			} else {
				delta -= (mid - f[k]) / 2
			}
		}

		if delta <= 0 {
			r = mid
		} else {
			l = mid + 1
		}
	}

	fmt.Fprintln(writer, r)
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var testCaseCount int
	fmt.Fscan(reader, &testCaseCount)
	for t := 0; t < testCaseCount; t++ {
		Solve(t, reader, writer)
	}
}


/*
Tram
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.

Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.

Input
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.

Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.

The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.
At the last stop, all the passengers exit the tram and it becomes empty. More formally, .
No passenger will enter the train at the last stop. That is, bn = 0.
Output
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

Sample test(s)
input
4
0 3
2 5
4 2
4 0
output
6
Note
For the first example, a capacity of 6 is sufficient:

At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.
At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now.
At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now.
Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
*/

package main

import (
	"fmt"
	"os"
)

func main() {
	var (
		n, a, b, curCap, maxCap int
	)
	fmt.Fscanf(os.Stdin, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(os.Stdin, "%d %d\n", &a, &b)
		curCap += b - a
		if curCap > maxCap {
			maxCap = curCap
		}
	}
	fmt.Println(maxCap)
}

package main

import "fmt"

func main() {

	var number int = 0
	_, _ = fmt.Scanln(&number)
	 var matrix = make([][2]int,number)

	 var max,min = 0,0

	 for i:=0; i<number; i++ {
		 _, _ = fmt.Scan(&matrix[i][0])
		 _, _ = fmt.Scan(&matrix[i][1])
		 min =  matrix[i][1] - matrix[i][0] + min
		if min > max {
			max = min
		}
	 }
	 fmt.Println(max)
}

package main

import "fmt"

func main(){
	var n int
	fmt.Scanf("%d", &n)
	prevStepPop := 0
	var maxCap int = 0
	for i:=0;i<n;i++{
		var a, b int
		fmt.Scan(&a)
		fmt.Scan(&b)
		b = b - a
		prevStepPop = prevStepPop + b
		if prevStepPop > maxCap{
			maxCap = prevStepPop
		}
	}
	fmt.Println(maxCap)
}

package main

import "fmt"

func main() {
	var n, a, b, z, m int

	fmt.Scan(&n)

	for i := 0; i < n; i++{
		fmt.Scan(&a, &b)
		b = b - a
		z = z + b
		if m < z {
			m = z
		}
	}
	fmt.Println(m)
}

package main

import (
    "fmt"
    //"math"
)

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

func main(){
    var (
        a,b,n,res int
    )
    res = 0
    temp := 0
    fmt.Scan(&n)
    for n>0 {
        fmt.Scan(&a,&b)
        res = res-a+b
        temp = max(temp,res)
        n--
    }
    fmt.Println(temp)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	cap := 0
	res := 0
	for i := 0; i < n; i++ {
		var out int
		var in int
		fmt.Scanf("%d %d\n", &out, &in)
		cap -= out
		cap += in
		res = int(math.Max(float64(res), float64(cap)))
	}

	fmt.Println(res)
}

package main
import (
	"fmt"
)
func main() {
	var n,a,b int
	c,m :=0,0
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		fmt.Scan(&a,&b)
		c-=a
		c+=b
		if c>m {
			m=c
		}
	}
	fmt.Println(m)

}

package main

import "fmt"

func main() {
	var stops int
	tram := 0
	max := 0
	fmt.Scan(&stops)

	for i := 0; i < stops; i++ {
		var exit, enter int
		fmt.Scan(&exit)
		tram -= exit
		fmt.Scan(&enter)
		tram += enter
		if tram > max {
			max = tram
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n, a, b, rs, cur int
	fmt.Scan(&n)
	fmt.Scan(&a, &b)
	rs, cur = a+b, a+b
	for ; n > 1; n-- {
		fmt.Scan(&a, &b)
		cur = cur - a + b
		if cur < 0 {
			cur = 0
		}
		if cur > rs {
			rs = cur
		}
	}
	fmt.Println(rs)
}

package main

import "fmt"

func main() {
	var n, x, y, cap, currentPassenger int
	fmt.Scan(&n, &currentPassenger, &currentPassenger)
	cap = currentPassenger
	for i := 1; i < n; i++ {
		fmt.Scan(&x, &y)
		currentPassenger = currentPassenger - x + y
		if currentPassenger > cap {
			cap = currentPassenger
		}
	}
	fmt.Println(cap)
}

package main

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

var scanner *bufio.Scanner

func getI() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  n := getI()
  max, current := int64(0), int64(0)
  for i := int64(0); i < n; i++ {
    a, b := getI(), getI()
    current += b-a
    if current > max {
      max = current
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", max))
}

package main

import (
	"fmt"
)

//import "strings"

//import "math"
//import "strconv"
//import "sort"

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

func main() {

	var n int

	fmt.Scan(&n)

	cur := 0
	mx := -100000
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scan(&a, &b)

		cur -= a
		cur += b

		mx = max(mx, cur)

	}
	fmt.Println(mx)
}

package main

import (
  "fmt"
)

func main() {
  var n, a, b, max, cur int
  fmt.Scan(&n)
  for i := 0; i < n; i++ {
    fmt.Scan(&a,&b)
    cur = (cur-a)+b
    if max<cur {
      max = cur
    }
  }
  fmt.Print(max)
}

package main

import "fmt"

func main() {
	tramStops, currentAmount := 0, 0
	minimumCapacity := 0
	fmt.Scanf("%d\n", &tramStops)
	for i := 0; i < tramStops; i++ {
		left, arrivals := 0, 0
		fmt.Scanf("%d %d\n", &left, &arrivals)

		currentAmount -= left
		currentAmount += arrivals

		if currentAmount > minimumCapacity {
			minimumCapacity = currentAmount
		}
	}

	if currentAmount < 0 {
		currentAmount = 0
	}

	fmt.Println(minimumCapacity)
}

package main

import "fmt"

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

	var a, b, c, capacity int
	for i:=0; i<n; i++ {
		fmt.Scan(&a, &b)
		c += b - a
		if c > capacity {capacity = c}
	}
	fmt.Println(capacity)
}

package main

import "fmt"

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

	var p, max int
	var in, out int
	for i := 0; i < n; i++ {
		fmt.Scan(&out, &in)
		p += in - out
		if p > max {
			max = p
		}
	}

	fmt.Print(max)
}

package main

import (
	"fmt"
)

func main() {
	var n, x, y, in int
	fmt.Scanln(&n)
	max := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &x, &y)
		if i == 0 {
			in = y
			max = y
		} else {
			in = in - x + y
			if in > max {
				max = in
			}
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n, in, out int
	fmt.Scanf("%d\n", &n)
	count := 0
	max := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &out, &in)
		count = count - out + in
		if max < count {
			max = count
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var busCapacity, busSize int
	for i := 0; i < n; i++ {
		var out, in int
		fmt.Scan(&out, &in)
		busSize += in - out
		if busSize > busCapacity {
			busCapacity = busSize
		}
	}
	fmt.Println(busCapacity)
}

package main

import (
	"fmt"
)

func main() {
	var n, ans, num, a, b int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b)
		num -= a
		num += b
		if num > ans {
			ans = num
		}
	}
	fmt.Print(ans)
}

package main

import (
	"fmt"
)

func main() {
	a116()
}

func a116() {
	var (
		a, b, n, load, maxLoad int
	)

	_, _ = fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Scanf("%d %d\n", &a, &b)
		if i == 0 {
			load, maxLoad = b, b
			continue
		}
		load = load - a + b
		if load > maxLoad {
			maxLoad = load
		}
	}

	fmt.Println(maxLoad)
}

package main

import "fmt"

func main() {
  var n int
  fmt.Scan(&n)
  res := 0
  cur := 0
  for i := 0; i < n; i++ {
    var a, b int
    fmt.Scan(&a, &b)
    cur += b - a
    if cur > res {
      res = cur
    }
  }
  fmt.Println(res)
}

package main

import "fmt"

func main() {
	var n, x, y, z, m int

	fmt.Scan(&n)

	for i := 0; i < n; i++{
		fmt.Scan(&x, &y)
		y = y - x
		z = z + y
		if m < z {
			m = z;
		}
	}
	fmt.Println(m)
}

package main

import "fmt"

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

func main() {
    var n,a,b int
    fmt.Scan(&n)
    ans, total := 0, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&a,&b)
        total -= a
        ans = max(ans,total)
        total += b
        ans = max(ans,total)
    }
    fmt.Println(ans)
}

package main

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

func main() {
	var scanner *bufio.Scanner
	var stops int
	var exits, enters int
	var line []string
	var capacity, maxCapacity int

	capacity = 0
	scanner = bufio.NewScanner(os.Stdin)

	fmt.Scanln(&stops)
	for i := 0; i < stops; i++ {
		if scanner.Scan() {
			line = strings.Fields(scanner.Text())
			exits, _ = strconv.Atoi(line[0])
			enters, _ = strconv.Atoi(line[1])

			capacity += (enters - exits)
			if capacity > maxCapacity {
				maxCapacity = capacity
			}
		}
	}

	fmt.Println(maxCapacity)
}

package main

import (
	"fmt"
)

var (
	n      int
	a      []int
	b      []int
	result int = 0
)

func in() {
	fmt.Scanln(&n)
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &a[i], &b[i])
	}
}

func out() {
	fmt.Println(result)
}

func run() {
	curr := 0
	for i := 0; i < n; i++ {
		curr += b[i] - a[i]
		if curr > result {
			result = curr
		}
	}
}

func main() {
	in()
	run()
	out()
}

//A. Трамвай
package main

import (
	"fmt"
)

func main() {
	var n, a, b, max, buf int
	fmt.Scan(&n)
	fmt.Scan(&a, &b)
	max, buf = b, b
	for i := 2; i <= n; i++ {
		fmt.Scan(&a, &b)
		buf = buf - a + b
		if max < buf {
			max = buf
		}
	}

	fmt.Print(max)
}

package main

import "fmt"

func main() {
	var st, s, i, m int
	fmt.Scan(&st)
	for i < st {
		var a, b int
		fmt.Scan(&a)
		fmt.Scan(&b)
		s = s - a
		s = s + b
		if m < s {
			m = s
		}
		i++
	}
	fmt.Println(m)
}

/* https://codeforces.com/problemset/problem/116/A
A. Tram
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.

Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.

Input
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.

Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.

The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.
At the last stop, all the passengers exit the tram and it becomes empty. More formally, .
No passenger will enter the train at the last stop. That is, bn = 0.
Output
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

Examples
inputCopy
4
0 3
2 5
4 2
4 0
outputCopy
6
Note
For the first example, a capacity of 6 is sufficient:

At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.
At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now.
At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now.
Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
*/

package main

import "fmt"

func main() {
	var n, a, b, capacity, min int
	fmt.Scanln(&n)

	for i := 0; i < n; i++ {
		fmt.Scanln(&a, &b)
		capacity -= a
		capacity += b
		if capacity > min {
			min = capacity
		}
	}
	fmt.Println(min)
}

/* https://codeforces.com/problemset/problem/116/A
A. Tram
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.

Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.

Input
The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.

Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.

The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.
At the last stop, all the passengers exit the tram and it becomes empty. More formally, .
No passenger will enter the train at the last stop. That is, bn = 0.
Output
Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

Examples
inputCopy
4
0 3
2 5
4 2
4 0
outputCopy
6
Note
For the first example, a capacity of 6 is sufficient:

At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.
At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now.
At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now.
Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints.
Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.
*/

package main

import "fmt"

func main() {
	var n, a, b, capacity, min int
	fmt.Scanln(&n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &a, &b)
		capacity -= a
		capacity += b
		if capacity > min {
			min = capacity
		}
	}
	fmt.Println(min)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	// Skip the number of stops.
	scanner.Scan()

	// Tram capacity.
	cap := 0
	// Max capacity.
	max := cap
	var in, out int
	for scanner.Scan() {
		if _, err := fmt.Sscanf(scanner.Text(), "%d %d", &in, &out); err != nil {
			continue
		}
		cap -= in
		cap += out
		if cap > max {
			max = cap
		}
	}
	fmt.Println(max)
}

package main
import (
	"fmt"
)
func main() {
	var n,a,b int
	c,m :=0,0
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		fmt.Scan(&a,&b)
		c-=a
		c+=b
		if c>m {
			m=c
		}
	}
	fmt.Println(m)

}

package main

import (
	"fmt"
)

func main() {
	var num int
	fmt.Scanf("%d\n", &num)
	max := 0
	curr := 0
	var indoor, outdoor int
	for i := 0; i < num; i++ {
		fmt.Scanf("%d %d\n", &outdoor, &indoor)
		curr -= outdoor
		curr += indoor
		if curr > max {
			max = curr
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var currentMax int
	var current int
	var stopNumber int
	fmt.Scan(&stopNumber)
	for offset := 0; offset < stopNumber; offset++ {
		var out, in int
		fmt.Scan(&out, &in)
		diff := in - out

		current += diff

		if current > currentMax{
			currentMax = current
		}

	}
	fmt.Print(currentMax)
}

package main

import "fmt"

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

	var c, maxc = 0, 0

	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scan(&a, &b)

		c += b - a
		if c > maxc {
			maxc = c
		}
	}

	fmt.Println(maxc)
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	n := nextInt(s)

	max := 0
	people := 0
	for i := 0; i < n; i++ {
		a := nextInt(s)
		b := nextInt(s)
		people = people - a + b
		if people > max {
			max = people
		}
	}

	fmt.Println(max)
}

func reverse(xs []rune) {
	for i, j := 0, len(xs)-1; i < j; i, j = i+1, j-1 {
		xs[i], xs[j] = xs[j], xs[i]
	}
}

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

func toLower(x byte) byte {
	return x + ('a' - 'A')
}

func isUpper(x byte) bool {
	return x >= 'A' && x <= 'Z'
}

func initArray(n, x int) []int {
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = x
	}
	return xs
}

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

package main
import "fmt"
func main () {
    var n, in, out int
    c:=0
    m:=0
    fmt.Scan(&n)
    for i:=0; i<n;i++ {
        fmt.Scan(&out,&in)
        c=c-out+in
        if (m<c) {
            m=c
        }
    }
    fmt.Println(m)
}

package main

import "fmt"

func main() {
	var stopsNum, exit, enter, current, high_time int
	fmt.Scan(&stopsNum)
	for i := 0; i < stopsNum; i++ {

		fmt.Scan(&exit, &enter)
		current -= exit
		current += enter

		if current > high_time {
			high_time = current
		}

	}

	fmt.Print(high_time)

	return

}

package main

import "fmt"

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

	caps := 0
	left := 0
	var u, v int
	for i := 0; i < n; i++ {
		fmt.Scan(&u, &v)
		left += (v - u)
		if left > caps {
			caps = left
		}
	}

	fmt.Print(caps)
}

package main

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

var n int

func main() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader := bufio.NewReaderSize(stdin, 1<<20)
	fmt.Fscanf(reader, "%d\n", &n)
	sum := 0
	ans := 0
	for ; n != 0; n-- {
		var a, b int
		fmt.Fscanf(reader, "%d%d\n", &a, &b)
		sum += b - a
		if sum > ans {
			ans = sum
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint32
	var a, b uint32
	var cb uint32
	var max uint32
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; uint32(i) < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		cb -= a
		cb += b
		if cb > max {
			max = cb
		}
	}
	fmt.Println(max)
}

package main

import (
	"fmt"
)

func main() {
	var t, a, b, max, p int
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&a, &b)
		p += b - a
		if p > max {
			max = p
		}
		t--
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var cur, max int
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		cur += b - a
		if cur > max {
			max = cur
		}
	}
	fmt.Print(max)
}

package main

import (
	"fmt"
)

func main() {
	var n, p, q, aux, min int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&p, &q)
		aux -= p
		aux += q
		if aux > min {
			min = aux
		}
	}
	fmt.Println(min)
}

package main

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

func cf116A(in io.Reader, out io.Writer) {
	var n, capacity, occupancy int
	capacity = 0
	occupancy = 0
	fmt.Fscan(in, &n)
	// fmt.Print(k, n, w)
	for n != 0 {
		n--
		var inbound, outbound int
		fmt.Fscan(in, &outbound, &inbound)
		occupancy = occupancy + inbound - outbound
		if occupancy > capacity {
			capacity = occupancy
		}

	}

	fmt.Println(capacity)

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

package main

import (
        "fmt"
)

func main() {
        n := 0
        cur := 0
        max := 0
        fmt.Scan(&n)
        for i := 0; i < n; i++ {
                a, b := 0, 0
                fmt.Scan(&a, &b)
                cur -= a
                cur += b
                if cur > max {
                        max = cur
                }
        }
        fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n int
	max := 0
	num := 0

	fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)

		num += -a + b
		if num > max {
			max = num
		}
	}

	fmt.Printf("%d", max)
}

package main

import "fmt"

func main() {
	var n, a, b, tmp, res int
	fmt.Scan(&n)
	for i := 0; i < n; i ++ {
		fmt.Scan(&a, &b)
		b -= a
		tmp += b
		if res < tmp {
			res = tmp
		}
	}
	fmt.Println(res)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	_ = scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	currentCapacity, maxCapacity := 0, 0

	for i := 0; i < n; i++ {
		_ = scanner.Scan()
		line := scanner.Text()
		splitted := strings.Split(line, " ")
		out, _ := strconv.Atoi(splitted[0])
		in, _ := strconv.Atoi(splitted[1])
		currentCapacity = currentCapacity - out + in
		if currentCapacity > maxCapacity {
			maxCapacity = currentCapacity
		}
	}
	fmt.Println(maxCapacity)

}

package main

import "fmt"

type stop_diff struct {
	pout int
	pin  int
}

func task_solution(in []stop_diff) (ans int) {
	size := 0
	for i := 0; i < len(in); i += 1 {
		size += in[i].pin - in[i].pout
		if ans < size {
			ans = size
		}
	}
	return ans
}

func main() {
	var n int
	_, err := fmt.Scan(&n)
	if err != nil {
		panic(err)
	}

	in := []stop_diff{}
	for i := 0; i < n; i += 1 {
		var pout, pin int
		_, err := fmt.Scan(&pout, &pin)
		if err != nil {
			panic(err)
		}
		in = append(in, stop_diff{pout, pin})
	}

	fmt.Println(task_solution(in))
}

package main

import "fmt"

func main() {
	var n int
	ans := 0
	sisa := 0
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var x, y int
		fmt.Scan(&x, &y)
		sisa -= x
		sisa += y
		if sisa > ans {
			ans = sisa
		}
	}
	fmt.Println(ans)
}

package main

// https://codeforces.com/problemset/problem/116/A

import "fmt"

type stop_diff struct {
	pout int
	pin  int
}

func task_solution(in []stop_diff) (ans int) {
	size := 0
	for i := 0; i < len(in); i += 1 {
		size += in[i].pin - in[i].pout
		if ans < size {
			ans = size
		}
	}
	return ans
}

func main() {
	var n int
	if _, err := fmt.Scan(&n); err != nil {
		panic(err)
	}

	in := []stop_diff{}
	for i := 0; i < n; i += 1 {
		var pout, pin int
		if _, err := fmt.Scan(&pout, &pin); err != nil {
			panic(err)
		}
		in = append(in, stop_diff{pout, pin})
	}

	fmt.Println(task_solution(in))
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/116/A

package main

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

type Stop struct {
	Ai int
	Bi int
}

func Solve(n int, stops []Stop) int {
	capacity := 0
	maxCapacity := 0
	for _, s := range stops {
		capacity -= s.Ai
		capacity += s.Bi
		if capacity > maxCapacity {
			maxCapacity = capacity
		}
	}
	return maxCapacity
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	stops := make([]Stop, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &stops[i].Ai, &stops[i].Bi)
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, stops))
}

package main

import (
	"fmt"
)

func main() {
	var n, a, b int
	fmt.Scanln(&n)

	current := 0
	max := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &a, &b)
		current -= a
		current += b
		if current > max {
			max = current
		}
	}

	fmt.Println(max)
}

package main

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

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

func main() {
	cin := bufio.NewReader(os.Stdin)
	cout := bufio.NewWriter(os.Stdout)
	defer cout.Flush()
	var n, a, b int
	result := 0
	cur := 0
	fmt.Fscan(cin, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(cin, &a, &b)
		cur -= a
		cur += b
		result = max(result, cur)
	}
	fmt.Fprintln(cout, result)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var current = 0
	var max = 0
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		current += b - a
		if current > max {
			max = current
		}
	}
	fmt.Println(max)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var a, b int
	var maxPersons, currentPersons int
	maxPersons = 0
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &a, &b)
		currentPersons -= a
		currentPersons += b
		if currentPersons > maxPersons {
			maxPersons = currentPersons
		}
	}
	fmt.Println(maxPersons)
}

package main

import (
	"fmt"
)

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

	max := 0
	now := 0

	var out int
	var in int

	for i := 0; i < n; i++ {

		_, err := fmt.Scanf("%d %d", &out, &in)

		if err != nil {
			i--
			continue
		}

		now = now - out + in

		if now > max {
			max = now
		}
	}
	fmt.Println(max)
}

package main

import (
	"fmt"
	"math"
)

// 4 stop
// 0 3 exit-enter
// 2 5
// 4 2
// 4 0
func main() {

	var stops int
	fmt.Scanln(&stops)
	var ans, cap float64 = 0, 0
	var x, y int
	for i := 1; i <= stops; i++ {
		fmt.Scanf("%d %d\n", &x, &y)
		cap = cap + float64(y) - float64(x)
		ans = math.Max(cap, ans)
	}
	fmt.Println(int(ans))
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	tot := 0
	max := 0
	for i := 0; i < t; i++ {
		var tm int
		fmt.Scan(&tm)
		tot -= tm

		fmt.Scan(&tm)
		tot += tm

		if max < tot {
			max = tot
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
    var n int
    fmt.Scan(&n)
    var m, cur int
    m = 0
    cur = 0
    for i := 0; i < n; i++ {
        var leave, enter int
        fmt.Scan(&leave, &enter)
        cur -= leave
        cur += enter
        if m < cur {
            m = cur
        }
    }

    fmt.Println(m)
}

//  URL: http://codeforces.com/problemset/problem/116/A
//  ~ Basic Implementation Problem

package main

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

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var a, b, capacity, maxCapacity, n int
	fmt.Fscanf(reader, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &a, &b)
		capacity += (b - a)
		if capacity > maxCapacity {
			maxCapacity = capacity
		}
	}
	fmt.Fprintf(writer, "%d\n", maxCapacity)
}

package main
import (
	"fmt"
)
func main() {
	var n,a,b int
	c,m :=0,0
	fmt.Scan(&n)
	for i:=0; i<n; i++ {
		fmt.Scan(&a,&b)
		c-=a
		c+=b
		if c>m {
			m=c
		}
	}
	fmt.Println(m)

}

package main

import "fmt"

func main() {
    var n, a, b int
    c := 0
    d := 0
    fmt.Scan(&n)
    for i := 0; i < n; i ++ {
        fmt.Scan(&a, &b)
        c += b - a
        if d < c {
            d = c
        }
    }
    fmt.Println(d)
}

package main

import (
    "fmt"
    )

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

    cap := 0
    rem := 0
    for i := 0; i < n ; i++ {
       var a, b int
       fmt.Scan(&b, &a)
       rem = (rem - b) + a
       if cap < rem {
           cap = rem
       }
    }

    fmt.Println(cap)
}

package main

import (
	"fmt"
)

func main() {
	var stop, turun, naik, max, tram int
	max = 0
	tram = 0
	fmt.Scan(&stop)
	for i := 0; i < stop; i++ {
		fmt.Scan(&turun)
		fmt.Scan(&naik)
		tram -= turun
		tram += naik
		if max < tram {
			max = tram
		}
	}
	fmt.Print(max)
}

// olymp
package main

import (
	"fmt"
)

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

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	cur, mx := 0, 0
	for i := 0; i < n; i++ {
		var in, out int
		fmt.Scanf("%d %d\n", &out, &in)
		cur += in - out
		mx = max(cur, mx)
	}
	fmt.Println(mx)
}

// 10.CodeForce 116A-Michael542
package main

import (
    "fmt"
)

func main() {
    var n, in, out, total, max int
    fmt.Scan(&n)
    for x := 0; x < n; x++ {
        fmt.Scan(&out, &in)
        total -= out
        total += in
        if total > max {
            max = total
        }
    }
    fmt.Println(max)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	//n, _ := strconv.Atoi(scanner.Text())
	max := 0
	cap := 0
	for scanner.Scan() {
		in := strings.Split(scanner.Text(), " ")
		a, _ := strconv.Atoi(in[0])
		b, _ := strconv.Atoi(in[1])
		cap -= a
		cap += b
		if cap > max {
			max = cap
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var testcount, a, b, count, max int
	fmt.Scanf("%d\n", &testcount)
	for i := 0; i < testcount; i++ {
		fmt.Scanf("%d %d\n", &a, &b) //а выходят, b заходят
		count = count - a
		count = count + b
		if max < count {
			max = count
		}
	}
	fmt.Println(max)
}

//
// Created by aldair on 21/10/20.
// https://codeforces.com/problemset/problem/116/A
//

package main

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

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

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

func main() {
	defer writer.Flush()

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

	var exit, enter, capacity, aux int
	for; stops > 0; stops-- {
		scanf("%d%d\n", &exit, &enter)

		aux += -exit + enter
		if aux > capacity {
			capacity = aux
		}
	}

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

package main

import "fmt"

func main()  {

    var psNow,n,in,out,max int

    fmt.Scanf("%d", &n)
psNow=0
max=0
    for i:= 0;  i< n; i++ {
        fmt.Scan( &out)
        fmt.Scan (&in)
        psNow= psNow - out + in
        if psNow>max {
            max= psNow
        }
    }
    fmt.Println (max)
}

package main

import (
	"fmt"
)

func main() {
	var T int
	fmt.Scan(&T)
	c := 0
	capia := 0
	for i := 0; i < T; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		c = c - a + b
		if capia < c {
			capia = c
		}

	}
	fmt.Println(capia)

}

package main

import "fmt"

func main() {
	var n uint16
	var cap, maxcap int32
	fmt.Scan(&n)
	for ; n > uint16(0); n-- {
		var a, b int16
		fmt.Scan(&a, &b)
		cap += int32(b - a)
		if cap > maxcap {
			maxcap = cap
		}
	}
	fmt.Println(maxcap)
}

package main

import (
	"fmt"
)

func main() {
	var numStops, total, final int
    _, err1 := fmt.Scanf("%d",&numStops)
    //.Println(numStops)
	for x := 0; x < numStops; x++ {
        var out, in int
        fmt.Scan(&out)
        fmt.Scan(&in)
        //fmt.Println(out,in)
    //temp = append(temp, out,in)

		total += in-out
		//.Println(total)
		if final < total{
			final = total
		}

	}
	if err1!= nil{
	    panic(err1)
	}
	fmt.Println(final)

	//fmt.Println(strings.Compare(numStops,B))

}

package main

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

func main() {
	minCap := 0
	curr := 0
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	stops,_ := strconv.Atoi(scanner.Text())
	for i := 0; i < stops; i++ {
		scanner.Scan()
		stp := scanner.Text()
		inout := strings.Split(stp, " ")
		pOut,_ := strconv.Atoi(inout[0])
		pIn,_ := strconv.Atoi(inout[1])
		curr -= pOut
		curr += pIn
		if curr > minCap {
			minCap = curr
		}
	}
	fmt.Println(minCap)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	var max = 0
	var a, b int
	var temp = 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b)
		temp += b - a
		if temp > max {
			max = temp
		}
	}
	fmt.Print(max)
}

package main

import "fmt"

func main() {
	var n, max, on, off, current int
	fmt.Scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &off, &on)
		current += on - off
		if current > max {
			max = current
		}
	}

	fmt.Println(max)
}

package main
import (
    "fmt"
)
func main() {
    var n,a,b int
    fmt.Scan(&n)
    maxc:=0
    capc:=0
    for i:=0;i<n;i++ {
        fmt.Scan(&a,&b)
        capc=capc+b-a
        if capc > maxc {
            maxc=capc
        }
    }
    fmt.Println(maxc)
}

package main

import "fmt"

// A. Tram
// time limit per test
// 2 seconds
// memory limit per test
// 256 megabytes
// input
// standard input
// output
// standard output

// Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.

// Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.
// Input

// The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.

// Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.

//     The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.
//     At the last stop, all the passengers exit the tram and it becomes empty. More formally, .
//     No passenger will enter the train at the last stop. That is, bn = 0.

// Output

// Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

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

	var minCapacity, nPeopleOnTrain int
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		nPeopleOnTrain -= a
		nPeopleOnTrain += b
		if nPeopleOnTrain > minCapacity {
			minCapacity = nPeopleOnTrain
		}
	}
	fmt.Print(minCapacity)
}

package main

import "fmt"

func main(){
	var n int
	fmt.Scanf("%d", &n)
	prevStepPop := 0
	var maxCap int = 0
	for i:=0;i<n;i++{
		var a, b int
		fmt.Scanf("%d%d", &a, &b)
		b = b - a
		prevStepPop = prevStepPop + b
		if prevStepPop > maxCap{
			maxCap = prevStepPop
		}
	}
	fmt.Println(maxCap)
}

package main

import "fmt"

func main(){
	var n int
	fmt.Scanf("%d", &n)
	prevStepPop := 0
	var maxCap int = 0
	for i:=0;i<n;i++{
		var a, b int
		fmt.Scanf("%d%d", &a, &b)
		if ((prevStepPop - a ) + b) > maxCap {
			maxCap = (prevStepPop - a) + b
		}
		fmt.Println(prevStepPop)
		prevStepPop = (prevStepPop - a) + b
	}
	fmt.Println(maxCap)
}

package main

import "fmt"

func main(){
	var n int
	fmt.Scanf("%d", &n)
	prevStepPop := 0
	var maxCap int = 0
	for i:=0;i<n;i++{
		var a, b int
		fmt.Scanf("%d%d", &a, &b)
		if prevStepPop - a  + b > maxCap {
			maxCap = prevStepPop - a + b
		}
		prevStepPop = prevStepPop - a + b
	}
	fmt.Println(maxCap)
}

package main

import "fmt"

func main(){
	var n int
	fmt.Scanf("%d", &n)
	prevStepPop := 0
	var maxCap int = 0
	for i:=0;i<n;i++{
		var a, b int
		fmt.Scanf("%d%d", &a, &b)
		if ((prevStepPop - a ) + b) > maxCap {
			maxCap = (prevStepPop - a) + b
		}
		prevStepPop = (prevStepPop - a) + b
	}
	fmt.Println(maxCap)
}

package main

import "fmt"

func main() {
	var n, x, y, cap, currentPassenger int
	fmt.Scan(&n, &currentPassenger, &currentPassenger)
	cap = currentPassenger
	for i := 1; i < n; i++ {
		fmt.Scan(&x, &y)
		if currentPassenger+x-y > cap {
			cap = currentPassenger + x - y
		}
		currentPassenger = currentPassenger + x - y
	}
	fmt.Println(cap)
}

package main

import "fmt"

func main() {
	var n, x, y, cap, currentPassenger int
	fmt.Scan(&n, &currentPassenger, &currentPassenger)
	cap = currentPassenger
	for i := 1; i < n; i++ {
		fmt.Scan(&x, &y)
		if currentPassenger+x > cap {
			cap = currentPassenger + x
		}
		currentPassenger = currentPassenger + x - y
	}
	fmt.Println(cap)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	ejemplo()
}

func ejemplo() {
	var n, m, a float64
	fmt.Scanf("%g %g %g", &n, &m, &a)
	fmt.Println(math.Ceil(n/a) * math.Ceil(m/a))
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m, a float64
	fmt.Scanf("%g%g%g", &n, &m, &a)
	fmt.Println(int64(math.Ceil(n/a) * math.Ceil(m/a)))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint16
	var a, b uint16
	var cb uint32
	var max uint16
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; uint16(i) < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		cb -= uint32(a)
		cb += uint32(b)
		if cb > uint32(max) {
			max = uint16(cb)
		}
	}
	fmt.Println(max)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint16
	var a, b uint16
	var cb uint16
	var max uint16
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; uint16(i) < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		cb -= a
		cb += b
		if cb > max {
			max = cb
		}
	}
	fmt.Println(max)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n uint16
	var a, b uint16
	var cb uint16
	var max uint32
	fmt.Fscanf(in, "%d\n", &n)
	for i := 0; uint16(i) < n; i++ {
		fmt.Fscanf(in, "%d %d\n", &a, &b)
		cb -= a
		cb += b
		if uint32(cb) > max {
			max = uint32(cb)
		}
	}
	fmt.Println(max)
}

package main

import (
	"fmt"
)

func main() {
	var t, a, b, ctr int
	fmt.Scan(&t)
	for t > 0 {
		fmt.Scan(&a, &b)
		if b-a > 0 {
			ctr += b - a
		}
		t--
	}
	fmt.Println(ctr)
}

package main

import "fmt"

func main() {
	var n int
	max := 0
	num := 0

	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%d %d", &a, &b)

		num += -a + b
		if num > max {
			max = num
		}
	}
	// xD

	fmt.Printf("%d", max)
}

package main

import "fmt"

func main() {
	var n int
	max := 0
	num := 0

	fmt.Scanf("%d", &n)

	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%d %d", &a, &b)

		num += -a + b
		if num > max {
			max = num
		}
	}

	fmt.Printf("%d", max)
}

package main

import "fmt"

func main() {
	var n int
	ans := 0
	sisa := 0
	fmt.Scan(&n)
	for ; n > 0; n-- {
		var x, y int
		fmt.Scan(&x, &y)
		sisa -= x
		sisa += y
		if sisa > ans {
			ans = sisa
		}
	}
	print(ans)
}

package main

import (
	"fmt"
)

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

	max := 0

	for i := 0; i < n; i++ {
		var out int
		var in int

		_, err := fmt.Scanf("%d %d", &out, &in)

		if err != nil {
			i--
			continue
		}

		diff := in - out

		if max+diff > max {
			max = max + diff
		}
	}
	fmt.Println(max)
}

package main

import (
	"fmt"
)

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

	max := 0
	now := 0

	var out int
	var in int

	for i := 0; i < n; i++ {

		_, err := fmt.Scanf("%d %d", &out, &in)

		if err != nil {
			i--
			continue
		}

		now = now - out + in

		if now > max {
			max = now
		}

		fmt.Println(max)
	}
	fmt.Println(max)
}

package main

import (
	"fmt"
	"math"
)

// 4 stop
// 0 3 exit-enter
// 2 5
// 4 2
// 4 0
func main() {

	var stops int
	fmt.Scanln(&stops)
	var cap float64 = 0
	var x, y int
	for i := 1; i <= stops; i++ {
		fmt.Scanf("%d %d\n", &x, &y)
		cap = math.Max(cap, cap+float64(y)-float64(x))
	}
	fmt.Println(int(cap))
}

package main

import (
	"fmt"
	"math"
)

// 4 stop
// 0 3 exit-enter
// 2 5
// 4 2
// 4 0
func main() {

	var stops int
	fmt.Scanln(&stops)
	var ans, cap float64 = 0, 0
	var x, y int
	for i := 1; i <= stops; i++ {
		fmt.Scanf("%d %d\n", &x, &y)
		cap = cap + float64(y) - float64(x)
		ans = math.Max(cap, ans)
		fmt.Println(cap)
	}
	fmt.Println(int(ans))
}

package main

import (
        "fmt"
)

func main() {
        var num int
        fmt.Scanf("%d", &num)
        max := 0
        curr := 0
        var indoor, outdoor int
        for i := 0; i < num; i++ {
                fmt.Scanf("%d %d", &outdoor, &indoor)
                curr -= outdoor
                curr += indoor
                if curr > max {
                        max = curr
                }
        }
        fmt.Println(max)
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	tot := 0
	max := 0
	for i := 0; i < t; i++ {
		var tm int
		fmt.Scan(&tm)
		tot -= tm

		fmt.Scan(&tm)
		tot += t

		if max < tot {
			max = tot
		}
	}
	fmt.Println(max)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	//n, _ := strconv.Atoi(scanner.Text())
	max := 0
	cap := 0
	for scanner.Scan() {
		scanner.Scan()
		in := strings.Split(scanner.Text(), " ")
		a, _ := strconv.Atoi(in[0])
		b, _ := strconv.Atoi(in[1])
		cap -= a
		cap += b
		if cap > max {
			max = cap
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n uint16
	var cap int32
	fmt.Scan(&n)
	for ; n > uint16(0); n-- {
		var a, b int16
		fmt.Scan(&a, &b)
		if int32(b-a) > 0 {
			cap += int32(b - a)
		}
	}
	fmt.Println(cap)
}

package main

import (
	"fmt"
)

func main() {
	var numStops, total, final int
    _, err1 := fmt.Scanf("%d",&numStops)
    fmt.Println(numStops)
	for x := 0; x < numStops; x++ {
        var out, in int
        fmt.Scan(&out)
        fmt.Scan(&in)
        //fmt.Println(out,in)
    //temp = append(temp, out,in)

		total += in-out
		//.Println(total)
		if final < total{
			final = total
		}

	}
	if err1!= nil{
	    panic(err1)
	}
	fmt.Println(final)

	//fmt.Println(strings.Compare(numStops,B))

}

package main

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

func main() {
	minCap := 0
	curr := 0
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	stops,_ := strconv.Atoi(scanner.Text())
	for i := 0; i < stops; i++ {
		temp := curr
		scanner.Scan()
		stp := scanner.Text()
		inout := strings.Split(stp, " ")
		pOut,_ := strconv.Atoi(inout[0])
		pIn,_ := strconv.Atoi(inout[1])
		temp -= pOut
		temp += pIn
		if temp > minCap {
			minCap = temp
		}
	}
	fmt.Println(minCap)
}

package main

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

func main() {
	minCap := 0
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	stops,_ := strconv.Atoi(scanner.Text())
	for i := 0; i < stops; i++ {
		temp := minCap
		scanner.Scan()
		stp := scanner.Text()
		inout := strings.Split(stp, " ")
		pOut,_ := strconv.Atoi(inout[0])
		pIn,_ := strconv.Atoi(inout[1])
		temp -= pOut
		temp += pIn
		if temp > minCap {
			minCap = temp
		}
	}
	fmt.Println(minCap)
}

package main

import (
	"fmt"
)

func main() {
	var n, x, y, in int
	fmt.Scanln(&n)
	max := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &x, &y)
		if i == 0 {
			in = y
		} else {
			in = in - x + y
			if in > max {
				max = in
			}
		}
	}
	fmt.Println(max)
}

package main

import "fmt"

func main() {
	var n, in, out int
	fmt.Scanf("%d\n", &n)
	count := 0
	max := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &out, &in)
		count := count - out + in
		if max < count {
			max = count
		}
	}
	fmt.Println(max)
}


package main

import (
	"bufio"
	. "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 n, v int
		Fscan(in, &n)
		ans := int64(0)
		psum := map[int]int64{}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			ans += int64(n-i) * psum[v]
			psum[v] += int64(i + 1)
		}
		Fprintln(out, ans)
	}

	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 (
	"bufio"
	"fmt"
	"os"
)

var t int

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

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

		for i := 1; i <= n; i++ {
			var x int
			fmt.Fscan(in, &x)
			mp[x] = append(mp[x], int64(i))
		}
		var ans int64 = 0
		for _, value := range mp {
			if len(value) < 2 {
				continue
			}
			suf := make([]int64, len(value))
			suf[len(suf)-1] = value[len(value)-1]
			for i := len(suf) - 2; i >= 0; i-- {
				suf[i] = suf[i+1] + value[i]
			}
			for i := 0; i < len(value)-1; i++ {
				sm := suf[i+1]
				ans += int64(len(value)-i-1)*int64(int64(n)*value[i]+value[i]) - value[i]*sm
			}
		}
		fmt.Fprintln(out, ans)
	}

}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int64
	scan(&n)
	var elems = make(map[int][]int64)
	for i := int64(0); i < n; i++ {
		x := 0
		scan(&x)
		elems[x] = append(elems[x], i)
	}
	var ans int64
	for _, v := range elems {
		sort.Slice(v, func(i, j int) bool { return v[i] < v[j] })
		var fullsum int64
		for _, i := range v {
			fullsum += n - i
		}
		for _, i := range v {
			fullsum -= n - i
			ans += (i + 1) * fullsum
		}
	}
	printf("%v\n", ans)
}

package main

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

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		a := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		mp := map[int][]int{}
		for i:=1;i<=n;i++{
			mp[a[i]] = append(mp[a[i]],i)
		}
		var ans int64
		for _,v := range mp{
			pre := 0
			for i:=0;i<len(v);i++{
				ans += int64(pre) * int64(n-v[i]+1)
				pre += v[i]
			}
		}
		fmt.Fprintln(out,ans)
	}
}

package main

import (
	"bufio"
	"math/big"
	"os"
	"strconv"
)

type node struct {
	n, h *node
	pars []*node
	end  bool
}

func start() {
	t := sint()
	for ; t > 0; t-- {
		n := sint()
		a := sints(n)
		res := big.NewInt(0)
		pLocSum := make(map[int]int64)
		for i, v := range a {
			pSum := pLocSum[v]
			res.Add(res, big.NewInt(pSum*int64(n-i)))
			pLocSum[v] += int64(i + 1)
		}
		wlstring(res.String())
	}
}

func main() {
	start()
	// flush
	writer.Flush()
}

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

// io utils

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

func wstring(s string) {
	writer.WriteString(s)
}
func wrune(r rune) {
	writer.WriteRune(r)
}
func wint(i int) {
	wstring(strconv.Itoa(i))
}
func wlstring(s string) {
	writer.WriteString(s)
	wrune('\n')
}
func wlrune(r rune) {
	writer.WriteRune(r)
	wrune('\n')
}
func wlint(i int) {
	wstring(strconv.Itoa(i))
	wrune('\n')
}

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

func printls(in []int) {
	for _, v := range in {
		wint(v)
		wrune(' ')
	}
	wlstring("")
}

func sint() int {
	i, err := strconv.Atoi(sstring())
	if err != nil {
		panic("sint: Error")
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

package main

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

var t int

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

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

		for i := 1; i <= n; i++ {
			var x int
			fmt.Fscan(in,&x)
			mp[x] = append(mp[x], i)
		}
		var ans = 0
		for _, value := range mp {
			if len(value) < 2 {
				continue
			}
			suf := make([]int, len(value))
			suf[len(suf)-1] = value[len(value)-1]
			for i := len(suf) - 2; i >= 0; i-- {
				suf[i] = suf[i+1] + value[i]
			}
			for i := 0; i < len(value)-1; i++ {
				sm := suf[i+1]
				ans += (len(value)-i-1)*(n*value[i]+value[i]) - value[i]*sm
			}
		}
		fmt.Fprintln(out,ans)
	}

}

package main

import (
	"bufio"
	"math/big"
	"os"
	"strconv"
)

type node struct {
	n, h *node
	pars []*node
	end  bool
}

func start() {
	t := sint()
	for ; t > 0; t-- {
		n := sint()
		a := sints(n)
		res := big.NewInt(0)
		pLocSum := make(map[int]int)
		for i, v := range a {
			pSum := pLocSum[v]
			res.Add(res, big.NewInt(int64(pSum*(n-i))))
			pLocSum[v] += i + 1
		}
		wlstring(res.String())
	}
}

func main() {
	start()
	// flush
	writer.Flush()
}

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

// io utils

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

func wstring(s string) {
	writer.WriteString(s)
}
func wrune(r rune) {
	writer.WriteRune(r)
}
func wint(i int) {
	wstring(strconv.Itoa(i))
}
func wlstring(s string) {
	writer.WriteString(s)
	wrune('\n')
}
func wlrune(r rune) {
	writer.WriteRune(r)
	wrune('\n')
}
func wlint(i int) {
	wstring(strconv.Itoa(i))
	wrune('\n')
}

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

func printls(in []int) {
	for _, v := range in {
		wint(v)
		wrune(' ')
	}
	wlstring("")
}

func sint() int {
	i, err := strconv.Atoi(sstring())
	if err != nil {
		panic("sint: Error")
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

package main

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

type node struct {
	n, h *node
	pars []*node
	end  bool
}

func start() {
	t := sint()
	for ; t > 0; t-- {
		n := sint()
		a := sints(n)
		res := 0
		pLocSum := make(map[int]int)
		for i, v := range a {
			pSum := pLocSum[v]
			res += pSum * (n - i)
			pLocSum[v] += i + 1
		}
		wlint(res)
	}
}

func main() {
	start()
	// flush
	writer.Flush()
}

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

// io utils

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

func wstring(s string) {
	writer.WriteString(s)
}
func wrune(r rune) {
	writer.WriteRune(r)
}
func wint(i int) {
	wstring(strconv.Itoa(i))
}
func wlstring(s string) {
	writer.WriteString(s)
	wrune('\n')
}
func wlrune(r rune) {
	writer.WriteRune(r)
	wrune('\n')
}
func wlint(i int) {
	wstring(strconv.Itoa(i))
	wrune('\n')
}

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

func printls(in []int) {
	for _, v := range in {
		wint(v)
		wrune(' ')
	}
	wlstring("")
}

func sint() int {
	i, err := strconv.Atoi(sstring())
	if err != nil {
		panic("sint: Error")
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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


package main

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

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

	var n int;
	Fscan(in, &n);
	a := make([]int, n+1);
	dp := make([]int, n+2);
	l := make([]int, n+1);
	r := make([]int, n+1);
	cnt := make([]int, n+1);
	for i:=1;i<=n;i++ {
		Fscan(in, &a[i]);
		if l[a[i]] == 0 {
			l[a[i]] = i;
		}
		r[a[i]] = i;
	}
	for i:=n;i>=1;i-- {
		cnt[a[i]]++;
		if dp[i+1] < cnt[a[i]] {
			dp[i] = cnt[a[i]];
		} else{
			dp[i] = dp[i+1];
		}

		if i == l[a[i]] {
			if dp[i] < cnt[a[i]] + dp[r[a[i]]+1] {
				dp[i] = cnt[a[i]] + dp[r[a[i]]+1];
			}
		}
	}
	Fprint(out, n-dp[1], "\n");
}

package main

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

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

	var buf bytes.Buffer

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

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
}

func solve(n int, C []int) int {
	L, R := make([]int, n), make([]int, n)
	F := make([]int, n)

	for i := 0; i < n; i++ {
		L[i] = -1
	}

	for i := 0; i < n; i++ {
		x := C[i] - 1
		if L[x] < 0 {
			L[x] = i
		}
		R[x] = i
		F[x]++
	}

	CF := make([]int, n)
	dp := make([]int, n+1)

	for i := n - 1; i >= 0; i-- {
		dp[i] = dp[i+1]
		x := C[i] - 1
		CF[x]++
		if i == L[x] {
			// color x都留在原地，其他的都被移到到后端
			dp[i] = max(dp[i], dp[R[x]+1]+F[x])
		} else {
			dp[i] = max(dp[i], CF[x])
		}
	}

	return n - dp[0]
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1481E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	type pair struct{ l, r int }

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	pos := make([]pair, n+1)
	for i := range pos {
		pos[i].l = -1
	}
	for i := range a {
		Fscan(in, &a[i])
		v := a[i]
		if pos[v].l < 0 {
			pos[v].l = i
		}
		pos[v].r = i
	}
	dp := make([]int, n+1)
	c := make([]int, n+1)
	for i := n - 1; i >= 0; i-- {
		v := a[i]
		c[v]++
		dp[i] = dp[i+1]
		if p := pos[v]; i > p.l {
			dp[i] = max(dp[i], c[v])
		} else {
			dp[i] = max(dp[i], dp[p.r+1]+c[v])
		}
	}
	Fprint(out, n-dp[0])
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1481E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	type pair struct{ l, r int }

	var n int
	Fscan(in, &n)
	n++
	a := make([]int, n)
	ps := make([]pair, n)
	for i := 1; i < n; i++ {
		Fscan(in, &a[i])
		v := a[i]
		if ps[v].l == 0 {
			ps[v].l = i
		}
		ps[v].r = i
	}
	dp := make([]int, n+1)
	c := make([]int, n)
	for i := n - 1; i > 0; i-- {
		v := a[i]
		c[v]++
		dp[i] = dp[i+1]
		if i > ps[v].l {
			dp[i] = max(dp[i], c[v])
		} else {
			dp[i] = max(dp[i], dp[ps[v].r+1]+c[v])
		}
	}
	Fprint(out, n-1-dp[1])
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1481E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	type pair struct{ l, r int }

	var n int
	Fscan(in, &n)
	n++
	a := make([]int, n)
	c := make([]int, n)
	ps := make([]pair, n)
	for i := 1; i < n; i++ {
		Fscan(in, &a[i])
		v := a[i]
		c[v]++
		if ps[v].l == 0 {
			ps[v].l = i
		}
		ps[v].r = i
	}
	dp := make([]int, n+1)
	sc := make([]int, n)
	for i := n - 1; i > 0; i-- {
		v := a[i]
		sc[v]++
		dp[i] = dp[i+1]
		if i > ps[v].l {
			dp[i] = max(dp[i], sc[v])
		} else {
			dp[i] = max(dp[i], dp[ps[v].r+1]+c[v])
		}
	}
	Fprint(out, n-1-dp[1])
}

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

package main

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

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

	var n int;
	Fscan(in, &n);
	a := make([]int, n+1);
	dp := make([]int, n+1);
	cnt := make([]int, n+1);
	l := make([]int, n+1);
	r := make([]int, n+1);
	for i:=1;i<=n;i++ {
		Fscan(in, &a[i]);
		if l[a[i]] == 0 {
			l[a[i]] = i;
		}
		r[a[i]] = i;
	}
	ans := 0;
	for i:=1;i<=n;i++ {
		cnt[a[i]]++;
		if dp[i-1] < dp[l[a[i]]] + cnt[a[i]] {
			dp[i] = dp[l[a[i]]] + cnt[a[i]];
		} else{
			dp[i] = dp[i-1];
		}

		if ans < dp[i] {
			ans = dp[i];
		}
	}
	Fprint(out, n-ans, "\n");
}