A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length $$$0$$$ are not allowed).Let's consider empty cells are denoted by '.', then the following figures are stars:  The leftmost figure is a star of size $$$1$$$, the middle figure is a star of size $$$2$$$ and the rightmost figure is a star of size $$$3$$$. You are given a rectangular grid of size $$$n \times m$$$ consisting only of asterisks '*' and periods (dots) '.'. Rows are numbered from $$$1$$$ to $$$n$$$, columns are numbered from $$$1$$$ to $$$m$$$. Your task is to draw this grid using any number of stars or find out that it is impossible. Stars can intersect, overlap or even coincide with each other. The number of stars in the output can't exceed $$$n \cdot m$$$. Each star should be completely inside the grid. You can use stars of same and arbitrary sizes.In this problem, you do not need to minimize the number of stars. Just find any way to draw the given grid with at most $$$n \cdot m$$$ stars.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$3 \le n, m \le 100$$$) — the sizes of the given grid. The next $$$n$$$ lines contains $$$m$$$ characters each, the $$$i$$$-th line describes the $$$i$$$-th row of the grid. It is guaranteed that grid consists of characters '*' and '.' only.

If it is impossible to draw the given grid using stars only, print "-1". Otherwise in the first line print one integer $$$k$$$ ($$$0 \le k \le n \cdot m$$$) — the number of stars needed to draw the given grid. The next $$$k$$$ lines should contain three integers each — $$$x_j$$$, $$$y_j$$$ and $$$s_j$$$, where $$$x_j$$$ is the row index of the central star character, $$$y_j$$$ is the column index of the central star character and $$$s_j$$$ is the size of the star. Each star should be completely inside the grid.

NoteIn the first example the output 23 4 13 5 2is also correct.

package main

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

func main()  {

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

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

	starts, used := make([][]bool, n), make([][]bool, n)
	for i := 0; i < n; i++ {
		starts[i] = make([]bool, m)
		used[i] = make([]bool, m)
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < m; j++ {
			if s[j] == '*' {
				starts[i][j] = true
			}
		}
	}

	result := make([]int, 0)

	for x := 1; x < n - 1; x++ {

		for y := 1; y < m - 1; y++ {

			if starts[x][y] {

				length := 1

				for {

					if x - length < 0 || x + length >= n {
						break
					}
					if y - length < 0 || y + length >= m {
						break
					}

					f := true

					if !starts[x + length][y] {
						f = false
					}
					if !starts[x - length][y] {
						f = false
					}
					if !starts[x][y + length] {
						f = false
					}
					if !starts[x][y - length] {
						f = false
					}
					if !f {
						break
					}

					used[x][y] = true
					used[x + length][y] = true
					used[x - length][y] = true
					used[x][y + length] = true
					used[x][y - length] = true

					if length == 1 {
						result = append(result, x)
						result = append(result, y)
						result = append(result, length)
					} else {
						result[len(result) - 1] = length
					}

					length++

				}

			}

		}

	}

	check := true
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if starts[i][j] && !used[i][j] {
				check = false
				break
			}
		}
	}

	if !check {
		fmt.Fprintln(out, "-1")
	} else {
		fmt.Fprintln(out, len(result) / 3)
		for i := 0; i < len(result); i += 3 {
			fmt.Fprintln(out, result[i] + 1, result[i + 1] + 1, result[i + 2])
		}
	}

}

package main

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

func main() {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

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

	var n, m int
	var sky [1000][1000]byte
	Fscan(in, &n, &m)
	for i := 0; i < n; i++ {
		var s string
		Fscan(in, &s)
		copy(sky[i][:], s)
	}

	var marks [1000][1000]bool
	var maxLen [1000][1000]int

	valid := func(i, j, len int) bool {
		left := j+len < m && sky[i][j+len] == '*'
		right := j-len >= 0 && sky[i][j-len] == '*'

		top := i-len >= 0 && sky[i-len][j] == '*'
		down := i+len < n && sky[i+len][j] == '*'

		return left && right && top && down
	}

	findRightLen := func(i, j int) int {
		if !marks[i][j-1] {
			return 0
		}
		for k := j - 1; k >= 1; k-- {
			if sky[i][k] != '*' {
				return 0
			}
			l := maxLen[i][k]
			if l > 0 {
				return max(0, l-(j-k))
			}
		}
		return 0
	}

	findDownLen := func(i, j int) int {
		if !marks[i-1][j] {
			return 0
		}
		for k := i - 1; k >= 1; k-- {
			if sky[k][j] != '*' {
				return 0
			}
			l := maxLen[k][j]
			if l > 0 {
				return max(0, l-(i-k))
			}
		}
		return 0
	}

	mark := func(x, y, len int) {
		for j := y - len; j <= y+len; j++ {
			marks[x][j] = true
		}
		for i := x - len; i <= x+len; i++ {
			marks[i][y] = true
		}
	}

	var ans []int
	for i := 1; i < n-1; i++ {
		for j := 1; j < m-1; j++ {
			if sky[i][j] == '*' {
				rightLen := findRightLen(i, j)
				downLen := findDownLen(i, j)

				l := min(rightLen, downLen)

				for ; valid(i, j, l+1); l++ {
				}

				if l > 0 {
					maxLen[i][j] = l
					mark(i, j, l)
					ans = append(ans, i,j,l)
				}

			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if sky[i][j] == '*' && !marks[i][j] {
				Fprintln(out, -1)
				return
			}
		}
	}

	l := len(ans)
	Fprintln(out, l/3)
	for i := 0; i < l; i+=3 {
		Fprintln(out, ans[i]+1, ans[i+1]+1, ans[i+2])
	}
}

package main

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

const (
	N = 1024
	M = 1024
)

type star struct {
	i, j int
	len  int
}

var n, m int
var pic [N][M]byte
var res [N][M]byte
var maxRay, h, v, left, right, up, down [N][M]int
var stars []star

func min(args ... int) int {
	m := args[0]
	for _, v := range args[1:] {
		if v < m {
			m = v
		}
	}
	return m
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(buf, "%c", &pic[i][j])
		}
		fmt.Fscanf(buf, "\n")
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if pic[i][j] == '*' {
				up[i][j]++
				left[i][j]++
				if i > 0 {
					up[i][j] += up[i-1][j]
				}
				if j > 0 {
					left[i][j] += left[i][j-1]
				}
			}
		}
	}

	for i := n - 1; i >= 0; i-- {
		for j := m - 1; j >= 0; j-- {
			if pic[i][j] == '*' {
				down[i][j]++
				right[i][j]++
				if i < n-1 {
					down[i][j] += down[i+1][j]
				}
				if j < m-1 {
					right[i][j] += right[i][j+1]
				}
			}
		}
	}

	stars = make([]star, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			mray := min(up[i][j], down[i][j], left[i][j], right[i][j]) - 1
			if mray > 0 {
				stars = append(stars, star{i, j, mray})
			}
		}
	}

	for i := 0; i < len(stars); i++ {
		x := stars[i].i
		y := stars[i].j
		l := stars[i].len
		v[x - l][y]++
		v[x + l + 1][y]--
		h[x][y - l]++
		h[x][y + l + 1]--
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if i > 0 {
				v[i][j] += v[i - 1][j]
			}
			if j > 0 {
				h[i][j] += h[i][j - 1]
			}
		}
	}

	//for i := 0; i < n; i++ {
	//	for j := 0; j < m; j++ {
	//		fmt.Printf("%d ", v[i][j])
	//	}
	//	fmt.Println()
	//}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if v[i][j] > 0 || h[i][j] > 0 {
				res[i][j] = '*'
			} else {
				res[i][j] = '.'
			}
		}
	}

	writer := bufio.NewWriter(os.Stdout)
	if res == pic {
		fmt.Fprintln(writer, len(stars))
		for i := 0; i < len(stars); i++ {
			fmt.Fprintln(writer, stars[i].i + 1, stars[i].j + 1, stars[i].len)
		}
	} else {
		fmt.Fprintln(writer, -1)
	}
	writer.Flush()

}

package main

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

func main() {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

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

	var n, m int
	var sky [1000][1000]byte
	Fscan(in, &n, &m)
	for i := 0; i < n; i++ {
		var s string
		Fscan(in, &s)
		copy(sky[i][:], s)
	}

	var marks [1000][1000]bool
	var maxLen [1000][1000]int

	valid := func(i, j, len int) bool {
		left := j+len < m && sky[i][j+len] == '*'
		right := j-len >= 0 && sky[i][j-len] == '*'

		top := i-len >= 0 && sky[i-len][j] == '*'
		down := i+len < n && sky[i+len][j] == '*'

		return left && right && top && down
	}

	findRightLen := func(i, j int) int {
		if !marks[i][j-1] {
			return 0
		}
		for k := j - 1; k >= 1; k-- {
			if sky[i][k] != '*' {
				return 0
			}
			l := maxLen[i][k]
			if l > 0 {
				return max(0, l-(j-k))
			}
		}
		return 0
	}

	findDownLen := func(i, j int) int {
		if !marks[i-1][j] {
			return 0
		}
		for k := i - 1; k >= 1; k-- {
			if sky[k][j] != '*' {
				return 0
			}
			l := maxLen[k][j]
			if l > 0 {
				return max(0, l-(i-k))
			}
		}
		return 0
	}

	mark := func(x, y, len int) {
		for j := y - len; j <= y+len; j++ {
			marks[x][j] = true
		}
		for i := x - len; i <= x+len; i++ {
			marks[i][y] = true
		}
	}

	var ans []int
	for i := 1; i < n-1; i++ {
		for j := 1; j < m-1; j++ {
			if sky[i][j] == '*' {
				rightLen := findRightLen(i, j)
				downLen := findDownLen(i, j)

				l := min(rightLen, downLen)

				for ; valid(i, j, l+1); l++ {
				}

				if l > 0 {
					maxLen[i][j] = l
					mark(i, j, l)
					ans = append(ans, i, j, l)
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if sky[i][j] == '*' && !marks[i][j] {
				Fprintln(out, -1)
				return
			}
		}
	}
	Fprintln(out, len(ans)/3)
	for i := 0; i < len(ans); i += 3 {
		Fprintln(out, ans[i]+1, ans[i+1]+1, ans[i+2])
	}
}

package main

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

func main()  {

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

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

	starts, used := make([][]byte, n), make([][]bool, n)
	for i := 0; i < n; i++ {
		starts[i] = make([]byte, m)
		used[i] = make([]bool, m)
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < m; j++ {
			starts[i][j] = s[j]
		}
	}

	result := make([]int, 0)

	for x := 0; x < n; x++ {
		for y := 0; y < m; y++ {
			if starts[x][y] == '*' {
				length := 1
				for findStart(starts, x, y, length) {
					used[x][y] = true
					for i := 1; i <= length; i++ {
						used[x + i][y] = true
						used[x - i][y] = true
						used[x][y + i] = true
						used[x][y - i] = true
					}
					result = append(result, x)
					result = append(result, y)
					result = append(result, length)
					length++
				}
			}
		}
	}

	if !check(starts, used) {
		fmt.Fprintln(out, "NO")
	} else {
		fmt.Fprintln(out, len(result) / 3)
		for i := 0; i < len(result); i += 3 {
			fmt.Fprintln(out, result[i] + 1, result[i + 1] + 1, result[i + 2])
		}
	}

}

func findStart(starts [][]byte, x, y int, length int) bool{

	defer func() {
		_ = recover()
	}()

	f := true
	for i := 1; i <= length; i++ {
		if starts[x + i][y] != '*' {
			f = false
			break
		}
		if starts[x - i][y] != '*' {
			f = false
			break
		}
		if starts[x][y + i] != '*' {
			f = false
			break
		}
		if starts[x][y - i] != '*' {
			f = false
			break
		}
	}

	return f

}

func check(starts [][]byte, used [][]bool) bool {
	f := true
	for i := 0; i < len(starts); i++ {
		for j := 0; j < len(starts[i]); j++ {
			if starts[i][j] == '*' && !used[i][j] {
				f = false
				break
			}
		}
	}
	return f
}

package main

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

func main()  {

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

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

	starts, used := make([][]byte, n), make([][]bool, n)
	for i := 0; i < n; i++ {
		starts[i] = make([]byte, m)
		used[i] = make([]bool, m)
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < m; j++ {
			starts[i][j] = s[j]
		}
	}

	result := make([]int, 0)

	for x := 0; x < n; x++ {
		for y := 0; y < m; y++ {
			if starts[x][y] == '*' {
				length := 1
				for findStart(starts, x, y, length) {
					for i := 1; i <= length; i++ {
						used[x + i][y] = true
						used[x - i][y] = true
						used[x][y + i] = true
						used[x][y - i] = true
					}
					result = append(result, x)
					result = append(result, y)
					result = append(result, length)
					length++
				}
			}
		}
	}

	if check(starts, used) {
		fmt.Fprintln(out, "NO")
	} else {
		fmt.Fprintln(out, len(result) / 3)
		for i := 0; i < len(result); i += 3 {
			fmt.Fprintln(out, result[i] + 1, result[i + 1] + 1, result[i + 2])
		}
	}

}

func findStart(starts [][]byte, x, y int, length int) bool{

	defer func() {
		_ = recover()
	}()

	f := true
	for i := 1; i <= length; i++ {
		if starts[x + i][y] != '*' {
			f = false
			break
		}
		if starts[x - i][y] != '*' {
			f = false
			break
		}
		if starts[x][y + i] != '*' {
			f = false
			break
		}
		if starts[x][y - i] != '*' {
			f = false
			break
		}
	}

	return f

}

func check(starts [][]byte, used [][]bool) bool {
	f := true
	for i := 0; i < len(starts); i++ {
		for j := 0; j < len(starts[i]); j++ {
			if starts[i][j] == '*' && !used[i][j] {
				f = false
				break
			}
		}
	}
	return f
}

package main

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

func main()  {

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

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

	starts, used := make([][]byte, n), make([][]bool, n)
	for i := 0; i < n; i++ {
		starts[i] = make([]byte, m)
		used[i] = make([]bool, m)
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < m; j++ {
			starts[i][j] = s[j]
		}
	}

	result := make([]int, 0)

	for x := 0; x < n; x++ {
		for y := 0; y < m; y++ {
			if starts[x][y] == '*' {
				length := 1
				for findStart(starts, x, y, length) {
					used[x][y] = true
					for i := 1; i <= length; i++ {
						used[x + i][y] = true
						used[x - i][y] = true
						used[x][y + i] = true
						used[x][y - i] = true
					}
					result = append(result, x)
					result = append(result, y)
					result = append(result, length)
					length++
				}
			}
		}
	}

	if !check(starts, used) || len(result) == 0 {
		fmt.Fprintln(out, "-1")
	} else {
		fmt.Fprintln(out, len(result) / 3)
		for i := 0; i < len(result); i += 3 {
			fmt.Fprintln(out, result[i] + 1, result[i + 1] + 1, result[i + 2])
		}
	}

}

func findStart(starts [][]byte, x, y int, length int) bool{

	defer func() {
		_ = recover()
	}()

	f := true
	for i := 1; i <= length; i++ {
		if starts[x + i][y] != '*' {
			f = false
			break
		}
		if starts[x - i][y] != '*' {
			f = false
			break
		}
		if starts[x][y + i] != '*' {
			f = false
			break
		}
		if starts[x][y - i] != '*' {
			f = false
			break
		}
	}

	return f

}

func check(starts [][]byte, used [][]bool) bool {
	f := true
	for i := 0; i < len(starts); i++ {
		for j := 0; j < len(starts[i]); j++ {
			if starts[i][j] == '*' && !used[i][j] {
				f = false
				break
			}
		}
	}
	return f
}

package main

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

func main()  {

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

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

	starts, used := make([][]byte, n), make([][]bool, n)
	for i := 0; i < n; i++ {
		starts[i] = make([]byte, m)
		used[i] = make([]bool, m)
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < m; j++ {
			starts[i][j] = s[j]
		}
	}

	result := make([]int, 0)

	for x := 0; x < n; x++ {
		for y := 0; y < m; y++ {

			if starts[x][y] == '*' {

				length := 1

				for findStart(starts, x, y, length) {

					used[x][y] = true
					used[x + length][y] = true
					used[x - length][y] = true
					used[x][y + length] = true
					used[x][y - length] = true

					result = append(result, x)
					result = append(result, y)
					result = append(result, length)

					length++
				}

			}

		}
	}

	if !check(starts, used) {
		fmt.Fprintln(out, "-1")
	} else {
		fmt.Fprintln(out, len(result) / 3)
		for i := 0; i < len(result); i += 3 {
			fmt.Fprintln(out, result[i] + 1, result[i + 1] + 1, result[i + 2])
		}
	}

}

func findStart(starts [][]byte, x, y int, length int) bool{

	defer func() {
		_ = recover()
	}()

	if x - length < 0 || x + length >= len(starts) {
		return false
	}
	if y - length < 0 || y + length >= len(starts[0]) {
		return false
	}

	f := true
	for i := 1; i <= length; i++ {
		if starts[x + i][y] != '*' {
			f = false
			break
		}
		if starts[x - i][y] != '*' {
			f = false
			break
		}
		if starts[x][y + i] != '*' {
			f = false
			break
		}
		if starts[x][y - i] != '*' {
			f = false
			break
		}
	}

	return f

}

func check(starts [][]byte, used [][]bool) bool {
	f := true
	for i := 0; i < len(starts); i++ {
		for j := 0; j < len(starts[i]); j++ {
			if starts[i][j] == '*' && !used[i][j] {
				f = false
				break
			}
		}
	}
	return f
}

package main

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

func main()  {

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

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

	starts, used := make([][]byte, n), make([][]bool, n)
	for i := 0; i < n; i++ {
		starts[i] = make([]byte, m)
		used[i] = make([]bool, m)
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < m; j++ {
			starts[i][j] = s[j]
		}
	}

	result := make([]int, 0)

	for x := 0; x < n; x++ {
		for y := 0; y < m; y++ {
			if starts[x][y] == '*' {
				length := 1
				for findStart(starts, x, y, length) {
					used[x][y] = true
					for i := 1; i <= length; i++ {
						used[x + i][y] = true
						used[x - i][y] = true
						used[x][y + i] = true
						used[x][y - i] = true
					}
					result = append(result, x)
					result = append(result, y)
					result = append(result, length)
					length++
				}
			}
		}
	}

	if !check(starts, used) {
		fmt.Fprintln(out, "-1")
	} else {
		fmt.Fprintln(out, len(result) / 3)
		for i := 0; i < len(result); i += 3 {
			fmt.Fprintln(out, result[i] + 1, result[i + 1] + 1, result[i + 2])
		}
	}

}

func findStart(starts [][]byte, x, y int, length int) bool{

	defer func() {
		_ = recover()
	}()

	f := true
	for i := 1; i <= length; i++ {
		if starts[x + i][y] != '*' {
			f = false
			break
		}
		if starts[x - i][y] != '*' {
			f = false
			break
		}
		if starts[x][y + i] != '*' {
			f = false
			break
		}
		if starts[x][y - i] != '*' {
			f = false
			break
		}
	}

	return f

}

func check(starts [][]byte, used [][]bool) bool {
	f := true
	for i := 0; i < len(starts); i++ {
		for j := 0; j < len(starts[i]); j++ {
			if starts[i][j] == '*' && !used[i][j] {
				f = false
				break
			}
		}
	}
	return f
}

package main

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

func main() {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

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

	var n, m int
	var sky [1000][1000]byte
	Fscan(in, &n, &m)
	for i := 0; i < n; i++ {
		var s string
		Fscan(in, &s)
		copy(sky[i][:], s)
	}

	var marks [1000][1000]bool
	var maxLen [1000][1000]int

	valid := func(i, j, len int) bool {
		left := j+len < m && sky[i][j+len] == '*'
		right := j-len >= 0 && sky[i][j-len] == '*'

		top := i-len >= 0 && sky[i-len][j] == '*'
		down := i+len < n && sky[i+len][j] == '*'

		return left && right && top && down
	}

	findRightLen := func(i, j int) int {
		if !marks[i][j-1] {
			return 0
		}
		for k := j - 1; k >= 1; k-- {
			if sky[i][k] != '*' {
				return 0
			}
			l := maxLen[i][k]
			if l > 0 {
				return max(0, l-(j-k))
			}
		}
		return 0
	}

	findDownLen := func(i, j int) int {
		if !marks[i-1][j] {
			return 0
		}
		for k := i - 1; k >= 1; k-- {
			if sky[k][j] != '*' {
				return 0
			}
			l := maxLen[k][j]
			if l > 0 {
				return max(0, l-(i-k))
			}
		}
		return 0
	}

	mark := func(x, y, len int) {
		for j := y - len; j <= y+len; j++ {
			marks[x][j] = true
		}
		for i := x - len; i <= x+len; i++ {
			marks[i][y] = true
		}
	}

	var ans []int
	for i := 1; i < n-1; i++ {
		for j := 1; j < m-1; j++ {
			if sky[i][j] == '*' {
				rightLen := findRightLen(i, j)
				downLen := findDownLen(i, j)

				l := min(rightLen, downLen)

				for ; valid(i, j, l+1); l++ {
				}

				if l > 0 {
					maxLen[i][j] = l
					mark(i, j, l)
					ans = append(ans, i,j,l)
				}

			}
		}
	}

	for i := 1; i < n-1; i++ {
		for j := 1; j < m-1; j++ {
			if sky[i][j] == '*' && !marks[i][j] {
				Fprintln(out, -1)
				return
			}
		}
	}

	l := len(ans)
	Fprintln(out, l/3)
	for i := 0; i < l; i+=3 {
		Fprintln(out, ans[i]+1, ans[i+1]+1, ans[i+2])
	}
}

package main

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

func main()  {

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

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

	starts, used := make([][]bool, n), make([][]bool, n)
	for i := 0; i < n; i++ {
		starts[i] = make([]bool, m)
		used[i] = make([]bool, m)
	}

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(in, &s)
		for j := 0; j < m; j++ {
			if s[j] == '*' {
				starts[i][j] = true
			}
		}
	}

	result := make([]int8, 0)

	for x := 1; x < n - 1; x++ {

		for y := 1; y < m - 1; y++ {

			if starts[x][y] {

				length := 1

				for {

					if x - length < 0 || x + length >= n {
						break
					}
					if y - length < 0 || y + length >= m {
						break
					}

					f := true

					if !starts[x + length][y] {
						f = false
					}
					if !starts[x - length][y] {
						f = false
					}
					if !starts[x][y + length] {
						f = false
					}
					if !starts[x][y - length] {
						f = false
					}
					if !f {
						break
					}

					used[x][y] = true
					used[x + length][y] = true
					used[x - length][y] = true
					used[x][y + length] = true
					used[x][y - length] = true

					if length == 1 {
						result = append(result, int8(x))
						result = append(result, int8(y))
						result = append(result, int8(length))
					} else {
						result[len(result) - 1] = int8(length)
					}

					length++

				}

			}

		}

	}

	check := true
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if starts[i][j] && !used[i][j] {
				check = false
				break
			}
		}
	}

	if !check {
		fmt.Fprintln(out, "-1")
	} else {
		fmt.Fprintln(out, len(result) / 3)
		for i := 0; i < len(result); i += 3 {
			fmt.Fprintln(out, result[i] + 1, result[i + 1] + 1, result[i + 2])
		}
	}

}

package main

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

const (
	N = 1024
	M = 1024
)

type star struct {
	i, j int
	len  int
}

var n, m int
var pic [N][M]byte
var res [N][M]byte
var maxRay, h, v, left, right, up, down [N][M]int
var stars []star

func min(args ... int) int {
	m := args[0]
	for _, v := range args[1:] {
		if v < m {
			m = v
		}
	}
	return m
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(buf, "%c", &pic[i][j])
		}
		fmt.Fscanf(buf, "\n")
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if pic[i][j] == '*' {
				up[i][j]++
				left[i][j]++
				if i > 0 {
					up[i][j] += up[i-1][j]
				}
				if j > 0 {
					left[i][j] += left[i][j-1]
				}
			}
		}
	}

	for i := n - 1; i >= 0; i-- {
		for j := m - 1; j >= 0; j-- {
			if pic[i][j] == '*' {
				down[i][j]++
				right[i][j]++
				if i < n-1 {
					down[i][j] += down[i+1][j]
				}
				if j < m-1 {
					right[i][j] += right[i][j+1]
				}
			}
		}
	}

	stars = make([]star, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			mray := min(up[i][j], down[i][j], left[i][j], right[i][j]) - 1
			if mray > 0 {
				stars = append(stars, star{i, j, mray})
			}
		}
	}

	fmt.Println(stars)

	for i := 0; i < len(stars); i++ {
		x := stars[i].i
		y := stars[i].j
		l := stars[i].len
		v[x - l][y]++
		v[x + l + 1][y]--
		h[x][y - l]++
		h[x][y + l + 1]--
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if i > 0 {
				v[i][j] += v[i - 1][j]
			}
			if j > 0 {
				h[i][j] += h[i][j - 1]
			}
		}
	}

	//for i := 0; i < n; i++ {
	//	for j := 0; j < m; j++ {
	//		fmt.Printf("%d ", v[i][j])
	//	}
	//	fmt.Println()
	//}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if v[i][j] > 0 || h[i][j] > 0 {
				res[i][j] = '*'
			} else {
				res[i][j] = '.'
			}
		}
	}

	if res == pic {
		fmt.Println(len(stars))
		for i := 0; i < len(stars); i++ {
			fmt.Println(stars[i].i + 1, stars[i].j + 1, stars[i].len)
		}
	} else {
		fmt.Println(-1)
	}

}


DZY has a sequence a, consisting of n integers.We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.You only need to output the length of the subsegment you find.

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

In a single line print the answer to the problem — the maximum length of the required subsegment.

NoteYou can choose subsegment a2, a3, a4, a5, a6 and change its 3rd element (that is a4) to 4.

//446A
package main
import (
	"fmt"
	"os"
	"bufio"
	"strconv"
)

func main() {
	var nn, maks int
	var aa[100005]int
	var x[100005]int
	var y[100005]int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	r.Scan()
	nn, _ = strconv.Atoi(r.Text())
	for i:=0; i<nn; i++ {
		r.Scan()
		aa[i], _ = strconv.Atoi(r.Text())
	}
	x[0]=1
	for i:=1; i<nn; i++ {
		if aa[i]>aa[i-1] {
			x[i]=x[i-1]+1
		} else {
			x[i]=1
		}
		if x[i]>maks {
			maks=x[i]
		}
	}
	if maks<nn {
		maks+=1
	}
	y[nn-1]=1
	for i:=nn-2; i>0; i-- {
		if aa[i]<aa[i+1] {
			y[i]=y[i+1]+1
		} else {
			y[i]=1
		}
		if (aa[i+1]-aa[i-1])>1 {
			if x[i-1]+(y[i+1]+1)>maks {
				maks=x[i-1]+(y[i+1]+1)
			}
		}
	}
	fmt.Println(maks)
}

package main

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

func main() {
	var n int

	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	fmt.Sscanf(line, "%d", &n)

	if n <= 2 {
		fmt.Println(n)
		return
	}

	line, _ = reader.ReadString('\n')
	tokens := strings.Fields(line)
	numbers := make([]int, n)
	for i := 0; i < n; i++ {
		numbers[i], _ = strconv.Atoi(tokens[i])
	}

	l := make([]int, n)
	l[0] = 1
	for i := 1; i < n; i++ {
		if numbers[i-1] < numbers[i] {
			l[i] = l[i-1] + 1
		} else {
			l[i] = 1
		}
	}

	r := make([]int, n)
	r[n-1] = 1
	for i := n - 2; i >= 0; i-- {
		if numbers[i] < numbers[i+1] {
			r[i] = r[i+1] + 1
		} else {
			r[i] = 1
		}
	}

	bestLength := 2
	for i := 0; i < n; i++ {
		if i == 0 {
			if r[i+1]+1 >= bestLength {
				bestLength = r[i+1] + 1
			}
		} else if i == n-1 {
			if l[i-1]+1 >= bestLength {
				bestLength = l[i-1] + 1
			}
		} else {
			if numbers[i-1]+1 < numbers[i+1] {
				if l[i-1]+r[i+1]+1 > bestLength {
					bestLength = l[i-1] + r[i+1] + 1
				}
			} else if l[i-1] < l[i] && l[i] > l[i+1] {
				if l[i-1]+2 > bestLength {
					bestLength = l[i-1] + 2
				}
			} else if r[i+1] < r[i] && r[i] > r[i-1] {
				if r[i+1]+2 > bestLength {
					bestLength = r[i+1] + 2
				}
			}
		}
	}
	fmt.Println(bestLength)
}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"time"
	"unicode/utf8"
)

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

var ()

func solve() {
	n := readInt()
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = readInt()
	}
	dpL := make([]int, n)
	dpL[0] = 1;
	for i := 1; i < n; i++ {
		if array[i - 1] < array[i] {
			dpL[i] = dpL[i - 1] + 1;
		} else {
			dpL[i] = 1;
		}
	}
	dpR := make([]int, n)
	dpR[n - 1] = 1;
	for i := n - 2; i >= 0; i-- {
		if array[i + 1] > array[i] {
			dpR[i] = dpR[i + 1] + 1;
		} else {
			dpR[i] = 1;
		}
	}

	res := 0
	for i := 0; i < n; i++ {
		res = maxInt(res, dpL[i])
		if i > 0 {
			res = maxInt(res, 1 + dpL[i - 1])
		}
		if i < n - 1 {
			res = maxInt(res, 1 + dpR[i + 1])
		}
		if i > 0 && i < n - 1 && array[i - 1] + 1 < array[i + 1] {
			res = maxInt(res, 1 + dpL[i - 1] + dpR[i + 1])
		}
	}
//	logln(dpL)
//	logln(dpR)
	printInt(res)
	printLine()

}

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

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	dbg := flag.Bool("dbg", false, "Equals true, if run is in debug mode.")
	opt := flag.Bool("opt", false, "Equals true, if run is in optimized mode.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *opt || *dbg {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
		if *dbg {
			cpuprofile, _ := os.Create("/home/outside/coding/workspace/go/io/cpuprofile.txt")
			pprof.StartCPUProfile(cpuprofile)
			defer cpuprofile.Close()
			defer pprof.StopCPUProfile()
		}
	} else {
		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()

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

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

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

type TupleSlice []Tuple

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

func (p TupleSlice) Less(j, i int) bool {
	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
}

// 446A
package main

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

var (
	x1, x2, x3 [1000000]int64
	n, i, o    int64
)

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

func main() {
	in := bufio.NewReader(os.Stdin)
	o = 0
	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &x1[i])
	}
	for i = 1; i < n; i++ {
		if x1[i] > x1[i-1] {
			x2[i] = x2[i-1] + 1
			o = max(o, x2[i])
		} else {
			x2[i] = 0
		}

	}
	for i = n - 2; ^i != 0; i-- {
		if x1[i] < x1[i+1] {
			x3[i] = x3[i+1] + 1
			o = max(o, x3[i])
		} else {
			x3[i] = 0
		}

	}
	for i = n - 1; i != 0; i-- {
		if x1[i-1]+1 < x1[i+1] {
			o = max(o, x2[i-1]+x3[i+1]+1)
		}

	}
	fmt.Println(min(n, o+2))
}

package main

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

func main() {
	var n int
	var a, b, c [10000000]int
	r := bufio.NewReader(os.Stdin)
	maxx := 1
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Fscan(r, &a[i])
	}
	b[1] = 1
	for i := 2; i <= n; i++ {
		if a[i] > a[i-1] {
			b[i] = b[i-1] + 1
		} else {
			b[i] = 1
		}
		if maxx < b[i] {
			maxx = b[i]
		}
	}
	if maxx < n {
		maxx++
	}
	c[n] = 1
	for i := n - 1; i > 0; i-- {
		if a[i+1] > a[i] {
			c[i] = c[i+1] + 1
		} else {
			c[i] = 1
		}
	}
	for i := 2; i <= n; i++ {
		if b[i] == 1 && (a[i-1]+1 < a[i+1] || a[i-2]+1 < a[i]) && b[i-1]+c[i] > maxx {
			maxx = b[i-1] + c[i]
		} else {
			if b[i] == 1 && maxx < b[i-1]+1 {
				maxx = b[i-1] + 1
			}
		}
	}
	if n < 3 {
		fmt.Println(n)
	} else {
		if maxx == 1 {
			fmt.Println("2")
		} else {
			fmt.Println(maxx)
		}
	}
}

package main

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

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

	var n int
	if scanner.Scan() {
		line := scanner.Text()
		fmt.Sscanf(line, "%d", &n)

	}

	if scanner.Scan() {
		line := scanner.Text()
		tokens := strings.Fields(line)
		numbers := make([]int, n)
		for i := 0; i < n; i++ {
			numbers[i], _ = strconv.Atoi(tokens[i])
		}

		if n <= 2 {
			fmt.Println(n)
			return
		}

		l := make([]int, n)
		l[0] = 1
		for i := 1; i < n; i++ {
			if numbers[i-1] < numbers[i] {
				l[i] = l[i-1] + 1
			} else {
				l[i] = 1
			}
		}

		r := make([]int, n)
		r[n-1] = 1
		for i := n - 2; i >= 0; i-- {
			if numbers[i] < numbers[i+1] {
				r[i] = r[i+1] + 1
			} else {
				r[i] = 1
			}
		}

		bestLength := 1
		for i := 1; i < n-1; i++ {
			if numbers[i-1]+1 < numbers[i+1] || (numbers[i-1] < numbers[i] && numbers[i] > numbers[i+1]) {
				if l[i-1]+r[i+1]+1 >= bestLength {
					bestLength = l[i-1] + r[i+1] + 1
				}
			}
		}
		fmt.Println(bestLength)
	}
}

package main

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

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

	var n int
	if scanner.Scan() {
		line := scanner.Text()
		fmt.Sscanf(line, "%d", &n)

		if n <= 2 {
			fmt.Println(n)
			return
		}
	}

	if scanner.Scan() {
		line := scanner.Text()
		tokens := strings.Fields(line)
		numbers := make([]int, n)
		for i := 0; i < n; i++ {
			numbers[i], _ = strconv.Atoi(tokens[i])
		}
		if n == 10000 {
			fmt.Println("Y u no print", len(tokens))
		}

		l := make([]int, n)
		l[0] = 1
		for i := 1; i < n; i++ {
			if numbers[i-1] < numbers[i] {
				l[i] = l[i-1] + 1
			} else {
				l[i] = 1
			}
		}

		r := make([]int, n)
		r[n-1] = 1
		for i := n - 2; i >= 0; i-- {
			if numbers[i] < numbers[i+1] {
				r[i] = r[i+1] + 1
			} else {
				r[i] = 1
			}
		}

		bestLength := 2
		for i := 0; i < n; i++ {
			if i == 0 {
				if r[i+1]+1 >= bestLength {
					bestLength = r[i+1] + 1
				}
			} else if i == n-1 {
				if l[i-1]+1 >= bestLength {
					bestLength = l[i-1] + 1
				}
			} else {
				if numbers[i-1]+1 < numbers[i+1] {
					if l[i-1]+r[i+1]+1 > bestLength {
						bestLength = l[i-1] + r[i+1] + 1
					}
				} else if l[i-1] < l[i] && l[i] > l[i+1] {
					if l[i-1]+2 > bestLength {
						bestLength = l[i-1] + 2
					}
				} else if r[i+1] < r[i] && r[i] > r[i-1] {
					if r[i+1]+2 > bestLength {
						bestLength = r[i+1] + 2
					}
				}
			}
		}
		fmt.Println(bestLength)
	}
}

package main

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

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

	var n int
	if scanner.Scan() {
		line := scanner.Text()
		fmt.Sscanf(line, "%d", &n)

	}

	if scanner.Scan() {
		line := scanner.Text()
		tokens := strings.Fields(line)
		numbers := make([]int, n)
		for i := 0; i < n; i++ {
			numbers[i], _ = strconv.Atoi(tokens[i])
		}

		if n <= 2 {
			fmt.Println(n)
			return
		}

		l := make([]int, n)
		l[0] = 1
		for i := 1; i < n; i++ {
			if numbers[i-1] < numbers[i] {
				l[i] = l[i-1] + 1
			} else {
				l[i] = 1
			}
		}

		r := make([]int, n)
		r[n-1] = 1
		for i := n - 2; i >= 0; i-- {
			if numbers[i] < numbers[i+1] {
				r[i] = r[i+1] + 1
			} else {
				r[i] = 1
			}
		}

		bestLength := 1
		for i := 0; i < n; i++ {
			if i == 0 {
				if r[i+1]+1 >= bestLength {
					bestLength = r[i+1] + 1
				}
			} else if i == n-1 {
				if l[i-1]+1 >= bestLength {
					bestLength = l[i-1] + 1
				}
			} else {

				if numbers[i-1]+1 < numbers[i+1] {
					if l[i-1]+r[i+1]+1 > bestLength {
						bestLength = l[i-1] + r[i+1] + 1
					}

				} else if l[i-1] < l[i] && l[i] > l[i+1] {
					if l[i-1]+2 > bestLength {
						bestLength = l[i-1] + 2
					}
				} else if r[i+1] < r[i] && r[i] > r[i-1] {
					if r[i+1]+2 > bestLength {
						bestLength = r[i+1] + 2
					}
				}
			}
		}
		fmt.Println(bestLength)
	}
}

package main

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

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

	var n int
	if scanner.Scan() {
		line := scanner.Text()
		fmt.Sscanf(line, "%d", &n)

		if n <= 2 {
			fmt.Println(n)
			return
		}
	} else {
		fmt.Println(scanner.Err())
	}

	if scanner.Scan() {
		line := scanner.Text()
		tokens := strings.Fields(line)
		numbers := make([]int, n)
		for i := 0; i < n; i++ {
			numbers[i], _ = strconv.Atoi(tokens[i])
		}

		l := make([]int, n)
		l[0] = 1
		for i := 1; i < n; i++ {
			if numbers[i-1] < numbers[i] {
				l[i] = l[i-1] + 1
			} else {
				l[i] = 1
			}
		}

		r := make([]int, n)
		r[n-1] = 1
		for i := n - 2; i >= 0; i-- {
			if numbers[i] < numbers[i+1] {
				r[i] = r[i+1] + 1
			} else {
				r[i] = 1
			}
		}

		bestLength := 2
		for i := 0; i < n; i++ {
			if i == 0 {
				if r[i+1]+1 >= bestLength {
					bestLength = r[i+1] + 1
				}
			} else if i == n-1 {
				if l[i-1]+1 >= bestLength {
					bestLength = l[i-1] + 1
				}
			} else {
				if numbers[i-1]+1 < numbers[i+1] {
					if l[i-1]+r[i+1]+1 > bestLength {
						bestLength = l[i-1] + r[i+1] + 1
					}
				} else if l[i-1] < l[i] && l[i] > l[i+1] {
					if l[i-1]+2 > bestLength {
						bestLength = l[i-1] + 2
					}
				} else if r[i+1] < r[i] && r[i] > r[i-1] {
					if r[i+1]+2 > bestLength {
						bestLength = r[i+1] + 2
					}
				}
			}
		}
		fmt.Println(bestLength)
	} else {
		fmt.Println(scanner.Err())
	}
}

package main

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

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

	var n int
	if scanner.Scan() {
		line := scanner.Text()
		fmt.Sscanf(line, "%d", &n)

	}

	if scanner.Scan() {
		line := scanner.Text()
		tokens := strings.Fields(line)
		numbers := make([]int, n)
		for i := 0; i < n; i++ {
			numbers[i], _ = strconv.Atoi(tokens[i])
		}

		if n <= 2 {
			fmt.Println(n)
			return
		}

		l := make([]int, n)
		l[0] = 1
		for i := 1; i < n; i++ {
			if numbers[i-1] < numbers[i] {
				l[i] = l[i-1] + 1
			} else {
				l[i] = 1
			}
		}

		r := make([]int, n)
		r[n-1] = 1
		for i := n - 2; i >= 0; i-- {
			if numbers[i] < numbers[i+1] {
				r[i] = r[i+1] + 1
			} else {
				r[i] = 1
			}
		}

		// fmt.Println(l, r)
		bestLength := 1
		for i := 0; i < n; i++ {
			if i == 0 {
				if r[i+1]+1 >= bestLength {
					bestLength = r[i+1] + 1
				}
			} else if i == n-1 {
				if l[i-1]+1 >= bestLength {
					bestLength = l[i-1] + 1
				}
			} else {
				if numbers[i-1]+1 < numbers[i+1] || (l[i-1] < l[i] && r[i+1] == 1) || (r[i+1] < r[i] && l[i-1] == 1) {
					if l[i-1]+r[i+1]+1 >= bestLength {
						// fmt.Println(i)
						bestLength = l[i-1] + r[i+1] + 1
					}
				}
			}
		}
		fmt.Println(bestLength)
	}
}

package main

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

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

	var n int
	if scanner.Scan() {
		line := scanner.Text()
		fmt.Sscanf(line, "%d", &n)

	}

	if scanner.Scan() {
		line := scanner.Text()
		tokens := strings.Fields(line)
		numbers := make([]int, n)
		for i := 0; i < n; i++ {
			numbers[i], _ = strconv.Atoi(tokens[i])
		}

		if n == 1 {
			fmt.Println(numbers[0])
			return
		}

		l := make([]int, n)
		l[0] = 1
		for i := 1; i < n; i++ {
			if numbers[i-1] < numbers[i] {
				l[i] = l[i-1] + 1
			} else {
				l[i] = 1
			}
		}

		r := make([]int, n)
		r[n-1] = 1
		for i := n - 1; i >= 1; i-- {
			if numbers[i-1] < numbers[i] {
				r[i-1] = r[i] + 1
			} else {
				r[i-1] = 1
			}
		}

		bestLength := 1
		for i := 1; i < n-1; i++ {
			if numbers[i-1] < numbers[i+1] {
				if l[i-1]+r[i+1]+1 > bestLength {
					bestLength = l[i-1] + r[i+1] + 1
				}
			}
		}
		fmt.Println(bestLength)
	}
}

package main

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

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

	var n int
	if scanner.Scan() {
		line := scanner.Text()
		fmt.Sscanf(line, "%d", &n)

	}

	if scanner.Scan() {
		line := scanner.Text()
		tokens := strings.Fields(line)
		numbers := make([]int, n)
		for i := 0; i < n; i++ {
			numbers[i], _ = strconv.Atoi(tokens[i])
		}

		if n <= 2 {
			fmt.Println(n)
			return
		}

		l := make([]int, n)
		l[0] = 1
		for i := 1; i < n; i++ {
			if numbers[i-1] < numbers[i] {
				l[i] = l[i-1] + 1
			} else {
				l[i] = 1
			}
		}

		r := make([]int, n)
		r[n-1] = 1
		for i := n - 2; i >= 0; i-- {
			if numbers[i] < numbers[i+1] {
				r[i] = r[i+1] + 1
			} else {
				r[i] = 1
			}
		}

		fmt.Println(l, r)
		bestLength := 1
		for i := 0; i < n; i++ {
			if i == 0 {
				if r[i+1]+1 >= bestLength {
					bestLength = r[i+1] + 1
				}
			} else if i == n-1 {
				if l[i-1]+1 >= bestLength {
					bestLength = l[i-1] + 1
				}
			} else {
				if numbers[i-1]+1 < numbers[i+1] || (l[i-1] < l[i] && r[i+1] == 1) || (r[i+1] < r[i] && l[i-1] == 1) {
					if l[i-1]+r[i+1]+1 >= bestLength {
						fmt.Println(i)
						bestLength = l[i-1] + r[i+1] + 1
					}
				}
			}
		}
		fmt.Println(bestLength)
	}
}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"time"
	"unicode/utf8"
)

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

var ()

func solve() {
	n := readInt()
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = readInt()
	}
	dpL := make([]int, n)
	dpL[0] = 1;
	for i := 1; i < n; i++ {
		if array[i - 1] < array[i] {
			dpL[i] = dpL[i - 1] + 1;
		} else {
			dpL[i] = 1;
		}
	}
	dpR := make([]int, n)
	dpR[n - 1] = 1;
	for i := n - 2; i >= 0; i-- {
		if array[i + 1] > array[i] {
			dpR[i] = dpR[i + 1] + 1;
		} else {
			dpR[i] = 1;
		}
	}

	res := 0
	for i := 0; i < n; i++ {
		if i > 0 {
			res = maxInt(res, 1 + dpL[i - 1])
		}
		if i < n - 1 {
			res = maxInt(res, 1 + dpR[i + 1])
		}
		if i > 0 && i < n - 1 && array[i - 1] + 1 < array[i + 1] {
			res = maxInt(res, 1 + dpL[i - 1] + dpR[i + 1])
		}
	}
//	logln(dpL)
//	logln(dpR)
	printInt(res)
	printLine()

}

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

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	dbg := flag.Bool("dbg", false, "Equals true, if run is in debug mode.")
	opt := flag.Bool("opt", false, "Equals true, if run is in optimized mode.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *opt || *dbg {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
		if *dbg {
			cpuprofile, _ := os.Create("/home/outside/coding/workspace/go/io/cpuprofile.txt")
			pprof.StartCPUProfile(cpuprofile)
			defer cpuprofile.Close()
			defer pprof.StopCPUProfile()
		}
	} else {
		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()

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

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

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

type TupleSlice []Tuple

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

func (p TupleSlice) Less(j, i int) bool {
	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
}

// 446A
package main

import (
	"fmt"
)

var (
	x1, x2, x3 [100000]int
	n, o       int
)

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

func main() {
	o = 0
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(x1[i])
	}
	for i := 1; i < n; i++ {
		if x1[i] > x1[i-1] {
			x2[i] = x2[i-1] + 1
			o = max(o, x2[i])
		} else {
			x2[i] = 0
		}

	}
	for i := n - 2; ^i != 0; i-- {
		if x1[i] < x1[i+1] {
			x3[i] = x3[i+1] + 1
			o = max(o, x3[i])
		} else {
			x3[i] = 0
		}

	}
	for i := n - 1; i != 0; i-- {
		if x1[i-1]+1 < x1[i+1] {
			o = max(o, x2[i-1]+x3[i+1]+1)
		}

	}
	fmt.Println(min(n, o+2))
}


Alice and Bob are playing a game on a matrix, consisting of $$$2$$$ rows and $$$m$$$ columns. The cell in the $$$i$$$-th row in the $$$j$$$-th column contains $$$a_{i, j}$$$ coins in it.Initially, both Alice and Bob are standing in a cell $$$(1, 1)$$$. They are going to perform a sequence of moves to reach a cell $$$(2, m)$$$.The possible moves are:   Move right — from some cell $$$(x, y)$$$ to $$$(x, y + 1)$$$;  Move down — from some cell $$$(x, y)$$$ to $$$(x + 1, y)$$$. First, Alice makes all her moves until she reaches $$$(2, m)$$$. She collects the coins in all cells she visit (including the starting cell).When Alice finishes, Bob starts his journey. He also performs the moves to reach $$$(2, m)$$$ and collects the coins in all cells that he visited, but Alice didn't.The score of the game is the total number of coins Bob collects.Alice wants to minimize the score. Bob wants to maximize the score. What will the score of the game be if both players play optimally?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of the testcase contains a single integer $$$m$$$ ($$$1 \le m \le 10^5$$$) — the number of columns of the matrix. The $$$i$$$-th of the next $$$2$$$ lines contain $$$m$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,m}$$$ ($$$1 \le a_{i,j} \le 10^4$$$) — the number of coins in the cell in the $$$i$$$-th row in the $$$j$$$-th column of the matrix. The sum of $$$m$$$ over all testcases doesn't exceed $$$10^5$$$.

For each testcase print a single integer — the score of the game if both players play optimally.

NoteThe paths for the testcases are shown on the following pictures. Alice's path is depicted in red and Bob's path is depicted in blue.

package main

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

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

	var t int
	fmt.Fscan(r,&t)

	for k:=0;k<t;k++{
		var m int
		fmt.Fscan(r,&m)
		nums:=[2][]int{}
		for i:=0;i<2;i++{
			nums[i]=make([]int,m)
		}
		for i:=0;i<2;i++{
			for j:=0;j<m;j++{
				fmt.Fscan(r,&nums[i][j])
			}
		}
		solve(&nums)
	}
}
func solve(nums *[2][]int){
	m:=len(nums[0])
	//在原切片上计算每行的前缀和
	for j:=1;j<m;j++{
		nums[0][j]=nums[0][j-1]+nums[0][j]
		nums[1][j]=nums[1][j-1]+nums[1][j]
	}
	var bob int=nums[0][m-1]-nums[0][0]
	for j:=1;j<m;j++{
		bob=min(bob,max(nums[0][m-1]-nums[0][j],nums[1][j-1]))
	}
	fmt.Println(bob)
}
func max(a,b int) int{
	if a>=b{
		return a
	}
	return b
}
func min(a,b int)int{
	if a<=b{
		return a
	}
	return b
}

package main

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

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

	var t int
	var n, v int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		fir := make([]int, n+1)
		sec := make([]int, n+1)
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			fir[i+1] = fir[i] + v
		}
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			sec[i+1] = sec[i] + v
		}
		ans := math.MaxInt32
		for i := 0; i < n; i++ {
			ans = min(ans, max(fir[n]-fir[i+1], sec[i]-sec[0]))
		}
		Fprintln(out, ans)
	}
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

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

package main

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

/*
1
5
5 4 3 5 4
3 6 3 6 2
---

*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var m int
	scanf("%d\n", &m)

	mtx := make([][]int, 2)

	for i := range mtx {
		mtx[i] = make([]int, m)

		for j := range mtx[i] {
			scanf("%d", &mtx[i][j])

		}
		scanf("\n")
	}

	ps := make([][]int, 2)

	for i := range ps {
		ps[i] = make([]int, m)

		sum := 0
		for j := range ps[i] {
			sum += mtx[i][j]
			ps[i][j] = sum
		}
	}

	minBobSum := maxInt

	for j := 0; j < m; j++ {
		bobSum := max(ps[0][m-1]-ps[0][j], ps[1][j]-mtx[1][j])
		minBobSum = min(minBobSum, bobSum)
	}

	fmt.Fprintln(writer, minBobSum)
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return nums[minNumIdx]
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return nums[maxNumIdx]
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		ans := int(2e9)
		s0, s1 := 0, 0
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			s0 += a[i]
		}
		for _, v := range a {
			s0 -= v
			ans = min(ans, max(s0, s1))
			Fscan(in, &v)
			s1 += v
		}
		Fprintln(out, ans)
	}
}

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

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

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

package main

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

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

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

func main() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var m, temp int
		scanf("%d\n", &m)

		arr1 := make([]int, m)
		arr2 := make([]int, m)
		for j := 0; j < m; j++ {
			scanf("%d", &temp)
			arr1[j] = temp
		}
		scanf("\n")

		for j := 0; j < m; j++ {
			scanf("%d", &temp)
			arr2[j] = temp
		}
		scanf("\n")

		printf("%d\n", compute(m, arr1, arr2))
	}
}

func compute(m int, arr1, arr2 []int) int {
	sum1 := 0
	for _, a := range arr1 {
		sum1 += a
	}

	tot1 := arr1[0]
	tot2 := arr2[0]
	result := sum1 - tot1

	for i := 1; i < m-1; i++ {
		tot1 += arr1[i]

		temp := tot2
		if sum1-tot1 > temp {
			temp = sum1 - tot1
		}

		if temp < result {
			result = temp
		}

		tot2 += arr2[i]
	}

	if tot2 < result {
		result = tot2
	}

	return result
}

package main

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

func main() {

	r := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(r, &t)

	for i := 0; i < t; i++ {
		var m int
		fmt.Fscan(r, &m)

		a := make([][]int64, 2)

		for j := 0; j < 2; j++ {
			a[j] = make([]int64, m)
			for k := 0; k < m; k++ {
				fmt.Fscan(r, &a[j][k])
			}
		}

		fmt.Println(solve(a, m))
	}
}

func solve(a [][]int64, m int) int64 {
	dp := [2][]int64{}
	dp[0] = make([]int64, m + 1)
	dp[1] = make([]int64, m + 1)

	dp[0][0] = a[0][0]

	for i := 1; i < m; i++ {
		dp[0][i] = a[0][i] +  dp[0][i - 1]
	}

	dp[1][0] = a[1][0]

	for j := 1; j < m; j++ {
		dp[1][j] = a[1][j] +  dp[1][j - 1]
	}

	var bob int64 = 1e18

	for i := 0; i < m; i++ {
		var s1 int64
		if i > 0 {
			s1 = dp[1][i - 1]
		}
		s2 := dp[0][m - 1] - dp[0][i]

		s := max(s1, s2)

		bob = min(s, bob)
	}

	return bob
}

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

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

package main

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

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

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

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

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

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

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

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

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

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

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

		}
		return initial
	}
}

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

	}
	return m
}

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

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

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

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

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

	return
}

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

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

	return num
}

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

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

var t int

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

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

		var n int
		fmt.Fscan(input, &n)

		FIRST := make([]int, n)
		SECOND := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(input, &FIRST[i])

		}
		var SUMSECOND int
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &SECOND[i])
			SUMSECOND = SUMSECOND + SECOND[i]
		}
		NEWWW := make([]int, 0)
		begin := 0
		SUMSECOND = SUMSECOND - SECOND[n-1]
		NEWWW = append(NEWWW, SUMSECOND)
		for j := n - 2; j > -1; j-- {
			begin = begin + FIRST[j+1]
			SUMSECOND = SUMSECOND - SECOND[j]

			q := MAXX(begin, SUMSECOND)
			NEWWW = append(NEWWW, q)

		}

		sort.Ints(NEWWW)
		fmt.Println(NEWWW[0])

	}

}