package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int64 {
		sc.Scan()
		i, _ := strconv.ParseInt(sc.Text(), 10, 64)
		return i
	}

	n := in()

	a := make([]int64, n)

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

	b := make([]int64, n)
	c := make([]bool, n)

	for i := range b {
		b[i] = 1
	}

	var i int64

	for i = 1; i < n; i++ {
		if a[i] > a[i-1] {
			if b[i-1]+1 > b[i] {
				b[i] = b[i-1] + 1
				c[i] = c[i-1]
			}
		}

		if i-2 >= 0 && a[i] > a[i-2] {
			if c[i-2] != true {
				if b[i-2]+1 > b[i] {
					b[i] = b[i-2] + 1
					c[i] = true
				}
			}
		}
	}

	max := b[0]

	for i := range b {
		if max < b[i] {
			max = b[i]
		}
	}

	fmt.Println(max)
}

package main

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

const (
	maxn = 201000
)

var (
	a [maxn]int
	f [maxn]int
)

func main() {
	var n int
	ans := 1
	input := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(input, &n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Fscan(input, &a[i])
	}
	f[0] = 1
	for i := 1; i < n; i++ {
		if a[i-1] < a[i] {
			f[i] = f[i-1] + 1
		} else {
			f[i] = 1
		}
		if f[i] > ans {
			ans = f[i]
		}
	}
	for i := n - 1; i >= 0; i-- {
		preIndex := i - f[i]
		if preIndex == -1 {
			continue
		}
		if (preIndex-1 >= 0) && (a[preIndex-1] < a[preIndex+1]) {
			if f[i]+f[preIndex]-1 > ans {
				ans = f[i] + f[preIndex] - 1
			}
		}
		if (preIndex+2 < n) && (a[preIndex] < a[preIndex+2]) {
			if f[i]+f[preIndex]-1 > ans {
				ans = f[i] + f[preIndex] - 1
			}
		}
	}
	fmt.Println(ans)
}

package main

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

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

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var A []int

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

	// 階差
	diff := []int{} // len(diff) == n-1
	for i := 1; i < n; i++ {
		diff = append(diff, A[i]-A[i-1])
	}

	// 自身が含まれる増加列の長さ
	uf := NewUnionFind(n)
	L := make([]int, n)
	for i := 0; i < n; i++ {
		if i == 0 {
			continue
		}

		if A[i] > A[i-1] {
			uf.Unite(i, i-1)
		}
	}
	for i := 0; i < n; i++ {
		L[i] = uf.CcSize(i)
	}
	PrintDebug("%v\n", L)

	ans := 0
	// 何もしない場合の最大値で初期化
	for i := 0; i < n; i++ {
		ChMax(&ans, L[i])
	}

	// すべて試す
	for i := 1; i < len(diff); i++ {
		if diff[i] > 0 && diff[i-1] > 0 {
			continue
		}
		if diff[i] <= 0 && diff[i-1] <= 0 {
			continue
		}

		if diff[i]+diff[i-1] > 0 {
			// この場合のみ意味がある
			ChMax(&ans, L[i-1]+L[i+1]-1)
		}
	}
	fmt.Println(ans)
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// 0-based
// uf := NewUnionFind(n)
// uf.Root(x) 			// Get root node of the node x
// uf.Unite(x, y) 	// Unite node x and node y
// uf.Same(x, y) 		// Judge x and y are in the same connected component.
// uf.CcSize(x) 		// Get size of the connected component including node x
// uf.CcNum() 			// Get number of connected components

// UnionFind provides disjoint set algorithm.
// Node id starts from 0 (0-based setting).
type UnionFind struct {
	parents []int
}

// NewUnionFind returns a pointer of a new instance of UnionFind.
func NewUnionFind(n int) *UnionFind {
	uf := new(UnionFind)
	uf.parents = make([]int, n)

	for i := 0; i < n; i++ {
		uf.parents[i] = -1
	}

	return uf
}

// Root method returns root node of an argument node.
// Root method is a recursive function.
func (uf *UnionFind) Root(x int) int {
	if uf.parents[x] < 0 {
		return x
	}

	// route compression
	uf.parents[x] = uf.Root(uf.parents[x])
	return uf.parents[x]
}

// Unite method merges a set including x and a set including y.
func (uf *UnionFind) Unite(x, y int) bool {
	xp := uf.Root(x)
	yp := uf.Root(y)

	if xp == yp {
		return false
	}

	// merge: xp -> yp
	// merge larger set to smaller set
	if uf.CcSize(xp) > uf.CcSize(yp) {
		xp, yp = yp, xp
	}
	// update set size
	uf.parents[yp] += uf.parents[xp]
	// finally, merge
	uf.parents[xp] = yp

	return true
}

// Same method returns whether x is in the set including y or not.
func (uf *UnionFind) Same(x, y int) bool {
	return uf.Root(x) == uf.Root(y)
}

// CcSize method returns the size of a set including an argument node.
func (uf *UnionFind) CcSize(x int) int {
	return -uf.parents[uf.Root(x)]
}

// CcNum method returns the number of connected components.
// Time complextity is O(n)
func (uf *UnionFind) CcNum() int {
	res := 0
	for i := 0; i < len(uf.parents); i++ {
		if uf.parents[i] < 0 {
			res++
		}
	}
	return res
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

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

package main

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

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

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int
var A []int

var dp1, dp2 [200000 + 5]int

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

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

	for i := 0; i < n; i++ {
		if i-1 >= 0 && A[i] > A[i-1] {
			ChMax(&dp1[i], dp1[i-1]+1)
			ChMax(&dp2[i], dp2[i-1]+1)
		}
		if i-2 >= 0 && A[i] > A[i-2] {
			ChMax(&dp2[i], dp1[i-2]+1)
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		ChMax(&ans, dp1[i])
		ChMax(&ans, dp2[i])
	}
	fmt.Println(ans)
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

/*
- まずは全探索を検討しましょう
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
- MOD取る系はint64必須ですよ？
*/

/*
ASCII code

ASCII   10進数  ASCII   10進数  ASCII   10進数
!       33      "       34      #       35
$       36      %       37      &       38
'       39      (       40      )       41
*       42      +       43      ,       44
-       45      .       46      /       47
0       48      1       49      2       50
3       51      4       52      5       53
6       54      7       55      8       56
9       57      :       58      ;       59
<       60      =       61      >       62
?       63      @       64      A       65
B       66      C       67      D       68
E       69      F       70      G       71
H       72      I       73      J       74
K       75      L       76      M       77
N       78      O       79      P       80
Q       81      R       82      S       83
T       84      U       85      V       86
W       87      X       88      Y       89
Z       90      [       91      \       92
]       93      ^       94      _       95
`       96      a       97      b       98
c       99      d       100     e       101
f       102     g       103     h       104
i       105     j       106     k       107
l       108     m       109     n       110
o       111     p       112     q       113
r       114     s       115     t       116
u       117     v       118     w       119
x       120     y       121     z       122
{       123     |       124     }       125
~       126             127
*/

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

package main

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

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

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var A []int

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

	// 階差
	diff := []int{} // len(diff) == n-1
	for i := 1; i < n; i++ {
		diff = append(diff, A[i]-A[i-1])
	}

	// 自身が含まれる増加列の長さ
	L := make([]int, n)
	for i := 0; i < n; i++ {
		if i == 0 {
			L[i] = 1
			continue
		}

		if A[i] > A[i-1] {
			L[i] = L[i-1] + 1
		} else {
			L[i] = 1
		}
	}
	// PrintDebug("%v\n", L)
	cur, l := 0, 0
	for i := n - 1; i >= 0; i-- {
		if cur == 0 {
			cur, l = L[i], L[i]
		}
		L[i] = l
		cur--
	}
	// PrintDebug("%v\n", L)

	ans := 0
	// 何もしない場合の最大値で初期化
	for i := 0; i < n; i++ {
		ChMax(&ans, L[i])
	}

	// すべて試す
	for i := 1; i < len(diff); i++ {
		if diff[i] > 0 && diff[i-1] > 0 {
			continue
		}
		if diff[i] <= 0 && diff[i-1] <= 0 {
			continue
		}

		if diff[i]+diff[i-1] > 0 {
			// この場合のみ意味がある
			// if memo[i-1] > 0 && memo[i+1] > 0 {
			// 	tmp := memo[i-1] + memo[i+1] + 1
			// 	ChMax(&ans, tmp)
			// }
			ChMax(&ans, L[i-1]+L[i+1]-1)
		}
	}
	fmt.Println(ans)
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

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

package main

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

func max(i, j int) int {
	if i < j {
		return j
	}
	return i
}
func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	arr := make([]int, n)
	l := make([]int, n)
	r := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &arr[i])
		l[i] = 1
		r[i] = 1
	}
	fmt.Fscanf(reader, "\n")
	var ans int
	ans = 1
	for i := 1; i < n; i++ {
		if arr[i-1] < arr[i] {
			r[i] = r[i-1] + 1
		}
		ans = max(ans, r[i])
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i+1] > arr[i] {
			l[i] = l[i+1] + 1
		}
		ans = max(ans, l[i])
	}

	//fmt.Println(l, r, ans)
	for i := 0; i < n-2; i++ {
		if arr[i] < arr[i+2] {
			//fmt.Println("arr[i]", arr[i], "arr[i + 2]", arr[i + 2], "r[i]", r[i], "l[i + 2]", l[i + 2], ans)
			ans = max(ans, r[i]+l[i+2])
		}
	}
	fmt.Fprintf(writer, "%d\n", ans)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1272/problem/D

package main

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

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

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

func Solve(n int, a []int) int {
	start := make([]int, n)
	for i := n - 1; i >= 0; i-- {
		if i == n-1 {
			start[i] = 1
		} else if a[i] < a[i+1] {
			start[i] = start[i+1] + 1
		} else {
			start[i] = 1
		}
	}
	end := make([]int, n)
	for i := 0; i < n; i++ {
		if i == 0 {
			end[i] = 1
		} else if a[i] > a[i-1] {
			end[i] = end[i-1] + 1
		} else {
			end[i] = 1
		}
	}
	maxJoin := maxArray(start)
	for i := 1; i <= n-2; i++ {
		if a[i-1] < a[i+1] {
			maxJoin = max(maxJoin, end[i-1]+start[i+1])
		}
	}
	return maxJoin
}

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

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

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

package main

import (
	"fmt"
)

const (
	maxn = 101000
)

var (
	a [maxn]int
	f [maxn]int
)

func main() {
	var n int
	ans := 1
	_, _ = fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&a[i])
	}
	f[0] = 1
	for i := 1; i < n; i++ {
		if a[i-1] < a[i] {
			f[i] = f[i-1] + 1
		} else {
			f[i] = 1
		}
		if f[i] > ans {
			ans = f[i]
		}
	}
	for i := 0; i < n; i++ {
		preIndex := i - f[i]
		if preIndex == -1 {
			continue
		}
		if (preIndex-1 >= 0) && (a[preIndex-1] < a[preIndex+1]) {
			if f[i]+f[preIndex]-1 > ans {
				ans = f[i] + f[preIndex] - 1
			}
		}
		if (preIndex+2 < n) && (a[preIndex] < a[preIndex+2]) {
			if f[i]+f[preIndex]-1 > ans {
				ans = f[i] + f[preIndex] - 1
			}
		}
	}
	println(ans)
}

package main

import (
	"fmt"
)

const (
	maxn = 101000
)

var (
	a [maxn]int
	f [maxn]int
)

func main() {
	var n int
	ans := 1
	_, _ = fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&a[i])
	}
	f[0] = 1
	for i := 1; i < n; i++ {
		if a[i-1] < a[i] {
			f[i] = f[i-1] + 1
		} else {
			f[i] = 1
		}
		if f[i] > ans {
			ans = f[i]
		}
	}
	for i := 0; i < n; i++ {
		preIndex := i - f[i]
		if preIndex == -1 {
			continue
		}
		if (preIndex-1 >= 0) && (a[preIndex-1] < a[preIndex+1]) {
			if f[i]+f[preIndex] > ans {
				ans = f[i] + f[preIndex] - 1
			}
		}
		if (preIndex+2 < n) && (a[preIndex] < a[preIndex+2]) {
			if f[i]+f[preIndex] > ans {
				ans = f[i] + f[preIndex] - 1
			}
		}
	}
	println(ans)
}

package main

import (
	"fmt"
)

const (
	maxn = 101000
)

var (
	a [maxn]int
	f [maxn]int
)

func main() {
	var n int
	ans := 1
	_, _ = fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&a[i])
	}
	f[0] = 1
	for i := 1; i < n; i++ {
		if a[i-1] < a[i] {
			f[i] = f[i-1] + 1
		} else {
			f[i] = 1
		}
		if f[i] > ans {
			ans = f[i]
		}
	}
	for i := 0; i < n; i++ {
		preIndex := i - f[i]
		if preIndex == -1 {
			continue
		}
		if (preIndex-1 >= 0) && (a[preIndex-1] < a[preIndex+1]) {
			if f[i]+f[preIndex] > ans {
				ans = f[i] + f[preIndex]
			}
		}
		if (preIndex+2 < n) && (a[preIndex] < a[preIndex+2]) {
			if f[i]+f[preIndex] > ans {
				ans = f[i] + f[preIndex]
			}
		}
	}
	println(ans)
}

package main

import (
	"fmt"
)

const (
	maxn = 201000
)

var (
	a [maxn]int
	f [maxn]int
)

func main() {
	var n int
	ans := 1
	_, _ = fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		_, _ = fmt.Scan(&a[i])
	}
	f[0] = 1
	for i := 1; i < n; i++ {
		if a[i-1] < a[i] {
			f[i] = f[i-1] + 1
		} else {
			f[i] = 1
		}
		if f[i] > ans {
			ans = f[i]
		}
	}
	for i := 0; i < n; i++ {
		preIndex := i - f[i]
		if preIndex == -1 {
			continue
		}
		if (preIndex-1 >= 0) && (a[preIndex-1] < a[preIndex+1]) {
			if f[i]+f[preIndex]-1 > ans {
				ans = f[i] + f[preIndex] - 1
			}
		}
		if (preIndex+2 < n) && (a[preIndex] < a[preIndex+2]) {
			if f[i]+f[preIndex]-1 > ans {
				ans = f[i] + f[preIndex] - 1
			}
		}
	}
	println(ans)
}

package main

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

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

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var n int
var A []int

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

	// 階差
	diff := []int{} // len(diff) == n-1
	for i := 1; i < n; i++ {
		diff = append(diff, A[i]-A[i-1])
	}
	// 階差を抽象化
	pn := []int{}
	for i := 0; i < len(diff); i++ {
		if diff[i] <= 0 {
			pn = append(pn, -1)
		} else {
			pn = append(pn, 1)
		}
	}

	// 抽象化した階差をランレングス圧縮
	pressedPN, countPN := RunLengthEncoding(pn)
	ans := 0
	for i := 0; i < len(countPN); i++ {
		// 正の連続区間のみチェック
		if pressedPN[i] > 0 {
			ChMax(&ans, countPN[i]+1)
		}
	}

	// 復号
	memo := []int{}
	for i := 0; i < len(countPN); i++ {
		for j := 0; j < countPN[i]; j++ {
			if pressedPN[i] < 0 {
				memo = append(memo, pressedPN[i])
			} else {
				// 圧縮が正の場合のみ連長をメモする
				memo = append(memo, countPN[i])
			}
		}
	}

	// すべて試す, iは真ん中
	for i := 1; i < len(diff)-1; i++ {
		if diff[i] > 0 && diff[i-1] > 0 {
			continue
		}
		if diff[i] <= 0 && diff[i-1] <= 0 {
			continue
		}

		if diff[i]+diff[i-1] > 0 {
			// この場合のみ意味がある
			if memo[i-1] > 0 && memo[i+1] > 0 {
				tmp := memo[i-1] + memo[i+1] + 1
				ChMax(&ans, tmp)
			}
		}
	}

	fmt.Println(ans)
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// RunLengthEncoding returns encoded slice of an input.
func RunLengthEncoding(S []int) ([]int, []int) {
	runes := []int{}
	lengths := []int{}

	l := 0
	for i := 0; i < len(S); i++ {
		// 1文字目の場合保持
		if i == 0 {
			l = 1
			continue
		}

		if S[i-1] == S[i] {
			// 直前の文字と一致していればインクリメント
			l++
		} else {
			// 不一致のタイミングで追加し、長さをリセットする
			runes = append(runes, S[i-1])
			lengths = append(lengths, l)
			l = 1
		}
	}
	runes = append(runes, S[len(S)-1])
	lengths = append(lengths, l)

	return runes, lengths
}

// RunLengthDecoding decodes RLE results.
func RunLengthDecoding(S []int, L []int) []int {
	if len(S) != len(L) {
		panic("S, L are not RunLengthEncoding results")
	}

	res := []int{}

	for i := 0; i < len(S); i++ {
		for j := 0; j < L[i]; j++ {
			res = append(res, S[i])
		}
	}

	return res
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
*/

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

package main

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

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

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

/********** 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 MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60
const INF_INT32 = math.MaxInt32
const INF_BIT30 = 1 << 30

var n int
var A []int

var dp1, dp2 [200000 + 5]int

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

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

	for i := 0; i < n; i++ {
		if i-1 >= 0 && A[i] > A[i-1] {
			ChMax(&dp1[i], dp1[i-1]+1)
			ChMax(&dp2[i], dp2[i-1]+1)
		}
		if i-2 >= 0 && A[i] > A[i-2] {
			ChMax(&dp2[i], dp1[i-2]+1)
		}
	}

	fmt.Println(Max(dp1[n-1], dp2[n-1]))
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

/*
- まずは全探索を検討しましょう
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
- いきなりオーバーフローはしていませんか？
- MOD取る系はint64必須ですよ？
*/

/*
ASCII code

ASCII   10進数  ASCII   10進数  ASCII   10進数
!       33      "       34      #       35
$       36      %       37      &       38
'       39      (       40      )       41
*       42      +       43      ,       44
-       45      .       46      /       47
0       48      1       49      2       50
3       51      4       52      5       53
6       54      7       55      8       56
9       57      :       58      ;       59
<       60      =       61      >       62
?       63      @       64      A       65
B       66      C       67      D       68
E       69      F       70      G       71
H       72      I       73      J       74
K       75      L       76      M       77
N       78      O       79      P       80
Q       81      R       82      S       83
T       84      U       85      V       86
W       87      X       88      Y       89
Z       90      [       91      \       92
]       93      ^       94      _       95
`       96      a       97      b       98
c       99      d       100     e       101
f       102     g       103     h       104
i       105     j       106     k       107
l       108     m       109     n       110
o       111     p       112     q       113
r       114     s       115     t       116
u       117     v       118     w       119
x       120     y       121     z       122
{       123     |       124     }       125
~       126             127
*/

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


package main

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

type Node struct {
	id  int
	cnt int
}

type Heap struct {
	pq []Node
}

func (h *Heap) init(n int) {
	h.pq = make([]Node, n+1)[:1]
}
func (h *Heap) isEmpty() bool {
	return h.pq == nil || len(h.pq) == 1
}
func (h *Heap) len() int {
	return len(h.pq) - 1
}
func (h *Heap) delMax() Node {
	t := h.pq[1]
	h.pq[1] = h.pq[len(h.pq)-1]
	h.pq = h.pq[:len(h.pq)-1]
	h.sink(1)
	return t
}
func (h *Heap) insert(x Node) {
	h.pq = append(h.pq, x)
	h.swim(len(h.pq) - 1)
}
func (h *Heap) less(a, b int) bool {
	return h.pq[a].cnt < h.pq[b].cnt
}
func (h *Heap) swap(a, b int) {
	h.pq[a], h.pq[b] = h.pq[b], h.pq[a]
}
func (h *Heap) swim(k int) {
	for k > 1 && h.less(k/2, k) {
		h.swap(k, k/2)
		k /= 2
	}
}
func (h *Heap) sink(k int) {
	N := len(h.pq) - 1
	for (k << 1) <= N {
		j := k << 1
		if j < N && h.less(j, j+1) {
			j++
		}
		if h.less(j, k) {
			break
		}
		h.swap(j, k)
		k = j
	}
}

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

	var t int
	var n, v int
	ans := make([][2]int, 0, 5000)
	for Fscan(in, &t); t > 0; t-- {
		sum := 0
		ans = ans[:0]
		Fscan(in, &n)
		h := &Heap{}
		h.init(n)
		for i := 1; i <= n; i++ {
			Fscan(in, &v)
			if v != 0 {
				h.insert(Node{i, v})
			}
		}
		for h.len() >= 2 {
			sum++
			fir, sec := h.delMax(), h.delMax()
			ans = append(ans, [2]int{fir.id, sec.id})
			fir.cnt--
			if fir.cnt != 0 {
				h.insert(fir)
			}
			sec.cnt--
			if sec.cnt != 0 {
				h.insert(sec)
			}
		}
		Fprintln(out, sum)
		for i := 0; i < sum; i++ {
			Fprintf(out, "%d %d\n", ans[i][0], ans[i][1])
		}
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type pair struct{ v, i int }
type hp []pair

func (h hp) Len() int            { return len(h) }
func (h hp) Less(i, j int) bool  { return h[i].v > h[j].v }
func (h hp) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *hp) Push(v interface{}) { *h = append(*h, v.(pair)) }
func (h *hp) Pop() interface{}   { a := *h; v := a[len(a)-1]; *h = a[:len(a)-1]; return v }

func CF1579D(_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)
		h := make(hp, n)
		for i := range h {
			Fscan(in, &h[i].v)
			h[i].i = i + 1
		}
		heap.Init(&h)
		ans := [][2]int{}
		for {
			p, q := heap.Pop(&h).(pair), heap.Pop(&h).(pair)
			if q.v == 0 {
				break
			}
			ans = append(ans, [2]int{p.i, q.i})
			p.v--
			q.v--
			heap.Push(&h, p)
			heap.Push(&h, q)
		}
		Fprintln(out, len(ans))
		for _, p := range ans {
			Fprintln(out, p[0], p[1])
		}
	}
}

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

package main

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

//problem D
func max(x, y int) int {
	if x >= y {
		return x
	}

	return y
}

type node struct {
	index, num, sum int
}

type problem struct {
	N    int
	data []node
}

func (p *problem) Scanf(reader *bufio.Reader) {
	for i := 0; i < p.N-1; i++ {
		fmt.Fscanf(reader, "%d ", &p.data[i].num)
		p.data[i].index = i + 1
	}

	fmt.Fscanf(reader, "%d\n", &p.data[p.N-1].num)
	p.data[p.N-1].index = p.N
}

func (p *problem) Run() {
	sort.Slice(p.data, func(i, j int) bool { return p.data[i].num < p.data[j].num })
	ans := 0
	p.data[0].sum = p.data[0].num
	for i := 1; i < p.N; i++ {
		p.data[i].sum = p.data[i].num + p.data[i-1].sum
	}

	if p.data[p.N-1].num >= p.data[p.N-2].sum {
		ans = max(ans, p.data[p.N-2].sum)
	} else {
		ans = max(ans, p.data[p.N-1].sum/2)
	}

	fmt.Println(ans)

	var mid, yu int

	for i := 0; i < p.N; i++ {
		if p.data[i].sum >= ans {
			mid = i
			yu = p.data[i].sum - ans
			break
		}
	}

	for yu > 0 && p.data[mid].num > yu && ans > 0 {
		fmt.Printf("%d %d\n", p.data[mid].index, p.data[p.N-1].index)
		p.data[mid].num--
		p.data[p.N-1].num--
		ans--
	}

	var start1, start2 int = 0, mid

	if yu == 0 {
		start2 = mid + 1
	}

	for ; ans > 0; ans-- {
		for ; p.data[start1].num == 0; start1++ {
		}

		for ; p.data[start2].num == 0; start2++ {
		}

		fmt.Printf("%d %d\n", p.data[start1].index, p.data[start2].index)
		p.data[start1].num--
		p.data[start2].num--
	}
}

func NewProblem(n int) *problem {
	return &problem{
		N:    n,
		data: make([]node, n),
	}
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var t, n int
	fmt.Fscanf(reader, "%d\n", &t)
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d\n", &n)
		p := NewProblem(n)
		p.Scanf(reader)
		p.Run()
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1243D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

	n, m := read(), read()
	g := make([][]int, n)
	for ; m > 0; m-- {
		v, w := read()-1, read()-1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprint(out, n-1)
		return
	}

	merge0 := func(v int, edges []int) {
		vs := map[int]bool{v: true}
		for _, w := range edges {
			vs[w] = true
		}
		for i := 0; i < n; i++ {
			if !vs[i] {
				merge(i, v)
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	for v, edges := range g {
		if !same(v, maxDeg0V) {
			merge0(v, edges)
		}
	}

	ans := -1
	for i, v := range fa {
		if i == v {
			ans++
		}
	}
	Fprint(out, ans)
}

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

package main

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

var fa []int

func initFa(n int) {
	fa = make([]int, n)
	for i := range fa {
		fa[i] = i
	}
}
func find(x int) int {
	if fa[x] != x {
		fa[x] = find(fa[x])
	}
	return fa[x]
}
func merge(from, to int) { fa[find(from)] = find(to) }
func same(x, y int) bool { return find(x) == find(y) }

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

	var n, m int
	Fscan(in, &n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		var v, w int
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	// 寻找 0-边最大的点 maxDeg0V
	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}

	// 若图中没有 0-边，答案就是点的个数-1
	if maxDeg0 == 0 {
		Print(n - 1)
		return
	}

	mergeEdge0 := func(v int, edges []int) {
		vs := map[int]bool{v: true}
		for _, w := range edges {
			vs[w] = true
		}
		for i := 0; i < n; i++ {
			if !vs[i] { // i-v 是 0-边
				merge(i, v)
			}
		}
	}
	initFa(n)
	mergeEdge0(maxDeg0V, g[maxDeg0V])
	for v, edges := range g {
		if !same(v, maxDeg0V) {
			// 暴力遍历剩余的点
			mergeEdge0(v, edges)
		}
	}

	// 计算联通分量个数-1
	ans := -1
	for i, faI := range fa {
		if i == faI {
			ans++
		}
	}
	Print(ans)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1243D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprint(out, n-1)
		return
	}

	merge0 := func(to int, edges []int) {
		sort.Ints(edges)
		j := 0
		for i := 0; i < n; i++ {
			if i == to {
				continue
			}
			if j == len(edges) || i < edges[j] {
				merge(i, to)
			} else {
				j++
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	vs := map[int]bool{maxDeg0V: true}
	for _, w := range g[maxDeg0V] {
		vs[w] = true
	}
	for v, edges := range g {
		if same(v, maxDeg0V) {
			continue
		}
		cnt := 1
		for _, w := range edges {
			if !vs[w] { // same(w, maxDeg0V)
				cnt++
			}
		}
		if cnt < n-len(g[maxDeg0V]) { // has 0 to vs
			merge(v, maxDeg0V)
		} else {
			merge0(v, edges)
		}
	}

	for i := range fa {
		find(i)
	}
	ans := -1
	for i, v := range fa {
		if i == v {
			ans++
		}
	}
	Fprint(out, ans)
}

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

package main

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

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

	var n, m int
	fmt.Fscanf(r, "%d %d\n", &n, &m)

	g := make(map[int][]int)
	for i := 0; i < m; i++ {
		var u, v int
		fmt.Fscanf(r, "%d %d\n", &u, &v)
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}

	out := make(map[int]bool)
	for u := 1; u <= n; u++ {
		out[u] = true
	}

	in_tree := make(map[int]bool)
	in_q1 := make(map[int]bool)

	var q0, q1 []int
	q0 = append(q0, 1)
	cost := 0
	for len(q0) > 0 || len(q1) > 0 {
		var u int
		if len(q0) > 0 {
			u = q0[0]
			q0 = q0[1:]
		} else {
			u = q1[0]
			q1 = q1[1:]
			if !in_tree[u] {
				cost++
			}
		}

		if in_tree[u] {
			continue
		}
		in_tree[u] = true

		t := make(map[int]bool)
		for _, v := range g[u] {
			if in_tree[v] {
				continue
			}
			if out[v] {
				t[v] = true
				delete(out, v)
			}
		}

		for v := range out {
			q0 = append(q0, v)
		}
		for v := range t {
			if !in_tree[v] && !in_q1[v] {
				in_q1[v] = true
				q1 = append(q1, v)
			}
		}
		out = t
	}

	fmt.Println(cost)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1243D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	var fa, sz []int
	initFa := func(n int) {
		fa = make([]int, n)
		sz = make([]int, n)
		for i := range fa {
			fa[i] = i
			sz[i] = 1
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) {
		faFrom, faTo := find(from), find(to)
		fa[faFrom] = faTo
		sz[faTo] += sz[faFrom]
	}
	same := func(x, y int) bool { return find(x) == find(y) }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprint(out, n-1)
		return
	}

	merge0 := func(to int, edges []int) {
		sort.Ints(edges)
		j := 0
		for i := 0; i < n; i++ {
			if i == to {
				continue
			}
			if j == len(edges) || i < edges[j] {
				merge(i, to)
			} else {
				j++
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	for v, edges := range g {
		if same(v, maxDeg0V) {
			continue
		}
		cnt := 1
		for _, w := range edges {
			if same(w, maxDeg0V) {
				cnt++
			}
		}
		if cnt < n-sz[maxDeg0V] { // has 0 to vs
			merge(v, maxDeg0V)
		} else {
			merge0(v, edges)
		}
	}

	for i := range fa {
		find(i)
	}
	ans := -1
	for i, v := range fa {
		if i == v {
			ans++
		}
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1243D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprint(out, n-1)
		return
	}

	merge0 := func(to int, edges []int) {
		sort.Ints(edges)
		j := 0
		for i := 0; i < n; i++ {
			if i == to {
				continue
			}
			if j == len(edges) || i < edges[j] {
				merge(i, to)
			} else {
				j++
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	for v, edges := range g {
		if same(v, maxDeg0V) {
			continue
		}
		cnt := 0
		for _, w := range edges {
			if same(w, maxDeg0V) {
				cnt++
			}
		}
		if cnt < len(g[maxDeg0V]) { // has 0 to vs
			merge(v, maxDeg0V)
		} else {
			merge0(v, edges)
		}
	}

	for i := range fa {
		find(i)
	}
	ans := -1
	for i, v := range fa {
		if i == v {
			ans++
		}
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol1243D(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	var fa []int
	initFa := func(n int) {
		fa = make([]int, n)
		for i := range fa {
			fa[i] = i
		}
	}
	var find func(int) int
	find = func(x int) int {
		if fa[x] != x {
			fa[x] = find(fa[x])
		}
		return fa[x]
	}
	merge := func(from, to int) { fa[find(from)] = find(to) }
	same := func(x, y int) bool { return find(x) == find(y) }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]int, n)
	for ; m > 0; m-- {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	maxDeg0, maxDeg0V := 0, 0
	for v, edges := range g {
		if deg0 := n - 1 - len(edges); deg0 > maxDeg0 {
			maxDeg0 = deg0
			maxDeg0V = v
		}
	}
	if maxDeg0 == 0 {
		Fprint(out, n-1)
		return
	}

	merge0 := func(to int, edges []int) {
		sort.Ints(edges)
		j := 0
		for i := 0; i < n; i++ {
			if i == to {
				continue
			}
			if j == len(edges) || i < edges[j] {
				merge(i, to)
			} else {
				j++
			}
		}
	}
	initFa(n)
	merge0(maxDeg0V, g[maxDeg0V])
	vs := map[int]bool{maxDeg0V: true}
	for v, edges := range g {
		if same(v, maxDeg0V) {
			continue
		}
		cnt := 0
		for _, w := range edges {
			if !vs[w] { // same(w, maxDeg0V)
				cnt++
			}
		}
		if cnt < n-len(g[maxDeg0V]) { // has 0 to vs
			merge(v, maxDeg0V)
		} else {
			merge0(v, edges)
		}
	}

	for i := range fa {
		find(i)
	}
	ans := -1
	for i, v := range fa {
		if i == v {
			ans++
		}
	}
	Fprint(out, ans)
}

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


package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  n := ni()
  cur := 0
  a, b := make([]int, n), make([]int, n)
  used := make([]bool, n)
  var dfs func(v, to int) bool
  dfs = func(v, to int) bool {
    if v == to {
      return true
    } else {
      ans := false
      for j := 0; j < cur; j++ {
        if ((a[j] < a[v] && a[v] < b[j]) || (a[j] < b[v] && b[v] < b[j])) && !used[j] {
          used[j] = true
          ans = ans || dfs(j, to)
        }
      }
      return ans
    }
  }
  for i := 0; i < n; i++ {
    t := ni()
    if t == 1 {
      a[cur], b[cur] = ni(), ni()
      cur++
    } else {
      x, y := ni()-1, ni()-1
      used = make([]bool, n)
      if dfs(x, y) {
        w.WriteString("YES\n")
      } else {
        w.WriteString("NO\n")
      }
    }
  }
  w.Flush()
}

package main

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

var scanner *bufio.Scanner

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

type Segment struct {
  Id, Left, Right int
  Reach []*Segment
}

var seen map[int]bool

func Seek(u, v *Segment) bool {
  if seen[u.Id] {
    return false
  }
  if v.Id == u.Id {
    return true
  }
  seen[u.Id] = true
  for _, w := range u.Reach {
    if Seek(w, v) {
      return true
    }
  }
  return false
}

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

  q := getI()
  segments := []*Segment{ nil }
  for qi := 1; qi <= q; qi++ {
    kind, x, y := getI(), getI(), getI()
    if kind == 1 {
      segment := &Segment{ qi, x, y, []*Segment{} }
      for i := 1; i < len(segments); i++ {
        previous := segments[i]
        r, s := previous.Left, previous.Right
        if (x < r && r < y) || (x < s && s < y) {
          previous.Reach = append(previous.Reach, segment)
        }
        if (r < x && x < s) || (r < y && y < s) {
          segment.Reach = append(segment.Reach, previous)
        }
      }
      segments = append(segments, segment)
    } else {
      seen = map[int]bool{}
      if Seek(segments[x], segments[y]) {
        writer.WriteString("YES\n")
      } else {
        writer.WriteString("NO\n")
      }
    }
  }
}

package main

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

var scanner *bufio.Scanner

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

type Segment struct {
  Left, Right int
  Leader *Segment
}

func getLeader(segment *Segment) *Segment {
  if segment.Leader == segment {
    return segment
  } else {
    leader := getLeader(segment.Leader)
    segment.Leader = leader
    return leader
  }
}

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

  q := getI()
  segments := []*Segment{}
  for qi := 0; qi < q; qi++ {
    kind, a, b := getI(), getI(), getI()
    if kind == 1 {
      segment := &Segment{ Left: a, Right: b }
      segment.Leader = segment
      for _, previous := range segments {
        c, d := previous.Left, previous.Right
        if (c < a && a < d) || (c < b && b < d) {
          previous.Leader = segment
        }
      }
      segments = append(segments, segment)
    } else {
      s, t := getLeader(segments[a-1]), getLeader(segments[b-1])
      if s == t {
        writer.WriteString("YES\n")
      } else {
        writer.WriteString("NO\n")
      }
    }
  }
}

package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  n := ni()
  cur := 0
  a, b := make([]int, n), make([]int, n)
  used := make([]bool, n)
  var dfs func(v, to int) bool
  dfs = func(v, to int) bool {
    if v == to {
      return true
    } else {
      ans := false
      for j := 0; j < cur; j++ {
        if ((a[j] < a[v] && a[v] < b[j]) || (a[j] < b[v] && b[v] < b[j])) && !used[j] {
          used[j] = true
          ans = ans || dfs(j, to)
        }
      }
      return ans
    }
  }
  for i := 0; i < n; i++ {
    t := ni()
    if t == 1 {
      a[cur], b[cur] = ni(), ni()
      cur++
    } else {
      x, y := ni()-1, ni()-1
      if dfs(x, y) {
        w.WriteString("YES\n")
      } else {
        w.WriteString("NO\n")
      }
    }
  }
  w.Flush()
}


package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n int
		var s string
		Fscan(in, &n, &s)
		dp := make([][2][2]int, n)
		for i := range dp {
			for j := range dp[i] {
				dp[i][j] = [2]int{-1, -1}
			}
		}
		var f func(int, int, int) int
		f = func(i, odd, one int) (res int) {
			if i == n {
				return
			}
			dv := &dp[i][odd][one]
			if *dv != -1 {
				return *dv
			}
			defer func() { *dv = res }()
			z := s[i] == '0'
			res = 1e9
			if one == 0 {
				// keep zero
				r := 0
				if z == (odd == 0) {
					r = f(i+1, odd, 0)
				} else {
					r = f(i+1, odd^1, 0) + 1
				}
				res = min(res, r)

				// to one
				r = 0
				if z == (odd == 0) {
					r = f(i+1, odd^1, 1) + 1
				} else {
					r = f(i+1, odd, 1)
				}
				res = min(res, r)
			} else {
				// keep one
				r := 0
				if z == (odd == 0) {
					r = f(i+1, odd^1, 1)+1
				} else {
					r = f(i+1, odd, 1)
				}
				res = min(res, r)
			}
			return
		}
		ans := f(0, 0, 0)
		Fprintln(out, ans)
	}

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

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

}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1732B
Date: 11/18/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1732/B
Problem: CF1732B
**/
func (in *CF1732B) Run() {
	var sol strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		var last uint8 = '-'
		ans := 0

		d := 0
		for d < n {
			if str[d] == '0' {
				d++
			} else {
				break
			}
		}

		for i := n - 1; i >= d; i-- {
			if i == n-1 {
				last = str[i]
			}

			if last != str[i] {
				//fmt.Println("last ", string(last), " current ", string(str[i]), " value ", current)
				ans++
				last = str[i]
			}
		}

		sol.WriteString(fmt.Sprintf("%v\n", ans))
	}
	fmt.Print(sol.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1732B
Date: 11/18/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1732/B
Problem: CF1732B
**/
func (in *CF1732B) Run() {
	var sol strings.Builder
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		str := in.NextString()
		var last uint8 = '-'
		current := 0
		ans := 0

		d := 0
		for d < n {
			if str[d] == '0' {
				d++
			} else {
				break
			}
		}

		for i := n - 1; i >= d; i-- {
			if i == n-1 {
				last = str[i]
				current = int(str[i] - '0')
			}

			if last != str[i] {
				//fmt.Println("last ", string(last), " current ", string(str[i]), " value ", current)
				if current == 0 {
					current = 1
				} else {
					current = 0
				}
				ans++
				last = str[i]
			}
		}

		sol.WriteString(fmt.Sprintf("%v\n", ans))
	}
	fmt.Print(sol.String())
}

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

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

package main

import "fmt"

// 暴力递归 TLE
// func Verse(bs []byte, poi int, mins int) int {
// 	if(poi == -1) {
// 		return mins
// 	}
// 	next := -1
// 	flag := false
// 	for i := poi; i < len(bs);i++ {
// 		if bs[i] == '1' {
// 			bs[i] = '0'
// 		} else {
// 			flag = true
// 			bs[i] = '1'
// 			if next == -1 && i < (len(bs)-1){
// 				next = i
// 			}
// 		}
// 	}
// 	if flag {
// 		mins = mins + 1
// 	}
// 	return Verse(bs, next, mins)
// }

// 不用每次进行赋值操作,直接跳过
// 01010
func Verse(bs []byte, poi int, mins int) int {
	if(poi == -1) {
		return mins
	}
	next := -1
	flag := false
	for i := poi; i < len(bs);i++ {
		val := bs[i]
		if mins % 2 != 0 {
			if val == '0' {
				val = '1'
			} else {
				val = '0'
			}
		}
		if val == '0' {
			flag = true
			if next == -1 && i < (len(bs)-1){
				next = i
				break;
			}
		}
	}
	if flag {
		mins = mins + 1
	}
	return Verse(bs, next, mins)
}

func main(){
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var l int
		var s string
		fmt.Scan(&l)
		fmt.Scan(&s)
		bs := []byte(s)
		flag := false
		for	j:=0;j<l;j++ {
			if bs[j] == '1' {
				fmt.Println(Verse(bs, j, 0))
				flag = true
				break;
			}
		}
		if !flag {
			fmt.Println(0)
		}
	}
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		n := readInt(reader)
		a := readString(reader)
		diff := 0
		for i := 1; i < n; i++ {
			if a[i-1] != a[i] {
				diff++
			}
		}
		if diff == 0 {
			fmt.Fprintln(writer, 0)
		} else if a[0] == '0' {
			fmt.Fprintln(writer, diff-1)
		} else {
			fmt.Fprintln(writer, diff)
		}

		t--
	}

	writer.Flush()
}

func max(a int, b int) int {
	return int(maxInt64(int64(a), int64(b)))
}

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

	return b
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

const cf = true

type pair struct {
	begin int
	end   int
}

type val struct {
	ind      int
	val      int
	haveZero bool
}

func solve() {
	var n int
	fmt.Fscan(in, &n)
	var str string
	fmt.Fscan(in, &str)
	i := 0
	for i < n && str[i] == '0' {
		i++
	}
	ans := 0
	for ; i < n-1; i++ {
		if str[i] != str[i+1] {
			ans++
		}
	}
	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func LCM(a, b int) int {
	return a * b / GCD(a, b)
}

func GCD(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

type SqrtInt interface {
	SignedSqrt | UnsignedSqrt
}

type SignedSqrt interface {
	~int | ~int32 | ~int64
}

type UnsignedSqrt interface {
	~uint | ~uint32 | ~uint64 | ~uintptr
}

func sqrt[T SqrtInt](x T) T {
	l, r := T(0), T(2000000123)
	for l < r {
		mid := (l + r) / 2
		if mid*mid > x {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l - 1
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []byte(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

const N = 1e5 + 10

var (
	t, n int
	str  string
	a    []int
)

func gcd(x, y int) int {
	r := 0
	for y != 0 {
		r = x % y
		x = y
		y = r
	}
	return x
}

func main() {
	defer flush()
	scan(&t)
	a = make([]int, N)
	for ; t != 0; t-- {
		scan(&n, &str)
		d := 0
		ans := 0
		flag := true
		for i := 0; i < n; i++ {

			temp := int(str[i]-'0') ^ d
			if temp == 0 {
				if flag {
					continue
				}
				d = d ^ 1
				ans++
			}
			flag = false
		}
		println(ans)
	}

}

var (
	ioR *bufio.Reader
	ioW *bufio.Writer
)

func init() {
	ioR = bufio.NewReader(os.Stdin)
	ioW = bufio.NewWriter(os.Stdout)
}

func scan(a ...any) {
	fmt.Fscan(ioR, a...)
}

func println(a ...any) {
	fmt.Fprintln(ioW, a...)
}

func Print(a ...any) {
	fmt.Fprint(ioW, a...)
}

func flush() {
	ioW.Flush()
}

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 2000005
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}
func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}
func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("WITHIN") == "TEMPTATION" }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("REMEMBER_YOU_AS_LONG_AS_I_CAN"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		iost.Writer.Flush()
	}()
	solve()
}
func solve() {
	t := iost.GetNextInt()
	for i := 0; i < t; i++ {
		testcase()
	}
}
func testcase() {
	n := iost.GetNextInt()
	s := iost.Text()
	r := false
	ans := 0
	for i := 1; i < n; i++ {
		if s[i] == s[i-1] {
			continue
		}
		switch {
		case r && s[i-1] == '0' || !r && s[i-1] == '1':
			ans++
			r = !r
		}
	}
	iost.Println(ans)
}

package main

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

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		fmt.Fscan(r, &n)
		a := make([]byte, n)
		fmt.Fscan(r, &a)

		i := n-2
		res := 0
		res2 := 0
		flag := a[n-1]
		for i >= 0 {
			if flag == '0' && a[i] == '1' {
				res = res2 + 1
				res2 = res
			} else if flag == '1' && a[i] == '0' {
				res2++
			}
			flag = a[i]
			i--
		}

		fmt.Fprintln(w, res)
	}

}

package main

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

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

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

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

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

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

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

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

func sol(n int, s string) int {
	n0 := make([]int, n)
	n1 := make([]int, n)
	for i := n - 2; i >= 0; i-- {
		n0[i] = n0[i+1]
		n1[i] = n1[i+1]
		if s[i+1] == '0' {
			n0[i]++
		} else {
			n1[i]++
		}
	}
	// printf("%v %v\n", n0, n1)
	flip := false
	ret := 0
	for i := range s {
		if !flip {
			if s[i] == '1' && n0[i] > 0 {
				ret++
				flip = !flip
			}
			continue
		}
		if s[i] == '0' && n1[i] > 0 {
			ret++
			flip = !flip
		}
	}
	return ret
}