Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square.A number x is said to be a perfect square if there exists an integer y such that x = y2.

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second line contains n integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — the elements of the array. It is guaranteed that at least one element of the array is not a perfect square.

Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists.

NoteIn the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2.

package main

import "fmt"

func main() {
	sq := make(map[int]bool)
	for i := 0; i < 1e4; i++ {
		sq[i*i] = true
	}
	var n int
	ma := int(-1e7)
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if !sq[a] && ma < a {
			ma = a
		}
	}
	fmt.Println(ma)
}

package main

import (
	"fmt"
	"math"
)

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

	f := false
	c := int32(math.MinInt32)
	for _, p := range a {
		if p == 0 || (f && p <= c) {
			continue
		}
		if p < 0 || !isPerfectSquare(p) {
			if p < c {
				continue
			}
			c = p
			f = true
		}
	}
	fmt.Println(c)
}

func isPerfectSquare(a int32) bool {
	s := int32(math.Sqrt(float64(a)))
	return (s * s) == a
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanln(&n)
	result := -1000000
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a >= 0 && int(math.Sqrt(float64(a)))*int(math.Sqrt(float64(a))) == a {
			continue
		}
		if a > result {
			result = a
		}

	}
	fmt.Println(result)
}

package main

import (
	"fmt"
	"math"
)

func sqrtSqr(a int) int {
	sqrtA := int(math.Sqrt(float64(a)))
	return sqrtA * sqrtA
}

func main() {
	var n int
	fmt.Scanln(&n)
	result := -1000000
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a > result && sqrtSqr(a) != a {
			result = a
		}
	}
	fmt.Println(result)
}

package main

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

func main() {
	var n, x int
	maxNotPerfectSquare := -1000001
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(stdin, &x)
		if !isPerfectSquare(x) && maxNotPerfectSquare < x {
			maxNotPerfectSquare = x
		}
	}
	fmt.Println(maxNotPerfectSquare)
}

func isPerfectSquare(x int) bool {
	if x < 0 {
		return false
	}
	num := math.Sqrt(float64(x))
	floorNum := math.Floor(num)
	return (num - floorNum) == 0
}

package main

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

const (
	max = 1000000
	min = -max
)

var sqrs map[int]struct{}

func init() {
	sqrs = map[int]struct{}{}
	for i := 0; i*i <= max; i++ {
		sqrs[i*i] = struct{}{}
	}
}

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

	var n int
	fmt.Fscan(r, &n)
	ans := min - 1
	for i := 0; i < n; i++ {
		var v int
		fmt.Fscan(r, &v)
		if _, ok := sqrs[v]; ok {
			continue
		}
		if v > ans {
			ans = v
		}
	}
	fmt.Println(ans)
}

package main

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

type Int64 []int64

func (a Int64) Len() int           { return len(a) }
func (a Int64) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Int64) Less(i, j int) bool { return a[i] < a[j] }

func solve() {
	n := readInt()
	a := readInt64Array(n)
	sort.Sort(Int64(a))
	for i := n - 1; i >= 0; i-- {
		v := a[i]
		b := int64(math.Sqrt(float64(v)))
		if b*b != v {
			fmt.Println(v)
			return
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Scan()
	a := strings.Split(scanner.Text(), " ")
	max := int(-10e6)
	for _, val := range a {
		i := 0
		intVal, _ := strconv.Atoi(val)
		for ; i*i < intVal; i++ {
		}
		if i*i != intVal {
			if max <= intVal {
				max = intVal
			}
		}
	}
	fmt.Println(max)
}

package main

import (
	"fmt"
	"math"
	//"time"
)

var (
	co int
	ar [1000]int
)

func main() {
	fmt.Scanf("%d \n", &co)
	for i := 0; i < co; i++ {
		fmt.Scanf("%d", &ar[i])
	}
	var res int = -10000000
	for i := 0; i < co; i++ {
		if int(math.Pow(float64(int(math.Sqrt(float64(ar[i])))), 2)) != ar[i] {
			if ar[i] > res {
				res = ar[i]
			}
		}
	}
	fmt.Println(res)
}

package main

import "fmt"
import "math"

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

    var largest int = -9999999
    for i:=0; i < n; i++ {
        var tmp int
        fmt.Scan(&tmp)
        if tmp < 0 {
            if largest < tmp {
                largest = tmp
            }
            continue
        }
        sq := int(math.Floor(math.Sqrt(float64(tmp))))
        if sq * sq != tmp {
            if largest < tmp {
                largest = tmp
            }
        }
    }
    fmt.Print(largest)
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    var a int
    var ans int = -1000001
    var x int
    fmt.Scan(&n)
    for i := 0; i < n;i ++ {
        fmt.Scan(&a);
        if a < 0 {
            if a > ans {
                ans = a
            }
        } else {
            x = int(math.Sqrt(float64(a)))
            if x * x != a {
                if a > ans {
                    ans = a
                }
            }
        }
    }
    fmt.Println(ans)
}

package main

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

var (
	SQ = make(map[int]bool)
)

func Init() {
	for i := 0; i * i <= 1000000; i++ {
		SQ[i * i] = true
	}
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextIntArray(N)

	best := -123456789
	for _, v := range A {
		if !SQ[v] {
			best = Max(best, v)
		}
	}
	io.Println(best)
}

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

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextIntArray()

	mx := int(-1e7)
	for _, v := range A {

		if v < 0 {
			mx = max(mx, v)
		} else {
			ok := false
			for k := 0; k*k <= v; k++ {
				if k*k == v {
					ok = true
				}
			}
			if !ok {
				mx = max(mx, v)
			}
		}
	}
	fmt.Println(mx)

}

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

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	var n int
	// var a int
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n)

	ans := -19999999
	for i := 0; i < n; i++ {
		var a int
		fmt.Fscan(input, &a)
		if a < 0 {
			if ans < a {
				ans = a
			}
		} else {
			t := int(math.Floor(math.Sqrt(float64(a))))
			if t*t != a && ans < a {
				ans = a
			}
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"math"
)

func isSquare(a int) bool {
	if a < 0 {
		return false
	}
	var x = int(math.Sqrt(float64(a)))
	return x*x == a
}

func main() {
	var n int
	fmt.Scan(&n)
	var t int
	var m = math.MinInt32
	for i := 0; i < n; i++ {
		fmt.Scan(&t)
		if t > m && !isSquare(t) {
			m = t
		}
	}
	fmt.Println(m)
}

package main

import ("fmt";
		"math")

func check(a float64)bool{
	return math.Ceil(math.Sqrt(a)) * math.Ceil(math.Sqrt(a)) == a
}

func main(){
	var n, max int
	scan(&n)
	max = -1e8
	for i := 0; i < n; i++{
		var a int
		scan(&a)
		if max < a && !check(float64(a)){
			max = a
		}
	}
	sout(max)
}

func scan(in ... interface{}){
	for _,k := range in{
		fmt.Scan(k)
	}
}

func sout(obj ... interface{}){
	for _, k := range obj{
		fmt.Print(k, " ")
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

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

	sq := make(map[int]bool)

	for i:=0; i < 1e4; i++ {
		sq[i*i] = true
	}

	mps := int(-1e7)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)

		if(!sq[x] && mps < x){
			mps = x
		}
	}
	fmt.Println(mps)
}

// cf914a project main.go
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := -10000000
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		f := math.Sqrt(float64(t))
		if math.Ceil(f)-f != 0 {
			if t > m {
				m = t
			}
		}
	}
	if m == -10000000 {
		fmt.Println(-1)
	} else {
		fmt.Println(m)
	}
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanln(&n)
	result := -1000000
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		if a > 0 && int(math.Sqrt(float64(a)))*int(math.Sqrt(float64(a))) == a {
			continue
		}
		if a > result {
			result = a
		}

	}
	fmt.Println(result)
}

package main

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

const (
	max = 1000000
	min = -max
)

var sqrs map[int]struct{}

func init() {
	sqrs = map[int]struct{}{}
	for i := 1; i*i <= max; i++ {
		sqrs[i*i] = struct{}{}
	}
}

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

	var n int
	fmt.Fscan(r, &n)
	ans := min - 1
	for i := 0; i < n; i++ {
		var v int
		fmt.Fscan(r, &v)
		if _, ok := sqrs[v]; ok {
			continue
		}
		if v > ans {
			ans = v
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Scan()
	a := strings.Split(scanner.Text(), " ")
	max := int(-10e6)
	for _, val := range a {
		i := 1
		intVal, _ := strconv.Atoi(val)
		for ; i*i < intVal; i++ {
		}
		if i*i != intVal {
			if max <= intVal {
				max = intVal
			}
		}
	}
	fmt.Println(max)
}

package main

import (
	"fmt"
	"math"
	//"time"
)

var (
	co int
	ar [1000]int
)

func main() {
	fmt.Scanf("%d \n", &co)
	for i := 0; i < co; i++ {
		fmt.Scanf("%d \n", &ar[i])
	}
	var res int = -10000000
	for i := 0; i < co; i++ {
		if int(math.Pow(float64(int(math.Sqrt(float64(ar[i])))), 2)) != ar[i] {
			if ar[i] > res {
				res = ar[i]
			}
		}
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
	"math"
	//"time"
)

var (
	co int
	ar [1000]int
)

func main() {
	fmt.Scanf("%d", &co)
	for i := 0; i < co; i++ {
		fmt.Scanf("%d", &ar[i])
	}
	var res int = -10000000
	for i := 0; i < co; i++ {
		if int(math.Pow(float64(int(math.Sqrt(float64(ar[i])))), 2)) != ar[i] {
			if ar[i] > res {
				res = ar[i]
			}
		}
	}
	fmt.Println(res)
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    var a int
    var ans int = 0
    var x int
    fmt.Scan(&n)
    for i := 0; i < n;i ++ {
        fmt.Scan(&a);
        x = int(math.Sqrt(float64(a)))
        if x * x != a {
            if a > ans {
                ans = a
            }
        }
    }
    fmt.Println(ans)
}

package main

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

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextIntArray()

	mx := 0
	for _, v := range A {
		a := math.Sqrt(float64(v))
		if v < 0 || a*a != float64(v) {
			mx = max(mx, v)
		}
	}
	fmt.Println(mx)

}

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

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextIntArray()

	mx := 0
	for _, v := range A {

		if v < 0 {
			mx = max(mx, v)
		} else {
			ok := false
			for k := 0; k*k <= v; k++ {
				if k*k == v {
					ok = true
				}
			}
			if !ok {
				mx = max(mx, v)
			}
		}
	}
	fmt.Println(mx)

}

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

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

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

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

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

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

	return mp
}

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

package main

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

func main() {
	sc := NewScanner()
	_ = sc.NextInt()
	A := sc.NextIntArray()

	mx := 0
	for _, v := range A {
		a := math.Sqrt(float64(v))
		if a*a != float64(v) {
			mx = max(mx, v)
		}
	}
	fmt.Println(mx)

}

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

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

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

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

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

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

	return mp
}

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

package main

import "fmt"
import (
	"math"
)

func main() {
	var n int
	// var a int
	//
	fmt.Scanf("%d", &n)
	ans := -19999999
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)
		if a < 0 {
			if ans < a {
				ans = a
			}
		} else {
			t := int(math.Floor(math.Sqrt(float64(a))))
			if t*t != a && ans < a {
				ans = a
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"
import (
	"math"
)

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

	ans := -19999999
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &n)
		if a < 0 {
			if ans < a {
				ans = a
			}
		} else {
			t := int(math.Floor(math.Sqrt(float64(a))))
			if t*t != a && ans < a {
				ans = a
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"
import (
	"math"
)

func main() {
	var n int
	// var a int
	//
	fmt.Scanf("%d", &n)
	fmt.Println(n)
	ans := -19999999
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)
		if a < 0 {
			if ans < a {
				ans = a
			}
		} else {
			t := int(math.Floor(math.Sqrt(float64(a))))
			if t*t != a && ans < a {
				ans = a
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"
import (
	"math"
)

func main() {
	var n int
	// var a int
	//
	fmt.Scanf("%d", &n)
	ans := -19999999
	fmt.Println(n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)
		fmt.Println(a)
		if a < 0 {
			if ans < a {
				ans = a
			}
		} else {
			t := int(math.Floor(math.Sqrt(float64(a))))
			if t*t != a && ans < a {
				ans = a
			}
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	var n int
	// var a int
	input := bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &n)

	ans := -19999999
	for i := 0; i < n; i++ {
		var a int
		fmt.Fscan(input, &a)
		if a < 0 {
			if ans < a {
				ans = a
			}
		} else {
			t := int(math.Floor(math.Sqrt(float64(a))))
			if t*t == a && ans < a {
				ans = a
			}
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	var n int
	// var a int
	input := bufio.NewReader(os.Stdin)
	fmt.Fscanf(input, "%d", &n)

	ans := -19999999
	for i := 0; i < n; i++ {
		var a int
		fmt.Fscanf(input, "%d", &a)
		if a < 0 {
			if ans < a {
				ans = a
			}
		} else {
			t := int(math.Floor(math.Sqrt(float64(a))))
			if t*t != a && ans < a {
				ans = a
			}
		}
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"math"
)

func isSquare(a int) bool {
	if a < 0 {
		return false
	}
	var x = int(math.Sqrt(float64(a)))
	return x*x == a
}

func main() {
	var n int
	fmt.Scanf("%d", &n)
	var t int
	var m = math.MinInt32
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &t)
		if t > m && !isSquare(t) {
			m = t
		}
	}
	fmt.Println(m)
}

package main

import ("fmt";
		"math")

func check(a float64)bool{
	return math.Sqrt(a) * math.Sqrt(a) == a
}

func main(){
	var n, max int
	scan(&n)
	max = -1e8
	for i := 0; i < n; i++{
		var a int
		scan(&a)
		if max < a && !check(float64(a)){
			max = a
		}
	}
	sout(max)
}

func scan(in ... interface{}){
	for _,k := range in{
		fmt.Scan(k)
	}
}

func sout(obj ... interface{}){
	for _, k := range obj{
		fmt.Print(k, " ")
	}
	fmt.Println()
}

package main

import (
	"fmt"
	"math"
)

func isPerfectSquare(number int32) bool {
	if number < 0 {
		return false
	}
	var i int32 = 0
	for ; i*i < number; i++ {
		;
	}
	return i*i == number
}

func min(nums ...int32) int32{
	var minv int32 = math.MaxInt32

	for _, v := range nums {
		if v < minv {
			minv = v
		}
	}
	return minv
}

func max(nums ...int32) int32{
	var maxv int32 = math.MinInt32

	for _, v := range nums {
		if v > maxv {
			maxv = v
		}
	}
	return maxv
}

func main() {
	var num int32
	_, _ = fmt.Scanf("%d", &num)

	arr := make([]int32, num)

	var i int32 = 0
	for ; i < num; i++ {
		_, _ = fmt.Scanf("%d", &arr[i])
	}

	var maxNotPerfect int32 = math.MinInt32
	for i = 0; i < num; i++ {

		if !isPerfectSquare(arr[i]) {
			maxNotPerfect = max(maxNotPerfect, arr[i])
		}
	}
	fmt.Printf("%v\n", maxNotPerfect)
}

// cf914a project main.go
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	m := -1
	for i := 0; i < n; i++ {
		t := -2
		fmt.Scan(&t)
		f := math.Sqrt(float64(t))
		if math.Ceil(f)-f != 0 {
			if t > m {
				m = t
			}
		}
	}
	fmt.Println(m)
}

// cf914a project main.go
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	var m int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		f := math.Sqrt(float64(t))
		if math.Ceil(f)-f != 0 {
			if t > m {
				m = t
			}
		}
	}
	fmt.Println(m)
}

// cf914a project main.go
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	var m int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		f := math.Sqrt(float64(t))
		if math.Ceil(f)-f != 0 {
			if t > m || t < 0 {
				m = t
			}
		}
	}
	if m == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(m)
	}
}

// cf914a project main.go
package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scan(&n)
	var m int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		f := math.Sqrt(float64(t))
		if math.Ceil(f)-f != 0 {
			if t > m {
				m = t
			}
		}
	}
	if m == 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(m)
	}
}


In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction).Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different.

The first line of the input contains n (2 ≤ n ≤ 1000) — number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1 ≤ pi ≤ 10000), where pi stands for the price offered by the i-th bidder.

The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based.

package main

import "fmt"
var price[1000]int
var (
        n = 0
        max = 0
        imax = 0
        answer1 = 0
        answer2 = 0
    )

func main() {
    fmt.Scanf("%d\n",&n)
    for i:=0;i<n;i++ {
        fmt.Scanf("%d",&price[i])
    }
    findmax()
    answer1 = imax
    price[imax] = 0
    imax = 0
    max = 0
    findmax()
    answer2 = max
    fmt.Println(answer1+1," ",answer2)
}

func findmax() {
    for i:=0;i<n;i++ {
        if (price[i]>max) {
            max = price[i]
            imax = i
        }
    }
}


Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple task. You are able to do it too, aren't you?Leha has two strings s and t. The hacker wants to change the string s at such way, that it can be found in t as a substring. All the changes should be the following: Leha chooses one position in the string s and replaces the symbol in this position with the question mark "?". The hacker is sure that the question mark in comparison can play the role of an arbitrary symbol. For example, if he gets string s="ab?b" as a result, it will appear in t="aabrbb" as a substring.Guaranteed that the length of the string s doesn't exceed the length of the string t. Help the hacker to replace in s as few symbols as possible so that the result of the replacements can be found in t as a substring. The symbol "?" should be considered equal to any other symbol.

The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly. The second line contains n lowercase English letters — string s. The third line contains m lowercase English letters — string t.

In the first line print single integer k — the minimal number of symbols that need to be replaced. In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering of the positions begins from one.

package main

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

func solve() {
	readInt()
	readInt()
	n := []rune(readString())
	m := []rune(readString())
	best := 10000
	bestIndex := 0
	for i := 0; i < len(m); i++ {
		cnt := 0
		if i+len(n) <= len(m) {
			for j := 0; j < len(n); j++ {
				if m[i+j] != n[j] {
					cnt++
				}
			}
			if cnt < best {
				best = cnt
				bestIndex = i
			}
		}
	}
	fmt.Println(best)
	cnt := 0
	for j := 0; j < len(n); j++ {
		if m[bestIndex+j] != n[j] {
			if cnt > 0 {
				fmt.Printf(" ")
			}
			fmt.Printf("%d", j+1)
			cnt++
		}
	}
	fmt.Println()
}

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

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

package main

import (
    "fmt"
)

var (
    a,b int
    s,l string
)
func main(){
    fmt.Scanln(&a,&b)
    fmt.Scanln(&s)
    fmt.Scanln(&l)
    //fmt.Println(len(s))
    ansloc := make([]int, 0, len(s))
    for i:= 0 ; i < len(s) ; i++ {
        ansloc=append(ansloc,i+1)
    }
    for i := 0 ; i<len(l) ; i++ {
        if len(s) + i - 1 < len(l) {
            tmploc := make([]int, 0, len(s))
            for j := 0 ; j<len(s) ; j++ {
                if s[j] != l[i+j] {
                    tmploc=append(tmploc,j+1)
                }
            }
            if len(tmploc) < len(ansloc) { ansloc=tmploc }
        }
    }
    fmt.Println(len(ansloc))
    for _, loc := range ansloc {
        fmt.Printf("%d ",loc)
    }
}

package main

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

func main() {
	sc := NewScanner()
	_ = sc.NextLine()
	S := sc.NextLine()

	T := sc.NextLine()

	var ansNum []int = nil

	for i := 0; i <= len(T)-len(S); i++ {
		a := make([]int, 0, len(S))
		for j := 0; j < len(S); j++ {
			if T[i+j] != S[j] {
				a = append(a, j+1)
			}
		}
		if ansNum == nil || len(ansNum) > len(a) {
			ansNum = a
		}
	}
	fmt.Println(len(ansNum))

	PrintI(ansNum...)
}

func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

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

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

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

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

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

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

	return mp
}

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

package main

import (
	"fmt"
)

var s, t string

func diffNum(p int) int {
	sum := 0
	for i := 0; i < len(s); {
		if s[i] != t[p] {
			sum++
		}
		i++
		p++
	}

	return sum
}

func main() {

	var temp, min, pos int

	fmt.Scanf("%d %d\n%s\n%s", &min, &pos, &s, &t)

	//fmt.Scanf("%s", &s)
	//fmt.Scanf("%s", &t)

	min = len(s) + 1

	for i := 0; i <= len(t)-len(s); {
		temp = diffNum(i)
		if temp < min {
			min = temp
			pos = i
		}

		i++
	}

	fmt.Println(min)

	for i := 0; min > 0 && i < len(s); {
		if s[i] != t[pos] {
			fmt.Printf("%d ", i+1)
			min--
		}

		pos++
		i++
	}
}

package main

import (
	"fmt"
)

var s, t string
var ls, lt int

func diffNum(p int) int {
	sum := 0
	for i := 0; i < ls; {
		if s[i] != t[p] {
			sum++
		}
		i++
		p++
	}

	return sum
}

func main() {

	var temp, min, pos int

	fmt.Scanf("%d %d\n%s\n%s", &ls, &lt, &s, &t)

	//fmt.Scanf("%s", &s)
	//fmt.Scanf("%s", &t)

	min = ls + 1

	for i := 0; i <= lt-ls; i++ {
		temp = diffNum(i)
		if temp < min {
			min = temp
			pos = i
		}
	}

	fmt.Println(min)

	for i := 0; min > 0 && i < ls; {
		if s[i] != t[pos] {
			fmt.Printf("%d ", i+1)
			min--
		}

		pos++
		i++
	}
}

package main

import (
	"fmt"
)

var s, t string

func diffNum(p int) int {
	sum := 0
	for i := 0; i < len(s); {
		if s[i] != t[p] {
			sum++
		}
		i++
		p++
	}

	return sum
}

func main() {

	var temp, min, pos int

	fmt.Scanf("%d %d", &min, &pos)

	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)

	min = len(s)

	for i := 0; i <= len(t)-len(s); i++ {
		temp = diffNum(i)
		if temp < min {
			min = temp
			pos = i
		}
	}

	fmt.Println(min, s, t)

	for i := 0; min > 0 && i < len(s); {
		if s[i] != t[pos] {
			fmt.Printf("%d ", i+1)
			min--
		}

		pos++
		i++
	}
}

package main

import (
	"fmt"
)

var s, t string

func diffNum(p int) int {
	sum := 0
	for i := 0; i < len(s); {
		if s[i] != t[p] {
			sum++
		}
		i++
		p++
	}

	return sum
}

func main() {

	var temp, min, pos int

	fmt.Scanf("%d %d", &min, &pos)
	fmt.Scanf("%s\n%s", &s, &t)

	min = len(s)

	for i := 0; i <= len(t)-len(s); i++ {
		temp = diffNum(i)
		if temp < min {
			min = temp
			pos = i
		}
	}

	fmt.Println(min)

	for i := 0; min > 0 && i < len(s); {
		if s[i] != t[pos] {
			fmt.Printf("%d ", i+1)
			min--
		}

		pos++
		i++
	}
}

package main

import (
	"fmt"
)

var s, t string

func diffNum(p int) int {
	sum := 0
	for i := 0; i < len(s); {
		if s[i] != t[p] {
			sum++
		}
		i++
		p++
	}

	return sum
}

func main() {

	var temp, min, pos int

	fmt.Scanf("%d %d", &min, &pos)

	fmt.Scanf("%s", &s)
	fmt.Scanf("%s", &t)

	min = len(s)

	for i := 0; i <= len(t)-len(s); i++ {
		temp = diffNum(i)
		if temp < min {
			min = temp
			pos = i
		}
	}

	fmt.Println(min)

	for i := 0; min > 0 && i < len(s); {
		if s[i] != t[pos] {
			fmt.Printf("%d ", i+1)
			min--
		}

		pos++
		i++
	}
}


This time around, Baby Ehab will play with permutations. He has $$$n$$$ cubes arranged in a row, with numbers from $$$1$$$ to $$$n$$$ written on them. He'll make exactly $$$j$$$ operations. In each operation, he'll pick up $$$2$$$ cubes and switch their positions.He's wondering: how many different sequences of cubes can I have at the end? Since Baby Ehab is a turbulent person, he doesn't know how many operations he'll make, so he wants the answer for every possible $$$j$$$ between $$$1$$$ and $$$k$$$.

The only line contains $$$2$$$ integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 10^9$$$, $$$1 \le k \le 200$$$) — the number of cubes Baby Ehab has, and the parameter $$$k$$$ from the statement.

Print $$$k$$$ space-separated integers. The $$$i$$$-th of them is the number of possible sequences you can end up with if you do exactly $$$i$$$ operations. Since this number can be very large, print the remainder when it's divided by $$$10^9+7$$$.

NoteIn the second example, there are $$$3$$$ sequences he can get after $$$1$$$ swap, because there are $$$3$$$ pairs of cubes he can swap. Also, there are $$$3$$$ sequences he can get after $$$2$$$ swaps:  $$$[1,2,3]$$$,  $$$[3,1,2]$$$,  $$$[2,3,1]$$$.

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, k := readTwoNums(reader)
	res := solve(n, k)
	var buf bytes.Buffer

	for i := 0; i < k; i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	fmt.Println(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
}

const MOD = 1000000007

const K = 405

var I []int64
var F []int64
var IV []int64

func init() {
	F = make([]int64, K)
	F[0] = 1
	for i := 1; i < K; i++ {
		F[i] = (int64(i) * F[i-1]) % MOD
	}
	I = make([]int64, K)
	I[K-1] = int64(pow(int(F[K-1]), MOD-2))
	for i := K - 2; i >= 0; i-- {
		I[i] = (int64(i+1) * I[i+1]) % MOD
	}

	IV = make([]int64, K)

	IV[1] = 1
	for i := 2; i < K; i++ {
		IV[i] = IV[MOD%i] * (MOD - MOD/int64(i)) % MOD
	}
}

func pow(a, b int) int {
	A := int64(a)
	R := int64(1)
	for b > 0 {
		if b&1 == 1 {
			R = (R * A) % MOD
		}
		A = (A * A) % MOD
		b >>= 1
	}
	return int(R)
}

func nCr(n, r int) int {
	res := F[n]
	res = (res * I[r]) % MOD
	res = (res * I[n-r]) % MOD
	return int(res)
}

func big_nCr(n, r int) int {
	var res int64 = 1
	for i := n - r + 1; i <= n; i++ {
		res = (res * int64(i)) % MOD
	}

	for i := 1; i <= r; i++ {
		res = (res * IV[i]) % MOD
	}
	return int(res)
}

func solve(n, k int) []int {
	// dp[i][j] = length n array, j swaps to make it sorted
	dp := make([][]int64, 2*k+1)
	dp[0] = make([]int64, 2*k+1)
	for i := 1; i <= 2*k; i++ {
		dp[i] = make([]int64, 2*k+1)
		dp[i][0] = 1
		for j := 1; j <= 2*k; j++ {
			dp[i][j] = (dp[i-1][j] + int64(i-1)*dp[i-1][j-1]%MOD) % MOD
		}
	}
	res := make([]int, k)
	ans := []int64{1, 0}

	for j := 1; j <= k; j++ {
		for i := 1; i <= min(n, 2*j); i++ {
			var cnt int64
			for f := 0; f <= i; f++ {
				if f%2 == 1 {
					cnt = (cnt - (int64(nCr(i, f))*dp[i-f][j])%MOD + MOD) % MOD
				} else {
					cnt = (cnt + int64(nCr(i, f))*dp[i-f][j]) % MOD
				}
			}
			ans[j%2] = (ans[j%2] + (int64(big_nCr(n, i))*cnt)%MOD) % MOD
		}
		res[j-1] = int(ans[j%2])
	}
	return res
}

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


Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.According to the schedule, a student can take the exam for the i-th subject on the day number ai. However, Valera has made an arrangement with each teacher and the teacher of the i-th subject allowed him to take an exam before the schedule time on day bi (bi < ai). Thus, Valera can take an exam for the i-th subject either on day ai, or on day bi. All the teachers put the record of the exam in the student's record book on the day of the actual exam and write down the date of the mark as number ai.Valera believes that it would be rather strange if the entries in the record book did not go in the order of non-decreasing date. Therefore Valera asks you to help him. Find the minimum possible value of the day when Valera can take the final exam if he takes exams so that all the records in his record book go in the order of non-decreasing date.

The first line contains a single positive integer n (1 ≤ n ≤ 5000) — the number of exams Valera will take. Each of the next n lines contains two positive space-separated integers ai and bi (1 ≤ bi < ai ≤ 109) — the date of the exam in the schedule and the early date of passing the i-th exam, correspondingly.

Print a single integer — the minimum possible number of the day when Valera can take the last exam if he takes all the exams so that all the records in his record book go in the order of non-decreasing date.

NoteIn the first sample Valera first takes an exam in the second subject on the first day (the teacher writes down the schedule date that is 3). On the next day he takes an exam in the third subject (the teacher writes down the schedule date, 4), then he takes an exam in the first subject (the teacher writes down the mark with date 5). Thus, Valera takes the last exam on the second day and the dates will go in the non-decreasing order: 3, 4, 5.In the second sample Valera first takes an exam in the third subject on the fourth day. Then he takes an exam in the second subject on the fifth day. After that on the sixth day Valera takes an exam in the first subject.

package main

import (
	"bufio"
	"bytes"
	"errors"
	"io"
	"math/rand"
	"os"
	"strconv"
	"time"
	"sort"
	"unicode/utf8"
)

// ******************************** CODE STARTS ********************************

const (
)

var (
)

func solve() {
	n := readInt()
	array := make([]Tuple, n)
	for i := 0; i < n; i++ {
		array[i].a = readInt()
		array[i].b = readInt()
	}
	sort.Sort(TupleSlice(array))
//	logln(array)
	day := -1
	for i := 0; i < n; i++ {
		if array[i].b >= day {
			day = array[i].b
		} else {
			day = array[i].a
		}
	}
	printInt(day)
	printLine()
}

// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
)

func main() {
	input := os.Stdin
	output := os.Stdout
	//	input, _ := os.Open("")
	//	output, _ := os.Create("")

	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	rand.Seed(int64(time.Now().Nanosecond()))
	solve()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

// Sorting

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	if p[j].a == p[i].a {
		return p[j].b < p[i].b
	} else {
		return p[j].a < p[i].a
	}
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

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

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

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

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

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

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

import (
	"fmt"
	"sort"
)

type Pair struct {
	x int
	y int
}

type PairList []Pair

func (p PairList) Len() int {
	return len(p)
}

func (p PairList) Less(i, j int) bool {
	return p[i].x < p[j].x || (p[i].x == p[j].x && p[i].y < p[j].y)
}

func (p PairList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func main() {
	var n int
	fmt.Scan(&n)
	pairs := make(PairList, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&pairs[i].x, &pairs[i].y)
	}
	sort.Sort(pairs)

	minDay := pairs[0].y
	for _, v := range pairs {
		if v.y < minDay {
			minDay = v.x
		} else {
			minDay = v.y
		}
	}
	fmt.Println(minDay)
}

package main

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

type Pair struct {
	x int
	y int
}

type PairList []Pair

func (p PairList) Len() int {
	return len(p)
}

func (p PairList) Less(i, j int) bool {
	return p[i].x < p[j].x || (p[i].x == p[j].x && p[i].y < p[j].y)
}

func (p PairList) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

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

	var n int
	fmt.Scan(&n)
	pairs := make(PairList, n)

	for i := 0; i < n; i++ {
		for scanner.Scan() {
			if scanner.Text() != "" { break }
		}
		pairValues := strings.Split(scanner.Text(), " ")
		pairs[i].x, _ = strconv.Atoi(pairValues[0])
		pairs[i].y, _ = strconv.Atoi(pairValues[1])
	}
	sort.Sort(pairs)

	minDay := pairs[0].y
	for _, v := range pairs {
		if v.y < minDay {
			minDay = v.x
		} else {
			minDay = v.y
		}
	}
	fmt.Println(minDay)
}

package main

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

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

type Byb []ExamDay

func (a Byb) Len() int 				{ return len(a) }
func (a Byb) Swap(i, j int) 		{ a[i], a[j] = a[j], a[i] }
func (a Byb) Less(i, j int) bool {
	if a[i].a == a[j].a {
		return a[i].b < a[j].b
	}

	return a[i].a < a[j].a
}

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

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

	for i := 0; i < n; i++ {
		a[i].a = nextInt()
		a[i].b = nextInt()
	}

	sort.Sort(Byb(a))
	day := 0
	// println(a)
	for i := 0; i < n; i ++ {
		if day <= a[i].b {
			day = a[i].b
		} else {
			day = a[i].a
		}
		// println(day)
	}

	println(day)
}

type ExamDay struct {
	a, b int
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

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

type branch struct {
    mx, mn int
}
//sort
type navalny []branch
func (a navalny) Len() int           { return len(a) }
func (a navalny) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a navalny) Less(i, j int) bool { return a[i].mx < a[j].mx || (a[i].mx == a[j].mx && a[i].mn < a[j].mn)}
//---

func main() {
    //io
    scanner := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    //---
    var n, cur int
    fmt.Fscan(scanner, &n)
    a := make([]branch, n)

    for i := 0; i < n; i++ {
        fmt.Fscan(scanner, &a[i].mx, &a[i].mn)
    }
    sort.Sort(navalny(a))

    for i := 0; i < n; i++ {
        if cur <= a[i].mn {
            cur = a[i].mn
        } else {
            cur = a[i].mx
        }
    }
    //fmt.Println(cur)
    //fmt.Println(a)
    writer.WriteString(strconv.Itoa(cur))
    writer.Flush()
}

package main

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

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

type pair struct {
	first  int
	second int
}

type pairs []pair

var n int

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	read(&n)
	a := make([]pair, n)

	for i := 0; i < n; i++ {
		read(&a[i].first, &a[i].second)
	}

	sort.Sort(pairs(a))

	/*for i := 0; i < n; i++ {
		writeln(a[i].first, a[i].second)
	}*/

	ans := -1

	for i := 0; i < n; i++ {
		if ans <= a[i].second {
			ans = a[i].second
		} else {
			ans = a[i].first
		}
	}

	writeln(ans)
}

func (a pairs) Len() int {
	return len(a)
}

func (a pairs) Less(i, j int) bool {
	if a[i].first < a[j].first || (a[i].first == a[j].first && a[i].second < a[j].second) {
		return true
	} else {
		return false
	}
}

func (a pairs) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func writeln(num ...int) {

	for _, value := range num {
		out.WriteString(strconv.Itoa(value))
		out.WriteString(" ")
	}
	out.WriteString("\n")
}

func read(num ...*int) {

	for _, value := range num {
		in.Scan()
		*value, _ = strconv.Atoi(in.Text())
	}
}

package main

import (
	"fmt"
	"sort"
)

type exam struct {
	a int
	b int
}

type exams []exam

func (es exams) Len() int      { return len(es) }
func (es exams) Swap(i, j int) { es[i], es[j] = es[j], es[i] }
func (es exams) Less(i, j int) bool {
	if es[i].a == es[j].a {
		return es[i].b < es[j].b
	}
	return es[i].a < es[j].a
}

func main() {
	var n int
	fmt.Scan(&n)
	es := make(exams, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&es[i].a, &es[i].b)
	}
	sort.Sort(es)
	d := 0
	for i := 0; i < n; i++ {
		if es[i].b >= d {
			d = es[i].b
		} else {
			d = es[i].a
		}
	}
	fmt.Println(d)
}

package main

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

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

type Byb []ExamDay

func (a Byb) Len() int 				{ return len(a) }
func (a Byb) Swap(i, j int) 		{ a[i], a[j] = a[j], a[i] }
func (a Byb) Less(i, j int) bool 	{ return a[i].a < a[j].a }

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

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

	for i := 0; i < n; i++ {
		a[i].a = nextInt()
		a[i].b = nextInt()
	}

	sort.Sort(Byb(a))
	day := 0
	// println(a)
	for i := 0; i < n; i ++ {
		if day <= a[i].b {
			day = a[i].b
		} else {
			day = a[i].a
		}
		// println(day)
	}

	println(day)
}

type ExamDay struct {
	a, b int
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}


You have $$$n$$$ chains, the $$$i$$$-th chain consists of $$$c_i$$$ vertices. Vertices in each chain are numbered independently from $$$1$$$ to $$$c_i$$$ along the chain. In other words, the $$$i$$$-th chain is the undirected graph with $$$c_i$$$ vertices and $$$(c_i - 1)$$$ edges connecting the $$$j$$$-th and the $$$(j + 1)$$$-th vertices for each $$$1 \le j < c_i$$$.Now you decided to unite chains in one graph in the following way:   the first chain is skipped;  the $$$1$$$-st vertex of the $$$i$$$-th chain is connected by an edge with the $$$a_i$$$-th vertex of the $$$(i - 1)$$$-th chain;  the last ($$$c_i$$$-th) vertex of the $$$i$$$-th chain is connected by an edge with the $$$b_i$$$-th vertex of the $$$(i - 1)$$$-th chain.   Picture of the first test case. Dotted lines are the edges added during uniting process Calculate the length of the longest simple cycle in the resulting graph.A simple cycle is a chain where the first and last vertices are connected as well. If you travel along the simple cycle, each vertex of this cycle will be visited exactly once.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains the single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of chains you have. The second line of each test case contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$2 \le c_i \le 10^9$$$) — the number of vertices in the corresponding chains. The third line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_1 = -1$$$; $$$1 \le a_i \le c_{i - 1}$$$). The fourth line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$b_1 = -1$$$; $$$1 \le b_i \le c_{i - 1}$$$). Both $$$a_1$$$ and $$$b_1$$$ are equal to $$$-1$$$, they aren't used in graph building and given just for index consistency. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case, print the length of the longest simple cycle.

NoteIn the first test case, the longest simple cycle is shown below:   We can't increase it with the first chain, since in such case it won't be simple — the vertex $$$2$$$ on the second chain will break simplicity.

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

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

	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, A []int, B []int) int64 {
	var best int64
	open := int64(abs(B[1]-A[1])) + 2
	for i := 1; i < n; i++ {
		best = max(best, int64(C[i])-1+open)
		if i < n-1 {
			a, b := A[i+1], B[i+1]
			if a > b {
				a, b = b, a
			}
			if a == b {
				// have to close
				open = 0
			} else {
				open += int64(a - 1)
				open += int64(C[i] - b)
			}
			open = max(open, int64(b-a))
			open += 2
		}
	}
	return best
}

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func max(x, y int64) int64{
	if x>y{
		return x
	}
	return y
}
func abs(x int)int{
	if x<0{
		return -x
	}
	return x
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		c := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&c[i])
		}
		a := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		b := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&b[i])
		}
		var ans,cur int64
		ans = 0
		cur = 0
		for i:=2;i<=n;i++{
			anow := a[i]
			bnow := b[i]
			if anow>bnow{
				temp := anow
				anow=bnow
				bnow=temp
			}
			if i==2{
				cur = int64(bnow-anow)+2+int64(c[i]-1)
				ans = max(ans,cur)
				continue
			}
			if bnow==anow{
				cur = 2+int64(c[i]-1)
			}else{
				t := cur
				t -= int64(abs(a[i]-b[i]))
				t += 2+int64(c[i]-1)
				cur = max(int64(abs(a[i]-b[i]))+2+int64(c[i]-1),t)
			}
			ans = max(ans,cur)
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

func solve(n int64, c, a, b []int64) {
	var (
		ans      int64
		opt      int64
		inD      = make([]int64, n)
		outD     = make([]int64, n)
		prevOutD int64
	)

	inD[n-1] = -1
	outD[n-1] = -1
	for i := int64(0); i < n-1; i++ {
		mx, mn := IntMax(a[i+1], b[i+1]), IntMin(a[i+1], b[i+1])
		inD[i] = mx - mn
		outD[i] = (mn - 1) + (c[i] - mx)
	}

	// ans[i] = c[i] - 1 + 2i + psOutterDist[i-1] + max[j] --> -2j + innerDist[j] - psOutterDist[j]
	prevOutD = outD[0]
	opt = -prevOutD + inD[0]
	for i := int64(1); i < n; i++ {
		if a[i] == b[i] {
			ans = IntMax(ans, c[i]+1)
			prevOutD = outD[i]
			opt = IntMax(-2*(i-1), -prevOutD-2*i+inD[i])
			continue
		}

		res := (c[i] - 1) + prevOutD + 2*i + opt
		ans = IntMax(ans, res)

		prevOutD += outD[i]
		opt = IntMax(opt, -prevOutD-2*i+inD[i])
	}

	printf("%v\n", ans)
}

func main() {
	defer writer.Flush()
	//RedirectInputToFile(reader, "input.txt")
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var (
			n int64
		)
		scan(&n)

		var (
			c = make([]int64, n)
			a = make([]int64, n)
			b = make([]int64, n)
		)
		for i := range c {
			scan(&c[i])
		}
		for i := range a {
			scan(&a[i])
		}
		for i := range b {
			scan(&b[i])
		}

		solve(n, c, a, b)
	}
}

// IntMax returns maximum of received int numbers
func IntMax(nums ...int64) int64 {
	cand := nums[0]
	for _, num := range nums {
		if cand < num {
			cand = num
		}
	}
	return cand
}

func IntMin(nums ...int64) int64 {
	cand := nums[0]
	for _, num := range nums {
		if cand > num {
			cand = num
		}
	}
	return cand
}

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

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

package main

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

func solve(n int64, c, a, b []int64) {
	var (
		ans      int64
		opt      int64
		inD      = make([]int64, n)
		outD     = make([]int64, n)
		prevOutD int64
	)

	inD[n-1] = -1
	outD[n-1] = -1
	for i := int64(0); i < n-1; i++ {
		mx, mn := IntMax(a[i+1], b[i+1]), IntMin(a[i+1], b[i+1])
		inD[i] = mx - mn
		outD[i] = (mn - 1) + (c[i] - mx)
	}

	// ans[i] = c[i] - 1 + 2i + psOutterDist[i-1] + max[j] --> -2j + innerDist[j] - psOutterDist[j]
	prevOutD = outD[0]
	opt = -prevOutD + inD[0]
	for i := int64(1); i < n; i++ {
		if a[i] == b[i] {
			ans = IntMax(ans, c[i]+1)
			prevOutD = outD[i]
			opt = IntMax(-2*(i-1), -prevOutD-2*i+inD[i])
			continue
		}

		res := (c[i] - 1) + prevOutD + 2*i + opt
		ans = IntMax(ans, res)

		prevOutD += outD[i]
		opt = IntMax(opt, -prevOutD-2*i+inD[i])
	}

	printf("%v\n", ans)
}

func main() {
	defer writer.Flush()
	//RedirectInputToFile(reader, "input.txt")
	t := 1
	scan(&t)

	for T := 0; T < t; T++ {
		var (
			n int64
		)
		scan(&n)

		var (
			c = make([]int64, n)
			a = make([]int64, n)
			b = make([]int64, n)
		)
		for i := range c {
			scan(&c[i])
		}
		for i := range a {
			scan(&a[i])
		}
		for i := range b {
			scan(&b[i])
		}

		solve(n, c, a, b)
	}
}

// ------------------------------------------------------------------------------------------------

// UniqueInts takes a sorted slice of ints, transforms it to contain only unique numbers, and returns this slice
// E.g. v = []{3, 3, 7, 8, 8, 8, 9} -> v = []{3, 7, 8, 9}
func UniqueInts(v []int) []int {
	prev := int(0)
	if len(v) > 0 && v[0] == prev {
		prev = -1
	}

	i := 0
	for j := range v {
		if v[j] != prev {
			prev = v[j]
			v[i], v[j] = v[j], v[i]
			i++
		}
	}

	return v[:i]
}

// IntMax returns maximum of received int numbers
func IntMax(nums ...int64) int64 {
	cand := nums[0]
	for _, num := range nums {
		if cand < num {
			cand = num
		}
	}
	return cand
}

// IntMin returns minimum of received int numbers
func IntMin(nums ...int64) int64 {
	cand := nums[0]
	for _, num := range nums {
		if cand > num {
			cand = num
		}
	}
	return cand
}

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.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)
}

package main

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

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

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

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		c := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &c[i])
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &b[i])
		}

		var oldLen, newLen int64
		curLen := int64(-10000000000)
		maxLen := curLen + int64(c[1]-1)
		for i := 1; i < n; i++ {
			if a[i] == b[i] {
				maxLen = max64(curLen+int64(c[i-1]-1), maxLen)
				curLen = 2
			} else {
				oldLen = curLen + int64(c[i-1]-max(a[i], b[i])) + int64(min(a[i], b[i])-1) + 2
				newLen = int64(max(a[i], b[i])-min(a[i], b[i])) + 2
				curLen = max64(oldLen, newLen)
			}
			maxLen = max64(maxLen, curLen+int64(c[i]-1))
			//fmt.Println(curLen, maxLen, i)
		}
		fmt.Println(maxLen)
	}
}

package main

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

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

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

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

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

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

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

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

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

func sol(n int64, c, a, b []int64) int64 {
	dp := make([]int64, n)
	for i := int64(1); i < n; i++ {
		top := a[i]
		btm := b[i]
		if btm < top { // enforce btm > top
			top, btm = btm, top
		}
		curr := c[i] + (btm - top + 1)
		if top != btm {
			curr = max(curr, c[i]+dp[i-1]-(btm-top-1))
		}
		dp[i] = curr
	}
	return max(dp...)
}

func max(a ...int64) int64 {
	ret := int64(0)
	for _, i := range a {
		if i > ret {
			ret = i
		}
	}
	return ret
}

package main

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

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

const maxN = 100005

var c [maxN]int64
var a [maxN]int64
var b [maxN]int64
var f [maxN]int64

func main() {
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n int
		fmt.Fscan(in, &n)
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &c[i])
		}
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &a[i])
		}
		for i := 1; i <= n; i++ {
			fmt.Fscan(in, &b[i])
		}

		var ans int64
		f[1] = -1e9
		for i := 2; i <= n; i++ {
			if a[i] > b[i] {
				a[i], b[i] = b[i], a[i]
			}
			if a[i] == b[i] {
				f[i] = 2
			} else {
				f1 := f[i-1] + c[i-1] - 1 - (b[i] - a[i]) + 2
				f2 := b[i] - a[i] + 2
				if f1 > f2 {
					f[i] = f1
				} else {
					f[i] = f2
				}
			}
			if f[i]+c[i]-1 > ans {
				ans = f[i] + c[i] - 1
			}
		}
		// for i := 1; i <= n; i++ {
		//     fmt.Printf("%d ", f[i])
		// }
		// fmt.Println()
		fmt.Fprintln(out, ans)
	}
	out.Flush()
}

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 int
		Fscan(in, &n)

		ans := int64(0)

		type pair struct{ l, r int64 }
		c := make([]int64, n)
		for i := range c {
			Fscan(in, &c[i])
		}
		a := make([]pair, n)
		for i := range a {
			Fscan(in, &a[i].l)
		}
		for i := range a {
			Fscan(in, &a[i].r)
			if a[i].l > a[i].r {
				a[i].l, a[i].r = a[i].r, a[i].l
			}
		}

		s := c[n-1]
		for i := n - 2; i >= 0; i-- {
			p := a[i+1]
			if p.l == p.r {
				ans = max(ans, s+1)
				s = c[i]
			} else {
				ans = max(ans, s+p.r-p.l+1)
				s = max(c[i], s+c[i]-(p.r-p.l-1))
			}
		}

		Fprintln(out, ans)
	}

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

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

func main() { run(os.Stdin, os.Stdout) }
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

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

	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, A []int, B []int) int64 {
	var best int64 = int64(C[0])
	open := int64(abs(B[1]-A[1])) + 2
	for i := 1; i < n; i++ {
		best = max(best, int64(C[i])-1+open)
		if i < n-1 {
			a, b := A[i+1], B[i+1]
			if a > b {
				a, b = b, a
			}
			if a == b {
				// have to close
				open = 0
			} else {
				open += int64(a - 1)
				open += int64(C[i] - b)
			}
			open += 2
		}
	}
	return best
}

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

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

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

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

	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, A []int, B []int) int64 {
	var best int64
	open := int64(abs(B[1]-A[1])) + 2
	for i := 1; i < n; i++ {
		best = max(best, int64(C[i])-1+open)
		if i < n-1 {
			a, b := A[i+1], B[i+1]
			if a > b {
				a, b = b, a
			}
			if a == b {
				// have to close
				open = 0
			} else {
				open += int64(a - 1)
				open += int64(C[i] - b)
			}
			open += 2
		}
	}
	return best
}

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func max(x, y int) int{
	if x>y{
		return x
	}
	return y
}
func abs(x int)int{
	if x<0{
		return -x
	}
	return x
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		c := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&c[i])
		}
		a := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		b := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&b[i])
		}
		ans := 0
		cur := 0
		for i:=2;i<=n;i++{
			anow := a[i]
			bnow := b[i]
			if anow>bnow{
				temp := anow
				anow=bnow
				bnow=temp
			}
			if i==2{
				cur = (bnow-anow)+2+(c[i]-1)
				ans = max(ans,cur)
				continue
			}
			if bnow==anow{
				cur = 2+(c[i]-1)
			}else{
				t := cur
				t -= abs(a[i]-b[i])
				t += 2+(c[i]-1)
				cur = max(abs(a[i]-b[i])+2+(c[i]-1),t)
			}
			ans = max(ans,cur)
		}
		fmt.Fprintln(out,ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func max(x, y int) int{
	if x>y{
		return x
	}
	return y
}
func abs(x int)int{
	if x<0{
		return -x
	}
	return x
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n int
		fmt.Fscan(in,&n)
		c := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&c[i])
		}
		a := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&a[i])
		}
		b := make([]int,n+5)
		for i:=1;i<=n;i++{
			fmt.Fscan(in,&b[i])
		}
		ans := 0
		cur := 0
		for i:=2;i<=n;i++{
			anow := a[i]
			bnow := b[i]
			if anow>bnow{
				temp := anow
				anow=bnow
				bnow=temp
			}
			if i==2{
				cur = (bnow-anow)+2+(c[i]-1)

				ans = max(ans,cur)
				continue
			}
			if bnow==anow{
				cur = 2+(c[i]-1)
			}else{

				cur -= abs(a[i]-b[i])

				cur += 2+(c[i]-1)
			}
			ans = max(ans,cur)
		}
		fmt.Fprintln(out,ans)
	}
}

package main

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

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

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		c := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &c[i])
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &b[i])
		}

		curLen := int64(max(a[1], b[1])-min(a[1], b[1])) + 2
		maxLen := curLen + int64(c[1]-1)
		for i := 2; i < n; i++ {
			curLen += int64(c[i-1]-max(a[i], b[i])) + int64(min(a[i], b[i])-1) + 2
			if a[i] == b[i] {
				if curLen-2 > maxLen {
					maxLen = curLen - 2
				}
				curLen = 2
			}
			if curLen+int64(c[i]-1) > maxLen {
				maxLen = curLen + int64(c[i]-1)
			}
		}
		curLen += int64(c[n-1] - 1)
		if curLen > maxLen {
			maxLen = curLen
		}
		fmt.Println(maxLen)
	}
}

package main

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

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

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		c := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &c[i])
		}
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &b[i])
		}

		curLen := int64(max(a[1], b[1])-min(a[1], b[1])) + 2
		maxLen := curLen + int64(c[1]-1)
		for i := 2; i < n; i++ {
			curLen += int64(c[i-1]-max(a[i], b[i])) + int64(min(a[i], b[i])-1) + 2
			if a[i] == b[i] {
				curLen -= 2
				if curLen > maxLen {
					maxLen = curLen
				}
				curLen = 2
			} else {
				if curLen-2+int64(c[i]-1) > maxLen {
					maxLen = curLen - 2 + int64(c[i]-1)
				}
			}
		}
		curLen += int64(c[n-1] - 1)
		if curLen > maxLen {
			maxLen = curLen
		}
		fmt.Println(maxLen)
	}
}

package main

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

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

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

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

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

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

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

func sbytes() []byte {
	scanner.Scan()
	return scanner.Bytes()
}

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

func sol(n int64, c, a, b []int64) int64 {
	dp := make([]int64, n)
	for i := int64(1); i < n; i++ {
		top := a[i]
		btm := b[i]
		curr := c[i] + (btm - top + 1)
		if top != btm {
			curr = max(curr, c[i]+dp[i-1]-(btm-top-1))
		}
		dp[i] = curr
	}
	return max(dp...)
}

func max(a ...int64) int64 {
	ret := int64(0)
	for _, i := range a {
		if i > ret {
			ret = i
		}
	}
	return ret
}