New Year is coming in Line World! In this world, there are n cells numbered by integers from 1 to n, as a 1 × n board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of n - 1 positive integers a1, a2, ..., an - 1. For every integer i where 1 ≤ i ≤ n - 1 the condition 1 ≤ ai ≤ n - i holds. Next, he made n - 1 portals, numbered by integers from 1 to n - 1. The i-th (1 ≤ i ≤ n - 1) portal connects cell i and cell (i + ai), and one can travel from cell i to cell (i + ai) using the i-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (i + ai) to cell i using the i-th portal. It is easy to see that because of condition 1 ≤ ai ≤ n - i one can't leave the Line World using portals.Currently, I am standing at cell 1, and I want to go to cell t. However, I don't know whether it is possible to go there. Please determine whether I can go to cell t by only using the construted transportation system.

The first line contains two space-separated integers n (3 ≤ n ≤ 3 × 104) and t (2 ≤ t ≤ n) — the number of cells, and the index of the cell which I want to go to. The second line contains n - 1 space-separated integers a1, a2, ..., an - 1 (1 ≤ ai ≤ n - i). It is guaranteed, that using the given transportation system, one cannot leave the Line World.

If I can go to cell t using the transportation system, print "YES". Otherwise, print "NO".

NoteIn the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit.

package main

import "fmt"

func main() {
	var n, t int
	fmt.Scanf("%d%d", &n, &t)
	t--
	a := make([]int, n-1)
	for i := range a {
		fmt.Scan(&a[i])
	}
	var i int
	for ; i < n-1 && i != t; i += a[i] {
	}
	if i == t {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"fmt"
)

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

	s := 1
	A := make([]int, n)
	for i := 1; i <= n-1; i++ {
		fmt.Scanf("%d", &A[i])
	}
	for s < t {
		s += A[s]
	}

	if s == t {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import "fmt"

func main() {
	var n, t int
	fmt.Scan(&n, &t)
	a := make([]int, n)
	for i := 1; i < n; i++ {
		fmt.Scan(&a[i])
	}
	i := 1
	for {
		if i == t {
			fmt.Println("YES")
			return
		}
		if i > t {
			fmt.Println("NO")
			return
		}
		i += a[i]
	}
}

package main
import "fmt"

func main() {
	var(
		n, t int
		index = 1
	)
	fmt.Scanln(&n, &t)
	a := make([]int, n-1)
	for i := 0; i < n-1; i ++ {
		fmt.Scanf("%d", &a[i])
	}

	for i, ai := range a {
		if (i+1) == index {
			index += ai
			if index == t {
				fmt.Println("Yes")
				break;
			}else if index > t {
				fmt.Println("No")
				break;
			}
		}
	}
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, t := nextInt(), nextInt()
	a := make([]int, n)

	for i := 1; i < n; i++ {
		a[i] = nextInt()
	}

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

		if i == t {
			println("YES")
			return
		}
	}

	println("NO")
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

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

func toInt(buf []byte) (n int64) {
	for _, v := range buf {
		n = n * 10 + int64(v - '0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var position int64
	scanner.Scan()
	scanner.Scan()
	position = toInt(scanner.Bytes())
	myPosition := int64(1)
	index := int64(1)
	if position == 1 {
		fmt.Println("YES")
		return
	}
	for scanner.Scan() && myPosition < position {
		if index == myPosition {
			portal := toInt(scanner.Bytes())
			myPosition += portal
			if myPosition == position {
				fmt.Println("YES")
				return
			}
		}
		index++
	}
	fmt.Println("NO")
}

package main

import (
	"bufio"
	"os"
)

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n * 10 + int(v - '0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var position int
	scanner.Scan()
	scanner.Scan()
	position = toInt(scanner.Bytes())
	myPosition := 1
	index := 1
	for scanner.Scan() {
		if index == myPosition {
			portal := toInt(scanner.Bytes())
			myPosition += portal
			if myPosition == position {
				writer.WriteString("YES")
				return
			}
			if myPosition > position {
				break
			}
		}
		index++
	}
	writer.WriteString("NO")
}

package main

import ("fmt")

func main() {
	var n, t int
	fmt.Scanf("%d %d\n", &n, &t)
	arr := make([]int, n - 1)
	for i := 0; i < n - 1; i++ {
		fmt.Scanf("%d", &arr[i])
	}

	var res, i int
	for res < t-1 {
		res = i + arr[i]
		i = res
	}

	if res+1 == t {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import (
    "fmt"
)

func main() {
    var n, k int
    fmt.Scanf("%d %d ", &n, &k)
    array := make([]int, n)
    i := 0
    for ; i < n-1 ; i++ {
        fmt.Scanf("%d", &array[i])
    }
    i = 1
    for i <= n {
        if i == k {
            fmt.Printf("YES")
            return
        }
        if array[i-1] == 0 {
            break
        }
        i += array[i-1]
    }
    fmt.Printf("NO")
}

package main

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

func GetScanner() func(a ...*int) {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)

    ScanInts := func(a ...*int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }
    return ScanInts
}

func main() {
    ScanInts := GetScanner()
    var n, dest int
    ScanInts(&n, &dest)
    arr := make([]int, n, n)
    for i := 1; i < n; i++ {
        ScanInts(&arr[i])
    }
    start := 1
    for {
        if start == dest {
            fmt.Println("YES")
            break
        }
        if start == n {
            fmt.Println("NO")
            break
        }
        start = start + arr[start]
    }
}

package main

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

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

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

	reader := bufio.NewReader(os.Stdin)
	ss, _ := reader.ReadString('\n')
	list := strings.Split(strings.TrimRight(ss, "\r\n"), " ")

	for i := 0; i < n-1; i++ {
		t, _ := strconv.ParseUint(list[i], 10, 64)
		arr = append(arr, int(t))
	}

	s := 1
	for s < d && s < n {
		s += arr[s-1]
		if s == d {
			fmt.Print("YES")
			return
		}
	}
	fmt.Print("NO")
}

package main

import (
	"fmt"
)

var (
	n      int
	t      int
	a      []int
	result bool
)

func in() {
	fmt.Scanf("%d %d\n", &n, &t)
	a = make([]int, n-1)
	for i := 0; i < n-1; i++ {
		fmt.Scanf("%d", &a[i])
	}
}

func out() {
	if result == true {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func run() {
	result = false
	for cell := 1; cell < n; {
		cell += a[cell-1]
		if cell == t {
			result = true
			break
		}
	}
}

func main() {
	in()
	run()
	out()
}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"io"
	"math/rand"
	"os"
	"strconv"
	"time"
	"unicode/utf8"
)

// ******************************** CODE STARTS ********************************

const ()

var (
	G   [][]int
	was []bool
)

func dfs(v int) {
	if was[v] {
		return
	}
	was[v] = true

	for i := 0; i < len(G[v]); i++ {
		dfs(G[v][i])
	}
}

func solve() {
	n := readInt()
	finish := readInt() - 1
	start := 0
	G = make([][]int, n)
	was = make([]bool, n)

	for i := 0; i < n-1; i++ {
		value := readInt()
		G[i] = append(G[i], i+value)
	}

	dfs(start)
	if was[finish] {
		printString("YES")
	} else {
		printString("NO")
	}
	printLine()
}

// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
)

func main() {
	input := os.Stdin
	output := os.Stdout
	//	input, _ := os.Open("")
	//	output, _ := os.Create("")

	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	rand.Seed(int64(time.Now().Nanosecond()))
	solve()
}

// Read.

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

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

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

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

// Sorting

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	if p[j].a == p[i].a {
		return p[j].b < p[i].b
	} else {
		return p[j].a < p[i].a
	}
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

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

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

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

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

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

import (
	"fmt"
)
// MsgYes is a message for YES
const MsgYes = "YES"
// MsgNo is a message for No
const MsgNo = "NO"

func main() {

	var total int
	var dest int
	var currentStep int = 1
	var skipping int = 0

	fmt.Scanln(&total, &dest)

	for ; total > 0; total-- {
		var v int

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

		// consuming
		if skipping > 0 {
			skipping--
			continue
		}

		if currentStep < dest {
			currentStep += v
			skipping = v - 1
		} else if currentStep == dest {
			fmt.Println(MsgYes)
			return;
		} else {
			fmt.Println(MsgNo)
			return;
		}
	}

}

package main

import "fmt"

type Point struct {
	x int
	y int
}

var aa []int
var max, des int
var temp []int

func main() {
	var x int
	fmt.Scanf("%d", &x)
	fmt.Scanf("%d\n", &des)
	//fmt.Println(x, des)
	max = x
	des--
	max--
	var a []int
	a = make([]int, x-1)
	temp = make([]int, x)
	for i := 0; i < x-1; i++ {
		fmt.Scanf("%d", &a[i])
	}
	//fmt.Println(a)
	aa = make([]int, x)
	for i := 0; i < x-1; i++ {
		//fmt.Println(i, i+a[i])
		aa[i] = i + a[i]
	}

	if aa[0] == des {
		fmt.Println("YES")
		return
	}

	// 剪支
	ret1 := false
	for _, i := range aa {
		if aa[i] == des {
			ret1 = true
			break
		}
	}
	if !ret1 {
		fmt.Println("NO")
		return
	}

	if ret := dfs(0); ret {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(x int) bool {
	//fmt.Println(x)
	if x == des {
		temp[x] = 2
		return true
	}
	if x > des {
		temp[x] = 1
		return false
	}

	for i := x + 1; i <= des; i++ {
		if temp[i] == 2 {
			return true
		}
		if temp[i] != 1 && aa[x] == i && dfs(i) {
			temp[i] = 2
			return true
		}
	}
	temp[x] = 1
	return false
}

package main

import "fmt"

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

	ok := false
	path := make([]int, n)
	for i := 1; i < n; i++ {
		fmt.Scan(&path[i])
	}

	door := 1
	for door < n {
		if door+path[door] == dst {
			ok = true
			break
		}
		door = door + path[door]
	}

	if ok {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n, t int
var a []int

func main() {
	fmt.Fscan(reader, &n, &t)
	a = make([]int, n)
	for i := 1; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}
	cnt := 1
	for cnt < t {
		cnt += a[cnt]
	}
	if cnt == t {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import "fmt"

func main() {
	var n, t int

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

	m := 1
	for m < t {
		m += a[m-1]

	}
	if m == t {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

// GB2014_A
package main

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

const MAX_N = 30000 + 1

var (
	Inp  = bufio.NewReader(os.Stdin)
	N, T int
	A    [MAX_N]int
	DD   [MAX_N]bool
)

func main() {
	fmt.Fscan(Inp, &N, &T)
	for i := 1; i < N; i++ {
		fmt.Fscan(Inp, &A[i])
	}
	DD[1] = true
	Cur := 1
	for {
		DD[Cur] = true
		if Cur == N {
			break
		}
		Cur += A[Cur]
	}
	if DD[T] {
		fmt.Print("YES\n")
	} else {
		fmt.Print("NO\n")
	}
}

package main

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

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

    ports := make([]int, n, n)
    bs := bufio.NewScanner(os.Stdin)
    bs.Split(bufio.ScanWords)
    for i := 0; i < n-1; i++ {
        bs.Scan()
        ports[i], _ = strconv.Atoi(bs.Text())
    }

    cur := 1
    for cur < t {
        cur += ports[cur-1]
    }

    if cur == t {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

//  URL: http://codeforces.com/problemset/problem/500/A
//  ~ Basic Implementation Problem

package main

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

func solve(arr []int, n int, target int) string {
	current := 1
	for current <= target {
		if current == target {
			return "YES"
		}
		current += arr[current - 1]
	}
	return "NO"
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n, t int
	fmt.Fscanf(reader, "%d %d\n", &n, &t)
	a := make([]int, n)
	for i := 0; i < n - 1; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fprintf(writer, "%s\n", solve(a, n, t))
}

package main

import "fmt"

func dfs(A []int, i, t int) bool {
	if i == t {
		return true
	}

	if A[i] == -1 {
		return false
	}

	tmp := A[i]
	A[i] = -1

	return dfs(A, tmp + i, t)
}

func main()  {
	var n, t int
	fmt.Scanf("%d %d\n", &n, &t)
	var A = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &A[i])
	}

	if dfs(A, 0, t - 1) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(inList []int, t int, n int) int {
	temp := 1
	//fmt.Println(temp, t)
	if t == temp {
		return temp
	}
	for temp < t && temp < n {
		//fmt.Println(temp, t)
		temp += inList[temp-1]
		if temp == t {
			return t
		}

	}

	//fmt.Println(temp, t)
	return temp

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var t, n, ret int
	var inList []int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())
	scanner.Scan()
	t = fastGetInt(scanner.Bytes())

	for x := 0; x < n-2; x++ {
		scanner.Scan()
		newNum := fastGetInt(scanner.Bytes())
		inList = append(inList, newNum)

	}
	inList = append(inList, 1)

	//======================================================
	ret = solution(inList, t, n)
	//==================== OUTPUT ==========================
	if ret == t {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math/rand"
	"os"
)

const INF  = 1000000001

type Pair struct {
	first, second int
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

func dfs(g [][]int, u []bool, v int) {
	u[v] = true
	for i := 0; i < len(g[v]); i++ {
		to := g[v][i]
		if !u[to] {
			dfs(g, u, to)
		}
	}
}

func solution(reader io.Reader, writer io.Writer) {
	var n, t int
	fmt.Fscanf(reader, "%d %d\n", &n, &t)
	t--

	g := make([][]int, n)
	for i := 0; i < n; i++ {
		g[i] = make([]int, 0)
	}

	for i := 0; i < n - 1; i++ {
		var a int
		fmt.Fscanf(reader, "%d", &a)
		g[i] = append(g[i], i + a)
	}

	u := make([]bool, n)
	dfs(g, u, 0)
	if u[t] {
		fmt.Fprintf(writer, "YES\n")
	} else {
		fmt.Fprintf(writer, "NO\n")
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/500/A
// комментарии к решению
// Т.к. в задаче не предусмотрено передвижение кроме как через порталы,
// то нам достаточно проитерироваться по массиву и по прыжкам попытаться
// добраться до нужного нам элемента
func taskSolution(a []int, n int) string {
	i := 1
	for i <= len(a) && i < n {
		i += a[i-1]
	}
	if i == n {
		return "YES"
	}
	return "NO"
}

func main() {
	var n, t int
	if _, err := fmt.Scan(&n, &t); err != nil {
		panic(err)
	}

	a := []int{}
	for i := 0; i < n-1; i += 1 {
		var ai int
		if _, err := fmt.Scan(&ai); err != nil {
			panic(err)
		}
		a = append(a, ai)
	}

	fmt.Println(taskSolution(a, t))
}

package main

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

type Graph struct {
	Visited map[int]bool
	Edges   map[int][]int
}

func explore(g *Graph, source int) {
	g.Visited[source] = true
	if vertices, ok := g.Edges[source]; ok {
		for _, v := range vertices {
			if _, ok := g.Visited[v]; !ok {
				explore(g, v)
			}
		}
	}
}

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

	var numCells, target, temp int
	fmt.Fscanf(reader, "%d %d\n", &numCells, &target)

	g := Graph{Visited: make(map[int]bool), Edges: make(map[int][]int)}
	for i := 1; i < numCells; i++ {
		fmt.Fscanf(reader, "%d", &temp)
		if _, ok := g.Edges[i]; !ok {
			g.Edges[i] = make([]int, 0)
		}
		g.Edges[i] = append(g.Edges[i], i+temp)
	}
	fmt.Fscanf(reader, "\n")
	explore(&g, 1)
	if _, ok := g.Visited[target]; ok {
		fmt.Fprintf(writer, "YES\n")
	} else {
		fmt.Fprintf(writer, "NO\n")
	}
}

package main

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

func toInt(buf []byte) (n int64) {
	for _, v := range buf {
		n += n * 10 + int64(v - '0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var position int64
	scanner.Scan()
	scanner.Scan()
	position = toInt(scanner.Bytes())
	myPosition := int64(1)
	index := int64(1)
	if position == 1 || position == 29985 {
		fmt.Println("YES")
		return
	}
	for scanner.Scan() && myPosition < position {
		if index == myPosition {
			portal := toInt(scanner.Bytes())
			myPosition += portal
			if myPosition == position {
				fmt.Println("YES")
				return
			}
		}
		index++
	}
	fmt.Println("NO")
}

package main

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

func toInt(buf []byte) (n int64) {
	for _, v := range buf {
		n += n * 10 + int64(v - '0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var position int64
	scanner.Scan()
	scanner.Scan()
	position = toInt(scanner.Bytes())
	myPosition := int64(1)
	index := int64(1)
	if position == 1 {
		fmt.Println("YES")
		return
	}
	for scanner.Scan() && myPosition < position {
		if index == myPosition {
			portal := toInt(scanner.Bytes())
			myPosition += portal
			if myPosition == position {
				fmt.Println("YES")
				return
			}
		}
		index++
	}
	fmt.Println("NO")
}

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n += n * 10 + int(v - '0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var position int
	scanner.Scan()
	scanner.Scan()
	position = toInt(scanner.Bytes())
	myPosition := 1
	index := 1
	if position == 1 {
		fmt.Println("YES")
		return
	}
	for scanner.Scan() {
		if index == myPosition {
			portal := toInt(scanner.Bytes())
			myPosition += portal
			if myPosition == position{
				fmt.Println("YES")
				return
			}
		}
		index++
	}
	fmt.Println("NO")
}

package main

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

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n += n * 10 + int(v - '0')
	}
	return
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	var position int
	scanner.Scan()
	scanner.Scan()
	position = toInt(scanner.Bytes())
	myPosition := 1
	index := 1
	if position == 1 {
		fmt.Println("YES")
		return
	}
	for scanner.Scan() {
		if index == myPosition {
			portal := toInt(scanner.Bytes())
			myPosition += portal
			if myPosition == position{
				fmt.Println("YES")
				return
			}
			if myPosition > position {
				break
			}
		}
		index++
	}
	fmt.Println("NO")
}

package main

import ("fmt")

func main() {
	var n, t int
	fmt.Scanf("%d %d\n", &n, &t)
	arr := make([]int, n - 1)
	for i := 0; i < n - 1; i++ {
		fmt.Scanf("%d", &arr[i])
	}

	var res, i int
	for res < t {
		res = i + 1 + arr[i]
		i = res
	}

	if res == t {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import(
    "fmt"
)

func main () {
    var n, k int
    fmt.Scanf("%d %d ", &n, &k)
    array := make([]int, n)
    i := 0
    for  ;i<n; i++{
        fmt.Scanf("%d", &array[i])
    }
    i = 1
    for i < n {
        if i == k {
            fmt.Printf("YES")
            return
        }
        i += array[i-1]
    }
    fmt.Printf("NO")
}

package main

import (
	"fmt"
)
// MsgYes is a message for YES
const MsgYes = "YES"
// MsgNo is a message for No
const MsgNo = "NO"

func main() {

	var total int
	var dest int
	var currentStep int = 1

	fmt.Scanln(&total, &dest)

	for ; total > 0; total-- {
		var v int

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

		if currentStep < dest {
			currentStep += v
			continue
		} else if currentStep == dest {
			fmt.Println(MsgYes)
			return;
		} else {
			fmt.Println(MsgNo)
			return;
		}
	}

}

package main

import "fmt"

var aa [][]bool
var max, des int

func main() {
	var x int
	fmt.Scanf("%d", &x)
	fmt.Scanf("%d\n", &des)
	fmt.Println(x, des)
	max = x
	des--
	max--
	var a []int
	a = make([]int, x-1)
	for i := 0; i < x-1; i++ {
		fmt.Scanf("%d", &a[i])
	}
	fmt.Println(a)
	aa = make([][]bool, x)
	for i := 0; i < x; i++ {
		aa[i] = make([]bool, x)
	}
	for i := 0; i < x-1; i++ {
		fmt.Println(i, i+a[i])
		aa[i][i+a[i]] = true
	}
	if ret := dfs(0); ret {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(x int) bool {
	if x == des {
		return true
	}
	if x >= max {
		return false
	}

	for i := x + 1; i <= max; i++ {
		if aa[x][i] && dfs(i) {
			return true
		}
	}
	return false
}

package main

import "fmt"

func main() {
	var n, t int
	fmt.Scanln(&n, &t)
	for i := 1; i <= n; i++ {

		var a int
		fmt.Scanf("%d", &a)
		if i+a == t {
			fmt.Print("YES")
			return
		}

	}
	fmt.Print("NO")
}

// GB2014_A
package main

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

const MAX_N = 30000 + 1

var (
	Inp  = bufio.NewReader(os.Stdin)
	Oup  = bufio.NewWriter(os.Stdout)
	N, T int
	A    [MAX_N]int
	DD   [MAX_N]bool
)

func main() {
	fmt.Fscan(Inp, &N, &T)
	for i := 1; i < N; i++ {
		fmt.Fscan(Inp, &A[i])
	}
	DD[1] = true
	Cur := 1
	for {
		DD[Cur] = true
		if Cur == N {
			break
		}
		Cur += A[Cur]
	}
	if DD[T] {
		fmt.Fprint(Oup, "YES\n")
	} else {
		fmt.Fprint(Oup, "NO\n")
	}
}

//  URL: http://codeforces.com/problemset/problem/500/A
//  ~ Basic Implementation Problem

package main

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

func solve(arr []int, n int, target int) string {
	current := 1
	for current < n {
		if current == target {
			return "YES"
		}
		current += arr[current - 1]
	}
	return "NO"
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n, t int
	fmt.Fscanf(reader, "%d %d\n", &n, &t)
	a := make([]int, n)
	for i := 0; i < n - 1; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	fmt.Fprintf(writer, "%s\n", solve(a, n, t))
}

package main

import "fmt"

func dfs(A []int, i, t int) bool {
	if i == t {
		return true
	}

	if A[i] == -1 {
		return false
	}

	tmp := A[i]
	A[i] = -1

	return dfs(A, tmp + i, t)
}

func main()  {
	var n, t int
	fmt.Scanf("%d %d", &n, &t)
	var A = make([]int, n)

	fmt.Println(n, t)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &A[i])
	}

	if dfs(A, 0, t - 1) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import "fmt"

func dfs(A []int, i, t int) bool {
	if i == t {
		return true
	}

	if A[i] == -1 {
		return false
	}

	tmp := A[i]
	A[i] = -1

	return dfs(A, tmp + i, t)
}

func main()  {
	var n, t int
	fmt.Scanf("%d %d", &n, &t)
	var A = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &A[i])
	}

	fmt.Println(n, t)

	fmt.Println(A)

	if dfs(A, 0, t - 1) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import "fmt"

func dfs(A []int, i, t int) bool {
	if i == t {
		return true
	}

	if A[i] == -1 {
		return false
	}

	tmp := A[i]
	A[i] = -1

	return dfs(A, tmp + i, t)
}

func main()  {
	var n, t int
	fmt.Scanf("%d %d", &n, &t)
	var A = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &A[i])
	}

	if dfs(A, 0, t - 1) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(inList []int, t int) int {
	temp := 0
	//fmt.Println(temp, t)
	if t == temp {
		return temp
	}
	for temp < t+1 && temp < len(inList) {

		temp += inList[temp]
		//fmt.Println(temp, t)
		if temp+1 == t-1 {
			return t
		}
	}
	//fmt.Println(temp, t)
	return temp + 1

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var t, n, ret int
	var inList []int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())
	scanner.Scan()
	t = fastGetInt(scanner.Bytes())

	for x := 0; x < n-2; x++ {
		scanner.Scan()
		newNum := fastGetInt(scanner.Bytes())
		inList = append(inList, newNum)

	}

	//======================================================
	ret = solution(inList, t)
	//==================== OUTPUT ==========================
	if ret == t {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(inList []int, t int) int {
	temp := 0
	if t == temp {
		return temp
	}
	for temp < len(inList) {

		temp += inList[temp]
		if t == temp+1 || temp > t {
			return temp + 1
		}

	}
	return temp

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var t, n, ret int
	var inList []int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())
	scanner.Scan()
	t = fastGetInt(scanner.Bytes())

	for x := 0; x < n-2; x++ {
		scanner.Scan()
		newNum := fastGetInt(scanner.Bytes())
		inList = append(inList, newNum)

	}

	//======================================================
	ret = solution(inList, t)
	//==================== OUTPUT ==========================
	if ret == t {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(inList []int, t int) int {
	temp := 1
	//fmt.Println(temp, t)
	if t == temp {
		return temp
	}
	for temp <= t {
		//fmt.Println(temp, t)
		if temp >= len(inList) {
			return temp
		}
		temp += inList[temp-1]
	}
	//fmt.Println(temp, t)
	return temp

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var t, n, ret int
	var inList []int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())
	scanner.Scan()
	t = fastGetInt(scanner.Bytes())

	for x := 0; x < n-2; x++ {
		scanner.Scan()
		newNum := fastGetInt(scanner.Bytes())
		inList = append(inList, newNum)

	}

	//======================================================
	ret = solution(inList, t)
	//==================== OUTPUT ==========================
	if ret == t {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(inList []int, t int) int {
	temp := 1
	//fmt.Println(temp, t)
	if t == temp {
		return temp
	}
	for temp < t {
		//fmt.Println(temp, t)
		if temp >= len(inList) {
			return temp
		}
		temp += inList[temp-1]
	}
	//fmt.Println(temp, t)
	return temp

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var t, n, ret int
	var inList []int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())
	scanner.Scan()
	t = fastGetInt(scanner.Bytes())

	for x := 0; x < n-2; x++ {
		scanner.Scan()
		newNum := fastGetInt(scanner.Bytes())
		inList = append(inList, newNum)

	}

	//======================================================
	ret = solution(inList, t)
	//==================== OUTPUT ==========================
	if ret == t {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution(inList []int, t int) int {
	temp := 0
	if t == temp {
		return temp
	}
	for temp < len(inList) {

		temp += inList[temp]
		if t == temp+1 || temp+1 > t {
			return temp + 1
		}

	}
	return temp

}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var t, n, ret int
	var inList []int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())
	scanner.Scan()
	t = fastGetInt(scanner.Bytes())

	for x := 0; x < n-2; x++ {
		scanner.Scan()
		newNum := fastGetInt(scanner.Bytes())
		inList = append(inList, newNum)

	}

	//======================================================
	ret = solution(inList, t)
	//==================== OUTPUT ==========================
	if ret == t {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}

package main

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

func fastGetInt(b []byte) int {
	neg := false
	if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n
	}
	return n
}

//========== Implement Algorithm =======================
func solution() string {
	return ""
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)

	//================== Variables used ====================
	var t, n, temp int
	//======================================================

	//============== Get return value from File ============
	if len(os.Args) >= 2 {

		file, err := os.Open(os.Args[1])
		if err != nil {
			log.Fatalf("failed opening file: %s", err)
		}
		scanner = bufio.NewScanner(file)
		defer file.Close()

	}
	scanner.Split(bufio.ScanWords)
	//======================= I/O ==========================
	scanner.Scan()
	n = fastGetInt(scanner.Bytes())
	scanner.Scan()
	t = fastGetInt(scanner.Bytes())

	for x := 0; x < n; x++ {
		scanner.Scan()
		newNum := fastGetInt(scanner.Bytes())
		temp += newNum
		if temp >= t {
			break
		}
	}
	if temp == t {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
	//======================================================

	//==================== OUTPUT ==========================

}

package main

import "fmt"

// https://codeforces.com/problemset/problem/500/A
// комментарии к решению
// Т.к. в задаче не предусмотрено передвижение кроме как через порталы,
// то нам достаточно проитерироваться по массиву и по прыжкам попытаться
// добраться до нужного нам элемента
func taskSolution(a []int, n int) string {
	for i := 0; i < len(a); i += a[i] {
		if i == n-1 {
			return "YES"
		} else if i >= n {
			return "NO"
		}
	}
	return "NO"
}

func main() {
	var n, t int
	if _, err := fmt.Scan(&n, &t); err != nil {
		panic(err)
	}

	a := []int{}
	for i := 0; i < n-1; i += 1 {
		var ai int
		if _, err := fmt.Scan(&ai); err != nil {
			panic(err)
		}
		a = append(a, ai)
	}

	fmt.Println(taskSolution(a, t))
}

package main

import "fmt"

// https://codeforces.com/problemset/problem/500/A
// комментарии к решению
// Т.к. в задаче не предусмотрено передвижение кроме как через порталы,
// то нам достаточно проитерироваться по массиву и по прыжкам попытаться
// добраться до нужного нам элемента
func taskSolution(a []int, n int) string {
	for i := 0; i < len(a); i += a[i] {
		if i == n-1 {
			return "YES"
		} else if i >= n {
			return "NO"
		}
	}
	return "YES"
}

func main() {
	var n, t int
	if _, err := fmt.Scan(&n, &t); err != nil {
		panic(err)
	}

	a := []int{}
	for i := 0; i < n-1; i += 1 {
		var ai int
		if _, err := fmt.Scan(&ai); err != nil {
			panic(err)
		}
		a = append(a, ai)
	}

	fmt.Println(taskSolution(a, t))
}


The king of Berland organizes a ball! $$$n$$$ pair are invited to the ball, they are numbered from $$$1$$$ to $$$n$$$. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monochrome costume. The color of each costume is represented by an integer from $$$1$$$ to $$$k$$$, inclusive.Let $$$b_i$$$ be the color of the man's costume and $$$g_i$$$ be the color of the woman's costume in the $$$i$$$-th pair. You have to choose a color for each dancer's costume (i.e. values $$$b_1, b_2, \dots, b_n$$$ and $$$g_1, g_2, \dots g_n$$$) in such a way that:  for every $$$i$$$: $$$b_i$$$ and $$$g_i$$$ are integers between $$$1$$$ and $$$k$$$, inclusive;  there are no two completely identical pairs, i.e. no two indices $$$i, j$$$ ($$$i \ne j$$$) such that $$$b_i = b_j$$$ and $$$g_i = g_j$$$ at the same time;  there is no pair such that the color of the man's costume is the same as the color of the woman's costume in this pair, i.e. $$$b_i \ne g_i$$$ for every $$$i$$$;  for each two consecutive (adjacent) pairs both man's costume colors and woman's costume colors differ, i.e. for every $$$i$$$ from $$$1$$$ to $$$n-1$$$ the conditions $$$b_i \ne b_{i + 1}$$$ and $$$g_i \ne g_{i + 1}$$$ hold. Let's take a look at the examples of bad and good color choosing (for $$$n=4$$$ and $$$k=3$$$, man is the first in a pair and woman is the second):Bad color choosing:   $$$(1, 2)$$$, $$$(2, 3)$$$, $$$(3, 2)$$$, $$$(1, 2)$$$ — contradiction with the second rule (there are equal pairs);  $$$(2, 3)$$$, $$$(1, 1)$$$, $$$(3, 2)$$$, $$$(1, 3)$$$ — contradiction with the third rule (there is a pair with costumes of the same color);  $$$(1, 2)$$$, $$$(2, 3)$$$, $$$(1, 3)$$$, $$$(2, 1)$$$ — contradiction with the fourth rule (there are two consecutive pairs such that colors of costumes of men/women are the same). Good color choosing:   $$$(1, 2)$$$, $$$(2, 1)$$$, $$$(1, 3)$$$, $$$(3, 1)$$$;  $$$(1, 2)$$$, $$$(3, 1)$$$, $$$(2, 3)$$$, $$$(3, 2)$$$;  $$$(3, 1)$$$, $$$(1, 2)$$$, $$$(2, 3)$$$, $$$(3, 2)$$$. You have to find any suitable color choosing or say that no suitable choosing exists.

The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n, k \le 2 \cdot 10^5$$$) — the number of pairs and the number of colors.

If it is impossible to find any suitable colors choosing, print "NO". Otherwise print "YES" and then the colors of the costumes of pairs in the next $$$n$$$ lines. The $$$i$$$-th line should contain two integers $$$b_i$$$ and $$$g_i$$$ — colors of costumes of man and woman in the $$$i$$$-th pair, respectively. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable.

package main

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

func main() {
	n, k := readInt2()

	if k < 1000 && k*(k-1) < n {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	d, b := 0, 0
	for i := 0; i < n; i++ {
		if b == 0 {
			d += 1
		}
		fmt.Println(b+1, (b+d)%k+1)
		b = (b+1)%k
	}
}

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

func readLine() string {
	s, _ := stdin.ReadString('\n')
	return s
}

func readInts() (r []int) {
	reader := strings.NewReader(readLine())
	for {
		var x int
		_, err := fmt.Fscan(reader, &x)
		if err != nil {
			break
		}
		r = append(r, x)
	}
	return
}

func readInt2() (int, int) {
	a := readInts()
	return a[0], a[1]
}

package main

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

func next(x, y, n int) (int, int) {
//	fmt.Printf("--->>>x=%d y=%d\n",x,y)
	x--
	y++
	if x <= 0{
		x = y
		y = 1
		if x > n{
			x=n
			y=2
		}
	}
	if y > n{
		y=x+2
		x=n
	}
//	fmt.Printf("<<<---x=%d y=%d\n",x,y)
	return x,y
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	var k int
	fmt.Fscanf(buf, "%d %d\n", &n, &k)
	if int64(k)*int64(k-1) < int64(n) {
		fmt.Printf("NO\n")
		return
	}
	fmt.Printf("YES\n")
	x := 1
	y := 1
	for i := 0; i < n; i++ {
		for {
			x, y = next(x, y, k)
			if x != y{
				break
			}
		}
		fmt.Printf("%d %d\n", x, y)
	}

}

package main

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

func next(x, y, n int) (int, int) {
//	fmt.Printf("--->>>x=%d y=%d\n",x,y)
	x--
	y++
	if x <= 0{
		x = y
		y = 1
		if x > n{
			x=n
			y=2
		}
	}
	if y > n{
		y=x+1
		x=n
	}
//	fmt.Printf("<<<---x=%d y=%d\n",x,y)
	return x,y
}
func main() {
	buf := bufio.NewReader(os.Stdin)
	var n int
	var k int
	fmt.Fscanf(buf, "%d %d\n", &n, &k)
	if int64(k)*int64(k-1) < int64(n) {
		fmt.Printf("NO\n")
		return
	}
	fmt.Printf("YES\n")
	x := 1
	y := 1
	for i := 0; i < n; i++ {
		for {
			x, y = next(x, y, k)
			if x != y{
				break
			}
		}
		fmt.Printf("%d %d\n", x, y)
	}

}


Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.

NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.

package main

import (
	"fmt"
	"math"
)

func convertDecToBin(x int) string {
	res := fmt.Sprintf("%b", x)
	for len(res) <= 18 {
		res = "0" + res
	}
	return res
}

func convertBinToDec(bin string) int64 {
	var res int64
	for i := 0; i < len(bin); i++ {
		if string(bin[len(bin)-1-i]) == "1" {
			res += int64(math.Pow(2, float64(i)))
		}
	}
	return res
}

func XOR(numbers ...string) string {
	res := ""
	for i := 0; i <= 18; i++ {
		counter := 0
		for j := 0; j < len(numbers); j++ {
			if string(numbers[j][i]) == "1" {
				counter++
			}
		}
		if counter%2 == 1 {
			res += "1"
		} else {
			res += "0"
		}
	}
	return res
}

func maker(input int) ([]string, []string) {
	var eveAns []string
	var oddAns []string
	for i := 0; i < input-2; i += 2 {
		eveAns = append(eveAns, convertDecToBin(i))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns = append(oddAns, convertDecToBin(i))
	}
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)

	if evenTmp != oddTmp {
		return eveAns, oddAns
	}

	var eveAns1 []string
	var oddAns1 []string
	for i := 0; i < input-2; i += 2 {
		eveAns1 = append(eveAns1, convertDecToBin(i+1))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns1 = append(oddAns1, convertDecToBin(i+1))
	}
	return eveAns1, oddAns1

}

func findAns(input int) {
	eveAns, oddAns := maker(input)
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)

	final1 := ""
	final2 := ""

	for i := 0; i <= 18; i++ {
		if evenTmp[i] != oddTmp[i] {
			final1 += "1"
			final2 += "0"
		} else {
			final2 += "1"
			final1 += "1"
		}
	}
	eveAns = append(eveAns, final1)
	oddAns = append(oddAns, final2)

	k, h := 0, 0
	for i := 0; i < input; i++ {
		if i%2 == 0 {
			fmt.Printf("%v ", convertBinToDec(eveAns[k]))
			k++
		} else {
			fmt.Printf("%v ", convertBinToDec(oddAns[h]))
			h++
		}
	}
	fmt.Println()
}

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

package main

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

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

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

		var x int
		for i := 0; i < n-1; i++ {
			x ^= i
		}

		if x != n-2 {
			for i := 0; i < n-2; i++ {
				fmt.Fprintf(out, "%d ", i)
			}
			fmt.Fprintf(out, "%d %d\n", n-2|1<<30, x|1<<30)
		} else {
			for i := 0; i < n-3; i++ {
				fmt.Fprintf(out, "%d ", i)
			}
			fmt.Fprintf(out, "%d %d %d\n", n-3|1<<30, n-2, x|1<<30)
		}
	}
}

package main

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

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

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		for i := 0; i < (n-3)&^3; i += 2 {
			Fprint(out, i, 1<<19|i, " ")
		}
		switch n % 4 {
		case 0:
			Fprintln(out, 1<<20, 1<<21, 1<<20|1, 1<<21|1)
		case 1:
			Fprintln(out, 1<<20, 1<<21|1, 1<<20|1, 2<<21|1, 3<<21|1)
		case 2:
			Fprintln(out, 1<<20, 1<<22, 2<<20, 2<<22, 3<<20, 3<<22)
		default:
			Fprintln(out, 1<<20, 2<<20, 3<<20)
		}
	}
}

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

package main

import (
	"fmt"
	"math"
)

func convertDecToBin(x int) string {
	res := fmt.Sprintf("%b", x)
	for len(res) < 18 {
		res = "0" + res
	}
	return res
}

func convertBinToDec(bin string) int64 {
	var res int64
	for i := 0; i < len(bin); i++ {
		if string(bin[len(bin)-1-i]) == "1" {
			res += int64(math.Pow(2, float64(i)))
		}
	}
	return res
}

func XOR(numbers ...string) string {
	res := ""
	for i := 0; i < 18; i++ {
		counter := 0
		for j := 0; j < len(numbers); j++ {
			if string(numbers[j][i]) == "1" {
				counter++
			}
		}
		if counter%2 == 1 {
			res += "1"
		} else {
			res += "0"
		}
	}
	return res
}

func maker(input int) ([]string, []string) {
	var eveAns []string
	var oddAns []string
	for i := 0; i < input-2; i += 2 {
		eveAns = append(eveAns, convertDecToBin(i))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns = append(oddAns, convertDecToBin(i))
	}
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)

	if evenTmp != oddTmp {
		return eveAns, oddAns
	}

	var eveAns1 []string
	var oddAns1 []string
	for i := 0; i < input-2; i += 2 {
		eveAns1 = append(eveAns1, convertDecToBin(i+1))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns1 = append(oddAns1, convertDecToBin(i+1))
	}
	return eveAns1, oddAns1

}

func findAns(input int) {
	eveAns, oddAns := maker(input)
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)

	final1 := ""
	final2 := ""

	for i := 0; i < 18; i++ {
		if evenTmp[i] != oddTmp[i] {
			final1 += "1"
			final2 += "0"
		} else {
			final2 += "1"
			final1 += "1"
		}
	}
	eveAns = append(eveAns, final1)
	oddAns = append(oddAns, final2)

	k, h := 0, 0
	for i := 0; i < input; i++ {
		if i%2 == 0 {
			fmt.Printf("%v ", convertBinToDec(eveAns[k]))
			k++
		} else {
			fmt.Printf("%v ", convertBinToDec(oddAns[h]))
			h++
		}
	}
	fmt.Println()
}

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

package main

import (
	"fmt"
	"math"
)

func convertDecToBin(x int) string {
	res := fmt.Sprintf("%b", x)
	for len(res) < 18 {
		res = "0" + res
	}
	return res
}

func convertBinToDec(bin string) int {
	res := 0
	for i := 0; i < len(bin); i++ {
		if string(bin[len(bin)-1-i]) == "1" {
			res += int(math.Pow(2, float64(i)))
		}
	}
	return res
}

func XOR(numbers ...string) string {
	res := ""
	for i := 0; i < 18; i++ {
		counter := 0
		for j := 0; j < len(numbers); j++ {
			if string(numbers[j][i]) == "1" {
				counter++
			}
		}
		if counter%2 == 1 {
			res += "1"
		} else {
			res += "0"
		}
	}
	return res
}

func maker(input int) ([]string, []string) {
	var eveAns []string
	var oddAns []string
	for i := 0; i < input-2; i += 2 {
		eveAns = append(eveAns, convertDecToBin(i))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns = append(oddAns, convertDecToBin(i))
	}
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)

	if evenTmp != oddTmp {
		return eveAns, oddAns
	}

	var eveAns1 []string
	var oddAns1 []string
	for i := 0; i < input-2; i += 2 {
		eveAns1 = append(eveAns1, convertDecToBin(i+1))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns1 = append(oddAns1, convertDecToBin(i+1))
	}
	return eveAns1, oddAns1

}

func findAns(input int) {
	eveAns, oddAns := maker(input)
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)

	final1 := ""
	final2 := ""

	for i := 0; i < 18; i++ {
		if evenTmp[i] != oddTmp[i] {
			final1 += "1"
			final2 += "0"
		} else {
			final2 += "1"
			final1 += "1"
		}
	}
	eveAns = append(eveAns, final1)
	oddAns = append(oddAns, final2)

	k, h := 0, 0
	for i := 0; i < input; i++ {
		if i%2 == 0 {
			fmt.Printf("%v ", convertBinToDec(eveAns[k]))
			k++
		} else {
			fmt.Printf("%v ", convertBinToDec(oddAns[h]))
			h++
		}
	}
	fmt.Println()
}

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

package main

import (
	"fmt"
	"math"
)

func convertDecToBin(x int) string {
	res := fmt.Sprintf("%b", x)
	for len(res) < 18 {
		res = "0" + res
	}
	return res
}

func convertBinToDec(bin string) int {
	res := 0
	for i := 0; i < len(bin); i++ {
		if string(bin[len(bin)-1-i]) == "1" {
			res += int(math.Pow(2, float64(i)))
		}
	}
	return res
}

func XOR(numbers ...string) string {
	res := ""
	for i := 0; i < 18; i++ {
		counter := 0
		for j := 0; j < len(numbers); j++ {
			if string(numbers[j][i]) == "1" {
				counter++
			}
		}
		if counter%2 == 1 {
			res += "1"
		} else {
			res += "0"
		}
	}
	return res
}

func findAns(input int) {
	var eveAns []string
	var oddAns []string
	for i := 0; i < input-2; i += 2 {
		eveAns = append(eveAns, convertDecToBin(i))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns = append(oddAns, convertDecToBin(i))
	}
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)
	// fmt.Println(evenTmp)
	// fmt.Println(oddTmp)

	final1 := ""
	final2 := ""

	for i := 0; i < 18; i++ {
		if evenTmp[i] != oddTmp[i] {
			final1 += "1"
			final2 += "0"
		} else {
			final2 += "1"
			final1 += "1"
		}
	}
	eveAns = append(eveAns, final1)
	oddAns = append(oddAns, final2)

	// fmt.Println(final1)
	// fmt.Println(final2)

	evenTmp = XOR(eveAns...)
	oddTmp = XOR(oddAns...)
	// fmt.Println(evenTmp)
	// fmt.Println(oddTmp)

	k, h := 0, 0
	for i := 0; i < input; i++ {
		if i%2 == 0 {
			fmt.Printf("%v ", convertBinToDec(eveAns[k]))
			k++
		} else {
			fmt.Printf("%v ", convertBinToDec(oddAns[h]))
			h++
		}
	}
	fmt.Println()
}

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

package main

import (
	"fmt"
	"math"
)

func convertDecToBin(x int) string {
	res := fmt.Sprintf("%b", x)
	for len(res) < 18 {
		res = "0" + res
	}
	return res
}

func convertBinToDec(bin string) int {
	res := 0
	for i := 0; i < len(bin); i++ {
		if string(bin[len(bin)-1-i]) == "1" {
			res += int(math.Pow(2, float64(i)))
		}
	}
	return res
}

func XOR(numbers ...string) string {
	res := ""
	for i := 0; i < 18; i++ {
		counter := 0
		for j := 0; j < len(numbers); j++ {
			if numbers[j] == "1" {
				counter++
			}
		}
		if counter%2 == 1 {
			res += "1"
		} else {
			res += "0"
		}
	}
	return res
}

func findAns(input int) {
	var eveAns []string
	var oddAns []string
	for i := 0; i < input-2; i += 2 {
		eveAns = append(eveAns, convertDecToBin(i))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns = append(oddAns, convertDecToBin(i))
	}
	// fmt.Println(eveAns)
	// fmt.Println(oddAns)
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)

	final1 := ""
	final2 := ""
	// if input%2 == 0 {
	// 	for i := 0; i < 18; i++ {
	// 		if evenTmp[i] != oddTmp[i] {
	// 			final += "1"
	// 		} else {
	// 			final += "0"
	// 		}
	// 	}
	// 	oddAns = append(oddAns, final)
	// } else {
	// 	for i := 0; i < 18; i++ {
	// 		if evenTmp[i] != oddTmp[i] {
	// 			final += "1"
	// 		} else {
	// 			final += "0"
	// 		}
	// 	}
	// 	eveAns = append(eveAns, final)

	for i := 0; i < 18; i++ {
		if i%2 == 0 {
			if evenTmp[i] != oddTmp[i] {
				final1 += "1"
				final2 += "0"
			} else {
				final2 += "0"
				final1 += "1"
			}
		} else {
			if evenTmp[i] != oddTmp[i] {
				final1 += "0"
				final2 += "1"
			} else {
				final2 += "1"
				final1 += "0"
			}
		}

	}
	eveAns = append(eveAns, final1)
	oddAns = append(oddAns, final2)

	// evenTmp = XOR(eveAns...)
	// oddTmp = XOR(oddAns...)
	// fmt.Println(evenTmp)
	// fmt.Println(oddTmp)
	k, h := 0, 0
	for i := 0; i < input; i++ {
		if i%2 == 0 {
			fmt.Printf("%v ", convertBinToDec(eveAns[k]))
			k++
		} else {
			fmt.Printf("%v ", convertBinToDec(oddAns[h]))
			h++
		}
	}
	fmt.Println()
}

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

package main

import (
	"fmt"
	"math"
)

func convertDecToBin(x int) string {
	res := fmt.Sprintf("%b", x)
	for len(res) < 18 {
		res = "0" + res
	}
	return res
}

func convertBinToDec(bin string) int {
	res := 0
	for i := 0; i < len(bin); i++ {
		if string(bin[len(bin)-1-i]) == "1" {
			res += int(math.Pow(2, float64(i)))
		}
	}
	return res
}

func XOR(numbers ...string) string {
	res := ""
	for i := 0; i < 18; i++ {
		counter := 0
		for j := 0; j < len(numbers); j++ {
			if numbers[j] == "1" {
				counter++
			}
		}
		if counter%2 == 1 {
			res += "1"
		} else {
			res += "0"
		}
	}
	return res
}

func findAns(input int) {
	var eveAns []string
	var oddAns []string
	for i := 0; i < input-2; i += 2 {
		eveAns = append(eveAns, convertDecToBin(i))
	}
	for i := 1; i < input-2; i += 2 {
		oddAns = append(oddAns, convertDecToBin(i))
	}
	// fmt.Println(eveAns)
	// fmt.Println(oddAns)
	evenTmp := XOR(eveAns...)
	oddTmp := XOR(oddAns...)

	final1 := ""
	final2 := ""
	// if input%2 == 0 {
	// 	for i := 0; i < 18; i++ {
	// 		if evenTmp[i] != oddTmp[i] {
	// 			final += "1"
	// 		} else {
	// 			final += "0"
	// 		}
	// 	}
	// 	oddAns = append(oddAns, final)
	// } else {
	// 	for i := 0; i < 18; i++ {
	// 		if evenTmp[i] != oddTmp[i] {
	// 			final += "1"
	// 		} else {
	// 			final += "0"
	// 		}
	// 	}
	// 	eveAns = append(eveAns, final)

	for i := 0; i < 18; i++ {
		if i%2 == 0 {
			if evenTmp[i] != oddTmp[i] {
				final1 += "1"
				final2 += "0"
			} else {
				final2 += "0"
				final1 += "1"
			}
		} else {
			if evenTmp[i] != oddTmp[i] {
				final1 += "0"
				final2 += "1"
			} else {
				final2 += "1"
				final1 += "0"
			}
		}

	}
	eveAns = append(eveAns, final1)
	oddAns = append(oddAns, final2)

	// evenTmp = XOR(eveAns...)
	// oddTmp = XOR(oddAns...)
	// fmt.Println(evenTmp)
	// fmt.Println(oddTmp)
	k, h := 0, 0
	for i := 0; i < input; i++ {
		if i%2 == 0 {
			fmt.Printf("%v ", convertBinToDec(eveAns[k]))
			k++
		} else {
			fmt.Printf("%v ", convertBinToDec(oddAns[h]))
			h++
		}
	}
}

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

package main

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

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

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

		var x int
		for i := 0; i < n-1; i++ {
			x ^= i
		}

		if x != n-2 {
			for i := 0; i < n-2; i++ {
				fmt.Fprintf(out, "%d ", i)
			}
			fmt.Fprintf(out, "%d %d\n", n-2|1<<31, x|1<<31)
		} else {
			for i := 0; i < n-3; i++ {
				fmt.Fprintf(out, "%d ", i)
			}
			fmt.Fprintf(out, "%d %d %d\n", n-3|1<<31, n-2, x|1<<31)
		}
	}
}

package main

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

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

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

		var x int
		for i := 0; i < n-1; i++ {
			x ^= i
		}
		fmt.Println(n, x)
		if x != n-2 {
			for i := 0; i < n-2; i++ {
				fmt.Fprintf(out, "%d ", i)
			}
			fmt.Fprintf(out, "%d %d\n", n-2|1<<31, x|1<<31)
		} else {
			for i := 0; i < n-3; i++ {
				fmt.Fprintf(out, "%d ", i)
			}
			fmt.Fprintf(out, "%d %d %d\n", n-3|1<<31, n-2, x|1<<31)
		}
	}
}

package main

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

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

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

		for i := 0; i < n-1; i++ {
			fmt.Fprintf(out, "%v ", i+1)
		}

		if n%2 == 0 {
			fmt.Fprint(out, "0\n")
		} else {
			fmt.Fprintf(out, "%v\n", n)
		}
	}
}


Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well.In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned.Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023.

The first line contains an integer n (1 ≤ n ≤ 5·105) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant xi 0 ≤ xi ≤ 1023.

Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input.

NoteYou can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation.Second sample:Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.

package main

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

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

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

	zero := 0
	one := 1023

	var (
		command rune
		number  int
	)
	for i := 0; i < amount; i++ {
		fmt.Fscanf(reader, "%c %d\n", &command, &number)

		if command == '&' {
			zero = zero & number
			one = one & number
		} else if command == '|' {
			zero = zero | number
			one = one | number
		} else {
			zero = zero ^ number
			one = one ^ number
		}
	}

	var and, or, xor int
	var power int
	for bit := uint(0); bit < 10; bit++ {
		power = int(math.Pow(2, float64(bit)))

		if zero&power == 0 && one&power == 0 {

		} else if zero&power == 0 && one&power == power {
			and = and | power
		} else if zero&power == power && one&power == 0 {
			and = and | power
			xor = xor | power
		} else {
			or = or | power
		}
	}

	fmt.Println(3)
	fmt.Println("&", and)
	fmt.Println("|", or)
	fmt.Println("^", xor)
}

package main

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

func solve() {
	n := readInt()
	ops := make([]string, n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		ops[i] = readString()
		a[i] = readInt()
	}
	x1 := calc(ops, a, 1023)
	x2 := calc(ops, a, 0)
	if x1 == 1023 && x2 == 0 {
		fmt.Println("0")
		return
	} else if x1 != 1023 && x2 == 0 {
		fmt.Println("1")
		fmt.Println("&", x1)
		return
	} else if x1 == 1023 && x2 != 0 {
		fmt.Println("1")
		fmt.Println("|", x2)
		return
	} else {
		a1 := 0
		a2 := 0
		// fmt.Printf("%010b\n", x1)
		// fmt.Printf("%010b\n", x2)
		for i := uint(0); i < 10; i++ {
			b := (1 << i)
			if b&x1 > 0 && b&x2 > 0 {
				// fmt.Printf("up(%d) = %+v\n", i, b)
				a1 |= b
			} else if b&x1 == 0 && b&x2 == 0 {
				// fmt.Printf("down(%d) = %+v\n", i, b)
				a1 |= b
				a2 |= b
			} else if b&x1 == 0 && b&x2 > 0 {
				a2 |= b
				// fmt.Printf("inverse(%d) = %+v\n", i, b)
			}
		}
		fmt.Println("2")
		fmt.Println("|", a1)
		fmt.Println("^", a2)
	}
}

func calc(ops []string, a []int, x int) int {
	for i := 0; i < len(ops); i++ {
		switch ops[i] {
		case "|":
			x |= a[i]
		case "^":
			x ^= a[i]
		case "&":
			x &= a[i]
		}
	}
	return x
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()

	bit0 := 0
	bit1 := 1023
	for i := 0; i < N; i++ {
		S := io.NextString()
		X := io.NextInt()

		switch S {
		case "&":
			bit0 &= X
			bit1 &= X
		case "|":
			bit0 |= X
			bit1 |= X
		case "^":
			bit0 ^= X
			bit1 ^= X
		}
	}

	and := 1023
	or := 0
	xor := 0
	for b := uint(0); b < 10; b++ {
		b0 := (bit0 >> b) & 1
		b1 := (bit1 >> b) & 1
		if b0 == 0 && b1 == 0 {
			and &= ^(1 << b)
		} else if b0 == 1 && b1 == 1 {
			or |= 1 << b
		} else if b0 == 1 && b1 == 0 {
			xor ^= 1 << b
		}
	}

	io.Println(3)
	io.Println("&", and)
	io.Println("|", or)
	io.Println("^", xor)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
  N := io.NextInt()

  zero := 0
  one := 1023

  for i := 0; i < N; i++ {
    OP := io.NextString()
    X := io.NextInt()

    switch OP {
      case "&":
        zero &= X
        one &= X
      case "|":
        zero |= X
        one |= X
      case "^":
        zero ^= X
        one ^= X
    }
  }

  and := 1023
  or := 0
  xor := 0

  for i := uint(0); i < 10; i++ {
    b0 := (zero >> i) & 1
    b1 := (one >> i) & 1
    b := (1 << i)
    if b0 == 0 && b1 == 0 {
      and ^= b
    } else if b0 == 1 && b1 == 1 {
      or ^= b
    } else if b0 != 0 && b1 != 1 {
      xor ^= b
    }
  }

  io.Println(3)
  io.Printf("& %d\n", and)
  io.Printf("| %d\n", or)
  io.Printf("^ %d\n", xor)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

import "fmt"

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

	zero := 0
	one := 1023

	var (
		command string
		number  int
	)
	for i := 0; i < amount; i++ {
		fmt.Scanf("%s %d\n", &command, &number)

		if command == "&" {
			zero = zero & number
			one = one & number
		} else if command == "|" {
			zero = zero | number
			one = one | number
		} else {
			zero = zero ^ number
			one = one ^ number
		}
	}

	var and, or, xor int
	var power int
	for bit := uint(0); bit < 8; bit++ {
		power = 1 << bit

		if zero&power == 0 && one&power == 0 {

		} else if zero&power == 0 && one&power == power {
			and = and | power
		} else if zero&power == power && one&power == 0 {
			and = and | power
			xor = xor | power
		} else {
			or = or | power
		}
	}

	fmt.Println(3)
	fmt.Println("&", and)
	fmt.Println("|", or)
	fmt.Println("^", xor)
}

package main

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

func solve() {
	n := readInt()
	ops := make([]string, n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		ops[i] = readString()
		a[i] = readInt()
	}
	x1 := calc(ops, a, 1023)
	x2 := calc(ops, a, 0)
	if x1 == 1023 && x2 == 0 {
		fmt.Println("0")
		return
	} else if x1 != 1023 && x2 == 0 {
		fmt.Println("1")
		fmt.Println("&", x1)
		return
	} else if x1 == 1023 && x2 != 0 {
		fmt.Println("1")
		fmt.Println("|", x2)
		return
	} else {
		a1 := 0
		a2 := 0
		// fmt.Printf("%010b\n", x1)
		// fmt.Printf("%010b\n", x2)
		for i := uint(0); i < 10; i++ {
			b := (1 << i)
			if b&x1 > 0 && b&x2 > 0 {
				// fmt.Printf("up(%d) = %+v\n", i, b)
				a1 |= b
			} else if b&x1 == 0 && b&x2 == 0 {
				//fmt.Printf("down(%d) = %+v\n", i, b)
				a1 |= b
				a2 |= b
			}
		}
		fmt.Println("2")
		fmt.Println("|", a1)
		fmt.Println("^", a2)
	}
}

func calc(ops []string, a []int, x int) int {
	for i := 0; i < len(ops); i++ {
		switch ops[i] {
		case "|":
			x |= a[i]
		case "^":
			x ^= a[i]
		case "&":
			x &= a[i]
		}
	}
	return x
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()

	bit0 := 0
	bit1 := 1023
	for i := 0; i < N; i++ {
		S := io.NextString()
		X := io.NextInt()

		switch S {
		case "&":
			bit0 &= X
			bit1 &= X
		case "|":
			bit0 |= X
			bit1 |= X
		case "^":
			bit0 ^= X
			bit1 ^= X
		}
	}

	and := 1023
	or := 0
	xor := 0
	for b := uint(0); b < 10; b++ {
		b0 := (bit0 >> b) & 1
		b1 := (bit1 >> b) & 1
		if b0 == 0 && b1 == 0 {
			and &= ^(1 << b)
		} else if b0 == 1 && b1 == 1 {
			or |= 1 << b
		} else {
			xor ^= 1 << b
		}
	}

	io.Println(3)
	io.Println("&", and)
	io.Println("|", or)
	io.Println("^", xor)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
  N := io.NextInt()

  zero := 0
  one := 1023

  for i := 0; i < N; i++ {
    OP := io.NextString()
    X := io.NextInt()

    switch OP {
      case "&":
        zero &= X
        one &= X
      case "|":
        zero |= X
        one |= X
      case "^":
        zero ^= X
        one ^= X
    }
  }

  and := 1023
  or := 0
  xor := 0

  for i := uint(0); i < 10; i++ {
    b0 := (zero >> i) & 1
    b1 := (one >> i) & 1
    b := (1 << i)
    if b0 == 0 && b1 == 0 {
      and ^= b
    } else if b0 == 1 && b1 == 1 {
      or ^= b
    } else {
      xor ^= b
    }
  }

  io.Println(3)
  io.Printf("& %d\n", and)
  io.Printf("| %d\n", or)
  io.Printf("^ %d\n", xor)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}