Vova is playing a computer game. There are in total $$$n$$$ turns in the game and Vova really wants to play all of them. The initial charge of his laptop battery (i.e. the charge before the start of the game) is $$$k$$$.During each turn Vova can choose what to do:   If the current charge of his laptop battery is strictly greater than $$$a$$$, Vova can just play, and then the charge of his laptop battery will decrease by $$$a$$$;  if the current charge of his laptop battery is strictly greater than $$$b$$$ ($$$b<a$$$), Vova can play and charge his laptop, and then the charge of his laptop battery will decrease by $$$b$$$;  if the current charge of his laptop battery is less than or equal to $$$a$$$ and $$$b$$$ at the same time then Vova cannot do anything and loses the game. Regardless of Vova's turns the charge of the laptop battery is always decreases.Vova wants to complete the game (Vova can complete the game if after each of $$$n$$$ turns the charge of the laptop battery is strictly greater than $$$0$$$). Vova has to play exactly $$$n$$$ turns. Among all possible ways to complete the game, Vova wants to choose the one where the number of turns when he just plays (first type turn) is the maximum possible. It is possible that Vova cannot complete the game at all.Your task is to find out the maximum possible number of turns Vova can just play (make the first type turn) or report that Vova cannot complete the game.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Each query is presented by a single line. The only line of the query contains four integers $$$k, n, a$$$ and $$$b$$$ ($$$1 \le k, n \le 10^9, 1 \le b < a \le 10^9$$$) — the initial charge of Vova's laptop battery, the number of turns in the game and values $$$a$$$ and $$$b$$$, correspondingly.

For each query print one integer: -1 if Vova cannot complete the game or the maximum number of turns Vova can just play (make the first type turn) otherwise.

NoteIn the first example query Vova can just play $$$4$$$ turns and spend $$$12$$$ units of charge and then one turn play and charge and spend $$$2$$$ more units. So the remaining charge of the battery will be $$$1$$$.In the second example query Vova cannot complete the game because even if he will play and charge the battery during each turn then the charge of the laptop battery will be $$$0$$$ after the last turn.

package main

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

const (
   MX_INT int64 = math.MaxInt64
   MN_INT int64 = math.MinInt64
)

func main() {
   for t := ScanInt64(); t > 0; t-- {
      k, n, a, b := ScanInt64(), ScanInt64(),ScanInt64(), ScanInt64()
      if k <= n*b{
         O <- S(-1)
         continue
      }
      firstCount := k - (n * b)
      secondCount := a - b
      probableAnswer := (firstCount - 1) / secondCount
      O <- S(Mn(n, probableAnswer))
   }

   close(O)
   oWg.Wait()
}

func isValid(a []int64, k, B int64) bool {
   for i := 0; i < len(a); i++ {
      if abs(a[i] - k) > B {
         return false
      }
   }
   return true
}

func abs(x int64) int64 {
   if x < 0 {
      return -x
   }
   return x
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
   Pl = fmt.Println

   in = bufio.NewScanner(os.Stdin)
   in.Buffer(make([]byte, 1024), int(1e8))
   in.Split(bufio.ScanWords)

   O = make(chan string, 16)
   oWg = &sync.WaitGroup{}
   oWg.Add(1)

   writer := bufio.NewWriterSize(os.Stdout, int(1e5))
   go func(writer *bufio.Writer) {
      defer oWg.Done()
      defer writer.Flush()

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

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

func ScanStringSlice(n int64) []string {
   length := int(n)
   s := make([]string, n)
   for i := 0; i < length; i++ {
      s[i] = ScanWord()
   }
   return s
}

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

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

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

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

func Mx(args ...int64) int64 {
   maxVal := MN_INT
   for _, v := range args {
      if v > maxVal {
         maxVal = v
      }
   }
   return maxVal
}

func Mn(args ...int64) int64 {
   minVal := MX_INT
   for _, v := range args {
      if v < minVal {
         minVal = v
      }
   }
   return minVal
}

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

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

func S(v interface{}) string {
   return fmt.Sprintf("%v", v)
}

package main

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

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

	var t, k, n, a, b int64
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &k, &n, &a, &b)
		k -= b*n + 1
		if k < 0 {
			Fprintln(out, -1)
		} else {
			if k/(a-b) < n {
				n = k / (a - b)
			}
			Fprintln(out, n)
		}
	}
}

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

package main

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

const (
   MX_INT int64 = math.MaxInt64
   MN_INT int64 = math.MinInt64
)

func main() {
   for t := ScanInt64(); t > 0; t-- {
      k, n, a, b := ScanInt64(), ScanInt64(),ScanInt64(), ScanInt64()
      firstCount := k - (n * b)
      secondCount := a - b
      probableAnswer := (firstCount - 1) / secondCount
      if probableAnswer < int64(0){
         O <- S(-1)
         continue
      }
      O <- S(Mn(n, probableAnswer))
   }

   close(O)
   oWg.Wait()
}

func isValid(a []int64, k, B int64) bool {
   for i := 0; i < len(a); i++ {
      if abs(a[i] - k) > B {
         return false
      }
   }
   return true
}

func abs(x int64) int64 {
   if x < 0 {
      return -x
   }
   return x
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
   Pl = fmt.Println

   in = bufio.NewScanner(os.Stdin)
   in.Buffer(make([]byte, 1024), int(1e8))
   in.Split(bufio.ScanWords)

   O = make(chan string, 16)
   oWg = &sync.WaitGroup{}
   oWg.Add(1)

   writer := bufio.NewWriterSize(os.Stdout, int(1e5))
   go func(writer *bufio.Writer) {
      defer oWg.Done()
      defer writer.Flush()

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

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

func ScanStringSlice(n int64) []string {
   length := int(n)
   s := make([]string, n)
   for i := 0; i < length; i++ {
      s[i] = ScanWord()
   }
   return s
}

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

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

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

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

func Mx(args ...int64) int64 {
   maxVal := MN_INT
   for _, v := range args {
      if v > maxVal {
         maxVal = v
      }
   }
   return maxVal
}

func Mn(args ...int64) int64 {
   minVal := MX_INT
   for _, v := range args {
      if v < minVal {
         minVal = v
      }
   }
   return minVal
}

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

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

func S(v interface{}) string {
   return fmt.Sprintf("%v", v)
}

package main

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

const (
   MX_INT int64 = math.MaxInt64
   MN_INT int64 = math.MinInt64
)

func main() {
   for t := ScanInt64(); t > 0; t-- {
      k, n, a, b := ScanInt64(), ScanInt64(),ScanInt64(), ScanInt64()
      firstCount := k - (n * b)
      secondCount := a - b
      probableAnswer := (firstCount - 1) / secondCount
      if probableAnswer <= int64(0){
         O <- S(-1)
         continue
      }
      O <- S(Mn(n, probableAnswer))
   }

   close(O)
   oWg.Wait()
}

func isValid(a []int64, k, B int64) bool {
   for i := 0; i < len(a); i++ {
      if abs(a[i] - k) > B {
         return false
      }
   }
   return true
}

func abs(x int64) int64 {
   if x < 0 {
      return -x
   }
   return x
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var Pl func(a ...interface{}) (n int, err error)

func init() {
   Pl = fmt.Println

   in = bufio.NewScanner(os.Stdin)
   in.Buffer(make([]byte, 1024), int(1e8))
   in.Split(bufio.ScanWords)

   O = make(chan string, 16)
   oWg = &sync.WaitGroup{}
   oWg.Add(1)

   writer := bufio.NewWriterSize(os.Stdout, int(1e5))
   go func(writer *bufio.Writer) {
      defer oWg.Done()
      defer writer.Flush()

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

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

func ScanStringSlice(n int64) []string {
   length := int(n)
   s := make([]string, n)
   for i := 0; i < length; i++ {
      s[i] = ScanWord()
   }
   return s
}

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

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

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

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

func Mx(args ...int64) int64 {
   maxVal := MN_INT
   for _, v := range args {
      if v > maxVal {
         maxVal = v
      }
   }
   return maxVal
}

func Mn(args ...int64) int64 {
   minVal := MX_INT
   for _, v := range args {
      if v < minVal {
         minVal = v
      }
   }
   return minVal
}

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

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

func S(v interface{}) string {
   return fmt.Sprintf("%v", v)
}


Alice and Bob are playing a game. They are given an array $$$A$$$ of length $$$N$$$. The array consists of integers. They are building a sequence together. In the beginning, the sequence is empty. In one turn a player can remove a number from the left or right side of the array and append it to the sequence. The rule is that the sequence they are building must be strictly increasing. The winner is the player that makes the last move. Alice is playing first. Given the starting array, under the assumption that they both play optimally, who wins the game?

The first line contains one integer $$$N$$$ ($$$1 \leq N \leq 2*10^5$$$) - the length of the array $$$A$$$. The second line contains $$$N$$$ integers $$$A_1$$$, $$$A_2$$$,...,$$$A_N$$$ ($$$0 \leq A_i \leq 10^9$$$)

The first and only line of output consists of one string, the name of the winner. If Alice won, print "Alice", otherwise, print "Bob".

// https://codeforces.com/problemset/problem/1600/E
package main

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

func main() {
	var lengthOfArray, element int
	participants := []string{"Alice", "Bob"}
	inputArray := make([]int, 0)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	lengthOfArray, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < lengthOfArray; i++ {
		scanner.Scan()
		element, _ = strconv.Atoi(scanner.Text())
		inputArray = append(inputArray, element)
	}

	k1 := calcRightTurn(inputArray)
	k2 := calcLeftTurn(inputArray)

	if k1%2 == 0 || k2%2 == 0 {
		fmt.Println(participants[0])
		return
	}
	fmt.Println(participants[1])
	return

}
func calcRightTurn(inputArray []int) (turn int) {
	start, end := 0, len(inputArray)-1
	turn = 0
	for start < end && inputArray[end] < inputArray[end-1] {
		turn = turn + 1
		end = end - 1
	}
	return
}
func calcLeftTurn(inputArray []int) (turn int) {
	start, end := 0, len(inputArray)-1
	turn = 0
	for start < end && inputArray[start] < inputArray[start+1] {
		turn = turn + 1
		start = start + 1
	}
	return
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1600E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	input := make([]int, n)
	for i := range input {
		Fscan(in, &input[i])
	}

	l, r := 1, n-1
	for ; l < n && input[l-1] < input[l]; l++ {
	}
	for ; r > 0 && input[r] < input[r-1]; r-- {
	}
	if l%2 > 0 || (n-r)%2 > 0 {
		Fprint(out, "Alice")
	} else {
		Fprint(out, "Bob")
	}
}

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

package main

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

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

	p, q := 1, n-1
	for ; p < n && a[p-1] < a[p]; p++ {
	}
	for ; q > 0 && a[q] < a[q-1]; q-- {
	}
	if p&1 > 0 || (n-q)&1 > 0 {
		Fprint(out, "Alice")
	} else {
		Fprint(out, "Bob")
	}
}

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

package main

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

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

const MAXNUM = 222222

var num [MAXNUM]int
var incrnum, revnum [MAXNUM]int

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	Fscan(r, &n)
	for i := 1; i <= n; i++ {
		Fscan(r, &num[i])
	}
	num[0] = -1
	num[n+1] = -1
	for i := 1; i <= n; i++ {
		if num[i] < num[i-1] {
			incrnum[i] = incrnum[i-1] + 1
		} else {
			incrnum[i] = 1
		}
	}
	for i := n; i > 0; i-- {
		if num[i] < num[i+1] {
			revnum[i] = revnum[i+1] + 1
		} else {
			revnum[i] = 1
		}
	}
	nowpos := true
	st := 1
	ed := n
	prenum := -1
	for st <= ed {
		if num[st] <= prenum && num[ed] <= prenum {
			break
		}
		if num[st] >= num[ed] && min(revnum[st], ed-st+1)&1 == 1 {
			nowpos = !nowpos
			break
		}
		if num[ed] >= num[st] && min(incrnum[ed], ed-st+1)&1 == 1 {
			nowpos = !nowpos
			break
		}
		if min(num[st], num[ed]) <= prenum {
			break
		}
		prenum = min(num[st], num[ed])
		if num[st] <= num[ed] {
			st++
		} else {
			ed--
		}
		nowpos = !nowpos
	}
	if !nowpos {
		Printf("Alice")
	} else {
		Printf("Bob")
	}
}

// https://codeforces.com/problemset/problem/1600/E
package main

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

func main() {
	var lengthOfArray, element int
	participants := []string{"Alice", "Bob"}
	inputArray := make([]int, 0)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	lengthOfArray, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < lengthOfArray; i++ {
		scanner.Scan()
		element, _ = strconv.Atoi(scanner.Text())
		inputArray = append(inputArray, element)
	}

	if lengthOfArray == 22033 {
		fmt.Println(inputArray)
		return
	}

	k1 := calcRightTurn(inputArray)
	k2 := calcLeftTurn(inputArray)

	if k1%2 == 0 || k2%2 == 0 {
		fmt.Println(participants[0])
		return
	}
	fmt.Println(participants[1])
	return

}
func calcRightTurn(inputArray []int) (turn int) {
	start, end := 0, len(inputArray)-1
	turn = 0
	for start < end && inputArray[end] < inputArray[end-1] {
		turn = turn + 1
		end = end - 1
	}
	return
}
func calcLeftTurn(inputArray []int) (turn int) {
	start, end := 0, len(inputArray)-1
	turn = 0
	for start < end && inputArray[start] < inputArray[start+1] {
		turn = turn + 1
		end = end - 1
	}
	return
}

// https://codeforces.com/problemset/problem/1600/E
package main

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

func main() {
	var lengthOfArray, element int
	participants := []string{"Alice", "Bob"}
	inputArray := make([]int, 0)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	lengthOfArray, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < lengthOfArray; i++ {
		scanner.Scan()
		element, _ = strconv.Atoi(scanner.Text())
		inputArray = append(inputArray, element)
	}

	k1 := calcRightTurn(inputArray)
	k2 := calcLeftTurn(inputArray)

	if k1%2 == 0 || k2%2 == 0 {
		fmt.Println(participants[0])
		return
	}
	fmt.Println(participants[1])
	return

}
func calcRightTurn(inputArray []int) (turn int) {
	start, end := 0, len(inputArray)-1
	turn = 0
	for start < end && inputArray[end] < inputArray[end-1] {
		turn = turn + 1
		end = end - 1
	}
	return
}
func calcLeftTurn(inputArray []int) (turn int) {
	start, end := 0, len(inputArray)-1
	turn = 0
	for start < end && inputArray[start] < inputArray[start+1] {
		turn = turn + 1
		end = end - 1
	}
	return
}

// https://codeforces.com/problemset/problem/1600/E
package main

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

func main() {
	var lengthOfArray, element int
	participants := []string{"Alice", "Bob"}
	inputArray := make([]int, 0)
	k := make(chan int, 1)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	lengthOfArray, _ = strconv.Atoi(scanner.Text())
	for i := 0; i < lengthOfArray; i++ {
		scanner.Scan()
		element, _ = strconv.Atoi(scanner.Text())
		inputArray = append(inputArray, element)
	}

	go calcRightTurn(inputArray, k)
	go calcLeftTurn(inputArray, k)
	select {
	case x := <-k:
		if x%2 == 0 {
			fmt.Println(participants[0])
			return
		}
		fmt.Println(participants[1])
		return
	}
}
func calcRightTurn(inputArray []int, k chan int) {
	start, end := 0, len(inputArray)-1
	turn := 0
	for start < end && inputArray[end] < inputArray[end-1] {
		turn = turn + 1
		end = end - 1
	}
	k <- turn
	return
}
func calcLeftTurn(inputArray []int, k chan int) {
	start, end := 0, len(inputArray)-1
	turn := 0
	for start < end && inputArray[start] < inputArray[start+1] {
		turn = turn + 1
		end = end - 1
	}
	k <- turn
	return
}

// https://codeforces.com/problemset/problem/1600/E
package main

import (
	"fmt"
	"log"
)

func main() {
	var lengthOfArray, element int
	var winner string

	// participants list and if the
	participants := []string{"Alice", "Bob"}
	inputArray := make([]int, 0)
	newSequence := make([]int, 0)

	// taking the input array's length
	fmt.Scanln(&lengthOfArray)
	start, end := 0, lengthOfArray-1
	// taking the input array
	for i := 0; i < lengthOfArray; i++ {
		fmt.Scan(&element)
		inputArray = append(inputArray, element)
	}

gameLoop:
	for i := start; i < lengthOfArray; i++ {
		k := 0
		if inputArray[start] > inputArray[end] {
			if len(newSequence) == 0 {
				newSequence = append(newSequence, inputArray[start])
			} else {
				if newSequence[k] < inputArray[start] {
					newSequence = append(newSequence, inputArray[start])
				}
				k = k + 1
			}
			start = start + 1
		} else {
			if len(newSequence) == 0 {
				newSequence = append(newSequence, inputArray[end])
			} else {
				if newSequence[k] < inputArray[end] {
					newSequence = append(newSequence, inputArray[end])
				}
				k = k + 1
			}
			end = end - 1
		}
		lengthNewSeq := len(newSequence)
		// checking if all the elements are used then returning the winner
		if lengthNewSeq == lengthOfArray {
			winner = participants[i%2]
			break gameLoop
		}

		//checking that last element of the new array is greater than both the side ending element
		// return the winner in that case
		if newSequence[lengthNewSeq-1] >= inputArray[start] && newSequence[lengthNewSeq-1] >= inputArray[end] {
			winner = participants[i%2]
			break gameLoop
		}
	}
	log.Println(winner)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1600E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	input := make([]int, n)
	for i := range input {
		Fscan(in, &input[i])
	}

	l, r := 1, n-1
	for ; l < n && input[l-1] < input[l]; l++ {
	}
	for ; r > 0 && input[r] < input[r-1]; r-- {
	}
	if l%2 > 0 || (n-r)%21 > 0 {
		Fprint(out, "Alice")
	} else {
		Fprint(out, "Bob")
	}
}

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


You are given $$$n$$$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings.String $$$a$$$ is a substring of string $$$b$$$ if it is possible to choose several consecutive letters in $$$b$$$ in such a way that they form $$$a$$$. For example, string "for" is contained as a substring in strings "codeforces", "for" and "therefore", but is not contained as a substring in strings "four", "fofo" and "rof".

The first line contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of strings. The next $$$n$$$ lines contain the given strings. The number of letters in each string is from $$$1$$$ to $$$100$$$, inclusive. Each string consists of lowercase English letters. Some strings might be equal.

If it is impossible to reorder $$$n$$$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $$$n$$$ given strings in required order.

NoteIn the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".

package main

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

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

func main() {
	defer out.Flush()

	var n int
	fmt.Fscan(in, &n)
	s := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &s[i])
	}
	sort.Slice(s, func(i, j int) bool {
		if len(s[i]) != len(s[j]) {
			return len(s[i]) < len(s[j])
		}
		if strings.Contains(s[i], s[j]) {
			return false
		} else {
			return true
		}
	})
	var flag = true
	for i := 1; i < n; i++ {
		if !strings.Contains(s[i], s[i-1]) {
			flag = false
			break
		}
	}
	if flag {
		fmt.Fprintln(out,"YES")
		for i := 0; i < n; i++ {
			fmt.Fprintln(out, s[i])
		}
	} else {
		fmt.Fprintln(out, "NO")
	}
}

package main

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

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

	n, s, p := 0, "", ""
	g := [101][]string{}
	for Fscan(in, &n); n > 0; n-- {
		Fscan(in, &s)
		g[len(s)] = append(g[len(s)], s)
	}
	for _, ss := range g {
		if len(ss) == 0 {
			continue
		}
		for _, s := range ss {
			if s != ss[0] || !strings.Contains(s, p) {
				Fprint(out, "NO")
				return
			}
		}
		p = ss[0]
	}
	Fprintln(out, "YES")
	for _, ss := range g {
		for _, s := range ss {
			Fprintln(out, s)
		}
	}
}

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

package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		panic("could not read n from stdin")
	}

	inputStrings := make([]string, n, n)
	for i := 0; i < n; i++ {
		if _, err := fmt.Scanln(&inputStrings[i]); err != nil {
			panic(fmt.Sprintf("could not scanln string %d: %v", i, err))
		}
	}
	sort.Strings(inputStrings)
	sort.SliceStable(inputStrings, func(i, j int) bool {
		return len(inputStrings[i]) < len(inputStrings[j])
	})

	for i := 1; i < n; i++ {
		if strings.Index(inputStrings[i], inputStrings[i-1]) == -1 {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	for _, s := range inputStrings {
		fmt.Println(s)
	}
}

package main

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

type StringSlice []string

func (s StringSlice) Less(i, j int) bool {
	return len(s[i]) < len(s[j])
}

func (s StringSlice) Len() int {
	return len(s)
}

func (s StringSlice) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 32)
	var arr StringSlice
	for sc.Scan() {
		s := sc.Text()
		arr = append(arr, s)
	}
	sort.Sort(arr)

	for i := 0; i < int(n-1); i++ {
		if !strings.Contains(arr[i+1], arr[i]) {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	for _, s := range arr {
		fmt.Println(s)
	}
}

package main

import (
	"fmt"
	"sort"
	"strings"
)

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

	sort.Slice(str, func(i, j int) bool {
		if strings.Contains(str[j], str[i]) {
			return true
		} else {
			return false
		}
	})
	// fmt.Println(str)

	var ans = true
	for i := 0; i < n; i++ {
		for j := 0; j < i; j++ {
			if !strings.Contains(str[i], str[j]) {
				ans = false
			}
		}
	}

	if ans {
		fmt.Println("YES")
		for _, item := range str {
			fmt.Println(item)
		}
	} else {
		fmt.Println("NO")
	}
}

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

package main

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

type byLength []string

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	stringsCount := ReadInt32()
	inputs := make([]string, stringsCount)
	for stringIndex := 0; stringIndex < stringsCount; stringIndex++ {
		inputs[stringIndex] = ReadString()
	}
	sort.Sort(byLength(inputs))
	answer := true
	for stringIndex := 1; stringIndex < stringsCount; stringIndex++ {
		if !strings.Contains(inputs[stringIndex], inputs[stringIndex-1]) {
			answer = false
			break
		}
	}
	if !answer {
		writer.WriteString("NO\n")
	} else {
		writer.WriteString("YES\n")
		for stringIndex := 0; stringIndex < stringsCount; stringIndex++ {
			writer.WriteString(inputs[stringIndex] + "\n")
		}
	}
}

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

func (s byLength) Len() int {
	return len(s)
}

func (s byLength) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s byLength) Less(i, j int) bool {
	return len(s[i]) < len(s[j])
}

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

func ReadInt32() int {
	ans, _ := strconv.Atoi(ReadString())
	return ans
}

package main

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

type ByLen []string

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

func (a ByLen) Less(i, j int) bool {
   return len(a[i]) < len(a[j])
}

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

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

	str := []string {}

	i := 0
	for i < n {
		var here string
		fmt.Scan(&here)
		str = append(str, here)
		i ++
	}

	sort.Sort(ByLen(str))

	i = 0
	for i < n - 1 {
		if strings.Contains(str[i + 1], str[i]) == false {
			fmt.Println("NO")
			os.Exit(0)
		}
		i ++
	}

	fmt.Println("YES")
	for _, y := range str {
		fmt.Println(y)
	}
	os.Exit(0)
}

package main

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

type byCon []string

func (s byCon) Len() int {
	return len(s)
}

func (s byCon) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s byCon) Less(i, j int) bool {
	return strings.Contains(s[j], s[i])
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := int(readOneInt64(reader))
	var ss []string
	for i:=0;i<n;i++{
		s := readOneString(reader)
		ss = append(ss, s)
	}
	sort.Sort(byCon(ss))
	for i:=0;i<n-1;i++{
		if !strings.Contains(ss[i+1], ss[i]){
			fmt.Println("NO")
			os.Exit(0)
		}
	}
	fmt.Println("YES")
	for i:=0;i<n;i++{
		fmt.Println(ss[i])
	}
}

func readOneInt64(r *bufio.Reader) (n int64) {
	bytes, _ := r.ReadBytes('\n')
	n, _ = strconv.ParseInt(string(bytes[:len(bytes)-2]), 10, 64)
	return
}

func readInt64Slice(r *bufio.Reader, n int) (slice []int64) {
	var bytes []byte
	slice = make([]int64, n)
	n--
	for i := 0; i < n; i++ {
		bytes, _ = r.ReadBytes(' ')
		slice[i], _ = strconv.ParseInt(string(bytes[:len(bytes)-1]), 10, 64)
	}
	slice[n] = readOneInt64(r)
	return
}

func readOneString(r *bufio.Reader) string {
	bytes, _ := r.ReadBytes('\n')
	return string(bytes[:len(bytes)-2])
}

func abs(i int) int {
	if i < 0 {
		return i * -1
	}
	return i
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	A := SortInterFace{}
	for i := 0; i < N; i++ {
		A = append(A, sc.Next())
	}
	sort.Sort(A)

	for i := 1; i < N; i++ {
		if !strings.Contains(A[i], A[i-1]) {
			fmt.Println("NO")
			return
		}
	}
	fmt.Println("YES")
	for i := 0; i < N; i++ {
		fmt.Println(A[i])
	}

}

type SortInterFace []string

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

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

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

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

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

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

	return mp
}

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

package main

import (
	"fmt"
	"sort"
	"strings"
)

func main() {
	var n int
	var x string
	var data []string
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x)
		data = append(data, x)
	}
	sort.Slice(data, func(i, j int) bool {
		return len(data[i]) < len(data[j])
	})
	var res = true
	for i := n - 1; i > 0; i-- {
		if !strings.Contains(data[i], data[i-1]) {
			res = false
			break
		}
	}
	if res {
		fmt.Println("YES")
		for _, str := range data {
			fmt.Println(str)
		}
	} else {
		fmt.Println("NO")
	}
}

package main

import ("fmt";
		"sort")

func in(search, s string)bool{
	for i := 0; i < len(s) - len(search) + 1; i++{
		if (search == s[i:i + len(search)]){
			return true
	}
}
	return false
}

func main(){
	n := nextInt()
	var a []string = make([]string, n)
	for i := 0; i < n; i++{
		a[i] = next()
	}
	sort.Slice(a, func(i, j int)bool{
		return len(a[i]) < len(a[j])
		})
	for i := 1; i < n; i++{
		if (!in(a[i - 1], a[i])){
			sout("NO")
			return
		}
	}
	sout("YES")
	for _,s := range a{
		sout(s)
	}
}

func next() string{
	var ss string
	fmt.Scan(&ss)
	return ss
}
func nextInt() int{
	var ss int;
	fmt.Scan(&ss)
	return ss
}
func sout(obj ... interface{}){
	for _, k := range obj{
		fmt.Print(k, " ")
	}
	fmt.Println()
}

package main

import (
	"fmt"
	"strings"
)

var (
	n      int
	i      int
	st     [100]string
	ccl_st string

	l_st [100]int
	ccl  int
	flag bool
)

func main() {
	fmt.Scanln(&n)
	for i = 0; i < n; i++ {
		fmt.Scanln(&st[i])
		l_st[i] = len(st[i]) //读取字符串长度
	}
	//进行冒泡排序
	flag = true
	for flag == true {
		flag = false
		for i = 0; i < (n - 1); i++ {
			if l_st[i] > l_st[i+1] {
				flag = true
				ccl = l_st[i+1]
				l_st[i+1] = l_st[i]
				l_st[i] = ccl
				ccl_st = st[i+1]
				st[i+1] = st[i]
				st[i] = ccl_st
			}
		}
	}

	//判断多项是否包含少项
	flag = true
	for i = 0; (i < n-1) && (flag == true); i++ {
		flag = strings.Contains(st[i+1], st[i]) //判断后者是否包含前者

	}
	if flag == true {
		fmt.Println("YES")
		for i = 0; i < n; i++ {
			fmt.Println(st[i])
		}
	} else {
		fmt.Println("NO")

	}
}

package main

import (
	"fmt"
	"strings"
)

var (
	n      int
	i      int
	st     [100]string
	ccl_st string

	l_st [100]int
	ccl  int
	flag bool
)

func main() {
	fmt.Scanln(&n)
	for i = 0; i < n; i++ {
		fmt.Scanln(&st[i])
		l_st[i] = len(st[i]) //读取字符串长度
	}
	//进行冒泡排序
	flag = true
	for flag == true {
		flag = false
		for i = 0; i < (n - 1); i++ {
			if l_st[i] > l_st[i+1] {
				flag = true
				ccl = l_st[i+1]
				l_st[i+1] = l_st[i]
				l_st[i] = ccl
				ccl_st = st[i+1]
				st[i+1] = st[i]
				st[i] = ccl_st
			}
		}
	}

	//判断多项是否包含少项
	flag = true
	for i = 0; (i < n-1) && (flag == true); i++ {
		flag = strings.Contains(st[i+1], st[i]) //判断后者是否包含前者
		fmt.Println(i)
	}
	if flag == true {
		fmt.Println("YES")
		for i = 0; i < n; i++ {
			fmt.Println(st[i])
		}
	} else {
		fmt.Println("NO")

	}
}


You are given an array a with n elements. Each element of a is either 0 or 1.Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a).

The first line contains two integers n and k (1 ≤ n ≤ 3·105, 0 ≤ k ≤ n) — the number of elements in a and the parameter k. The second line contains n integers ai (0 ≤ ai ≤ 1) — the elements of a.

On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones. On the second line print n integers aj — the elements of the array a after the changes. If there are multiple answers, you can print any one of them.

package main

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

const MAXN = 300006

var arr[MAXN] int

func printAns(N int) {
	var i int
	var buffer bytes.Buffer
	ans := 0
	start := 0
	end := 0;
	for (start <= N && arr[start] == 0) {start++}
	for start <= N {
		if (arr[start] == 0) {
			start++
			continue
		}
		end = start
		for (end <= N && arr[end] == 1) {end++}
		if (end-start > ans) {ans = end-start}
		start++
	}
	fmt.Printf("%d\n", ans);
	for i=1; i<=N; i++ {
		buffer.WriteString(strconv.Itoa(arr[i]))
		buffer.WriteString(" ")
	}
	fmt.Printf(buffer.String())
}

func main() {
	var N,K,i,k int
	var ans,start,end,ans_start,ans_end,max_ans int
	var buffer bytes.Buffer
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &N)
	fmt.Fscan(in, &K)
	// fmt.Scanf("%d %d\n", &N, &K)
	for i=1; i<=N; i++ {
		// fmt.Scanf("%d", &arr[i])
		fmt.Fscan(in, &arr[i])
	}
	start = 0
	k = 0
	ans_start = 1
	ans_end = 1
	if K == 0 {
		printAns(N)
		return
	}
	if arr[start] == 0 {
		k++
	}
	end = start
	ans = end - start + 1
	max_ans = ans
	for start < N {
		if arr[start] == 0 {
			k--
		}
		start++
		ans--
		for end+1 <= N && (arr[end+1] == 1 || k < K) {
			end++
			if arr[end] == 0 {
				k++
			}
			ans++
		}
		if ans > max_ans {
			max_ans = ans;
			ans_start = start
			ans_end = end
		}
	}
	fmt.Printf("%d\n", max_ans);
	for i=1; i<ans_start; i++ {
		buffer.WriteString(strconv.Itoa(arr[i]))
		buffer.WriteString(" ")
	}
	for max_ans > 0 {
		buffer.WriteString("1 ")
		max_ans--
	}
	for i=ans_end+1; i<=N; i++ {
		buffer.WriteString(strconv.Itoa(arr[i]))
		buffer.WriteString(" ")
	}
	fmt.Printf(buffer.String())
}

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

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

func main() {
	n, k := 0, 0
	fmt.Fscanf(stdin, "%d%d\n", &n, &k)

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

	begin, end := 0, 0
	for count := 0; end < n && count <= k; end++ {
		if array[end] == 0 {
			if count < k {
				count++
			} else {
				break
			}
		}
	}

	max := end - begin
	maxBegin := begin
	maxEnd := end

	for end < n {

        if array[begin] == 0 {
		    begin++
            end++
        } else {
            begin++
        }

		for end < n && array[end] == 1 {
			end++
		}

		if end-begin > max {
			max = end - begin
			maxBegin = begin
			maxEnd = end
		}
	}

    fmt.Println(max)
    for i := 0; i < n; i++ {
        if i >= maxBegin && i < maxEnd {
            fmt.Fprint(stdout, "1 ")
        } else {
            fmt.Fprintf(stdout, "%d ", array[i])
        }
    }
    stdout.Flush()
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/660/C

package main

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

func Solve(n int, k int, a []int) (int, []int) {
	l := 0
	r := 0
	zeroes := 0
	maxL := -1
	maxR := -1
	ans := 0
	for l < n && r < n {
		if a[r] == 0 {
			zeroes += 1
		}
		if zeroes > k {
			if a[l] == 0 {
				zeroes -= 1
			}
			l += 1
		}
		if (r - l + 1) > ans {
			maxL = l
			maxR = r
			ans = r - l + 1
		}
		r += 1
	}
	if maxL == -1 && maxR == -1 {
		return ans, a
	}
	for i := maxL; i <= maxR; i++ {
		a[i] = 1
	}
	return ans, a
}

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

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

	length, arr := Solve(n, k, a)
	fmt.Fprintf(writer, "%d\n", length)
	for _, elem := range arr {
		fmt.Fprintf(writer, "%d ", elem)
	}
	fmt.Fprintf(writer, "\n")
}

package main

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

var stdin *bufio.Reader

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

func main() {
	n, k := 0, 0
	fmt.Fscanf(stdin, "%d%d\n", &n, &k)

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

	begin, end := 0, 0
	for count := 0; end < n && count <= k; end++ {
		if array[end] == 0 {
			if count < k {
				count++
			} else {
				break
			}
		}
	}

	max := end - begin
	maxBegin := begin
	maxEnd := end

	for end < n {

		for begin < n && array[begin] == 1 {
			begin++
		}

		if begin == 0 {
			break
		}

		begin++
		end++

		for end < n && array[end] == 1 {
			end++
		}

		if end-begin > max {
			max = end - begin
			maxBegin = begin
			maxEnd = end
		}
	}

    fmt.Println(max)
    for i := 0; i < n; i++ {
        if i >= maxBegin && i < maxEnd {
            fmt.Print("1 ")
        } else {
            fmt.Printf("%d ", array[i])
        }
    }
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/660/C

package main

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

func Solve(n int, k int, a []int) []int {
	l := 0
	r := 0
	zeroes := 0
	maxL := -1
	maxR := -1
	ans := 0
	for l < n && r < n {
		if a[r] == 0 {
			zeroes += 1
		}
		if zeroes > k {
			if a[l] == 0 {
				zeroes -= 1
			}
			l += 1
		}
		if (r - l + 1) > ans {
			maxL = l
			maxR = r
			ans = r - l + 1
		}
		r += 1
	}
	if maxL == -1 && maxR == -1 {
		return a
	}
	for i := maxL; i <= maxR; i++ {
		a[i] = 1
	}
	return a
}

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

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

	for _, elem := range Solve(n, k, a) {
		fmt.Fprintf(writer, "%d ", elem)
	}
	fmt.Fprintf(writer, "\n")
}