You are given a rectangular matrix of size $$$n \times m$$$ consisting of integers from $$$1$$$ to $$$2 \cdot 10^5$$$.In one move, you can:  choose any element of the matrix and change its value to any integer between $$$1$$$ and $$$n \cdot m$$$, inclusive;  take any column and shift it one cell up cyclically (see the example of such cyclic shift below). A cyclic shift is an operation such that you choose some $$$j$$$ ($$$1 \le j \le m$$$) and set $$$a_{1, j} := a_{2, j}, a_{2, j} := a_{3, j}, \dots, a_{n, j} := a_{1, j}$$$ simultaneously.  Example of cyclic shift of the first column You want to perform the minimum number of moves to make this matrix look like this:  In other words, the goal is to obtain the matrix, where $$$a_{1, 1} = 1, a_{1, 2} = 2, \dots, a_{1, m} = m, a_{2, 1} = m + 1, a_{2, 2} = m + 2, \dots, a_{n, m} = n \cdot m$$$ (i.e. $$$a_{i, j} = (i - 1) \cdot m + j$$$) with the minimum number of moves performed.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2 \cdot 10^5, n \cdot m \le 2 \cdot 10^5$$$) — the size of the matrix. The next $$$n$$$ lines contain $$$m$$$ integers each. The number at the line $$$i$$$ and position $$$j$$$ is $$$a_{i, j}$$$ ($$$1 \le a_{i, j} \le 2 \cdot 10^5$$$).

Print one integer — the minimum number of moves required to obtain the matrix, where $$$a_{1, 1} = 1, a_{1, 2} = 2, \dots, a_{1, m} = m, a_{2, 1} = m + 1, a_{2, 2} = m + 2, \dots, a_{n, m} = n \cdot m$$$ ($$$a_{i, j} = (i - 1)m + j$$$).

NoteIn the first example, you can set $$$a_{1, 1} := 7, a_{1, 2} := 8$$$ and $$$a_{1, 3} := 9$$$ then shift the first, the second and the third columns cyclically, so the answer is $$$6$$$. It can be shown that you cannot achieve a better answer.In the second example, the matrix is already good so the answer is $$$0$$$.In the third example, it is enough to shift the second column cyclically twice to obtain a good matrix, so the answer is $$$2$$$.

package main

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

func main() {
	var n, m int // rows, cols
	fmt.Scanln(&n, &m)

	// index col, then row
	a := make([][]int, m)
	for i := 0; i < m; i++ {
		a[i] = make([]int, n)
	}

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			scanner.Scan()
			a[j][i], _ = strconv.Atoi(scanner.Text())
		}
	}

	s := 0

	for i := 0; i < m; i++ {
		// we need to make column [i] into the sequence
		// i+1, i+1+m, ..., i+1+(n-1)m

		shifts := make([]int, n)

		// for each position, calculate shift to right position
		for j := 0; j < n; j++ {
			row := a[i][j] - (i+1)
			if row % m == 0 && row / m < n {
				shift := (j - row / m + n) % n
				shifts[shift] += 1
			}
		}

		// choose the number of cycles to minimise the remaining moves
		// consider each shift and choose the minimum
		best := n - shifts[0]
		for j := 1; j < n; j++ {
			cur := n - shifts[j] + j
			if cur < best {
				best = cur
			}
		}
		s += best
	}

	fmt.Println(s)
}

package main

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

var _ = sort.Slice
var _ = math.Sqrt
var _ = strconv.Itoa

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, m int
	fmt.Fscan(in, &n, &m)
	var ans []string
	mape := make([][]int, m)
	for i := 0; i < m; i++ {
		mape[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscan(in, &mape[j][i])
		}
	}
	moves := 0
	for i := 0; i < m; i++ {
		tmp := make([]int, n)
		move := n
		//fmt.Println(i)
		for j := 0; j < n; j++ {
			start := i+1
			now := mape[i][j]
			orgplace := (now-start)/m
			if ((now - start) % m == 0 && now <= n*m){
				tmp[(j-orgplace+n)%n]++
			}
		}
		for j := 0; j < n; j++{
			nowmove := n - tmp[j] + j
			if nowmove < move {
				move = nowmove
			}
		}
		moves = moves + move
	}
	ans = append(ans, fmt.Sprint(moves))
	fmt.Fprintln(out, strings.Join(ans, "\n"));
}

package main

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

var _ = sort.Slice
var _ = math.Sqrt
var _ = strconv.Itoa

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, m int
	fmt.Fscan(in, &n, &m)
	var ans []string
	mape := make([][]int, m)
	for i := 0; i < m; i++ {
		mape[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscan(in, &mape[j][i])
		}
	}
	moves := 0
	for i := 0; i < m; i++ {
		tmp := make([]int, n)
		move := n
		//fmt.Println(i)
		for j := 0; j < n; j++ {
			start := i+1
			now := mape[i][j]
			orgplace := (now-start)/m
			if (now - start) % m == 0 && now <= n{
				tmp[(j-orgplace+n)%n]++
			}
		}
		for j := 0; j < n; j++{
			nowmove := n - tmp[j] + j
			if nowmove < move {
				move = nowmove
			}
		}
		moves = moves + move
	}
	ans = append(ans, fmt.Sprint(moves))
	fmt.Fprintln(out, strings.Join(ans, "\n"));
}

package main

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

var _ = sort.Slice
var _ = math.Sqrt
var _ = strconv.Itoa

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, m int
	fmt.Fscan(in, &n, &m)
	var ans []string
	mape := make([][]int, m)
	for i := 0; i < m; i++ {
		mape[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscan(in, &mape[j][i])
		}
	}
	moves := 0
	for i := 0; i < m; i++ {
		tmp := make([]int, n)
		move := n
		for j := 0; j < n; j++ {
			start := i+1
			now := mape[i][j]
			orgplace := (now-start)/3
			if (now - start) % m == 0 {
				tmp[(j-orgplace+n)%n]++
			}
		}
		//fmt.Println(tmp)
		for j := 0; j < n; j++{
			nowmove := n - tmp[j] + j
			if nowmove < move {
				move = nowmove
			}
		}
		moves = moves + move
	}
	ans = append(ans, fmt.Sprint(moves))
	fmt.Fprintln(out, strings.Join(ans, "\n"));
}


There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0.Also, each minute Vasya's bank account receives C·k, where k is the amount of received but unread messages.Vasya's messages are very important to him, and because of that he wants to have all messages read after T minutes.Determine the maximum amount of money Vasya's bank account can hold after T minutes.

The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T).

Output one integer  — the answer to the problem.

NoteIn the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total.In the second sample the messages can be read at any integer moment.In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at the corresponding minutes, he gets 40 points for them. When reading messages, he receives (5 - 4·3) + (5 - 3·3) + (5 - 2·3) + (5 - 1·3) + 5 =  - 5 points. This is 35 in total.

package main

import (
	"fmt"
)

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

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

func main() {
	var n, A, B, C, T int
	var timeFreq map[int]int
	var dp [][]int

	fmt.Scanf("%d %d %d %d %d\n", &n, &A, &B, &C, &T)

	timeFreq = make(map[int]int)
	dp = make([][]int, 2)
	dp[0] = make([]int, n+1)
	dp[1] = make([]int, n+1)

	for i := 0; i <= T; i++ {
		timeFreq[i] = 0
	}

	for i := 0; i < n; i++ {
		var temp int
		fmt.Scanf("%d", &temp)
		timeFreq[temp]++
		dp[0][i] = -1e9
		dp[1][i] = -1e9
	}

	dp[0][n] = -1e9
	dp[1][n] = -1e9

	dp[0][0] = 0

	prev := 0
	curr := 1

	maxReceived := 1

	for t := 1; t <= T; t++ {
		arrivingNow := timeFreq[t]
		maxReceived += arrivingNow
		//fmt.Print("Arriving now: ", arrivingNow, " ")
		for messagesLeft := 0; messagesLeft <= min(n, maxReceived); messagesLeft++ {
			low := max(0, messagesLeft-arrivingNow)

			for i := low; i <= n; i++ {
				cost := dp[prev][i] + (A * max(0, i+arrivingNow-messagesLeft)) +
					(C * messagesLeft) - (B * messagesLeft)
				dp[curr][messagesLeft] = max(dp[curr][messagesLeft], cost)
			}
		}

		//fmt.Println(dp[prev])

		prev = (prev + 1) % 2
		curr = (curr + 1) % 2
	}

	fmt.Println(dp[prev][0])
}


You are given a tree of $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$, with edges numbered from $$$1$$$ to $$$n-1$$$. A tree is a connected undirected graph without cycles. You have to assign integer weights to each edge of the tree, such that the resultant graph is a prime tree.A prime tree is a tree where the weight of every path consisting of one or two edges is prime. A path should not visit any vertex twice. The weight of a path is the sum of edge weights on that path.Consider the graph below. It is a prime tree as the weight of every path of two or less edges is prime. For example, the following path of two edges: $$$2 \to 1 \to 3$$$ has a weight of $$$11 + 2 = 13$$$, which is prime. Similarly, the path of one edge: $$$4 \to 3$$$ has a weight of $$$5$$$, which is also prime.  Print any valid assignment of weights such that the resultant tree is a prime tree. If there is no such assignment, then print $$$-1$$$. It can be proven that if a valid assignment exists, one exists with weights between $$$1$$$ and $$$10^5$$$ as well.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$2 \leq n \leq 10^5$$$) — the number of vertices in the tree. Then, $$$n-1$$$ lines follow. The $$$i$$$-th line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq n$$$) denoting that edge number $$$i$$$ is between vertices $$$u$$$ and $$$v$$$. It is guaranteed that the edges form a tree. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, if a valid assignment exists, then print a single line containing $$$n-1$$$ integers $$$a_1, a_2, \dots, a_{n-1}$$$ ($$$1 \leq a_i \le 10^5$$$), where $$$a_i$$$ denotes the weight assigned to the edge numbered $$$i$$$. Otherwise, print $$$-1$$$. If there are multiple solutions, you may print any.

NoteFor the first test case, there are only two paths having one edge each: $$$1 \to 2$$$ and $$$2 \to 1$$$, both having a weight of $$$17$$$, which is prime.  The second test case is described in the statement.It can be proven that no such assignment exists for the third test case.

package main

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

var err = fmt.Errorf("something wrong")

var read = func() func(format string, args ...interface{}) {
	var r = bufio.NewReader(os.Stdin)
	return func(format string, args ...interface{}) {
		_, _ = fmt.Fscanf(r, format, args...)
	}
}()

var write, flush = func() (func(format string, args ...interface{}), func()) {
	var w = bufio.NewWriter(os.Stdout)
	return func(format string, args ...interface{}) {
			_, _ = fmt.Fprintf(w, format, args...)
			if DEBUG {
				_ = w.Flush()
			}
		}, func() {
			_ = w.Flush()
		}
}()

var DEBUG = false

var debug = func(format string, args ... interface{}) {
	if DEBUG {
		write(format, args...)
	}
}

func Int() int {
	var n int
	read("%d\n", &n)
	return n
}

func Int2() (int, int) {
	var n, m int
	read("%d %d\n", &n, &m)
	return n, m
}

func main() {
	defer flush()
	for n := Int(); n > 0; n-- {
		var g = make(gg)
		m := Int()
		for i := 0; i < m-1; i++ {
			a, b := Int2()
			g.add(a, b, i)
		}
		res := solve(g, m)
		debug("ans->")
		for i, v := range res {
			if i != 0 {
				write(" ")
			}
			write("%v", v)
		}
		write("\n")
	}
}

type gg map[int][]struct {
	y, i int
}

func (g gg) add(x, y, i int) {
	g[x] = append(g[x], struct{ y, i int }{y: y, i: i})
	x, y = y, x
	g[x] = append(g[x], struct{ y, i int }{y: y, i: i})
}

func (g gg) find(x, y int) (int, int) {
	if g[x][0].y != y {
		return g[x][0].y, g[x][0].i
	}
	return g[x][1].y, g[x][1].i
}

func (g gg) findStartEnd() (int, int) {
	for _, v := range g {
		if len(v) > 2 {
			return -1, -1
		}
	}
	var d []int
	for k, v := range g {
		if len(v) == 1 {
			d = append(d, k)
		}
	}
	if len(d) != 2 {
		return -1, -1
	}
	debug("start->end %d %d\n", d[0], d[1])
	return d[0], d[1]
}

func solve(g gg, m int) []int {
	debug("g %v", g)
	s, e := g.findStartEnd()
	if s == -1 {
		return []int{-1}
	}
	debug("start-> %v\n", s)
	var res = make([]int, m-1)
	ps := -1
	for {
		next, idx := g.find(s, ps)
		res[idx] = nextPrime()
		debug("start->new_start %v %v %v %v\n", s, next, idx, res[idx])
		if next == e {
			break
		}
		ps, s = s, next
	}
	return res
}

var nextPrime = func() func() int {
	var a, b = 2, 5
	return func() int {
		a, b = b, a
		return a
	}
}()

package main

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

var err = fmt.Errorf("something wrong")

var read = func() func(format string, args ...interface{}) {
	var r = bufio.NewReader(os.Stdin)
	return func(format string, args ...interface{}) {
		_, _ = fmt.Fscanf(r, format, args...)
	}
}()

var write, flush = func() (func(format string, args ...interface{}), func()) {
	var w = bufio.NewWriter(os.Stdout)
	return func(format string, args ...interface{}) {
			_, _ = fmt.Fprintf(w, format, args...)
			if DEBUG {
				_ = w.Flush()
			}
		}, func() {
			_ = w.Flush()
		}
}()

var DEBUG = false

var debug = func(format string, args ... interface{}) {
	if DEBUG {
		write(format, args...)
	}
}

func Int() int {
	var n int
	read("%d\n", &n)
	return n
}

func Int2() (int, int) {
	var n, m int
	read("%d %d\n", &n, &m)
	return n, m
}

func main() {
	defer flush()
	for n := Int(); n > 0; n-- {
		var p [][2]int
		for m := Int()-1; m > 0; m-- {
			a, b := Int2()
			if b < a {
				a, b = b, a
			}
			p = append(p, [2]int{a, b})
		}
		res := solve(p)
		debug("ans->")
		for i, v := range res {
			if i != 0 {
				write(" ")
			}
			write("%v", v)
		}
		write("\n")
	}
}

func solve(p [][2]int) []int {
	var c = make(map[int][][2]int)
	for i, v := range p {
		c[v[0]] = append(c[v[0]], [2]int{i, v[1]})
		c[v[1]] = append(c[v[1]], [2]int{i, v[0]})
	}
	for _, v := range c {
		if len(v) > 2 {
			return []int{-1}
		}
	}
	var d []int
	for i, v := range c {
		if len(v) == 1 {
			d = append(d, i)
		}
	}
	if len(d) != 2 {
		panic(err)
	}
	start, end := d[0], d[1]
	debug("start->end %v %v\n", start, end)
	var res = make([]int, len(p))
	var t int

	for start != end {
		if t == len(p) {
			panic(err)
		}
		if len(c[start]) != 1 {
			panic(err)
		}
		idx, next := c[start][0][0], c[start][0][1]
		res[idx] = nextPrime()
		debug("start->new_start %v %v %v %v\n", start, next, idx, res[idx])
		if len(c[next]) != 2 {
			if len(c[next]) == 1 && next == end {
				break
			}
			panic(err)
		}
		a, b := c[next][0], c[next][1]
		debug("start->next_2 %v %v %v %v\n", start, next, a[1], b[1])
		if a[1] == start {
			debug("start->next_2 %v\n", b[1])
			c[next] = [][2]int {b}
		} else if b[1] == start {
			debug("start->next_2 %v\n", a[1])
			c[next] = [][2]int {a}
		} else {
			panic(err)
		}

		debug("start->new_start %v %v\n", start, next)
		start = next
		t++
	}
	return res
}

var nextPrime = func() func() int {
	var a, b = 2, 5
	return func() int {
		a, b = b, a
		return a
	}
}()

package main

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

type edge struct {
	from, to int
}

func CF1627C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t, n int
	var v1, v2 int
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		graph := make([][]int, n)
		edges := make([]edge, 0, n)
		for i := 0; i < n-1; i++ {
			Fscan(in, &v1, &v2)
			v1--
			v2--
			if v1 > v2 {
				v1, v2 = v2, v1
			}
			edges = append(edges, edge{v1, v2})
			graph[v1] = append(graph[v1], v2)
			graph[v2] = append(graph[v2], v1)
		}
		// check answer
		// Println(graph)
		start := 0
		for i := range graph {
			if len(graph[i]) >= 3 {
				Fprintln(out, -1)
				continue Outer
			}
			if len(graph[i]) == 1 {
				start = i
			}
		}
		// Println("start:", start)
		flag := true
		// visited := make([]bool, n)
		// visited[start] = true
		m := make(map[edge]int, n)
		for i := 0; i < n-1; i++ {
			adjs := graph[start]
			var v1, v2 int
			v1 = start
			if len(adjs) == 2 {
				for _, v := range adjs {
					_, ok1 := m[edge{start, v}]
					_, ok2 := m[edge{v, start}]
					if ok1 || ok2 {
						continue
					}
					v2 = v
					break
				}
			} else {
				v2 = adjs[0]
			}
			start = v2
			if v1 > v2 {
				v1, v2 = v2, v1
			}
			if flag {
				m[edge{v1, v2}] = 2
			} else {
				m[edge{v1, v2}] = 3
			}
			flag = !flag
		}
		// Println(m)
		for _, e := range edges {
			Fprintf(out, "%d ", m[e])
		}
		Fprintln(out)
	}
}

// func solve(start int, graph [][]int, edges []edge) []int {
//     visited := make([]bool, len(graph))
//     var dfs func(i int, flag bool)
//     dfs = func(i int, flag bool) {
//         if visited[i] {
//             return
//         }
//         visited[i] = true
//         for _, e := range graph[i] {
//
//         }
//     }
// }

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

package main

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

type Edge struct {
	u int
	v int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)

		degrees := make([]int, n)
		positions := make(map[Edge]int)
		adjacent := make([][]int, n)
		var x, y int
		for i := 0; i < n-1; i++ {
			fmt.Fscan(in, &x, &y)
			x--
			y--
			degrees[x]++
			degrees[y]++
			positions[Edge{x, y}] = i
			positions[Edge{y, x}] = i
			adjacent[x] = append(adjacent[x], y)
			adjacent[y] = append(adjacent[y], x)
		}

		isPossible := true
		start, end := -1, -1
		for i := range degrees {
			if degrees[i] > 2 {
				isPossible = false
				break
			} else if degrees[i] == 1 {
				if start == -1 {
					start = i
				} else {
					end = i
				}
			}
		}

		if isPossible {
			visited := make([]bool, n)
			ans := make([]int, n-1)
			two := true
			visited[start] = true
			for i := start; i != end; {
				for j := 0; j < len(adjacent[i]); j++ {
					v := adjacent[i][j]
					if visited[v] == false {
						if two {
							ans[positions[Edge{i, v}]] = 2
						} else {
							ans[positions[Edge{i, v}]] = 3
						}
						two = !two
						visited[v] = true
						i = v
						break
					}
				}
			}
			fmt.Fprint(out, ans[0])
			for i := 1; i < n-1; i++ {
				fmt.Fprint(out, " ", ans[i])
			}
		} else {
			fmt.Fprint(out, -1)
		}
		fmt.Fprintln(out)
		out.Flush()
	}
}

package main

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

const mod = 998244353

type idx struct {
	l int
	r int
}

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in,&n)
	m := map[idx]int{}
	degree := make([]int,n + 1)
	g := make([][]int,n + 1)
	for i := 0;i < n - 1;i++{
		var a,b int
		fmt.Fscan(in,&a,&b)
		m[idx{l:min(a,b),r:max(a,b)}] = i
		g[a] = append(g[a],b)
		g[b] = append(g[b],a)
		degree[a]++
		degree[b]++
	}
	begin := -1
	for i,v := range degree{
		if v > 2{
			fmt.Fprintln(out,-1)
			return
		}
		if v == 1{
			begin = i
		}
	}
	ans := make([]int,n - 1)
	dfs(g,begin,0,0,m,ans)
	for _,v := range ans{
		fmt.Fprintf(out,"%d ",v)
	}
	fmt.Fprintln(out)
}

func dfs(g [][]int,cur,f,nVal int,m map[idx]int,ans []int){
	for _,v := range g[cur]{
		if v != f{
			ix := m[idx{l:min(cur,v),r:max(cur,v)}]
			if nVal == 0{
				ans[ix] = 2
			}else{
				ans[ix] = 5
			}
			dfs(g,v,cur,1 - nVal,m,ans)
		}
	}
}

func abs(a,b int)int{
	if a > b{
		return a - b
	}
	return b - a
}
func sum(a,b int64)int64{
	return (b + a) * (b - a + 1) / 2
}

func max(a,b int)int{
	if a > b{
		return a
	}
	return b
}
func min(a,b int)int{
	if a > b{
		return b
	}
	return a
}
func gcd(a,b int)int{
	if a % b == 0{
		return b
	}
	return gcd(b,a%b)
}

func main() {
	stdin := os.Stdin
	stdout := os.Stdout
	in := bufio.NewReader(stdin)
	out := bufio.NewWriter(stdout)
	n := 1
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		solve(in, out)
	}
}

package main

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

func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)

	defer out.Flush()

	var T, n, v, w int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		type edge struct{ to, i int }
		g := make([][]edge, n)
		ok := true
		for i := 0; i < n-1; i++ {
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], edge{w, i})
			g[w] = append(g[w], edge{v, i})
			ok = ok && len(g[v]) < 3 && len(g[w]) < 3
		}
		if !ok {
			Fprintln(out, -1)
			continue
		}

		st := 0
		for i, e := range g {
			if len(e) == 1 {
				st = i
				break
			}
		}

		ans := make([]int, n-1)
		cur := 2
		var dfs func(int, int)
		dfs = func(v, fa int) {
			for _, e := range g[v] {
				w := e.to
				if w != fa {
					ans[e.i] = cur
					cur = 5 - cur
					dfs(w, v)
				}
			}
		}

		dfs(st, -1)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)

	}
}

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

package main

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

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

	var T, n, v, w int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		type edge struct{ to, i int }
		g := make([][]edge, n)
		ok := true
		for i := 0; i < n-1; i++ {
			Fscan(in, &v, &w)
			v--
			w--
			g[v] = append(g[v], edge{w, i})
			g[w] = append(g[w], edge{v, i})
			ok = ok && len(g[v]) < 3 && len(g[w]) < 3
		}
		if !ok {
			Fprintln(out, -1)
			continue
		}
		st := 0
		for i, e := range g {
			if len(e) == 1 {
				st = i
				break
			}
		}
		ans := make([]int, n-1)
		cur := 2
		var dfs func(int, int)
		dfs = func(v, fa int) {
			for _, e := range g[v] {
				w := e.to
				if w != fa {
					ans[e.i] = cur
					cur = 5 - cur
					dfs(w, v)
				}
			}
		}
		dfs(st, -1)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

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

var tree [][]int
var edgeId [][]int
var ans []int

func solve(node, parent, prev int) bool {
	if len(tree[node]) > 2 {
		return false
	}
	if prev == -1 {
		if len(tree[node]) == 2 {
			ans[edgeId[node][0]] = 2
			ans[edgeId[node][1]] = 3
			if solve(tree[node][0], node, 2) && solve(tree[node][1], node, 3) {
				return true
			}
			ans[edgeId[node][0]] = 3
			ans[edgeId[node][1]] = 2
			return solve(tree[node][0], node, 3) && solve(tree[node][1], node, 2)
		}
		if len(tree[node]) == 1 {
			ans[edgeId[node][0]] = 2
			if solve(tree[node][0], node, 2) {
				return true
			}
			ans[edgeId[node][0]] = 3
			return solve(tree[node][0], node, 3)
		}
	}
	if len(tree[node]) == 1 {
		return true
	}
	var index = 0
	if tree[node][index] == parent {
		index++
	}
	var eid = edgeId[node][index]
	ans[eid] = 5 - prev
	return solve(tree[node][index], node, 5-prev)
}

func solveCase() {
	var n int
	fmt.Fscan(in, &n)
	tree = make([][]int, n)
	edgeId = make([][]int, n)
	ans = make([]int, n-1)
	for i := 0; i < n-1; i++ {
		var a, b int
		fmt.Fscan(in, &a, &b)
		a--
		b--
		tree[a] = append(tree[a], b)
		tree[b] = append(tree[b], a)
		edgeId[a] = append(edgeId[a], i)
		edgeId[b] = append(edgeId[b], i)
	}
	// fmt.Fprintf(out, "tree = %v\n", tree)
	// fmt.Fprintf(out, "edgeId = %v\n", edgeId)
	// out.Flush()

	if !solve(0, 0, -1) {
		fmt.Fprintf(out, "-1\n")
	} else {
		for i := 0; i < n-1; i++ {
			fmt.Fprintf(out, "%d ", ans[i])
		}
		fmt.Fprintf(out, "\n")
	}
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		solveCase()
	}
	out.Flush()
}

package main

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

var err = fmt.Errorf("something wrong")

var read = func() func(format string, args ...interface{}) {
	var r = bufio.NewReader(os.Stdin)
	return func(format string, args ...interface{}) {
		_, _ = fmt.Fscanf(r, format, args...)
	}
}()

var write, flush = func() (func(format string, args ...interface{}), func()) {
	var w = bufio.NewWriter(os.Stdout)
	return func(format string, args ...interface{}) {
			_, _ = fmt.Fprintf(w, format, args...)
			if DEBUG {
				_ = w.Flush()
			}
		}, func() {
			_ = w.Flush()
		}
}()

var DEBUG = true

var debug = func(format string, args ... interface{}) {
	if DEBUG {
		write(format, args...)
	}
}

func Int() int {
	var n int
	read("%d\n", &n)
	return n
}

func Int2() (int, int) {
	var n, m int
	read("%d %d\n", &n, &m)
	return n, m
}

func main() {
	defer flush()
	for n := Int(); n > 0; n-- {
		var g = make(gg)
		m := Int()
		for i := 0; i < m-1; i++ {
			a, b := Int2()
			g.add(a, b, i)
		}
		res := solve(g, m)
		debug("ans->")
		for i, v := range res {
			if i != 0 {
				write(" ")
			}
			write("%v", v)
		}
		write("\n")
	}
}

type gg map[int][]struct {
	y, i int
}

func (g gg) add(x, y, i int) {
	g[x] = append(g[x], struct{ y, i int }{y: y, i: i})
	x, y = y, x
	g[x] = append(g[x], struct{ y, i int }{y: y, i: i})
}

func (g gg) find(x, y int) (int, int) {
	if g[x][0].y != y {
		return g[x][0].y, g[x][0].i
	}
	return g[x][1].y, g[x][1].i
}

func (g gg) findStartEnd() (int, int) {
	for _, v := range g {
		if len(v) > 2 {
			return -1, -1
		}
	}
	var d []int
	for k, v := range g {
		if len(v) == 1 {
			d = append(d, k)
		}
	}
	if len(d) != 2 {
		return -1, -1
	}
	debug("start->end %d %d\n", d[0], d[1])
	return d[0], d[1]
}

func solve(g gg, m int) []int {
	debug("g %v", g)
	s, e := g.findStartEnd()
	if s == -1 {
		return []int{-1}
	}
	debug("start-> %v\n", s)
	var res = make([]int, m-1)
	ps := -1
	for {
		next, idx := g.find(s, ps)
		res[idx] = nextPrime()
		debug("start->new_start %v %v %v %v\n", s, next, idx, res[idx])
		if next == e {
			break
		}
		ps, s = s, next
	}
	return res
}

var nextPrime = func() func() int {
	var a, b = 2, 5
	return func() int {
		a, b = b, a
		return a
	}
}()

package main

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

type edge struct {
	from, to int
}

func CF1627C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t, n int
	var v1, v2 int
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		graph := make([][]int, n)
		edges := make([]edge, 0, n)
		for i := 0; i < n-1; i++ {
			Fscan(in, &v1, &v2)
			v1--
			v2--
			if v1 > v2 {
				v1, v2 = v2, v1
			}
			edges = append(edges, edge{v1, v2})
			graph[v1] = append(graph[v1], v2)
			graph[v2] = append(graph[v2], v1)
		}
		// check answer
		// Println(graph)
		start := 0
		for i := range graph {
			if len(graph[i]) >= 3 {
				Fprintln(out, -1)
				break Outer
			}
			if len(graph[i]) == 1 {
				start = i
			}
		}
		// Println("start:", start)
		flag := true
		// visited := make([]bool, n)
		// visited[start] = true
		m := make(map[edge]int, n)
		for i := 0; i < n-1; i++ {
			adjs := graph[start]
			var v1, v2 int
			v1 = start
			if len(adjs) == 2 {
				for _, v := range adjs {
					_, ok1 := m[edge{start, v}]
					_, ok2 := m[edge{v, start}]
					if ok1 || ok2 {
						continue
					}
					v2 = v
					break
				}
			} else {
				v2 = adjs[0]
			}
			start = v2
			if v1 > v2 {
				v1, v2 = v2, v1
			}
			if flag {
				m[edge{v1, v2}] = 2
			} else {
				m[edge{v1, v2}] = 3
			}
			flag = !flag
		}
		// Println(m)
		for _, e := range edges {
			Fprintf(out, "%d ", m[e])
		}
		Fprintln(out)
	}
}

// func solve(start int, graph [][]int, edges []edge) []int {
//     visited := make([]bool, len(graph))
//     var dfs func(i int, flag bool)
//     dfs = func(i int, flag bool) {
//         if visited[i] {
//             return
//         }
//         visited[i] = true
//         for _, e := range graph[i] {
//
//         }
//     }
// }

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

package main

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

type edge struct {
	from, to int
}

func CF1627C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t, n int
	var v1, v2 int
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		graph := make([][]int, n)
		edges := make([]edge, 0, n)
		for i := 0; i < n-1; i++ {
			Fscan(in, &v1, &v2)
			v1--
			v2--
			if v1 > v2 {
				v1, v2 = v2, v1
			}
			edges = append(edges, edge{v1, v2})
			graph[v1] = append(graph[v1], v2)
			graph[v2] = append(graph[v2], v1)
		}
		// check answer
		// Println(graph)
		start := 0
		for i := range graph {
			if len(graph[i]) >= 3 {
				Fprintln(out, -1)
				break Outer
			}
			if len(graph[i]) == 1 {
				start = i
			}
		}
		// Println("start:", start)
		flag := true
		// visited := make([]bool, n)
		// visited[start] = true
		m := make(map[edge]int, n)
		for i := 0; i < n; i++ {
			adjs := graph[start]
			var v1, v2 int
			v1 = start
			if len(adjs) == 2 {
				for _, v := range adjs {
					_, ok1 := m[edge{start, v}]
					_, ok2 := m[edge{v, start}]
					if ok1 || ok2 {
						continue
					}
					v2 = v
				}
			} else {
				v2 = adjs[0]
			}
			start = v2
			if v1 > v2 {
				v1, v2 = v2, v1
			}
			if flag {
				m[edge{v1, v2}] = 2
			} else {
				m[edge{v1, v2}] = 3
			}
			flag = !flag
		}
		for _, e := range edges {
			Fprintf(out, "%d ", m[e])
		}
		Fprintln(out)
	}
}

// func solve(start int, graph [][]int, edges []edge) []int {
//     visited := make([]bool, len(graph))
//     var dfs func(i int, flag bool)
//     dfs = func(i int, flag bool) {
//         if visited[i] {
//             return
//         }
//         visited[i] = true
//         for _, e := range graph[i] {
//
//         }
//     }
// }

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)

		degrees := make([]int, n)
		var x, y int
		for i := 0; i < n-1; i++ {
			fmt.Fscan(in, &x, &y)
			degrees[x-1]++
			degrees[y-1]++
		}

		isPossible := true
		for i := range degrees {
			if degrees[i] > 2 {
				isPossible = false
				break
			}
		}

		if isPossible {
			two := true
			for i := 0; i < n-1; i++ {
				if i != 0 {
					fmt.Fprint(out, " ")
				}
				if two {
					fmt.Fprint(out, 2)
				} else {
					fmt.Fprint(out, 3)
				}
				two = !two
			}
		} else {
			fmt.Fprint(out, -1)
		}
		fmt.Fprintln(out)
		out.Flush()
	}
}


Polycarp remembered the $$$2020$$$-th year, and he is happy with the arrival of the new $$$2021$$$-th year. To remember such a wonderful moment, Polycarp wants to represent the number $$$n$$$ as the sum of a certain number of $$$2020$$$ and a certain number of $$$2021$$$.For example, if:   $$$n=4041$$$, then the number $$$n$$$ can be represented as the sum $$$2020 + 2021$$$;  $$$n=4042$$$, then the number $$$n$$$ can be represented as the sum $$$2021 + 2021$$$;  $$$n=8081$$$, then the number $$$n$$$ can be represented as the sum $$$2020 + 2020 + 2020 + 2021$$$;  $$$n=8079$$$, then the number $$$n$$$ cannot be represented as the sum of the numbers $$$2020$$$ and $$$2021$$$. Help Polycarp to find out whether the number $$$n$$$ can be represented as the sum of a certain number of numbers $$$2020$$$ and a certain number of numbers $$$2021$$$.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 10^6$$$) — the number that Polycarp wants to represent as the sum of the numbers $$$2020$$$ and $$$2021$$$.

For each test case, output on a separate line:    "YES" if the number $$$n$$$ is representable as the sum of a certain number of $$$2020$$$ and a certain number of $$$2021$$$;  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

package main

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

func newYearNumber(number int64) bool {
	var result bool = false
	var year int64 = 2020
	if (number%year) <= (number/year) {
		result = true
	}

	return result
}

func main() {
	var number, testCases int64
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	strTestCases := scanner.Text()
	strTestCases = strings.Replace(strTestCases, "\n", "", -1)
	testCases, _ = strconv.ParseInt(strTestCases, 10, 64)

	for testCases > 0 {
		scanner.Scan()
		n := scanner.Text()
		n = strings.TrimSuffix(n, "\n")
		number, _ = strconv.ParseInt(n, 10, 64)
		result := newYearNumber(number)
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		testCases--
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)
	for {
		var n int64
		fmt.Scanln(&n)
		a := n / 2020
		b := n % 2020
		if a >= b {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		t--
		if t == 0 {
			break
		}
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var t, n int
	scanf("%d\n", &t)
	for i := 1; i <= t; i++ {
		scanf("%d\n", &n)
		s := n % 2020
		if s == 0 {
			printf("YES\n")
		} else {
			if (n - s) / 2020 >= s {
				printf("YES\n")
			} else {
				printf("NO\n")
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func scanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		div, mod := n/2020, n%2020

		if mod <= div {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var N int
	var x int
	Fscan(in, &N)
	p := make([] bool, 1000005)
	p[0] = true
	p[2020] = true
	for i := 2021; i< len(p); i++ {
		if p[i - 2020] || p[i - 2021] {
			p[i] = true
		}
	}
	for tt:=0; tt < N; tt ++ {
		Fscan(in, &x)
		ans := "YES\n"
		if !p[x] {
			ans = "NO\n"
		}
		out.WriteString(ans)
	}
}

package main

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

var (
	t      int
	input  io.Reader = bufio.NewReader(os.Stdin)
	output           = bufio.NewWriter(os.Stdout)
)

var (
	arr [1e6 + 3]bool
)

func init() {
	arr[2020] = true
	arr[2021] = true

	for i := 2022; i <= 1e6; i++ {

		if arr[i-2020] == true {
			arr[i] = true
		}

		if arr[i-2021] == true {
			arr[i] = true
		}

	}
}

func solve() {

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

	if arr[n] {
		fmt.Fprintln(output, "YES")
	} else {
		fmt.Fprintln(output, "NO")
	}
}

func main() {
	fmt.Fscan(input, &t)

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

	defer output.Flush()
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Scanf("%d\n", &n)
		k := n / 2020
		if k == 0 {
			fmt.Printf("NO\n")
		} else {
			if (0 <= n-k*2020) && (n-k*2020 <= k) {
				fmt.Printf("YES\n")
			} else {
				fmt.Printf("NO\n")
			}
		}
	}
}

package main

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

func solve(r *bufio.Reader) {
	var n int64
	fmt.Fscan(r, &n)

	if n/2020 >= n%2020 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

/*
3
10103
10105
10099
---
YES
YES
NO
10103 = 2*2020+3*2021
*/

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

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

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		qtt := n / 2020
		rem := n % 2020

		if qtt >= rem && 2020*(qtt-rem)+2021*rem == n {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

const maxUint = ^uint(0)

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n int
		Fscan(in, &n)

		if n % 2021 == 0 || n % 2020 == 0 {
			Fprintln(out, "YES")

		} else if n % 2020 <= n / 2020 {
			Fprintln(out, "YES")

		} else {
			Fprintln(out, "NO")
		}
	}

}

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

package main

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

func generateToken(tokens map[int32]bool, n int32) map[int32]bool {
	if n > 1000005 || tokens[n] {
		return tokens
	}
	tokens = generateToken(tokens, n+2020)
	tokens = generateToken(tokens, n+2021)
	tokens[n] = true
	return tokens
}

func solve(tokens map[int32]bool, n int32) string {
	if tokens[n] {
		return "YES"
	} else {
		return "NO"
	}
}

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

	tokens := map[int32]bool{}
	tokens = generateToken(tokens, 0)

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)

		fmt.Fscanf(in, "%d\n", &n)
		fmt.Fprintf(out, "%s\n", solve(tokens, n))
		tt--
	}
	out.Flush()
}

package main

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

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

func scan(a ...interface{}) (n int, err error)             { return fmt.Fscan(in, a...) }
func scanf(f string, a ...interface{}) (n int, err error)  { return fmt.Fscanf(in, f, a...) }
func printf(f string, a ...interface{}) (n int, err error) { return fmt.Fprintf(out, f, a...) }

//https://codeforces.com/problemset/problem/1475/B

func main() {
	defer out.Flush()

	var n, a int
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		scanf("%d\n", &a)
		q, r := a/2020, a%2020
		if r > q {
			printf("NO\n")
		} else {
			printf("YES\n")
		}
	}
}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)

		if res {
			buf.WriteString("YES\n")
		} else {
			buf.WriteString("NO\n")
		}
	}

	fmt.Print(buf.String())
}

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) bool {
	k, r := n/2020, n%2020
	return r <= k
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n int64
		fmt.Scan(&n)

		var cnt2021 = n % 2020
		var cnt2020 = (n-cnt2021)/2020 - cnt2021
		if cnt2020 >= 0 && 2020*cnt2020+2021*cnt2021 == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

type ti uint64

var scanner = bufio.NewScanner(os.Stdin)

// SplitNums splits a string into a slice of integers
func SplitNums(s string) []ti {
	nums := strings.Split(strings.TrimSpace(s), " ")
	var result []ti
	for _, n := range nums {
		result = append(result, ParseInt(n))
	}
	return result
}

// ParseInt converts a string into an integer
func ParseInt(s string) ti {
	num, _ := strconv.ParseInt(strings.TrimSpace(s), 10, 64)
	return ti(num)
}

// ReadInput reads the input and returns the text
func ReadInput() string {
	scanner.Scan()
	return scanner.Text()
}

func solve(n ti) string {
	if n%2020 == 0 || n%2021 == 0 {
		return "Yes"
	}

	if n < 2020 {
		return "No"
	}

	if n%21 == 0 {
		return solve(n - 2021)
	}
	return solve(n - 2020)
}

func main() {
	input := ReadInput()
	test_cases := ParseInt(input)

	for i := ti(0); i < test_cases; i++ {
		input := ReadInput()
		num := ParseInt(input)
		fmt.Println(solve(num))
	}
}

package main

import "fmt"

func main() {
	var T int
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n int
		fmt.Scan(&n)
		if n%2020 <= n/2020 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main
//one year will be given ..we need to find if the number can be represented by using 2020 || 2021
import "fmt"

func main() {
	var test int //gets the number of test case
	var input int //gets the input
	fmt.Scanln(&test)
	for i := 0; i < test; i++ {
		fmt.Scan(&input)
		if (input % 2021==0 || input % 2020==0) {
			fmt.Println("YES")
			continue
		}else if true {
			for(input>=2020 ){
				//fmt.Println("the value of input is",input)
				input=input-2021
				if input%2020==0 {
					fmt.Println("YES")
					break
				}
			}
			if input%2020!=0 {
				fmt.Println("NO")
			}
		}else {
			fmt.Println("NO")
			continue
		}
	}
}

package main

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

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

func main() {

	defer out.Flush()

	fmt.Fscan(in, &t)

	for ; t > 0; t-- {

		fmt.Fscan(in, &n)

		fmt.Fprintln(out, solve(n))

	}

}

func solve(n int) string {

	a := 0

	for a*2020 <= n {

		b := 0

		for b*2021 <= n {

			if a*2020+b*2021 == n {
				return "YES"
			}

			b++

		}

		a++

	}

	return "NO"

}

package main

import (
	. "fmt"
)

func main(){
	var t int;
	Scan(&t);

	for i:=0;i<t;i++ {
		var n int;
		Scan(&n);
		var ok bool = false;
		for i:=0;i*2020<=n;i++ {
			if i*2020 <= n && (n-i*2020)%2021 == 0 {
				ok = true;
			}
		}
		if ok == true {
			Println("YES");
		} else{
			Println("NO");
		}
	}
}

package main

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

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

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

func main() {
	t := 10000
	fmt.Fscan(in, &t)
	for ; t != 0; t-- {
		var n int64
		fmt.Fscan(in, &n)
		if (n/2020)*2020+(n/2020) >= n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import . "fmt"

type pii struct {
	x, y int
}

func main() {
	var t int
	Scan(&t)
	solve := func() {
		var n int
		Scan(&n)
		cnt2021 := n % 2020
		cnt2020 := (n - cnt2021) / 2020 - cnt2021
		if cnt2020 >= 0 && 2020 * cnt2020 + 2021 * cnt2021 == n {
			Println(`YES`)
		} else {
			Println(`NO`)
		}
	}
	for t > 0 {
		solve()
		t--
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 1; i <= t; i++ {
		var n int64
		fmt.Scan(&n)
		x := n / 2020
		y := n % 2020
		if (y <= x) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assertion!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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

func solve() {
    var (
        n int
    )
    fmt.Fscan(input, &n)
    // n - b= (a + b)*2020
    for i := 0; n - i >= i*2020; i++ {
        if (n - i) % 2020 == 0 {
            fmt.Fprintln(output, "Yes")
            return
        }
    }
    fmt.Fprintln(output, "No")
}

/*
 * @Author: RBQRBQ
 * @Date: 2021-01-26 21:08:09
 * @LastEditors: RBQRBQ
 * @LastEditTime: 2021-01-26 21:16:49
 */
package main

import "fmt"

var ok [1000000 + 1]bool

func main() {
	for i := 0; i <= 1000000; i++ {
		ok[i] = false
	}
	for i := 0; i <= 1000; i++ {
		for j := 0; j <= 1000; j++ {
			if 2021*i+2020*j <= 1000000 {
				ok[2021*i+2020*j] = true
			}
		}
	}
	var t int
	fmt.Scan(&t)
	for i := 1; i <= t; i++ {
		var x int64
		fmt.Scan(&x)
		if ok[x] == true {
			fmt.Println("YES")
		}
		if ok[x] == false {
			fmt.Println("NO")
		}
	}
}

package main

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

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

func main() {
	defer writer.Flush()

	var t int
	fmt.Fscan(reader, &t)

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

		if find(n) {
			fmt.Fprintln(writer, "YES")
		} else {
			fmt.Fprintln(writer, "NO")
		}
	}
}

func find(n int) bool {
	for x := 0; x <= 500; x++ {
		for y := 0; y <= 500; y++ {
			if x*2020+y*2021 == n {
				return true
			}
		}
	}
	return false
}

// Written by : Syed Mujtaba
// Seek knowledge from the cradle to the grave
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 Abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	defer writer.Flush()

	var t int
	fmt.Scanf("%d\n", &t)
	for T := 0; T < t; T++ {
		var n int64
		scanf("%d\n", &n)
		if (n-n%2020)/2020 >= n%2020 {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

package main

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

func main() {
	a:=bufio.NewReader(os.Stdin)
	l, _ :=a.ReadString('\n')
	l=strings.Trim(strings.Trim(l,"\n"),"\r")
	ln, _ :=strconv.Atoi(l)
	for i:=0; i<ln;i++{
		s,_:=a.ReadString('\n')
		d, _ :=strconv.Atoi(strings.Trim(strings.Trim(s,"\n"), "\r"))
		fmt.Printf("%s\n",fn(d))

	}

}

func fn(n int) string{
	x:=n/2020
	o:=n%2020
	if o == 0 || x >= o{
		return "YES"
	}
	return "NO"
}

package main

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

func MIN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

var t int

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

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

		initial := n
		k := 0
		if n%2020 == 0 {
			fmt.Println("YES")
		} else {
			for i := 1; initial > 0; i++ {
				if initial%2021 == 0 {
					k = 1
					break
				}
				initial = initial - 2020
			}

			if k == 0 {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}
		}
	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		for i := 0; 2020*i<=n; i++ {
			if (n-2020*i)%2021 == 0 {
				Fprintln(out, "YES")
				return
			}
		}
		Fprintln(out, "NO")
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

func newYearNumber(number int64) bool {
	var result bool
	if number < 2020 {
		result = false
	} else if number == 2020 || number == 2021 {
		result = true
	} else {
		number -= 2021
		if (number % 2 == 0 && number % 5 == 0 && number % 101 == 0) || (number % 43 == 0 && number % 47 == 0) {
			result = true
		} else {
			result = false
		}
	}

	return result
}

func main() {
	var number, testCases int64
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	strTestCases := scanner.Text()
	strTestCases = strings.Replace(strTestCases, "\n", "", -1)
	testCases, _ = strconv.ParseInt(strTestCases, 10, 64)

	for testCases > 0 {
		scanner.Scan()
		n := scanner.Text()
		n = strings.TrimSuffix(n, "\n")
		number, _ = strconv.ParseInt(n, 10, 64)
		result := newYearNumber(number)
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		testCases--
	}
}

package main

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

func newYearNumber(number int64) bool {
	var result bool
	if number <= 2020 {
		result = false
	} else {
		number -= 2021
		if (number % 2 == 0 && number % 5 == 0 && number % 101 == 0) || (number % 43 == 0 && number % 47 == 0) {
			result = true
		} else {
			result = false
		}
	}

	return result
}

func main() {
	var number, testCases int64
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	strTestCases := scanner.Text()
	strTestCases = strings.Replace(strTestCases, "\n", "", -1)
	testCases, _ = strconv.ParseInt(strTestCases, 10, 64)

	for testCases > 0 {
		scanner.Scan()
		n := scanner.Text()
		n = strings.TrimSuffix(n, "\n")
		number, _ = strconv.ParseInt(n, 10, 64)
		result := newYearNumber(number)
		if result {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		testCases--
	}
}

package main

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

func newYearNumber(number int64) bool {
	var result bool
	if number <= 2020 {
		result = false
	} else {
		number -= 2021
		if (number % 2 == 0 && number % 5 == 0 && number % 101 == 0) || (number % 43 == 0 && number % 47 == 0) {
			result = true
		} else {
			result = false
		}
	}

	return result
}

func main() {
	var number, testCases int64
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	strTestCases := scanner.Text()
	strTestCases = strings.Replace(strTestCases, "\n", "", -1)
	testCases, _ = strconv.ParseInt(strTestCases, 10, 64)

	for testCases > 0 {
		scanner.Scan()
		n := scanner.Text()
		n = strings.TrimSuffix(n, "\n")
		number, _ = strconv.ParseInt(n, 10, 64)
		fmt.Println(newYearNumber(number))
		testCases--
	}
}

package main

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

func newYearNumber(number int64) bool {
	var result bool
	if number <= 2020 {
		result = false
	} else {
		number -= 2021
		if (number % 2 == 0 && number % 5 == 0 && number % 101 == 0) || (number % 43 == 0 && number % 47 == 0) {
			result = true
		} else {
			result = false
		}
	}

	return result
}

func main() {
	var number, testCases int64
	reader := bufio.NewReader(os.Stdin)
	strTestCases, _ := reader.ReadString('\n')
	strTestCases = strings.TrimSuffix(strTestCases, "\n")
	testCases, _ = strconv.ParseInt(strTestCases, 10, 64)

	for testCases > 0 {
		n, _ := reader.ReadString('\n')
		n = strings.TrimSuffix(n, "\n")
		number, _ = strconv.ParseInt(n, 10, 64)
		fmt.Println(newYearNumber(number))
		testCases--
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)
	for {
		var n int64
		fmt.Scanln(&n)
		if n < 2020 {
			fmt.Println("NO")
		} else {
			if n%10 == 0 {
				if n%2020 == 0 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			} else {
				if n%2021 == 0 {
					fmt.Println("YES")
				} else {
					for n%2020 != 0 && n > 2020 {
						n -= 2021
					}
					if n%2020 == 0 {
						fmt.Println("YES")
					} else {
						fmt.Println("NO")
					}
				}

			}
		}
		t--
		if t == 0 {
			break
		}
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanln(&t)
	for {
		var n int64
		fmt.Scanln(&n)
		if n < 2020 {
			fmt.Println("NO")
		} else {
			if n%10 == 0 {
				if n%2020 == 0 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			} else {
				for n%2020 != 0 && n > 2020 {
					n -= 2021
				}
				if n%2020 == 0 {
					fmt.Println("YES")
				} else {
					fmt.Println("NO")
				}
			}
		}
		t--
		if t == 0 {
			break
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strings"
)

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func scanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func scanInt() int {
	return int(scanInt64())
}

func scanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	for t := scanInt(); t > 0; t-- {
		n := scanInt()
		div, mod := n/2020, n%2020

		if mod < div {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var N int
	var x int
	Fscan(in, &N)
	p := make([] bool, 1000005)
	p[0] = true
	p[2020] = true
	for i := 2021; i< len(p); i++ {
		if p[i - 2020] || p[i - 2021] {
			p[i] = true
		}
	}
	for tt:=0; tt < N; tt ++ {
		Fscan(in, &x)
		for x>0 && x&1 == 0 {
			x = x >> 1
		}
		ans := "YES\n"
		if !p[x] {
			ans = "NO\n"
		}
		out.WriteString(ans)
	}
}


You are given an undirected unweighted graph consisting of $$$n$$$ vertices and $$$m$$$ edges (which represents the map of Bertown) and the array of prices $$$p$$$ of length $$$m$$$. It is guaranteed that there is a path between each pair of vertices (districts).Mike has planned a trip from the vertex (district) $$$a$$$ to the vertex (district) $$$b$$$ and then from the vertex (district) $$$b$$$ to the vertex (district) $$$c$$$. He can visit the same district twice or more. But there is one issue: authorities of the city want to set a price for using the road so if someone goes along the road then he should pay the price corresponding to this road (he pays each time he goes along the road). The list of prices that will be used $$$p$$$ is ready and they just want to distribute it between all roads in the town in such a way that each price from the array corresponds to exactly one road.You are a good friend of Mike (and suddenly a mayor of Bertown) and want to help him to make his trip as cheap as possible. So, your task is to distribute prices between roads in such a way that if Mike chooses the optimal path then the price of the trip is the minimum possible. Note that you cannot rearrange prices after the start of the trip.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains five integers $$$n, m, a, b$$$ and $$$c$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$n-1 \le m \le min(\frac{n(n-1)}{2}, 2 \cdot 10^5)$$$, $$$1 \le a, b, c \le n$$$) — the number of vertices, the number of edges and districts in Mike's trip. The second line of the test case contains $$$m$$$ integers $$$p_1, p_2, \dots, p_m$$$ ($$$1 \le p_i \le 10^9$$$), where $$$p_i$$$ is the $$$i$$$-th price from the array. The following $$$m$$$ lines of the test case denote edges: edge $$$i$$$ is represented by a pair of integers $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$), which are the indices of vertices connected by the edge. There are no loops or multiple edges in the given graph, i. e. for each pair ($$$v_i, u_i$$$) there are no other pairs ($$$v_i, u_i$$$) or ($$$u_i, v_i$$$) in the array of edges, and for each pair $$$(v_i, u_i)$$$ the condition $$$v_i \ne u_i$$$ is satisfied. It is guaranteed that the given graph is connected. It is guaranteed that the sum of $$$n$$$ (as well as the sum of $$$m$$$) does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$, $$$\sum m \le 2 \cdot 10^5$$$).

For each test case, print the answer — the minimum possible price of Mike's trip if you distribute prices between edges optimally.

NoteOne of the possible solution to the first test case of the example:One of the possible solution to the second test case of the example:

package main

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

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 main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		firstLine := readNNums(reader, 5)
		n, m, a, b, c := firstLine[0], firstLine[1], firstLine[2], firstLine[3], firstLine[4]
		P := readNNums(reader, m)
		edges := make([][]int, m)
		for i := 0; i < m; i++ {
			edges[i] = readNNums(reader, 2)
		}
		fmt.Println(solve(n, m, a, b, c, P, edges))
	}
}

func solve(n, m, a, b, c int, P []int, edges [][]int) int64 {
	sort.Ints(P)

	pref := make([]int64, m+1)

	for i := 0; i < m; i++ {
		pref[i+1] = pref[i] + int64(P[i])
	}

	E := make([][]int, n)

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

	for _, edge := range edges {
		u, v := edge[0], edge[1]
		u--
		v--
		E[u] = append(E[u], v)
		E[v] = append(E[v], u)
	}

	da := make([]int, n)
	db := make([]int, n)
	dc := make([]int, n)

	for i := 0; i < n; i++ {
		da[i] = -1
		db[i] = -1
		dc[i] = -1
	}

	que := make([]int, n)

	bfs := func(x int, dist []int) {
		var front, end int
		que[end] = x
		dist[x] = 0
		end++
		for front < end {
			u := que[front]
			front++
			for _, v := range E[u] {
				if dist[v] < 0 {
					dist[v] = dist[u] + 1
					que[end] = v
					end++
				}
			}
		}
	}

	bfs(a-1, da)
	bfs(b-1, db)
	bfs(c-1, dc)

	var best = int64(-1)

	for i := 0; i < n; i++ {
		if da[i]+db[i]+dc[i] > m {
			continue
		}
		tmp := pref[db[i]] + pref[da[i]+db[i]+dc[i]]
		if best < 0 || best > tmp {
			best = tmp
		}
	}

	return best
}

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		d := make([]int, n+1)
		for i := range d {
			d[i] = -1
		}
		d[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if d[w] < 0 {
					d[w] = d[v] + 1
					q = append(q, w)
				}
			}
		}
		return d
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}
		ans := int64(1e18)
		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		for v := 1; v <= n; v++ {
			if cost := depA[v] + depB[v] + depC[v]; cost <= m {
				if s := sum[cost] + sum[depB[v]]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		dep := make([]int, n+1)
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dep[w] == -1 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		dab := depA[b]
		if dab == 0 {
			d := depB[c]
			Fprintln(out, sum[d])
			continue
		}
		ans := int64(1e18)
		for v := 1; v <= n; v++ {
			if depA[v]+depB[v] > dab {
				continue
			}
			dbv, dcv := depB[v], depC[v]
			cost := dab + dcv
			if cost <= m {
				if s := sum[dbv] + sum[cost]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		dep := make([]int, n+1)
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dep[w] == -1 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		ans := int64(9e18)
		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		dab := depA[b]
		for v := 1; v <= n; v++ {
			dav, dbv, dcv := depA[v], depB[v], depC[v]
			if dav+dbv > dab {
				continue
			}
			if cost := dav + dbv + dcv; cost <= m {
				if s := sum[cost] + sum[dbv]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		dep := make([]int, n+1)
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dep[w] == -1 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		ans := int64(1e18)
		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		dab := depA[b]
		for v := 1; v <= n; v++ {
			if depA[v]+depB[v] > dab {
				continue
			}
			dbv, dcv := depB[v], depC[v]
			cost := dab + dcv
			if cost <= m {
				if s := sum[dbv] + sum[cost]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

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

	var t, n, m, a, b, c, v, w int
	calcDep := func(g [][]int, st int) []int {
		dep := make([]int, n+1)
		for i := range dep {
			dep[i] = -1
		}
		dep[st] = 0
		for q := []int{st}; len(q) > 0; {
			v, q = q[0], q[1:]
			for _, w := range g[v] {
				if dep[w] == -1 {
					dep[w] = dep[v] + 1
					q = append(q, w)
				}
			}
		}
		return dep
	}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m, &a, &b, &c)
		p := make([]int, m)
		for i := range p {
			Fscan(in, &p[i])
		}
		sort.Ints(p)
		sum := make([]int64, m+1)
		for i, v := range p {
			sum[i+1] = sum[i] + int64(v)
		}
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			Fscan(in, &v, &w)
			g[v] = append(g[v], w)
			g[w] = append(g[w], v)
		}

		ans := int64(9e18)
		depA, depB, depC := calcDep(g, a), calcDep(g, b), calcDep(g, c)
		dab := depA[b]
		if a == c {
			Fprintln(out, 2*sum[depA[b]])
			continue
		}

		for v := 1; v <= n; v++ {
			if depA[v]+depB[v] != dab {
				continue
			}
			dbv, dcv := depB[v], depC[v]
			cost := dab + dcv
			if cost <= m {
				if s := sum[dbv] + sum[cost]; s < ans {
					ans = s
				}
			}
		}
		Fprintln(out, ans)
	}
}

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


As their story unravels, a timeless tale is told once again...Shirahime, a friend of Mocha's, is keen on playing the music game Arcaea and sharing Mocha interesting puzzles to solve. This day, Shirahime comes up with a new simple puzzle and wants Mocha to solve them. However, these puzzles are too easy for Mocha to solve, so she wants you to solve them and tell her the answers. The puzzles are described as follow.There are $$$n$$$ squares arranged in a row, and each of them can be painted either red or blue.Among these squares, some of them have been painted already, and the others are blank. You can decide which color to paint on each blank square.Some pairs of adjacent squares may have the same color, which is imperfect. We define the imperfectness as the number of pairs of adjacent squares that share the same color.For example, the imperfectness of "BRRRBBR" is $$$3$$$, with "BB" occurred once and "RR" occurred twice.Your goal is to minimize the imperfectness and print out the colors of the squares after painting.

Each test contains multiple test cases.  The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case consists of two lines. The first line of each test case contains an integer $$$n$$$ ($$$1\leq n\leq 100$$$) — the length of the squares row. The second line of each test case contains a string $$$s$$$ with length $$$n$$$, containing characters 'B', 'R' and '?'. Here 'B' stands for a blue square, 'R' for a red square, and '?' for a blank square.

For each test case, print a line with a string only containing 'B' and 'R', the colors of the squares after painting, which imperfectness is minimized. If there are multiple solutions, print any of them.

NoteIn the first test case, if the squares are painted "BRRBRBR", the imperfectness is $$$1$$$ (since squares $$$2$$$ and $$$3$$$ have the same color), which is the minimum possible imperfectness.

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		dd()
	}
}
func dd() {
	var n int
	fmt.Scan(&n)
	var str string
	fmt.Scan(&str)
	arr := []byte(str)

	//正反两次遍历
	for i := 0; i+1 < n; i++ {
		if arr[i+1] == '?' && arr[i] != '?' {
			if arr[i] == 'B' {
				arr[i+1] = 'R'
			} else {
				arr[i+1] = 'B'
			}
		}
	}
	if arr[n-1] == '?' {
		arr[n-1] = 'R'
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i] == '?' && arr[i+1] != '?' {
			if arr[i+1] == 'B' {
				arr[i] = 'R'
			} else {
				arr[i] = 'B'
			}
		}
	}
	fmt.Println(string(arr))
}

package main

import (
    "fmt"
)

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

    for i := 0; i < tC; i++ {
        var (
            length int
            line string
        )
        fmt.Scanln(&length)
        fmt.Scanln(&line)
        if length == 1 && line == "?" {
            fmt.Println("R")
            continue
        }
        answ := []byte(line)
        contrary := map[byte]byte{
            'R': 'B',
            'B': 'R',
        }
        count := 0
        for _, v := range line {
            if v != '?' {
                count++
            }
        }

        if count == 0 {
            chars := []byte{'R', 'B'}
            for i, _ := range line {
                answ[i] = chars[i % 2]
            }
        } else {
            back, forw := 0, 1
            for forw < length {
                if answ[back] != '?' && answ[forw] == '?' {
                    answ[forw] = contrary[answ[back]]
                }
                back++
                forw++
            }
            forw, back = length-2, length-1
            for back > 0 {
                if answ[back] != '?' && answ[forw] == '?' {
                    answ[forw] = contrary[answ[back]]
                }
                back -= 1
                forw -= 1
            }
        }

        fmt.Println(string(answ))
    }
}

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}

func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("I") == "IronMan" }

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("END_GAME"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}

func solve() {
	t := iost.GetNextInt()
	for t > 0 {
		t--
		func() {
			n := iost.GetNextInt()
			s := iost.Text()
			idx := -1
			for i := 0; i < n; i++ {
				if s[i] != '?' {
					idx = i
					break
				}
			}
			prev := byte('B')
			if idx > -1 {
				if idx%2 == 0 {
					prev = s[idx]
				} else {
					if s[idx] == 'B' {
						prev = 'R'
					} else {
						prev = 'B'
					}
				}
			}
			iost.Print(string(prev))
			for i := 1; i < n; i++ {
				if s[i] == '?' {
					if prev == 'B' {
						prev = 'R'
						iost.Print("R")
					} else {
						prev = 'B'
						iost.Print("B")
					}
				} else {
					iost.Print(string(s[i]))
					prev = s[i]
				}
			}
			iost.Println()
		}()
	}
}

// 45min，'B' is byte, "B" is string

package main

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

var iost *Iost

type Iost struct {
	Scanner *bufio.Scanner
	Writer  *bufio.Writer
}

func NewIost(fp io.Reader, wfp io.Writer) *Iost {
	const BufSize = 1000000
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, BufSize), BufSize)
	return &Iost{Scanner: scanner, Writer: bufio.NewWriter(wfp)}
}

func (i *Iost) Text() string {
	if !i.Scanner.Scan() {
		panic("scan failed")
	}
	return i.Scanner.Text()
}

func (i *Iost) Atoi(s string) int                 { x, _ := strconv.Atoi(s); return x }
func (i *Iost) GetNextInt() int                   { return i.Atoi(i.Text()) }
func (i *Iost) Atoi64(s string) int64             { x, _ := strconv.ParseInt(s, 10, 64); return x }
func (i *Iost) GetNextInt64() int64               { return i.Atoi64(i.Text()) }
func (i *Iost) Atof64(s string) float64           { x, _ := strconv.ParseFloat(s, 64); return x }
func (i *Iost) GetNextFloat64() float64           { return i.Atof64(i.Text()) }
func (i *Iost) Print(x ...interface{})            { fmt.Fprint(i.Writer, x...) }
func (i *Iost) Printf(s string, x ...interface{}) { fmt.Fprintf(i.Writer, s, x...) }
func (i *Iost) Println(x ...interface{})          { fmt.Fprintln(i.Writer, x...) }
func isLocal() bool                               { return os.Getenv("I") == "IronMan" }

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	if isLocal() {
		fp, _ = os.Open(os.Getenv("END_GAME"))
	}
	iost = NewIost(fp, wfp)
	defer func() {
		if isLocal() {
			iost.Println(recover())
		}
		iost.Writer.Flush()
	}()
	solve()
	for i := 0; isLocal() && i < 100; i++ {
		iost.Println("-----------------------------------")
		solve()
	}
}

func getVal(s byte) int {
	// fmt.Println("xxx: ", s, byte('R'), byte('B'))
	if s == byte('R') {
		// fmt.Println("is R")
		return 1
	} else {
		// fmt.Println("is B")
		return 2
	}
}

func solve() {
	t := iost.GetNextInt()
	for t > 0 {
		t--
		func() {
			n := iost.GetNextInt()
			s := iost.Text()
			idx := -1
			for i := 0; i < n; i++ {
				if s[i] != '?' {
					idx = i
					break
				}
			}
			prev := byte('B')
			if idx > -1 {
				if idx%2 == 0 {
					prev = s[idx]
				} else {
					if s[idx] == 'B' {
						prev = 'R'
					} else {
						prev = 'B'
					}
				}
			}
			iost.Printf("%s", string(prev))
			for i := 1; i < n; i++ {
				if s[i] == '?' {
					if prev == 'B' {
						prev = 'R'
						iost.Printf("R")
					} else {
						prev = 'B'
						iost.Printf("B")
					}
				} else {
					iost.Printf("%s", string(s[i]))
					prev = s[i]
				}
			}
			iost.Println()

			// for i := 0; i < n; i++ {
			// 	if s[i] == '?' {
			// 		k := i + 1
			// 		for ; k < n; k++ {
			// 			if s[k] != '?' {
			// 				ret[k] = getVal(s[k])
			// 				break
			// 			}
			// 		}
			// 		for j := k - 1; j >= i; j-- {
			// 			if ret[j+1] == 2 {
			// 				ret[j] = 1
			// 			} else {
			// 				ret[j] = 2
			// 			}
			// 		}
			// 		i = k - 1
			// 	} else {
			// 		ret[i] = getVal(s[i])
			// 	}
			// }
			// for i := 0; i < n; i++ {
			// 	if ret[i] == 1 {
			// 		iost.Printf("R")
			// 	} else {
			// 		iost.Printf("B")
			// 	}
			// }
			// iost.Println()
		}()
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
	s      string
)

func solve(n int, s string) string {
	var m, cnt = []byte(s), 0
	for _, x := range m {
		if x != '?' {
			cnt++
		}
	}
	if cnt == 0 {
		m[0] = 'R'
	}
	for i := n - 2; i >= 0; i-- {
		if m[i+1] != '?' && m[i] == '?' {
			m[i] = 'B'
			if m[i+1] == 'B' {
				m[i] = 'R'
			}
		}
	}
	for i := 1; i < n; i++ {
		if m[i-1] != '?' && m[i] == '?' {
			m[i] = 'B'
			if m[i-1] == 'B' {
				m[i] = 'R'
			}
		}
	}
	return string(m)
}

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

// 1559B. Mocha and Red and Blue
package main

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

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n int
		fmt.Fscan(reader, &n)
		var s string
		fmt.Fscan(reader, &s)
		a := []byte(s)
		i := 0
		for i < n && a[i] == '?' {
			i++
		}
		if i == n {
			blue := true
			for i > 0 {
				if blue {
					a[i-1] = 'B'
				} else {
					a[i-1] = 'R'
				}
				i--
				blue = !blue
			}
		}
		for i > 0 {
			if a[i] == 'B' {
				a[i-1] = 'R'
			} else {
				a[i-1] = 'B'
			}
			i--
		}
		for i < n {
			if a[i] == '?' {
				if a[i-1] == 'R' {
					a[i] = 'B'
				} else {
					a[i] = 'R'
				}
			}
			i++
		}
		fmt.Println(string(a))
	}
}

package main

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

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t int
	var n int
	var s string
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(r, &n, &s)
		w1 := do(n, s)
		if ti != 0 {
			fmt.Fprintln(w)
		}
		fmt.Fprint(w, w1)
	}
}

var m = map[byte]byte{'R': 'B', 'B': 'R'}

func do(n int, s string) string {
	t := []byte(s)
	i := 0
	for i < n && t[i] == '?' {
		i++
	}
	if i == n {
		return strings.Repeat("BR", (n+1)/2)[:n]
	}
	for ; i >= 1; i-- {
		t[i-1] = m[t[i]]
	}
	for i = 1; i < n; i++ {
		if t[i] == '?' {
			t[i] = m[t[i-1]]
		}
	}
	return string(t)
}

package main

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

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

	tmpLine, _ := reader.ReadString('\n')
	testCount, _ := strconv.Atoi(strings.TrimSpace(tmpLine))

	for i := 0; i < testCount; i++ {
		reader.ReadString('\n')
		tmpLine, _ = reader.ReadString('\n')
		newArr := strings.Split(strings.TrimSpace(tmpLine), "")
		var count int
		for {
			newArr, count = solve(newArr)
			if count == 0 {
				break
			}
		}
		var res string
		for j := range newArr {
			res+=newArr[j]
		}
		fmt.Println(res)
	}
}

func solve(ss []string) ([]string, int) {
	var count int
	for i := range ss {
		switch ss[i] {
		case "B":
			if i != 0 {
				if ss[i-1] == "?" {
					ss[i-1] = "R"
				}
			}
			if i != len(ss)-1 {
				if ss[i+1] == "?" {
					ss[i+1] = "R"
				}
			}
		case "?":
			count++
		case "R":
			if i != 0 {
				if ss[i-1] == "?" {
					ss[i-1] = "B"
				}
			}
			if i != len(ss)-1 {
				if ss[i+1] == "?" {
					ss[i+1] = "B"
				}
			}
		}
	}
	if count == len(ss) {
		for i := range ss {
			if i%2 == 0 {
				ss[i] = "R"
			} else {
				ss[i] = "B"
			}
		}
		count = 0
	}
	return ss, count
}

func countSlozh(ss []string) int {
	var count int
	for i := 0; i < len(ss)-1; i++ {
		if ss[i] == ss[i+1] {
			count++
		}
	}
	return count
}

package main

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

var in = NewIn()
var out = NewOut()

func main() {
	defer out.flush()

	cases()
	// solve()
}

/* --- Solution B --- */
func solve() {
	n := in.nextInt()

	s := []byte(in.next())

	var pos int

	for i := 0; i < n; i++ {
		if s[i] != '?' {
			pos = i
			break
		}
	}

	c := [2]byte{'B', 'R'}

	k := pos % 2
	if s[pos] == 'R' {
		k++
	}
	for i := 0; i < n; i++ {
		if s[i] == '?' {
			s[i] = c[k%2]
			k++
		} else if s[i] == 'B' {
			k = 1
		} else if s[i] == 'R' {
			k = 0
		}
	}

	out.println(string(s))
}

func cases() {
	t := in.nextInt()
	for ; t > 0; t-- {
		solve()
	}
}

/* --- I/O --- */
const BUF_MAX_CAP int = 1e7

type In struct {
	scanner *bufio.Scanner
}

func NewIn() *In {
	scn := bufio.NewScanner(os.Stdin)

	buf := make([]byte, BUF_MAX_CAP)
	scn.Buffer(buf, BUF_MAX_CAP)
	scn.Split(bufio.ScanWords)

	return &In{scn}
}

func (in *In) nextInt() int {
	in.scanner.Scan()
	i, _ := strconv.Atoi(in.scanner.Text())
	return i
}

func (in *In) nextLong() int64 {
	in.scanner.Scan()
	i, _ := strconv.ParseInt(in.scanner.Text(), 10, 64)
	return i
}

func (in *In) nextDouble() float64 {
	in.scanner.Scan()
	i, _ := strconv.ParseFloat(in.scanner.Text(), 64)
	return i
}

func (in *In) next() string {
	in.scanner.Scan()
	return in.scanner.Text()
}

type Out struct {
	writer *bufio.Writer
}

func NewOut() *Out {
	out := Out{bufio.NewWriter(os.Stdout)}
	return &out
}

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

func (out *Out) printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

func (out *Out) print(a ...interface{}) {
	fmt.Fprint(out.writer, a...)
}

func (out *Out) flush() {
	out.writer.Flush()
}

package main

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

func main() {
	defer wr.Flush()
	t := scanInt()
	for i := 0; i < t; i++ {
		fmt.Fprintln(wr, solve())
	}
}

// imperfectness as the number of pairs of adjacent squares that share the same color.
func solve() string {
	n := scanInt()
	s := scanStr()

	b := make([]byte, n)
	q := 0
	for i := range s {
		if s[i] == '?' {
			q++
			continue
		}
		b[i] = s[i]
		if q == 0 {
			continue
		}
		j := i - q - 1
		var c byte
		if j < 0 {
			if q%2 == 0 {
				c = s[i]
			} else {
				c = op[s[i]]
			}
		} else {
			c = op[s[j]]
		}

		j++
		for ; j < i; j++ {
			b[j] = c
			c = op[c]
		}
		q = 0
	}

	if q > 0 {
		j := n - q - 1
		var c byte
		if j < 0 {
			c = 'R'
		} else {
			c = op[s[j]]
		}

		j++
		for ; j < n; j++ {
			b[j] = c
			c = op[c]
		}
	}
	return string(b)
}

var op = map[byte]byte{
	'R': 'B',
	'B': 'R',
}

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

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

	wr = bufio.NewWriter(os.Stdout)
}

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

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

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MINN(x, y int) int {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int64) int64 {
	if x > y {
		return x
	} else {
		return y
	}
}

func MAXX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

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

		// ARR := make([]int, n)
		// for i := 0; i < n; i++ {
		// 	fmt.Fscan(input, &ARR[i])
		// }

		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		le := 0
		begin := 0
		for i := 0; i < n; i++ {
			if STRING[i] == 63 {
				le++
			} else {
				begin = int(STRING[i])
				break
			}

		}
		if le == 0 {
			for i := 1; i < n; i++ {
				if STRING[i] == 63 {
					if STRING[i-1] == 66 {
						STRING[i] = 82
					} else {
						STRING[i] = 66
					}
				}
			}
		} else {
			if le%2 == 0 {
				if begin == 66 {
					STRING[0] = 66
				} else {
					STRING[0] = 82
				}
				for i := 1; i < n; i++ {
					if STRING[i] == 63 {
						if STRING[i-1] == 66 {
							STRING[i] = 82
						} else {
							STRING[i] = 66
						}
					}
				}
			} else {
				if begin == 66 {
					STRING[0] = 82
				} else {
					STRING[0] = 66
				}
				for i := 1; i < n; i++ {
					if STRING[i] == 63 {
						if STRING[i-1] == 66 {
							STRING[i] = 82
						} else {
							STRING[i] = 66
						}
					}
				}
			}
		}
		fmt.Println(string(STRING))

	}

}

package main

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

type Scanner struct {
	*bufio.Scanner
}

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

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

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

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

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

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

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

type state struct {
	pos int
	ch  byte
}

func expand(b []byte, i int, q *[]state) {
	if b[i] == '?' {
		panic("what")
	}

	ch := byte('B')
	if b[i] == 'B' {
		ch = 'R'
	}

	if l := i - 1; l >= 0 && b[l] == '?' {
		*q = append(*q, state{pos: l, ch: ch})
	}
	if r := i + 1; r < len(b) && b[r] == '?' {
		*q = append(*q, state{pos: r, ch: ch})
	}
}

func solve(s string) string {
	b := []byte(s)
	q := []state{}

	for i := range b {
		if b[i] != '?' {
			expand(b, i, &q)
		}
	}

	for len(q) > 0 {
		st := q[0]
		q = q[1:]

		if b[st.pos] == '?' {
			b[st.pos] = st.ch
			expand(b, st.pos, &q)
		}
	}

	if b[0] == '?' {
		for i := range b {
			if i%2 == 0 {
				b[i] = 'B'
			} else {
				b[i] = 'R'
			}
		}
	}

	return string(b)
}

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

	for i := 0; i < tests; i += 1 {
		stdin.Int()
		s := stdin.Word()
		fmt.Println(solve(s))
	}
}

package main

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

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

	solve := func(Case int) {
		var n int
		var s []byte
		Fscan(in, &n, &s)
		dp := make([][2]int, n)
		from := make([][2]int, n)
		if s[0] == 'B' {
			dp[0][1] = 1e9
		} else if s[0] == 'R' {
			dp[0][0] = 1e9
		}
		for i := 1; i < n; i++ {
			if s[i] == 'B' {

				dp[i][0] ,from[i][0] = min(dp[i-1][0]+1, dp[i-1][1])
				dp[i][1] = 1e9
			} else if s[i] == 'R' {
				dp[i][0] = 1e9
				dp[i][1],from[i][1] = min(dp[i-1][0], dp[i-1][1]+1)
			} else {
				dp[i][0],from[i][0]  = min(dp[i-1][0]+1, dp[i-1][1])
				dp[i][1] ,from[i][1] = min(dp[i-1][0], dp[i-1][1]+1)
			}
		}
		_,j := min(dp[n-1][0],dp[n-1][1])
		for i := len(s) - 1; i >= 0; i-- {
			v := s[i]
			if v == '?' {
				if j == 0 {
					s[i] = 'B'
				} else {
					s[i] ='R'
				}
				j = from[i][j]
			} else if v == 'B' {
				j = from[i][0]
			}  else {
				j = from[i][1]
			}
		}
		Fprintln(out, string(s))
	}

	T := 1
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

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

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		dd()
	}
}
func dd() {
	var n int
	fmt.Scan(&n)
	var str string
	fmt.Scan(&str)
	arr := []byte(str)

	//正反两次遍历
	for i := 1; i < n; i++ {
		if arr[i-1] == '?' && arr[i] != '?' {
			if arr[i] == 'B' {
				arr[i-1] = 'R'
			} else {
				arr[i-1] = 'B'
			}
		}
	}
	if arr[n-1] == '?' {
		arr[n-1] = 'R'
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i] == '?' {
			if arr[i+1] == 'B' {
				arr[i] = 'R'
			} else {
				arr[i] = 'B'
			}
		}
	}
	fmt.Println(string(arr))
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		dd()
	}
}
func dd() {
	var n int
	fmt.Scan(&n)
	var str string
	fmt.Scan(&str)
	arr := []byte(str)

	//正反两次遍历
	for i := 1; i < n; i++ {
		if arr[i-1] == '?' && arr[i] != '?' {
			if arr[i] == 'B' {
				arr[i-1] = 'R'
			} else {
				arr[i-1] = 'B'
			}
		}
	}
	if arr[n-1] == '?' {
		arr[n-1] = 'R'
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i] == '?' && arr[i+1] != '?' {
			if arr[i+1] == 'B' {
				arr[i] = 'R'
			} else {
				arr[i] = 'B'
			}
		}
	}
	fmt.Println(string(arr))
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		dd()
	}
}
func dd() {
	var n int
	fmt.Scan(&n)
	var str string
	fmt.Scan(&str)
	arr := []byte(str)

	//正反两次遍历
	for i := 1; i < n; i++ {
		if arr[i-1] == '?' && arr[i] != '?' {
			if arr[i] == 'B' {
				arr[i-1] = 'R'
			} else {
				arr[i-1] = 'B'
			}
		}
	}
	if arr[n-1] == '?' {
		arr[n-1] = 'B'
	}
	for i := n - 2; i >= 0; i-- {
		if arr[i] == '?' && arr[i+1] != '?' {
			if arr[i+1] == 'B' {
				arr[i] = 'R'
			} else {
				arr[i] = 'B'
			}
		}
	}
	fmt.Println(string(arr))
}

package main

import (
    "fmt"
)

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

    for i := 0; i < tC; i++ {
        var (
            length int
            line string
        )
        fmt.Scanln(&length)
        fmt.Scanln(&line)
        if length == 1 && line == "?" {
            fmt.Println("R")
            continue
        }
        answ := []byte(line)
        contrary := map[byte]byte{
            'R': 'B',
            'B': 'R',
        }

        back, forw := 0, 1
        for forw < length {
            if answ[back] != '?' && answ[forw] == '?' {
                answ[forw] = contrary[answ[back]]
            }
            back++
            forw++
        }
        forw, back = length-2, length-1
        for back > 0 {
            if answ[back] != '?' && answ[forw] == '?' {
                answ[forw] = contrary[answ[back]]
            }
            back -= 1
            forw -= 1
        }

        fmt.Println(string(answ))
    }
}

package main

import (
    "fmt"
)

func main() {
    var testCases int
    var length int
    fmt.Println("Scanning testcases")
    fmt.Scan(&testCases)

    for i := 0; i < testCases; i++ {
        fmt.Scan(&length)
        var row string
        fmt.Scan(&row)
        if length == 1 {
            if row == "?" {
                fmt.Println("B")
            } else {
                fmt.Println(row)
            }
        } else {
            fmt.Println(formAnsw(row))
        }
    }
}

func formAnsw(row string) string {
    back, forward := 0, 1
    contrary := map[string]string{
        "B": "R",
        "R": "B",
    }
    for ; forward < len(row);  {
        if row[back] == '?' && row[forward] == '?' {
            row = row[:back] + "RB" + row[forward+1:]
        } else if row[back] == '?' && row[forward] != '?' {
            row = row[:back] + contrary[string(row[forward])] + row[back+1:]
        } else if row[back] != '?' && row[forward] == '?' {
            row = row[:forward] + contrary[string(row[back])] + row[forward+1:]
        }
        back++
        forward++
    }
    return row
}

package main

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int

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

	for t := 0; t < T; t++ {
		var n int
		var s string

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

		res := []byte(s)

		for i := 0; i < len(res); i++ {
			if res[i] == '?' {
				cr := 0
				cb := 0
				if i > 0 {
					if res[i-1] == 'B' {
						cb++
					} else if res[i-1] == 'R' {
						cr++
					}
				}
				if i < n-1 {
					if res[i+1] == 'B' {
						cb++
					} else if res[i+1] == 'R' {
						cr++
					}
				}

				if cb < cr {
					res[i] = 'B'
				} else {
					res[i] = 'R'
				}
			}
		}

		fmt.Println(string(res))
	}
}