package main

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

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

	var t, n int
	var a [4]int
T:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &a[0], &a[1], &a[2], &a[3])
	o:
		for i := 0; i < 16; i++ {
			x := i | i&1<<4
			for j, v := range a {
				if v == 0 && x>>j&3 > 0 || v == 1 && x>>j&3 == 3 || v == n-1 && x>>j&3 == 0 || v == n && x>>j&3 < 3 {
					continue o
				}
			}
			Fprintln(out, "YES")
			continue T
		}
		Fprintln(out, "NO")
	}
}
func main() { CF1494B(os.Stdin, os.Stdout) }

package main

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

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

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

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	for t := 0; t < T; t++ {

		var n, u, d, r, l int
		scanf("%d %d %d %d %d\n", &n, &u, &r, &d, &l)

		var is_ok bool = false
		for i := 0; i <= 15; i++ {
			var nu int = u
			var nr int = r
			var nd int = d
			var nl int = l

			if i&1 == 1 {
				nu = nu - 1
				nl = nl - 1
			}

			if i&2 == 2 {
				nu = nu - 1
				nr = nr - 1
			}

			if i&4 == 4 {
				nd = nd - 1
				nr = nr - 1
			}

			if i&8 == 8 {
				nd = nd - 1
				nl = nl - 1
			}

			if (nu >= 0 && nd >= 0 && nr >= 0 && nl >= 0) && (nu <= n-2 && nd <= n-2 && nr <= n-2 && nl <= n-2) {
				is_ok = true
				break
			}
		}

		if is_ok == true {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main
import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var t, n int
	var a [4]int
T:
	for Scan(&t); t > 0; t-- {
		Scan(&n, &a[0], &a[1], &a[2], &a[3])
	o:
		for i := 0; i < 16; i++ {
			x := i | i&1<<4
			for j, v := range a {
				if v == 0 && x>>j&3 > 0 || v == 1 && x>>j&3 == 3 || v == n-1 && x>>j&3 == 0 || v == n && x>>j&3 < 3 {
					continue o
				}
			}
			Println("YES")
			continue T
		}
		Println("NO")
	}
}

package main

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

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

	var t, n, u, r, d, l int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &u, &r, &d, &l)
		minU, minR, minD, minL, minHor, minVer := 0, 0, 0, 0, 0, 0
		if u == n {
			minR++
			minL++
			minVer += 2
		}
		if u == n-1 {
			minVer++
		}
		if d == n {
			minR++
			minL++
			minVer += 2
		}
		if d == n-1 {
			minVer++
		}
		if l == n {
			minU++
			minD++
			minHor += 2
		}
		if l == n-1 {
			minHor++
		}
		if r == n {
			minU++
			minD++
			minHor += 2
		}
		if r == n-1 {
			minHor++
		}
		if u >= minU && d >= minD && r >= minR && l >= minL && u+d >= minHor && l+r >= minVer {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		arr := make([]int, 4)
		for i := 0; i < 4; i++ {
			_, _ = fmt.Fscan(in, &arr[i])
		}

		ans := false
		for i := 0; i < 16; i++ {
			temp := true
			for j := 0; j < 4; j++ {
				now := 0
				if (i & (1 << j)) > 0 {
					now++
				}
				k := (1 + j) % 4
				if (i & (1 << k)) > 0 {
					now++
				}
				if now > arr[j] {
					temp = false
				}
				if now+n-2 < arr[j] {
					temp = false
				}
			}
			ans = ans || temp
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	for t := 0; t < T; t++ {

		var n, u, d, r, l int
		scanf("%d %d %d %d %d\n", &n, &u, &r, &d, &l)

		var is_ok bool = false
		for i := 0; i <= 15; i++ {
			var nu int = u
			var nr int = r
			var nd int = d
			var nl int = l

			if i&1 == 1 {
				nu = nu - 1
				nl = nl - 1
			}

			if i&2 == 1 {
				nu = nu - 1
				nr = nr - 1
			}

			if i&4 == 1 {
				nd = nd - 1
				nr = nr - 1
			}

			if i&8 == 1 {
				nd = nd - 1
				nl = nl - 1
			}

			if (nu >= 0 && nd >= 0 && nr >= 0 && nl >= 0) && (nu <= n-2 && nd <= n-2 && nr <= n-2 && nl <= n-2) {
				is_ok = true
				break
			}
		}

		if is_ok == true {
			printf("NO\n")
		} else {
			printf("YES\n")
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	for t := 0; t < T; t++ {

		var n, u, d, r, l int
		scanf("%d %d %d %d %d\n", &n, &u, &r, &d, &l)

		var is_ok bool = false
		for i := 0; i <= 15; i++ {
			var nu int = u
			var nr int = r
			var nd int = d
			var nl int = l

			if i&1 == 1 {
				nu = nu - 1
				nl = nl - 1
			}

			if i&2 == 1 {
				nu = nu - 1
				nr = nr - 1
			}

			if i&4 == 1 {
				nd = nd - 1
				nr = nr - 1
			}

			if i&8 == 1 {
				nd = nd - 1
				nl = nl - 1
			}

			if (nu >= 0 && nd >= 0 && nr >= 0 && nl >= 0) && (nu <= n-2 && nd <= n-2 && nr <= n-2 && nl <= n-2) {
				is_ok = true
				break
			}
		}

		if is_ok == true {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

	package main

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

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

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

	func main() {
		defer writer.Flush()

		var T int = 0
		scanf("%d\n", &T)

		for t := 0; t < T; t++ {

			var n, u, d, r, l int
			scanf("%d %d %d %d %d\n", &n, &u, &r, &d, &l)

			var is_ok bool = false
			for i := 0; i <= 15; i++ {
				var nu int = u
				var nr int = r
				var nd int = d
				var nl int = l

				if i&1 == 1 {
					nu = nu - 1
					nl = nl - 1
				}

				if i&2 == 1 {
					nu = nu - 1
					nr = nr - 1
				}

				if i&4 == 1 {
					nd = nd - 1
					nr = nr - 1
				}

				if i&8 == 1 {
					nd = nd - 1
					nl = nl - 1
				}

				if (nu >= 0 && nd >= 0 && nr >= 0 && nl >= 0) || (nu <= n-2 && nd <= n-2 && nr <= n-2 && nl <= n-2) {
					is_ok = true
					break
				}
			}

			if is_ok == true {
				printf("YES\n")
			} else {
				printf("NO\n")
			}
		}
	}

package main

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

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

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

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	for t := 0; t < T; t++ {

		var n, u, d, r, l int
		scanf("%d %d %d %d %d\n", &n, &u, &r, &d, &l)

		var is_ok bool = false
		for i := 1; i <= 15; i++ {
			var nu int = u
			var nr int = r
			var nd int = d
			var nl int = l

			if i&1 == 1 {
				nu = nu - 1
				nl = nl - 1
			}

			if i&2 == 1 {
				nu = nu - 1
				nr = nr - 1
			}

			if i&4 == 1 {
				nd = nd - 1
				nr = nr - 1
			}

			if i&8 == 1 {
				nd = nd - 1
				nl = nl - 1
			}

			if (nu >= 0 && nd >= 0 && nr >= 0 && nl >= 0) || (nu <= n-2 && nd <= n-2 && nr <= n-2 && nl <= n-2) {
				is_ok = true
				break
			}
		}

		if is_ok == true {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

	for t := 0; t < T; t++ {

		var n, u, d, r, l int
		scanf("%d %d %d %d %d\n", &n, &u, &r, &d, &l)

		var is_ok bool = false
		for i := 1; i <= 15; i++ {
			var nu int = u
			var nr int = r
			var nd int = d
			var nl int = l

			if i&1 == 1 {
				nu = nu - 1
				nl = nl - 1
			}

			if i&2 == 1 {
				nu = nu - 1
				nr = nr - 1
			}

			if i&4 == 1 {
				nd = nd - 1
				nr = nr - 1
			}

			if i&8 == 1 {
				nd = nd - 1
				nl = nl - 1
			}

			if (nu > 0 && nd > 0 && nr > 0 && nl > 0) || (nu < n-2 && nd < n-2 && nr < n-2 && nl < n-2) {
				is_ok = true
				break
			}
		}

		if is_ok == true {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

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

	var t, n, u, r, d, l int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &u, &r, &d, &l)
		var minU, minR, minD, minL, minHor, minVer int
		if u == n {
			minR++
			minL++
		}
		if u == n-1 {
			minVer++
		}
		if d == n {
			minR++
			minL++
		}
		if d == n-1 {
			minVer++
		}
		if l == n {
			minU++
			minD++
		}
		if l == n-1 {
			minHor++
		}
		if r == n {
			minU++
			minD++
		}
		if r == n-1 {
			minHor++
		}
		if u >= minU && d >= minD && r >= minR && l >= minL && u+d >= minHor && l+r >= minVer {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Seg struct {
		l, r, t int
	}

	n := io.NextInt()
	a := make([]Seg, n)
	x := []int{-1}
	for i := 0; i < n; i++ {
		a[i] = Seg{io.NextInt(), io.NextInt(), io.NextInt() - 1}
		x = append(x, a[i].l, a[i].r)
	}

	sort.Ints(x)
	lx := len(x)
	idx := func(v int) int { return sort.Search(lx, func(i int) bool { return v <= x[i] }) }
	e := make([][]Seg, lx)
	for _, s := range a {
		s.l, s.r = idx(s.l), idx(s.r)
		e[s.r] = append(e[s.r], s)
	}

	st := []*SegTree{NewSegTree(lx), NewSegTree(lx)}
	for i, ss := range e {
		for _, s := range ss {
			st[s.t].Update(0, s.l, 1)
		}
		c := max(st[0].Query(0, i), st[1].Query(0, i))
		st[0].Update(i, i+1, c)
		st[1].Update(i, i+1, c)
	}

	ans := max(st[0].Query(0, lx), st[1].Query(0, lx))
	io.Println(ans)
}

type SegTree struct {
	n    int
	data []int
	lazy []int
}

func NewSegTree(n int) *SegTree           { return &SegTree{n, make([]int, 4*n), make([]int, 4*n)} }
func (t *SegTree) Update(l, r int, v int) { t.update(1, 0, t.n, l, r, v) }
func (t *SegTree) Query(l, r int) int     { return t.query(1, 0, t.n, l, r) }

func (t *SegTree) get(i int) int { return t.data[i] + t.lazy[i] }

func (t *SegTree) update(i, s, e, l, r int, v int) {
	if e <= l || r <= s {
		return
	}
	if l <= s && e <= r {
		t.lazy[i] += v
		return
	}
	m := (s + e) / 2
	t.update(i*2, s, m, l, r, v)
	t.update(i*2+1, m, e, l, r, v)
	t.data[i] = max(t.get(i*2), t.get(i*2+1))
}

func (t *SegTree) query(i, s, e, l, r int) int {
	if e <= l || r <= s {
		return 0
	}
	if l <= s && e <= r {
		return t.get(i)
	}
	m := (s + e) / 2
	return t.lazy[i] + max(t.query(i*2, s, m, l, r), t.query(i*2+1, m, e, l, r))
}

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	type Event struct {
		l, r, t, i, x int
	}
	type End struct {
		r, i int
	}

	n := io.NextInt()
	var ev []Event
	for i := 0; i < n; i++ {
		l, r, t := io.NextInt(), io.NextInt()+1, io.NextInt()-1
		ev = append(ev, Event{l, r, t, i, l}, Event{l, r, t, i, r})
	}
	sort.Slice(ev, func(i, j int) bool {
		a, b := ev[i], ev[j]
		if a.x != b.x {
			return a.x < b.x
		}
		return a.x == a.r && b.x != b.r
	})

	cmp := func(i, j interface{}) bool { return i.(End).r < j.(End).r }
	h := []Heap{{Les: cmp}, {Les: cmp}}
	rem := make([]bool, n)
	ans := n
	for _, e := range ev {
		if e.x == e.l {
			h[e.t].HPush(End{e.r, e.i})
		} else if !rem[e.i] {
			rem[e.i] = true
			for h[e.t^1].Len() > 0 {
				i := h[e.t^1].HPop().(End).i
				if !rem[i] {
					rem[i] = true
					ans--
					break
				}
			}
		}
	}

	io.Println(ans)
}

type Heap struct {
	Les func(_, _ interface{}) bool
	h   []interface{}
}

func (h Heap) Len() int           { return len(h.h) }
func (h Heap) Less(i, j int) bool { return h.Les(h.h[i], h.h[j]) }
func (h Heap) Swap(i, j int)      { h.h[i], h.h[j] = h.h[j], h.h[i] }

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

func (h *Heap) Pop() interface{} {
	x := h.h[h.Len()-1]
	h.h = h.h[:h.Len()-1]
	return x
}

func (h *Heap) HPush(x interface{}) {
	heap.Push(h, x)
}

func (h *Heap) HPop() interface{} {
	return heap.Pop(h)
}

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{Reader: bufio.NewReader(r), Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}


package main

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

var reader io.Reader
var scanner *bufio.Scanner

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()
	c := make([]int, 26)

	for t := 0; t < T; t++ {
		n, k := NextInt(), NextInt()
		s := NextBytes()
		for i := 0; i < 26; i++ {
			c[i] = 0
		}
		for i := 0; i < n; i++ {
			c[s[i]-'a']++
		}
		filled := 0
		for i := 0; i < 26; i++ {
			if c[i] == 0 {
				continue
			}
			if filled < k {
				if filled+c[i] >= k {
					if filled > 0 {
						fmt.Fprint(out, string(byte('a'+i)))
						break
					} else {
						fmt.Fprint(out, string(byte('a'+i)))
						filled += k
						c[i] -= k
					}
				} else {
					filled += c[i]
					continue
				}
			}
			if c[i] == 0 {
				continue
			}
			if filled+c[i] < n {
				for j := 0; j < c[i]; j++ {
					fmt.Fprint(out, string(byte('a'+i)))
				}
				k = 1
			} else {
				l := c[i] / k
				r := c[i] % k
				for j := 0; j < l; j++ {
					fmt.Fprint(out, string(byte('a'+i)))
				}
				if r != 0 {
					fmt.Fprint(out, string(byte('a'+i)))
				}
			}
			filled += c[i]
		}
		fmt.Fprintln(out)
	}

}

/*
URL:
https://codeforces.com/contest/1348/problem/C
*/

package main

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

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

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

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

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

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

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

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

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

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, k := ReadInt2()
		S := ReadRuneSlice()
		solve(n, k, S)
	}
}

func solve(n, k int, S []rune) {
	tmp := Char{}
	for _, r := range S {
		tmp = append(tmp, r)
	}
	sort.Stable(tmp)

	T := []rune{}
	for i := 0; i < len(tmp); i++ {
		T = append(T, rune(tmp[i]))
	}

	if T[0] != T[k-1] {
		fmt.Printf("%c\n", T[k-1])
		return
	}

	if T[0] == T[n-1] {
		num := Kiriage(n, k)
		for i := 0; i < num; i++ {
			fmt.Printf("%c", T[0])
		}
		fmt.Printf("\n")
		return
	}

	if T[k] == T[n-1] {
		num := Kiriage(n-k, k)
		fmt.Printf("%c", T[0])
		for i := 0; i < num; i++ {
			fmt.Printf("%c", T[k])
		}
		fmt.Printf("\n")
		return
	}

	fmt.Printf("%s\n", string(T[k-1:n]))

	// fmt.Println(string(T[k-1 : n]))
	// for i := 0; i+k-1 < n; i += k {
	// 	if T[i] == T[i+k-1] {
	// 		fmt.Printf("%c", T[i])
	// 	} else {
	// 		fmt.Printf("%s\n", string(T[i:n]))
	// 		return
	// 	}
	// }
	// fmt.Printf("\n")
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

type Char []rune

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

// S := Char{'a', 'b', 'c'}
// sort.Sort(S) or sort.Sort(sort.Reverse(S))

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T, n, k int
	var b []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &k, &b)
		sort.Slice(b, func(i, j int) bool { return b[i] < b[j] })
		if s := string(b); s[k-1] != s[0] {
			Fprintln(out, string(s[k-1]))
		} else if k == n || s[k] != s[n-1] {
			Fprintln(out, s[k-1:])
		} else {
			Fprintln(out, s[:1]+strings.Repeat(s[n-1:], (n-1)/k))
		}
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

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

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

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

func (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}

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

func main() {
	defer writer.Flush()
	t := reader.NextInt64()
	for ; t > 0; t-- {
		_, k := reader.NextInt64(), reader.NextInt64()
		s := reader.NextString()
		writer.Printf("%s\n", sol(s, k))
	}
}

func sol(s string, k int64) string {
	runes := []rune(s)
	sort.Slice(runes, func(a, b int) bool {
		return runes[a] < runes[b]
	})
	ans := make([][]rune, k)
	for i := int64(0); i < k; i++ {
		ans[i] = append(ans[i], runes[i])
	}
	remainCount := count(runes[k:])
	if remainCount == 1 {
		remainEle := int64(len(s)) - k
		var numToAppend int64
		if remainEle % k == 0 {
			numToAppend = remainEle / k
		} else {
			numToAppend = remainEle / k + 1
		}
		for i := int64(0); i < numToAppend; i++ {
			ans[0] = append(ans[0], runes[k])
		}
		first := string(ans[0])
		last := string(ans[len(ans)-1])
		if last > first {
			return last
		}
		return first
	}
	for i := k; i < int64(len(runes)); i++ {
		ans[0] = append(ans[0], runes[i])
	}
	first := string(ans[0])
	last := string(ans[len(ans)-1])
	if last > first {
		return last
	}
	return first
}

func count(runes []rune) int64 {
	m := map[rune]bool{}
	for _, r := range runes {
		m[r] = true
	}
	return int64(len(m))
}

func debug(runes [][]rune) {
	for _, r := range runes {
		writer.Printf("debug: %s \n", string(r))
	}
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

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

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

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

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

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

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

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

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

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

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

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

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

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

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	T := NextInt()
	c := make([]int, 26)

	for t := 0; t < T; t++ {
		n, k := NextInt(), NextInt()
		s := NextBytes()
		for i := 0; i < 26; i++ {
			c[i] = 0
		}
		for i := 0; i < n; i++ {
			c[s[i]-'a']++
		}
		filled := 0
		firstchars := 0
		for i := 0; i < 26; i++ {
			if filled < k {
				if filled+c[i] >= k {
					if filled > 0 {
						fmt.Fprint(out, string(byte('a'+i)))
						break
					} else {
						fmt.Fprint(out, string(byte('a'+i)))
						filled += k
						c[i] -= k
					}
				} else {
					filled += c[i]
					firstchars++
					continue
				}
			}
			if filled+c[i] < n {
				for j := 0; j < c[i]; j++ {
					fmt.Fprint(out, string(byte('a'+i)))
				}
			} else {
				l := c[i] / k
				r := c[i] % k
				for j := 0; j < l; j++ {
					fmt.Fprint(out, string(byte('a'+i)))
				}
				if r != 0 {
					fmt.Fprint(out, string(byte('a'+i)))
				}
			}
			filled += c[i]
		}
		fmt.Fprintln(out)
	}

}


package main

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

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

const (
	//MaxScanTokenSize = 64 * 1024 // package default
	MaxScanTokenSize = 8 * 1024 * 1024 // 8M
)

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

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(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; 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
}

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

func readFloat64Array(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = readFloat64()
	}
	return res
}

func main() {
	defer writer.Flush()

	n, k := readInt(), readInt()
	pre := readIntArray(n)
	aft := readIntArray(n)
	diff := make([]int, n, n)
	total := 0
	for i := 0; i < n; i++ {
		diff[i] = aft[i] - pre[i]
		total += pre[i]
	}
	sort.Sort(sort.Reverse(sort.IntSlice(diff)))
	//for i := 0; i < n; i++ {
	//	fmt.Printf("[%d] %d\n", i, diff[i])
	//}

	save := 0
	for i := 0; i < n; i++ {
		if i < k || diff[i] > 0 {
			continue
		} else {
			save += diff[i]
		}
	}
	total += save
	fmt.Fprintf(writer, "%d\n", total)
}

package main

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

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

type MySlice [][2]int

func (slice MySlice) Len() int           { return len(slice) }
func (slice MySlice) Less(i, j int) bool { return slice[i][1] < slice[j][1] }
func (slice MySlice) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	ini()
	defer writer.Flush()

	n := scanInt()
	k := scanInt()
	k++
	var a [200000]int
	var b MySlice

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

	var temp [2]int
	for i:=0;i<n;i++ {
		temp[0] = i
		temp[1] = a[i] - scanInt()
		b = append(b, temp)
	}

	sort.Sort(b)
	//
	//for i:=0; i<n;i++ {
	//	writer.WriteString(strconv.Itoa(b[i][0]))
	//}
	//writer.WriteString("\n")
	//for i:=0; i<n;i++ {
	//	writer.WriteString(strconv.Itoa(b[i][1]))
	//}
	//writer.WriteString("\n")

	kt := 1
	result := 0
	for i:=0; i<n; i++ {
		if kt < k || b[i][1] < 0 {
			result += a[b[i][0]]
			kt++
			//writer.WriteString("1\n")
		} else {
			result += a[b[i][0]] - b[i][1]
			//writer.WriteString("2\n")
		}
	}

	writer.WriteString(strconv.Itoa(result))

	return

}

func ini() {
	scanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	scanner.Split(bufio.ScanWords)
}

func scanInt() int {
	scanner.Scan()
	i, _ := strconv.Atoi(scanner.Text())
	return i
}

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

package main

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

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
		return
	}

	ab := make([][2]int, n)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for j := 0; j < 2; j++ {
		for i := 0; i < n && scanner.Scan(); i++ {
			_in, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			ab[i][j] = _in
		}
	}

	merge_sort(ab, 0, n-1)

	money := 0
	for i := 0; i < n; i++ {
		if i < k {
			money += ab[i][0]
		} else if ab[i][0]-ab[i][1] < 0 {
			money += ab[i][0]
		} else {
			money += ab[i][1]
		}
	}
	fmt.Println(money)
}

func le(a, b [2]int) bool {
	return (a[0] - a[1]) <= (b[0] - b[1])
}

func merge(buffer [][2]int, start, middle, end int) {
	sorted := make([][2]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if le(buffer[i], buffer[j]) {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer [][2]int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

var stdReader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() (result int) {
	var negative, started bool
READER_LOOP:
	for {
		char, err := stdReader.ReadByte()
		switch {
		case err != nil:
			break READER_LOOP
		case char == '-':
			negative = true
		case unicode.IsDigit(rune(char)):
			started = true
			result = result*10 + int(char&0xf)
		case started:
			break READER_LOOP
		}
	}
	if negative {
		result = -result
	}
	return
}

func main() {
	n, k := readInt(), readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}
	var d []int
	var total, bought int
	for _, ai := range a {
		bi := readInt()
		if ai <= bi {
			total += ai
			bought++
		} else {
			total += bi
			d = append(d, ai-bi)
		}
	}
	sort.Ints(d)
	for i := 0; bought < k; i++ {
		total += d[i]
		bought++
	}
	fmt.Println(total)
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF1519D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sum := int64(0)
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
		sum += a[i] * b[i]
	}

	ans := sum
	for i := 0; i < n; i++ {
		cur := sum
		for l, r := i-1, i+1; l >= 0 && r < n; l, r = l-1, r+1 {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
		}
		cur = sum
		for l, r := i-1, i; l >= 0 && r < n; l, r = l-1, r+1 {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
		}
	}
	Fprint(out, ans)
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func max(x, y int64)int64{
	if x>y{
		return x
	}
	return y
}
func main() {
	in:= bufio.NewReader(os.Stdin)
	out := os.Stdout

	var n int
	fmt.Fscan(in,&n)
	a := make([]int64,n+5)
	b := make([]int64,n+5)
	for i:=1;i<=n;i++{
		fmt.Fscan(in,&a[i])
	}
	for i:=1;i<=n;i++{
		fmt.Fscan(in,&b[i])
	}
	pre := make([]int64,n+5)
	for i:=1;i<=n;i++{
		pre[i]=pre[i-1]+a[i]*b[i]
	}
	f := make([][]int64,n+5)
	for i:=1;i<=n;i++{
		f[i] = make([]int64,n+5)
	}
	for i:=1;i<=n;i++{
		f[i][i]=a[i]*b[i]
	}
	for k:=2;k<=n;k++{
		for i:=1;i+k-1<=n;i++{
			if k==2{
				f[i][i+k-1]=(a[i]*b[i+k-1]+a[i+k-1]*b[i])
				continue
			}else{
				f[i][i+k-1]=f[i+1][i+k-1-1]+(a[i]*b[i+k-1])+(a[i+k-1]*b[i])
			}
		}
	}
	ans := pre[n]
	for i:=1;i<=n;i++{
		for j:=i+1;j<=n;j++{
			ans = max(ans,pre[i-1]+f[i][j]+pre[n]-pre[j])
		}
	}
	fmt.Fprintln(out,ans)
}

package main

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

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

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

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	if len(os.Args[1:]) == 1 {
		file, _ := os.Open(os.Args[1])
		reader = bufio.NewReader(file)
	}

	var n int
	scanf("%d\n", &n)
	a := make([]int64, n)
	b := make([]int64, n)
	var s1, s2 string
	s1, _ = reader.ReadString('\n')
	s2, _ = reader.ReadString('\n')
	//fmt.Println(s1, s2)
	sa := strings.Split(s1, " ")
	sb := strings.Split(s2, " ")
	//fmt.Println(sa, sb)
	dp := make([]int64, len(a))
	dp2 := make([]int64, n+1)
	dp3 := make([][]int64, n)
	for i := 0; i < n; i++ {
		dp3[i] = make([]int64, n)
		for j := 0; j < n; j++ {
			dp3[i][j] = -1
		}
	}
	for i := 0; i < n; i++ {
		dp[i] = -1
	}

	for i := 0; i < n; i++ {
		tmp1, _ := strconv.Atoi(strings.Trim(sa[i], "\r\n"))
		tmp2, _ := strconv.Atoi(strings.Trim(sb[i], "\r\n"))
		a[i] = int64(tmp1)
		b[i] = int64(tmp2)
	}
	dp2[n] = 0
	for i := n - 1; i >= 0; i-- {
		dp2[i] = dp2[i+1] + a[i]*b[i]
	}
	//fmt.Println(a, b)
	printf("%d\n", solve(0, a, b, dp, dp2, dp3))
}

func solve(i int, a, b []int64, dp []int64, dp2 []int64, dp3 [][]int64) int64 {
	if i == len(a) {
		return 0
	}
	if dp[i] != -1 {
		return dp[i]
	}
	dp[i] = a[i]*b[i] + solve(i+1, a, b, dp, dp2, dp3)
	for j := i + 1; j < len(a); j++ {
		dp[i] = max(dp[i], solve2(a, b, i, j, dp3)+dp2[j+1])
	}
	return dp[i]
}

func solve2(a, b []int64, i, j int, dp3 [][]int64) int64 {
	if i > j {
		return 0
	}
	//fmt.Println(i, j, dp3[i][j])
	if dp3[i][j] != -1 {
		return dp3[i][j]
	}
	ans := solve2(a, b, i+1, j-1, dp3)
	if i == j {
		ans += a[i] * b[i]
	} else {
		ans += a[i]*b[j] + a[j]*b[i]
	}

	//fmt.Println(i, j, ans)
	dp3[i][j] = ans
	return ans
}

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

package main

import (
	"fmt"
)

func max(a int64, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	var n int
	fmt.Scan(&n)
	var a, b []int64 = make([]int64, n), make([]int64, n)
	for i := 0; i < n; i++ {
		var x int64
		fmt.Scan(&x)
		a[i] = x
	}
	for i := 0; i < n; i++ {
		var x int64
		fmt.Scan(&x)
		b[i] = x
	}
	var dpr, dpl []int64 = make([]int64, n), make([]int64, n)
	var su int64 = 0
	for i := 0; i < n; i++ {
		su += a[i] * b[i]
		dpl[i] = su
	}
	su = 0
	for i := n - 1; i >= 0; i-- {
		su += a[i] * b[i]
		dpr[i] = su
	}
	var dp [][]int64 = make([][]int64, n)
	for i := range dp {
		dp[i] = make([]int64, n)
	}
	for i := range dp {
		dp[i][i] = (a[i] * b[i])
	}
	for l := 2; l <= n; l++ {
		for i := 0; i < (n - l + 1); i++ {
			j := i + l - 1
			if l == 2 {
				dp[i][j] = (a[i]*b[j] + a[j]*b[i])
			} else {
				dp[i][j] = (a[i]*b[j] + a[j]*b[i]) + dp[i+1][j-1]
			}
		}
	}
	var ans int64 = dpl[n-1]
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			if i == 0 && j == n-1 {
				ans = max(ans, dp[i][j])
			} else if i == 0 {
				ans = max(ans, dp[i][j]+dpr[j+1])
			} else if j == n-1 {
				ans = max(ans, dp[i][j]+dpl[i-1])
			} else {
				ans = max(ans, dp[i][j]+dpl[i-1]+dpr[j+1])
			}
		}
	}
	fmt.Println(ans)
}

package main

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

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

func cf(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)

	fmt.Fprintln(out, n)
}

func cf1519D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	nums1, nums2 := make([]int64, n), make([]int64, n)
	for i := range nums1 {
		fmt.Fscan(in, &nums1[i])
	}
	for i := range nums2 {
		fmt.Fscan(in, &nums2[i])
	}
	f := make([]int64, n+1)
	for i := range nums1 {
		f[i+1] = f[i] + nums1[i]*nums2[i]
	}
	ans := f[n]
	for i := range nums1 {
		for j, d, sum := i, 1, nums1[i]*nums2[i]; j-d >= 0 && j+d < n; d++ {
			sum += nums1[j-d]*nums2[j+d] + nums1[j+d]*nums2[j-d]
			ans = max64(ans, sum+f[n]-f[j+d+1]+f[j-d])
		}
		for j1, j2, d, sum := i, i+1, 0, int64(0); j1-d >= 0 && j2+d < n; d++ {
			sum += nums1[j2+d]*nums2[j1-d] + nums1[j1-d]*nums2[j2+d]
			ans = max64(ans, sum+f[n]-f[j2+d+1]+f[j1-d])
		}
	}

	fmt.Fprintln(out, ans)
}

func cf175C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	nums := make([][2]int64, n)
	for i := range nums {
		fmt.Fscan(in, &nums[i][0], &nums[i][1])
	}
	var t int
	fmt.Fscan(in, &t)
	p := make([]int64, t+2)
	p[t+1] = 1e12
	pre := int64(0)
	for i := 1; i <= t; i++ {
		fmt.Fscan(in, &p[i])
		pre, p[i] = p[i], p[i]-pre
	}
	sort.Slice(nums, func(i, j int) bool {
		return nums[i][1] < nums[j][1]
	})
	sum := int64(0)
	for i, j := 0, 1; i < len(nums); {
		sum += min64(nums[i][0], p[j]) * nums[i][1] * int64(j)
		if nums[i][0] > p[j] {
			nums[i][0] -= p[j]
			j++
		} else {
			p[j] -= nums[i][0]
			i++
		}
	}

	fmt.Fprintln(out, sum)
}

func cf494A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var s string
	fmt.Fscan(in, &s)
	sum, minSum, cnt := 0, len(s), 0
	for i := range s {
		if s[i] == '(' {
			sum++
		} else if s[i] == ')' {
			sum--
		} else {
			sum--
			minSum = sum
			cnt++
		}
		if sum < 0 {
			fmt.Fprintln(out, -1)
			return
		}
		minSum = min(minSum, sum)
	}
	if minSum < sum {
		fmt.Fprintln(out, -1)
	} else {
		fmt.Fprintln(out, strings.Repeat("1\n", cnt-1), sum+1)
	}
}

func cf1281B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	for ; n > 0; n-- {
		var s, c string
		fmt.Fscan(in, &s, &c)
		cs := []byte(s)
		j, a, b := len(s)-1, 0, 0
		for i := len(s) - 1; i >= 0; i-- {
			if cs[i] > cs[j] {
				a, b = i, j
			} else if cs[i] < cs[j] {
				j = i
			}
		}
		cs[a], cs[b] = cs[b], cs[a]
		if s = string(cs); s < c {
			fmt.Fprintln(out, s)
		} else {
			fmt.Fprintln(out, "---")
		}
	}
}

func cf605A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	nums := make([][3]int, n) // nums[0]原数字  nums[1]原下标	nums[2]排序后的下标
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &nums[i][0])
		nums[i][1] = i
	}
	sort.SliceStable(nums, func(i, j int) bool {
		return nums[i][0] < nums[j][0]
	})
	for i := range nums {
		nums[i][2] = i
	}
	sort.Slice(nums, func(i, j int) bool {
		return nums[i][1] < nums[j][1]
	})
	f := make([]int, n+1)
	for _, num := range nums {
		f[num[2]+1] = f[num[2]] + 1
	}

	fmt.Fprintln(out, n-max(f...))
}

func cf297B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, m, k int
	fmt.Fscan(in, &n, &m, &k)
	if n > m {
		fmt.Fprintln(out, "YES")
		return
	}
	a, b := make([]int, n), make([]int, m)
	for i := range a {
		fmt.Fscan(in, &a[i])
	}
	for i := range b {
		fmt.Fscan(in, &b[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sort.Sort(sort.Reverse(sort.IntSlice(b)))
	for i := range a {
		if a[i] > b[i] {
			fmt.Fprintln(out, "YES")
			return
		}
	}

	fmt.Fprintln(out, "NO")
}

func helan(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	nums := make([]int, n)
	for i := range nums {
		fmt.Fscan(in, &nums[i])
	}

	less, more := -1, n
	for i := 0; i < more; i++ {
		if nums[i] == 0 {
			less++
			nums[i], nums[less] = nums[less], nums[i]
		} else if nums[i] == 2 {
			more--
			nums[i], nums[more] = nums[more], nums[i]
			i--
		}
	}

	fmt.Fprintln(out, nums)
}

func cf1203D2(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var s, t string
	fmt.Fscan(in, &s, &t)
	ans := 0
	left, right := make([]int, len(t)), make([]int, len(t))
	i, j := 0, 0
	for ; i < len(s) && j < len(t); i++ {
		if s[i] == t[j] {
			left[j] = i
			j++
		}
	}
	ans = max(ans, len(s)-i)
	i, j = len(s)-1, len(t)-1
	for ; i >= 0 && j >= 0; i-- {
		if s[i] == t[j] {
			right[j] = i
			j--
		}
	}
	ans = max(ans, i+1)
	for k := 0; k < len(t)-1; k++ {
		ans = max(ans, right[k+1]-left[k]-1)
	}

	fmt.Fprintln(out, ans)

}

func cf1196D2(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n, k int
	var s string
	fmt.Fscan(in, &t)
	pat := "RGB"
	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &k, &s)
		ans := k
		for i := 0; i < 3; i++ {
			diff := 0
			for j := range s[:k] {
				if s[j] != pat[(i+j)%3] {
					diff++
				}
			}
			ans = min(ans, diff)
			for j := k; j < n; j++ {
				if s[j] != pat[(i+j)%3] {
					diff++
				}
				if s[j-k] != pat[(i+j-k%3)%3] {
					diff--
				}
				ans = min(ans, diff)
			}
		}

		fmt.Fprintln(out, ans)
	}
}

func cf44H(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var s string
	fmt.Fscan(in, &s)
	f := make([][10]int64, len(s))
	for i := range f[0] {
		f[0][i] = 1
	}
	for i := 1; i < len(s); i++ {
		for j := range f[i] {
			f[i][(j+int(s[i])-'0')/2] += f[i-1][j]
			if (j+int(s[i])-'0')&1 == 1 {
				f[i][(j+int(s[i])-'0'+1)/2] += f[i-1][j]
			}
		}
	}
	flag := true
	for i := range s[:len(s)-1] {
		if s[i]-s[i+1] <= 1 || s[i+1]-s[i] <= 1 {
			continue
		} else {
			flag = false
			break
		}
	}
	ans := int64(0)
	for i := range f[0] {
		ans += f[len(s)-1][i]
	}
	if flag {
		ans--
	}
	fmt.Fprintln(out, ans)
}

func cf1051D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, k int
	fmt.Fscan(in, &n, &k)
	if k == 1 {
		fmt.Fprintln(out, 2)
		return
	}
	mod := int64(998244353)
	f := make([][2]int64, k+1)
	f[1][1], f[2][0] = 2, 2
	for i := 2; i <= n; i++ {
		for j := min(k, 2*i); j >= 2; j-- {
			f[j][1] = (f[j][0]*2 + f[j][1] + f[j-1][1]) % mod
			f[j][0] = (f[j][0] + f[j-2][0] + f[j-1][1]*2) % mod
		}
	}

	fmt.Fprintln(out, (f[k][0]+f[k][1])%mod)
}

func cf1051D3(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, k int
	fmt.Fscan(in, &n, &k)
	if k == 1 {
		fmt.Fprintln(out, 2)
		return
	}
	mod := int64(998244353)
	f := make([][][2]int64, n+1)
	for i := range f {
		f[i] = make([][2]int64, k+1)
	}
	f[1][1][1], f[1][2][0] = 2, 2
	for i := 2; i <= n; i++ {
		f[i][1][1] = 2
		for j := 2; j <= k && j <= 2*i; j++ {
			f[i][j][0] = (f[i-1][j][0] + f[i-1][j-2][0] + f[i-1][j-1][1]*2) % mod
			f[i][j][1] = (f[i-1][j][0]*2 + f[i-1][j][1] + f[i-1][j-1][1]) % mod
		}
	}

	fmt.Fprintln(out, (f[n][k][0]+f[n][k][1])%mod)
}

func cf468A(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	fmt.Fscan(in, &n)
	if n < 4 {
		fmt.Fprintln(out, "NO")
		return
	}
	fmt.Fprintln(out, "YES")
	if (n-4)&1 == 0 {
		fmt.Fprintln(out, "1 * 2 = 2")
		fmt.Fprintln(out, "2 * 3 = 6")
		fmt.Fprintln(out, "6 * 4 = 24")
	} else {
		fmt.Fprintln(out, "2 * 4 = 8")
		fmt.Fprintln(out, "3 * 5 = 15")
		fmt.Fprintln(out, "8 + 15 = 23")
		fmt.Fprintln(out, "23 + 1 = 24")
	}
	for i := 5 + n&1; i < n; i += 2 {
		fmt.Fprintln(out, i+1, "-", i, "= 1")
		fmt.Fprintln(out, "1 * 24 = 24")
	}
}

func cf573B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, ans int
	fmt.Fscan(in, &n)
	arr := make([]int, n+2)
	for i := 1; i <= n; i++ {
		fmt.Fscan(in, &arr[i])
		arr[i] = min(arr[i], arr[i-1]+1)
	}
	for i := n; i >= 1; i-- {
		arr[i] = min(arr[i], arr[i+1]+1)
		ans = max(ans, arr[i])
	}

	fmt.Fprintln(out, ans)
}

func min(nums ...int) int {
	ans := nums[0]
	for _, num := range nums {
		if ans > num {
			ans = num
		}
	}
	return ans
}

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

func max(nums ...int) int {
	ans := nums[0]
	for _, num := range nums {
		if ans < num {
			ans = num
		}
	}
	return ans
}

func max64(nums ...int64) int64 {
	ans := nums[0]
	for _, num := range nums {
		if ans < num {
			ans = num
		}
	}
	return ans
}

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

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"path"
	"runtime"
	"sort"
	"strings"
	"time"
)

/**
https://codeforces.com/contest/1519/problem/d
*/

func main() {
	StdIO(func(fio *fastIO) { cf1519d(fio) })
	// CaseIO(func(fio *fastIO) { cf1519d(fio) })
}

func cf1519d(fio *fastIO) {
	n := fio.r1i()
	a, b := fio.rni64(n), fio.rni64(n)
	var sum int64
	for i, v := range a {
		sum += v * b[i]
	}
	max, prev := sum, sum
	for i := 1; i < (n-1)<<1; i++ {
		l, r := i>>1, i>>1+i&1
		if l == r {
			l--
			r++
		}
		prev = sum
		for l >= 0 && r < n {
			prev += a[l]*b[r] + a[r]*b[l] - a[l]*b[l] - a[r]*b[r]
			max = Max(max, prev)
			l--
			r++
		}
	}
	fio.wln(max)
}

// ================== utils ==================

type _integer_ interface {
	~uint8 | ~uint16 | ~uint32 | ~uint64 | ~int8 | ~int16 | ~int32 | ~int64 | ~int | ~uint
}

type _float_ interface {
	~float32 | ~float64
}

type _number_ interface {
	_integer_ | _float_
}

type _ordered_ interface {
	_number_ | ~string
}

func _select_[T _ordered_](f func(x, t T) bool, ts ...T) T {
	n := len(ts)
	if n == 0 {
		panic("At Least One Argument")
	} else {
		x := ts[0]
		for i := 1; i < n; i++ {
			if f(x, ts[i]) {
				x = ts[i]
			}
		}
		return x
	}
}

func Max[T _ordered_](ts ...T) T {
	return _select_(func(x, t T) bool { return x < t }, ts...)
}
func Min[T _ordered_](ts ...T) T {
	return _select_(func(x, t T) bool { return x > t }, ts...)
}
func SumI[T _integer_](ts []T) (sum uint64) {
	for _, t := range ts {
		sum += uint64(t)
	}
	return
}
func SumF[T _float_](ts []T) (sum float64) {
	for _, t := range ts {
		sum += float64(t)
	}
	return
}
func SortASC[T _ordered_](ts []T) {
	sort.Slice(ts, func(i, j int) bool { return ts[i] < ts[j] })
}
func SortDESC[T _ordered_](ts []T) {
	sort.Slice(ts, func(i, j int) bool { return ts[i] > ts[j] })
}

func SliceInit[T _ordered_ | bool](n int, v T) []T {
	arr := make([]T, n)
	for i := range arr {
		arr[i] = v
	}
	return arr
}

// SliceInit2 M * N
func SliceInit2[T _ordered_ | bool](m, n int, v T) [][]T {
	arr := make([][]T, m)
	for i := range arr {
		arr[i] = SliceInit(n, v)
	}
	return arr
}

// SliceInit3 L * M * N
func SliceInit3[T _ordered_ | bool](l, m, n int, v T) [][][]T {
	arr := make([][][]T, l)
	for i := range arr {
		arr[i] = SliceInit2(m, n, v)
	}
	return arr
}

func b2i[T _integer_](b bool) T {
	if b {
		return 1
	} else {
		return 0
	}
}

// ================== fastIO ==================

// StdIO 标准输入输出，用于提交
func StdIO(f func(fio *fastIO)) {
	fio := newFastIO(os.Stdin, os.Stdout)
	f(fio)
	fio.flush()
}

// CaseIO 测试用例文件输入输出，用于测试，不支持多种答案的情况
// 读入`main`函数文件同目录的`inputs.txt`文件中的测试用例进行测试，文件格式参考`datafiles/inputs.txt`
func CaseIO(f func(fio *fastIO)) {
	_, file, _, _ := runtime.Caller(0)
	inputs, _ := os.Open(path.Dir(file) + "/inputs.txt")
	all, _ := io.ReadAll(inputs)
	buf := new(bytes.Buffer)
	for i, testcase := range strings.Split(string(all), "input\n")[1:] {
		items := strings.Split(testcase, "\noutput\n")
		input, expect := items[0], items[1]
		if expect[len(expect)-1] != '\n' {
			expect += "\n"
		}
		fmt.Printf("\n=== RUN   CASE %d\n", i+1)
		start := time.Now().UnixMilli()
		fio := newFastIO(strings.NewReader(input), buf)
		f(fio)
		fio.flush()
		cost := time.Now().UnixMilli() - start
		answer := buf.String()
		if expect == answer {
			fmt.Printf("--- PASS: CASE %d (%dms)\n", i+1, cost)
		} else {
			fmt.Printf("--- FAIL: CASE %d (%dms)\n[EXPECT]:\n%v[ANSWER]:\n%v", i+1, cost, expect, answer)
		}
		buf.Reset()
	}
}

type fastIO struct {
	reader io.Reader
	writer io.Writer
	out    *bufio.Writer
	buf    []byte // 4KB
	i, n   int
}

func newFastIO(reader io.Reader, writer io.Writer) *fastIO {
	return &fastIO{reader: reader, writer: writer, out: bufio.NewWriter(writer), buf: make([]byte, 1<<12)}
}

// 读取整数
func (f *fastIO) r1i() int             { return fioR1(f.ri) }
func (f *fastIO) r2i() (int, int)      { return fioR2(f.r1i) }
func (f *fastIO) r3i() (int, int, int) { return fioR3(f.r1i) }
func (f *fastIO) rni(n int) []int      { return fioRn(n, f.r1i) }
func (f *fastIO) rxi() (nums []int)    { return fioRx(f.ri) }

func (f *fastIO) rnimms(n int) (min, max int, sum uint64)   { return fioRnMMS(n, f.r1i) }
func (f *fastIO) rximms() (n int, min, max int, sum uint64) { return fioRxMMS(f.ri) }

func (f *fastIO) r1i64() int64                 { return fioR1(f.ri64) }
func (f *fastIO) r2i64() (int64, int64)        { return fioR2(f.r1i64) }
func (f *fastIO) r3i64() (int64, int64, int64) { return fioR3(f.r1i64) }
func (f *fastIO) rni64(n int) []int64          { return fioRn(n, f.r1i64) }
func (f *fastIO) rxi64() (nums []int64)        { return fioRx(f.ri64) }

func (f *fastIO) rni64mms(n int) (min, max int64, sum uint64)   { return fioRnMMS(n, f.r1i64) }
func (f *fastIO) rxi64mms() (n int, min, max int64, sum uint64) { return fioRxMMS(f.ri64) }

// 读取字符串
func (f *fastIO) r1s() []byte                   { return fioR1(f.rs) }
func (f *fastIO) r2s() ([]byte, []byte)         { return fioR2(f.r1s) }
func (f *fastIO) r3s() ([]byte, []byte, []byte) { return fioR3(f.r1s) }
func (f *fastIO) rns(n int) [][]byte            { return fioRn(n, f.r1s) }
func (f *fastIO) rxs() (strs [][]byte)          { return fioRx(f.rs) }

// 输出
func (f *fastIO) w(a ...any)                 { f.panic(fmt.Fprint(f.out, a...)) }
func (f *fastIO) wf(format string, a ...any) { f.panic(fmt.Fprintf(f.out, format, a...)) }
func (f *fastIO) wln(a ...any)               { f.panic(fmt.Fprintln(f.out, a...)) }
func (f *fastIO) flush()                     { f.panic(f.out.Flush()) }

// 尝试读取一个字符
func (f *fastIO) rc() (b byte, err error) {
	if f.i == f.n {
		f.i = 0
		if f.n, _ = f.reader.Read(f.buf); f.n == 0 {
			return 0, io.EOF
		}
	}
	b = f.buf[f.i]
	f.i++
	return
}

// 尝试读取一个整数（包括负数）
func (f *fastIO) ri() (x int, err error)     { return fioRi[int](f.rc) }
func (f *fastIO) ri64() (x int64, err error) { return fioRi[int64](f.rc) }

func fioRi[T _integer_](f func() (byte, error)) (x T, err error) {
	var b byte
	negative := false
	for b, err = f(); err == nil && !isDigit(b); b, err = f() {
		if b == '-' {
			negative = true
		}
	}
	if err != nil {
		return 0, err
	} else {
		x = T(b & 15)
		for b, _ = f(); isDigit(b); b, _ = f() {
			x = x*10 + T(b&15)
		}
		if negative {
			x = -x
		}
		return
	}
}

// 空白字符
var _ioWs = map[byte]bool{' ': true, '\n': true, '\r': true, '\t': true, '\v': true, '\f': true}

// 尝试读取一个被空白字符分隔的字符串
func (f *fastIO) rs() ([]byte, error) {
	b, err := f.rc()
	for ; err == nil && _ioWs[b]; b, err = f.rc() {
	}
	if err != nil {
		return nil, err
	} else {
		chars := []byte{b}
		for b, err = f.rc(); err == nil && !_ioWs[b]; b, err = f.rc() {
			chars = append(chars, b)
		}
		return chars, nil
	}
}

func isDigit(b byte) bool    { return '0' <= b && b <= '9' }
func isUpper(b byte) bool    { return 'A' <= b && b <= 'Z' }
func isLower(b byte) bool    { return 'a' <= b && b <= 'z' }
func isAlphabet(b byte) bool { return isLower(b) || isUpper(b) }

func fioPanic[T _number_ | []byte](x T, err any) T {
	if err != nil {
		panic(err)
	}
	return x
}

func fioR1[T _number_ | []byte](f func() (T, error)) T { return fioPanic(f()) }
func fioR2[T _number_ | []byte](f func() T) (T, T)     { return f(), f() }
func fioR3[T _number_ | []byte](f func() T) (T, T, T)  { return f(), f(), f() }
func fioRn[T _number_ | []byte](n int, f func() T) []T {
	arr := make([]T, n)
	for i := range arr {
		arr[i] = f()
	}
	return arr
}
func fioRx[T _number_ | []byte](f func() (T, error)) (arr []T) {
	for t, err := f(); err == nil; t, err = f() {
		arr = append(arr, t)
	}
	return
}
func fioRnMMS[T _integer_](n int, f func() T) (min, max T, sum uint64) {
	min = f()
	max, sum = min, uint64(min)
	for i := 1; i < n; i++ {
		t := f()
		sum += uint64(t)
		min, max = fioMinMax(min, max, t)
	}
	return
}
func fioRxMMS[T _integer_](f func() (T, error)) (n int, min, max T, sum uint64) {
	if t, err := f(); err == nil {
		n, min, max, sum = 0, t, t, uint64(t)
		for t, err = f(); err == nil; t, err = f() {
			n++
			sum += uint64(t)
			min, max = fioMinMax(min, max, t)
		}
	}
	return
}
func fioMinMax[T _number_](min, max, t T) (T, T) {
	if min > t {
		min = t
	} else if max < t {
		max = t
	}
	return min, max
}

func (fastIO) panic(a ...any) {
	n := len(a)
	if err := a[n-1]; err != nil {
		panic(err)
	}
}

package main

import "fmt"

func main() {
	var n int
	_, _ = fmt.Scan(&n)
	a := make([]int, n)
	b := make([]int, n)
	for i := 0; i < n; i += 1 {
		_, _ = fmt.Scan(&a[i])
	}
	var sum int64 = 0
	for i := 0; i < n; i += 1 {
		_, _ = fmt.Scan(&b[i])
		sum += int64(a[i]) * int64(b[i])
	}
	ans := sum
	for i := 0; i < n*2; i += 1 {
		j, k := i/2, (i+1)/2
		cur := sum
		for j >= 0 && k < n {
			cur -= int64(a[j]) * int64(b[j])
			cur -= int64(a[k]) * int64(b[k])
			cur += int64(a[j]) * int64(b[k])
			cur += int64(a[k]) * int64(b[j])
			if ans < cur {
				ans = cur
			}
			j -= 1
			k += 1
		}
	}
	fmt.Println(ans)
}

package main

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

func max(x, y int64) int64 {
	if x < y {
		return y
	} else {
		return x
	}
}
func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()

	solve := func() {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int64, n)
		b := make([]int64, n)
		pre := make([]int64, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &b[i])
		}
		for i := 0; i < n; i++ {
			if i > 0 {
				pre[i] = pre[i-1] + a[i]*b[i]
			} else {
				pre[i] = a[i] * b[i]
			}
		}
		ans := pre[n-1]
		res := make([]int64, n)
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if i+j < n {
					res[i+j] += a[i] * b[j]
				}
			}
		}
		calc := func(l, r int) int64 {
			if l > r {
				return 0
			} else if l == 0 {
				return pre[r]
			} else {
				return pre[r] - pre[l-1]
			}
		}
		for i := 0; i < n; i++ {
			// for j := i; j < n; j++ {
			// 	fmt.Fprint(out, res[j], " ")
			// }
			// fmt.Fprintln(out)
			for j := i; j < n; j++ {
				if i == 0 {
					ans = max(ans, calc(j+1, n-1)+res[j])
				} else {
					ans = max(ans, pre[i-1]+calc(j+1, n-1)+res[j])
				}
			}
			for j := i; j < n; j++ {
				res[j] -= a[i] * b[j]
				res[j] -= b[i] * a[j]
			}
			for j := 0; j < n-1; j++ {
				res[j] = res[j+1]
			}
			res[n-1] = 0
			for j := i + 1; j < n; j++ {
				res[n-1] += a[j] * b[n-(j-i)]
			}
		}
		fmt.Fprintln(out, ans)

	}

	T := 1
	//fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

import (
	"bufio"
	. "fmt"
	"os"
	// "strings"
	// "container/heap"
	// "bytes"
	// "math"
	// "strconv"
)

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

var n,m int
var k int64
var turn int
const MOD int64 = 1e9 + 7
var s,t string
func solve(){
	dp:=make([][]int64,n)
	a,b:=make([]int64,n),make([]int64,n)
	for i:=0;i<n;i++{
		Fscan(r,&a[i])
	}
	sum:=int64(0)
	for i:=0;i<n;i++{
		Fscan(r,&b[i])
		sum+=a[i]*b[i]
	}
	//dp[l][r]=dp[l+1][r-1]-a[l]*b[l]-a[r]*b[r]+a[l]*b[r]+a[r]*b[l]
	for i:=0;i<n;i++{
		dp[i]=make([]int64,n+1)
		dp[i][i]=sum
		if i>=1{
			dp[i][i-1]=sum
		}
	}
	ans:=sum
	for len:=1;len<n;len++{
		for l:=0;l+len<n;l++{
			r:=l+len
			dp[l][r]=max(dp[l+1][r-1]+(a[l]-a[r])*(b[r]-b[l]),dp[l][r])
			ans=max(ans,dp[l][r])
		}
	}
	Fprint(w,ans)

	return
}

func main(){
	defer w.Flush()
	// Fscan(r,&n,&m)
	Fscan(r,&n)
	// Fscan(r,&turn)
	// Fscan(r,&s)
	// Fscan(r,&k)

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

	solve()
}

/* ===========================PART 1: Math Func ============================  */
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 min(x, y int) int {if x < y {return x};return y}
func memset(a []int, v int) {
    if len(a) == 0 {return}
    a[0] = v
    for bp := 1; bp < len(a); bp *= 2 {
        copy(a[bp:], a[:bp])
    }
}

// /* ===========================PART 2: Heap func ============================  */
// type hp struct{ sort.IntSlice }
// func (h hp) Less(i, j int) bool  { return h.IntSlice[i] > h.IntSlice[j] }
// func (h *hp) Push(v interface{}) { h.IntSlice = append(h.IntSlice, v.(int)) }
// func (h *hp) Pop() interface{}   { a := h.IntSlice; v := a[len(a)-1]; h.IntSlice = a[:len(a)-1]; return v }

//  ===========================PART 3: String func ============================
// func reverse(a []byte){
// 	for i,n :=0,len(a);i<n/2;i++{
// 		a[i],a[n-1-i]=a[n-1-i],a[i]
// 	}
// }

// /* ===========================PART 4: Array func ============================  */
// func reverse(a []int){
// 	for i,n :=0,len(a);i<n/2;i++{
// 		a[i],a[n-1-i]=a[n-1-i],a[i]
// 	}
// }

// /* ===========================PART 5: Hash func ============================  */
// func containKey(m map[int]int, key int) bool {
// 	if _, ok := m[key]; ok {
// 		return true
// 	}
// 	return false
// }

package main

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

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

var n,m int
var k int64
var turn int
const MOD int64 = 1e9 + 7
var s,t string
func solve(){
	dp:=make([][]int64,n+1)
	a,b:=make([]int64,n),make([]int64,n)
	for i:=0;i<n;i++{
		Fscan(r,&a[i])
	}
	for i:=0;i<n;i++{
		Fscan(r,&b[i])
	}
	sum:=int64(0)
	for i:=0;i<n;i++{
		sum+=a[i]*b[i]
	}
	//dp[l][r]=dp[l+1][r-1]-a[l]*b[l]-a[r]*b[r]+a[l]*b[r]+a[r]*b[l]
	for i:=0;i<n;i++{
		dp[i]=make([]int64,n+1)
		dp[i][i]=sum
		if i>=1{
			dp[i][i-1]=sum
		}
	}
	ans:=sum
	for len:=1;len<n;len++{
		for l:=0;l+len<n;l++{
			r:=l+len
			dp[l][r]=max(dp[l+1][r-1]-a[l]*b[l]-a[r]*b[r]+a[l]*b[r]+a[r]*b[l],dp[l][r])
			ans=max(ans,dp[l][r])
		}
	}
	Fprint(w,ans)

	return
}

func main(){
	defer w.Flush()
	// Fscan(r,&n,&m)
	Fscan(r,&n)
	// Fscan(r,&turn)
	// Fscan(r,&s)
	// Fscan(r,&k)

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

	solve()
}

/* ===========================PART 1: Math Func ============================  */
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 min(x, y int) int {if x < y {return x};return y}
func memset(a []int, v int) {
	if len(a) == 0 {return}
	a[0] = v
	for bp := 1; bp < len(a); bp *= 2 {
		copy(a[bp:], a[:bp])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1519D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	sum := int64(0)
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
		sum += a[i] * b[i]
	}

	ans := sum
	for i := 0; i < n; i++ {
		cur := sum
		for l, r := i-1, i+1; l >= 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
		cur = sum
		for l, r := i-1, i; l >= 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
	}
	Fprint(out, ans)
}

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

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	var sum int64
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
		sum += a[i] * b[i]
	}

	ans := sum
	for i := 0; i < n; i++ {
		cur := sum
		for l, r := i-1, i+1; l >= 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
		cur = sum
		for l, r := i-1, i; l >= 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
	}
	Fprint(out, ans)
}

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

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

package main
import("bufio";."fmt";"os")

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	n,s:=0,int64(0)
	Fscan(in,&n)
	a:=make([][2]int64,n)
	for i:= range a{Fscan(in,&a[i][0])}
	for i:= range a{Fscan(in,&a[i][1]); s+=a[i][0]*a[i][1]}
	c := make([]int64, 2*n)
	ans := s
	for i, p := range a {
		for j, q := range a[:i] {
			if c[i+j]-=(p[0]-q[0])*(p[1]-q[1]); s+c[i+j]>ans {
				ans=s+c[i+j]
			}
		}
	}
	Print(ans)
}

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	var sum int64
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
		sum += a[i] * b[i]
	}

	ans := sum
	for i := 0; i < n; i++ {
		cur := sum
		for l, r := i-1, i+1; l >= 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
		cur = sum
		for l, r := i-1, i; l >= 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
	}
	Fprint(out, ans)
}

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

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

package main

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

func CF1519D(as []int, bs []int) int64 {
	n := len(as)
	var ans int64
	for i := 0; i < n; i++ {
		ans += int64(as[i]) * int64(bs[i])
	}
	base := ans
	nega := make([][]int64, n)
	for i := n - 1; i >= 0; i-- {
		nega[i] = make([]int64, n)
		for j := i; j < n; j++ {
			if i == j {
				nega[i][j] = int64(as[j]) * int64(bs[j])
			} else if i == j-1 {
				nega[i][j] = int64(as[i])*int64(bs[j]) + int64(as[j])*int64(bs[i])
			} else {
				nega[i][j] = int64(as[i])*int64(bs[j]) + int64(as[j])*int64(bs[i]) + nega[i+1][j-1]
			}
		}
	}

	for i := 0; i < n; i++ {
		var posi int64 = 0
		for j := i; j >= 0; j-- {
			posi += int64(as[j]) * int64(bs[j])
			ans = max(ans, base-posi+nega[j][i])
		}
	}
	return ans
}

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

func main() {
	// read, _ := os.Open("input.txt")
	read := os.Stdin
	write := os.Stdout
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	as := make([]int, n)
	bs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &as[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &bs[i])
	}
	fmt.Fprintln(out, CF1519D(as, bs))
}

package main

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

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

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

	var n int64
	fmt.Fscan(_r, &n)
	a, b := make([]int64, n), make([]int64, n)
	for i := int64(0); i < n; i++ {
		fmt.Fscan(_r, &a[i])
	}
	sum := int64(0)
	for i := int64(0); i < n; i++ {
		fmt.Fscan(_r, &b[i])
		sum += a[i] * b[i]
	}

	ans := sum
	for i := int64(0); i < n; i++ {
		cur := sum
		for l, r := i-1, i+1; l >= 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
		cur = sum
		for l, r := i-1, i; l >= 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
	}
	fmt.Fprintln(_w, ans)
}

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

package main

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

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

var n,m int
var k int64
var turn int
const MOD int64 = 1e9 + 7
var s,t string
func solve(){
	dp:=make([][]int64,n+1)
	a,b:=make([]int64,n),make([]int64,n)
	for i:=0;i<n;i++{
		Fscan(r,&a[i])
	}
	for i:=0;i<n;i++{
		Fscan(r,&b[i])
	}
	sum:=int64(0)
	for i:=0;i<n;i++{
		sum+=a[i]*b[i]
	}
	//dp[l][r]=dp[l+1][r-1]-a[l]*b[l]-a[r]*b[r]+a[l]*b[r]+a[r]*b[l]
	for i:=0;i<n;i++{
		dp[i]=make([]int64,n+1)
		dp[i][i]=sum
		if i>1{
			dp[i][i-1]=sum
		}
	}
	ans:=sum
	for len:=1;len<n;len++{
		for l:=0;l+len<n;l++{
			r:=l+len
			dp[l][r]=max(dp[l+1][r-1]-a[l]*b[l]-a[r]*b[r]+a[l]*b[r]+a[r]*b[l],dp[l][r])
			ans=max(ans,dp[l][r])
		}
	}
	Fprint(w,ans)

	return
}

func main(){
	defer w.Flush()
	// Fscan(r,&n,&m)
	Fscan(r,&n)
	// Fscan(r,&turn)
	// Fscan(r,&s)
	// Fscan(r,&k)

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

	solve()
}

/* ===========================PART 1: Math Func ============================  */
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 min(x, y int) int {if x < y {return x};return y}
func memset(a []int, v int) {
	if len(a) == 0 {return}
	a[0] = v
	for bp := 1; bp < len(a); bp *= 2 {
		copy(a[bp:], a[:bp])
	}
}

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	var sum int64
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
		sum += a[i] * b[i]
	}

	ans := sum
	for i := 0; i < n; i++ {
		cur := sum
		for l, r := i-1, i+1; l > 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
		cur = sum
		for l, r := i-1, i; l > 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
		cur = sum
		for l, r := i, i+1; l > 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
	}
	Fprintln(out, ans)
}

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

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

package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	var sum int64
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
		sum += a[i] * b[i]
	}

	ans := sum

	//center
	for i := 1; i < n-1; i++ {
		cur := sum
		for l, r := i-1, i+1; l > 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
	}

	for i := 1; i < n; i++ {
		cur := sum
		for l, r := i-1, i; l > 0 && r < n; l-- {
			cur -= (a[l] - a[r]) * (b[l] - b[r])
			ans = max(ans, cur)
			r++
		}
	}
	Fprint(out, ans)
}

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

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

package main

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

func CF1519D(as []int, bs []int) int64 {
	n := len(as)
	var ans int64
	for i := 0; i < n; i++ {
		ans += int64(as[i] * bs[i])
	}
	base := ans
	nega := make([][]int64, n)
	for i := n - 1; i >= 0; i-- {
		nega[i] = make([]int64, n)
		for j := i; j < n; j++ {
			if i == j {
				nega[i][j] = int64(as[j]) * int64(bs[j])
			} else if i == j-1 {
				nega[i][j] = int64(as[i])*int64(bs[j]) + int64(as[j])*int64(bs[i])
			} else {
				nega[i][j] = int64(as[i])*int64(bs[j]) + int64(as[j])*int64(bs[i]) + nega[i+1][j-1]
			}
		}
	}

	for i := 0; i < n; i++ {
		var posi int64 = 0
		for j := i; j >= 0; j-- {
			posi += int64(as[j]) * int64(bs[j])
			ans = max(ans, base-posi+nega[j][i])
		}
	}
	return ans
}

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

func main() {
	// read, _ := os.Open("input.txt")
	read := os.Stdin
	write := os.Stdout
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	as := make([]int, n)
	bs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &as[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &bs[i])
	}
	fmt.Fprintln(out, CF1519D(as, bs))
}

package main

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

func CF1519D(as []int, bs []int) int64 {
	n := len(as)
	var ans int64
	for i := 0; i < n; i++ {
		ans += int64(as[i] * bs[i])
	}
	base := ans
	nega := make([][]int64, n)
	for i := n - 1; i >= 0; i-- {
		nega[i] = make([]int64, n)
		for j := i; j < n; j++ {
			if i == j {
				nega[i][j] = int64(as[j] * bs[j])
			} else if i == j-1 {
				nega[i][j] = int64(as[i]*bs[j] + as[j]*bs[i])
			} else {
				nega[i][j] = int64(as[i]*bs[j]+as[j]*bs[i]) + nega[i+1][j-1]
			}
		}
	}

	for i := 0; i < n; i++ {
		var posi int64 = 0
		for j := i; j >= 0; j-- {
			posi += int64(as[j] * bs[j])
			ans = max(ans, base-posi+nega[j][i])
		}
	}
	return ans
}

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

func main() {
	// read, _ := os.Open("input.txt")
	read := os.Stdin
	write := os.Stdout
	in := bufio.NewReader(read)
	out := bufio.NewWriter(write)
	defer out.Flush()
	var n int
	fmt.Fscan(in, &n)
	as := make([]int, n)
	bs := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &as[i])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &bs[i])
	}
	fmt.Fprintln(out, CF1519D(as, bs))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
func max(x, y int)int{
	if x>y{
		return x
	}
	return y
}
func main() {
	in:= bufio.NewReader(os.Stdin)
	out := os.Stdout

	var n int
	fmt.Fscan(in,&n)
	a := make([]int,n+5)
	b := make([]int,n+5)
	for i:=1;i<=n;i++{
		fmt.Fscan(in,&a[i])
	}
	for i:=1;i<=n;i++{
		fmt.Fscan(in,&b[i])
	}
	pre := make([]int,n+5)
	for i:=1;i<=n;i++{
		pre[i]=pre[i-1]+a[i]*b[i]
	}
	f := [5005][5005]int{}
	for i:=1;i<=n;i++{
		f[i][i]=a[i]*b[i]
	}
	for k:=2;k<=n;k++{
		for i:=1;i+k-1<=n;i++{
			if k==2{
				f[i][i+k-1]=(a[i]*b[i+k-1]+a[i+k-1]*b[i])
				continue
			}else{
				f[i][i+k-1]=f[i+1][i+k-1-1]+(a[i]*b[i+k-1])+(a[i+k-1]*b[i])
			}
		}
	}
	ans := pre[n]
	for i:=1;i<=n;i++{
		for j:=i+1;j<=n;j++{
			ans = max(ans,pre[i-1]+f[i][j]+pre[n]-pre[j])
		}
	}
	fmt.Fprintln(out,ans)
}

package main

import (
	"fmt"
)

func max(a int64, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}
func main() {
	var n int
	fmt.Scanln(&n)
	var a, b []int64 = make([]int64, n), make([]int64, n)
	for i := 0; i < n; i++ {
		var x int64
		fmt.Scanln(&x)
		a[i] = x
	}
	for i := 0; i < n; i++ {
		var x int64
		fmt.Scanln(&x)
		b[i] = x
	}
	var dpr, dpl []int64 = make([]int64, n), make([]int64, n)
	var su int64 = 0
	for i := 0; i < n; i++ {
		su += a[i] * b[i]
		dpl[i] = su
	}
	su = 0
	for i := n - 1; i >= 0; i-- {
		su += a[i] * b[i]
		dpr[i] = su
	}
	var dp [][]int64 = make([][]int64, n)
	for i := range dp {
		dp[i] = make([]int64, n)
	}
	for i := range dp {
		dp[i][i] = (a[i] * b[i])
	}
	for l := 2; l <= n; l++ {
		for i := 0; i < (n - l + 1); i++ {
			j := i + l - 1
			if l == 2 {
				dp[i][j] = (a[i]*b[j] + a[j]*b[i])
			} else {
				dp[i][j] = (a[i]*b[j] + a[j]*b[i]) + dp[i+1][j-1]
			}
		}
	}
	var ans int64 = dpl[n-1]
	for i := 0; i < n; i++ {
		for j := i; j < n; j++ {
			if i == 0 && j == n-1 {
				ans = max(ans, dp[i][j])
			} else if i == 0 {
				ans = max(ans, dp[i][j]+dpr[j+1])
			} else if j == n-1 {
				ans = max(ans, dp[i][j]+dpl[i-1])
			} else {
				ans = max(ans, dp[i][j]+dpl[i-1]+dpr[j+1])
			}
		}
	}
	fmt.Println(ans)
}


package main

import "fmt"

var on [105]int

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

	u, v := 0, 0
	for i := 0; i < n; i++ {
		fmt.Scan(&u)
		for j := 0; j < u; j++ {
			fmt.Scan(&v)
			on[v] += 1
		}
	}

	for i := 1; i <= m; i++ {
		if on[i] == 0 {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")

}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var dict = make(map[int]int)
	for i := 0; i < n; i++ {
		var numBulb int
		fmt.Scan(&numBulb)
		for j := 0; j < numBulb; j++ {
			var id int
			fmt.Scan(&id)
			dict[id] = 1
		}
	}
	var dictlen = len(dict)
	if dictlen < m {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

package main

import "fmt"

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

    on := make([]bool, m)
    num_on := 0
    for i := 0; i < n; i++ {
        var x int
        fmt.Scanf("%d", &x);
        for j := 0; j < x; j++ {
            var y int
            fmt.Scanf("%d", &y)
            if !on[y-1] {
                on[y-1] = true
                num_on++
            }
        }
        fmt.Scanf("\n")
    }

    if num_on == m {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

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

    scanner.Scan()
    m, _ := strconv.Atoi(scanner.Text())

    mm := make(map[int]bool)
    for i:=0 ; i<n ; i++ {
        scanner.Scan()
        xn, _ := strconv.Atoi(scanner.Text())
        for j:=0 ; j<xn ; j++ {
            scanner.Scan()
            x, _ := strconv.Atoi(scanner.Text())
            mm[x] = true
        }
    }

    if len(mm) == m {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

import (
	"fmt"
)

func main() {
	var n, m uint
	mee := make(map[uint]uint)
	//in := bufio.NewReader(os.Stdin)
	fmt.Scan(&n, &m)
	for i := uint(0); i < n; i++ {
		var b, c uint
		fmt.Scan(&b)
		for j := uint(0); j < b; j++ {
			fmt.Scan(&c)
			mee[c] = c
		}
	}
	if len(mee) == int(m) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
	//fmt.Println(mee)
}

package main

import (
    "fmt"
    )

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

    bulbs := make([]bool, m, m)
    for i := 0; i < n; i++ {
        var x, y int
        fmt.Scan(&x)
        for j := 0; j < x; j++ {
            fmt.Scan(&y)
            bulbs[y-1] = true
        }
    }

    possible := true
    for i := 0; i < m; i++ {
        if bulbs[i] == false {
            possible = false
            break
        }
    }

    if possible {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

func main() {
	n := nextInt()
	m := nextInt()
	can := make([]bool, m)
	for i := 0; i < n; i++ {
		x := nextInt()
		for j := 0; j < x; j++ {
			y := nextInt() - 1
			can[y] = true
		}
	}
	for i := 0; i < m; i++ {
		if !can[i] {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
}

func init() {
	// maybe defer writer.Flush() in main

	lineScanner = bufio.NewScanner(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)

	/*
		inputFile, err := os.Open("a.in")
		if err != nil {
			panic(err)
		}
		outputFile, err := os.Create("a.out")
		if err != nil {
			panic(err)
		}
		lineScanner = bufio.NewScanner(inputFile)
		writer = bufio.NewWriter(outputFile)
	*/

	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

var writer *bufio.Writer

func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

import (
	"fmt"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	ma := make([]bool,m)
	for i :=0;i<n;i++ {
		var x int
		fmt.Scan(&x)
		for j :=0;j<x; j++ {
			var l int
			fmt.Scan(&l)
			ma[l-1] = true
		}
	}
	flag := true
	for _,b := range(ma) {
		if !b {
			flag = false
			break
		}
	}
	if flag {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	scanner.Text()

	resMap := make(map[int]int)
	for i := 0; i < n; i++ {
		scanner.Scan()
		bulbIn := scanner.Text()//[:len(scanner.Text()) - 2]
		bulbs := strings.Split(bulbIn, " ")
		bulbSum, _ := strconv.Atoi(bulbs[0])
		for j := 1; j <= bulbSum; j++ {
			bulbIdx, _ := strconv.Atoi(bulbs[j])
			resMap[bulbIdx]++
		}
	}
	if len(resMap) == m {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

	resMap := make(map[int]int)
	for i := 0; i < n; i++ {
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		bulbIn := scanner.Text()
		bulbs := strings.Split(bulbIn, " ")
		bulbSum, _ := strconv.Atoi(bulbs[0])
		for j := 1; j <= bulbSum; j++ {
			bulbIdx, _ := strconv.Atoi(bulbs[j])
			resMap[bulbIdx]++
		}
	}
	if len(resMap) == m {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

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

	resMap := make(map[int]int)
	for i := 0; i < n; i++ {
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		bulbIn := scanner.Text()
		bulbs := strings.Split(bulbIn, " ")
		bulbSum, _ := strconv.Atoi(bulbs[0])
		for j := 1; j <= bulbSum; j++ {
			bulbIdx, _ := strconv.Atoi(bulbs[j])
			resMap[bulbIdx]++
		}
	}
	// fmt.Println(resMap)
	if len(resMap) == m {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

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

	resMap := make(map[int]int)
	for i := 0; i < n; i++ {
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		bulbIn := scanner.Text()
		bulbs := strings.Split(bulbIn, " ")
		bulbSum, _ := strconv.Atoi(bulbs[0])
		for j := 1; j <= bulbSum; j++ {
			bulbIdx, _ := strconv.Atoi(bulbs[j])
			resMap[bulbIdx]++
		}
	}
	if len(resMap) == m {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

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

	resMap := make(map[int]int)
	for i := 0; i < n; i++ {
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		bulbIn := scanner.Text()
		bulbs := strings.Split(bulbIn, " ")
		bulbSum, _ := strconv.Atoi(bulbs[0])
		for j := 1; j <= bulbSum; j++ {
			bulbIdx, _ := strconv.Atoi(bulbs[j])
			resMap[bulbIdx]++
		}
	}
	// fmt.Println(resMap)
	if len(resMap) == m {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

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

	resMap := make(map[int]int)
	for i := 0; i <= n; i++ {
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		bulbIn := strings.Trim(scanner.Text(), "\n")
		bulbs := strings.Split(bulbIn, " ")
		bulbSum, _ := strconv.Atoi(bulbs[0])
		for j := 1; j <= bulbSum; j++ {
			bulbIdx, _ := strconv.Atoi(bulbs[j])
			resMap[bulbIdx]++
		}
	}
	if len(resMap) == m {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

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

	resMap := make(map[int]int)
	for i := 0; i < n; i++ {
		scanner := bufio.NewScanner(os.Stdin)
		scanner.Scan()
		bulbIn := scanner.Text()//[:len(scanner.Text()) - 2]
		bulbs := strings.Split(bulbIn, " ")
		bulbSum, _ := strconv.Atoi(bulbs[0])
		for j := 1; j <= bulbSum; j++ {
			bulbIdx, _ := strconv.Atoi(bulbs[j])
			resMap[bulbIdx]++
		}
	}
	if len(resMap) == m {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import "fmt"

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

    on := make([]bool, m)
    num_on := 0
    for i := 0; i < n; i++ {
        var x int
        fmt.Scanf("%d", &x);
        for j := 0; j < x; j++ {
            var y int
            fmt.Scanf("%d", &y)
            if !on[y-1] {
                on[y-1] = true
                num_on++
            }
        }
        //fmt.Scanf("\n")
    }

    if num_on == m {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

func main() {
	var n, m uint
	mee := make(map[uint]uint)
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	for i := uint(0); i < n; i++ {
		var b, c uint
		fmt.Fscanf(in, "%d", &b)
		for j := uint(0); j < b; j++ {
			if j == b-1 {
				fmt.Fscanf(in, "%d\n", &c)
				mee[c] = c
			} else {
				fmt.Fscanf(in, "%d ", &c)
				mee[c] = c
			}

		}
	}
	if len(mee) == int(m) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"fmt"
)

func main() {
	var n, m uint
	mee := make(map[uint]uint)
	//in := bufio.NewReader(os.Stdin)
	fmt.Scan(&n, &m)
	for i := uint(0); i < n; i++ {
		var b, c uint
		fmt.Scan(&b)
		for j := uint(0); j < b; j++ {
			fmt.Scan(&c)
			mee[c] = c
		}
	}
	if len(mee) == int(m) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
	fmt.Println(mee)
}