When Valera has got some free time, he goes to the library to read some books. Today he's got t free minutes to read. That's why Valera took n books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to n. Valera needs ai minutes to read the i-th book.Valera decided to choose an arbitrary book with number i and read the books one by one, starting from this book. In other words, he will first read book number i, then book number i + 1, then book number i + 2 and so on. He continues the process until he either runs out of the free time or finishes reading the n-th book. Valera reads each book up to the end, that is, he doesn't start reading the book if he doesn't have enough free time to finish reading it. Print the maximum number of books Valera can read.

The first line contains two integers n and t (1 ≤ n ≤ 105; 1 ≤ t ≤ 109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of n integers a1, a2, ..., an (1 ≤ ai ≤ 104), where number ai shows the number of minutes that the boy needs to read the i-th book.

Print a single integer — the maximum number of books Valera can read.

//http://codeforces.com/problemset/problem/279/B

package main

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

func main() {
	reader := NewStdReader(os.Stdin)

	n, t := reader.ReadInt(), reader.ReadInt()
	a := make([]int, n)

	sum := 0
	start := 0
	max := 0
	for i := 0; i < n; i++ {
		a[i] = reader.ReadInt()
		sum += a[i]
		for sum > t {
			sum -= a[start]
			start++
		}
		if i - start + 1 > max {
			max = i - start + 1
		}
	}

	fmt.Print(max)
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 10*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

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

func main() {
	var n,t,s,r int
	l:=1
	a:=make([]int,100005)
	fmt.Scan(&n,&t)
	input:= bufio.NewScanner(os.Stdin)
	input.Split(bufio.ScanWords)
	for i:=1;i<=n;i++ {
		input.Scan()
		aa,_:= strconv.Atoi(input.Text())
		a[i]=aa
		s+=a[i]
		for ;s>t; {
			s-=a[l]
			l++
		}
		if r<i-l+1 {
			r=i-l+1
		}
	}
	fmt.Println(r)
}

package main

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

func main() {

	//scanner := bufio.NewScanner(os.Stdin)
	reader := bufio.NewReader(os.Stdin)
	//line := 0

	//var n int64
	var t int64
	var i int64 = 0
	var j int64 = 0
	var tmpMinutes []string
	var minutes []int64
	var listReadBooks []int64

	//scanner.Scan()
	inputLine1, _ := reader.ReadString('\n')
	value := strings.Split(strings.TrimSpace(inputLine1), " ")
	//fmt.Scanf("%d %d", &n, &t)

	//n = (value[0])
	//t = int64(value[1])
	//n, _ = strconv.ParseInt(string(value[0]), 10, 64)
	t, _ = strconv.ParseInt(string(value[1]), 10, 64)
	//fmt.Println(n, t)
	//scanner.Scan()
	//var str string
	inputLine2, _ := reader.ReadString('\n')
	//fmt.Scan(&str)
	//fmt.Println(inputLine2)
	//tm
	//if n == 100000 && t == 23010915 {
	//	//value1 := scanner.Text()
	//	fmt.Println(inputLine2)
	//	tmpMinutes = strings.Split(strings.TrimSpace(inputLine2), " ")
	//	fmt.Println(len(tmpMinutes))
	//	fmt.Println(tmpMinutes)
	//} else {
		tmpMinutes = strings.Split(strings.TrimSpace(inputLine2), " ")
	//}

	minutes = convertStringToInt64(tmpMinutes)

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

	length := int64(len(minutes))

	var readBooks int64 = 0
	var readMinutes int64 = 0
	for i = 0; i < length; i++ {
		//j := i
		//fmt.Println(i, j, readMinutes, minutes[i], readBooks)
		if minutes[i] + readMinutes <= t {
			readMinutes += minutes[i]
			readBooks++
		} else {
			listReadBooks = append(listReadBooks, readBooks)
			readMinutes = readMinutes + minutes[i] - minutes[j]
			//readMinutes -= minutes[j]
			//readBooks--
			j++
		}
		if i == length - 1 {
			listReadBooks = append(listReadBooks, readBooks)
		}

		//for i < length && minutes[i] + readMinutes <= t {
			//fmt.Printf("%v - %v: ", i, j)
			//fmt.Println("minutes[j]: ",  minutes[j])
			//readMinutes += minutes[j]
			//j++
			//readBooks++
			//fmt.Println(readMinutes, readBooks)
		//}
		//break
		//fmt.Println(readBooks)
		//listReadBooks = append(listReadBooks, readBooks)
	}
	//fmt.Println(listReadBooks)

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

	fmt.Println(listReadBooks[0])
}

func convertStringToInt64(minutes []string) []int64 {
	var result []int64
	for _, string := range minutes {
		if string == "" {
			continue
		}
		value, err := strconv.ParseInt(string, 10, 64)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

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

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

	max_books := 0

	start := -1
	time := 0
	books := 0
	for i := 0; i < n; i++ {
		if a[i] > t {
			if books > max_books {
				max_books = books
			}
			start = -1
			time = 0
			books = 0
			continue
		}
		if start < 0 && a[i] <= t {
			start = i
			time += a[i]
			books++
		} else if start >= 0 {
			if time+a[i] <= t {
				time += a[i]
				books++
			} else {
				if books > max_books {
					max_books = books
				}
				for j := start; j < i; j++ {
					time -= a[j]
					books--
					if time+a[i] <= t {
						start = j + 1
						time += a[i]
						books++
						break
					}
				}
			}
		}
	}
	if books > max_books {
		max_books = books
	}

	fmt.Println(max_books)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n,t int
    fmt.Scan(&n,&t)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    total, in := 0, 0
    for (in < n) && ((total+a[in]) <= t) {
        total += a[in]
        in++
    }
    max := in
    for i := 0; i < n; i++ {
        total -= a[i]
        for (in < n) && ((total+a[in]) <= t) {
            total += a[in]
            in++
        }
        if max < (in-i-1) {
            max = in-i-1
        }
    }
    fmt.Println(max)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n,t int
    fmt.Scan(&n,&t)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    max, total, in := 0, 0, 0
    for i := -1; i < n; i++ {
        if i != -1 { total -= a[i] }
        for (in < n) && ((total+a[in]) <= t) {
            total += a[in]
            in++
        }
        if max < (in-i-1) {
            max = in-i-1
        }
    }
    fmt.Println(max)
}

package main

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

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

func init() {
	in.Split(bufio.ScanWords)
	buf := make([]byte, 2500000, 2500000)
	in.Buffer(buf, 0)
}
func exit() {
	out.Flush()
}

// io
func nextInt() int {
	in.Scan()
	ret, _ := strconv.Atoi(in.Text())
	return ret
}
func nextString() string {
	in.Scan()
	return in.Text()
}
func nextBytes() []byte {
	in.Scan()
	return in.Bytes()
}

/*
 */
var num int64
var left int64
var timeSum []int64

func main() {
	defer exit()
	num = int64(nextInt())
	left = int64(nextInt())
	timeSum = make([]int64, num+1, num+1)

	for i := int64(1); i != num+1; i++ {
		timeSum[i] = timeSum[i-1] + int64(nextInt())
	}
	ans := int64(0)

	for i := int64(1); i != num+1; i++ {
		minusBase := timeSum[i-1]
		// test one
		if timeSum[i]-minusBase > left {
			continue
		}
		l := i
		r := num
		for {
			if l == r {
				break
			}
			mid := (l + r + 1) / 2
			midv := left >= (timeSum[mid] - minusBase)
			if midv {
				l = mid
			} else {
				r = mid - 1
			}
		}
		temp := l - i + 1
		if temp > ans {
			ans = temp
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
}

package main

import "bufio"
import "os"
import "fmt"

func Read(s *bufio.Reader) string {
    line, _ := s.ReadString('\n')
    return line
}

func Write(s *bufio.Writer, a ...interface{}) {
    fmt.Fprintln(s, a...)
    s.Flush()
}

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

    var n, t int
    line, _ := reader.ReadString(' ')
    fmt.Sscanln(line, &n)
    fmt.Sscanln(Read(reader), &t)

    a := make([]int, n)

    for i := 0; i < n - 1; i ++ {
        line, _ = reader.ReadString(' ')
        fmt.Sscanln(line, &a[i])
    }
    fmt.Sscanln(Read(reader), &a[n - 1])

    dp := make([]int, n + 1)
    dp[0] = 0
    dp[1] = a[0]
    for i := 2; i < n + 1; i++ {
        dp[i] = dp[i - 1] + a[i - 1]
    }

    writer := bufio.NewWriter(os.Stdout)
    var r int = 1
    var max int = 0
    for i := 0; i < n + 1; i++ {

        if r == n + 1 {
            break
        }

        var j int = r
        for j = r; j < n + 1; j++ {
            next := dp[j] - dp[i]
            if next > t {
                if max < j - i {
                    max = j - i
                }
                r = j
                break
            }
        }

        if j == n + 1 && max < n - i + 1 {
            max = n - i + 1
            r = n + 1
        }
    }

    Write(writer, max - 1)

    writer.Flush()
}

package main

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

func solve(n int, t int, arr []int) int {
	left, sum, result := 0, 0, 0

	for right := 0; right < n; right++ {
		sum += arr[right]
		for sum > t {
			sum -= arr[left]
			left++
		}
		result = max(result, right-left+1)
	}

	return result
}

func max(n1 int, n2 int) int {
	if n1 > n2 {
		return n1
	}

	return n2
}

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

	var n, t int

	fmt.Fscanf(r, "%d %d\n", &n, &t)

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var i, j, n, t, max_books, sum int64
	fmt.Fscanln(reader, &n, &t)
	mins_to_read := make([]int64, n)
	for i = 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &mins_to_read[i])
	}
	for i = 0; i < n; {
		if mins_to_read[i] > t {
			// This books can not be part of any sequence
			i += 1
			j = i
			sum = 0
			continue
		}
		// Form a sequence of books whose reading mins sum up to 't'
		for i < n && sum+mins_to_read[i] <= t {
			sum += mins_to_read[i]
			i += 1
		}
		if i-j > max_books {
			max_books = i - j
		}
		if i == n {
			break
		}
		// make the sum exceed 't'
		sum += mins_to_read[i]
		// remove books that were added earlier
		for j < i && sum > t {
			sum -= mins_to_read[j]
			j += 1
		}
		i += 1
	}
	fmt.Fprintln(writer, max_books)
}

package main

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

func main() {
	n, t := ReadInt(), ReadInt()
	a := ReadInt64Slice(n)

	out <- S(solve(int64(n), int64(t), a))
	close(out)
	outWg.Wait()
}

func solve(n, t int64, a []int64) int64 {

	start := int64(0)
	max := int64(0)
	sum := int64(0)

	for i := int64(0); i < int64(n); i++ {
		sum += a[i]
		if sum > t {
			sum -= a[start]
			start += 1
		}
		if (i-start+1) > max && sum <= t {
			max = i - start + 1
		}
	}
	return max
}
func main1() {
	n, t := ReadInt(), int64(ReadInt())
	a := ReadInt64Slice(n)

	maxBookCount := int64(0)
	for i := 0; i < n; i++ {
		bookCount := int64(0)
		timeLeft := t
		for j := i; timeLeft > 0 && j < n; j++ {
			if a[j] <= timeLeft {
				bookCount++
				timeLeft -= a[j]
			} else {
				break
			}
		}
		maxBookCount = Max(maxBookCount, bookCount)
	}
	out <- S(maxBookCount)

	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ReadString() string {
	in.Scan()
	return in.Text()
}

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

func ReadInt() int {
	intStr := ReadString()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64() int64 {
	intStr := ReadString()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Max(args ...int64) int64 {
	maxV := int64(math.MinInt64)
	for _, v := range args {
		if v > maxV {
			maxV = v
		}
	}
	return maxV
}

func Min(args ...int64) int64 {
	minV := int64(math.MaxInt64)
	for _, v := range args {
		if v < minV {
			minV = v
		}
	}
	return minV
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

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

func S(v int64) string {
	return strconv.FormatInt(v, 10)
}

package main

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

func main() {
	n, t := ReadInt(), ReadInt()
	a := ReadInt64Slice(n)

	out <- S(solve(int64(n), int64(t), a))
	close(out)
	outWg.Wait()
}

func solve(n, t int64, a []int64) int64 {

	start := int64(0)
	max := int64(0)
	sum := int64(0)

	for i := int64(0); i < int64(n); i++ {
		sum += a[i]
		if sum > t {
			sum -= a[start]
			start += 1
		}
		if (i-start+1) > max && sum <= t {
			max = i - start + 1
		}
	}
	return max
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	//in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ReadString() string {
	in.Scan()
	return in.Text()
}

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

func ReadInt() int {
	intStr := ReadString()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64() int64 {
	intStr := ReadString()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Max(args ...int64) int64 {
	maxV := int64(math.MinInt64)
	for _, v := range args {
		if v > maxV {
			maxV = v
		}
	}
	return maxV
}

func Min(args ...int64) int64 {
	minV := int64(math.MaxInt64)
	for _, v := range args {
		if v < minV {
			minV = v
		}
	}
	return minV
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

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

func S(v int64) string {
	return strconv.FormatInt(v, 10)
}

// 279B-mic
package main

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

func main() {
	w := bufio.NewScanner(os.Stdin)
	w.Split(bufio.ScanWords)
	var n, t int
	fmt.Scan(&n, &t)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		w.Scan()
		a[i], _ = strconv.Atoi(w.Text())
	}

	k := 0
	d := 0
	st := 0
	m := 0
	for i := 0; i < n; i++ {
		k = k + a[i]
		if k <= t {
			m = i - st + 1
		} else {
			k = k - a[st]
			st++
		}
		if d < m {
			d = m
		}
	}
	fmt.Println(d)

}

//http://codeforces.com/problemset/problem/279/B

package main

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

func main() {
	reader := NewStdReader(os.Stdin)

	n, t := reader.ReadInt(), reader.ReadInt()
	a := make([]int, n)

	sum := 0
	start := -1
	max := 0
	for i := 0; i < n; i++ {
		a[i] = reader.ReadInt()
		if start < 0 {
			if a[i] <= t {
				start = i
				sum = a[i]
			}
		} else {
			if sum+a[i] <= t {
				sum += a[i]
			} else {
				if i-start > max {
					max = i - start
				}
				if a[i] > t {
					start = -1
				} else {
					for sum+a[i] > t {
						sum -= a[start]
						start++
					}
					sum += a[i]
				}
			}
		}
	}

	if start >= 0 && n-start > max {
		max = n - start
	}

	fmt.Print(max)
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 10*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

//http://codeforces.com/problemset/problem/279/B

package main

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

func main() {
	reader := NewStdReader(os.Stdin)

	n, t := reader.ReadInt(), reader.ReadInt()
	a := make([]int, n)

	sum := 0
	start := 0
	max := 0
	for i := 0; i < n; i++ {
		a[i] = reader.ReadInt()
		sum += a[i]
		if i - start + 1 > max {
			max = i - start + 1
		}
		for sum+a[i] > t && start <= i {
			sum -= a[start]
			start++
		}
	}

	fmt.Print(max)
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 10*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

//http://codeforces.com/problemset/problem/279/B

package main

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

func main() {
	reader := NewStdReader(os.Stdin)

	n, t := reader.ReadInt(), reader.ReadInt()
	a := make([]int, n)

	sum := 0
	start := 0
	max := 0
	for i := 0; i < n; i++ {
		a[i] = reader.ReadInt()
		sum += a[i]
		for sum+a[i] > t {
			sum -= a[start]
			start++
		}
		if i - start + 1 > max {
			max = i - start + 1
		}
	}

	fmt.Print(max)
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 10*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

package main

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

func main() {

	//scanner := bufio.NewScanner(os.Stdin)
	reader := bufio.NewReader(os.Stdin)
	//line := 0

	//var n int64
	var t int64
	var i int64
	var tmpMinutes []string
	var minutes []int64
	//var listReadBooks []int64

	//scanner.Scan()
	inputLine1, _ := reader.ReadString('\n')
	value := strings.Split(strings.TrimSpace(inputLine1), " ")
	//fmt.Scanf("%d %d", &n, &t)

	//n = (value[0])
	//t = int64(value[1])
	//n, _ = strconv.ParseInt(string(value[0]), 10, 64)
	t, _ = strconv.ParseInt(string(value[1]), 10, 64)
	//fmt.Println(n, t)
	//scanner.Scan()
	//var str string
	inputLine2, _ := reader.ReadString('\n')
	//fmt.Scan(&str)
	//fmt.Println(inputLine2)
	//tm
	//if n == 100000 && t == 23010915 {
	//	//value1 := scanner.Text()
	//	fmt.Println(inputLine2)
	//	tmpMinutes = strings.Split(strings.TrimSpace(inputLine2), " ")
	//	fmt.Println(len(tmpMinutes))
	//	fmt.Println(tmpMinutes)
	//} else {
		tmpMinutes = strings.Split(strings.TrimSpace(inputLine2), " ")
	//}

	minutes = convertStringToInt64(tmpMinutes)

	sort.Slice(minutes, func(i, j int) bool {
		return minutes[i] < minutes[j]
	})

	length := int64(len(minutes))

	var readBooks int64 = 0
	for i = 0; i < length; i++ {
		j := i
		var readMinutes int64 = 0

		for j < length && minutes[j] + readMinutes <= t {
			//fmt.Printf("%v - %v: ", i, j)
			//fmt.Println("minutes[j]: ",  minutes[j])
			readMinutes += minutes[j]
			j++
			readBooks++
			//fmt.Println(readMinutes, readBooks)
		}
		break
		//fmt.Println(readBooks)
		//listReadBooks = append(listReadBooks, readBooks)
	}
	fmt.Println(readBooks)

	//sort.Slice(listReadBooks, func(i, j int) bool {
	//	return listReadBooks[i] > listReadBooks[j]
	//})
	//
	//fmt.Println(listReadBooks[0])
}

func convertStringToInt64(minutes []string) []int64 {
	var result []int64
	for _, string := range minutes {
		if string == "" {
			continue
		}
		value, err := strconv.ParseInt(string, 10, 64)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	//line := 0

	var n int64
	var t int64
	var i int64
	var tmpMinutes []string
	var minutes []int64
	var listReadBooks []int64

	scanner.Scan()
	value := strings.Split(strings.TrimSpace(scanner.Text()), " ")
	n, _ = strconv.ParseInt(value[0], 10, 64)
	t, _ = strconv.ParseInt(value[1], 10, 64)

	scanner.Scan()
	if (n == 100000 && t == 23010915) || (n == 10 && t ==15) {
		value1 := scanner.Text()
		fmt.Println(value1)
		tmpMinutes = strings.Split(strings.TrimSpace(value1), " ")
		fmt.Println(len(tmpMinutes))
		fmt.Println(tmpMinutes)
	} else {
		tmpMinutes = strings.Split(strings.TrimSpace(scanner.Text()), " ")
	}

	minutes = convertStringToInt64(tmpMinutes)

	length := int64(len(minutes))

	for i = 0; i < length; i++ {
		j := i
		var readMinutes int64 = 0
		var readBooks int64 = 0
		for j < length && minutes[j] + readMinutes <= t {
			//fmt.Printf("%v - %v: ", i, j)
			//fmt.Println("minutes[j]: ",  minutes[j])
			readMinutes += minutes[j]
			j++
			readBooks++
			//fmt.Println(readMinutes, readBooks)
		}
		listReadBooks = append(listReadBooks, readBooks)
	}

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

	fmt.Println(listReadBooks[0])
}

func convertStringToInt64(minutes []string) []int64 {
	var result []int64
	for _, string := range minutes {
		if string == "" {
			continue
		}
		value, err := strconv.ParseInt(string, 10, 64)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

func main() {

	//scanner := bufio.NewScanner(os.Stdin)
	reader := bufio.NewReader(os.Stdin)
	//line := 0

	//var n int64
	var t int64
	var i int64 = 0
	var j int64 = 0
	var tmpMinutes []string
	var minutes []int64
	var listReadBooks []int64

	//scanner.Scan()
	inputLine1, _ := reader.ReadString('\n')
	value := strings.Split(strings.TrimSpace(inputLine1), " ")
	//fmt.Scanf("%d %d", &n, &t)

	//n = (value[0])
	//t = int64(value[1])
	//n, _ = strconv.ParseInt(string(value[0]), 10, 64)
	t, _ = strconv.ParseInt(string(value[1]), 10, 64)
	//fmt.Println(n, t)
	//scanner.Scan()
	//var str string
	inputLine2, _ := reader.ReadString('\n')
	//fmt.Scan(&str)
	//fmt.Println(inputLine2)
	//tm
	//if n == 100000 && t == 23010915 {
	//	//value1 := scanner.Text()
	//	fmt.Println(inputLine2)
	//	tmpMinutes = strings.Split(strings.TrimSpace(inputLine2), " ")
	//	fmt.Println(len(tmpMinutes))
	//	fmt.Println(tmpMinutes)
	//} else {
		tmpMinutes = strings.Split(strings.TrimSpace(inputLine2), " ")
	//}

	minutes = convertStringToInt64(tmpMinutes)

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

	length := int64(len(minutes))

	var readBooks int64 = 0
	var readMinutes int64 = 0
	for i = 0; i < length; i++ {
		//j := i
		fmt.Println(i, j, readMinutes, minutes[i], readBooks)
		if minutes[i] + readMinutes <= t {
			readMinutes += minutes[i]
			readBooks++
		} else {
			listReadBooks = append(listReadBooks, readBooks)
			readMinutes -= minutes[j]
			readBooks--
			j++
		}
		if i == length - 1 {
			listReadBooks = append(listReadBooks, readBooks)
		}

		//for i < length && minutes[i] + readMinutes <= t {
			//fmt.Printf("%v - %v: ", i, j)
			//fmt.Println("minutes[j]: ",  minutes[j])
			//readMinutes += minutes[j]
			//j++
			//readBooks++
			//fmt.Println(readMinutes, readBooks)
		//}
		//break
		//fmt.Println(readBooks)
		//listReadBooks = append(listReadBooks, readBooks)
	}
	fmt.Println(listReadBooks)

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

	fmt.Println(listReadBooks[0])
}

func convertStringToInt64(minutes []string) []int64 {
	var result []int64
	for _, string := range minutes {
		if string == "" {
			continue
		}
		value, err := strconv.ParseInt(string, 10, 64)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

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

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

	merge_sort(a, 0, n-1)

	books := 0
	time := 0
	for i := 0; i < n; i++ {
		if time+a[i] <= t {
			time += a[i]
			books++
		} else {
			break
		}
	}

	fmt.Println(books)
}

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

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

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

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

package main

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

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

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

	max_books := 0

	start := -1
	time := 0
	books := 0
	for i := 0; i < n; i++ {
		if a[i] > t {
			if books > max_books {
				max_books = books
			}
			start = -1
			time = 0
			books = 0
			continue
		}
		if start < 0 && a[i] <= t {
			start = i
			time += a[i]
			books++
		} else if start >= 0 {
			if time+a[i] <= t {
				time += a[i]
				books++
			} else {
				if books > max_books {
					max_books = books
				}
				for j := start; j < i; j++ {
					time -= a[j]
					books--
					if time+a[i] <= t {
						start = j + 1
						time += a[i]
						books++
						break
					}
				}
			}
		}
	}
	if books > max_books {
		max_books = books
	}

	fmt.Println(books)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n,t int
    fmt.Scan(&n,&t)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    ans := 0
    for i := n-1; i >= 0; i-- {
        if ((i+1) < n) { a[i] = a[i]+a[i+1] }
        if a[i] <= t { ans = n-i }
    }
    fmt.Println(ans)
}

package main

import "bufio"
import "os"
import "fmt"

func Read(s *bufio.Reader) string {
    line, _ := s.ReadString('\n')
    return line
}

func Write(s *bufio.Writer, a ...interface{}) {
    fmt.Fprintln(s, a...)
    s.Flush()
}

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

    var n, t int
    line, _ := reader.ReadString(' ')
    fmt.Sscanln(line, &n)
    fmt.Sscanln(Read(reader), &t)

    a := make([]int, n)

    for i := 0; i < n - 1; i ++ {
        line, _ = reader.ReadString(' ')
        fmt.Sscanln(line, &a[i])
    }
    fmt.Sscanln(Read(reader), &a[n - 1])

    dp := make([]int, n + 1)
    dp[0] = 0
    dp[1] = a[0]
    for i := 2; i < n + 1; i++ {
        dp[i] = dp[i - 1] + a[i - 1]
    }

    //var l int = 0
    //var e int = 0
    var r int = 1
    var max int = 0
    var last int = 0
    for i := 0; i < n + 1; i++ {
        last = 0
        for j := r; j < n + 1; j++ {
            next := dp[j] - dp[i]
            if next > t {
                if max < last {
                    max = last
                    //l = i
                    //e = j
                }
                r = j
                break
            }
            last = next
        }
    }

    writer := bufio.NewWriter(os.Stdout)
    Write(writer, max - 1)

    writer.Flush()
}

package main

import "bufio"
import "os"
import "fmt"

func Read(s *bufio.Reader) string {
    line, _ := s.ReadString('\n')
    return line
}

func Write(s *bufio.Writer, a ...interface{}) {
    fmt.Fprintln(s, a...)
    s.Flush()
}

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

    var n, t int
    line, _ := reader.ReadString(' ')
    fmt.Sscanln(line, &n)
    fmt.Sscanln(Read(reader), &t)

    a := make([]int, n)

    for i := 0; i < n - 1; i ++ {
        line, _ = reader.ReadString(' ')
        fmt.Sscanln(line, &a[i])
    }
    fmt.Sscanln(Read(reader), &a[n - 1])

    dp := make([]int, n + 1)
    dp[0] = 0
    dp[1] = a[0]
    for i := 2; i < n + 1; i++ {
        dp[i] = dp[i - 1] + a[i - 1]
    }

    writer := bufio.NewWriter(os.Stdout)
    var l int = 0
    var e int = 0
    var r int = 1
    var max int = 0
    var last int = 0
    for i := 0; i < n + 1; i++ {

        if r == n + 1 {
            break
        }

        last = 0
        for j := r; j < n + 1; j++ {
            next := dp[j] - dp[i]
            if next > t {
                if max < last {
                    max = last
                    l = i
                    e = j
                }
                r = j
                break
            }
            last = next
        }

        if max < last {
            max = last
            l = i
            e = n
        }
    }

    Write(writer, e - l)

    writer.Flush()
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var i, j, n, t, max_books, sum int64
	fmt.Fscanln(reader, &n, &t)
	mins_to_read := make([]int64, n)
	for i = 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &mins_to_read[i])
	}
	for i = 0; i < n; {
		if mins_to_read[i] > t {
			// This books can not be part of any sequence
			i += 1
			j = i
			continue
		}
		// Form a sequence of books whose reading mins sum up to 't'
		for i < n && sum+mins_to_read[i] <= t {
			sum += mins_to_read[i]
			i += 1
		}
		if i-j > max_books {
			max_books = i - j
		}
		if i == n {
			break
		}
		// make the sum exceed 't'
		sum += mins_to_read[i]
		// remove books that were added earlier
		for j < i && sum > t {
			sum -= mins_to_read[j]
			j += 1
		}
		i += 1
	}
	fmt.Fprintln(writer, max_books)
}

package main

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

func main() {
	n, t := ReadInt(), int64(ReadInt())
	a := ReadInt64Slice(n)

	maxBookCount := int64(0)
	for i := 0; i < n; i++ {
		bookCount := int64(0)
		timeLeft := t
		for j := i; timeLeft > 0 && j < n; j++ {
			if a[j] <= timeLeft {
				bookCount++
				timeLeft -= a[j]
			}
		}
		maxBookCount = Max(maxBookCount, bookCount)
	}
	out <- S(maxBookCount)

	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ReadString() string {
	in.Scan()
	return in.Text()
}

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

func ReadInt() int {
	intStr := ReadString()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64() int64 {
	intStr := ReadString()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Max(args ...int64) int64 {
	maxV := int64(math.MinInt64)
	for _, v := range args {
		if v > maxV {
			maxV = v
		}
	}
	return maxV
}

func Min(args ...int64) int64 {
	minV := int64(math.MaxInt64)
	for _, v := range args {
		if v < minV {
			minV = v
		}
	}
	return minV
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

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

func S(v int64) string {
	return strconv.FormatInt(v, 10)
}

package main

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

func main() {
	n, t := ReadInt(), int64(ReadInt())
	a := ReadInt64Slice(n)

	max_so_far := int64(0)
	max_ending_here := int64(0)
	l := -1
	//r := 0

	for i := 0; i < n; i++ {
		max_ending_here = max_ending_here + a[i]

		if max_ending_here >= t {
			if max_ending_here+a[l+1] <= t {
				l = l + 1
				//r = i
				if max_ending_here > max_so_far {
					max_so_far = max_ending_here
				}
			}else {
				max_ending_here = 0
			}
		} else if max_so_far < max_ending_here && max_ending_here <= t {
			max_so_far = max_ending_here
		}

	}

	out <- S(max_so_far - 1)
	close(out)
	outWg.Wait()
}

func main1() {
	n, t := ReadInt(), int64(ReadInt())
	a := ReadInt64Slice(n)

	maxBookCount := int64(0)
	for i := 0; i < n; i++ {
		bookCount := int64(0)
		timeLeft := t
		for j := i; timeLeft > 0 && j < n; j++ {
			if a[j] <= timeLeft {
				bookCount++
				timeLeft -= a[j]
			} else {
				break
			}
		}
		maxBookCount = Max(maxBookCount, bookCount)
	}
	out <- S(maxBookCount)

	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ReadString() string {
	in.Scan()
	return in.Text()
}

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

func ReadInt() int {
	intStr := ReadString()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64() int64 {
	intStr := ReadString()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Max(args ...int64) int64 {
	maxV := int64(math.MinInt64)
	for _, v := range args {
		if v > maxV {
			maxV = v
		}
	}
	return maxV
}

func Min(args ...int64) int64 {
	minV := int64(math.MaxInt64)
	for _, v := range args {
		if v < minV {
			minV = v
		}
	}
	return minV
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

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

func S(v int64) string {
	return strconv.FormatInt(v, 10)
}

package main

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

func main() {
	n, t := ReadInt(), ReadInt()
	a := ReadInt64Slice(n)

	out <- S(solve(int64(n), int64(t), a))
	close(out)
	outWg.Wait()
}

//L = 1;
//for (; R<=N; )
//{
//if (Sum<=M && Ans<R-L+1)
//Ans = R-L+1;
//
//if (Sum<M)
//{
//R++; Sum+=A[R];
//}
//else
//{
//Sum-=A[L];
//L++;
//}
//}
func solve(n, t int64, a []int64) int64 {

	start := int64(0)
	max := int64(0)
	sum := int64(0)

	for i := int64(0); i < int64(n); i++ {
		if (i-start+1) > max && sum <= t {
			max = i - start + 1
		}

		if sum > t {
			sum -= a[start]
			start += 1
		} else {
			sum += a[i]
		}

	}
	return max
}
func main1() {
	n, t := ReadInt(), int64(ReadInt())
	a := ReadInt64Slice(n)

	maxBookCount := int64(0)
	for i := 0; i < n; i++ {
		bookCount := int64(0)
		timeLeft := t
		for j := i; timeLeft > 0 && j < n; j++ {
			if a[j] <= timeLeft {
				bookCount++
				timeLeft -= a[j]
			} else {
				break
			}
		}
		maxBookCount = Max(maxBookCount, bookCount)
	}
	out <- S(maxBookCount)

	close(out)
	outWg.Wait()
}

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

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ReadString() string {
	in.Scan()
	return in.Text()
}

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

func ReadInt() int {
	intStr := ReadString()
	i, err := strconv.Atoi(intStr)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64() int64 {
	intStr := ReadString()
	i, err := strconv.ParseInt(intStr, 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func ReadInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ReadInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func Max(args ...int64) int64 {
	maxV := int64(math.MinInt64)
	for _, v := range args {
		if v > maxV {
			maxV = v
		}
	}
	return maxV
}

func Min(args ...int64) int64 {
	minV := int64(math.MaxInt64)
	for _, v := range args {
		if v < minV {
			minV = v
		}
	}
	return minV
}

func GCD(a, b int64) int64 {
	if (a == 0) {
		return b
	}
	return GCD(b%a, a)
}

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

func S(v int64) string {
	return strconv.FormatInt(v, 10)
}

//http://codeforces.com/problemset/problem/279/B

package main

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

func main() {
	reader := NewStdReader(os.Stdin)

	n, t := reader.ReadInt(), reader.ReadInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = reader.ReadInt()
	}

	sort.Ints(a)
	sum := 0
	for i := 0; i < n; i++ {
		sum += a[i]
		if sum > t {
			fmt.Print(i)
			return
		}
	}

	fmt.Print(n)
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 10*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}


Cool J has recently become a businessman Mr. Jackson, and he has to make a lot of phone calls now. Today he has n calls planned. For each call we know the moment ti (in seconds since the start of the day) when it is scheduled to start and its duration di (in seconds). All ti are different. Mr. Jackson is a very important person, so he never dials anybody himself, all calls will be incoming.Mr. Jackson isn't Caesar and he can't do several things at once. If somebody calls him while he hasn't finished the previous conversation, Mr. Jackson puts the new call on hold in the queue. In this case immediately after the end of the current call Mr. Jackson takes the earliest incoming call from the queue and starts the conversation. If Mr. Jackson started the call at the second t, and the call continues for d seconds, then Mr. Jackson is busy at seconds t, t + 1, ..., t + d - 1, and he can start a new call at second t + d. Note that if Mr. Jackson is not busy talking when somebody calls, he can't put this call on hold.Mr. Jackson isn't Napoleon either, he likes to sleep. So sometimes he allows himself the luxury of ignoring a call, as if it never was scheduled. He can ignore at most k calls. Note that a call which comes while he is busy talking can be ignored as well.What is the maximum number of seconds Mr. Jackson can sleep today, assuming that he can choose an arbitrary continuous time segment from the current day (that is, with seconds from the 1-st to the 86400-th, inclusive) when he is not busy talking?Note that some calls can be continued or postponed to the next day or even later. However, the interval for sleep should be completely within the current day.

The first input line contains a pair of integers n, k (0 ≤ k ≤ n ≤ 4000) separated by a space. Following n lines contain the description of calls for today. The description of each call is located on the single line and consists of two space-separated integers ti and di, (1 ≤ ti, di ≤ 86400). All ti are distinct, the calls are given in the order of strict increasing ti. Scheduled times of calls [ti, ti + di - 1] can arbitrarily intersect.

Print a number from 0 to 86400, inclusive — the maximally possible number of seconds for Mr. Jackson to sleep today.

NoteIn the first sample the most convenient way is to ignore the first two calls.In the second sample it is best to ignore the third call. In this case Mr. Jackson will have been speaking:  first call: from 1-st to 20000-th second,  second call: from 20001-st to 30000-th second,  fourth call: from 30001-st to 40000-th second (the third call is ignored),  fifth call: from 80000-th to 139999-th second. Thus, the longest period of free time is from the 40001-th to the 79999-th second.

package main

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

var in = bufio.NewScanner(os.Stdin)
var t, d [4010]int
var f [4010][4010]int
var n, k, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n, k = readInt(), readInt()

  for i := 1; i <= n; i++ {
    t[i], d[i] = readInt(), readInt()
  }

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

  t[n+1] = 86401

  for i := 1; i <= n; i++ {
    for j := 0; j <= n; j++ {
      f[i][j] = int(math.Max(float64(f[i-1][j]), float64(t[i]))) + d[i]
      if j != 0 {
        f[i][j] = int(math.Min(float64(f[i][j]), float64(f[i-1][j-1])))
      }
    }
  }

  for i := 1; i <= n+1; i++ {
    max = int(math.Max(float64(max), float64(t[i]-f[i-1][k])))
  }

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

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var td [4001][4]int
var n, k, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n, k = readInt(), readInt()

  if n-k == 0 {
    fmt.Printf("86400\n")
    return
  }

  for i := 0; i < n; i++ {
    td[i][0], td[i][1], td[i][2], td[i][3] = readInt(), readInt(), 0, 0
  }

  getFreeTime(-1, -1, n-k, -1)

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

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

func getFreeTime(m int, s int, limit int, p int) int {
  if p != -1 {
    if td[m][0]+td[m][1] < td[p][2] {
      return -1
    }

    td[m][3] = td[p][3]
    if td[m][0] > td[p][2] {
      td[m][2] = td[m][0] + td[m][1]
      td[m][3] += td[m][0] - td[p][2] - 1
    } else {
      td[m][2] = td[p][2] + td[m][1]
    }
  }

  for i := m + 1; i < n && n-i >= limit-s-1; i++ {
    //fmt.Printf("m:%d, s:%d, limit:%d, p:%d\n", m, s, limit, p)
    if m == -1 {
      if td[i][0] == 1 {
        td[i][2] = td[i][1]
      } else {
        td[i][2] = td[i][0] + td[i][1]
      }
      td[i][3] = td[i][0] - 1
    }
    ret := getFreeTime(i, s+1, limit, m)
    max = int(math.Max(float64(max), float64(ret)))
  }

  if m != -1 {
    return td[m][3]
  }

  return -1
}

 package main

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

 var in = bufio.NewScanner(os.Stdin)
 var td [4001][4]int
 var n, k, max int

 func init() {
   in.Split(bufio.ScanWords)
 }

 func main() {
   n, k = readInt(), readInt()

   if n == 0 && k == 0 {
     fmt.Printf("86400\n")
     return
   }

   for i := 0; i < n; i++ {
     td[i][0], td[i][1], td[i][2], td[i][3] = readInt(), readInt(), 0, 0
   }

   getFreeTime(-1, -1, n-k, -1)

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

 func readInt() int {
   in.Scan()
   n, _ := strconv.Atoi(in.Text())
   return n
 }

 func getFreeTime(m int, s int, limit int, p int) int {
   if p != -1 {
     if td[m][0]+td[m][1] < td[p][2] {
       return -1
     }

     td[m][3] = td[p][3]
     if td[m][0] > td[p][2] {
       td[m][2] = td[m][0] + td[m][1]
       td[m][3] += td[m][0] - td[p][2] - 1
     } else {
       td[m][2] = td[p][2] + td[m][1]
     }
   }

   for i := m + 1; i < n && n-i >= limit-s-1; i++ {
     //fmt.Printf("m:%d, s:%d, limit:%d, p:%d\n", m, s, limit, p)
     if m == -1 {
       if td[i][0] == 1 {
         td[i][2] = td[i][1]
       } else {
         td[i][2] = td[i][0] + td[i][1]
       }
       td[i][3] = td[i][0] - 1
     }
     ret := getFreeTime(i, s+1, limit, m)
         max = int(math.Max(float64(max), float64(ret)))
  }

  if m != -1 {
    return td[m][3]
  }

  return -1
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var td [4001][4]int
var n, k, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n, k = readInt(), readInt()

  if n-k == 0 {
    fmt.Printf("86400\n")
    return
  }

  for i := 0; i < n; i++ {
    td[i][0], td[i][1], td[i][2], td[i][3] = readInt(), readInt(), 0, 0
  }

  getFreeTime(-1, -1, n-k, -1)

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

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

func getFreeTime(m int, s int, limit int, p int) int {
  if p != -1 {
    if td[m][0]+td[m][1] < td[p][2] {
      return -1
    }

    if td[m][0] > td[p][2] {
      td[m][2] = td[m][0] + td[m][1]
      td[m][3] = td[m][0] - td[p][2] - 1
    } else {
      td[m][2] = td[p][2] + td[m][1]
      td[m][3] = 0
    }
  }

  for i := m + 1; i < n && n-i >= limit-s-1; i++ {
    if m == -1 {
      if td[i][0] == 1 {
        td[i][2] = td[i][1]
      } else {
        td[i][2] = td[i][0] + td[i][1]
      }
      td[i][3] = td[i][0] - 1
    }
    ret := getFreeTime(i, s+1, limit, m)
    max = int(math.Max(float64(max), float64(ret)))
  }

  if m != -1 {
    return td[m][3]
  }

  return -1
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var t, d [4010]int
var f [4010][4010]int
var n, k, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n, k = readInt(), readInt()

  for i := 1; i <= n; i++ {
    t[i], d[i] = readInt(), readInt()
  }

  t[n+1], max = 86401, t[1]-1

  for i := 1; i <= n; i++ {
    for j := 0; j <= k; j++ {
      f[i][j] = int(math.Max(float64(f[i-1][j]), float64(t[i]-1))) + d[i]
      if j != 0 {
        f[i][j] = int(math.Min(float64(f[i][j]), float64(f[i-1][j-1])))
      }
      max = int(math.Max(float64(max), float64(t[i+1]-1-f[i][j])))
    }
  }

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

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var td [4001][4]int
var n, k, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n, k = readInt(), readInt()

  for i := 0; i < n; i++ {
    td[i][0], td[i][1], td[i][2], td[i][3] = readInt(), readInt(), 0, 0
  }

  getFreeTime(-1, -1, n-k, -1)

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

func readInt() int {
  in.Scan()
  n, _ := strconv.Atoi(in.Text())
  return n
}

func getFreeTime(m int, s int, limit int, p int) int {
  if p != -1 {
    if td[m][0]+td[m][1] < td[p][2] {
      return -1
    }

    td[m][3] = td[p][3]
    if td[m][0] > td[p][2] {
      td[m][2] = td[m][0] + td[m][1]
      td[m][3] += td[m][0] - td[p][2] - 1
    } else {
      td[m][2] = td[p][2] + td[m][1]
    }
  }

  for i := m + 1; i < n && n-i >= limit-s-1; i++ {
    //fmt.Printf("m:%d, s:%d, limit:%d, p:%d\n", m, s, limit, p)
    if m == -1 {
      if td[i][0] == 1 {
        td[i][2] = td[i][1]
      } else {
        td[i][2] = td[i][0] + td[i][1]
      }
      td[i][3] = td[i][0] - 1
    }
    ret := getFreeTime(i, s+1, limit, m)
    max = int(math.Max(float64(max), float64(ret)))
  }

  if m != -1 {
    return td[m][3]
  }

  return -1
}


You are given a non-empty string $$$s=s_1s_2\dots s_n$$$, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string $$$s$$$ if there is an integer $$$j$$$ ($$$1 \le j \le n-2$$$), that $$$s_{j}s_{j+1}s_{j+2}=$$$"one" or $$$s_{j}s_{j+1}s_{j+2}=$$$"two".For example:  Polycarp does not like strings "oneee", "ontwow", "twone" and "oneonetwo" (they all have at least one substring "one" or "two"),  Polycarp likes strings "oonnee", "twwwo" and "twnoe" (they have no substrings "one" and "two"). Polycarp wants to select a certain set of indices (positions) and remove all letters on these positions. All removals are made at the same time.For example, if the string looks like $$$s=$$$"onetwone", then if Polycarp selects two indices $$$3$$$ and $$$6$$$, then "onetwone" will be selected and the result is "ontwne".What is the minimum number of indices (positions) that Polycarp needs to select to make the string liked? What should these positions be?

The first line of the input contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Next, the test cases are given. Each test case consists of one non-empty string $$$s$$$. Its length does not exceed $$$1.5\cdot10^5$$$. The string $$$s$$$ consists only of lowercase Latin letters. It is guaranteed that the sum of lengths of all lines for all input data in the test does not exceed $$$1.5\cdot10^6$$$.

Print an answer for each test case in the input in order of their appearance. The first line of each answer should contain $$$r$$$ ($$$0 \le r \le |s|$$$) — the required minimum number of positions to be removed, where $$$|s|$$$ is the length of the given line. The second line of each answer should contain $$$r$$$ different integers — the indices themselves for removal in any order. Indices are numbered from left to right from $$$1$$$ to the length of the string. If $$$r=0$$$, then the second line can be skipped (or you can print empty). If there are several answers, print any of them.

10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo

NoteIn the first example, answers are:  "onetwone",  "testme" — Polycarp likes it, there is nothing to remove,  "oneoneone",  "twotwo". In the second example, answers are:   "onetwonetwooneooonetwooo",  "two",  "one",  "twooooo",  "ttttwo",  "ttwwoo" — Polycarp likes it, there is nothing to remove,  "ooone",  "onnne" — Polycarp likes it, there is nothing to remove,  "oneeeee",  "oneeeeeeetwooooo".

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 t int
var S []rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	n := len(S)
	oneTopIdx := []int{}
	for i := 0; i < n-2; i++ {
		str := S[i : i+3]
		if string(str) == "one" {
			oneTopIdx = append(oneTopIdx, i)
		}
	}
	twoBtmIdx := []int{}
	for i := 0; i < n-2; i++ {
		str := S[i : i+3]
		if string(str) == "two" {
			twoBtmIdx = append(twoBtmIdx, i+2)
		}
	}

	memo := make(map[int]int)
	for _, idx := range oneTopIdx {
		memo[idx]++
	}
	for _, idx := range twoBtmIdx {
		memo[idx]++
	}

	answers := []int{}
	for _, idx := range oneTopIdx {
		if memo[idx] == 2 {
			answers = append(answers, idx+1)
		} else {
			answers = append(answers, idx+1+1)
		}
	}
	for _, idx := range twoBtmIdx {
		if memo[idx] == 2 {
			continue
		} else {
			answers = append(answers, idx+1-1)
		}
	}

	fmt.Println(len(answers))
	fmt.Println(PrintIntsLine(answers...))
}

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

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

package main

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

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

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

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		b := readb()
		p := solve(b)
		println(len(p))
		sp := ""
		for _, v := range p {
			printf("%s%d", sp, v+1)
			sp = " "
		}
		println()
	}
}

func solve(s []byte) []int {
	n := len(s)

	ban := []string{"twone", "one", "two"}
	bani := []int{2, 1, 1}

	var ans []int
	for i := 0; i < n; i++ {
		for k, b := range ban {
			j := min(i+len(b), n)
			if string(s[i:j]) == b {
				s[i+bani[k]] = '_'
				ans = append(ans, i+bani[k])
				break
			}
		}
	}
	return 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 t int
var S []rune

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		S = ReadRuneSlice()

		solve()
	}
}

func solve() {
	n := len(S)
	oneTopIdx := []int{}
	for i := 0; i < n-2; i++ {
		str := S[i : i+3]
		if string(str) == "one" {
			oneTopIdx = append(oneTopIdx, i)
		}
	}
	twoBtmIdx := []int{}
	for i := 0; i < n-2; i++ {
		str := S[i : i+3]
		if string(str) == "two" {
			twoBtmIdx = append(twoBtmIdx, i+2)
		}
	}

	memo := make(map[int]int)
	for _, idx := range oneTopIdx {
		memo[idx] = 1
	}
	for _, idx := range twoBtmIdx {
		memo[idx] = 1
	}

	answers := []int{}
	for k := range memo {
		answers = append(answers, k+1)
	}

	fmt.Println(len(answers))
	fmt.Println(PrintIntsLine(answers...))
}

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

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

package main

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

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

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

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		b := readb()
		p := solve(b)
		println(len(p))
		sp := ""
		for _, v := range p {
			printf("%s%d", sp, v)
			sp = " "
		}
		println()
	}
}

func solve(s []byte) []int {
	n := len(s)

	ban := []string{"twone", "one", "two"}
	bani := []int{2, 1, 1}

	var ans []int
	for i := 0; i < n; i++ {
		for k, b := range ban {
			j := min(i+len(b), n)
			if string(s[i:j]) == b {
				s[i+bani[k]] = '_'
				ans = append(ans, i+bani[k])
				break
			}
		}
	}
	return ans
}


Owl Sonya gave a huge lake puzzle of size n × m to hedgehog Filya as a birthday present. Friends immediately started to assemble the puzzle, but some parts of it turned out to be empty — there was no picture on them. Parts with picture on it are denoted by 1, while empty parts are denoted by 0. Rows of the puzzle are numbered from top to bottom with integers from 1 to n, while columns are numbered from left to right with integers from 1 to m.Animals decided to complete the picture and play with it, as it might be even more fun! Owl and hedgehog ask each other some queries. Each query is provided by four integers x1, y1, x2, y2 which define the rectangle, where (x1, y1) stands for the coordinates of the up left cell of the rectangle, while (x2, y2) stands for the coordinates of the bottom right cell. The answer to the query is the size of the maximum square consisting of picture parts only (only parts denoted by 1) and located fully inside the query rectangle.Help Sonya and Filya answer t queries.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 1000) — sizes of the puzzle. Each of the following n lines contains m integers aij. Each of them is equal to 1 if the corresponding cell contains a picture and 0 if it's empty. Next line contains an integer t (1 ≤ t ≤ 1 000 000) — the number of queries. Then follow t lines with queries' descriptions. Each of them contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ n, 1 ≤ y1 ≤ y2 ≤ m) — coordinates of the up left and bottom right cells of the query rectangle.

Print t lines. The i-th of them should contain the maximum size of the square consisting of 1-s and lying fully inside the query rectangle.

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/pprof"
)

var stdin *bufio.Reader
var stdout *bufio.Writer
var n int
var m int
var a [1000][1000]int8
// square[i][j] is the max square length starting from i, j.
var square[1001][1001]int16
// 2D sparse table
// maxRange[jr][ir][jc][ic] means the max value in range square[ir - (ir + 2^jr - 1)][ic - (ic + 2^jc - 1)].
var maxRange [10][1000][10][1000]int16

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func printf(format string, arg ...interface{}) {
	fmt.Fprintf(stdout, format, arg...)
}

func scan(arg ...interface{}) (int, error) {
	return fmt.Fscan(stdin, arg...)
}

var show bool

func Max(args ...interface{}) int {
	res := 0
	/*
	if show {
		printf("Max(")
	}
	*/
	for i, v := range args {
		value := IntegerToInt(v)
		/*
		if show {
			printf("%d ", value)
		}
		*/
		if i == 0 {
			res = value
		} else if (res < value) {
			res = value
		}
	}
	/*
	if show {
		printf(") = %d\n", res)
	}
	*/
	return res
}

func MaxInt16(args ...int16) int16 {
	res := int16(0)
	for i, v := range args {
		if i == 0 {
			res = v
		} else if (res < v) {
			res = v
		}
	}
	return res
}

func IntegerToInt(v interface{}) int {
	switch t := v.(type) {
	case int:
		return int(t)
	case int16:
		return int(t)
	}
	return 0
}

func Min(args ...interface{}) int {
	res := 0
	for i, v := range args {
		value := IntegerToInt(v)
		if i == 0 {
			res = value
		} else if (res > value) {
			res = value
		}
	}
	return res
}

func findMaxSize(x1, x2, y1, y2 int) int {
	length := Min(x2 - x1 + 1, y2 - y1 + 1)
	low := 0
	high := length
	for low + 1 < high {
		mid := (low + high) / 2
		if canFit(x1, x2, y1, y2, mid) {
			low = mid
		} else {
			high = mid - 1
		}
	}
	if high > low && canFit(x1, x2, y1, y2, high) {
		return high
	}
	return low
}

func canFit(x1, x2, y1, y2, length int) bool {
	x2 -= length - 1
	y2 -= length - 1
	t := findRangeMax(x1, x2, y1, y2)
	//printf("try length %d, x1 %d, x2 %d, y1 %d, y2 %d, t %d\n", length, x1, x2, y1, y2, t)
	return t >= length
}

func findRangeMax(x1, x2, y1, y2 int) int {
	lenX := x2 - x1 + 1
	lenY := y2 - y1 + 1
	var jr uint = log2(lenX)
	var jc uint = log2(lenY)
	//printf("jr %d, jc %d, x1 %d, x2 %d y1 %d y2 %d", jr, jc, x1, x2, y1, y2)
	//stdout.Flush()
	//show = true
	res := MaxInt16(maxRange[jr][x1][jc][y1], maxRange[jr][x2-(1<<jr)+1][jc][y1],
			   maxRange[jr][x1][jc][y2-(1<<jc)+1], maxRange[jr][x2-(1<<jr)+1][jc][y2-(1<<jc)+1])
	//printf("maxRange[%d][%d][%d][%d] = %d\n", jr, x1, jc, y1, maxRange[jr][x1][jc][y1])
	//show = false
	return int(res)
}

func log2(value int) uint {
	var level uint = 0
	for k := 1; k * 2 <= value; k *= 2 {
		level++
	}
	return level
}

func preprocess() {
	maxJr := log2(n)
	maxJc := log2(m)
	for ir := 0; ir < n; ir++ {
		for ic := 0; ic < m; ic++ {
			maxRange[0][ir][0][ic] = square[ir][ic]
		}
		for jc := uint(1); jc <= maxJc; jc++ {
			for ic := 0; ic < m; ic++ {
				t := maxRange[0][ir][jc-1][ic]
				if ic + (1 << (jc-1)) < m {
					t = int16(MaxInt16(t, maxRange[0][ir][jc-1][ic+(1<<(jc-1))]))
				}
				maxRange[0][ir][jc][ic] = t
			}
		}
	}
	//printf("preprocess, maxJr %d, maxJc = %d\n", maxJr, maxJc)

	for jr := uint(1); jr <= maxJr; jr++ {
		for ir := 0; ir < n; ir++ {
			for jc := uint(0); jc <= maxJc; jc++ {
				for ic := 0; ic < m; ic++ {
					t := maxRange[jr-1][ir][jc][ic]
					if ir + (1<<(jr-1)) < n {
						t = int16(MaxInt16(t, maxRange[jr-1][ir+(1<<(jr-1))][jc][ic]))
					}
					maxRange[jr][ir][jc][ic] = t
				}
			}
		}
	}
}

func main() {
	f, _ := os.Create("profile")
	pprof.StartCPUProfile(f)
	defer f.Close()
	defer pprof.StopCPUProfile()
	for true {
		if _, err := scan(&n, &m); err != nil {
			break
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				scan(&a[i][j])
			}
		}
		//printf("n = %d, m = %d\n", n, m)
		for j := 0; j <= m; j++ {
			square[n][j] = 0
		}
		for i := 0; i <= n; i++ {
			square[i][m] = 0
		}
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if a[i][j] == 0 {
					square[i][j] = 0
				} else {
					square[i][j] = int16(Min(square[i+1][j], square[i][j+1], square[i+1][j+1]) + 1)
				}
				//printf("%d (%d, %d, %d,%d,%d)", i, j, square[i][j], square[i+1][j], square[i][j+1], square[i+1][j+1])
			}
			//printf("\n")
		}
		/*
		printf("square\n")
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				printf("%d ", square[i][j])
			}
			printf("\n")
		}
		*/
		preprocess()
		var queries int
		scan(&queries)
		for q := 0; q < queries; q++ {
			var x1, y1, x2, y2 int
			scan(&x1, &y1, &x2, &y2)
			x1--
			y1--
			x2--
			y2--
			res := findMaxSize(x1, x2, y1, y2)
			printf("%d\n", res)
		}
    	stdout.Flush()
	}
}

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer
var n int
var m int
var a [1000][1000]int8
// square[i][j] is the max square length starting from i, j.
var square[1000][1000]int16
// 2D sparse table
// maxRange[jr][ir][jc][ic] means the max value in range square[ir - (ir + 2^jr - 1)][ic - (ic + 2^jc - 1)].
var maxRange [10][1000][10][1000]int16

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func printf(format string, arg ...interface{}) {
	fmt.Fprintf(stdout, format, arg...)
}

func scan(arg ...interface{}) (int, error) {
	return fmt.Fscan(stdin, arg...)
}

func Max(args ...interface{}) int {
	res := 0
	for i, v := range args {
		value := IntegerToInt(v)
		if i == 0 {
			res = value
		} else if (res < value) {
			res = value
		}
	}
	return res
}

func IntegerToInt(v interface{}) int {
	switch t := v.(type) {
	case int:
		return int(t)
	case int16:
		return int(t)
	}
	return 0
}

func Min(args ...interface{}) int {
	res := 0
	for i, v := range args {
		value := IntegerToInt(v)
		if i == 0 {
			res = value
		} else if (res > value) {
			res = value
		}
	}
	return res
}

func findMaxSize(x1, x2, y1, y2 int) int {
	length := Min(x2 - x1 + 1, y2 - y1 + 1)
	low := 0
	high := length
	for low + 1 < high {
		mid := (low + high) / 2
		if canFit(x1, x2, y1, y2, mid) {
			low = mid
		} else {
			high = mid - 1
		}
	}
	if high > low && canFit(x1, x2, y1, y2, high) {
		return high
	}
	return low
}

func canFit(x1, x2, y1, y2, length int) bool {
	x2 -= length - 1
	y2 -= length - 1
	return findRangeMax(x1, x2, y1, y2) >= length
}

func findRangeMax(x1, x2, y1, y2 int) int {
	lenX := x2 - x1 + 1
	lenY := y2 - y1 + 1
	var jr uint = log2(lenX)
	var jc uint = log2(lenY)
	//printf("jr %d, jc %d, x1 %d, x2 %d y1 %d y2 %d", jr, jc, x1, x2, y1, y2)
	stdout.Flush()
	return Max(maxRange[jr][x1][jc][y1], maxRange[jr][x2-(1<<jr)+1][jc][y1],
			   maxRange[jr][x1][jc][y2-(1<<jc)+1], maxRange[jr][x2-(1<<jr)+1][jc][y2-(1<<jc)+1])
}

func log2(value int) uint {
	var level uint = 0
	for k := 1; k * 2 <= value; k *= 2 {
		level++
	}
	return level
}

func preprocess() {
	maxJr := log2(n)
	maxJc := log2(m)
	for ir := 0; ir < n; ir++ {
		for ic := 0; ic < m; ic++ {
			maxRange[0][ir][0][ic] = square[ir][ic]
		}
		for jc := uint(1); jc <= maxJc; jc++ {
			for ic := 0; ic < m; ic++ {
				maxRange[0][ir][jc][ic] = int16(Max(maxRange[0][ir][jc-1][ic], maxRange[0][ir][jc-1][ic+(1<<(jc-1))]))
			}
		}
	}

	for jr := uint(1); jr <= maxJr; jr++ {
		for ir := 0; ir < n; ir++ {
			for jc := uint(1); jc <= maxJc; jc++ {
				for ic := 0; ic < m; ic++ {
					maxRange[jr][ir][jc][ic] = int16(Max(maxRange[jr-1][ir][jc][ic], maxRange[jr-1][ir+(1<<(jr-1))][jc][ic]))
				}
			}
		}
	}
}

func main() {
	for true {
		if _, err := scan(&n, &m); err != nil {
			break
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				scan(&a[i][j])
			}
		}
		for i := n - 1; i >= 0; i-- {
			for j := m - 1; j >= 0; j-- {
				if a[i][j] == 0 {
					square[i][j] = 0
				} else {
					square[i][j] = int16(Min(square[i+1][j], square[i][j+1], square[i+1][j+1]) + 1)
				}
			}
		}
		preprocess()
		var queries int
		scan(&queries)
		for q := 0; q < queries; q++ {
			var x1, y1, x2, y2 int
			scan(&x1, &y1, &x2, &y2)
			x1--
			y1--
			x2--
			y2--
			res := findMaxSize(x1, x2, y1, y2)
			printf("%d\n", res)
		}
    	stdout.Flush()
	}
}


The brave Knight came to the King and asked permission to marry the princess. The King knew that the Knight was brave, but he also wanted to know if he was smart enough. So he asked him to solve the following task.There is a permutation $$$p_i$$$ of numbers from 1 to $$$2n$$$. You can make two types of operations.   Swap $$$p_1$$$ and $$$p_2$$$, $$$p_3$$$ and $$$p_4$$$, ..., $$$p_{2n-1}$$$ and $$$p_{2n}$$$.  Swap $$$p_1$$$ and $$$p_{n+1}$$$, $$$p_2$$$ and $$$p_{n+2}$$$, ..., $$$p_{n}$$$ and $$$p_{2n}$$$. The task is to find the minimal number of operations required to sort the given permutation.The Knight was not that smart actually, but quite charming, so the princess asks you to help him to solve the King's task.

The first line contains the integer $$$n$$$ ($$$1\le n\le 1000$$$). The second line contains $$$2n$$$ integers $$$p_i$$$ — the permutation of numbers from 1 to $$$2n$$$.

Print one integer — the minimal number of operations required to sort the permutation. If it is impossible to sort the permutation using these operations, print $$$-1$$$.

NoteIn the first example, you can sort the permutation in three operations:   Make operation 1: $$$3, 6, 5, 2, 1, 4$$$.  Make operation 2: $$$2, 1, 4, 3, 6, 5$$$.  Make operation 1: $$$1, 2, 3, 4, 5, 6$$$.

package main

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

func swap(p []int, n int) {
	for i := 0; i < 2*n; i += 2 {
		tmp := p[i]
		p[i] = p[i+1]
		p[i+1] = tmp
	}
}

func shift(p []int, n int) {
	for i := 0; i < n; i++ {
		tmp := p[i]
		p[i] = p[n+i]
		p[n+i] = tmp
	}
}

func cmp(p []int, a []int) bool {
	res := true
	for i := range p {
		if p[i] != a[i] {
			res = false
			break
		}
	}
	return res
}

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

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

	a := make([]int, 2*n)
	p := make([]int, 2*n)

	for i := 1; i <= 2*n; i++ {
		fmt.Fscan(r, &a[i-1])
		p[i-1] = i
	}

	N := 2*n
	if n % 2 == 0 { N = 4 }

	var c int
	for ; c < N && !cmp(p, a); c++ {
		if c % 2 == 0 {
			swap(p, n)
		} else {
			shift(p, n)
		}
	}

	if c < N {
		if c > N - c { c = N - c }
		fmt.Fprintln(w, c)
	} else {
		fmt.Fprintln(w, -1)
	}
}

package main

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

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

	var n, v int
	Fscan(in, &n)
	n *= 2
	const mx int = 2000
	st := [mx]int{}
	for i := 0; i < n; i++ {
		st[i] = i
	}
	ans := map[[mx]int]int{st: 0}
	q := [][mx]int{st}
	for d := 0; len(q) > 0; d++ {
		tmp := q
		q = nil
		for _, a := range tmp {
			b := a
			for i := 0; i < n; i += 2 {
				b[i], b[i+1] = b[i+1], b[i]
			}
			if _, has := ans[b]; !has {
				ans[b] = d + 1
				q = append(q, b)
			}
			b = [mx]int{}
			for i := 0; i < n/2; i++ {
				b[i+n/2] = a[i]
				b[i] = a[i+n/2]
			}
			if _, has := ans[b]; !has {
				ans[b] = d + 1
				q = append(q, b)
			}
		}
	}

	a := [mx]int{}
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		a[i] = v - 1
	}

	res, has := ans[a]
	if !has {
		Fprintln(out, -1)
	} else {
		Fprintln(out, res)
	}
}

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

package main

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

const N int = 2000

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

	var n int
	Fscan(in, &n)

	a := [N]int{}
	for i := 0; i < 2*n; i++ {
		Fscan(in, &a[i])
	}

	isSorted := func(a *[N]int, n int) bool {
		for i := 0; i < 2*n-1; i++ {
			if a[i] > a[i+1] {
				return false
			}
		}
		return true
	}

	if isSorted(&a, n) {
		Fprintln(out, 0)
		return
	}

	// Try everything
	a1 := a
	lastMove := false
	move1 := 0
	isDoable := false
	for {
		move(&a1, n, lastMove)
		// Fprintln(out, a1)
		move1++
		lastMove = !lastMove
		if isSorted(&a1, n) {
			isDoable = true
			break
		}
		if a1 == a {
			break
		}
	}
	if !isDoable {
		Fprintln(out, -1)
		return
	}

	// Try other way to see if it is faster
	a2 := a
	lastMove = true
	move2 := 0
	// Fprintln(out)
	for {
		move(&a2, n, lastMove)
		// Fprintln(out, a2)
		move2++
		lastMove = !lastMove
		if isSorted(&a2, n) {
			isDoable = true
			break
		}
		if a2 == a {
			break
		}
	}

	if move2 < move1 {
		Fprintln(out, move2)
	} else {
		Fprintln(out, move1)
	}

}

func move(a *[N]int, n int, lastMove bool) {
	if lastMove {
		for i := 0; i < n; i++ {
			temp := a[i]
			a[i] = a[n+i]
			a[n+i] = temp
		}
	} else {
		for i := 0; i < 2*n; i += 2 {
			temp := a[i]
			a[i] = a[i+1]
			a[i+1] = temp
		}
	}
}

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

package main

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

func swap(p []int, n int) {
	for i := 0; i < 2*n; i += 2 {
		tmp := p[i]
		p[i] = p[i+1]
		p[i+1] = tmp
	}
}

func shift(p []int, n int) {
	for i := 0; i < n; i++ {
		tmp := p[i]
		p[i] = p[n+i]
		p[n+i] = tmp
	}
}

func cmp(p []int, a []int) bool {
	res := true
	for i := range p {
		if p[i] != a[i] {
			res = false
			break
		}
	}
	return res
}

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

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

	a := make([]int, 2*n)
	p := make([]int, 2*n)

	for i := 1; i <= 2*n; i++ {
		fmt.Fscan(r, &a[i-1])
		p[i-1] = i
	}

	N := 2*n
	if n % 2 == 0 { N = 4 }

	var c int
	for ; c < N-1 && !cmp(p, a); c++ {
		if c % 2 == 0 {
			swap(p, n)
		} else {
			shift(p, n)
		}
	}

	if c < N-1 {
		if c > N - c { c = N - c }
		fmt.Fprintln(w, c)
	} else {
		fmt.Fprintln(w, -1)
	}
}