Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string.More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print  - 1.

The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters.

Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.

package main

import (
    "bytes"
    "fmt"
)

func g ( s1, s2 string ) ( ret int ) {
    for i, len := 0, len(s1); i < len; i++ {
        if s1[i] == s2[i] {
            ret += 1
        }
    }
    return
}

func randByte ( a, b byte ) ( ret byte ) {
    for ret = 'a'; ret <= 'z' && (ret == a || ret == b); ret++ {}
    return
}

func solve ( s1, s2 string, cnt int ) (ret string) {
    c1 := cnt
    c2 := cnt
    var buf bytes.Buffer
    for i, n := 0, len(s1); i < n; i++ {
        if s1[i] != s2[i] {
            if c1 > 0 {
                buf.WriteByte(s1[i])
                c1--
            } else if c2 > 0 {
                buf.WriteByte(s2[i])
                c2--
            } else {
                buf.WriteByte(randByte(s1[i],s2[i]))
            }
        } else {
            if cnt >= 0 {
                buf.WriteByte(s1[i])
            } else {
                buf.WriteByte(randByte(s1[i],s2[i]))
                cnt++
            }
        }
    }
    return buf.String()
}

func main() {
    var x, y int
    var s1, s2 string
    fmt.Scan(&x,&y,&s1,&s2)
    y = x - y
    eq := g(s1,s2);

    if x - eq >= 2 * ( y - eq ) {
        fmt.Println(solve(s1,s2,y-eq))
    } else {
        fmt.Println(-1)
    }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF584C(_r io.Reader, out io.Writer) {
	var n, needSame int
	var s, t []byte
	Fscan(bufio.NewReader(_r), &n, &needSame, &s, &t)
	needSame = n - needSame
	same := 0
	for i, b := range s {
		if b == t[i] {
			same++
		}
	}
	ans := make([]byte, n)
	if needSame <= same {
		for i, b := range s {
			c := t[i]
			if needSame > 0 && b == c {
				ans[i] = b
				needSame--
				continue
			}
			ans[i] = 'a'
			if ans[i] == b || ans[i] == c {
				ans[i]++
			}
			if ans[i] == b || ans[i] == c {
				ans[i]++
			}
		}
	} else if (needSame-same)*2 > n-same {
		Fprint(out, -1)
		return
	} else {
		needSame = (needSame - same) * 2
		cnt := 0
		for i, b := range s {
			c := t[i]
			if b == c {
				ans[i] = b
				continue
			}
			if cnt*2 < needSame {
				cnt++
				ans[i] = b
			} else if cnt < needSame {
				cnt++
				ans[i] = c
			} else {
				ans[i] = 'a'
				if ans[i] == b || ans[i] == c {
					ans[i]++
				}
				if ans[i] == b || ans[i] == c {
					ans[i]++
				}
			}
		}
	}
	Fprint(out, string(ans))
}

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

package main

import (
	"fmt"
)

var (
	n, t int
	a, b string
)

func getDiff(a byte, b byte) byte {
	for i := 'a'; i <= 'b'; i++ {
		if byte(i) != a && byte(i) != b {
			return byte(i)
		}
	}
	return byte('c')
}

func solve() string {
	c := []byte(a)
	diffPos := make([]int, 0, n)
	samePos := make([]int, 0, n)
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			diffPos = append(diffPos, i)
		} else {
			samePos = append(samePos, i)
		}
	}
	lenDiff := len(diffPos)
	lenSame := len(samePos)
	needSame := n - t
	if needSame <= lenSame {
		for i := needSame; i < len(samePos); i++ {
			pos := samePos[i]
			c[pos] = getDiff(a[pos], b[pos])
		}
		for i := 0; i < lenDiff; i++ {
			pos := diffPos[i]
			c[pos] = getDiff(a[pos], b[pos])
		}
		return string(c)
	}
	needSame -= lenSame
	if needSame*2 > lenDiff {
		return "-1"
	}
	for i := 0; i < needSame; i++ {
		c[diffPos[i]] = a[diffPos[i]]
		c[diffPos[i+needSame]] = b[diffPos[i+needSame]]
	}
	for i := needSame * 2; i < len(diffPos); i++ {
		pos := diffPos[i]
		c[pos] = getDiff(a[pos], b[pos])
	}
	return string(c)
}

func main() {
	fmt.Scanf("%d %d ", &n, &t)
	fmt.Scanln(&a)
	fmt.Scanln(&b)
	//fmt.Println(" ", a, " ", b)
	fmt.Println(solve())
}

package main

import (
	"fmt"
)

var (
	n, t int
	a, b string
)

func getDiff(a byte, b byte) byte {
	for i := 'a'; i <= 'b'; i++ {
		if byte(i) != a && byte(i) != b {
			return byte(i)
		}
	}
	return byte('c')
}

func solve() string {
	c := []byte(a)
	diffPos := make([]int, 0, n)
	samePos := make([]int, 0, n)
	for i := 0; i < n; i++ {
		if a[i] != b[i] {
			diffPos = append(diffPos, i)
		} else {
			samePos = append(samePos, i)
		}
	}
	lenDiff := len(diffPos)
	lenSame := len(samePos)
	needSame := n - t
	if needSame <= lenSame {
		for i := needSame; i < lenSame; i++ {
			pos := samePos[i]
			c[pos] = getDiff(a[pos], b[pos])
		}
		for i := 0; i < lenDiff; i++ {
			pos := diffPos[i]
			c[pos] = getDiff(a[pos], b[pos])
		}
		return string(c)
	}
	needSame -= lenSame
	if needSame*2 > lenDiff {
		return "-1"
	}
	for i := 0; i < needSame; i++ {
		c[diffPos[i]] = a[diffPos[i]]
		c[diffPos[i+needSame]] = b[diffPos[i+needSame]]
	}
	for i := needSame * 2; i < lenDiff; i++ {
		pos := diffPos[i]
		c[pos] = getDiff(a[pos], b[pos])
	}
	return string(c)
}

func main() {
	fmt.Scanf("%d %d ", &n, &t)
	fmt.Scanln(&a)
	fmt.Scanln(&b)
	//fmt.Println(" ", a, " ", b)
	fmt.Println(solve())
}

package main

import (
    "fmt"
)

func g ( s1, s2 string ) ( ret int ) {
    for i, len := 0, len(s1); i < len; i++ {
        if s1[i] == s2[i] {
            ret += 1
        }
    }
    return
}

func randByte ( a, b byte ) ( ret byte ) {
    for ret = 'a'; ret <= 'z' && (ret == a || ret == b); ret++ {}
    return
}

func solve ( s1, s2 string, cnt int ) (ret string) {
    c1 := cnt
    c2 := cnt
    for i, n := 0, len(s1); i < n; i++ {
        if s1[i] != s2[i] {
            if c1 > 0 {
                ret += string(s1[i])
                c1--
            } else if c2 > 0 {
                ret += string(s2[i])
                c2--
            } else {
                ret += string(randByte(s1[i],s2[i]))
            }
        } else {
            ret += string(s1[i])
        }
    }
    return
}

func main() {
    var x, y int
    var s1, s2 string
    fmt.Scan(&x,&y,&s1,&s2)
    y = x - y

    fmt.Println(g(s1,s2),y,y-g(s1,s2))

    if x - g(s1,s2) >= 2 * ( y - g(s1,s2) ) {
        fmt.Println(solve(s1,s2,y-g(s1,s2)))
    } else {
        fmt.Println(-1)
    }
}

package main

import (
    "fmt"
)

func g ( s1, s2 string ) ( ret int ) {
    for i, len := 0, len(s1); i < len; i++ {
        if s1[i] == s2[i] {
            ret += 1
        }
    }
    return
}

func randByte ( a, b byte ) ( ret byte ) {
    for ret = 'a'; ret <= 'z' && (ret == a || ret == b); ret++ {}
    return
}

func solve ( s1, s2 string, cnt int ) (ret string) {
    c1 := cnt
    c2 := cnt
    for i, n := 0, len(s1); i < n; i++ {
        if s1[i] != s2[i] {
            if c1 > 0 {
                ret += string(s1[i])
                c1--
            } else if c2 > 0 {
                ret += string(s2[i])
                c2--
            } else {
                ret += string(randByte(s1[i],s2[i]))
            }
        } else {
            if cnt >= 0 {
                ret += string(s1[i])
            } else {
                ret += string(randByte(s1[i],s2[i]))
            }
        }
    }
    return
}

func main() {
    var x, y int
    var s1, s2 string
    fmt.Scan(&x,&y,&s1,&s2)
    y = x - y

    if x - g(s1,s2) >= 2 * ( y - g(s1,s2) ) {
        fmt.Println(solve(s1,s2,y-g(s1,s2)))
    } else {
        fmt.Println(-1)
    }
}

package main

import (
    "fmt"
)

func g ( s1, s2 string ) ( ret int ) {
    for i, len := 0, len(s1); i < len; i++ {
        if s1[i] == s2[i] {
            ret += 1
        }
    }
    return
}

func randByte ( a, b byte ) ( ret byte ) {
    for ret = 'a'; ret <= 'z' && (ret == a || ret == b); ret++ {}
    return
}

func solve ( s1, s2 string, cnt int ) (ret string) {
    c1 := cnt
    c2 := cnt
    for i, n := 0, len(s1); i < n; i++ {
        if s1[i] != s2[i] {
            if c1 > 0 {
                ret += string(s1[i])
                c1--
            } else if c2 > 0 {
                ret += string(s2[i])
                c2--
            } else {
                ret += string(randByte(s1[i],s2[i]))
            }
        } else {
            if cnt > 0 {
                ret += string(s1[i])
            } else {
                ret += string(randByte(s1[i],s2[i]))
            }
        }
    }
    return
}

func main() {
    var x, y int
    var s1, s2 string
    fmt.Scan(&x,&y,&s1,&s2)
    y = x - y

    if x - g(s1,s2) >= 2 * ( y - g(s1,s2) ) {
        fmt.Println(solve(s1,s2,y-g(s1,s2)))
    } else {
        fmt.Println(-1)
    }
}

package main

import (
    "fmt"
)

func g ( s1, s2 string ) ( ret int ) {
    for i, len := 0, len(s1); i < len; i++ {
        if s1[i] == s2[i] {
            ret += 1
        }
    }
    return
}

func randByte ( a, b byte ) ( ret byte ) {
    for ret = 'a'; ret <= 'z' && (ret == a || ret == b); ret++ {}
    return
}

func solve ( s1, s2 string, cnt int ) (ret string) {
    c1 := cnt
    c2 := cnt
    for i, n := 0, len(s1); i < n; i++ {
        if s1[i] != s2[i] {
            if c1 > 0 {
                ret += string(s1[i])
                c1--
            } else if c2 > 0 {
                ret += string(s2[i])
                c2--
            } else {
                ret += string(randByte(s1[i],s2[i]))
            }
        } else {
            ret += string(s1[i])
        }
    }
    return
}

func main() {
    var x, y int
    var s1, s2 string
    fmt.Scan(&x,&y,&s1,&s2)
    y = x - y

    if x - g(s1,s2) >= 2 * ( y - g(s1,s2) ) {
        fmt.Println(solve(s1,s2,y-g(s1,s2)))
    } else {
        fmt.Println(-1)
    }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF584C(_r io.Reader, out io.Writer) {
	var n, needSame int
	var s, t []byte
	Fscan(bufio.NewReader(_r), &n, &needSame, &s, &t)
	needSame = n - needSame
	same := 0
	for i, b := range s {
		if b == t[i] {
			same++
		}
	}
	ans := make([]byte, n)
	if needSame <= same {
		for i, b := range s {
			c := t[i]
			if needSame > 0 && b == c {
				ans[i] = b
				needSame--
				continue
			}
			ans[i] = 'a'
			if ans[i] == b || ans[i] == c {
				ans[i]++
			}
			if ans[i] == b || ans[i] == c {
				ans[i]++
			}
		}
	} else if (needSame-same)*2 != n-same {
		Fprint(out, -1)
		return
	} else {
		needSame -= same
		for i, b := range s {
			c := t[i]
			if b == c {
				ans[i] = b
				continue
			}
			if needSame > 0 {
				needSame--
				ans[i] = b
			} else {
				ans[i] = c
			}
		}
	}
	Fprint(out, string(ans))
}

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


Mitya and Vasya are playing an interesting game. They have a rooted tree with $$$n$$$ vertices, and the vertices are indexed from $$$1$$$ to $$$n$$$. The root has index $$$1$$$. Every other vertex $$$i \ge 2$$$ has its parent $$$p_i$$$, and vertex $$$i$$$ is called a child of vertex $$$p_i$$$.There are some cookies in every vertex of the tree: there are $$$x_i$$$ cookies in vertex $$$i$$$. It takes exactly $$$t_i$$$ time for Mitya to eat one cookie in vertex $$$i$$$. There is also a chip, which is initially located in the root of the tree, and it takes $$$l_i$$$ time to move the chip along the edge connecting vertex $$$i$$$ with its parent.Mitya and Vasya take turns playing, Mitya goes first.  Mitya moves the chip from the vertex, where the chip is located, to one of its children.  Vasya can remove an edge from the vertex, where the chip is located, to one of its children. Vasya can also decide to skip his turn.   Mitya can stop the game at any his turn. Once he stops the game, he moves the chip up to the root, eating some cookies along his way. Mitya can decide how many cookies he would like to eat in every vertex on his way. The total time spent on descend, ascend and eating cookies should not exceed $$$T$$$. Please note that in the end of the game the chip is always located in the root of the tree: Mitya can not leave the chip in any other vertex, even if he has already eaten enough cookies — he must move the chip back to the root (and every move from vertex $$$v$$$ to its parent takes $$$l_v$$$ time).Find out what is the maximum number of cookies Mitya can eat, regardless of Vasya's actions.

The first line contains two integers $$$n$$$ and $$$T$$$ — the number of vertices in the tree and the time he has to accomplish his task ($$$2\le n \le 10^5$$$; $$$1\le T\le10^{18}$$$). The second line contains $$$n$$$ integers $$$x_1$$$, $$$x_2$$$, ..., $$$x_n$$$ — number of cookies located in the corresponding vertex ($$$1\le x_i\le10^6$$$). The third line contains $$$n$$$ integers $$$t_1$$$, $$$t_2$$$, ..., $$$t_n$$$ — how much time it takes Mitya to eat one cookie in vertex $$$i$$$ ($$$1\le t_i\le10^6$$$). Each of the following $$$n - 1$$$ lines describe the tree. For every $$$i$$$ from $$$2$$$ to $$$n$$$, the corresponding line contains two integers $$$p_i$$$ and $$$l_i$$$, where $$$p_i$$$ denotes the parent of vertex $$$i$$$ and $$$l_i$$$ denotes the time it takes Mitya to move the chip along the edge from vertex $$$i$$$ to its parent ($$$1\le p_i < i$$$, $$$0\le l_i \le 10^9$$$).

Output a single integer — maximum number of cookies Mitya can eat.

NoteIn the first example test case, Mitya can start by moving the chip to vertex $$$2$$$. In this case no matter how Vasya plays, Mitya is able to eat at least $$$11$$$ cookies. Below you can find the detailed description of the moves:  Mitya moves chip to vertex $$$2$$$.  Vasya removes edge to vertex $$$4$$$.  Mitya moves chip to vertex $$$5$$$.  Since vertex $$$5$$$ has no children, Vasya does not remove any edges.  Mitya stops the game and moves the chip towards the root, eating cookies along the way ($$$7$$$ in vertex $$$5$$$, $$$3$$$ in vertex $$$2$$$, $$$1$$$ in vertex $$$1$$$). Mitya spend $$$1+0$$$ time to go down, $$$0+1$$$ to go up, $$$7\cdot 2$$$ to eat $$$7$$$ cookies in vertex 5, $$$3\cdot 3$$$ to eat $$$3$$$ cookies in vertex 2, $$$1\cdot 1$$$ to eat $$$1$$$ cookie in vertex 1. Total time is $$$1+0+0+1+7\cdot 2+3\cdot 3+1\cdot 1=26$$$.

package main

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

var (
	E    int = 1 << 20
	line     = make([]Point, 4000100)
	t    int64
)
type Point struct {
	t,c int64

}
type Edge struct {
	to, value int
}

func addEdge(g [][]*Edge, from, to, value int) {
	//fmt.Printf("fromt = %d to=%d\n", from, to)
	if len(g[from]) == 0 {
		g[from] = make([]*Edge, 0)
	}
	g[from] = append(g[from], &Edge{
		to:    to,
		value: value,
	})
}
func location(p int) int {
	return E + p-1
}
func update(pre int, t,c int64) {
//fmt.Printf("update pre=%d t=%d c=%d\n",pre,t,c)
	//tp := pre
	pre = location(pre)
	line[pre].c+=c
	line[pre].t += t
	pre>>=1
	for pre > 0 {
		line[pre].c = line[pre<<1].c+line[1+(pre<<1)].c
		line[pre].t = line[pre<<1].t+line[1+(pre<<1)].t
		pre >>= 1
	}
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[1].t,line[1].c)
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[2].t,line[2].c)
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[3].t,line[3].c)
}
func query(tt int64) (int64) {
	var sumt int64 = 0
	var sumc int64 = 0
	var root int = 1
	for  {
		if line[root*2].t+sumt > tt {
			root <<= 1
		} else {
			sumt += line[root*2].t
			sumc += line[root*2].c
			root = (root << 1) + 1
		}
		if root >= E{
		//	fmt.Printf("query tt=%d sumt=%d sumc=%d line.c=%d line.t=%d\n",tt,sumt,sumc,line[root].c,line[root].t)
			if line[root].t ==0 || sumt+line[root].t <= tt{
				return sumc+line[root].c
			}else{
				return sumc + (tt-sumt)*line[root].c/line[root].t
			}
		}
	}
}
func dfs(root int, g [][]*Edge, ti, cookies []int, costT int64) int64 {
	//if costT > t{
	//	return 0
	//}
	update(ti[root],int64(cookies[root])*int64(ti[root]), int64(cookies[root]))
	max := query(t - costT)
//	fmt.Printf("root =%d max1=%d tt=%d\n",root,max,t-costT)
	var max2 int64 = -1
	var max1 int64 = -1
	for _, next := range g[root] {
		tmp := dfs(next.to, g, ti, cookies, costT+int64(next.value*2))
		if max2 == -1 || max2 < tmp {
			max2 = tmp
			if max2 > max1 {
				sw := max1
				max1 = max2
				max2 = sw
			}
		}
	}

	update(ti[root],-int64(cookies[root])*int64(ti[root]), -int64(cookies[root]))
	if root == 1 {
		if max1!=-1 && max1 > max{
			max = max1
		}
	} else {
		if max2!=-1 && max2 > max{
			max = max2
		}
	}
//	fmt.Printf("====>res root =%d ans=%d\n",root,max)
	return max
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d %d\n", &n, &t)
	cookies := make([]int, n+1)
	g := make([][]*Edge, n+1)
	ti := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &cookies[i+1])
	}
	fmt.Fscanf(buf, "\n")
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &ti[i+1])
	}
	//	fmt.Print(ti)
	fmt.Fscanf(buf, "\n")
	for i := 2; i <= n; i++ {
		var value int = 0
		var from int = 0
		fmt.Fscanf(buf, "%d %d\n", &from, &value)
		//if n == 77&&t == 63{
		//	fmt.Printf("%d %d\n",from,value)
		//}
		addEdge(g, from, i, value)
	}
	fmt.Println(dfs(1, g, ti, cookies, 0))

}

/**
77 63
6 3 10 5 9 6 6 1 1 5 7 7 1 8 4 4 9 6 3 10 1 1 7 4 5 2 3 6 10 4 5 7 5 8 3 1 10 5 8 5 3 2 3 6 10 10 2 4 4 8 8 5 2 1 2 3 6 9 8 6 4 1 2 7 1 1 5 3 1 1 8 10 10 8 6 7 5
5 6 3 8 6 10 8 5 2 4 4 8 2 1 10 7 1 4 3 4 5 7 5 4 1 8 8 7 5 10 10 9 2 7 4 10 5 2 2 4 4 2 10 2 4 2 9 10 6 2 4 2 10 5 7 10 1 3 1 4 2 8 9 4 7 6 10 10 9 5 6 3 1 4 1 3 3
1 6
1 7
2 6
3 6
2 2
2 8
5 7
4 2
5 5
8 6
2 5
8 8
5 8
13 1
1 1
7 7
13 3
1 0
13 8
4 1
10 9
1 5
14 3
22 2
6 7
10 9
26 9
7 1
8 10
12 10
14 9
31 5
13 0
4 3
1 5
4 3
34 10
24 2
18 9
27 3
5 1
41 8
38 10
25 0
26 4
30 8
14 1
18 2
34 3
1 2
31 0
36 0
52 4
29 3
13 2
35 9
22 10
21 6
34 0
10 5
55 6
57 5
47 5
48 10
3 3
17 3
67 1
39 5
39 7
52 5
22 0
31 9
56 1
43 0
14 3
46 10

 */

package main

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

var (
	E    int = 1 << 20
	line     = make([]Point, 4000100)
	t    int64
)
type Point struct {
	t,c int64

}
type Edge struct {
	to, value int
}

func addEdge(g [][]*Edge, from, to, value int) {
	//fmt.Printf("fromt = %d to=%d\n", from, to)
	if len(g[from]) == 0 {
		g[from] = make([]*Edge, 0)
	}
	g[from] = append(g[from], &Edge{
		to:    to,
		value: value,
	})
}
func location(p int) int {
	return E + p-1
}
func update(pre int, t,c int64) {
//fmt.Printf("update pre=%d t=%d c=%d\n",pre,t,c)
	//tp := pre
	pre = location(pre)
	line[pre].c+=c
	line[pre].t += t
	pre>>=1
	for pre > 0 {
		line[pre].c = line[pre<<1].c+line[1+(pre<<1)].c
		line[pre].t = line[pre<<1].t+line[1+(pre<<1)].t
		pre >>= 1
	}
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[1].t,line[1].c)
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[2].t,line[2].c)
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[3].t,line[3].c)
}
func query(tt int64) (int64) {
	var sumt int64 = 0
	var sumc int64 = 0
	var root int = 1
	for  {
		if line[root*2].t+sumt > tt {
			root <<= 1
		} else {
			sumt += line[root*2].t
			sumc += line[root*2].c
			root = (root << 1) + 1
		}
		if root >= E{
		//	fmt.Printf("query tt=%d sumt=%d sumc=%d line.c=%d line.t=%d\n",tt,sumt,sumc,line[root].c,line[root].t)
			if sumt+line[root].t <= tt{
				return sumc+line[root].c
			}else{
				return sumc + (tt-sumt)*line[root].c/line[root].t
			}
		}
	}
}
func dfs(root int, g [][]*Edge, ti, cookies []int, costT int64) int64 {
	if costT > t{
		return 0
	}
	update(ti[root],int64(cookies[root])*int64(ti[root]), int64(cookies[root]))
	max := query(t - costT)
//	fmt.Printf("root =%d max1=%d tt=%d\n",root,max,t-costT)
	var max2 int64 = -1
	var max1 int64 = -1
	for _, next := range g[root] {
		tmp := dfs(next.to, g, ti, cookies, costT+int64(next.value*2))
		if max2 == -1 || max2 < tmp {
			max2 = tmp
			if max2 > max1 {
				sw := max1
				max1 = max2
				max2 = sw
			}
		}
	}

	update(ti[root],-int64(cookies[root])*int64(ti[root]), -int64(cookies[root]))
	if root == 1 {
		if max1!=-1 && max1 > max{
			max = max1
		}
	} else {
		if max2!=-1 && max2 > max{
			max = max2
		}
	}
//	fmt.Printf("====>res root =%d ans=%d\n",root,max)
	return max
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d %d\n", &n, &t)
	cookies := make([]int, n+1)
	g := make([][]*Edge, n+1)
	ti := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &cookies[i+1])
	}
	fmt.Fscanf(buf, "\n")
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &ti[i+1])
	}
	//	fmt.Print(ti)
	fmt.Fscanf(buf, "\n")
	for i := 2; i <= n; i++ {
		var value int = 0
		var from int = 0
		fmt.Fscanf(buf, "%d %d\n", &from, &value)
		addEdge(g, from, i, value)
	}
	fmt.Println(dfs(1, g, ti, cookies, 0))

}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */

package main

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

var (
	E    int = 1 << 20
	line     = make([]Point, 4000100)
	t    int64
)
type Point struct {
	t,c int64

}
type Edge struct {
	to, value int
}

func addEdge(g [][]*Edge, from, to, value int) {
	//fmt.Printf("fromt = %d to=%d\n", from, to)
	if len(g[from]) == 0 {
		g[from] = make([]*Edge, 0)
	}
	g[from] = append(g[from], &Edge{
		to:    to,
		value: value,
	})
}
func location(p int) int {
	return E + p-1
}
func update(pre int, t,c int64) {
//fmt.Printf("update pre=%d t=%d c=%d\n",pre,t,c)
	//tp := pre
	pre = location(pre)
	line[pre].c+=c
	line[pre].t += t
	pre>>=1
	for pre > 0 {
		line[pre].c = line[pre<<1].c+line[1+(pre<<1)].c
		line[pre].t = line[pre<<1].t+line[1+(pre<<1)].t
		pre >>= 1
	}
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[1].t,line[1].c)
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[2].t,line[2].c)
	//fmt.Printf("--update pre=%d t=%d c=%d\n",pre,line[3].t,line[3].c)
}
func query(tt int64) (int64) {
	var sumt int64 = 0
	var sumc int64 = 0
	var root int = 1
	for  {
		if line[root*2].t+sumt > tt {
			root <<= 1
		} else {
			sumt += line[root*2].t
			sumc += line[root*2].c
			root = (root << 1) + 1
		}
		if root >= E{
		//	fmt.Printf("query tt=%d sumt=%d sumc=%d line.c=%d line.t=%d\n",tt,sumt,sumc,line[root].c,line[root].t)
			if sumt+line[root].t <= tt{
				return sumc+line[root].c
			}else{
				return sumc + (tt-sumt)*line[root].c/line[root].t
			}
		}
	}
}
func dfs(root int, g [][]*Edge, ti, cookies []int, costT int64) int64 {
	if costT > t{
		return 0
	}
	update(ti[root],int64(cookies[root])*int64(ti[root]), int64(cookies[root]))
	max := query(t - costT)
//	fmt.Printf("root =%d max1=%d tt=%d\n",root,max,t-costT)
	var max2 int64 = -1
	var max1 int64 = -1
	for _, next := range g[root] {
		tmp := dfs(next.to, g, ti, cookies, costT+int64(next.value*2))
		if max2 == -1 || max2 < tmp {
			max2 = tmp
			if max2 > max1 {
				sw := max1
				max1 = max2
				max2 = sw
			}
		}
	}

	update(ti[root],-int64(cookies[root])*int64(ti[root]), -int64(cookies[root]))
	if root == 1 {
		if max1!=-1 && max1 > max{
			max = max1
		}
	} else {
		if max2!=-1 && max2 > max{
			max = max2
		}
	}
//	fmt.Printf("====>res root =%d ans=%d\n",root,max)
	return max
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d %d\n", &n, &t)
	cookies := make([]int, n+1)
	g := make([][]*Edge, n+1)
	ti := make([]int, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &cookies[i+1])
	}
	fmt.Fscanf(buf, "\n")
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &ti[i+1])
	}
	//	fmt.Print(ti)
	fmt.Fscanf(buf, "\n")
	for i := 2; i <= n; i++ {
		var value int = 0
		var from int = 0
		fmt.Fscanf(buf, "%d %d\n", &from, &value)
		if n == 77&&t == 63{
			fmt.Printf("%d %d\n",from,value)
		}
		addEdge(g, from, i, value)
	}
	fmt.Println(dfs(1, g, ti, cookies, 0))

}

/**
12 10
1 2
1 3
1 4
2 5
2 6
2 7
3 8
5 9
5 10
7 11

 */


The knight is standing in front of a long and narrow hallway. A princess is waiting at the end of it.In a hallway there are three doors: a red door, a green door and a blue door. The doors are placed one after another, however, possibly in a different order. To proceed to the next door, the knight must first open the door before.Each door can be only opened with a key of the corresponding color. So three keys: a red key, a green key and a blue key — are also placed somewhere in the hallway. To open the door, the knight should first pick up the key of its color.The knight has a map of the hallway. It can be transcribed as a string, consisting of six characters:   R, G, B — denoting red, green and blue doors, respectively;  r, g, b — denoting red, green and blue keys, respectively. Each of these six characters appears in the string exactly once.The knight is standing at the beginning of the hallway — on the left on the map.Given a map of the hallway, determine if the knight can open all doors and meet the princess at the end of the hallway.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 720$$$) — the number of testcases. Each testcase consists of a single string. Each character is one of R, G, B (for the doors), r, g, b (for the keys), and each of them appears exactly once.

For each testcase, print YES if the knight can open all doors. Otherwise, print NO.

NoteIn the first testcase, the knight first collects all keys, then opens all doors with them.In the second testcase, there is a red door right in front of the knight, but he doesn't have a key for it.In the third testcase, the key to each door is in front of each respective door, so the knight collects the key and uses it immediately three times.In the fourth testcase, the knight can't open the blue door.

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var input string
		fmt.Fscan(in,&input)
		if string(input[0]) == "R" || string(input[0]) == "B" || string(input[0]) == "G" {
			fmt.Fprintln(out,"NO")
		} else {
			var r,b,g int
			for j:=0;j<6;j++{
				if string(input[j]) == "r" {
					r = j
				} else if string(input[j]) == "b" {
					b = j
				} else if string(input[j]) == "g" {
					g = j
				}
			}
			counter:=0
			for j:=0;j<6;j++{
				if string(input[j]) == "R" {
					if r > j {
						counter++
					}
				} else if string(input[j]) == "G" {
					if g > j {
						counter++
					}
				} else if string(input[j]) == "B" {
					if b > j {
						counter++
					}
				}
			}
			if counter > 0 {
				fmt.Fprintln(out,"NO")
			} else {
				fmt.Fprintln(out,"YES")
			}
		}
	}
}

package main

import "fmt"
import "strings"

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

    var s string
    for i := 0; i < t; i++ {
        fmt.Scanln(&s)

        a := strings.Index(s, "r") < strings.Index(s, "R")
        b := strings.Index(s, "g") < strings.Index(s, "G")
        c := strings.Index(s, "b") < strings.Index(s, "B")

        if a && b && c {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

//nolint
package main

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

//{
var reader = bufio.NewReader(os.Stdin)
var 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 print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

var cR, cG, cB int

func Solve() {
	var st string
	cR, cG, cB = 0, 0, 0
	scan(&st)
	for _, c := range st {
		switch c {
		case 'r':
			cR++
		case 'g':
			cG++
		case 'b':
			cB++
		case 'R':
			cR--
		case 'G':
			cG--
		case 'B':
			cB--
		}
		if isFail() {
			println("NO")
			return
		}
	}
	println("YES")
}

func isFail() bool {
	if cR < 0 || cG < 0 || cB < 0 {
		return true
	}
	return false
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1644A
Date: 6/03/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1644/A
Problem: CF1644A
**/
func (in *CF1644A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		str := in.NextString()
		r,g,b := false, false, false
		ans := true
		for i:=0;i<len(str);i++ {
			if str[i] == 'r' {
				r = true
			}else if str[i] == 'g' {
				g = true
			} else if str[i] == 'b' {
				b = true
			} else if str[i] == 'R' {
				if !r {
					ans = false
				}else {
					r = false
				}
			}else if str[i] == 'G' {
				if !g {
					ans = false
				}else {
					g = false
				}
			} else if str[i] == 'B' {
				if !b {
					ans = false
				} else {
					b = false
				}
			}
		}
		if ans {
			fmt.Println("YES")
		}else {
			fmt.Println("NO")
		}
	}
}

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

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

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }
func solve()  {
	var s string
	set := make(map[string]bool) // New empty set
	scanf("%s\n", &s)
	for _, ch := range s {
		if ch >= 'a' && ch <= 'z' {
			set[string(ch)] = true
		} else {
			if !set[string(ch+32)]  {
				printf("NO\n")
				return
			}
		}
	}
	printf("YES\n")
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for i := 1 ; i <= t; i++ {
		solve()
	}
}

package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

func solve(str string) bool {
	keys := make(map[rune]struct{})
	for _, ch := range []rune(str) {
		if ch == unicode.ToLower(ch) {
			keys[unicode.ToUpper(ch)] = struct{}{}
		} else if _, has := keys[ch]; !has {
			return false
		}
	}
	return true
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i += 1 {
		if str := stdin.Word(); solve(str) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func solve(scanner *bufio.Scanner) {
	scanner.Scan()
	cur := scanner.Text()
	r, g, b := false, false, false
	for _, ru := range cur {
		switch rune(ru) {
		case 'r':
			r = true
			continue
		case 'g':
			g = true
			continue
		case 'b':
			b = true
			continue
		case 'R':
			if r {
				continue
			} else {
				fmt.Println("NO")
				return
			}
		case 'G':
			if g {
				continue
			} else {
				fmt.Println("NO")
				return
			}
		case 'B':
			if b {
				continue
			} else {
				fmt.Println("NO")
				return
			}
		default:
			break
		}
	}
	fmt.Println("YES")
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < t; i++ {
		solve(scanner)
	}

}

package main

import (
	"fmt"
	"unicode"
)

func main() {
	t := 0
	fmt.Scan(&t)
	strings := make([]string, t)
	for i := 0; i < t; i++ {
		fmt.Scan(&strings[i])
	}
	for i := 0; i < t; i++ {
		solve(strings[i])
	}
}

func solve(hallway string) {
	keys := map[rune]bool{
		'r': false,
		'g': false,
		'b': false,
	}
	canReach := true
	for _, c := range hallway {
		switch c {
		case 'r':
			keys['r'] = true
		case 'g':
			keys['g'] = true
		case 'b':
			keys['b'] = true
		default:
			if !keys[unicode.ToLower(c)] {
				canReach = false
			}
		}
	}
	if canReach {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}

package main

import (
	"fmt"
)

func solve() {
	var s string
	fmt.Scanf("%s\n", &s)

	x := make(map[byte]bool)
	rs := []byte(s)
	for i := 0; i < 6; i += 1 {
		if rs[i] >= 'a' && rs[i] <= 'z' {
			x[rs[i]] = true
		} else {
			c := 'a' + rs[i] - 'A'
			if !x[c] {
				fmt.Printf("NO\n")
				return
			}
		}
	}
	fmt.Printf("YES\n")

}

func main() {
	var T int
	for fmt.Scanf("%d\n", &T); T > 0; T-- {
		solve()
	}

}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	x      string
)

func solve(x string) string {
	y := make(map[byte]int)
	for j := range x {
		y[x[j]] = j
	}
	if (y['r'] > y['R']) || (y['g'] > y['G']) || (y['b'] > y['B']) {
		return "NO"
	}
	return "YES"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &x)
		fmt.Println(solve(x))
	}
}

package main

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

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

func CF1644A(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	const keys = "rgb"
	const doors = "RGB"
	c := 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		str := ""
		fmt.Fscan(in, &str)
		mp := make(map[rune]int, 3)
		for _, ch := range str {
			for _, chd := range doors {
				if ch == chd {
					if mp[ch+32] > 0 {
						break
					} else {
						fmt.Fprintln(out, "NO")
						goto out
					}
				}
			}
			for _, chk := range keys {
				if ch == chk {
					mp[chk]++
				}
			}
		}
		fmt.Fprintln(out, "YES")
	out:
	}
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}

func readString(in *bufio.Reader) string {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return nStr
}

func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

func readArrInt(in *bufio.Reader) []int {
	numbs := readLineNumbs(in)
	arr := make([]int, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.Atoi(n)
		arr[i] = val
	}
	return arr
}

func Solve(in string) string {
	var keys []string

	for _, v := range in {
		char := string(v)
		if char == "r" || char == "g" || char == "b" {
			keys = append(keys, char)
		} else {
			found := false

			for _, c := range keys {
				if strings.ToLower(char) == string(c) {
					found = true
				}
			}

			if !found {
				return "NO"
			}
		}
	}

	return "YES"
}

func main() {
	in := bufio.NewReader(os.Stdin)
	n := readInt(in)

	for i := 0; i < n; i++ {
		input := readString(in)

		res := Solve(input)

		fmt.Printf("%s\n", res)
	}
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var s string
	scanf("%s\n", &s)

	hm := make(map[rune]int)

	for i, r := range s {
		hm[r] = i
	}

	if hm['r'] < hm['R'] && hm['g'] < hm['G'] && hm['b'] < hm['B'] {
		fmt.Fprintln(writer, "YES")
	} else {
		fmt.Fprintln(writer, "NO")
	}
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int64) int64 {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

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

	return nums[idx], idx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

		k := make([]bool, 3)
		f := true
		for _, ch := range s {
			if ch == 'R' && !k[0] {
				f = false
				break
			} else if ch == 'G' && !k[1] {
				f = false
				break
			} else if ch == 'B' && !k[2] {
				f = false
				break
			} else if ch == 'r' {
				k[0] = true
			} else if ch == 'g' {
				k[1] = true
			} else if ch == 'b' {
				k[2] = true
			}
		}

		if !f {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, s := 0, ""
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &s)
		ok, r, g, b := true, false, false, false
		for j := 0; j < len(s); j++ {
			if string(s[j]) == "r" {
				r = true
			}
			if string(s[j]) == "b" {
				b = true
			}
			if string(s[j]) == "g" {
				g = true
			}
			if string(s[j]) == "R" {
				if !r {
					ok = false
				}
			} else if string(s[j]) == "G" {
				if !g {
					ok = false
				}
			} else if string(s[j]) == "B" {
				if !b {
					ok = false
				}
			}
		}
		if ok {
			fmt.Fprintln(w, "YES")
		} else {
			fmt.Fprintln(w, "NO")
		}
	}
	w.Flush()
}

func main() {
	solve()
}


Hosssam decided to sneak into Hemose's room while he is sleeping and change his laptop's password. He already knows the password, which is a string $$$s$$$ of length $$$n$$$. He also knows that there are $$$k$$$ special letters of the alphabet: $$$c_1,c_2,\ldots, c_k$$$.Hosssam made a program that can do the following.  The program considers the current password $$$s$$$ of some length $$$m$$$.  Then it finds all positions $$$i$$$ ($$$1\le i<m$$$) such that $$$s_{i+1}$$$ is one of the $$$k$$$ special letters.  Then it deletes all of those positions from the password $$$s$$$ even if $$$s_{i}$$$ is a special character. If there are no positions to delete, then the program displays an error message which has a very loud sound. For example, suppose the string $$$s$$$ is "abcdef" and the special characters are 'b' and 'd'. If he runs the program once, the positions $$$1$$$ and $$$3$$$ will be deleted as they come before special characters, so the password becomes "bdef". If he runs the program again, it deletes position $$$1$$$, and the password becomes "def". If he is wise, he won't run it a third time.Hosssam wants to know how many times he can run the program on Hemose's laptop without waking him up from the sound of the error message. Can you help him?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the initial length of the password. The next line contains a string $$$s$$$ consisting of $$$n$$$ lowercase English letters — the initial password. The next line contains an integer $$$k$$$ ($$$1 \le k \le 26$$$), followed by $$$k$$$ distinct lowercase letters $$$c_1,c_2,\ldots,c_k$$$ — the special letters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, print the maximum number of times Hosssam can run the program without displaying the error message, on a new line.

10

9

iloveslim

1 s

7

joobeel

2 o e

7

basiozi

2 s i

6

khater

1 r

7

abobeih

6 a b e h i o

5

zondl

5 a b c e f

6

shoman

2 a h

7

shetwey

2 h y

5

samez

1 m

6

mouraz

1 m

NoteIn the first test case, the program can run $$$5$$$ times as follows: $$$\text{iloveslim} \to \text{ilovslim} \to \text{iloslim} \to \text{ilslim} \to \text{islim} \to \text{slim}$$$In the second test case, the program can run $$$2$$$ times as follows: $$$\text{joobeel} \to \text{oel} \to \text{el}$$$In the third test case, the program can run $$$3$$$ times as follows: $$$\text{basiozi} \to \text{bioi} \to \text{ii} \to \text{i}$$$.In the fourth test case, the program can run $$$5$$$ times as follows: $$$\text{khater} \to \text{khatr} \to \text{khar} \to \text{khr} \to \text{kr} \to \text{r}$$$In the fifth test case, the program can run only once as follows: $$$\text{abobeih} \to \text{h}$$$In the sixth test case, the program cannot run as none of the characters in the password is a special character.

package main

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

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

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

	nextStr := func() string {
		in.Scan()
		return in.Text()
	}

	t := nextInt()
	sol := func() int {
		n := nextInt()
		s := nextStr()
		m := nextInt()
		special := make([]bool, 128)
		for i := 0; i < m; i++ {
			s1 := nextStr()
			special[s1[0]] = true
		}
		// fmt.Println(special)
		c := 0
		l := 0
		ans := 0
		for i := 0; i < n; i++ {
			if special[s[i]] {
				res := l
				if c > 0 {
					res++
				}
				if ans < res {
					ans = res
				}
				l = 0
				c++
			} else {
				l++
			}
		}
		return ans
	}
	for ; t > 0; t-- {
		fmt.Fprintln(out, sol())
	}
}

package main

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

func main() {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	in.Buffer(nil, 1e9)

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

	nextStr := func() string {
		in.Scan()
		return in.Text()
	}

	t := nextInt()
	sol := func() int {
		n := nextInt()
		s := nextStr()
		m := nextInt()
		special := make([]bool, 128)
		for i := 0; i < m; i++ {
			s1 := nextStr()
			special[s1[0]] = true
		}
		// fmt.Println(special)
		c := 0
		l := 0
		ans := 0
		for i := 0; i < n; i++ {
			if special[s[i]] {
				res := l
				if c > 0 {
					res++
				}
				if ans < res {
					ans = res
				}
				l = 0
				c++
			} else {
				l++
			}
		}
		return ans
	}
	for ; t > 0; t-- {
		fmt.Println(sol())
	}
}

package main

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

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n, k int
		var s string

		Fscan(in, &n, &s, &k)

		vis := make([]bool, 30)
		for i := 0; i < k; i++ {
			var ch string
			Fscan(in, &ch)
			vis[ch[0]-'a'] = true
		}

		cnt := L0
		ans := L0
		for _, ch := range s {
			if !vis[ch-'a'] {
				cnt++
			} else {
				ans = Max(ans, cnt)
				cnt = 1
			}
		}

		Fprintln(out, ans)

	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

package main

import (
	"bufio"
	"container/list"
	. "fmt"
	"os"
)

type Int int64

const (
	INF = 3e5 + 10
	L0  = Int(0)
	L1  = Int(1)
)

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

	var t int
	Fscan(in, &t)

	for tt := 0; tt < t; tt++ {
		var n, k int
		Fscan(in, &n)
		var s string
		Fscan(in, &s)

		Fscan(in, &k)

		a := make([]bool, 30)
		for i := 0; i < k; i++ {
			var ch string
			Fscan(in, &ch)
			a[ch[0]-'a'] = true
		}

		vis := make(map[int]bool)
		queue := list.New()

		for i, ch := range s {
			if a[ch-'a'] && i > 0 {
				vis[i] = true
				queue.PushBack(i)
			}
		}

		ans := 0
		for queue.Len() > 0 {
			ans++
			nVis := make(map[int]bool)
			nQueue := list.New()
			cnt := 1
			for e := queue.Front(); e != nil; e = e.Next() {
				m := e.Value.(int) - cnt
				if m > 0 && nVis[m] == false {
					nVis[m] = true
					nQueue.PushBack(m)
				}
				cnt++
			}
			vis = nVis
			queue = nQueue
		}

		Fprintln(out, ans)
	}

}

func MakeGrid(h, w int) [][]Int {
	index := make([][]Int, h)
	data := make([]Int, h*w)
	for i := 0; i < h; i++ {
		index[i] = data[i*w : (i+1)*w]
	}
	return index
}

func Abs(x Int) Int {
	if x > 0 {
		return x
	}
	return -x
}

func Min(nums ...Int) Int {
	return nums[MinIdx(nums...)]
}

func MinIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num < nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

func Max(nums ...Int) Int {
	return nums[MaxIdx(nums...)]
}

func MaxIdx(nums ...Int) Int {
	maxNumIdx := L0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = Int(i)
		}
	}
	return maxNumIdx
}

var (
	mod  Int
	fmod func(Int) Int = doNothing
)

// SetMod sets the mod. It must be called first.
func SetMod(newMod Int) {
	mod = newMod
	fmod = dynamicMod
}

func dynamicMod(m Int) Int {
	m %= mod
	if m < 0 {
		return m + mod
	}
	return m
}

func doNothing(m Int) Int {
	return m
}

// Mod returns m % mod.
func (m Int) Mod() Int {
	return fmod(m)
}

// Inv returns modular multiplicative inverse
func (m Int) Inv() Int {
	return m.Pow(Int(0).Sub(2))
}

// Pow returns m^n
func (m Int) Pow(n Int) Int {
	p := Int(1)
	for n > 0 {
		if n&1 == 1 {
			p.MulAs(m)
		}
		m.MulAs(m)
		n >>= 1
	}
	return p
}

// Add returns m+x
func (m Int) Add(x Int) Int {
	return (m + x).Mod()
}

// Sub returns m-x
func (m Int) Sub(x Int) Int {
	return (m - x).Mod()
}

// Mul returns m*x
func (m Int) Mul(x Int) Int {
	return (m * x).Mod()
}

// Div returns m/x
func (m Int) Div(x Int) Int {
	return m.Mul(x.Inv())
}

// AddAs assigns *m + x to *m and returns m
func (m *Int) AddAs(x Int) *Int {
	*m = m.Add(x)
	return m
}

// SubAs assigns *m - x to *m and returns m
func (m *Int) SubAs(x Int) *Int {
	*m = m.Sub(x)
	return m
}

// MulAs assigns *m * x to *m and returns m
func (m *Int) MulAs(x Int) *Int {
	*m = m.Mul(x)
	return m
}

// DivAs assigns *m / x to *m and returns m
func (m *Int) DivAs(x Int) *Int {
	*m = m.Div(x)
	return m
}

func (m *Int) MaxAs(x ...Int) *Int {
	*m = Max(append(x, *m)...)
	return m
}

func (m *Int) MinAs(x ...Int) *Int {
	*m = Min(append(x, *m)...)
	return m
}

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 n int
		var s string
		fmt.Fscan(in, &n, &s)

		var k int
		fmt.Fscan(in, &k)
		m := make([]bool, 26)
		for i := 0; i < k; i++ {
			var v string
			fmt.Fscan(in, &v)

			m[v[0]-'a'] = true
		}

		var max int
		last := -1
		for i := 1; i < n; i++ {
			if m[s[i]-'a'] {
				if last < 0 {
					max = i
				} else {
					if i-last > max {
						max = i - last
					}
				}
				last = i
			}
		}

		fmt.Fprintln(out, max)
	}
}

package main

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

func main() {
	var reader *bufio.Reader = bufio.NewReader(os.Stdin)
	var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var T int
	fmt.Scan(&T)
	var n int
	var k int
	var s string
	for t := 0; t < T; t++ {
		fmt.Fscan(reader, &n, &s, &k)
		// fmt.Println(n, s, k)
		ks := make(map[byte]bool)
		var ki string
		for i := 0; i < k; i++ {
			fmt.Fscan(reader, &ki)
			ks[ki[0]] = true
		}
		ans := 0
		count := 0
		for i := 0; i < n; i++ {
			if ks[s[i]] {
				if count > ans {
					ans = count
				}
				count = 1
			} else {
				count++
			}
		}
		fmt.Fprintln(writer, ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N := gi(); S := gs(); K := gi()
		special := make([]bool,26); for i:=0;i<K;i++ { ks := gs(); special[ks[0]-'a'] = true }
		streaks := make([]int,0); found := false; pre := 0
		for i:=N-1;i>=0;i-- {
			c := S[i]
			if special[c-'a'] {
				if !found { found = true; pre = 0 } else { streaks = append(streaks,pre); pre = 0 }
			} else {
				pre++
			}
		}
		if found { streaks = append(streaks,pre) }
		ans := 0
		if found {
			for i:=len(streaks)-1;i>=0;i-- {
				if i == len(streaks)-1 { ans = streaks[i]; continue }
				if streaks[i] < ans { continue }
				ans = streaks[i]+1
			}
		}
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove(T int) {
	defer w.Flush()
	var SSS int
	fmt.Fscan(r, &SSS)
	var s string
	fmt.Fscan(r, &s)
	var m int
	fmt.Fscan(r, &m)
	cnt := map[byte]bool{}
	for i:=0;i<m;i++ {
		var ss string
		fmt.Fscan(r, &ss)
		cnt[ss[0]] = true
	}
	idx := make([]int, 0)
	last := 0
	ans := 0
	for i := range s {
		if _, ok := cnt[s[i]]; ok {
			idx = append(idx, i)
			ans = max(ans, i - last)
			last = i
		}
	}
	fmt.Fprintln(w, ans)
}

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

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove(i)
	}
}

package main

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

/*
4
7
jhasdfg
3 a s d
7
ssfjasd
2 h f
7
klhjgfd
2 l j
12
aafbbbgccch
3 f g h
---
2 jhasdfg -> jdfg -> dfg
2 ssfjasd -> sfjasd -> fjasd
2
4 aafbbbgccch -> afbbgcch -> fbgch -> fgh -> h

klhjgfd

0 1
*/

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

	var m int
	scanf("%d", &m)

	runeToSpec := make(map[rune]bool)
	for i := 0; i < m; i++ {
		var r rune
		scanf(" %c", &r)

		runeToSpec[r] = true
	}
	scanf("\n")

	lastSpecIdx := -1
	maxSpecRange := 0

	for i, r := range s {
		if runeToSpec[r] {
			rng := i - lastSpecIdx
			if lastSpecIdx == -1 {
				rng--
			}
			maxSpecRange = max(maxSpecRange, rng)
			lastSpecIdx = i
		}
	}

	fmt.Fprintln(writer, maxSpecRange)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

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

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

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

func main() {
	defer out.Flush()

	var tc int
	for fmt.Fscan(in, &tc); tc > 0; tc-- {
		var n, k int
		var s string
		var special [26]bool
		fmt.Fscan(in, &n, &s, &k)
		for ; k > 0; k-- {
			var c string
			fmt.Fscan(in, &c)
			special[c[0]-'a'] = true
		}

		curRun, maxRun := -1, 0
		for i := len(s) - 1; i >= 0; i-- {
			if curRun != -1 {
				curRun++
				if curRun > maxRun {
					maxRun = curRun
				}
			}
			if special[s[i]-'a'] {
				curRun = 0
			}
		}
		fmt.Fprintln(out, maxRun)
	}
}


You are a paparazzi working in Manhattan.Manhattan has $$$r$$$ south-to-north streets, denoted by numbers $$$1, 2,\ldots, r$$$ in order from west to east, and $$$r$$$ west-to-east streets, denoted by numbers $$$1,2,\ldots,r$$$ in order from south to north. Each of the $$$r$$$ south-to-north streets intersects each of the $$$r$$$ west-to-east streets; the intersection between the $$$x$$$-th south-to-north street and the $$$y$$$-th west-to-east street is denoted by $$$(x, y)$$$. In order to move from the intersection $$$(x,y)$$$ to the intersection $$$(x', y')$$$ you need $$$|x-x'|+|y-y'|$$$ minutes.You know about the presence of $$$n$$$ celebrities in the city and you want to take photos of as many of them as possible. More precisely, for each $$$i=1,\dots, n$$$, you know that the $$$i$$$-th celebrity will be at the intersection $$$(x_i, y_i)$$$ in exactly $$$t_i$$$ minutes from now (and he will stay there for a very short time, so you may take a photo of him only if at the $$$t_i$$$-th minute from now you are at the intersection $$$(x_i, y_i)$$$). You are very good at your job, so you are able to take photos instantaneously. You know that $$$t_i < t_{i+1}$$$ for any $$$i=1,2,\ldots, n-1$$$.Currently you are at your office, which is located at the intersection $$$(1, 1)$$$. If you plan your working day optimally, what is the maximum number of celebrities you can take a photo of?

The first line of the input contains two positive integers $$$r, n$$$ ($$$1\le r\le 500$$$, $$$1\le n\le 100,000$$$) – the number of south-to-north/west-to-east streets and the number of celebrities. Then $$$n$$$ lines follow, each describing the appearance of a celebrity. The $$$i$$$-th of these lines contains $$$3$$$ positive integers $$$t_i, x_i, y_i$$$ ($$$1\le t_i\le 1,000,000$$$, $$$1\le x_i, y_i\le r$$$)  — denoting that the $$$i$$$-th celebrity will appear at the intersection $$$(x_i, y_i)$$$ in $$$t_i$$$ minutes from now. It is guaranteed that $$$t_i<t_{i+1}$$$ for any $$$i=1,2,\ldots, n-1$$$.

Print a single integer, the maximum number of celebrities you can take a photo of.

NoteExplanation of the first testcase: There is only one celebrity in the city, and he will be at intersection $$$(6,8)$$$ exactly $$$11$$$ minutes after the beginning of the working day. Since you are initially at $$$(1,1)$$$ and you need $$$|1-6|+|1-8|=5+7=12$$$ minutes to reach $$$(6,8)$$$ you cannot take a photo of the celebrity. Thus you cannot get any photo and the answer is $$$0$$$.Explanation of the second testcase: One way to take $$$4$$$ photos (which is the maximum possible) is to take photos of celebrities with indexes $$$3, 5, 7, 9$$$ (see the image for a visualization of the strategy):   To move from the office at $$$(1,1)$$$ to the intersection $$$(5,5)$$$ you need $$$|1-5|+|1-5|=4+4=8$$$ minutes, so you arrive at minute $$$8$$$ and you are just in time to take a photo of celebrity $$$3$$$.  Then, just after you have taken a photo of celebrity $$$3$$$, you move toward the intersection $$$(4,4)$$$. You need $$$|5-4|+|5-4|=1+1=2$$$ minutes to go there, so you arrive at minute $$$8+2=10$$$ and you wait until minute $$$12$$$, when celebrity $$$5$$$ appears.  Then, just after you have taken a photo of celebrity $$$5$$$, you go to the intersection $$$(6,6)$$$. You need $$$|4-6|+|4-6|=2+2=4$$$ minutes to go there, so you arrive at minute $$$12+4=16$$$ and you wait until minute $$$17$$$, when celebrity $$$7$$$ appears.  Then, just after you have taken a photo of celebrity $$$7$$$, you go to the intersection $$$(5,4)$$$. You need $$$|6-5|+|6-4|=1+2=3$$$ minutes to go there, so you arrive at minute $$$17+3=20$$$ and you wait until minute $$$21$$$ to take a photo of celebrity $$$9$$$.   Explanation of the third testcase: The only way to take $$$1$$$ photo (which is the maximum possible) is to take a photo of the celebrity with index $$$1$$$ (since $$$|2-1|+|1-1|=1$$$, you can be at intersection $$$(2,1)$$$ after exactly one minute, hence you are just in time to take a photo of celebrity $$$1$$$).Explanation of the fourth testcase: One way to take $$$3$$$ photos (which is the maximum possible) is to take photos of celebrities with indexes $$$3, 8, 10$$$:   To move from the office at $$$(1,1)$$$ to the intersection $$$(101,145)$$$ you need $$$|1-101|+|1-145|=100+144=244$$$ minutes, so you can manage to be there when the celebrity $$$3$$$ appears (at minute $$$341$$$).  Then, just after you have taken a photo of celebrity $$$3$$$, you move toward the intersection $$$(149,379)$$$. You need $$$|101-149|+|145-379|=282$$$ minutes to go there, so you arrive at minute $$$341+282=623$$$ and you wait until minute $$$682$$$, when celebrity $$$8$$$ appears.  Then, just after you have taken a photo of celebrity $$$8$$$, you go to the intersection $$$(157,386)$$$. You need $$$|149-157|+|379-386|=8+7=15$$$ minutes to go there, so you arrive at minute $$$682+15=697$$$ and you wait until minute $$$855$$$ to take a photo of celebrity $$$10$$$.

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)
var INF = 0
func abs(n int) int {
	if n>0{
		return n
	}
	return -n
}
func getAbs(x1,y1,x2,y2 int) int {
	return abs(x1-x2)+abs(y1-y2)
}
func max(a,b int) int {
	if a>b{
		return a
	}
	return b
}
func solve(_r io.Reader,_w io.Writer){
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var r,n int
	fmt.Fscan(in,&r,&n)
	t,x,y := make([]int,n),make([]int,n),make([]int,n)
	for i:=0;i<n;i++{
		fmt.Fscan(in,&t[i],&x[i],&y[i])
	}
	ans := make([]int,n)
	pre := make([]int,n)
	if getAbs(1,1,x[0],y[0])<=t[0]{
		ans[0] = 1
	}else {
		ans[0] = INF
	}
	pre[0] = ans[0]
	for i:=1;i<n;i++{
		if getAbs(1,1,x[i],y[i]) <=t[i]{
			ans[i] = 1
			if i>1000{
				ans[i] = max(ans[i],1+pre[i-1001])
				for j:=i-1000;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}else{
				for j:=0;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}
		}else{
			ans[i] = INF
		}
		pre[i] = max(pre[i-1],ans[i])
	}
	//fmt.Println(ans)
	//fmt.Println(x)
	//fmt.Println(y)
	//fmt.Println(t)
	//fmt.Println(pre[n-1])
	fmt.Fprintln(out,pre[n-1])
	//fmt.Println(pre[n-1])
}
func main() {
	var T int
	T = 1
	//fmt.Scanf("%d",&T)
	for i:=0;i<T;i++{
		solve(os.Stdin,os.Stdout)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ t, x, y int }
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	dis := func(p, q pair) int {
		return abs(p.x-q.x) + abs(p.y-q.y)
	}
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var r, n int
	Fscan(in, &r, &n)
	dp := make([]int, n)
	for _i := range dp {
		dp[_i] = -1
	}
	ps := make([]pair, n)
	mx := -1
	for i := range ps {
		var t, x, y int
		Fscan(in, &t, &x, &y)
		ps[i] = pair{t, x, y}
		p := ps[i]
		if d := dis(p, pair{0,1,1});d <=t {
			dp[i] = 1
		}

		if i <= 1000 {
			for j, q := range ps[:i] {
				if dp[j] == -1 {
					continue
				}
				if d := dis(p, q); d <= t-q.t {
					dp[i] = max(dp[i], dp[j]+1)
				}
			}
		} else {
			for j := i - 1000; j < i; j++ {
				if dp[j] == -1 {
					continue
				}
				q := ps[j]
				if d := dis(p, q); d <= t-q.t {
					dp[i] = max(dp[i], dp[j]+1)
				}
			}
			mx = max(mx, dp[i-1001])
			dp[i] = max(dp[i], mx+1)
		}
	}

	// all dp max
	mx = 0
	for _, v := range dp {
		mx = max(mx, v)
	}
	Fprintln(out, mx)
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
var INF = 0
func abs(n int) int {
	if n>0{
		return n
	}
	return -n
}
func getAbs(x1,y1,x2,y2 int) int {
	return abs(x1-x2)+abs(y1-y2)
}
func max(a,b int) int {
	if a>b{
		return a
	}
	return b
}
func solve(){
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var r,n int
	fmt.Fscan(in,&r,&n)
	t,x,y := make([]int,n),make([]int,n),make([]int,n)
	for i:=0;i<n;i++{
		fmt.Fscan(in,&t[i],&x[i],&y[i])
	}
	ans := make([]int,n)
	pre := make([]int,n)
	if getAbs(1,1,x[0],y[0])<=t[0]{
		ans[0] = 1
	}else {
		ans[0] = INF
	}
	pre[0] = ans[0]
	for i:=1;i<n;i++{
		ans[i] = INF
		if getAbs(1,1,x[i],y[i]) <=t[i]{
			if i>=2*r{
				ans[i] = max(ans[i],1+pre[i-2*r])
				for j:=i-2*r+ 1;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}else{
				for j:=0;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}
		}else{
			ans[i] = INF
		}
		pre[i] = max(pre[i-1],ans[i])
	}
	//fmt.Println(ans)
	//fmt.Println(x)
	//fmt.Println(y)
	//fmt.Println(t)
	//fmt.Println(pre[n-1])
	fmt.Fprintln(out,pre[n-1])
}
func main() {
	var T int
	T = 1
	//fmt.Scanf("%d",&T)
	for i:=0;i<T;i++{
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)
var INF = 0
func abs(n int) int {
	if n>0{
		return n
	}
	return -n
}
func getAbs(x1,y1,x2,y2 int) int {
	return abs(x1-x2)+abs(y1-y2)
}
func max(a,b int) int {
	if a>b{
		return a
	}
	return b
}
func solve(_r io.Reader,_w io.Writer){
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var r,n int
	fmt.Fscan(in,&r,&n)
	t,x,y := make([]int,n),make([]int,n),make([]int,n)
	for i:=0;i<n;i++{
		fmt.Fscan(in,&t[i],&x[i],&y[i])
	}
	ans := make([]int,n)
	pre := make([]int,n)
	if getAbs(1,1,x[0],y[0])<=t[0]{
		ans[0] = 1
	}else {
		ans[0] = INF
	}
	pre[0] = ans[0]
	for i:=1;i<n;i++{
		ans[i] = INF
		if getAbs(1,1,x[i],y[i]) <=t[i]{
			if i>=1000{
				ans[i] = max(ans[i],1+pre[i-1000])
				for j:=i-1000+ 1;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}else{
				for j:=0;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}
		}else{
			ans[i] = INF
		}
		pre[i] = max(pre[i-1],ans[i])
	}
	//fmt.Println(ans)
	//fmt.Println(x)
	//fmt.Println(y)
	//fmt.Println(t)
	//fmt.Println(pre[n-1])
	fmt.Fprintln(out,pre[n-1])
	//fmt.Println(pre[n-1])
}
func main() {
	var T int
	T = 1
	//fmt.Scanf("%d",&T)
	for i:=0;i<T;i++{
		solve(os.Stdin,os.Stdout)
	}
}

package main

import (
	"fmt"
)
var INF = 0
func abs(n int) int {
	if n>0{
		return n
	}
	return -n
}
func getAbs(x1,y1,x2,y2 int) int {
	return abs(x1-x2)+abs(y1-y2)
}
func max(a,b int) int {
	if a>b{
		return a
	}
	return b
}
func solve(){
	var r,n int
	fmt.Scanf("%d %d",&r,&n)
	t,x,y := make([]int,n),make([]int,n),make([]int,n)
	for i:=0;i<n;i++{
		fmt.Scanf("%d %d %d",&t[i],&x[i],&y[i])
	}
	ans := make([]int,n)
	pre := make([]int,n)
	if getAbs(1,1,x[0],y[0])<=t[0]{
		ans[0] = 1
	}else {
		ans[0] = INF
	}
	pre[0] = ans[0]
	for i:=1;i<n;i++{
		ans[i] = INF
		if getAbs(1,1,x[i],y[i]) <=t[i]{
			if i>=2*r{
				ans[i] = max(ans[i],1+pre[i-2*r])
				for j:=i-2*r+ 1;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}else{
				for j:=0;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}
		}else{
			ans[i] = INF
		}
		pre[i] = max(pre[i-1],ans[i])
	}
	//fmt.Println(ans)
	//fmt.Println(x)
	//fmt.Println(y)
	//fmt.Println(t)
	println(pre[n-1])
}
func main() {
	var T int
	T = 1
	//fmt.Scanf("%d",&T)
	for i:=0;i<T;i++{
		solve()
	}
}

package main

import (
	"fmt"
)
var INF = 0
func abs(n int) int {
	if n>0{
		return n
	}
	return -n
}
func getAbs(x1,y1,x2,y2 int) int {
	return abs(x1-x2)+abs(y1-y2)
}
func max(a,b int) int {
	if a>b{
		return a
	}
	return b
}
func solve(){
	var r,n int
	fmt.Scanf("%d %d",&r,&n)
	t,x,y := make([]int,n),make([]int,n),make([]int,n)
	for i:=0;i<n;i++{
		fmt.Scanf("%d %d %d",&t[i],&x[i],&y[i])
	}
	ans := make([]int,n)
	pre := make([]int,n)
	if getAbs(1,1,x[0],y[0])<=t[0]{
		ans[0] = 1
	}else {
		ans[0] = INF
	}
	pre[0] = ans[0]
	for i:=1;i<n;i++{
		ans[i] = INF
		if getAbs(1,1,x[i],y[i]) <=t[i]{
			if i>=2*r{
				ans[i] = max(ans[i],1+pre[i-2*r])
				for j:=i-2*r+ 1;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}else{
				for j:=0;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}
		}else{
			ans[i] = INF
		}
		pre[i] = max(pre[i-1],ans[i])
	}
	//fmt.Println(ans)
	//fmt.Println(x)
	//fmt.Println(y)
	//fmt.Println(t)
	fmt.Println(pre[n-1])
}
func main() {
	var T int
	T = 1
	//fmt.Scanf("%d",&T)
	for i:=0;i<T;i++{
		solve()
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)
var INF = 0
func abs(n int) int {
	if n>0{
		return n
	}
	return -n
}
func getAbs(x1,y1,x2,y2 int) int {
	return abs(x1-x2)+abs(y1-y2)
}
func max(a,b int) int {
	if a>b{
		return a
	}
	return b
}
func solve(_r io.Reader,_w io.Writer){
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var r,n int
	fmt.Fscan(in,&r,&n)
	t,x,y := make([]int,n),make([]int,n),make([]int,n)
	for i:=0;i<n;i++{
		fmt.Fscan(in,&t[i],&x[i],&y[i])
	}
	ans := make([]int,n)
	pre := make([]int,n)
	if getAbs(1,1,x[0],y[0])<=t[0]{
		ans[0] = 1
	}else {
		ans[0] = INF
	}
	pre[0] = ans[0]
	for i:=1;i<n;i++{
		ans[i] = INF
		if getAbs(1,1,x[i],y[i]) <=t[i]{
			if i>1000{
				ans[i] = max(ans[i],1+pre[i-1001])
				for j:=i-1000;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}else{
				for j:=0;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}
		}else{
			ans[i] = INF
		}
		pre[i] = max(pre[i-1],ans[i])
	}
	//fmt.Println(ans)
	//fmt.Println(x)
	//fmt.Println(y)
	//fmt.Println(t)
	//fmt.Println(pre[n-1])
	fmt.Fprintln(out,pre[n-1])
	//fmt.Println(pre[n-1])
}
func main() {
	var T int
	T = 1
	//fmt.Scanf("%d",&T)
	for i:=0;i<T;i++{
		solve(os.Stdin,os.Stdout)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)
var INF = 0
func abs(n int) int {
	if n>0{
		return n
	}
	return -n
}
func getAbs(x1,y1,x2,y2 int) int {
	return abs(x1-x2)+abs(y1-y2)
}
func max(a,b int) int {
	if a>b{
		return a
	}
	return b
}
func solve(_r io.Reader,_w io.Writer){
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var r,n int
	fmt.Fscan(in,&r,&n)
	t,x,y := make([]int,n),make([]int,n),make([]int,n)
	for i:=0;i<n;i++{
		fmt.Fscan(in,&t[i],&x[i],&y[i])
	}
	ans := make([]int,n)
	pre := make([]int,n)
	if getAbs(1,1,x[0],y[0])<=t[0]{
		ans[0] = 1
	}else {
		ans[0] = INF
	}
	pre[0] = ans[0]
	for i:=1;i<n;i++{
		ans[i] = INF
		if getAbs(1,1,x[i],y[i]) <=t[i]{
			if i>=2*r{
				ans[i] = max(ans[i],1+pre[i-2*r])
				for j:=i-2*r+ 1;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}else{
				for j:=0;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}
		}else{
			ans[i] = INF
		}
		pre[i] = max(pre[i-1],ans[i])
	}
	//fmt.Println(ans)
	//fmt.Println(x)
	//fmt.Println(y)
	//fmt.Println(t)
	//fmt.Println(pre[n-1])
	fmt.Fprintln(out,pre[n-1])
	//fmt.Println(pre[n-1])
}
func main() {
	var T int
	T = 1
	//fmt.Scanf("%d",&T)
	for i:=0;i<T;i++{
		solve(os.Stdin,os.Stdout)
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)
var INF = 0
func abs(n int) int {
	if n>0{
		return n
	}
	return -n
}
func getAbs(x1,y1,x2,y2 int) int {
	return abs(x1-x2)+abs(y1-y2)
}
func max(a,b int) int {
	if a>b{
		return a
	}
	return b
}
func solve(_r io.Reader,_w io.Writer){
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var r,n int
	fmt.Fscan(in,&r,&n)
	t,x,y := make([]int,n),make([]int,n),make([]int,n)
	for i:=0;i<n;i++{
		fmt.Fscan(in,&t[i],&x[i],&y[i])
	}
	ans := make([]int,n)
	pre := make([]int,n)
	if getAbs(1,1,x[0],y[0])<=t[0]{
		ans[0] = 1
	}else {
		ans[0] = INF
	}
	pre[0] = ans[0]
	for i:=1;i<n;i++{
		ans[i] = INF
		if getAbs(1,1,x[i],y[i]) <=t[i]{
			if i>1000{
				ans[i] = max(ans[i],1+pre[i-2*r])
				for j:=i-1000+ 1;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}else{
				for j:=0;j<i;j++{
					if getAbs(x[i],y[i],x[j],y[j])<= t[i]-t[j]{
						ans[i] = max(ans[i],1+ans[j])
					}
				}
			}
		}else{
			ans[i] = INF
		}
		pre[i] = max(pre[i-1],ans[i])
	}
	//fmt.Println(ans)
	//fmt.Println(x)
	//fmt.Println(y)
	//fmt.Println(t)
	//fmt.Println(pre[n-1])
	fmt.Fprintln(out,pre[n-1])
	//fmt.Println(pre[n-1])
}
func main() {
	var T int
	T = 1
	//fmt.Scanf("%d",&T)
	for i:=0;i<T;i++{
		solve(os.Stdin,os.Stdout)
	}
}