John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, such that each pair of them is connected by a graph edge. John has been painting for long, but he has not been a success. Help him find such graph. Note that the number of vertices there shouldn't exceed 100, or else John will have problems painting it.

A single line contains an integer k (1 ≤ k ≤ 105) — the number of cycles of length 3 in the required graph.

In the first line print integer n (3 ≤ n ≤ 100) — the number of vertices in the found graph. In each of next n lines print n characters "0" and "1": the i-th character of the j-th line should equal "0", if vertices i and j do not have an edge between them, otherwise it should equal "1". Note that as the required graph is undirected, the i-th character of the j-th line must equal the j-th character of the i-th line. The graph shouldn't contain self-loops, so the i-th character of the i-th line must equal "0" for all i.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF232A(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	c := func(n, k int) int {
		if k == 2 {
			return n * (n - 1) / 2
		}
		return n * (n - 1) * (n - 2) / 6
	}

	var n int
	Fscan(_r, &n)
	m := 3
	for ; c(m, 3) <= n; m++ {
	}
	m--
	n -= c(m, 3)
	ans := [101][101]int8{}
	for i := 0; i < m; i++ {
		for j := 0; j < i; j++ {
			ans[i][j] = 1
			ans[j][i] = 1
		}
	}
	for i := m - 1; i > 1; i-- {
		for ; c(i, 2) <= n; n -= c(i, 2) {
			for j := 0; j < i; j++ {
				ans[m][j] = 1
				ans[j][m] = 1
			}
			m++
		}
	}
	Fprintln(out, m)
	for i := 0; i < m; i++ {
		for j := 0; j < m; j++ {
			Fprint(out, ans[i][j])
		}
		Fprintln(out)
	}
}

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


You still have partial information about the score during the historic football match. You are given a set of pairs $$$(a_i, b_i)$$$, indicating that at some point during the match the score was "$$$a_i$$$: $$$b_i$$$". It is known that if the current score is «$$$x$$$:$$$y$$$», then after the goal it will change to "$$$x+1$$$:$$$y$$$" or "$$$x$$$:$$$y+1$$$". What is the largest number of times a draw could appear on the scoreboard?The pairs "$$$a_i$$$:$$$b_i$$$" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10000$$$) — the number of known moments in the match. Each of the next $$$n$$$ lines contains integers $$$a_i$$$ and $$$b_i$$$ ($$$0 \le a_i, b_i \le 10^9$$$), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team). All moments are given in chronological order, that is, sequences $$$x_i$$$ and $$$y_j$$$ are non-decreasing. The last score denotes the final result of the match.

Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.

NoteIn the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.

package main

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

func solveB(a,b,c,d int64) int64 {
	//fmt.Printf("%d %d %d %d\n",a,b,c,d)
	if a>b || c > d||b < c || a > d{
		return 0
	}
	var maxx int64=a
	if maxx < c{
		maxx = c
	}
	var maxy int64=b
	if maxy > d{
		maxy = d
	}
	//fmt.Printf("%d %d %d %d %d %d\n",a,b,c,d,maxx,maxy)
	if maxy-maxx+1 > 0{
		return maxy-maxx+1
	}
	return 0
}
func main() {
	buf := bufio.NewReader(os.Stdin)

	var n int
	var x,y int64

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

	var prex,prey int64
	var ans int64=1
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d %d\n" , &x,&y)
		if prex==prey{
			prex++
			prey++
		}
		ans += solveB(prex,x,prey,y)
		prex = x
		prey = y
	}

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

package main

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

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

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

func main() {
	var n, a, b, c, pcurr, a1, b1, prev, curr int
	c = 1
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d\n", &n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d %d\n", &a1, &b1)
		prev, curr = max(a, b), min(a1, b1)
		diff := curr - prev
		if diff >= 0 {
			c += diff
			if pcurr != prev {
				c++
			}
		}
		a = a1
		b = b1
		pcurr = curr
	}
	fmt.Printf("%d\n", c)
}

package main

import (
	"fmt"
)

func pow(x, y int) (res int) {
	res = 1
	for y > 0 {
		res = res * x
		y--
	}
	return res
}

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

func common(last_x, x, last_y, y int64) int64 {
	if x < last_y || y < last_x {
		return 0
	}
	if last_x > last_y {
		return common(last_y, y, last_x, x)
	}

	res := min(x, y) - last_y
	if last_x != last_y {
		res += 1
	}

	return res
}

func main() {
	var last_x, last_y int64 = 0, 0
	var n int
	fmt.Scan(&n)
	res := int64(1)
	for ; n > 0; n-- {
		var x, y int64
		fmt.Scan(&x, &y)
		res += common(last_x, x, last_y, y)
		last_x, last_y = x, y
	}
	fmt.Println(res)
}

package main

import "fmt"

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

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

func main() {
	var n, a, b, c, pcurr int
	c = 1
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var a1, b1 int
		fmt.Scan(&a1, &b1)
		// fmt.Println(a1, b1)

		var prev, curr int = max(a, b), min(a1, b1)
		// fmt.Println(prev, curr)
		diff := curr - prev
		if diff >= 0 {
			c += diff
			if pcurr != prev {
				c++
			}
		}
		// pa = a
		// pb = b
		// fmt.Println(pa, pb)

		a = a1
		b = b1
		pcurr = curr
		// fmt.Println(c)
	}
	// if c == 0 {
	// 	fmt.Println(1)
	// } else {
	fmt.Println(c)
	// }
}

package main

import "fmt"

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

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

func main() {
	var n, a, b, c, pcurr int
	c = 1
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var a1, b1 int
		fmt.Scan(&a1)
		fmt.Scan(&b1)
		//fmt.Println("input:", a1, b1)
		//fmt.Println(a, b)

		var prev, curr int = max(a, b), min(a1, b1)
		//fmt.Println(prev, curr)
		diff := curr - prev
		if diff >= 0 {
			c += diff
			if pcurr != prev {
				c++
			}
		}
		// pa = a
		// pb = b
		// fmt.Println(pa, pb)

		a = a1
		b = b1
		pcurr = curr
		//fmt.Println(c)
	}
	// if c == 0 {
	// 	fmt.Println(1)
	// } else {
	fmt.Println(c)
	// }
}

package main

import "fmt"

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

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

func main() {
	var n, a, b, c, pcurr, a1, b1, prev, curr int
	c = 1
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a1, &b1)
		prev, curr = max(a, b), min(a1, b1)
		diff := curr - prev
		if diff >= 0 {
			c += diff
			if pcurr != prev {
				c++
			}
		}
		a = a1
		b = b1
		pcurr = curr
	}
	fmt.Println(c)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	var ans, la, lb int
	var a, b int

	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &a, &b)
		r := minInt(a, b) - maxInt(la, lb) + 1
		if r >= 0 {
			ans += r
		}
		if a == b {
			ans--
		}
		la = a
		lb = b
	}
	if la == lb {
		ans++
	}

	fmt.Println(ans)
}
func minInt(a, b int) int {
	if b > a {
		return a
	}
	return b
}

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

package main

import (
	"fmt"
)

func pow(x, y int) (res int) {
	res = 1
	for y > 0 {
		res = res * x
		y--
	}
	return res
}

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

func main() {
	var last_x, last_y int64 = 0, 0
	var n int
	fmt.Scan(&n)
	res := int64(1)
	for ; n > 0; n-- {
		var x, y int64
		fmt.Scan(&x, &y)
		if last_x == last_y {
			res += min(x, y) - last_x
		}	else if last_x > last_y && x <= y {
			res += min(x, y) - last_x + 1
		} else if last_x < last_y && x >= y {
			res += min(x, y) - last_y + 1
		}
		last_x, last_y = x, y
	}
	fmt.Println(res)
}

package main

import "fmt"

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

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

func main() {
	var n, a, b, c int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var a1, b1 int
		fmt.Scanf("%d %d", &a1, &b1)
		if a == a1 && b == b1 {
			continue
		}
		var prev, curr int = max(a, b), min(a1, b1)
		// fmt.Println(prev, curr)
		c += curr - prev + 1
		a = a1
		b = b1
	}
	if c == 0 {
		fmt.Println(1)
	} else {
		fmt.Println(c)
	}
}

package main

import "fmt"

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

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

func main() {
	var n, a, b, c, pcurr int
	c = 1
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var a1, b1 int
		fmt.Scanf("%d %d", &a1, &b1)
		// fmt.Println(a1, b1)

		var prev, curr int = max(a, b), min(a1, b1)
		// fmt.Println(prev, curr)
		diff := curr - prev
		if diff >= 0 {
			c += diff
			if pcurr != prev {
				c++
			}
		}
		// pa = a
		// pb = b
		// fmt.Println(pa, pb)

		a = a1
		b = b1
		pcurr = curr
		// fmt.Println(c)
	}
	// if c == 0 {
	// 	fmt.Println(1)
	// } else {
	fmt.Println(c)
	// }
}

package main

import "fmt"

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

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

func main() {
	var n, a, b, c, pcurr int
	c = 1
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var a1, b1 int
		fmt.Scanf("%d %d", &a1, &b1)
		// fmt.Println(a1, b1)

		var prev, curr int = max(a, b), min(a1, b1)
		// fmt.Println(prev, curr)
		diff := curr - prev
		if diff > 0 {
			c += diff
			if pcurr != prev {
				c++
			}
		}
		// pa = a
		// pb = b
		// fmt.Println(pa, pb)

		a = a1
		b = b1
		pcurr = curr
		// fmt.Println(c)
	}
	// if c == 0 {
	// 	fmt.Println(1)
	// } else {
	fmt.Println(c)
	// }
}

package main

import (
	"fmt"
	"math"
)

type Score struct {
	A float64
	B float64
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	scores := make([]Score, n+1, n+1)
	scores[0] = Score{0, 0}

	for i := 1; i < n+1; i++ {
		score := Score{0, 0}
		fmt.Scanf("%f %f\n", &score.A, &score.B)
		scores[i] = score
	}

	var eq uint64 = 1
	if n == 1 {
		fmt.Println(eq)
		return
	}

	for i := 1; i < n+1; i++ {
		a := scores[i-1]
		b := scores[i]

		l := uint64(math.Min(b.A, b.B))
		u := uint64(math.Max(a.A, a.B))

		if l >= u {
			if l == u && l != 0 {
				eq++
				continue
			} else {
				eq += l - u
			}
		}
	}

	// check last
	last := scores[len(scores)-1]
	if uint64(last.A) == uint64(last.B) && uint64(last.A) != 0 {
		eq++
	}

	fmt.Println(eq)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	var ans, la, lb int
	for i := 0; i <= n; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		r := minInt(a, b) - maxInt(la, lb) + 1
		if r >= 0 {
			ans += r
		}
		if a == b {
			ans--
		}
		la = a
		lb = b
	}
	if la == lb {
		ans++
	}

	fmt.Println(ans)
}
func minInt(a, b int) int {
	if b > a {
		return a
	}
	return b
}

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

package main

import (
	"fmt"
	"math"
)

type Score struct {
	A float64
	B float64
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	scores := make([]Score, n+1, n+1)
	scores[0] = Score{0, 0}

	for i := 1; i < n+1; i++ {
		score := Score{0, 0}
		fmt.Scanf("%f %f\n", &score.A, &score.B)
		scores[i] = score
	}

	var eq uint64 = 1
	for i := 1; i < n+1; i++ {
		a := scores[i-1]
		b := scores[i]

		l := uint64(math.Min(b.A, b.B))
		u := uint64(math.Max(a.A, a.B))

		if l >= u {
			if l == u && l != 0 {
				eq++
				continue
			} else {
				eq += l - u
			}
		}
	}

	// check last
	if n > 1 {
		last := scores[len(scores)-1]
		if uint64(last.A) == uint64(last.B) && uint64(last.A) != 0 {
			eq++
		}
	}

	fmt.Println(eq)
}

package main

import (
	"fmt"
	"math"
)

type Score struct {
	A float64
	B float64
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	scores := make([]Score, n+1, n+1)
	scores[0] = Score{0, 0}

	for i := 1; i < n+1; i++ {
		score := Score{0, 0}
		fmt.Scanf("%f %f\n", &score.A, &score.B)
		scores[i] = score
	}

	var eq uint64 = 1
	for i := 1; i < n+1; i++ {
		a := scores[i-1]
		b := scores[i]

		l := uint64(math.Min(b.A, b.B))
		u := uint64(math.Max(a.A, a.B))

		if l >= u {
			if l == u && l != 0 {
				eq++
				continue
			} else {
				eq += l - u
			}
		}
	}

	// check last
	last := scores[len(scores)-1]
	if uint64(last.A) == uint64(last.B) && uint64(last.A) != 0 {
		eq++
	}

	fmt.Println(eq)
}

package main

import (
	"fmt"
	"math"
)

type Score struct {
	A float64
	B float64
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	scores := make([]Score, n+1, n+1)
	scores[0] = Score{0, 0}

	for i := 1; i < n+1; i++ {
		score := Score{0, 0}
		fmt.Scanf("%f %f\n", &score.A, &score.B)
		scores[i] = score
	}

	var eq uint64 = 1
	for i := 1; i < n+1; i++ {
		a := scores[i-1]
		b := scores[i]

		l := uint64(math.Min(b.A, b.B))
		u := uint64(math.Max(a.A, a.B))

		if l >= u {
			if l > u {
				eq += l - u
			} else if l != 0 && uint64(a.A) != uint64(a.B) {
				eq++
			}
		}
	}

	// check last
	if n > 1 {
		last := scores[len(scores)-1]
		if uint64(last.A) == uint64(last.B) && uint64(last.A) != 0 {
			eq++
		}
	}

	fmt.Println(eq)
}

package main

import (
	"fmt"
	"math"
)

type Score struct {
	A float64
	B float64
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)

	scores := make([]Score, n+1, n+1)
	scores[0] = Score{0, 0}

	for i := 1; i < n+1; i++ {
		score := Score{0, 0}
		fmt.Scanf("%f %f\n", &score.A, &score.B)
		scores[i] = score
	}

	var eq uint64 = 1
	for i := 1; i < n+1; i++ {
		a := scores[i-1]
		b := scores[i]

		l := uint64(math.Min(b.A, b.B))
		u := uint64(math.Max(a.A, a.B))

		if l >= u {
			if l == u && l != 0 {
				eq++
				continue
			} else {
				eq += l - u
			}
		}
	}

	fmt.Println(eq)
}


You are given a system of pipes. It consists of two rows, each row consists of $$$n$$$ pipes. The top left pipe has the coordinates $$$(1, 1)$$$ and the bottom right — $$$(2, n)$$$.There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types:  Types of pipes You can turn each of the given pipes $$$90$$$ degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types $$$1$$$ and $$$2$$$ can become each other and types $$$3, 4, 5, 6$$$ can become each other).You want to turn some pipes in a way that the water flow can start at $$$(1, 0)$$$ (to the left of the top left pipe), move to the pipe at $$$(1, 1)$$$, flow somehow by connected pipes to the pipe at $$$(2, n)$$$ and flow right to $$$(2, n + 1)$$$.Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes:  Examples of connected pipes Let's describe the problem using some example:  The first example input And its solution is below:   The first example answer As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at $$$(1, 2)$$$ $$$90$$$ degrees clockwise, the pipe at $$$(2, 3)$$$ $$$90$$$ degrees, the pipe at $$$(1, 6)$$$ $$$90$$$ degrees, the pipe at $$$(1, 7)$$$ $$$180$$$ degrees and the pipe at $$$(2, 7)$$$ $$$180$$$ degrees. Then the flow of water can reach $$$(2, n + 1)$$$ from $$$(1, 0)$$$.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Then $$$q$$$ queries follow. Each query consists of exactly three lines. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of pipes in each row. The next two lines contain a description of the first and the second rows correspondingly. Each row description consists of $$$n$$$ digits from $$$1$$$ to $$$6$$$ without any whitespaces between them, each digit corresponds to the type of pipe in the corresponding cell. See the problem statement to understand which digits correspond to which types of pipes. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For the $$$i$$$-th query print the answer for it — "YES" (without quotes) if it is possible to turn some pipes in a way that the water flow can reach $$$(2, n + 1)$$$ from $$$(1, 0)$$$, and "NO" otherwise.

NoteThe first query from the example is described in the problem statement.

package main

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

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

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

func Dprint(format string, a ...interface{}) {
	if Debug {
		fmt.Fprintf(os.Stderr, format+"\n", a...)
	}
}

var (
	q    int
	n    int
	rows [2][]int
)

func typ(t byte) int {
	switch t {
	case '1', '2':
		return 1
	case '3', '4', '5', '6':
		return 2
	}
	Dprint("Type=%v", t)
	panic("invalid type")
}

// walk from rows[sr][sc] to rows[1][n-1]
func walk(sr, sc int, ltr bool) bool {
	Dprint("walk, sr=%v,v sc=%v, ltr=%v", sr, sc, ltr)
	if sr == 1 && sc == n {
		return true
	}
	if sc >= n || sr < 0 || sr >= 2 {
		return false
	}

	if rows[sr][sc] == 1 {
		if ltr {
			return walk(sr, sc+1, true)
		} else {
			return false
		}
	}

	if rows[sr][sc] == 2 {
		if ltr {
			if sr == 0 {
				return walk(1, sc, false)
			} else {
				return walk(0, sc, false)
			}
		} else {
			return walk(sr, sc+1, true)
		}
	}

	panic("wat")
}

func main() {
	defer writer.Flush()
	Scanf("%d\n", &q)

	for i := 0; i < q; i++ {
		Scanf("%d\n", &n)

		for r := 0; r < 2; r++ {
			rows[r] = make([]int, n)
			for j := 0; j < n; j++ {
				var t byte
				Scanf("%c", &t)
				rows[r][j] = typ(t)
			}
			Scanf("\n")
		}

		Dprint("walk on %v", rows)
		if walk(0, 0, true) {
			Printf("YES\n")
		} else {
			Printf("NO\n")
		}
	}
}

package main

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

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

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

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

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

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

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

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

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

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

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

// DigitSum returns digit sum of a decimal number.
// DigitSum only accept a positive integer.
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// DigitNumOfDecimal returns digits number of n.
// n is non negative number.
func DigitNumOfDecimal(n int) int {
	res := 0

	for n > 0 {
		n /= 10
		res++
	}

	return res
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// Kiriage returns Ceil(a/b)
// a >= 0, b > 0
func Kiriage(a, b int) int {
	return (a + (b - 1)) / b
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of `strconv.Atoi()`.
// If `strconv.Atoi()` returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

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

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

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

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var q int
var n int
var Rows [2][]rune

func main() {
	q = ReadInt()

	for i := 0; i < q; i++ {
		n = ReadInt()
		Rows[0] = ReadRuneSlice()
		Rows[1] = ReadRuneSlice()
		// 現在地
		h, w := 0, 0

		for w < n {
			if Rows[h][w] == '1' || Rows[h][w] == '2' {
				w++
			} else {
				if h == 0 && (Rows[1][w] == '1' || Rows[1][w] == '2') {
					fmt.Println("NO")
					break
				}
				if h == 1 && (Rows[0][w] == '1' || Rows[0][w] == '2') {
					fmt.Println("NO")
					break
				}

				if h == 0 {
					h++
					w++
				} else {
					h--
					w++
				}
			}

			if w == n {
				if h == 0 {
					fmt.Println("NO")
				} else {
					fmt.Println("YES")
				}
			}
		}
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

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

package main

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

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

func f(in io.Reader, out io.Writer) {
	var q int
	fmt.Fscanf(in, "%d\n", &q)

	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 0, 200*1024), 200*1024)

	for i := 0; i < q; i += 1 {
		_ = read(s)
		m := [2][]byte{}
		m[0] = []byte(read((s)))
		m[1] = []byte(read((s)))
		if test(m) {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

func test(m [2][]byte) bool {
	from := "left"
	i := 1
	j := 1

	for true {
		pipe := m[i-1][j-1]

		switch from {
		case "left":
			switch pipe {
			case '1', '2':
				j += 1
			default:
				switch i {
				case 1:
					i += 1
					from = "top"
				case 2:
					i -= 1
					from = "bottom"
				}
			}
		case "top":
			switch pipe {
			case '1', '2':
				return false
			default:
				j += 1
				from = "left"
			}

		case "bottom":
			switch pipe {
			case '1', '2':
				return false
			default:
				j += 1
				from = "left"
			}
		}

		if j > len(m[1]) {
			return i == 2
		}
	}

	return false
}

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

package main

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

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

	var q, n int
	fmt.Fscanf(reader, "%d\n", &q)

	var s1, s2 string

	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Fscanf(reader, "%s\n", &s1)
		fmt.Fscanf(reader, "%s\n", &s2)

		xia := 0
		j := 0
		for ; j < n; j++ {
			if xia == 0 {
				if s1[j] == '1' || s1[j] == '2' {
					xia = 0
				} else {
					xia = 1
					j--
				}
			} else if xia == 1 {
				if s2[j] == '1' || s2[j] == '2' {
					break //NO
				} else {
					xia = 2
				}
			} else if xia == 2 {
				if s2[j] == '1' || s2[j] == '2' {
					xia = 2
				} else {
					xia = 3
					j--
				}
			} else if xia == 3 {
				if s1[j] == '1' || s1[j] == '2' {
					break //NO
				} else {
					xia = 0
				}
			}
		}

		if xia == 2 && j == n {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1234/problem/C

package main

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

type Transition struct {
	From string
	To   string
}

type Move struct {
	X int
	Y int
}

type QueueItem struct {
	X         int
	Y         int
	Direction string
}

var pieceMap = map[string]Transition{
	"1": {From: "Top", To: "Bottom"},
	"2": {From: "Left", To: "Right"},
	"3": {From: "Bottom", To: "Right"},
	"4": {From: "Left", To: "Bottom"},
	"5": {From: "Left", To: "Top"},
	"6": {From: "Top", To: "Right"},
}

var moveMap = map[string]Move{
	"Right":  {X: 0, Y: 1},
	"Bottom": {X: 1, Y: 0},
	"Top":    {X: -1, Y: 0},
}

var oppositeMap = map[string]string{
	"Right":  "Left",
	"Left":   "Right",
	"Top":    "Bottom",
	"Bottom": "Top",
}

var rotations = map[string][]string{
	"1": {"1", "2"},
	"2": {"1", "2"},
	"3": {"3", "4", "5", "6"},
	"4": {"3", "4", "5", "6"},
	"5": {"3", "4", "5", "6"},
	"6": {"3", "4", "5", "6"},
}

func Solve(n int, a []string) string {
	queue := []QueueItem{{0, 0, "Left"}}
	for len(queue) > 0 {
		var item QueueItem
		item, queue = queue[0], queue[1:]
		if item.X == 1 && item.Y == n {
			return "YES"
		}
		if item.X < 0 || item.X > 1 || item.Y < 0 || item.Y > n-1 {
			continue
		}
		currentPiece := string(a[item.X][item.Y])
		for _, pieceID := range rotations[currentPiece] {
			piece := pieceMap[pieceID]
			if item.Direction == piece.From {
				queue = append(queue, QueueItem{
					X:         item.X + moveMap[piece.To].X,
					Y:         item.Y + moveMap[piece.To].Y,
					Direction: oppositeMap[piece.To],
				})
			}
		}
	}
	return "NO"
}

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

	var q int
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		a := make([]string, 2)
		fmt.Fscanf(reader, "%d\n%s\n%s\n", &n, &a[0], &a[1])
		fmt.Fprintf(writer, "%s\n", Solve(n, a))
	}
}

package main

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

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

	var q, n int
	fmt.Fscanf(reader, "%d\n", &q)

	var s1, s2 string

	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Fscanf(reader, "%s\n", &s1)
		fmt.Fscanf(reader, "%s\n", &s2)

		xia := 0
		ans := false
		for j := n - 1; j >= 0 && !ans; j-- {
			if xia == 0 {
				if s2[j] == '1' || s2[j] == '2' {
					xia = 0
				} else {
					xia = 1
					j++
				}
			} else if xia == 1 {
				if s1[j] == '1' || s1[j] == '2' {
					fmt.Printf("NO\n")
					ans = true
				} else {
					xia = 2
				}
			} else if xia == 2 {
				if s1[j] == '1' || s1[j] == '2' {
					xia = 2
				} else {
					xia = 0
				}
			}
		}

		if !ans {
			if xia == 2 {
				fmt.Printf("YES\n")
			} else {
				fmt.Printf("NO\n")
			}
		}
	}
}

package main

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

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

	var q, n int
	fmt.Fscanf(reader, "%d\n", &q)

	var s1, s2 string

	for i := 0; i < q; i++ {
		fmt.Fscanf(reader, "%d\n", &n)
		fmt.Fscanf(reader, "%s\n", &s1)
		fmt.Fscanf(reader, "%s\n", &s2)

		xia := 0
		j := 0
		for ; j < n; j++ {
			if xia == 0 {
				if s2[j] == '1' || s2[j] == '2' {
					xia = 0
				} else {
					xia = 1
					j--
				}
			} else if xia == 1 {
				if s1[j] == '1' || s1[j] == '2' {
					break //NO
				} else {
					xia = 2
				}
			} else if xia == 2 {
				if s1[j] == '1' || s1[j] == '2' {
					xia = 2
				} else {
					xia = 3
					j--
				}
			} else if xia == 3 {
				if s1[j] == '1' || s1[j] == '2' {
					break //NO
				} else {
					xia = 0
				}
			}
		}

		if xia == 2 && j == n {
			fmt.Printf("YES\n")
		} else {
			fmt.Printf("NO\n")
		}
	}
}


Lunar New Year is approaching, and you bought a matrix with lots of "crosses".This matrix $$$M$$$ of size $$$n \times n$$$ contains only 'X' and '.' (without quotes). The element in the $$$i$$$-th row and the $$$j$$$-th column $$$(i, j)$$$ is defined as $$$M(i, j)$$$, where $$$1 \leq i, j \leq n$$$. We define a cross appearing in the $$$i$$$-th row and the $$$j$$$-th column ($$$1 < i, j < n$$$) if and only if $$$M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = $$$ 'X'.The following figure illustrates a cross appearing at position $$$(2, 2)$$$ in a $$$3 \times 3$$$ matrix. X.X.X.X.X Your task is to find out the number of crosses in the given matrix $$$M$$$. Two crosses are different if and only if they appear in different rows or columns.

The first line contains only one positive integer $$$n$$$ ($$$1 \leq n \leq 500$$$), denoting the size of the matrix $$$M$$$. The following $$$n$$$ lines illustrate the matrix $$$M$$$. Each line contains exactly $$$n$$$ characters, each of them is 'X' or '.'. The $$$j$$$-th element in the $$$i$$$-th line represents $$$M(i, j)$$$, where $$$1 \leq i, j \leq n$$$.

Output a single line containing only one integer number $$$k$$$ — the number of crosses in the given matrix $$$M$$$.

NoteIn the first sample, a cross appears at $$$(3, 3)$$$, so the answer is $$$1$$$.In the second sample, no crosses appear since $$$n < 3$$$, so the answer is $$$0$$$.In the third sample, crosses appear at $$$(3, 2)$$$, $$$(3, 4)$$$, $$$(4, 3)$$$, $$$(4, 5)$$$, so the answer is $$$4$$$.

package main

import (
	"fmt"
)

func main() {
	var n, count int
	fmt.Scan(&n)
	m := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&m[i])
	}
	for i := 1; i < n-1; i++ {
		for j := 1; j < n-1; j++ {
			if m[i][j] == 'X' && m[i-1][j-1] == 'X' && m[i-1][j+1] == 'X' && m[i+1][j+1] == 'X' && m[i+1][j-1] == 'X' {
				count += 1
			}
		}
	}
	fmt.Println(count)
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int

	fmt.Fscanf(buf, "%d\n", &n)
	mapp:= make([][]byte,n)
	for i := 0; i < n; i++ {
		v := make([]byte,n)
		fmt.Fscanf(buf,"%s\n",&v)
		mapp[i] = v
		//fmt.Printf("%s",v)
	}
	//fmt.Printf("%s\n",mapp[0])
	res:=0

	for i := 1;i < n-1;i++{
		for j := 1;j < n-1;j++{
			if mapp[i][j] == 'X' && mapp[i-1][j-1]=='X'&& mapp[i-1][j+1]=='X'&& mapp[i+1][j-1]=='X'&& mapp[i+1][j+1]=='X'{
				res++
			}
		}
	}
	fmt.Printf("%d\n",res)
}

package main

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

func readLine(r *bufio.Reader) string {
	v, _ := r.ReadString('\n')
	return strings.Trim(v,"\r\n ")
}
func toInt(s string) int  {
	i, _ := strconv.Atoi(s)
	return i
}

func checkForCross (m *[500][500]byte, i,j int) bool {
	if 	m[i][j] 	 == m[i-1][j-1] &&
		m[i-1][j-1]  == m[i-1][j+1] &&
		m[i-1][j+1]  == m[i+1][j-1] &&
		m [i-1][j+1] == m[i+1][j+1] &&
		m[i][j] 	 == byte('X') {
		return true
	}
	return false
}

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

	var m [500][500]byte

	for i:=0; i<n ; i++  {
		t := []byte(readLine(r))
		for j:=0; j<len(t); j++  {
			m[i][j] = t[j]
		}
	}

	count := 0
	for i:=1; i<n-1 ; i++ {
		for j := 1; j < n-1; j++ {
			if checkForCross(&m, i, j) {
				count++
			}
		}
	}
	fmt.Println(count)

}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	var m = make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &m[i])
	}
	var ans int
	for i := 1; i < n-1; i++ {
		for j := 1; j < n-1; j++ {
			if m[i][j] == 'X' && m[i-1][j-1] == 'X' && m[i-1][j+1] == 'X' && m[i+1][j-1] == 'X' && m[i+1][j+1] == 'X' {
				ans++
			}
		}
	}
	fmt.Println(ans)
}

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 main() {
	defer writer.Flush()
	n := 0
	scanf("%d\n", &n)
	arr := []string{}
	s := ""
	for i := 0; i < n; i++ {
		scanf("%s\n", &s)
		arr = append(arr, s)

	}
	ans := 0
	for i := 1; i < n-1; i++ {
		for j := 1; j < n-1; j++ {
			if arr[i][j] == arr[i-1][j-1] && arr[i][j] == arr[i+1][j+1] && arr[i][j] == arr[i-1][j+1] && arr[i][j] == arr[i+1][j-1] && arr[i][j] == byte('X') {
				ans++
			}
		}
	}
	printf("%d", ans)
}


Немногие знают, что сотрудники ВКонтакте могут менять цвет подсветки в куполе знаменитого Дома Зингера, где расположена штаб-квартира ВКонтакте. Для этого нужно всего лишь отправить сообщение с цветом в специальный чат «Зингер | color», а бот его распознает и сменит подсветку. При этом на время городских мероприятий смена цвета блокируется.Формально, бот обрабатывает три типа сообщений:   lock: заблокировать изменение цвета. Если оно и так заблокировано на данный момент, сообщение игнорируется.  unlock: разблокировать изменение цвета. Если оно и так разблокировано на данный момент, сообщение игнорируется.  red / orange / yellow / green / blue / indigo / violet: изменить цвет купола на заданный, если изменение цвета на данный момент не заблокировано. Вам дана история сообщений, полученных ботом, в хронологическом порядке. Считайте, что перед получением первого сообщения купол подсвечивается голубым (blue), а изменение цвета не заблокировано.Определите, какой цвет будет у купола Дома Зингера после обработки этих сообщений.

В первой строке задано одно целое число $$$n$$$ ($$$1 \le n \le 100$$$) — число сообщений, полученных ботом. В следующих $$$n$$$ строках заданы сообщения, полученные ботом, в хронологическом порядке, по одному сообщению в строке. Каждое сообщение — строка из следующего набора: lock, unlock, red, orange, yellow, green, blue, indigo, violet.

Выведите цвет купола после обработки сообщений ботом.

7
red
violet
unlock
red
orange
lock
indigo

package main

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

const (
	lock    = "lock"
	unlock = "unlock"
)

const (
	red     = "red"
	orange  = "orange"
	yellow  = "yellow"
	green   = "green"
	blue    = "blue"
	indigo  = "indigo"
	violet  = "violet"
)

type State struct {
	status string
	color string
}

func (s *State) DoCmd(cmd string) {
	switch cmd {
	case lock, unlock:
		s.status = cmd
	case red,orange,yellow,green, blue, indigo, violet:
		if s.status == lock {
			return
		}
		s.color = cmd
	}
}

func main() {
	state := State{
		status: unlock,
		color:  blue,
	}

	reader := bufio.NewReader(os.Stdin)
	countLine, _, err := reader.ReadLine()
	if err != nil {
		panic(err.Error())
	}

	countMsgs, err := strconv.Atoi(string(countLine))
	if err != nil {
		panic(err.Error())
	}

	for i := 0; i < countMsgs; i++{
		line, _, err := reader.ReadLine()
		if err != nil {
			fmt.Print(state.color)
			return
		}
		state.DoCmd(string(line))
	}

	fmt.Print(state.color)
}

package main

import "fmt"

func main(){

    var start string = "blue"
    var c int = 0

    ignore := false

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

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

        if msg == "lock" {
            ignore = true
        }else if msg == "unlock" {
            ignore = false
        }else if msg == "red" || msg == "orange" || msg == "yellow" || msg == "green" || msg == "blue" || msg == "indigo" || msg == "violet" {
            if !ignore{
                start = msg
            }
        }
    }
    fmt.Print(start)
}

package main

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

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

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

	current := "blue"
	isLocked := false

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(r, &s)

		if s == "lock" {
			isLocked = true
		} else if s == "unlock" {
			isLocked = false
		} else {
			if isLocked {
				continue
			}
			current = s
		}
	}

	fmt.Println(current)
}

package main

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

const (
    lockState = "lock"
    unlockState = "unlock"
)

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()

    color := "blue"
    lock := false

    cmdNum, _ := strconv.Atoi(scanner.Text())

    for i := 0 ; i < cmdNum ; i ++ {
        scanner.Scan()
        cmd := scanner.Text()

        switch cmd {
        case lockState:
            lock = true
        case unlockState:
            lock = false
        default:
            if !lock {
                color = cmd
            }
        }
    }

    fmt.Println(color)
}

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	col, s, ok := "blue", "", false
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &s)
		if s == "lock" {
			ok = true
			continue
		} else if s == "unlock" {
			ok = false
			continue
		} else {
			if !ok {
				col = s
			}
		}
	}
	fmt.Fprintln(w, col)
	w.Flush()
}

func main() {
	solve()
}

package main

import "fmt"

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

	isLock := false
	color := "blue"
	for i := 0; i < n; i++ {
		var command string
		_, err := fmt.Scanf("%s\n", &command)
		if err != nil {
			return
		}

		if command == "lock" {
			isLock = true
			continue
		}
		if command == "unlock" {
			isLock = false
			continue
		}
		if !isLock {
			color = command
		}
	}

	fmt.Println(color)
}

package main

import (
	"fmt"
)

func main() {
	var i int
	var str string
	curStr := "blue"
	curLockState := false

	_, _ = fmt.Scan(&i)
	for t := 0; t < i; t++ {
		_, _ = fmt.Scan(&str)
		if str == "lock" {
			curLockState = true
			continue
		}
		if str == "unlock" {
			curLockState = false
			continue
		}
		if curLockState == false {
			curStr = str
		}
	}
	fmt.Println(curStr)
}

package main

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

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

	var n int
	fmt.Fscanln(in, &n)

	color := "blue"
	var locked bool

	for i := 0; i < n; i++ {
		var command string
		fmt.Fscanln(in, &command)
		switch command {
		case "lock":
			locked = true
		case "unlock":
			locked = false
		default:
			if !locked {
				color = command
			}
		}
	}

	fmt.Println(color)
}

package main

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

const (
	lock    = "lock"
	unlock = "unlock"
)

const (
	red     = "red"
	orange  = "orange"
	yellow  = "yellow"
	green   = "green"
	blue    = "blue"
	indigo  = "indigo"
	violet  = "violet"
)

type State struct {
	status string
	color string
}

func (s *State) DoCmd(cmd string) {
	switch cmd {
	case lock, unlock:
		s.status = cmd
	case red,orange,yellow,green, blue, indigo, violet:
		if s.status == lock {
			return
		}
		s.color = cmd
	}
}

func main() {
	state := State{
		status: unlock,
		color:  blue,
	}

	reader := bufio.NewReader(os.Stdin)
	countLine, _, err := reader.ReadLine()
	if err != nil {
		panic(err.Error())
	}

	countMsgs, err := strconv.Atoi(string(countLine))
	if err != nil {
		panic(err.Error())
	}

	for i := 0; i < countMsgs-1; i++{
		line, _, err := reader.ReadLine()
		if err != nil {
			fmt.Print(state.color)
			return
		}
		state.DoCmd(string(line))
	}

	fmt.Print(state.color)
}

package main

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

const (
	lock    = "lock"
	unlock = "unlock"
)

const (
	red     = "red"
	orange  = "orange"
	yellow  = "yellow"
	green   = "green"
	blue    = "blue"
	indigo  = "indigo"
	violet  = "violet"
)

type State struct {
	status string
	color string
}

func (s *State) DoCmd(cmd string) {
	switch cmd {
	case lock, unlock:
		s.status = cmd
	case red,orange,yellow,green, blue, indigo, violet:
		if s.status == lock {
			return
		}
		s.color = cmd
	}
}

func main() {
	state := State{
		status: unlock,
		color:  blue,
	}
	reader := bufio.NewReader(os.Stdin)
	line, _, err := reader.ReadLine()
	if err != nil {
		return
	}

	countMsgs, err := strconv.Atoi(string(line))
	if err != nil {
		panic(err.Error())
	}

	for i := 0; i < countMsgs; i++{
		state.DoCmd(string(line))
	}

	fmt.Print(state.color)
}

package main

import "fmt"

func main(){

    var start string = "blue"
    var c int = 0

    ignore := false

    fmt.Scanf("%d", &c)

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

        if msg == "lock" {
            ignore = true
        }else if msg == "unlock" {
            ignore = false
        }else if msg == "red" || msg == "orange" || msg == "yellow" || msg == "green" || msg == "blue" || msg == "indigo" || msg == "violet"{
            if !ignore{
                start = msg
            }
        }
    }
    fmt.Print(start)
}

package main

import "fmt"

func main(){

    var start string = "blue"
    var c int = 0

    ignore := false

    fmt.Scanf("%d", &c)

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

        if msg == "lock" {
            ignore = true
        }else if msg == "unlock" {
            ignore = false
        }else{
            if !ignore{
                start = msg
            }
        }
    }
    fmt.Print(start)
}

package main

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

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

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

	current := "blue"
	isLocked := false

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(r, &s)

		if isLocked {
			continue
		}
		if s == "lock" {
			isLocked = true
		} else if s == "unlock" {
			isLocked = false
		} else {
			current = s
		}
	}

	fmt.Println(current)
}

package main

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

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

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

	current := "blue"
	isLocked := false

	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(r, &s)

		if isLocked {
			continue
		}
		if s == "lock" {
			isLocked = true
		} else if s == "unlocked" {
			isLocked = false
		} else {
			current = s
		}
	}

	fmt.Println(current)
}


For an array $$$b$$$ of $$$n$$$ integers, the extreme value of this array is the minimum number of times (possibly, zero) the following operation has to be performed to make $$$b$$$ non-decreasing:   Select an index $$$i$$$ such that $$$1 \le i \le |b|$$$, where $$$|b|$$$ is the current length of $$$b$$$.  Replace $$$b_i$$$ with two elements $$$x$$$ and $$$y$$$ such that $$$x$$$ and $$$y$$$ both are positive integers and $$$x + y = b_i$$$.  This way, the array $$$b$$$ changes and the next operation is performed on this modified array. For example, if $$$b = [2, 4, 3]$$$ and index $$$2$$$ gets selected, then the possible arrays after this operation are $$$[2, \underline{1}, \underline{3}, 3]$$$, $$$[2, \underline{2}, \underline{2}, 3]$$$, or $$$[2, \underline{3}, \underline{1}, 3]$$$. And consequently, for this array, this single operation is enough to make it non-decreasing: $$$[2, 4, 3] \rightarrow [2, \underline{2}, \underline{2}, 3]$$$.It's easy to see that every array of positive integers can be made non-decreasing this way.YouKn0wWho has an array $$$a$$$ of $$$n$$$ integers. Help him find the sum of extreme values of all nonempty subarrays of $$$a$$$ modulo $$$998\,244\,353$$$. If a subarray appears in $$$a$$$ multiple times, its extreme value should be counted the number of times it appears.An array $$$d$$$ is a subarray of an array $$$c$$$ if $$$d$$$ can be obtained from $$$c$$$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10\,000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^5$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case, print a single integer  — the sum of extreme values of all subarrays of $$$a$$$ modulo $$$998\,244\,353$$$.

NoteLet $$$f(l, r)$$$ denote the extreme value of $$$[a_l, a_{l+1}, \ldots, a_r]$$$.In the first test case,   $$$f(1, 3) = 3$$$, because YouKn0wWho can perform the following operations on the subarray $$$[5, 4, 3]$$$ (the newly inserted elements are underlined):$$$[5, 4, 3] \rightarrow [\underline{3}, \underline{2}, 4, 3] \rightarrow [3, 2, \underline{2}, \underline{2}, 3] \rightarrow [\underline{1}, \underline{2}, 2, 2, 2, 3]$$$; $$$f(1, 2) = 1$$$, because $$$[5, 4] \rightarrow [\underline{2}, \underline{3}, 4]$$$; $$$f(2, 3) = 1$$$, because $$$[4, 3] \rightarrow [\underline{1}, \underline{3}, 3]$$$; $$$f(1, 1) = f(2, 2) = f(3, 3) = 0$$$, because they are already non-decreasing. So the total sum of extreme values of all subarrays of $$$a = 3 + 1 + 1 + 0 + 0 + 0 = 5$$$.

package main

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

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

type big int64

var mod big = 998244353

func main() {
	defer w.Flush()
	var t big
	fmt.Fscan(r, &t)
	for t > 0 {
		t--
		var n big
		fmt.Fscan(r, &n)
		a := make([]big, n)
		for i := big(0); i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		b := make([]big, 0)
		c := make([]big, 0)
		var res big = 0
		for i := n - 1; i >= 0; i-- {
			b2 := make([]big, 1)
			c2 := make([]big, 1)
			b2[0] = a[i]
			c2[0] = 1
			for j := 0; j < len(b); j++ {
				tim := (a[i] - 1) / b[j]
				cur := a[i] / (tim + 1)
				if b2[len(b2)-1] == cur {
					c2[len(c2)-1] += c[j]
				} else {
					b2 = append(b2, cur)
					c2 = append(c2, c[j])
				}
				res = (res + (i+1)*tim%mod*c[j]) % mod
			}
			b = b2
			c = c2
		}
		fmt.Fprintln(w, res)
	}
}

package main

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

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

type big int64

var mod big = 998244353

func main() {
	defer w.Flush()
	var t big
	fmt.Fscan(r, &t)
	for t > 0 {
		t--
		var n big
		fmt.Fscan(r, &n)
		a := make([]big, n)
		for i := big(0); i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		b := make([]big, 1)
		c := make([]big, 1)
		b[0] = a[n-1]
		c[0] = 1
		var res big = 0
		for i := n - 2; i >= 0; i-- {
			b2 := make([]big, 1)
			c2 := make([]big, 1)
			b2[0] = a[i]
			c2[0] = 1
			for j := 0; j < len(b); j++ {
				tim := (a[i] - 1) / b[j]
				cur := a[i] / (tim + 1)
				if b2[len(b2)-1] == cur {
					c2[len(c2)-1] += c[j]
				} else {
					b2 = append(b2, cur)
					c2 = append(c2, c[j])
				}
				res = (res + (i+1)*tim%mod*c[j]) % mod
			}
			b = b2
			c = c2
		}
		fmt.Fprintln(w, res)
	}
}


A binary tree of $$$n$$$ nodes is given. Nodes of the tree are numbered from $$$1$$$ to $$$n$$$ and the root is the node $$$1$$$. Each node can have no child, only one left child, only one right child, or both children. For convenience, let's denote $$$l_u$$$ and $$$r_u$$$ as the left and the right child of the node $$$u$$$ respectively, $$$l_u = 0$$$ if $$$u$$$ does not have the left child, and $$$r_u = 0$$$ if the node $$$u$$$ does not have the right child.Each node has a string label, initially is a single character $$$c_u$$$. Let's define the string representation of the binary tree as the concatenation of the labels of the nodes in the in-order. Formally, let $$$f(u)$$$ be the string representation of the tree rooted at the node $$$u$$$. $$$f(u)$$$ is defined as follows: $$$$$$ f(u) = \begin{cases} \texttt{<empty string>}, & \text{if }u = 0; \\ f(l_u) + c_u + f(r_u) & \text{otherwise}, \end{cases} $$$$$$ where $$$+$$$ denotes the string concatenation operation.This way, the string representation of the tree is $$$f(1)$$$.For each node, we can duplicate its label at most once, that is, assign $$$c_u$$$ with $$$c_u + c_u$$$, but only if $$$u$$$ is the root of the tree, or if its parent also has its label duplicated.You are given the tree and an integer $$$k$$$. What is the lexicographically smallest string representation of the tree, if we can duplicate labels of at most $$$k$$$ nodes?A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:   $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;  in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 2 \cdot 10^5$$$). The second line contains a string $$$c$$$ of $$$n$$$ lower-case English letters, where $$$c_i$$$ is the initial label of the node $$$i$$$ for $$$1 \le i \le n$$$. Note that the given string $$$c$$$ is not the initial string representation of the tree. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i, r_i \le n$$$). If the node $$$i$$$ does not have the left child, $$$l_i = 0$$$, and if the node $$$i$$$ does not have the right child, $$$r_i = 0$$$. It is guaranteed that the given input forms a binary tree, rooted at $$$1$$$.

Print a single line, containing the lexicographically smallest string representation of the tree if at most $$$k$$$ nodes have their labels duplicated.

NoteThe images below present the tree for the examples. The number in each node is the node number, while the subscripted letter is its label. To the right is the string representation of the tree, with each letter having the same color as the corresponding node.Here is the tree for the first example. Here we duplicated the labels of nodes $$$1$$$ and $$$3$$$. We should not duplicate the label of node $$$2$$$ because it would give us the string "bbaaab", which is lexicographically greater than "baaaab".  In the second example, we can duplicate the labels of nodes $$$1$$$ and $$$2$$$. Note that only duplicating the label of the root will produce a worse result than the initial string.  In the third example, we should not duplicate any character at all. Even though we would want to duplicate the label of the node $$$3$$$, by duplicating it we must also duplicate the label of the node $$$2$$$, which produces a worse result.  There is no way to produce string "darkkcyan" from a tree with the initial string representation "darkcyan" :(.

package main

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

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

	n, k := readTwoNums(reader)
	A, _ := reader.ReadString('\n')
	C := make([][]int, n)
	for i := 0; i < n; i++ {
		C[i] = readNNums(reader, 2)
	}
	res := solve(n, k, A, C)
	fmt.Println(res)
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int, k int, A string, C [][]int) string {

	P := make([]int, n)

	var dfs1 func(u int)

	var it int

	dfs1 = func(u int) {
		if C[u][0] > 0 {
			dfs1(C[u][0] - 1)
		}
		P[it] = u
		it++

		if C[u][1] > 0 {
			dfs1(C[u][1] - 1)
		}
	}
	dfs1(0)

	diff := make([]int, n)

	for i := n - 1; i >= 0; i-- {
		diff[P[i]] = P[i]
		if i+1 < n {
			if A[P[i+1]] != A[P[i]] {
				diff[P[i]] = P[i+1]
			} else {
				diff[P[i]] = diff[P[i+1]]
			}
		}
	}

	dup := make([]bool, n)

	var dfs2 func(u, K int) int

	dfs2 = func(u, K int) int {
		if K == 0 {
			return 0
		}
		var res int

		if C[u][0] > 0 {
			res += dfs2(C[u][0]-1, K-1)
		}

		if res > 0 || A[u] < A[diff[u]] {
			// left need to duplicate, so do u
			dup[u] = true
			res++
		}
		if C[u][1] > 0 {
			// 如果u已经dup了, 右子树的处理和它就没有关系
			// 如果u不能dup
			if res > 0 {
				res += dfs2(C[u][1]-1, K-res)
			}
		}
		return res
	}

	dfs2(0, k)

	var buf bytes.Buffer

	for i := 0; i < n; i++ {
		u := P[i]
		buf.WriteByte(A[u])
		if dup[u] {
			buf.WriteByte(A[u])
		}
	}
	return buf.String()
}

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

package main

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

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

	n, k := readTwoNums(reader)
	A, _ := reader.ReadString('\n')
	C := make([][]int, n)
	for i := 0; i < n; i++ {
		C[i] = readNNums(reader, 2)
	}
	res := solve(n, k, A, C)
	fmt.Println(res)
}

func normalize(s string) string {

	for i := len(s); i > 0; i-- {
		if s[i-1] >= 'a' && s[i-1] <= 'z' {
			return s[:i]
		}
	}
	return ""
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int, k int, A string, C [][]int) string {

	P := make([]int, n)

	var dfs1 func(u int)

	var it int

	dfs1 = func(u int) {
		if C[u][0] > 0 {
			dfs1(C[u][0] - 1)
		}
		P[it] = u
		it++

		if C[u][1] > 0 {
			dfs1(C[u][1] - 1)
		}
	}
	dfs1(0)

	diff := make([]int, n)

	for i := n - 1; i >= 0; i-- {
		diff[P[i]] = i
		if i+1 < n {
			if A[P[i+1]] != A[P[i]] {
				diff[P[i]] = P[i+1]
			} else {
				diff[P[i]] = diff[P[i+1]]
			}
		}
	}

	dup := make([]bool, n)

	var dfs2 func(u, K int) int

	dfs2 = func(u, K int) int {
		if K == 0 {
			return 0
		}
		var res int

		if C[u][0] > 0 {
			res += dfs2(C[u][0]-1, K-1)
		}

		if res > 0 || A[u] < A[diff[u]] {
			// left need to duplicate, so do u
			dup[u] = true
			res++
		}
		if C[u][1] > 0 {
			// 如果u已经dup了, 右子树的处理和它就没有关系
			// 如果u不能dup
			if res > 0 {
				res += dfs2(C[u][1]-1, K-res)
			}
		}
		return res
	}

	dfs2(0, k)

	var buf bytes.Buffer

	for i := 0; i < n; i++ {
		u := P[i]
		buf.WriteByte(A[u])
		if dup[u] {
			buf.WriteByte(A[u])
		}
	}
	return buf.String()
}

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


The Squareland national forest is divided into equal $$$1 \times 1$$$ square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates $$$(x, y)$$$ of its south-west corner.Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land $$$A, B, C$$$ in the forest. Initially, all plots in the forest (including the plots $$$A, B, C$$$) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots $$$A, B, C$$$ from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.    For example, $$$A=(0,0)$$$, $$$B=(1,1)$$$, $$$C=(2,2)$$$. The minimal number of plots to be cleared is $$$5$$$. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.

The first line contains two integers $$$x_A$$$ and $$$y_A$$$ — coordinates of the plot $$$A$$$ ($$$0 \leq x_A, y_A \leq 1000$$$). The following two lines describe coordinates $$$(x_B, y_B)$$$ and $$$(x_C, y_C)$$$ of plots $$$B$$$ and $$$C$$$ respectively in the same format ($$$0 \leq x_B, y_B, x_C, y_C \leq 1000$$$). It is guaranteed that all three plots are distinct.

On the first line print a single integer $$$k$$$ — the smallest number of plots needed to be cleaned from trees. The following $$$k$$$ lines should contain coordinates of all plots needed to be cleaned. All $$$k$$$ plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them.

NoteThe first example is shown on the picture in the legend.The second example is illustrated with the following image:

package main

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

var ans int
var ansX []int
var ansY []int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	x := make([]int, 3)
	y := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Fscanf(in, "%d %d\n", &x[i], &y[i])
	}
	ans1, ans1X, ans1Y := solve(x, y)
	x[0], x[2] = x[2], x[0]
	y[0], y[2] = y[2], y[0]
	ans2, ans2X, ans2Y := solve(x, y)
	x[1], x[2] = x[2], x[1]
	y[1], y[2] = y[2], y[1]
	ans3, ans3X, ans3Y := solve(x, y)
	if ans1 <= ans2 && ans1 <= ans3 {
		ans, ansX, ansY = ans1, ans1X, ans1Y
	} else if ans2 <= ans1 && ans2 <= ans3 {
		ans, ansX, ansY = ans2, ans2X, ans2Y
	} else {
		ans, ansX, ansY = ans3, ans3X, ans3Y
	}
	outputAns(out)
	return
}

func solve(x []int, y []int) (int, []int, []int) {
	ans = 0
	ansX = make([]int, 0)
	ansY = make([]int, 0)
	ansX = append(ansX, x[0])
	ansY = append(ansY, y[0])
	ans++
	ansX = append(ansX, x[1])
	ansY = append(ansY, y[1])
	ans++
	fill(x[0], y[0], x[1], y[1])
	//fmt.Println(ans)
	dis := -1
	bestX := 0
	bestY := 0
	for i := 0; i < ans; i++ {
		dish := abs(ansX[i]-x[2]) + abs(ansY[i]-y[2])
		if dis == -1 || dis > dish {
			if dish == 0 {
				//outputAns(out)
				return ans, ansX, ansY
			}
			dis = dish
			bestX = ansX[i]
			bestY = ansY[i]
		}
	}
	ansX = append(ansX, x[2])
	ansY = append(ansY, y[2])
	ans++
	//fmt.Println(ans)
	fill(bestX, bestY, x[2], y[2])
	//outputAns(out)
	return ans, ansX, ansY
}

func outputAns(out io.Writer) {
	fmt.Fprintf(out, "%d\n", ans)
	for i := 0; i < ans; i++ {
		fmt.Fprintf(out, "%d %d\n", ansX[i], ansY[i])
	}
	return
}

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

func fill(x1, y1, x2, y2 int) {
	if x1 > x2 {
		fill(x2, y2, x1, y1)
		return
	}
	if x1 == x2 {
		if y1 < y2 {
			for i := y1 + 1; i < y2; i++ {
				ansX = append(ansX, x1)
				ansY = append(ansY, i)
				ans++
			}
			return
		}
		for i := y2 + 1; i < y1; i++ {
			ansX = append(ansX, x1)
			ansY = append(ansY, i)
			ans++
		}
		return
	}
	if y1 < y2 {
		for i := x1 + 1; i <= x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
		for i := y1 + 1; i < y2; i++ {
			ansX = append(ansX, x2)
			ansY = append(ansY, i)
			ans++
		}
	} else if y1 == y2 {
		for i := x1 + 1; i < x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
	} else {
		for i := x1 + 1; i <= x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
		for i := y2 + 1; i < y1; i++ {
			ansX = append(ansX, x2)
			ansY = append(ansY, i)
			ans++
		}
	}
}

// hmm........
package main

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

var dirs = [][2]int{
	[2]int{-1, 0},
	[2]int{1, 0},
	[2]int{0, -1},
	[2]int{0, 1},
}

func bfs(m [][]bool, root [2]int) (map[[2]int]int, map[[2]int][2]int) {
	w, h := len(m[0]), len(m)
	distance, parent := map[[2]int]int{}, map[[2]int][2]int{}
	visited, queue := map[[2]int]bool{}, [][2]int{}

	for i, l := range m {
		for j, v := range l {
			if v {
				visited[[2]int{i, j}], queue = true, append(queue, [2]int{i, j})
				distance[[2]int{i, j}] = 0
			}
		}
	}
	if !visited[root] {
		queue, distance[root] = append(queue, root), 1
	}

	for len(queue) > 0 {
		newQueue := make([][2]int, 0, len(queue)*2)
		for _, task := range queue {
			for _, d := range dirs {
				newPos := [2]int{task[0] + d[0], task[1] + d[1]}
				if visited[newPos] || (newPos[0] < 0) || (newPos[1] < 0) || (newPos[0] >= h) || (newPos[1] >= w) {
					continue
				}
				visited[newPos], parent[newPos], distance[newPos], newQueue = true, task, distance[task]+1, append(newQueue, newPos)
			}
		}
		queue = newQueue
	}
	return distance, parent
}

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	p, xs, ys := make([][2]int, 3), []int{}, []int{}

	for i := 0; i < 3; i++ {
		scanner.Scan()
		x, _ := strconv.Atoi(scanner.Text())
		xs = append(xs, x)
		scanner.Scan()
		y, _ := strconv.Atoi(scanner.Text())
		p[i] = [2]int{x, y}
		ys = append(ys, y)
	}

	sort.Ints(xs)
	midX, midY := xs[1], -1
	for i := 0; i < 3; i++ {
		if p[i][0] == midX {
			midY = p[i][1]
		}
	}

	visited, count, res := map[[2]int]bool{}, 0, ""
	for i := 0; i < 3; i++ {
		for j := min(midY, p[i][1]); j <= max(midY, p[i][1]); j++ {
			if visited[[2]int{midX, j}] {
				continue
			}
			count++
			visited[[2]int{midX, j}] = true
			res += fmt.Sprintln(midX, j)
		}
	}

	for i := 0; i < 3; i++ {
		for j := min(midX, p[i][0]); j <= max(midX, p[i][0]); j++ {
			if visited[[2]int{j, p[i][1]}] {
				continue
			}
			count++
			visited[[2]int{j, p[i][1]}] = true
			res += fmt.Sprintln(j, p[i][1])
		}
	}
	fmt.Println(count)
	fmt.Println(res)
}

package main

import (
	"fmt"
)

type node struct {
	x, y int
}

func main(){
	var xa, ya, xb, yb, xc, yc int
	fmt.Scan(&xa, &ya, &xb, &yb, &xc, &yc)

	//sort
	if xa > xb{
		t := xa
		xa = xb
		xb =t
		t = ya
		ya = yb
		yb = t
	}
	if xa > xc{
		t := xa
		xa = xc
		xc = t
		t = ya
		ya = yc
		yc = t
	}
	if xb > xc{
		t := xb
		xb = xc
		xc = t
		t = yb
		yb = yc
		yc = t
	}
	var result[] node
	result = append(result, node{xa, ya})
	tmpx := xa
	for ; ;{
		if tmpx < xb{
			tmpx++
			result = append(result, node{tmpx, ya})
		}else {
			break
		}
	}
	tmpy := ya
	for ; ;{
		if tmpy < yb{
			tmpy++
			result = append(result, node{tmpx, tmpy})
		}else if tmpy > yb{
			tmpy--
			result = append(result, node{tmpx, tmpy})
		}else {
			break
		}
	}
	if yc > ya && yc > yb{
		if ya > yb{
			tmpy = ya
		}else {
			tmpy = yb
		}
	}else if yc < ya && yc < yb{
		if ya < yb{
			tmpy = ya
		}else{
			tmpy = yb
		}
	}else{
		tmpy = yc
	}
	for ; ;{
		if tmpx < xc{
			tmpx++
			result = append(result, node{tmpx, tmpy})
		}else {
			break
		}
	}
	for ; ;{
		if tmpy < yc{
			tmpy++
			result = append(result, node{tmpx, tmpy})
		}else if tmpy > yc{
			tmpy--
			result = append(result, node{tmpx, tmpy})
		}else {
			break
		}
	}
	fmt.Println(len(result))
	for _, each := range result{
		fmt.Printf("%d %d\n", each.x, each.y)
	}

	}

package main

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

var ans int
var ansX []int
var ansY []int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	x := make([]int, 3)
	y := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Fscanf(in, "%d %d\n", &x[i], &y[i])
	}
	ans1, ans1X, ans1Y := solve(x, y)
	x[0], x[2] = x[2], x[0]
	y[0], y[2] = y[2], y[0]
	ans2, ans2X, ans2Y := solve(x, y)
	x[1], x[2] = x[2], x[1]
	y[1], y[2] = y[2], y[1]
	ans3, ans3X, ans3Y := solve(x, y)
	if ans1 <= ans2 && ans1 <= ans3 {
		ans, ansX, ansY = ans1, ans1X, ans1Y
	} else if ans2 <= ans1 && ans2 <= ans3 {
		ans, ansX, ansY = ans2, ans2X, ans2Y
	} else {
		ans, ansX, ansY = ans3, ans3X, ans3Y
	}
	outputAns(out)
	return
}

func solve(x []int, y []int) (int, []int, []int) {
	ans = 0
	ansX = make([]int, 0)
	ansY = make([]int, 0)
	ansX = append(ansX, x[0])
	ansY = append(ansY, y[0])
	ans++
	ansX = append(ansX, x[1])
	ansY = append(ansY, y[1])
	ans++
	fill(x[0], y[0], x[1], y[1])
	//fmt.Println(ans)
	dis := -1
	bestX := 0
	bestY := 0
	for i := 0; i < ans; i++ {
		dish := abs(ansX[i]-x[2]) + abs(ansY[i]-y[2])
		if dis == -1 || dis > dish {
			if dish == 0 {
				//outputAns(out)
				return ans, ansX, ansY
			}
			dis = dish
			bestX = ansX[i]
			bestY = ansY[i]
		}
	}
	ansX = append(ansX, x[2])
	ansY = append(ansY, y[2])
	ans++
	//fmt.Println(ans)
	fill(bestX, bestY, x[2], y[2])
	//outputAns(out)
	return ans, ansX, ansY
}

func outputAns(out io.Writer) {
	fmt.Fprintf(out, "%d\n", ans)
	for i := 0; i < ans; i++ {
		fmt.Fprintf(out, "%d %d\n", ansX[i], ansY[i])
	}
	return
}

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

func fill(x1, y1, x2, y2 int) {
	if x1 > x2 {
		fill(x2, y2, x1, y1)
		return
	}
	if x1 == x2 {
		for i := y1 + 1; i < y2; i++ {
			ansX = append(ansX, x1)
			ansY = append(ansY, y1)
			ans++
		}
		return
	}
	if y1 < y2 {
		for i := x1 + 1; i <= x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
		for i := y1 + 1; i < y2; i++ {
			ansX = append(ansX, x2)
			ansY = append(ansY, i)
			ans++
		}
	} else if y1 == y2 {
		for i := x1 + 1; i < x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
	} else {
		for i := x1 + 1; i <= x2; i++ {
			ansX = append(ansX, i)
			ansY = append(ansY, y1)
			ans++
		}
		for i := y2 + 1; i < y1; i++ {
			ansX = append(ansX, x2)
			ansY = append(ansY, i)
			ans++
		}
	}
}


The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $$$n$$$ haybale piles on the farm. The $$$i$$$-th pile contains $$$a_i$$$ haybales. However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an adjacent pile. Formally, in one day she can choose any two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$) such that $$$|i-j|=1$$$ and $$$a_i>0$$$ and apply $$$a_i = a_i - 1$$$, $$$a_j = a_j + 1$$$. She may also decide to not do anything on some days because she is lazy.Bessie wants to maximize the number of haybales in pile $$$1$$$ (i.e. to maximize $$$a_1$$$), and she only has $$$d$$$ days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile $$$1$$$ if she acts optimally!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$)  — the number of test cases. Next $$$2t$$$ lines contain a description of test cases  — two lines per test case. The first line of each test case contains integers $$$n$$$ and $$$d$$$ ($$$1 \le n,d \le 100$$$) — the number of haybale piles and the number of days, respectively.  The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 100$$$)  — the number of haybales in each pile.

For each test case, output one integer: the maximum number of haybales that may be in pile $$$1$$$ after $$$d$$$ days if Bessie acts optimally.

NoteIn the first test case of the sample, this is one possible way Bessie can end up with $$$3$$$ haybales in pile $$$1$$$:   On day one, move a haybale from pile $$$3$$$ to pile $$$2$$$  On day two, move a haybale from pile $$$3$$$ to pile $$$2$$$  On day three, move a haybale from pile $$$2$$$ to pile $$$1$$$  On day four, move a haybale from pile $$$2$$$ to pile $$$1$$$  On day five, do nothing  In the second test case of the sample, Bessie can do nothing on the first day and move a haybale from pile $$$2$$$ to pile $$$1$$$ on the second day.

package main;

import (
	"fmt"
)

func solve() {
	var n, d int
	fmt.Scan(&n, &d)
	var arr = make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	for i := 1; i < n; i++ {
		var tmp int
		if arr[i]<d/i{
			tmp = arr[i]
		} else {
			tmp = d/i
		}
		arr[0] += tmp
		arr[i] -= tmp
		d -= tmp * i
	}
	fmt.Println(arr[0])
}

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import "fmt"

func main() {
	var a [105]int
	var n, d, t, i, cas int
	fmt.Scan(&t)
	for cas = 0; cas < t; cas++ {
		fmt.Scan(&n, &d);
		for i = 1; i <= n; i++ {
			fmt.Scan(&a[i]);
		}
		for i = 2; i <= n; i++ {
			a[1] += min(a[i], d/(i-1))
			d -= min(a[i], d/(i-1)) * (i - 1)

		}
		fmt.Println(a[1])
	}
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main;

import (
    "fmt"
)

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

func solve() {
    var n, d int
    fmt.Scan(&n, &d)
    var a = make([]int, n + 1)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    for i := 1; i < n; i++ {
        var x int = min(a[i], d / i)
        a[0] += x
        a[i] -= x
        d -= x * i
    }
    fmt.Println(a[0])
}

func main() {
    var n int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        solve()
    }
}

package main

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

func scanInt(s *bufio.Scanner) int {
	s.Scan()
	x, _ := strconv.Atoi(s.Text())
	return x
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Buffer(make([]byte, 1<<12), 1<<20)

	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	t := scanInt(s)
	for i := 0; i < t; i++ {
		n, d := scanInt(s), scanInt(s)
		a := make([]int, n)
		for j := 0; j < n; j++ {
			a[j] = scanInt(s)
		}
		r := a[0]
		if n > 1 {
			for x, e := range a[1:] {
				if d > x {
					l := d / (x + 1)
					if l > e {
						d -= e * (x + 1)
						r += e
					} else {
						d -= l * (x + 1)
						r += l
						break
					}
				}
			}
		}
		fmt.Fprintln(w, r)
	}

}

package main

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] != ' ' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(scanner *bufio.Scanner) (a int) {
	scanner.Scan()
	readInt(scanner.Bytes(), 0, &a)
	return
}

func readTwoNums(scanner *bufio.Scanner) (a int, b int) {
	res := readNNums(scanner, 2)
	a, b = res[0], res[1]
	return
}

func readNNums(scanner *bufio.Scanner, n int) []int {
	res := make([]int, n)
	x := 0
	scanner.Scan()
	for i := 0; i < n; i++ {
		for x < len(scanner.Bytes()) && scanner.Bytes()[x] == ' ' {
			x++
		}
		x = readInt(scanner.Bytes(), x, &res[i])
	}
	return res
}

func fillNNums(scanner *bufio.Scanner, n int, res []int) {
	x := 0
	scanner.Scan()
	for i := 0; i < n; i++ {
		for x < len(scanner.Bytes()) && scanner.Bytes()[x] == ' ' {
			x++
		}
		x = readInt(scanner.Bytes(), x, &res[i])
	}
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] != ' ' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func readInt64(bytes []byte, from int, val *int64) int {
	i := from
	var tmp int64
	for i < len(bytes) && bytes[i] != ' ' {
		tmp = tmp*10 + int64(bytes[i]-'0')
		i++
	}
	*val = tmp
	return i
}

func readNInt64Nums(scanner *bufio.Scanner, n int) []int64 {
	res := make([]int64, n)
	x := -1
	scanner.Scan()
	for i := 0; i < n; i++ {
		x = readInt64(scanner.Bytes(), x+1, &res[i])
	}
	return res
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	tc := readNum(scanner)

	for tc > 0 {
		tc--
		n, d := readTwoNums(scanner)
		A := readNNums(scanner, n)
		fmt.Println(solve(n, d, A))
	}
}

func solve(n, d int, A []int) int {
	var res int

	for i := 1; i < n && d > 0; i++ {
		a := A[i]
		b := min(d, a*i)
		res += b / i
		d -= b
	}

	return A[0] + res
}

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

package main

import "fmt"

var (
        t, n, d int
        a [101]int
)

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

func main() {
        fmt.Scan(&t)
        for i := 0; i < t; i++ {
                fmt.Scan(&n, &d)
                for j := 0; j < n; j++ {
                        fmt.Scan(&a[j])
                }
                ans := a[0]
                for j := 1; j < n; j++ {
                        tmp := min(d/j, a[j])
                        ans += tmp
                        d -= tmp*j
                }
                fmt.Println(ans)
        }
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	cases := getIntFromInput(scanner)
	for i := int64(0); i < cases; i++ {
		scanner.Scan()
		arrs := scanner.Text()
		arr := strings.Split(arrs, " ")
		num, _ := strconv.ParseInt(arr[0], 10, 64)
		days, _ := strconv.ParseInt(arr[1], 10, 64)
		scanner.Scan()
		arrs = scanner.Text()
		arr = strings.Split(arrs, " ")
		a1, _ := strconv.ParseInt(arr[0], 10, 64)
		for i := int64(1); i < num; i++ {
			ai, _ := strconv.ParseInt(arr[i], 10, 64)
			if ai * i >= days {
				r := days / i
				a1 += r
				days = 0
				break
			} else {
				a1 += ai
				days -= ai * i
			}
		}
		fmt.Println(a1)
	}
}

func getIntFromInput(s *bufio.Scanner) int64 {
	s.Scan()
	numStr := s.Text()
	num, _ := strconv.ParseInt(string(numStr), 10, 64)
	return num
}

package main

import "fmt"
import "os"
import "bufio"
import "strings"
import "strconv"

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    line := scanner.Text()
    t, _ := strconv.Atoi(line)
    for i := 0; i < t; i++ {
        scanner.Scan()
        line = scanner.Text()
        parts := strings.Split(line, " ")
        n, _ := strconv.Atoi(parts[0])
        d, _ := strconv.Atoi(parts[1])
        a := make([]int, n)
        scanner.Scan()
        line = scanner.Text()
        parts = strings.Split(line, " ")
        for j := 0; j < n; j++ {
            a[j], _ = strconv.Atoi(parts[j])
        }
        //~ fmt.Println(n, d, a)

        days := 0
        for j := 1; j < n && days < d; j++ {
            for a[j] > 0 && days < d {
                for k := j; k > 0 && days < d; k-- {
                    a[k]--
                    a[k - 1]++
                    days++
                }
            }
        }

        fmt.Println(a[0])
    }
}

package main

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

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

	var T int
	fmt.Fscanf(reader, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n, d int
		fmt.Fscanf(reader, "%d %d\n", &n, &d)

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

		b := a[1:]

		for i := 0; i < len(b); i++ {
			for b[i] > 0 && d >= (i+1) {
				a[0] += 1
				b[i]--
				d -= (i + 1)
			}
		}

		fmt.Fprintf(writer, "%d\n", a[0])
	}
}

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

package main

import (
	"fmt"
)

func main(){
	var t int
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		var n, d int
		var c []int
		var res int
		fmt.Scanf("%d%d\n", &n, &d)

		for i:= 0; i < n; i++{
			var x int
			fmt.Scanf("%d", &x)
			c = append(c, x)
		}
		fmt.Scanf("\n")
		res = c[0]

		for i:= 1; i < n; i++{
			x := c[i]
			z := x * i
			if z < d {
				res += x
				d -= z
			} else {
				res += d / i
				break
			}
		}
		fmt.Println(res)

		t--
	}
}

package main

import (
        "fmt"
)

func calculateMaxHayBale(n int, d int, a []int) int {
        max := a[0]
        bale := 1
        for d > 0 && bale < n {
                increment := d / bale
                if increment > a[bale] {
                        increment = a[bale]
                }
                a[bale] -= increment
                if increment == 0 {
                        bale++
                        continue
                }
                max += increment
                d -= increment * bale
                // fmt.Printf("Increment = %v, max=%v, d=%v\n", increment, max, d)
        }

        return max
}

func main() {
        numTestCases := 0
        fmt.Scan(&numTestCases)
        for i := 0; i < numTestCases; i++ {
                n, d := 0, 0
                fmt.Scan(&n)
                fmt.Scan(&d)

                a := make([]int, n)
                for j := range a {
                        fmt.Scan(&a[j])
                }

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

package main;

import (
	"fmt"
)

func solve() {
	var n, d int
	fmt.Scan(&n, &d)
	var arr = make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}
	for i := 1; i < n; i++ {
		var tmp int
		if arr[i]< d/i{
			tmp = arr[i]
		} else{
			tmp = d
		}
		arr[0] += tmp
		arr[i] -= tmp
		d -= tmp * i
	}
	fmt.Println(arr[0])
}

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

import "fmt"

func main() {
	var a [105]int
	var n, d, t, i, cas int
	fmt.Scan(&t)
	for cas = 0; cas < 10; cas++ {
		fmt.Scan(&n, &d);
		for i = 1; i <= n; i++ {
			fmt.Scan(&a[i]);
		}
		for i = 2; i <= n; i++ {
			a[1] += min(a[i], d/(i-1))
			d -= min(a[i], d/(i-1)) * (i - 1)

		}
		fmt.Println(a[1])
	}
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import "fmt"

var (
        t, n, d int
        a [101]int
)

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

func main() {
        fmt.Scanln(&t)
        for i := 0; i < t; i++ {
                fmt.Scanf("%d%d",&n, &d)
                for j := 0; j < n; j++ {
                        fmt.Scanf("%d", &a[j])
                }
                ans := a[0]
                for j := 1; j < n; j++ {
                        tmp := min(d/j, a[j])
                        ans += tmp
                        d -= tmp*j
                }
                fmt.Println(ans)
        }
}

package main

import "fmt"
import "os"
import "bufio"
import "strings"
import "strconv"

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    line := scanner.Text()
    t, _ := strconv.Atoi(line)
    for i := 0; i < t; i++ {
        scanner.Scan()
        line = scanner.Text()
        parts := strings.Split(line, " ")
        n, _ := strconv.Atoi(parts[0])
        d, _ := strconv.Atoi(parts[1])
        a := make([]int, n)
        scanner.Scan()
        line = scanner.Text()
        parts = strings.Split(line, " ")
        for j := 0; j < n; j++ {
            a[j], _ = strconv.Atoi(parts[j])
        }
        //~ fmt.Println(n, d, a)

        days := 0
        for j := 1; j < n && days < d; j++ {
            for k := j; k > 0 && days < d; k-- {
                a[k]--
                a[k - 1]++
                days++
            }
        }

        fmt.Println(a[0])
    }
}

package main

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

func calculateMaxHayBale(n int, d int, a []int) int {
        max := a[0]
        bale := 1
        for d > 0 && bale < n {
                increment := d / bale
                if increment > a[bale] {
                        increment = a[bale]
                }
                a[bale] -= increment
                if increment == 0 {
                        bale++
                        continue
                }
                max += increment
                d -= increment * bale
                // fmt.Printf("Increment = %v, max=%v, d=%v\n", increment, max, d)
        }

        return max
}

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

        line, _, _ := reader.ReadLine()
        fmt.Sscanf(string(line), "%d", &numTestCases)
        for i := 0; i < numTestCases; i++ {
                n, d := 0, 0
                line, _, _ := reader.ReadLine()
                fmt.Sscanf(string(line), "%d %d", &n, &d)

                a := make([]int, n)
                line, _, _ = reader.ReadLine()
                for j := range a {
                        fmt.Sscanf(string(line), "%d", &a[j])
                }

                fmt.Printf("n=%d, d=%d, a=%v\n", n, d, a)
                fmt.Printf("%d\n", calculateMaxHayBale(n, d, a))
        }
}

package main

import (
        "fmt"
)

func calculateMaxHayBale(n int, d int, a []int) int {
        max := a[0]
        bale := 1
        for d > 0 && bale < n {
                increment := d / bale
                if increment > a[bale] {
                        increment = a[bale]
                }
                a[bale] -= increment
                if increment == 0 {
                        bale++
                        continue
                }
                max += increment
                d -= increment * bale
                // fmt.Printf("Increment = %v, max=%v, d=%v\n", increment, max, d)
        }

        return max
}

func main() {
        numTestCases := 0
        fmt.Scanf("%d\r\n", &numTestCases)
        n, d := 0, 0
        for i := 0; i < numTestCases; i++ {
                fmt.Scanf("%d %d\r\n", &n, &d)

                a := make([]int, n)
                for j := range a {
                        fmt.Scanf("%d", &a[j])
                }

                fmt.Printf("n=%d, d=%d, a=%v\n", n, d, a)
                fmt.Printf("%d\n", calculateMaxHayBale(n, d, a))
        }
}

package main

import (
        "fmt"
)

func calculateMaxHayBale(n int, d int, a []int) int {
        max := a[0]
        bale := 1
        for d > 0 && bale < n {
                increment := d / bale
                if increment > a[bale] {
                        increment = a[bale]
                }
                a[bale] -= increment
                if increment == 0 {
                        bale++
                        continue
                }
                max += increment
                d -= increment * bale
                // fmt.Printf("Increment = %v, max=%v, d=%v\n", increment, max, d)
        }

        return max
}

func main() {
        numTestCases := 0
        fmt.Scanf("%d\n", &numTestCases)
        n, d := 0, 0
        for i := 0; i < numTestCases; i++ {
                fmt.Scanf("%d %d\n", &n, &d)

                a := make([]int, n)
                for j := range a {
                        fmt.Scanf("%d", &a[j])
                }

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

package main

import (
        "fmt"
)

func calculateMaxHayBale(n int, d int, a []int) int {
        max := a[0]
        bale := 1
        for d > 0 && bale < n {
                increment := d / bale
                if increment > a[bale] {
                        increment = a[bale]
                }
                a[bale] -= increment
                if increment == 0 {
                        bale++
                        continue
                }
                max += increment
                d -= increment * bale
                // fmt.Printf("Increment = %v, max=%v, d=%v\n", increment, max, d)
        }

        return max
}

func main() {
        numTestCases := 0
        fmt.Scan(&numTestCases)
        for i := 0; i < numTestCases; i++ {
                n, d := 0, 0
                fmt.Scan(&n)
                fmt.Scan(&d)

                a := make([]int, n)
                for j := range a {
                        fmt.Scan(&a[j])
                }

                fmt.Printf("n=%d, d=%d, a=%v\n", n, d, a)
                fmt.Printf("%d\n", calculateMaxHayBale(n, d, a))
        }
}

package main

import (
        "fmt"
)

func calculateMaxHayBale(n int, d int, a []int) int {
        max := a[0]
        bale := 1
        for d > 0 && bale < n {
                increment := d / bale
                if increment > a[bale] {
                        increment = a[bale]
                }
                a[bale] -= increment
                if increment == 0 {
                        bale++
                        continue
                }
                max += increment
                d -= increment * bale
                // fmt.Printf("Increment = %v, max=%v, d=%v\n", increment, max, d)
        }

        return max
}

func main() {
        numTestCases := 0
        fmt.Scanf("%d\n", &numTestCases)
        n, d := 0, 0
        for i := 0; i < numTestCases; i++ {
                fmt.Scanf("%d %d\n", &n, &d)

                a := make([]int, n)
                for j := range a {
                        fmt.Scanf("%d", &a[j])
                }

                fmt.Printf("n=%d, d=%d, a=%v\n", n, d, a)
                fmt.Printf("%d\n", calculateMaxHayBale(n, d, a))
        }
}

package main

import "fmt"

func main() {
	nums := [3]int {1, 2, 3}
	for i, val := range nums {
		fmt.Println(val, i)
	}
}

package main;

import (
	"fmt"
)

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

func solve() {
	var n, d int
	fmt.Scan(&n, &d)
	var a = make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Scanf("%v", &a[i])
	}
	for i := 1; i < n; i++ {
		var x int = min(a[i], d / i)
		a[0] += x
		a[i] -= x
		d -= x * i
	}
	fmt.Println(a[0])
}

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main;

import "fmt"

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

func solve() {
	var n, d int
	fmt.Scan(&n, &d)
	var a = make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Scan("%d", &a[i])
	}
	for i := 1; i < n; i++ {
		var x int = min(a[i], d / i)
		a[0] += x
		a[i] -= x
		d -= x * i
	}
	fmt.Println(a[0])
}

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main;

import "fmt"

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

func solve() {
	var n, d int
	fmt.Scan(&n, &d)
	var a = make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d ", &a[i])
	}
	for i := 1; i < n; i++ {
		var x int = min(a[i], d / i)
		a[0] += x
		a[i] -= x
		d -= x * i
	}
	fmt.Println(a[0])
}

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main;

import "fmt"

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

func solve() {
	var n, d int
	fmt.Scan(&n, &d)
	var a = make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Scanf("%v", &a[i])
	}
	for i := 1; i < n; i++ {
		var x int = min(a[i], d / i)
		a[0] += x
		a[i] -= x
		d -= x * i
	}
	fmt.Println(a[0])
}

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main;

import "fmt"

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

func solve() {
	var n, d int
	fmt.Scan(&n, &d)
	var a = make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	for i := 1; i < n; i++ {
		var x int = min(a[i], d / i)
		a[0] += x
		a[i] -= x
		d -= x * i
	}
	fmt.Println(a[0])
}

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}


Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them.Now Pari asks you to write a program that gets a huge integer n from the input and tells what is the n-th even-length positive palindrome number?

The only line of the input contains a single integer n (1 ≤ n ≤ 10100 000).

Print the n-th even-length palindrome number.

NoteThe first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.

package main

import (
	"fmt"
)

func main() {
	var str string;
	fmt.Scan(&str)

  l := len(str)
  m := make([]rune, l)

  for _, c := range str {
    l--
    m[l] = c
  }

	fmt.Printf("%s%s\n", str, string(m))
}

package main

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

func main() {
	bio := bufio.NewReaderSize(os.Stdin, 100010)

	line, _, err := bio.ReadLine();

	if err != nil {
		panic(err)
	}

	fmt.Print(string(line))
	for i := len(line) - 1; i >= 0; i-- {
		fmt.Print(string(line[i]))
	}
}

// hello project main.go
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%s", &s)
	runes := []rune(s)
	for from, to := 0, len(runes)-1; from < to; from, to = from+1, to-1 {
		runes[from], runes[to] = runes[to], runes[from]
	}
	fmt.Println(s + string(runes))
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var s string
	fmt.Fscanln(reader, &s)
	l := len(s) * 2
	arr := make([]rune, l)
	for i, c := range s {
		arr[i] = c
		arr[l-i-1] = c
	}
	fmt.Fprintln(writer, string(arr))
}

package main

import(
    "fmt"
)

func main() {
    var n string
    fmt.Scanf("%s", &n)
    fmt.Print(n)
    for i := len(n) - 1; i >= 0; i-- {
        fmt.Print(n[i:i+1])
    }
    fmt.Println()
}

package main

import (
	"fmt"
)

func reverse(s string) string {
	runes := []rune(s)
	for from, to := 0, len(runes)-1; from < to; from, to = from+1, to-1 {
		runes[from], runes[to] = runes[to], runes[from]
	}
	return string(runes)
}

func main() {
	s := ""
	fmt.Scan(&s)
	s += reverse(s)
	fmt.Println(s)
}

package main

import "fmt"

func main() {
    var str string
    fmt.Scan(&str)
    fmt.Print(str)
    runes := []rune(str)
    for i:=len(runes)-1; i>=0; i-- {
        fmt.Printf("%c", runes[i])
    }
}

package main

import (
	"fmt"
)

func main() {
	var N string
	fmt.Scan(&N)
	fmt.Println(N + reverseString(N))
}
func reverseString(a string) string {
	r := make([]byte, len(a))
	for i := len(a) - 1; i >= 0; i-- {
		r[i] = a[len(a) - i - 1]
	}
	return string(r)
}

package main

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

func main() {
	bio := bufio.NewReader(os.Stdin)
	line, _, err := bio.ReadLine();

	if err != nil {
		panic(err)
	}

	fmt.Print(string(line))
	for i := len(line) - 1; i >= 0; i-- {
		fmt.Print(string(line[i]))
	}
}

package main

import "fmt"

func main() {
    var n string
    fmt.Scan(&n)
    fmt.Print(n)
    for i:=len(n)-1; i>=0; i-- {
        fmt.Print(n[i])
    }
}

package main

import "fmt"

func main() {
    var str string
    fmt.Scan(&str)
    fmt.Print(str)
    runes := []rune(str)
    fmt.Println(runes)
    for i:=len(runes)-1; i>=0; i-- {
        fmt.Print(runes[i])
    }
}

package main

import "fmt"

func main() {
    var n string
    fmt.Scan(&n)
    fmt.Print(n)
    runes := []rune(n)
    for i:=len(runes)-1; i>=0; i-- {
        fmt.Print(runes[i])
    }
}

package main

import "fmt"

func main() {
    var n string
    fmt.Scan(&n)
    fmt.Print(n)
    runes := []rune(n)
    for i:=len(runes)-1; i>=0; i-- {
        fmt.Print(rune(runes[i]))
    }
}