In the first line of input there is one integer $$$n$$$ ($$$0 \le n \le 6$$$) — the number of Gems in Infinity Gauntlet. In next $$$n$$$ lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.

In the first line output one integer $$$m$$$ ($$$0 \le m \le 6$$$) — the number of absent Gems. Then in $$$m$$$ lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.

NoteIn the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.In the second sample Thanos doesn't have any Gems, so he needs all six.

package main

import (
	"fmt"
)

func main() {
	var n int
	hash := map[string]bool{
		"purple": true,
		"green":  true,
		"blue":   true,
		"orange": true,
		"red":    true,
		"yellow": true,
	}
	gemName := map[string]string{
		"purple": "Power",
		"green":  "Time",
		"blue":   "Space",
		"orange": "Soul",
		"red":    "Reality",
		"yellow": "Mind",
	}

	fmt.Scanf("%d\n", &n)
	i := 0
	for i < n {
		var gem string
		fmt.Scanf("%s\n", &gem)
		hash[gem] = false
		i++
	}

	fmt.Println(6 - n)
	if n == 6 {
		return
	}
	for gem, exist := range hash {
		if exist {
			fmt.Println(gemName[gem])
		}
	}
}

// A. Infinity Gauntlet
/*
You took a peek on Thanos wearing Infinity Gauntlet. In the Gauntlet there is a place for six Infinity Gems:

    the Power Gem of purple color,
    the Time Gem of green color,
    the Space Gem of blue color,
    the Soul Gem of orange color,
    the Reality Gem of red color,
    the Mind Gem of yellow color.

Using colors of Gems you saw in the Gauntlet determine the names of absent Gems.

Input
In the first line of input there is one integer 𝑛 (0≤𝑛≤6) — the number of Gems in Infinity Gauntlet.

In next 𝑛 lines there are colors of Gems you saw. Words used for colors are: purple, green, blue, orange, red, yellow. It is guaranteed that all the colors are distinct. All colors are given in lowercase English letters.

Output
In the first line output one integer 𝑚 (0≤𝑚≤6) — the number of absent Gems.

Then in 𝑚 lines print the names of absent Gems, each on its own line. Words used for names are: Power, Time, Space, Soul, Reality, Mind. Names can be printed in any order. Keep the first letter uppercase, others lowercase.

Examples
Input
4
red
purple
yellow
orange

Output
2
Space
Time

Input
0

Output
6
Time
Mind
Soul
Power
Reality
Space

Note
In the first sample Thanos already has Reality, Power, Mind and Soul Gems, so he needs two more: Time and Space.

In the second sample Thanos doesn't have any Gems, so he needs all six.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

	fmt.Println(6 - n)

	gems := map[string]string{"purple": "Power", "green": "Time", "blue": "Space", "orange": "Soul", "red": "Reality", "yellow": "Mind"}
	i := map[string]int{}
	for ; n > 0; n-- {
		input2, _ := reader.ReadString('\n')
		v := strings.TrimSpace(input2)
		i[v]++
	}

	for k, v := range gems {
		if _, ok := i[k]; !ok {
			fmt.Println(v)
		}
	}
}

package main

import (
  "fmt"
)

func main()  {
  var keys = map[string] string{
    "purple": "Power",
    "green": "Time",
    "blue": "Space",
    "orange": "Soul",
    "red": "Reality",
    "yellow": "Mind",
  }
  var num int

  fmt.Scanf("%d\n", &num)

  for i := 0;  i < num ; i++{
    var text string
    fmt.Scanf("%s\n",&text)
    delete(keys, text)
  }

  fmt.Println(len(keys))
  for _ ,v := range keys {
    fmt.Println(v)
  }

}

package main

import (
	"fmt"
)

var gen map[string]string = map[string]string{
	"red":"Reality",
	"purple":"Power",
	"blue":"Space",
	"orange":"Soul",
	"yellow":"Mind",
	"green":"Time",
}

func main () {
	var n int

	fmt.Scanf("%d\n",&n)

	for i:=0 ;i < n ;i ++ {
		var color string
		fmt.Scanf("%s\n",&color)
		delete(gen , color)

	}

	fmt.Println(len(gen))

	for _ , v :=range gen {
		fmt.Println(v)
	}
}

package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n)
	gem := map[string]string{
		"purple": "Power",
		"green":  "Time",
		"blue":   "Space",
		"orange": "Soul",
		"red":    "Reality",
		"yellow": "Mind",
	}
	for ; n > 0; n-- {
		fmt.Scan(&s)
		delete(gem, s)
	}
	fmt.Println(len(gem))
	for _, v := range gem {
		fmt.Println(v)
	}
}

package main

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

func main() {
	// prepare necessary params
	var n int
	var color string
	stdin := bufio.NewReader(os.Stdin)
	colors := map[string]string{
		"purple": "Power",
		"green":  "Time",
		"blue":   "Space",
		"orange": "Soul",
		"red":    "Reality",
		"yellow": "Mind",
	}
	// scan input
	fmt.Fscanf(stdin, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(stdin, "%s\n", &color)
		// delete existing color from map
		delete(colors, color)
	}
	// print output
	fmt.Println(len(colors))
	for _, gem := range colors {
		fmt.Println(gem)
	}
}

package main

import . "fmt"

var (
	n int
	s string
)
var gem = map[string]string{
	"purple"	: "Power",
	"green"		: "Time",
	"blue"		: "Space",
	"orange"	: "Soul",
	"red"		: "Reality",
	"yellow"	: "Mind",
}
var bol = map[string]bool{
	"purple": false,
	"green" : false,
	"blue" 	: false,
	"orange": false,
	"red"	: false,
	"yellow":false,
}

func main(){
	Scanln(&n)
	for i:=0; i<n;i++ {
		Scanln(&s)
		bol[s] = true
	}

	Println(6-n)
	for k := range bol {
		if !bol[k] {
			Println(gem[k])
		}
	}
}

package main

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

func solve() {
	n := readInt()
	obj := map[string]string{
		"purple": "Power",
		"green":  "Time",
		"blue":   "Space",
		"orange": "Soul",
		"red":    "Reality",
		"yellow": "Mind",
	}
	values := make(map[string]int, 0)
	for i := 0; i < n; i++ {
		values[obj[readString()]]++
	}
	res := make([]string, 0)
	for _, v := range obj {
		if _, ok := values[v]; ok {
		} else {
			res = append(res, v)
		}
	}
	fmt.Println(len(res))
	sort.Strings(res)
	for i := 0; i < len(res); i++ {
		fmt.Println(res[i])
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main
import "fmt"

func main(){

	var m map[string]string
	m = make(map[string]string)

	m["purple"] = "Power"
	m["green"] = "Time"
	m["blue"] = "Space"
	m["orange"] = "Soul"
	m["red"] = "Reality"
	m["yellow"] = "Mind"

	var n int
	fmt.Scan(&n)

	i := 0

	var isExists map[string]bool
	isExists = make(map[string]bool)

	isExists["Power"] = false
	isExists["Time"] = false
	isExists["Space"] = false
	isExists["Soul"] = false
	isExists["Reality"] = false
	isExists["Mind"] = false

	for i < n {
		var s string
		fmt.Scan(&s)
		isExists[m[s]] = true
		i ++
	}

	var cnt int

	for _, v := range isExists {
		if v == false {
			cnt ++
		}
	}

	fmt.Println(cnt)

	for k, v := range isExists {
		if v == false {
			fmt.Println(k)
		}
	}

 }

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var count = 6
	n := int(readOneInt64(reader))
	m := map[string]bool{
		"purple": false,
		"green":  false,
		"blue":   false,
		"orange": false,
		"red":    false,
		"yellow": false,
	}
	for i := 0; i < n; i++ {
		s := readOneString(reader)
		m[s] = true
		count--
	}
	mm := map[string]string{
		"Power":   "purple",
		"Time":    "green",
		"Space":   "blue",
		"Soul":    "orange",
		"Reality": "red",
		"Mind":    "yellow",
	}
	fmt.Println(count)
	for k, v := range m {
		if v == false {
			for k2, v2 := range mm {
				if v2 == k {
					fmt.Println(k2)
				}
			}
		}
	}
}

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 (
	"fmt"
)

var colors = map[string]string{
	"purple": "Power",
	"green":  "Time",
	"blue":   "Space",
	"orange": "Soul",
	"red":    "Reality",
	"yellow": "Mind",
}

func main() {
	var n int
	var str string
	var gems = map[string]bool{
		"Time":    true,
		"Mind":    true,
		"Soul":    true,
		"Power":   true,
		"Reality": true,
		"Space":   true,
	}
	fmt.Scan(&n)
	fmt.Println(6 - n)
	for i := 0; i < n; i++ {
		fmt.Scan(&str)
		gems[colors[str]] = false
	}
	for v, k := range gems {
		if k {
			fmt.Println(v)
		}
	}
}

package main
import (
	"fmt"
)

func in_StrArray(arr []string, key string)bool{
	for _,i := range arr{
		if key == i{
			return true
		}
	}
	return false
}

func main(){
	var n_stones int
	//fmt.Print("Number OF Stones Seen: ")
	fmt.Scanln(&n_stones)
	//fmt.Print("Colour OF Stones Seen: ")
	var stonesPresent []string

	var i_Stones = map[string]string{
		"blue": "Space",
		"red": "Reality",
		"yellow": "Mind",
		"orange": "Soul",
		"purple": "Power",
		"green": "Time",
	}

	for i := 0; i < n_stones; i++{
		var temp string
		fmt.Scanln(&temp)
		stonesPresent = append(stonesPresent, i_Stones[temp])
	}

	fmt.Println(len(i_Stones)-len(stonesPresent))
	for _,types := range i_Stones{
		if ! in_StrArray(stonesPresent, types){
			fmt.Println(types)
		}
	}
}

package main

import (
	"fmt"
)

var (
	k     int
	i     int
	s     [6]string
	flag  bool
	count int
	s1    string
	s2    string
)

func main() {
	mieba := map[string]string{

		"green":  "Time",
		"yellow": "Mind",
		"orange": "Soul",
		"purple": "Power",
		"red":    "Reality",
		"blue":   "Space"}
	count = 0
	fmt.Scan(&k)
	for i = 0; i < k; i++ {
		fmt.Scan(&s[i])
	}
	for s1, s2 = range mieba {
		flag = false
		for i = 0; i < k; i++ {
			if s[i] == s1 {
				flag = true
			}
		}
		if flag == false {
			count++
		}
	}
	fmt.Println(count)
	for s1, s2 = range mieba {
		flag = false
		for i = 0; i < k; i++ {
			if s[i] == s1 {
				flag = true
			}
		}
		if flag == false {
			fmt.Println(s2)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var r = map[string]string{
		"purple":"Power",
		"green":"Time",
		"blue":"Space",
		"orange":"Soul",
		"red":"Reality",
		"yellow":"Mind",
	}
	var n int

	fmt.Scan(&n)
	for i:=0;i<n;i++{
		var m string
		fmt.Scan(&m)
		delete(r,m)
	}
	fmt.Println(len(r))
	for _,v := range(r){
		fmt.Println(v)
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main(){
	m := map[string]string{"purple": "Power", "green": "Time", "blue": "Space", "orange" : "Soul", "red": "Reality", "yellow": "Mind"}

	sc.Split(bufio.ScanWords)

	n := nextInt()
	for i:=0; i< n; i++{
		l := nextLine()
		delete(m, l)
	}

	fmt.Printf("%d\n", len(m))
	for _, v:= range m{
		fmt.Printf("%s\n", v)
	}

}

package main

import "fmt"

func main() {
	var n int
	var a = map[string]string{
		"purple": "Power",
		"green": "Time",
		"blue": "Space",
		"orange": "Soul",
		"red": "Reality",
		"yellow": "Mind",
	}
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Scanf("%s\n", &s)
		delete(a, s)
	}
	fmt.Println(len(a))
	for _, v := range a {
		fmt.Println(v)
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	hash := map[string]bool{
		"purple": true,
		"green":  true,
		"blue":   true,
		"orange": true,
		"red":    true,
		"yellow": true,
	}
	gemName := map[string]string{
		"purple": "Power",
		"green":  "Time",
		"blue":   "Space",
		"orange": "Soul",
		"red":    "Reality",
		"yellow": "Mind",
	}

	fmt.Scanf("%d", &n)
	i := 0
	for i < n {
		var gem string
		fmt.Scanf("%s", &gem)
		hash[gem] = false
		i++
	}

	fmt.Println(6 - n)
	for gem, exist := range hash {
		if exist {
			fmt.Println(gemName[gem])
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	hash := map[string]bool{
		"purple": true,
		"green":  true,
		"blue":   true,
		"orange": true,
		"red":    true,
		"yellow": true,
	}
	gemName := map[string]string{
		"purple": "Power",
		"green":  "Time",
		"blue":   "Space",
		"orange": "Soul",
		"red":    "Reality",
		"yellow": "Mind",
	}

	fmt.Scanf("%d", &n)
	i := 0
	for i < n {
		var gem string
		fmt.Scanf("%s", &gem)
		hash[gem] = false
		i++
	}

	fmt.Println(6 - n)
	if n == 6 {
		return
	}
	for gem, exist := range hash {
		if exist {
			fmt.Println(gemName[gem])
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	hash := map[string]bool{
		"purple": true,
		"green":  true,
		"blue":   true,
		"orange": true,
		"red":    true,
		"yellow": true,
	}
	gemName := map[string]string{
		"purple": "Power",
		"green":  "Time",
		"blue":   "Space",
		"orange": "Soul",
		"red":    "Reality",
		"yellow": "Mind",
	}

	fmt.Scanf("%d", &n)
	fmt.Println(6 - n)
	i := 0
	for i < n {
		var gem string
		fmt.Scanf("%s", &gem)
		hash[gem] = false
		i++
	}

	for gem, exist := range hash {
		if exist {
			fmt.Println(gemName[gem])
		}
	}
}

package main

import (
  "fmt"

)

func main()  {
  var keys = map[string] string{
    "purple": "Power",
    "green": "Time",
    "blue": "Space",
    "orange": "Soul",
    "red": "Reality",
    "yellow": "Mind",
  }
  var num int
  var text string
  fmt.Scanf("%d", &num)

  for i := 0;  i < num ; i++{
    fmt.Scanf("%s\n",&text)
    delete(keys, text)

  }

  fmt.Println(len(keys))
  for _ ,v := range keys {
    fmt.Println(v)
  }

}

package main

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

func main()  {
  var keys = map[string] string{
    "purple": "Power",
    "green": "Time",
    "blue": "Space",
    "orange": "Soul",
    "red": "Reality",
    "yellow": "Mind",
  }
  var num int
  reader := bufio.NewReader(os.Stdin)
  fmt.Scanf("%d", &num)

  for i := 0;  i < num ; i++{
    text, _ := reader.ReadString('\n')
    text = strings.TrimSuffix(text, "\n")

    delete(keys, text)

  }

  fmt.Println("\n")
  for _ ,v := range keys {
    fmt.Println(v)
  }

}

package main

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

func main()  {
  var keys = map[string] string{
    "purple": "Power",
    "green": "Time",
    "blue": "Space",
    "orange": "Soul",
    "red": "Reality",
    "yellow": "Mind",
  }
  var num int
  reader := bufio.NewReader(os.Stdin)
  fmt.Scanf("%d", &num)

  for i := 0;  i < num ; i++{
    text, _ := reader.ReadString('\n')
    text = strings.TrimSuffix(text, "\n")

    delete(keys, text)

  }

  fmt.Println(len(keys))
  for _ ,v := range keys {
    fmt.Println(v)
  }

}

package main
import (
	"fmt"
)

func in_StrArray(arr []string, key string)bool{
	for _,i := range arr{
		if key == i{
			return true
		}
	}
	return false
}

func main(){
	var n_stones int
	fmt.Print("Number OF Stones Seen: ")
	fmt.Scanln(&n_stones)
	fmt.Print("Colour OF Stones Seen: ")
	var stonesPresent []string

	var i_Stones = map[string]string{
		"blue": "Space",
		"red": "Reality",
		"yellow": "Mind",
		"orange": "Soul",
		"purple": "Power",
		"green": "Time",
	}

	for i := 0; i < n_stones; i++{
		var temp string
		fmt.Scanln(&temp)
		stonesPresent = append(stonesPresent, i_Stones[temp])
	}

	fmt.Printf(":: NOW HE JUST NEEDS %d STONES ::\n", len(i_Stones)-len(stonesPresent))
	for _,types := range i_Stones{
		if ! in_StrArray(stonesPresent, types){
			fmt.Println(types)
		}
	}
}

package main

import (
	"fmt"
)

var (
	k     int
	i     int
	s     [6]string
	flag  bool
	count int
	s1    string
	s2    string
)

func main() {
	mieba := map[string]string{

		"green":  "Time",
		"yellow": "Mind",
		"orange": "Soul",
		"purple": "Power",
		"red":    "Reality",
		"blue":   "Spcae"}
	count = 0
	fmt.Scan(&k)
	for i = 0; i < k; i++ {
		fmt.Scan(&s[i])
	}
	for s1, s2 = range mieba {
		flag = false
		for i = 0; i < k; i++ {
			if s[i] == s1 {
				flag = true
			}
		}
		if flag == false {
			count++
		}
	}
	fmt.Println(count)
	for s1, s2 = range mieba {
		flag = false
		for i = 0; i < k; i++ {
			if s[i] == s1 {
				flag = true
			}
		}
		if flag == false {
			fmt.Println(s2)
		}
	}
}


Consider a simplified penalty phase at the end of a football match.A penalty phase consists of at most $$$10$$$ kicks, the first team takes the first kick, the second team takes the second kick, then the first team takes the third kick, and so on. The team that scores more goals wins; if both teams score the same number of goals, the game results in a tie (note that it goes against the usual football rules). The penalty phase is stopped if one team has scored more goals than the other team could reach with all of its remaining kicks. For example, if after the $$$7$$$-th kick the first team has scored $$$1$$$ goal, and the second team has scored $$$3$$$ goals, the penalty phase ends — the first team cannot reach $$$3$$$ goals.You know which player will be taking each kick, so you have your predictions for each of the $$$10$$$ kicks. These predictions are represented by a string $$$s$$$ consisting of $$$10$$$ characters. Each character can either be 1, 0, or ?. This string represents your predictions in the following way:  if $$$s_i$$$ is 1, then the $$$i$$$-th kick will definitely score a goal;  if $$$s_i$$$ is 0, then the $$$i$$$-th kick definitely won't score a goal;  if $$$s_i$$$ is ?, then the $$$i$$$-th kick could go either way. Based on your predictions, you have to calculate the minimum possible number of kicks there can be in the penalty phase (that means, the earliest moment when the penalty phase is stopped, considering all possible ways it could go). Note that the referee doesn't take into account any predictions when deciding to stop the penalty phase — you may know that some kick will/won't be scored, but the referee doesn't.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1\,000$$$) — the number of test cases. Each test case is represented by one line containing the string $$$s$$$, consisting of exactly $$$10$$$ characters. Each character is either 1, 0, or ?.

For each test case, print one integer — the minimum possible number of kicks in the penalty phase.

NoteConsider the example test:In the first test case, consider the situation when the $$$1$$$-st, $$$5$$$-th and $$$7$$$-th kicks score goals, and kicks $$$2$$$, $$$3$$$, $$$4$$$ and $$$6$$$ are unsuccessful. Then the current number of goals for the first team is $$$3$$$, for the second team is $$$0$$$, and the referee sees that the second team can score at most $$$2$$$ goals in the remaining kicks. So the penalty phase can be stopped after the $$$7$$$-th kick.In the second test case, the penalty phase won't be stopped until all $$$10$$$ kicks are finished.In the third test case, if the first team doesn't score any of its three first kicks and the second team scores all of its three first kicks, then after the $$$6$$$-th kick, the first team has scored $$$0$$$ goals and the second team has scored $$$3$$$ goals, and the referee sees that the first team can score at most $$$2$$$ goals in the remaining kicks. So, the penalty phase can be stopped after the $$$6$$$-th kick.In the fourth test case, even though you can predict the whole penalty phase, the referee understands that the phase should be ended only after the $$$9$$$-th kick.

package main

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

var (
	in = bufio.NewReader(os.Stdin)
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}
func solve() {
	var givenString string
	fmt.Fscan(in, &givenString)
	ans := rec(givenString, 5, 5, 1, 0, 0, 0)
	fmt.Println(ans)
}
func rec(givenString string, firstPlayerMove int, secondPlayerMove int, currentPlayer int, firstPlayerScore int, SecondPlayerScore int, currentIndex int) int {
	if currentIndex == 10 {
		return 0
	}
	if firstPlayerMove+firstPlayerScore < SecondPlayerScore {
		return 0
	}
	if secondPlayerMove+SecondPlayerScore < firstPlayerScore {
		return 0
	}
	if string(givenString[currentIndex]) == "1" {
		if currentPlayer%2 == 0 {
			secondPlayerMove--
			SecondPlayerScore++
		} else {
			firstPlayerMove--
			firstPlayerScore++
		}
		return 1 + rec(givenString, firstPlayerMove, secondPlayerMove, currentPlayer+1, firstPlayerScore, SecondPlayerScore, currentIndex+1)
	} else if string(givenString[currentIndex]) == "0" {
		if currentPlayer%2 == 0 {
			secondPlayerMove--
		} else {
			firstPlayerMove--
		}
		return 1 + rec(givenString, firstPlayerMove, secondPlayerMove, currentPlayer+1, firstPlayerScore, SecondPlayerScore, currentIndex+1)
	} else {
		if currentPlayer%2 == 0 {
			first := rec(givenString, firstPlayerMove, secondPlayerMove-1, currentPlayer+1, firstPlayerScore, SecondPlayerScore, currentIndex+1)
			second := rec(givenString, firstPlayerMove, secondPlayerMove-1, currentPlayer+1, firstPlayerScore, SecondPlayerScore+1, currentIndex+1)
			return 1 + int(math.Min(float64(first), float64(second)))
		} else {
			first := rec(givenString, firstPlayerMove-1, secondPlayerMove, currentPlayer+1, firstPlayerScore, SecondPlayerScore, currentIndex+1)
			second := rec(givenString, firstPlayerMove-1, secondPlayerMove, currentPlayer+1, firstPlayerScore+1, SecondPlayerScore, currentIndex+1)
			return 1 + int(math.Min(float64(first), float64(second)))
		}
	}
}

//x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-TEMPLATE_STARTING-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-

type pair struct {
	a int64
	b int64
}

func sortPair(pairs []pair) {
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].a < pairs[j].a
	})
}
func max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

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

package main

import (
	"fmt"
)

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for t:= 0; t<T; t++{
		var s string
		fmt.Scanf("%s\n",&s)
		var a,b,c,d int = 0,0,0,0
		ans := 10
		for i := 0; i < 10; i++{
			if s[i] == '1'{
				if i % 2 == 0 {
					a++
				}else{
					b++
				}
			}
			if s[i] == '?'{
				if i % 2 ==0{
					c++
				}else{
					d++
				}
			}
			if a + c > b + (10 - i) / 2 || b + d > a + (9 - i) / 2{
				ans = i + 1
				break
			}
		}
		fmt.Printf("%d\n", ans)
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var s string
		fmt.Fscan(in, &s)

		var a, b int
		var x, y int
		min := 10
		for i, v := range s {
			if v == '1' {
				if i%2 == 0 {
					a++
					x++
				} else {
					b++
					y++
				}
			} else if v == '?' && i%2 == 0 {
				a++
			} else if v == '?' && i%2 != 0 {
				y++
			}

			if a > b+((10-i)/2) || y > x+(9-i)/2 {
				min = i + 1
				break
			}
		}

		fmt.Fprintln(out, min)
	}
}

package main

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

func main() {
	defer wr.Flush()
	t := scanInt()

	for ti := 0; ti < t; ti++ {
		solve()
	}
}

func solve() {
	word := scanWord()
	res := strings.Split(word, "")

	aWins := make([]int, 10)
	bWins := make([]int, 10)

	for i := range res {
		if res[i] == "1" {
			aWins[i] = 1
			bWins[i] = 1
		} else if res[i] == "0" {
			aWins[i] = 0
			bWins[i] = 0
		} else {
			if i%2 == 0 {
				aWins[i] = 1
				bWins[i] = 0
			} else {
				aWins[i] = 0
				bWins[i] = 1
			}
		}
	}

	var aScore, bScore = 0, 0
	var aRem, bRem = 5, 5
	var minPen int

	for i := range aWins {
		if i%2 == 0 {
			aScore += aWins[i]
		} else {
			bScore += aWins[i]
			bRem -= 1
		}
		if aScore > bScore + bRem || i == 9 {
			minPen = i + 1
			break
		}
	}

	aScore, bScore = 0, 0

	for i := range bWins {
		if i%2 == 0 {
			aScore += bWins[i]
			aRem -= 1
		} else {
			bScore += bWins[i]
		}
		if bScore > aScore + aRem || i == 9 {
			if i + 1 < minPen {
				minPen = i + 1
				break
			}
		}
	}

	fmt.Println(minPen)

}

var (
	sc *bufio.Scanner
	wr *bufio.Writer
)

func init() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	wr = bufio.NewWriter(os.Stdout)
}

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

func scanWord() string {
	sc.Scan()
	ret := sc.Text()
	return ret
}

package main

import "fmt"

func min_penalty_balls(pred_res string){
	team_a_certain := 0
	team_b_certain := 0
	team_a_uncertain := 0
	team_b_uncertain := 0
	for i := 0; i < len(pred_res); i++{
		ch := pred_res[i]
		if i%2 == 0 {
			switch ch{
				case '1': team_a_certain += 1
				case '?': team_a_uncertain += 1
			}
		}else{
			switch ch{
				case '1': team_b_certain += 1
				case '?': team_b_uncertain += 1
			}
		}
		var max_a = team_a_certain + team_a_uncertain
		var min_b = (10-i)/2 + team_b_certain
		var max_b = team_b_certain + team_b_uncertain
		var min_a = (9-i)/2 + team_a_certain
		if max_a > min_b{
			fmt.Println(i+1)
			break
		}
		if max_b > min_a{
			fmt.Println(i+1)
			break
		}
		if i == 9{
			fmt.Println(10)
		}
	}
}

func main(){
	var n int
	fmt.Scanln(&n)
	for i := 0; i<n; i++{
		var pred string
		fmt.Scanln(&pred)
		min_penalty_balls(pred)
	}
}

package main

import "fmt"

const maxKick=10
type score struct {
	possible int
	max,min int
}
func updateScore(sc *score,ch int32){
	if ch=='1'{
		sc.max++
		sc.min++
	}else if ch=='?'{
		sc.max++
	}
	sc.possible--
}
func solve (s string) int{
	var score1,score2 score
	score1.possible=maxKick/2
	score2.possible=maxKick/2
	for i,ch:=range s{
		if i%2==0{
			updateScore(&score1,ch)
		}else{
			updateScore(&score2,ch)
		}
		if score1.max>score2.possible+score2.min || score2.max>score1.possible+score1.min{
			return i+1
		}

	}
	return maxKick
}
func penalty(){
	var cases int
	_,err:=fmt.Scanf("%d\n",&cases)
	if err!=nil{
		return
	}
	for i:=0;i<cases;i++{
		var str string
		_,err=fmt.Scanf("%s\n",&str)
		if err!=nil{
			return
		}
		ans:=solve(str)
		fmt.Printf("%d\n",ans)
	}
}
func main() {
	penalty()
}

package main

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

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

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

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

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

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

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

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

func sol(s string) int {
	return min(max1(s), max2(s))
}

func max1(s string) int {
	g1 := 0
	g2 := 0
	r1 := 5
	r2 := 5
	for i := range s {
		if i&1 == 0 { // team 1
			r1--
			if s[i] == '?' || s[i] == '1' {
				g1++
			}
		} else { // team 2
			r2--
			if s[i] == '1' {
				g2++
			}
		}
		if g1 > g2+r2 {
			return i + 1
		}
	}
	return 10
}

func max2(s string) int {
	g1 := 0
	g2 := 0
	r1 := 5
	r2 := 5
	for i := range s {
		if i&1 == 1 { // team 2
			r2--
			if s[i] == '?' || s[i] == '1' {
				g2++
			}
		} else {
			r1--
			if s[i] == '1' {
				g1++
			}
		}
		if g2 > g1+r1 {
			return i + 1
		}
	}
	return 10
}

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

package main

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

var (
	ans int64
	in  = bufio.NewReader(os.Stdin)
)

func main() {
	var test int
	fmt.Fscan(in, &test)
	for i := 0; i < test; i++ {
		solve()
	}

}
func solve() {
	ans = math.MaxInt64
	var givenString string
	fmt.Fscan(in, &givenString)
	helper(givenString, "first", 0, 0, 0, 0, 0)
	fmt.Println(ans)

}

func helper(givenString string, currentTurn string, numberOfTurnBy1 int, numberOfTurnBy2 int, firstTeamScore int, secondTeamScore int, totalTurn int) {
	if totalTurn == 10 {
		ans = int64(math.Min(float64(ans), float64(totalTurn)))
		return
	}
	if currentTurn == "second" {
		if secondTeamScore+(5-numberOfTurnBy2) < firstTeamScore {
			ans = int64(math.Min(float64(ans), float64(totalTurn)))
			return
		} else if numberOfTurnBy2 == 4 && firstTeamScore > secondTeamScore && string(givenString[totalTurn]) == "0" {
			ans = int64(math.Min(float64(ans), float64(totalTurn+1)))
			return
		}
	} else if currentTurn == "first" {
		if firstTeamScore+(5-numberOfTurnBy1) < secondTeamScore {
			ans = int64(math.Min(float64(ans), float64(totalTurn)))
			return
		} else if numberOfTurnBy1 == 4 && secondTeamScore > firstTeamScore && string(givenString[totalTurn]) == "0" {
			ans = int64(math.Min(float64(ans), float64(totalTurn+1)))
			return
		}
	}
	if currentTurn == "first" {
		if string(givenString[totalTurn]) == "?" {
			helper(givenString, "second", numberOfTurnBy1+1, numberOfTurnBy2, firstTeamScore+0, secondTeamScore, totalTurn+1)
			helper(givenString, "second", numberOfTurnBy1+1, numberOfTurnBy2, firstTeamScore+1, secondTeamScore, totalTurn+1)
		} else if string(givenString[totalTurn]) == "1" {
			helper(givenString, "second", numberOfTurnBy1+1, numberOfTurnBy2, firstTeamScore+1, secondTeamScore, totalTurn+1)
		} else {
			helper(givenString, "second", numberOfTurnBy1+1, numberOfTurnBy2, firstTeamScore+0, secondTeamScore, totalTurn+1)
		}
	} else {
		if string(givenString[totalTurn]) == "?" {
			helper(givenString, "first", numberOfTurnBy1, numberOfTurnBy2+1, firstTeamScore+0, secondTeamScore, totalTurn+1)
			helper(givenString, "first", numberOfTurnBy1, numberOfTurnBy2+1, firstTeamScore, secondTeamScore+1, totalTurn+1)
		} else if string(givenString[totalTurn]) == "1" {
			helper(givenString, "first", numberOfTurnBy1, numberOfTurnBy2+1, firstTeamScore, secondTeamScore+1, totalTurn+1)
		} else {
			helper(givenString, "first", numberOfTurnBy1, numberOfTurnBy2+1, firstTeamScore+0, secondTeamScore, totalTurn+1)
		}
	}
}

//x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-TEMPLATE_STARTING-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-

type pair struct {
	a int64
	b int64
}

func sortPair(pairs []pair) {
	sort.Slice(pairs, func(i, j int) bool {
		return pairs[i].a < pairs[j].a
	})
}
func max(a int64, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func printArray(arr []int) {
	for i := 1; i < len(arr); i++ {
		fmt.Print(arr[i], " ")
	}
	fmt.Println()
}

type runeSort []rune

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


Amugae has a sentence consisting of $$$n$$$ words. He want to compress this sentence into one word. Amugae doesn't like repetitions, so when he merges two words into one word, he removes the longest prefix of the second word that coincides with a suffix of the first word. For example, he merges "sample" and "please" into "samplease".Amugae will merge his sentence left to right (i.e. first merge the first two words, then merge the result with the third word and so on). Write a program that prints the compressed word after the merging process ends.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of the words in Amugae's sentence. The second line contains $$$n$$$ words separated by single space. Each words is non-empty and consists of uppercase and lowercase English letters and digits ('A', 'B', ..., 'Z', 'a', 'b', ..., 'z', '0', '1', ..., '9'). The total length of the words does not exceed $$$10^6$$$.

In the only line output the compressed word after the merging process ends as described in the problem.

package main

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

func Sol1200E(reader io.Reader, writer io.Writer) {
	maxMergeLen := func(s string) int {
		n := len(s)
		f := make([]int, n)
		cnt := 0
		for i := 1; i < n; i++ {
			c := s[i]
			for cnt > 0 && s[cnt] != c {
				cnt = f[cnt-1]
			}
			if s[cnt] == c {
				cnt++
			}
			f[i] = cnt
		}
		return f[n-1]
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	var w, tmpMerge string
	Fscan(in, &n, &w)
	ans := append(make([]byte, 0, 1e6), w...)
	for n--; n > 0; n-- {
		Fscan(in, &w)
		if len(ans) >= len(w) {
			tmpMerge = w + "$" + string(ans[len(ans)-len(w):])
		} else {
			tmpMerge = w[:len(ans)] + "$" + string(ans)
		}
		if l := maxMergeLen(tmpMerge); l < len(w) {
			ans = append(ans, w[l:]...)
		}
	}
	Fprintln(out, string(ans))
}

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

package main
import "fmt"
import "bufio"
import "os"

var input *bufio.Reader
const p int64 = int64(203)
const MOD int64 = int64(1000000007)
var hash [1000005]int64
var rev [1000005]int64
var pw [1000005]int64

func pow(a, n int64) int64 {
    ans := int64(1)
    for ; n>0; n/=2 {
        if n%2==1 {
            ans = ans * a % MOD
        }
        a = a * a % MOD
    }
    return ans
}

func gao(t []byte, length int) {
    for i, j := range t {
        hash[i+length] = pw[length+i]*int64(j)%MOD
        if i+length > 0 {
            hash[i+length] += hash[i+length-1]
            hash[i+length] %= MOD
        }
    }
}

func gaogao(s string) []int64 {
    ans := make([]int64, len(s))
    for i, j := range s {
        ans[i] = pw[i]*int64(j)%MOD
        if i>0 {
            ans[i] += ans[i-1]
            ans[i] %= MOD
        }
    }
    return ans
}

func gethash(length, lhash int) int64 {
    if length > lhash {
        return -1
    } else if length == lhash {
        return hash[lhash-1]
    } else {
        return (hash[lhash-1] - hash[lhash-length-1] + MOD) * rev[lhash-length] % MOD
    }
}

func main(){
    input = bufio.NewReader(os.Stdin)

    rev[0] = 1; pw[0] = 1
    rev[1] = pow(p, MOD-2)
    pw[1] = p
    for i:=2; i<=1000002; i++ {
        rev[i] = rev[i-1] * rev[1] % MOD
        pw[i] = pw[i-1] * p %MOD
    }

    var s, t string
    var n int
    fmt.Fscanf(input, "%d\n%s", &n, &s)
    gao([]byte(s), 0)
    ans := []byte(s)

    for i:=1; i<n; i++ {
        fmt.Fscanf(input, "%s", &t)
        h := gaogao(t)
        flag := false
        /*
        fmt.Println(string(ans))
        for j:=0; j<len(ans); j++ {
            fmt.Printf("%d ", hash[j])
        }
        fmt.Println("")
        */
        for j:=len(h)-1; j>=0; j-- {
            //fmt.Printf("%d %d %d %d\n", i, j, h[j], gethash(j+1, len(ans)))
            if h[j] == gethash(j+1, len(ans)) {
                gao([]byte(t[j+1:len(t)]), len(ans))
                for k:=j+1; k<len(t); k++ {
                    ans = append(ans, t[k])
                }
                flag = true
                break
            }
        }
        if !flag {
            gao([]byte(t[0:len(t)]), len(ans))
            for k:=0; k<len(t); k++ {
                ans = append(ans, t[k])
            }
        }
    }

    fmt.Println(string(ans))

}

package main
import "fmt"
import "bufio"
import "os"

var input *bufio.Reader
const p int64 = int64(203)
const MOD int64 = int64(1000000007)
const N int = 1000005
var hash, rev, pw [N]int64

func pow(a, n int64) int64 {
    ans := int64(1)
    for ; n>0; n/=2 {
        if n%2==1 {
            ans = ans * a % MOD
        }
        a = a * a % MOD
    }
    return ans
}

func gao(t []byte, length int) {
    for i, j := range t {
        hash[i+length] = pw[length+i]*int64(j)%MOD
        if i+length > 0 {
            hash[i+length] += hash[i+length-1]
            hash[i+length] %= MOD
        }
    }
}

func gaogao(s string) []int64 {
    ans := make([]int64, len(s))
    for i, j := range s {
        ans[i] = pw[i]*int64(j)%MOD
        if i>0 {
            ans[i] += ans[i-1]
            ans[i] %= MOD
        }
    }
    return ans
}

func gethash(length, lhash int) int64 {
    if length > lhash {
        return -1
    } else if length == lhash {
        return hash[lhash-1]
    } else {
        return (hash[lhash-1] - hash[lhash-length-1] + MOD) * rev[lhash-length] % MOD
    }
}

func main(){
    input = bufio.NewReader(os.Stdin)

    rev[0] = 1; pw[0] = 1
    rev[1] = pow(p, MOD-2); pw[1] = p
    for i:=2; i<=1000002; i++ {
        rev[i] = rev[i-1] * rev[1] % MOD
        pw[i] = pw[i-1] * p %MOD
    }

    var s, t string
    var n int
    fmt.Fscanf(input, "%d\n%s", &n, &s)
    gao([]byte(s), 0)
    ans := []byte(s)

    for i:=1; i<n; i++ {
        fmt.Fscanf(input, "%s", &t)
        h := gaogao(t)
        flag := false
        for j:=len(h)-1; j>=0; j-- {
            if h[j] == gethash(j+1, len(ans)) {
                gao([]byte(t[j+1:]), len(ans))
                for k:=j+1; k<len(t); k++ {
                    ans = append(ans, t[k])
                }
                flag = true
                break
            }
        }
        if !flag {
            gao([]byte(t[:]), len(ans))
            for k:=0; k<len(t); k++ {
                ans = append(ans, t[k])
            }
        }
    }

    fmt.Println(string(ans))

}

package main

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

func Sol1200E(reader io.Reader, writer io.Writer) {
	min := func(a, b int) int {
		if a <= b {
			return a
		}
		return b
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var n int
	var w, prevW string
	Fscan(in, &n, &prevW)

	Fprint(out, prevW)
	for i := 0; i < n; i++ {
		Fscan(in, &w)
		common := min(len(prevW), len(w))
		for ; common > 0; common-- {
			if prevW[len(prevW)-common:] == w[:common] {
				break
			}
		}
		Fprint(out, w[common:])
		prevW = w
	}
}

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


It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds.Polar bears Alice and Bob each have caught some fish, and they are guessing who has the larger sum of weight of the fish he/she's caught. Given the type of the fish they've caught, determine whether it is possible that the fish caught by Alice has a strictly larger total weight than Bob's. In other words, does there exist a sequence of weights wi (not necessary integers), such that the fish caught by Alice has a strictly larger total weight?

The first line contains three integers n, m, k (1 ≤ n, m ≤ 105, 1 ≤ k ≤ 109) — the number of fish caught by Alice and Bob respectively, and the number of fish species. The second line contains n integers each from 1 to k, the list of fish type caught by Alice. The third line contains m integers each from 1 to k, the list of fish type caught by Bob. Note that one may have caught more than one fish for a same species.

Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise.

NoteIn the first sample, if w1 = 1, w2 = 2, w3 = 2.5,  then Alice has a total of 2 + 2 + 2 = 6 weight units, while Bob only has 1 + 1 + 2.5 = 4.5.In the second sample, the fish that Alice caught is a subset of Bob's. Therefore, the total weight of Bob’s fish is always not less than the total weight of Alice’s fish.

package main

import "os"
import "bufio"
import "strconv"
import "sort"

func main(){
	var n, m, k int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	r.Scan()
	m, _ = strconv.Atoi(r.Text())
	r.Scan()
	k, _ = strconv.Atoi(r.Text())
	a := make([]int, 111111)
	b := make([]int, 111111)
	k = k
	for i:=0; i<n; i++ {
		r.Scan()
		a[i], _ = strconv.Atoi(r.Text())
	}
	for i:=0; i<m; i++ {
		r.Scan()
		b[i], _ = strconv.Atoi(r.Text())
	}
	sort.Ints(a)
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sort.Ints(b)
	sort.Sort(sort.Reverse(sort.IntSlice(b)))
	for j:=0; j<n; j++ {
		if a[j] > b[j] {
			w.WriteString("YES\n")
			w.Flush()
			return
		}
	}
	w.WriteString("NO\n")
	w.Flush()
}

package main

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

func main() {
	var (
		na, nb, k, i int32
		a, b         sort.IntSlice
		in           *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &na)
	fmt.Fscan(in, &nb)
	fmt.Fscan(in, &k)

	a = make(sort.IntSlice, na, na)
	b = make(sort.IntSlice, nb, nb)

	for i = 0; i < na; i++ {
		fmt.Fscan(in, &a[i])
	}
	for i = 0; i < nb; i++ {
		fmt.Fscan(in, &b[i])
	}

	a.Sort()
	b.Sort()

	na--
	nb--
	for na >= 0 && nb >= 0 {
		if a[na] > b[nb] {
			break
		}
		na--
		nb--
	}

	if na < 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

package main

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

func Readint(r *bufio.Reader) int32 {
	var c byte = 0
	for {
		c, _ = r.ReadByte()
		if c >= '0' && c <= '9' {
			break
		}
	}
	var ret int32 = 0
	for {
		ret = 10*ret + int32(c-'0')
		c, _ = r.ReadByte()
		if c < '0' || c > '9' {
			break
		}
	}
	return ret
}

func main() {
	var (
		na, nb, k, i int32
		a, b         sort.IntSlice
		in           *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)

	na = Readint(in)
	nb = Readint(in)
	k = Readint(in)
	k++

	a = make(sort.IntSlice, na, na)
	b = make(sort.IntSlice, nb, nb)

	for i = 0; i < na; i++ {
		a[i] = int(Readint(in))
	}
	for i = 0; i < nb; i++ {
		b[i] = int(Readint(in))
	}

	a.Sort()
	b.Sort()

	na--
	nb--
	for na >= 0 && nb >= 0 {
		if a[na] > b[nb] {
			break
		}
		na--
		nb--
	}

	if na < 0 {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}

}

// 297B
package main

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

func main() {
	var i, n, m, k int
	var a, b sort.IntSlice
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	fmt.Fscan(in, &m)
	fmt.Fscan(in, &k)
	a = make(sort.IntSlice, n, n)
	b = make(sort.IntSlice, m, m)
	for i = 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	for i = 0; i < m; i++ {
		fmt.Fscan(in, &b[i])
	}
	a.Sort()
	b.Sort()
	for n != 0 && m != 0 && a[n-1] <= b[m-1] {
		n--
		m--
	}

	if n != 0 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

// 297B
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m, k int
	a := make([]int, 100100)
	b := make([]int, 100100)
	fmt.Scan(&n, &m, &k)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&b[i])
	}
	sort.Ints(a)
	sort.Ints(b)
	for n != 0 && m != 0 && a[n-1] <= b[m-1] {
		n--
		m--
	}

	if n != 0 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

// 297B
package main

import (
	"fmt"
	"sort"
)

func main() {
	var i, j, n, m, k int
	a := make([]int, 100100)
	b := make([]int, 100100)
	fmt.Scan(&n, &m, &k)
	for i = 0; i < n; i++ {
		fmt.Scan(&a[i])
		sort.Ints(a)
	}
	for i = 0; i < m; i++ {
		fmt.Scan(&b[i])
		sort.Ints(b)
	}
	i, j = 0, 0
	for i <= n && j <= m {
		if a[n-i] == b[m-j] {
			i++
			j++
		} else if a[n-i] > b[m-j] {
			i++
		} else {
			j++
		}
		if i > j {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

// 297B
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m, k int
	a := make([]int, 100100)
	b := make([]int, 100100)
	fmt.Scan(&n, &m, &k)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(b[i])
	}
	sort.Ints(a)
	sort.Ints(b)
	for n != 0 && m != 0 && a[n-1] <= b[m-1] {
		n--
		m--
	}

	if n != 0 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

// 297B
package main

import (
	"fmt"
	"sort"
)

func main() {
	var x, y, i, n, m, k int
	a := make([]int, 100100)
	b := make([]int, 100100)
	fmt.Scan(&n, &m, &k)
	for i = 0; i < n; i++ {
		fmt.Scan(&a[i])
		sort.Ints(a)
	}
	for i = 0; i < m; i++ {
		fmt.Scan(&b[i])
		sort.Ints(b)
	}
	x, y = 0, 0
	for x <= n && y <= m {
		if a[n-x] == b[m-y] {
			x++
			y++
		} else if a[n-x] > b[m-y] {
			x++
		} else {
			y++
		}
		if x > y {
			fmt.Println("YES")
			return
		}
	}
	fmt.Println("NO")
}

// 297B
package main

import (
	"fmt"
	"sort"
)

func main() {
	var i, n, m, k int
	a := make([]int, 100100)
	b := make([]int, 100100)
	fmt.Scan(&n, &m, &k)
	for i = 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i = 0; i < m; i++ {
		fmt.Scan(&b[i])
	}
	sort.Ints(a)
	sort.Ints(b)
	l := 1
	for i = 0; i < n; i++ {
		for l <= m && a[i] > b[l] {
			l++
		}
		if l > m {
			break
		}
		l++
	}
	if i == n+1 {
		fmt.Print("NO")
	} else {
		fmt.Print("YES")
	}
}


In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor.To begin with friends learned the rules: in the race there are n sections of equal length and m participants. The participants numbered from 1 to m. About each participant the following is known: li — the number of the starting section,  ri — the number of the finishing section (li ≤ ri), ti — the time a biathlete needs to complete an section of the path, ci — the profit in roubles. If the i-th sportsman wins on one of the sections, the profit will be given to the man who had placed a bet on that sportsman. The i-th biathlete passes the sections from li to ri inclusive. The competitor runs the whole way in (ri - li + 1)·ti time units. It takes him exactly ti time units to pass each section. In case of the athlete's victory on k sections the man who has betted on him receives k·ci roubles.In each section the winner is determined independently as follows: if there is at least one biathlete running this in this section, then among all of them the winner is the one who has ran this section in minimum time (spent minimum time passing this section). In case of equality of times the athlete with the smaller index number wins. If there are no participants in this section, then the winner in this section in not determined. We have to say that in the summer biathlon all the participants are moving at a constant speed.We should also add that Nikita can bet on each section and on any contestant running in this section.Help the friends find the maximum possible profit.

The first line contains two integers n and m (1 ≤ n, m ≤ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 ≤ li ≤ ri ≤ n, 1 ≤ ti, ci ≤ 1000).

Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.

NoteIn the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles.In the second test the optimal bet is: on 1 and 5 sections on biathlete 1, in the 2-4 sections on biathlete 2, in the 6-7 sections on athlete 4. There is no winner in the 8 section. Total: profit of 10 rubles for 1 section, the profit of 15 rubles for 2,3,4 section, profit of 10 rubles for a 5 section, profit of 20 rubles for 6, 7 section. Total profit 105 rubles.

package main

import "fmt"

const NMAX = 1e2 + 2;

var f[NMAX][2] int

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  for i := 0; i <= n; i++ {
    f[i][0] = 10000
    f[i][1] = 0
  }
  for i := 0; i < m; i++ {
    var l, r, t, c int
    fmt.Scan(&l, &r, &t, &c)
    for j := l; j <= r; j++ {
      if f[j][0] > t {
        f[j][0] = t
        f[j][1] = c
      }
    }
  }
  var res int
  res = 0
  for i := 1; i <= n; i++ {
    res += f[i][1]
  }
  fmt.Println(res)
}

package main

import "fmt"

const NMAX = 1e2 + 2;

var f[NMAX][2] int

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  for i := 0; i <= n; i++ {
    f[i][0] = 1000
    f[i][1] = 0
  }
  for i := 0; i < m; i++ {
    var l, r, t, c int
    fmt.Scan(&l, &r, &t, &c)
    for j := l; j <= r; j++ {
      if f[j][0] > t {
        f[j][0] = t
        f[j][1] = c
      }
    }
  }
  var res int
  res = 0
  for i := 1; i <= n; i++ {
    res += f[i][1]
  }
  fmt.Println(res)
}

package main

import "fmt"

const N = 1e2 + 2;

var f[N][2] int

func main() {
  var n, m int
  fmt.Scan(&n, &m)
  for i := 0; i <= n; i++ {
    f[i][0] = 1000
    f[i][1] = 0
  }
  for i := 0; i < m; i++ {
    var l, r, t, c int
    fmt.Scan(&l, &r, &t, &c)
    for j := l; j <= r; j++ {
      if f[j][0] > t {
        f[j][0] = t
        f[j][1] = c
      }
    }
  }
  var res int
  res = 0
  for i := 1; i <= n; i++ {
    res += f[i][1]
  }
  fmt.Println(res)
}


Hr0d1y has $$$q$$$ queries on a binary string $$$s$$$ of length $$$n$$$. A binary string is a string containing only characters '0' and '1'.A query is described by a pair of integers $$$l_i$$$, $$$r_i$$$ $$$(1 \leq l_i \lt r_i \leq n)$$$. For each query, he has to determine whether there exists a good subsequence in $$$s$$$ that is equal to the substring $$$s[l_i\ldots r_i]$$$.   A substring $$$s[i\ldots j]$$$ of a string $$$s$$$ is the string formed by characters $$$s_i s_{i+1} \ldots s_j$$$. String $$$a$$$ is said to be a subsequence of string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deleting some characters without changing the order of the remaining characters. A subsequence is said to be good if it is not contiguous and has length $$$\ge 2$$$. For example, if $$$s$$$ is "1100110", then the subsequences $$$s_1s_2s_4$$$ ("1100110") and $$$s_1s_5s_7$$$ ("1100110") are good, while $$$s_1s_2s_3$$$ ("1100110") is not good. Can you help Hr0d1y answer each query?

The first line of the input contains a single integer $$$t$$$ ($$$1\leq t \leq 100$$$) — the number of test cases. The description of each test case is as follows. The first line contains two integers $$$n$$$ ($$$2 \leq n \leq 100$$$) and $$$q$$$ ($$$1\leq q \leq 100$$$) — the length of the string and the number of queries.  The second line contains the string $$$s$$$. The $$$i$$$-th of the next $$$q$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \leq l_i \lt r_i \leq n$$$).

For each test case, output $$$q$$$ lines. The $$$i$$$-th line of the output of each test case should contain "YES" if there exists a good subsequence equal to the substring $$$s[l_i...r_i]$$$, and "NO" otherwise. You may print each letter in any case (upper or lower).

NoteIn the first test case,   $$$s[2\ldots 4] = $$$ "010". In this case $$$s_1s_3s_5$$$ ("001000") and $$$s_2s_3s_6$$$ ("001000") are good suitable subsequences, while $$$s_2s_3s_4$$$ ("001000") is not good.  $$$s[1\ldots 3] = $$$ "001". No suitable good subsequence exists.  $$$s[3\ldots 5] = $$$ "100". Here $$$s_3s_5s_6$$$ ("001000") is a suitable good subsequence.

package main

import (
	"fmt"
)

const N int = 1e2 + 5

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

	for tc := 1; tc <= t; tc++ {
		var length, query int
		var str string
		fmt.Scan(&length, &query, &str)

		str = "#" + str
		length = len(str)

		var prefixSum [N][2]int
		for i := 1; i < length; i++ {
			for j := 0; j <= 1; j++ {
				if int(str[i]-'0') == j {
					prefixSum[i][j]++
				}
				prefixSum[i][j] += prefixSum[i-1][j]
			}
		}

		ok := func(l int, r int, id int) bool {
			if l > r || l < 1 || r >= length {
				return false
			}
			if (prefixSum[r][id] - prefixSum[l-1][id]) > 0 {
				return true
			} else {
				return false
			}
		}

		for query > 0 {
			var l, r int
			fmt.Scan(&l, &r)
			if ok(1, l-1, int(str[l]-'0')) || ok(r+1, length-1, int(str[r]-'0')) {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
			query--
		}
	}
}

package main

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

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

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

func solveA() {
	var n int
	scanf("%d\n", &n)
	ans := 0
	if n % 2 == 0 {
		if n >= 4 {
			ans = 2
		} else if n == 2 {
			ans = 1
		}
	} else {
		if n >= 5 {
			ans = 3
		} else if n == 3 {
			ans = 2
		}
	}
	printf("%d\n", ans)
}

type point struct {
	left int
	right int
}

func solveB() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	var s string
	scanf("%s\n", &s)
	var P0, P1 point = point{n, -1}, point{n, -1}
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			P0.right = i
		} else {
			P1.right = i
		}
	}

	for i := n - 1; i >= 0; i-- {
		if s[i] == '0' {
			P0.left = i
		} else {
			P1.left = i
		}
	}

	for ; q > 0; q-- {
		var l, r int
		scanf("%d %d\n", &l, &r)
		l--
		r--
		ans := "NO"
		if (s[l] == '0' && P0.left < l || s[l] == '1' && P1.left < l) ||
			(s[r] == '0' && P0.right > r || s[r] == '1' && P1.right > r) {
			ans = "YES"
		}

		printf("%s\n", ans)
	}
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveB()
	}
}

package main
import (
	"os"
	"fmt"
	"bufio"
)
var rd = bufio.NewReader(os.Stdin)
func main() {
	t := 0
	fmt.Fscan(rd, &t)
	for tc := 0; tc < t; tc++ {
		n, q := 0, 0
		s := ""
		fmt.Fscan(rd, &n, &q, &s)
		for i := 0; i < q; i++ {
			l, r := 0, 0
			fmt.Fscan(rd, &l, &r)
			l--; r--
			ok := false
			for j := 0; j < l && !ok; j++ {
				if s[j] == s[l] {
					ok = true
				}
			}
			for j := r + 1; j < n && !ok; j++ {
				if s[j] == s[r] {
					ok = true
				}
			}
			if ok {
				fmt.Println("YES")
			} else {
				fmt.Println("NO")
			}
		}
	}
}


Iahub wants to enhance his multitasking abilities. In order to do this, he wants to sort n arrays simultaneously, each array consisting of m integers.Iahub can choose a pair of distinct indices i and j (1 ≤ i, j ≤ m, i ≠ j). Then in each array the values at positions i and j are swapped only if the value at position i is strictly greater than the value at position j.Iahub wants to find an array of pairs of distinct indices that, chosen in order, sort all of the n arrays in ascending or descending order (the particular order is given in input). The size of the array can be at most  (at most  pairs). Help Iahub, find any suitable array.

The first line contains three integers n (1 ≤  n ≤ 1000), m (1 ≤ m ≤  100) and k. Integer k is 0 if the arrays must be sorted in ascending order, and 1 if the arrays must be sorted in descending order. Each line i of the next n lines contains m integers separated by a space, representing the i-th array. For each element x of the array i, 1 ≤ x ≤ 106 holds.

On the first line of the output print an integer p, the size of the array (p can be at most ). Each of the next p lines must contain two distinct integers i and j (1 ≤ i, j ≤ m, i ≠ j), representing the chosen indices. If there are multiple correct answers, you can print any.

NoteConsider the first sample. After the first operation, the arrays become [1, 3, 2, 5, 4] and [1, 2, 3, 4, 5]. After the second operation, the arrays become [1, 2, 3, 5, 4] and [1, 2, 3, 4, 5]. After the third operation they become [1, 2, 3, 4, 5] and [1, 2, 3, 4, 5].

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
)

func main() {
	var n, m, k int
	fmt.Fscan(reader, &n, &m, &k)
	fmt.Println(m * (m - 1) / 2)
	if k == 0 {
		for i := 0; i < m; i++ {
			for j := 0; j < m-i-1; j++ {
				fmt.Println(j+1, j+2)
			}
		}
	} else {
		for i := 0; i < m; i++ {
			for j := m - 1; j >= 1+i; j-- {
				fmt.Println(j+1, j)
			}
		}
	}
}

package main
import "fmt"

func main(){
	var n,m,k int
	fmt.Scan(&n,&m,&k)
	s:=make([]int,n)
	for i:=0;i<n;i++ { fmt.Scan(&s[i])}

	fmt.Println(m*(m-1)/2)
	for u:=1; u<=m; u++ {
		for i:= u+1; i<=m; i++{
			if k==0 {
				fmt.Println(u,"",i)
			}else{
				fmt.Println(i,"",u)
			}
		}
	}

}

package main
import "fmt"

func main(){
	var n,m,k int
	fmt.Scan(&n,&m,&k)
	s:=make([]int,n)
	for i:=0;i<n;i++ { fmt.Scan(&s[i])}

	fmt.Println(m*(m-1)/2)
	for u:=1; u<=m; u++ {
		for i:= u+1; i<=m; i++{
			if k==0 {
				fmt.Println(u,i)
			}else{
				fmt.Println(i,u)
			}
		}
	}

}

// 384B
package main

import (
	"fmt"
)

func main() {
	var n, m, k int
	fmt.Scan(&n, &m, &k)
	fmt.Println((m - 1) * (m) / 2)
	for i := 1; i <= m; i++ {
		for j := i + 1; j <= m; j++ {
			if k == 0 {
				fmt.Println(i, j)
			} else {
				fmt.Println(j, i)
			}
		}
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
)

func main() {
	var n, m, k int
	fmt.Fscan(reader, &n, &m, &k)
	fmt.Println(m * (m - 1) / 2)
	if k == 0 {
		for i := 0; i < m; i++ {
			for j := i; j+1 < m; j++ {
				fmt.Println(j+1, j+2)
			}
		}
	} else {
		for i := m - 1; i >= 0; i-- {
			for j := i; j >= 1; j-- {
				fmt.Println(j+1, j)
			}
		}
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
)

func main() {
	var n, m, k int
	fmt.Fscan(reader, &n, &m, &k)
	fmt.Println(m * (m - 1) / 2)
	if k == 0 {
		for i := 0; i < m; i++ {
			for j := 0; j < m-i; j++ {
				fmt.Println(j+1, j+2)
			}
		}
	} else {
		for i := 0; i < m; i++ {
			for j := m - 1; j >= 1+i; j-- {
				fmt.Println(j+1, j)
			}
		}
	}
}

package main
import "fmt"

func main(){
	var n,m,k int
	fmt.Scan(&n,&m,&k)
	s:=make([]int,n)
	for i:=0;i<n;i++ { fmt.Scan(&s[i])}

	fmt.Println(m*(m-1)/2)
	for u:=0; u<=m; u++ {
		for i:= u+1; i<=m; i++{
			if k==0 {
				fmt.Println(u,"",i)
			}else{
				fmt.Println(i,"",u)
			}
		}
	}

}