You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pixels have the same color. In one move, you can choose no more than two pixels of the same color and paint them into some other color (if you choose two pixels, both should be painted into the same color).What is the minimum number of moves you have to make in order to fulfill your goal?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. Each of these lines contains two lowercase letters of Latin alphabet without any separators, denoting a row of pixels in the image.

For each test case, print one integer — the minimum number of moves you have to make so that all $$$4$$$ pixels of the image have the same color.

5

rb

br

cc

wb

aa

aa

ab

cd

yy

xx

NoteLet's analyze the test cases of the example.In the first test case, you can paint the bottom left pixel and the top right pixel (which share the same color) into the color r, so all pixels have this color.In the second test case, two moves are enough:  paint both top pixels, which have the same color c, into the color b;  paint the bottom left pixel into the color b. In the third test case, all pixels already have the same color.In the fourth test case, you may leave any of the pixels unchanged, and paint all three other pixels into the color of that pixel in three moves.In the fifth test case, you can paint both top pixels into the color x.

package main
import (
    "fmt"
)

func work(n string) int {
    u := map[rune]bool{}
    for _, c := range n {
        u[c] = true
    }
    return len(u)-1
}

func main() {
        var t int
        fmt.Scanf("%d\n", &t)
        for ;t>0; t-- {
            var a, b string
            fmt.Scanf("%s\n", &a)
            fmt.Scanf("%s\n", &b)
            a += b

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

package main

import (
	"fmt"
	"os"
)

func main() {
	var numberOfTests int
	//testData := "5\nrb\nbr\ncc\nwb\naa\naa\nab\ncd\nyy\nxx"
	//reader := strings.NewReader(testData)
	reader := os.Stdin
	fmt.Fscanln(reader, &numberOfTests)
	for testNumber := 1; testNumber <= numberOfTests; testNumber++ {
		m := make(map[rune]int)
		var twoColors string
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}

		fmt.Println(len(m) - 1)
	}
}

package main

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

func max(a int, rest ...int) int {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s1, s2 []byte
		fmt.Fscan(in, &s1, &s2)

		aa := make([]int, 26)
		aa[s1[0]-'a']++
		aa[s1[1]-'a']++
		aa[s2[0]-'a']++
		aa[s2[1]-'a']++

		g := max(aa[s1[0]-'a'], aa[s1[1]-'a'], aa[s2[0]-'a'], aa[s2[1]-'a'])
		if g == 4 {
			fmt.Fprintln(out, 0)
		} else if g == 3 {
			fmt.Fprintln(out, 1)
		} else if g == 1 {
			fmt.Fprintln(out, 3)
		} else {
			if aa[s1[0]-'a'] == 2 && aa[s1[1]-'a'] == 2 && aa[s2[0]-'a'] == 2 && aa[s2[1]-'a'] == 2 {
				fmt.Fprintln(out, 1)
			} else {
				fmt.Fprintln(out, 2)
			}
		}
	}
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1721A
Date: 8/29/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1721/A
Problem: CF1721A
**/
func (in *CF1721A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		mapa := make(map[uint8]bool)
		str := in.NextString()
		mapa[str[0]] = true
		mapa[str[1]] = true
		str = in.NextString()
		mapa[str[0]] = true
		mapa[str[1]] = true
		if len(mapa) == 1 {
			fmt.Println(0)
		} else if len(mapa) == 2 {
			fmt.Println(1)
		} else if len(mapa) == 3 {
			fmt.Println(2)
		} else {
			fmt.Println(3)
		}
	}
}

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

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

package main

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

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

func qwq() {
	var s1, s2 string
	ht := map[byte]int{}
	fmt.Fscan(in, &s1, &s2)
	ht[s1[0]]++
	ht[s1[1]]++
	ht[s2[0]]++
	ht[s2[1]]++
	fmt.Fprintln(out, len(ht)-1)
}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscanln(in, &q)
	for ; q > 0; q-- {
		qwq()
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b string
		fmt.Fscan(in,&a,&b)
		a+=b
		pairs:=0
		mapper:= make(map[string]bool)
		for j:=0;j<4;j++{
			if mapper[string(a[j])] == true {
				pairs++
				continue
			}
			mapper[string(a[j])]= true
		}
		if pairs == 3 {
			fmt.Fprintln(out,0)
		} else if pairs == 2 {
			fmt.Fprintln(out,1)
		} else if pairs == 1 {
			fmt.Fprintln(out,2)
		} else {
			fmt.Fprintln(out,3)
		}
	}
}

package main

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

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

	var t, cnt int
	for fmt.Fscan(r, &t); t > 0; t-- {
		s := make([]string, 2)
		m := make(map[byte]bool)
		cnt = -1

		for i := 0; i < 2; i++ {
			fmt.Fscan(r, &s[i])
			for j := 0; j < 2; j++ {
				e := s[i][j]
				if _, v := m[e]; !v {
					cnt++
					m[e] = true
				}
			}
		}

		fmt.Fprintln(w, cnt)
	}
}

package main

import (
    "fmt"
    "sort"
    "strings"
)

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

    for i := 0; i < n; i++ {
        var a, b string

        fmt.Scanf("%s\n%s\n",&a,&b)

        c := strings.Split(a + b, "")
        sort.Strings(c)

        ans := 0;
        for j := 1; j < 4; j++ {
            if (c[j] == c[j-1]) {
                continue
            }
            ans++
        }

        fmt.Println(ans)
    }
}

package main

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

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

	for t > 0 {
		t--
		s := make([]int, 26, 26)
		for _, c := range readLine(in) {
			s[int(c-'a')]++
		}
		for _, c := range readLine(in) {
			s[int(c-'a')]++
		}
		ret := 0
		for _, v := range s {
			if v > 0 {
				ret++
			}
		}
		fmt.Println(ret - 1)
	}
}

///////////////////////////////////
// DO NOT EDIT
///////////////////////////////////

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

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

func readLineNumbs(in *bufio.Reader) []string {
	numbs := strings.Split(readLine(in), " ")
	return numbs
}

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

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main

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

var P107 int = 1000000007

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 Abs(a int) int {
	return Max(a, -a)
}

func Gcd(a, b int) int {
	min := Min(a, b)
	max := Max(a, b)
	if min == 0 {
		return max
	}

	for max%min != 0 {
		min, max = max%min, min
	}

	return min
}

func Lcm(a, b int) int {
	return a / Gcd(a, b) * b
}

// var facs []int = make([]int, X + 1)
func FacP(n, p int) int {
  // if facs[n] != 0 {
  //   return facs[n]
  // }
	result := 1
  // facs[0] = 1
	for i := 1; i <= n; i++ {
		result = (result * i) % p
    // facs[i] = result
	}

	return result
}

func ExpP(a, x, p int) int {
	if x == 0 {
		return 1
	}

	if x%2 == 0 {
		half := ExpP(a, x/2, p)
		return (half * half) % p
	} else {
		return ((a % p) * ExpP(a, x-1, p)) % p
	}
}

func CombP(n, c, p int) int {
  // If CombP be called multiple times, you should optimize FacP using memoization.
	return (FacP(n, p) * ((ExpP(FacP(n-c, p), p-2, p) * ExpP(FacP(c, p), p-2, p)) % p)) % p
}

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())

  for _i := 0; _i < t; _i++ {
    scanner.Scan()
    a := []rune(scanner.Text())
    scanner.Scan()
    b := []rune(scanner.Text())
    aph := make([]bool, 26)

    same := 0
    for i := 0; i < 2; i++ {
      if aph[a[i] - 97] {
        same++
      } else {
        aph[a[i] - 97] = true
      }
      if aph[b[i] - 97] {
        same++
      } else {
        aph[b[i] - 97] = true
      }
    }

    wr.WriteString(strconv.Itoa(3 - same) + "\n")
  }
}

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

package main

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

func main() {
	r := readerStdin()

	for cases := readInt(r); cases != 0; cases-- {
		var image = make([]byte, 0, 4)
		for i := 0; i < 2; i++ {
			image = append(image, []byte(readString(r))...)
		}

		sort.Slice(image, func(i, j int) bool { return image[i] < image[j] })

		var countQuantity int
		for i := 0; i < len(image)-1; i++ {
			if image[i] != image[i+1] {
				countQuantity++
			}
		}
		fmt.Println(countQuantity)
	}
}

func readerStdin() *bufio.Reader {
	return bufio.NewReader(os.Stdin)
}

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

func readSliceInt(r *bufio.Reader) []int {
	str := readString(r)
	slice := strings.Split(str, " ")

	var result = make([]int, len(slice))
	for i, v := range slice {
		x, _ := strconv.Atoi(v)
		result[i] = x
	}

	return result
}

func readInt(r *bufio.Reader) (i int) {
	str := readString(r)
	i, _ = strconv.Atoi(str)
	return
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		myslice := []string{}
		for j := 0; j < 2; j++ {
			var temp string
			fmt.Scan(&temp)
			myslice = append(myslice, temp)
		}
		m1 := make(map[byte]int)
		for j := 0; j < 2; j++ {
			for k := 0; k < 2; k++ {
				char := myslice[j][k]
				m1[char]++
			}

		}
		fmt.Println(len(m1) - 1)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	t_ := scanner.Text()
	for t, _ := strconv.Atoi(t_); t > 0; t-- {
		var tm map[rune]bool = make(map[rune] bool)
		for i := 0; i < 2; i++ {
		    scanner.Scan()
			for _, c := range scanner.Text() {
				tm[c] = true
			}
		}
		fmt.Println(len(tm) - 1)
	}
}

package main

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

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

func main() {
	var t int
	fmt.Fscanln(in, &t)
	for t > 0 {
		mp := map[byte]int{}
		for row := 0; row < 2; row++ {
			var s string
			fmt.Fscanln(in, &s)
			for i := range s {
				mp[s[i]]++
			}
		}
		max1, max2 := 0, 0
		for _, v := range mp {
			if max1 < v {
				max2, max1 = max1, v
			} else if max2 < v {
				max2 = v
			}
		}
		if max1 == 4 {
			fmt.Println(0)
		} else if max1 == 3 {
			fmt.Println(1)
		} else if max1 == 2 {
			if max2 == 1 {
				fmt.Println(2)
			} else {
				fmt.Println(1)
			}
		} else {
			fmt.Println(3)
		}
		t--
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	p, q   string
)

func solve(p, q string) int {
	var f = make(map[rune]int)
	for _, x := range p {
		f[x]++
	}
	for _, x := range q {
		f[x]++
	}
	return len(f) - 1
}

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

package main

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

func main() {
	input := bufio.NewReader(os.Stdin)
	cases := readInt(input)
	for asdf := 0; asdf < cases; asdf++ {
		s1 := readLineNumbs(input)
		s2 := readLineNumbs(input)
		c := []rune(s1[0])
		tmp := []rune(s2[0])
		c = append(c, tmp[0])
		c = append(c, tmp[1])
		fmt.Println(solve(c))
	}
}

func solve(s []rune) int {
	a := []int{}
	for i := 0; i < 256; i++ {
		a = append(a, 0)
	}
	for i := 0; i < 4; i++ {
		a[int(s[i])]++
	}
	sort.Ints(a)
	tmp := 0
	for i := 0; i < 256; i++ {
		if a[i] > 0 {
			tmp++
		}
	}
	return tmp - 1
}

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

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

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

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

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

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

func readArrInt64(in *bufio.Reader) []int64 {
	numbs := readLineNumbs(in)
	arr := make([]int64, len(numbs))
	for i, n := range numbs {
		val, _ := strconv.ParseInt(n, 10, 64)
		arr[i] = val
	}
	return arr
}

package main
import (
    "fmt"
)

func work(n string) int {
    u := map[rune]bool{}
    for _, c := range n {
        u[c] = true
    }
    return len(u)
}

func main() {
        var t int
        fmt.Scanf("%d\n", &t)
        for ;t>0; t-- {
            var a, b string
            fmt.Scanf("%s\n", &a)
            fmt.Scanf("%s\n", &b)
            a += b

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

package main

import (
	"fmt"
	"os"
)

func main() {
	var numberOfTests int
	reader := os.Stdin
	fmt.Fscanln(reader, &numberOfTests)
	for testNumber := 1; testNumber <= numberOfTests; testNumber++ {
		m := make(map[rune]int)
		var twoColors string
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}

		fmt.Println(4 - len(m))
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var numberOfTests int
	testData := "5\nrb\nbr\ncc\nwb\naa\naa\nab\ncd\nyy\nxx\n"
	reader := strings.NewReader(testData)
	//reader := os.Stdin
	fmt.Fscanln(reader, &numberOfTests)
	for testNumber := 1; testNumber <= numberOfTests; testNumber++ {
		m := make(map[rune]int)
		var twoColors string
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}
		fmt.Fscanln(reader, &twoColors)
		for _, r := range twoColors {
			m[r]++
		}

		fmt.Println(4 - len(m))
	}
}

package main

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

func max(a int, rest ...int) int {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s1, s2 []byte
		fmt.Fscan(in, &s1, &s2)

		aa := make([]int, 26)
		aa[s1[0]-'a']++
		aa[s1[1]-'a']++
		aa[s2[0]-'a']++
		aa[s2[1]-'a']++

		g := max(aa[s1[0]-'a'], aa[s1[1]-'a'], aa[s2[0]-'a'], aa[s2[1]-'a'])
		if g == 4 {
			fmt.Fprintln(out, 0)
		} else if g == 3 {
			fmt.Fprintln(out, 1)
		} else if g == 1 {
			fmt.Fprintln(out, 3)
		} else {
			if (s1[0] == s1[1] && s2[0] != s2[1]) || (s2[0] == s2[1] && s1[0] != s1[1]) {
				fmt.Fprintln(out, 2)
			} else {
				fmt.Fprintln(out, 1)
			}
		}
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		var s1, s2 []byte
		fmt.Fscan(in, &s1, &s2)

		if s1[0] == s1[1] && s1[0] == s2[0] && s2[0] == s2[1] {
			fmt.Fprintln(out, 0)
		} else if s1[0] == s1[1] && s2[0] == s2[1] {
			fmt.Fprintln(out, 1)
		} else if (s1[0] == s2[0] || s1[0] == s2[1]) && (s1[1] == s2[0] || s1[1] == s2[1]) {
			fmt.Fprintln(out, 1)
		} else if (s1[0] == s1[1] && s2[0] != s2[1]) || (s1[0] != s1[1] && s2[0] == s2[1]) {
			fmt.Fprintln(out, 2)
		} else {
			fmt.Fprintln(out, 3)
		}
	}
}


Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least $$$2$$$ cosplayers, the number of males does not exceed the number of females (obviously).Currently, the line has $$$n$$$ cosplayers which can be described by a binary string $$$s$$$. The $$$i$$$-th cosplayer is male if $$$s_i = 0$$$ and female if $$$s_i = 1$$$. To ensure that the line is beautiful, you can invite some additional cosplayers (possibly zero) to join the line at any position. You can't remove any cosplayer from the line.Marin wants to know the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful. She can't do this on her own, so she's asking you for help. Can you help her?

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases.  The first line of each test case contains a positive integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of cosplayers in the initial line. The second line of each test case contains a binary string $$$s$$$ of length $$$n$$$ — describing the cosplayers already in line. Each character of the string is either 0 describing a male, or 1 describing a female. Note that there is no limit on the sum of $$$n$$$.

For each test case, print the minimum number of cosplayers you need to invite so that the group picture of all the cosplayers is beautiful.

NoteIn the first test case, for each pair of adjacent cosplayers, you can invite two female cosplayers to stand in between them. Then, $$$000 \rightarrow 0110110$$$.In the third test case, you can invite one female cosplayer to stand next to the second cosplayer. Then, $$$010 \rightarrow 0110$$$.

package main

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

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

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

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

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

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

/**
Run solve the problem CF1658A
Date: 19/04/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1658/A
Problem: CF1658A
**/
func (in *CF1658A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		in.NextInt()
		str := in.NextString()
		ans := 0

		for i := 1; i < len(str); i++ {
			if str[i] == '0' && str[i-1] == '0' {
				str = str[:i] + "11" + str[i:]
				ans += 2
			}
		}

		for i:=2;i< len(str);i++{
			if str[i-2]=='0' && str[i-1]=='1' && str[i] == '0'{
				str = str[:i-1] + "1" + str[i-1:]
				ans += 1
			}
		}

		fmt.Println(ans)
	}
}

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

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

package main

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

// var N int = 2e5 + 10
// var MOD int64 = 1e9 + 7

func main() {

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

	var T, n int
	var s string
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s)
		sz := len(s)
		ans := 0
		for i := 0; i+1 < sz; i++ {
			if s[i] == '0' {
				if s[i+1] == '0' {
					ans += 2
				} else if i+2 < sz && s[i+2] == '0' {
					ans++
				}
			}
		}
		Fprintln(out, ans)
	}
}

package main

import (
	"fmt"
)

func main() {
	var T, n int
	var s string
	fmt.Scan(&T)

	for ; T > 0; T-- {
		fmt.Scan(&n, &s)
		sz := len(s)
		ans := 0
		for i := 0; i+1 < sz; i++ {
			if s[i] == '0' {
				if s[i+1] == '0' {
					ans += 2
				} else if i+2 < sz && s[i+2] == '0' {
					ans++
				}
			}
		}
		fmt.Println(ans)
	}
}

package main
// github.com/jamesgrimard/codeforces
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		var word string
		fmt.Fscan(in,&word)
		var sum int
		for j:=0;j<n-1;j++{
			if string(word[j]) == "0" {
				count:=2
				for k:=j+1;k<n;k++{
					if string(word[k]) == "1" {
						count--
					}
					if string(word[k]) == "0" || count == 0 {
						sum+=count
						break
					}
				}
			}
		}
		fmt.Fprintln(out,sum)
	}
}

package main

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

const mod = 998244353

func solve(in *bufio.Reader, out *bufio.Writer) {
	defer out.Flush()
	var n int
	fmt.Fscan(in,&n)
	var str string
	fmt.Fscan(in,&str)
	var arr []int
	for i := 0;i < len(str);i++{
		if str[i] == '0'{
			arr = append(arr,i)
		}
	}
	ans := 0
	for i := 1;i < len(arr);i++{
		if arr[i] - arr[i - 1] <= 2{
			ans += 3 - (arr[i] - arr[i - 1])
		}
	}
	fmt.Fprintln(out,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 (
	"fmt"
	"strings"
)

func count(sub, pat string) int {
	var c int
	for d := range sub {
	   if strings.HasPrefix(sub[d:], pat) { c++ }
	}
	return c
 }

func main() {
	var (
		t   int
		n   int
		str string
	)
	for fmt.Scan(&t); t > 0; t-- {
		fmt.Scan(&n, &str)
		ans := 0
		ans += (count(str, "00") * 2)
		ans += count(str, "010")
		fmt.Println(ans)
	}
}

package main

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

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

const mod = 998244353

// 1 2 3 4
func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		var s string
		fmt.Fscan(in, &s)
		ans := 0
		last := -1
		for i := 0; i < n; i++ {
			if s[i] == '0' {
				if last != -1 && i-last < 3 {
					ans += 3 - i + last
				}
				last = i
			}
		}
		fmt.Fprintln(out, ans)
	}
}

package main

import "fmt"

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

func main() {
	var T int
	fmt.Scan(&T)
	for ; T > 0; T-- {
		var n int
		var str string
		fmt.Scan(&n, &str)
		last := -10
		ans := 0
		for i := 0; i < n; i++ {
			if str[i] == '0' {
				ans += Max(0, 2-(i-last)+1)
				last = i
			}
		}
		fmt.Println(ans)
	}
}

package main

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

var T int

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	Fscan(in, &T)
	for ; T > 0; T-- {
		var n int
		var str string
		Fscan(in, &n, &str)
		ans := 0
		i, j := 0, -1
		for i < n {
			if str[i] == '1' {
				i++
				continue
			}
			if j == -1 {
				j = i
				i++
			} else {
				if i - j == 1 {
					ans += 2
				} else if i - j == 2 {
					ans += 1
				}
				j = i
				i++
			}
		}
		Fprintln(out, ans)
	}
	defer out.Flush()
}

package main

import "fmt"

func main() {
	var T, n int
	var pos []int
	var s string
	fmt.Scan(&T)
	for ; T > 0; T-- {
		fmt.Scan(&n, &s)
		pos = []int{}
		for i, e := range s {
			if e == '0' {
				pos = append(pos, i)
			}
		}
		var ans int
		for i := 1; i < len(pos); i++ {
			if pos[i]-pos[i-1]-1 < 2 {
				ans += 2 - (pos[i] - pos[i-1] - 1)
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

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

		var req int
		for i := 0; i < n-1; i++ {
			if s[i] == '0' && s[i+1] == '0' {
				req += 2
			} else if s[i] == '0' && s[i+1] == '1' && i < n-2 && s[i+2] == '0' {
				req += 1
			}
		}
		fmt.Fprintln(out, req)
	}
}

package main

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

const (
	INF = 3e5 + 10
)

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

	var t int
	Fscan(in, &t)

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

		last := -1
		ans := 0
		for i := 0; i < len(s); i++ {
			if s[i] == '0' {
				if last != -1 {
					if i-last < 3 {
						ans += 3 - i + last
					}

				}
				last = i
			}

		}

		Fprintln(out, ans)
	}

}

package main

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

/*
4
1
0
1
1
2
00
3
010
---
0
0
2 0110
1 0110
==========
000
0110110
*/

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

	cnt := 0

	for i := 1; i < n; i++ {
		if s[i] == '0' && s[i-1] == '0' {
			cnt += 2
		}
	}

	for i := 2; i < n; i++ {
		if s[i-2] == '0' && s[i-1] == '1' && s[i] == '0' {
			cnt += 1
		}
	}

	fmt.Fprintln(writer, cnt)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

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

	return minNumIdx
}

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

	return maxNumIdx
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

import "fmt"

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

	for ; t > 0; t-- {
		var n int
		var s string

		fmt.Scan(&n)
		fmt.Scan(&s)

		var ans int

		var last int = -1
		for i := 0; i < n; i++ {
			switch s[i] {
			case '0':
				if last != -1 {
					length := i - last
					if length == 1 {
						ans += 2
					} else if length == 2 {
						ans += 1
					}
				}
				last = i
			}
		}

		fmt.Println(ans)
	}
}

// generated by 1e9y at 27-03-2022
// template version: 2022-01-11

package main

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

// 101101101101101101101101101101101101

// 0000.A
func solve(n int, s string) int {
	// here goes solution
	c := 0
	for i := 0; i < n-1; i++ {
		if s[i] == '0' && s[i+1] == '0' {
			c += 2
		} else if s[i] == '0' && s[i+1] == '1' {
			if i < n-2 {
				if s[i+2] == '0' {
					c += 1
				}
			}
		}
	}
	if c < 0 {
		return 0
	}
	return c
}

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

	t := ReadInt(in)
	for i := 0; i < t; i++ {
		// here goes input reading
		n := ReadInt(in)
		s := ReadLine(in)
		Output(solve(n, s))
	}
}

// helpers for convenient input reading

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

func ReadLine(in *bufio.Reader) string {
	line, _ := in.ReadString('\n')
	line = strings.Trim(line, "\n\r")
	return line
}

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

func ReadIntSlice(in *bufio.Reader) []int {
	parts := ReadLineParts(in)
	slice := make([]int, len(parts))
	for i, n := range parts {
		slice[i] = MustAtoi(n)
	}
	return slice
}

func ReadInt64Slice(in *bufio.Reader) []int64 {
	parts := ReadLineParts(in)
	slice := make([]int64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseInt(n, 10, 64)
	}
	return slice
}

func ReadUint64Slice(in *bufio.Reader) []uint64 {
	parts := ReadLineParts(in)
	slice := make([]uint64, len(parts))
	for i, n := range parts {
		slice[i] = MustParseUint(n, 10, 64)
	}
	return slice
}

func MustAtoi(s string) int {
	v, _ := strconv.Atoi(s)
	return v
}

func MustParseInt(s string, base, bitSize int) int64 {
	v, _ := strconv.ParseInt(s, base, bitSize)
	return v
}

func MustParseUint(s string, base, bitSize int) uint64 {
	v, _ := strconv.ParseUint(s, base, bitSize)
	return v
}

func SkipLine(in *bufio.Reader) {
	_, _ = in.ReadString('\n')
}

// helper for convenient answer output

func Output(v interface{}) {
	switch v.(type) {
	case bool:
		if v == true {
			Println("YES")
		} else {
			Println("NO")
		}
	default:
		Println(v)
	}
}

package main

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

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

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

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

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

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

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

func main() {
	defer writer.Flush()
	for t := _int(); t > 0; t-- {
		_ = _int()
		sol(_string())
	}
}

func sol(s string) {
	pos := []int{}
	for i := range s {
		if s[i] == '0' {
			pos = append(pos, i)
		}
	}
	res := 0
	for i := 0; i < len(pos)-1; i++ {
		if pos[i] == pos[i+1]-1 {
			res += 2
			continue
		}
		if pos[i] == pos[i+1]-2 {
			res += 1
			continue
		}
	}
	printf("%d\n", res)
}

package main

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

func readInt(in *bufio.Reader) int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.Atoi(nStr)
	return n
}
func readInt64(in *bufio.Reader) int64 {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	n, _ := strconv.ParseInt(nStr, 10, 64)
	return n
}
func readLineNumbs(in *bufio.Reader) []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	numbs := strings.Split(line, " ")
	return numbs
}

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

func main() {
	ip := bufio.NewReader(os.Stdin)
	t := readInt(ip)
	for t > 0 {
		t--
		n := readInt(ip)
		s, _ := ip.ReadString('\n')
		ans := 0
		for i := 0; i < n; {
			if s[i] == '0' {
				if i < n-1 && s[i+1] == '0' {
					ans += 2
				} else if i < n-2 && s[i+2] == '0' {
					ans++
					i++
				}
			}
			i++
		}
		fmt.Println(ans)
	}
}


This is the easy version of the problem. The difference is the constraints on $$$n$$$, $$$m$$$ and $$$t$$$. You can make hacks only if all versions of the problem are solved.Alice and Bob are given the numbers $$$n$$$, $$$m$$$ and $$$k$$$, and play a game as follows:The game has a score that Alice tries to maximize, and Bob tries to minimize. The score is initially $$$0$$$. The game consists of $$$n$$$ turns. Each turn, Alice picks a real number from $$$0$$$ to $$$k$$$ (inclusive) which Bob either adds to or subtracts from the score of the game. But throughout the game, Bob has to choose to add at least $$$m$$$ out of the $$$n$$$ turns.Bob gets to know which number Alice picked before deciding whether to add or subtract the number from the score, and Alice gets to know whether Bob added or subtracted the number for the previous turn before picking the number for the current turn (except on the first turn since there was no previous turn).If Alice and Bob play optimally, what will the final score of the game be?

The first line of the input contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. Each test case consists of a single line containing the three integers, $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \le m \le n \le 2000, 0 \le k < 10^9 + 7$$$) — the number of turns, how many of those turns Bob has to add, and the biggest number Alice can choose, respectively. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case output a single integer number — the score of the optimal game modulo $$$10^9 + 7$$$. Formally, let $$$M = 10^9 + 7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x < M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.

NoteIn the first test case, the entire game has $$$3$$$ turns, and since $$$m = 3$$$, Bob has to add in each of them. Therefore Alice should pick the biggest number she can, which is $$$k = 2$$$, every turn.In the third test case, Alice has a strategy to guarantee a score of $$$\frac{75}{8} \equiv 375000012 \pmod{10^9 + 7}$$$.In the fourth test case, Alice has a strategy to guarantee a score of $$$\frac{45}{2} \equiv 500000026 \pmod{10^9 + 7}$$$.

package main

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

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

func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...); out.Flush() }

const MOD = int(1e9 + 7)

func ExtendedGcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := ExtendedGcd(b, a%b)
	return d, y, (x - (a/b)*y)
}

func Add(a, b int) int {
	return (a + b) % MOD
}

func Mul(a, b int) int {
	return int((int64(a) * int64(b)) % int64(MOD))
}

func Neg(a int) int {
	return (MOD - a) % MOD
}

func Inv(a int) int {
	_, x, _ := ExtendedGcd(a, MOD)
	// x*a + y*MOD = 1
	return ((x % MOD) + MOD) % MOD
}

func solveCase() int {
	var n, m, k int
	scan(&n, &m, &k)
	m = n - m

	var dp = make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+2)
	}
	for i := 1; i <= n; i++ {
		dp[i][0] = i
	}
	for i := 2; i <= n; i++ {
		for j := 1; j <= m; j++ {
			dp[i][j] = Mul(Add(dp[i-1][j], dp[i-1][j-1]), Inv(2))
		}
	}
	return Mul(dp[n][m], k)
}

func main() {
	defer out.Flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		printf("%d\n", solveCase())
	}
}

package main

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

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

func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...); out.Flush() }

const MOD = int(1e9 + 7)

func ExtendedGcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := ExtendedGcd(b, a%b)
	return d, y, (x - (a/b)*y)
}

func Add(a, b int) int {
	return (a + b) % MOD
}

func Mul(a, b int) int {
	return int((int64(a) * int64(b)) % int64(MOD))
}

func Neg(a int) int {
	return (MOD - a) % MOD
}

func Inv(a int) int {
	_, x, _ := ExtendedGcd(a, MOD)
	// x*a + y*MOD = 1
	return ((x % MOD) + MOD) % MOD
}

func solveCase() int {
	var n, m, k int
	scan(&n, &m, &k)

	var dp = make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+2)
	}
	for i := 1; i <= n; i++ {
		dp[i][0] = i
	}
	for i := 2; i <= n; i++ {
		for j := 1; j <= m; j++ {
			dp[i][j] = Mul(Add(dp[i-1][j], dp[i-1][j-1]), Inv(2))
		}
	}
	return Mul(dp[n][m], k)
}

func main() {
	defer out.Flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		printf("%d\n", solveCase())
	}
}


While Farmer John rebuilds his farm in an unfamiliar portion of Bovinia, Bessie is out trying some alternative jobs. In her new gig as a reporter, Bessie needs to know about programming competition results as quickly as possible. When she covers the 2016 Robot Rap Battle Tournament, she notices that all of the robots operate under deterministic algorithms. In particular, robot i will beat robot j if and only if robot i has a higher skill level than robot j. And if robot i beats robot j and robot j beats robot k, then robot i will beat robot k. Since rapping is such a subtle art, two robots can never have the same skill level.Given the results of the rap battles in the order in which they were played, determine the minimum number of first rap battles that needed to take place before Bessie could order all of the robots by skill level.

The first line of the input consists of two integers, the number of robots n (2 ≤ n ≤ 100 000) and the number of rap battles m (). The next m lines describe the results of the rap battles in the order they took place. Each consists of two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi), indicating that robot ui beat robot vi in the i-th rap battle. No two rap battles involve the same pair of robots. It is guaranteed that at least one ordering of the robots satisfies all m relations.

Print the minimum k such that the ordering of the robots by skill level is uniquely defined by the first k rap battles. If there exists more than one ordering that satisfies all m relations, output -1.

NoteIn the first sample, the robots from strongest to weakest must be (4, 2, 1, 3), which Bessie can deduce after knowing the results of the first four rap battles.In the second sample, both (1, 3, 2) and (3, 1, 2) are possible orderings of the robots from strongest to weakest after both rap battles.

package main

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

func main() {
	defer out.Flush()
	n := in.NextInt()
	m := in.NextInt()
	inDeg := make([]int, n)
	edges := make([][]int, n)
	inputs := make([]Line, m)
	for i := range inputs {
		a := in.NextInt() - 1
		b := in.NextInt() - 1
		inputs[i] = Line{a, b}
		edges[a] = append(edges[a], b)
		inDeg[b]++
	}

	root := -1
	for i := range inDeg {
		if inDeg[i] == 0 {
			if root != -1 {
				fmt.Fprintln(out, -1)
				return
			}
			root = i
		}
	}

	next := make([]int, n)
	for root != -1 {
		nextRoot := -1
		for _, u := range edges[root] {
			inDeg[u]--
			if inDeg[u] == 0 {
				if nextRoot != -1 {
					fmt.Fprintln(out, -1)
					return
				}
				nextRoot = u
			}
		}
		next[root] = nextRoot
		root = nextRoot
	}

	for i := range inDeg {
		if inDeg[i] != 0 {
			fmt.Fprintln(out, -1)
			return
		}
	}

	k := 0
	for i := range inputs {
		a := inputs[i].a
		b := inputs[i].b
		if next[a] == b {
			k++
			if k == n-1 {
				fmt.Fprintln(out, i+1)
				return
			}
		}
	}

	fmt.Fprintln(out, -1)
}

type Line struct {
	a, b int
}

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

type FastReader struct {
	r   *bufio.Reader
	buf string
}

func NewFastReader(r io.Reader) *FastReader {
	return &FastReader{
		r: bufio.NewReader(r),
	}
}

func (r *FastReader) advance() {
	for len(r.buf) != 0 && r.buf[0] == ' ' {
		r.buf = r.buf[1:]
	}
	for len(r.buf) == 0 {
		var buf bytes.Buffer
		for {
			chunk, more, _ := r.r.ReadLine()
			buf.Write(chunk)
			if !more {
				break
			}
		}
		r.buf = buf.String()
	}
}

func (r *FastReader) NextLine() string {
	r.advance()
	line := r.buf
	r.buf = ""
	return line
}

func (r *FastReader) NextWord() string {
	r.advance()
	var word string
	wordStart := 0
	for i := 0; i < len(r.buf); i++ {
		b := r.buf[i]
		if b == ' ' {
			if i != wordStart {
				word = r.buf[wordStart:i]
				r.buf = r.buf[i:]
				break
			}
			wordStart = i + 1
		}
	}
	if len(word) == 0 {
		word = r.buf
		r.buf = ""
	}
	return word
}

func (r *FastReader) NextInt() int {
	return parseInt(r.NextWord())
}

func parseInt(word string) int {
	sign := 1
	if word[0] == '-' {
		sign = -1
		word = word[1:]
	}
	result := 0
	for i := 0; i < len(word); i++ {
		result = result*10 + int(word[i]) - '0'
	}
	result *= sign
	return result
}

package main

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

type Pair struct {
	first,second int
}

const MAXN = 100006

var edges [MAXN][] Pair
var vis [MAXN] bool
var cur int
var ord[MAXN] int

func ini(N int) {
	var i int
	var emp[] Pair
	for i=1; i<=N; i++ {
		vis[i] = false
		edges[i] = emp
	}
	cur = N
}

func dfs(node int) {
	if vis[node] == true {return}
	vis[node] = true
	length := len(edges[node])
	for i:=0; i<length; i++ {
		dfs(edges[node][i].first)
	}
	ord[cur] = node
	cur--
}

func check(node,now int) int {
	length := len(edges[node])
	for i:=0; i<length; i++ {
		if edges[node][i].first == now {return edges[node][i].second}
	}
	return -1
}

func main() {
	var N,M,ans int
	var u,v,i int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &N)
	fmt.Fscan(in, &M)
	ini(N)
	for m:=1; m<=M; m++ {
		fmt.Fscan(in, &u)
		fmt.Fscan(in, &v)
		edges[u] = append(edges[u],Pair{v,m})
	}
	for i=1; i<=N; i++ {
		dfs(i)
	}
	ans = -1
	for i=2; i<=N; i++ {
		u = check(ord[i-1],ord[i])
		if u == -1 {break}
		if u > ans {ans = u}
	}
	if i<=N { ans = -1 }
	fmt.Printf("%d\n", ans)
}


After watching a certain anime before going to sleep, Mark dreams of standing in an old classroom with a blackboard that has a sequence of $$$n$$$ positive integers $$$a_1, a_2,\dots,a_n$$$ on it.Then, professor Koro comes in. He can perform the following operation:  select an integer $$$x$$$ that appears at least $$$2$$$ times on the board,  erase those $$$2$$$ appearances, and  write $$$x+1$$$ on the board. Professor Koro then asks Mark the question, "what is the maximum possible number that could appear on the board after some operations?"Mark quickly solves this question, but he is still slower than professor Koro. Thus, professor Koro decides to give Mark additional challenges. He will update the initial sequence of integers $$$q$$$ times. Each time, he will choose positive integers $$$k$$$ and $$$l$$$, then change $$$a_k$$$ to $$$l$$$. After each update, he will ask Mark the same question again.Help Mark answer these questions faster than Professor Koro!Note that the updates are persistent. Changes made to the sequence $$$a$$$ will apply when processing future updates.

The first line of the input contains two integers $$$n$$$ and $$$q$$$ ($$$2\leq n\leq 2\cdot 10^5$$$, $$$1\leq q\leq 2\cdot 10^5$$$) — the length of the sequence $$$a$$$ and the number of updates, respectively. The second line contains $$$n$$$ integers $$$a_1,a_2,\dots,a_n$$$ ($$$1\leq a_i\leq 2\cdot 10^5$$$) Then, $$$q$$$ lines follow, each consisting of two integers $$$k$$$ and $$$l$$$ ($$$1\leq k\leq n$$$, $$$1\leq l\leq 2\cdot 10^5$$$), telling to update $$$a_k$$$ to $$$l$$$.

Print $$$q$$$ lines. The $$$i$$$-th line should consist of a single integer — the answer after the $$$i$$$-th update.

NoteIn the first example test, the program must proceed through $$$4$$$ updates.The sequence after the first update is $$$[2,3,2,4,5]$$$. One sequence of operations that achieves the number $$$6$$$ the following.   Initially, the blackboard has numbers $$$[2,3,2,4,5]$$$.  Erase two copies of $$$2$$$ and write $$$3$$$, yielding $$$[3,4,5,\color{red}{3}]$$$.  Erase two copies of $$$3$$$ and write $$$4$$$, yielding $$$[4,5,\color{red}{4}]$$$.  Erase two copies of $$$4$$$ and write $$$5$$$, yielding $$$[5,\color{red}{5}]$$$.  Erase two copies of $$$5$$$ and write $$$6$$$, yielding $$$[\color{red}{6}]$$$. Then, in the second update, the array is changed to $$$[2,3,2,4,3]$$$. This time, Mark cannot achieve $$$6$$$. However, one sequence that Mark can use to achieve $$$5$$$ is shown below.   Initially, the blackboard has $$$[2,3,2,4,3]$$$.  Erase two copies of $$$2$$$ and write $$$3$$$, yielding $$$[3,4,3,\color{red}{3}]$$$.  Erase two copies of $$$3$$$ and write $$$4$$$, yielding $$$[3,4,\color{red}{4}]$$$.  Erase two copies of $$$4$$$ and write $$$5$$$, yielding $$$[3,\color{red}{5}]$$$. In the third update, the array is changed to $$$[2,3,2,1,3]$$$. One way to achieve $$$4$$$ is shown below.   Initially, the blackboard has $$$[2,3,2,1,3]$$$.  Erase two copies of $$$3$$$ and write $$$4$$$, yielding $$$[2,2,1,\color{red}{4}]$$$.

package main

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

// github.com/EndlessCheng/codeforces-go
type seg []struct {
	l, r  int
	state int8
	flip  bool
}

func (t seg) maintain(o int) {
	x, y := t[o<<1].state, t[o<<1|1].state
	if x < 0 && y < 0 {
		t[o].state = -1
	} else if x > 0 && y > 0 {
		t[o].state = 1
	} else {
		t[o].state = 0
	}
}

func (t seg) build(o, l, r int) {
	t[o].l, t[o].r, t[o].state = l, r, -1
	if l == r {
		return
	}
	m := (l + r) >> 1
	t.build(o<<1, l, m)
	t.build(o<<1|1, m+1, r)
}

func (t seg) do(o int) {
	t[o].state = -t[o].state
	t[o].flip = !t[o].flip
}

func (t seg) spread(o int) {
	if t[o].flip {
		t.do(o << 1)
		t.do(o<<1 | 1)
		t[o].flip = false
	}
}

func (t seg) flip(o, l, r int) {
	if l <= t[o].l && t[o].r <= r {
		t.do(o)
		return
	}
	t.spread(o)
	m := (t[o].l + t[o].r) >> 1
	if l <= m {
		t.flip(o<<1, l, r)
	}
	if m < r {
		t.flip(o<<1|1, l, r)
	}
	t.maintain(o)
}

func (t seg) next0(o, l int) int {
	if t[o].l == t[o].r {
		if t[o].state < 0 {
			return t[o].l
		}
		return 0
	}
	t.spread(o)
	m := (t[o].l + t[o].r) >> 1
	if l <= m && t[o<<1].state <= 0 {
		if p := t.next0(o<<1, l); p > 0 {
			return p
		}
	}
	return t.next0(o<<1|1, l)
}

func (t seg) next1(o, l int) int {
	if t[o].l == t[o].r {
		if t[o].state > 0 {
			return t[o].l
		}
		return 0
	}
	t.spread(o)
	m := (t[o].l + t[o].r) >> 1
	if l <= m && t[o<<1].state >= 0 {
		if p := t.next1(o<<1, l); p > 0 {
			return p
		}
	}
	return t.next1(o<<1|1, l)
}

func (t seg) last1(o int) int {
	if t[o].l == t[o].r {
		return t[o].l
	}
	t.spread(o)
	if t[o<<1|1].state >= 0 {
		return t.last1(o<<1 | 1)
	}
	return t.last1(o << 1)
}

func CF1705E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mx int = 2e5 + 20

	var n, q, i, v int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	t := make(seg, mx*4)
	t.build(1, 1, mx)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		t.flip(1, a[i], t.next0(1, a[i]))
	}
	for ; q > 0; q-- {
		Fscan(in, &i, &v)
		t.flip(1, a[i], t.next1(1, a[i]))
		a[i] = v
		t.flip(1, v, t.next0(1, v))
		Fprintln(out, t.last1(1))
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
type seg []struct {
	l, r  int
	state int8
	flip  bool
}

func (t seg) maintain(o int) {
	x, y := t[o<<1].state, t[o<<1|1].state
	if x < 0 && y < 0 {
		t[o].state = -1
	} else if x > 0 && y > 0 {
		t[o].state = 1
	} else {
		t[o].state = 0
	}
}

func (t seg) build(o, l, r int) {
	t[o].l, t[o].r, t[o].state = l, r, -1
	if l == r {
		return
	}
	m := (l + r) >> 1
	t.build(o<<1, l, m)
	t.build(o<<1|1, m+1, r)
}

func (t seg) do(o int) {
	t[o].state = -t[o].state
	t[o].flip = !t[o].flip
}

func (t seg) spread(o int) {
	if t[o].flip {
		t.do(o << 1)
		t.do(o<<1 | 1)
		t[o].flip = false
	}
}

func (t seg) flip(o, l, r int) {
	if l <= t[o].l && t[o].r <= r {
		t.do(o)
		return
	}
	t.spread(o)
	m := (t[o].l + t[o].r) >> 1
	if l <= m {
		t.flip(o<<1, l, r)
	}
	if m < r {
		t.flip(o<<1|1, l, r)
	}
	t.maintain(o)
}

func (t seg) next0(o, l int) int {
	if t[o].l == t[o].r {
		if t[o].state < 0 {
			return t[o].l
		}
		return 0
	}
	t.spread(o)
	m := (t[o].l + t[o].r) >> 1
	if l <= m && t[o<<1].state <= 0 {
		if p := t.next0(o<<1, l); p > 0 {
			return p
		}
	}
	return t.next0(o<<1|1, l)
}

func (t seg) next1(o, l int) int {
	if t[o].l == t[o].r {
		if t[o].state > 0 {
			return t[o].l
		}
		return 0
	}
	t.spread(o)
	m := (t[o].l + t[o].r) >> 1
	if l <= m && t[o<<1].state >= 0 {
		if p := t.next1(o<<1, l); p > 0 {
			return p
		}
	}
	return t.next1(o<<1|1, l)
}

func (t seg) last1(o int) int {
	if t[o].l == t[o].r {
		return t[o].l
	}
	t.spread(o)
	if t[o<<1|1].state >= 0 {
		return t.last1(o<<1 | 1)
	}
	return t.last1(o << 1)
}

func CF1705E(_r io.Reader, _w io.Writer) {
	out := bufio.NewWriter(_w)
	defer out.Flush()
	buf := make([]byte, 1<<12)
	_i := len(buf)
	rc := func() byte {
		if _i >= len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		for ; '0' > b; b = rc() {
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		return
	}

	n, q := r(), r()
	a := make([]int, n+1)
	t := make(seg, (2e5+20)*4)
	t.build(1, 1, 2e5+20)
	for i := 1; i <= n; i++ {
		a[i] = r()
		t.flip(1, a[i], t.next0(1, a[i]))
	}
	for ; q > 0; q-- {
		i, v := r(), r()
		t.flip(1, a[i], t.next1(1, a[i]))
		a[i] = v
		t.flip(1, v, t.next0(1, v))
		Fprintln(out, t.last1(1))
	}
}

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

package main

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

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

	var buf bytes.Buffer

	n, m := readTwoNums(reader)
	A := readNNums(reader, n)
	ques := make([][]int, m)
	for i := 0; i < m; i++ {
		ques[i] = readNNums(reader, 2)
	}
	res := solve(A, ques)

	for _, ans := range res {
		buf.WriteString(fmt.Sprintf("%d\n", ans))
	}

	fmt.Print(buf.String())
}

func readString(reader *bufio.Reader) string {
	s, _ := reader.ReadString('\n')
	for i := 0; i < len(s); i++ {
		if s[i] == '\n' || s[i] == '\r' {
			return s[:i]
		}
	}
	return s
}

func normalize(s string) string {

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

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

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

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

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

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

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

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

	return i
}

func readNInt64s(reader *bufio.Reader, n int) []int64 {
	res := make([]int64, n)
	s, _ := reader.ReadBytes('\n')

	var pos int

	for i := 0; i < n; i++ {
		pos = readInt64(s, pos, &res[i]) + 1
	}

	return res
}

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

const MAX_A = 200100

type Node struct {
	left, right *Node
	start, end  int
	tag         int
	val         int
	lazy        bool
}

func NewNode(start int, end int) *Node {
	node := new(Node)
	node.start = start
	node.end = end
	node.tag = 0
	node.val = 0
	node.lazy = false
	if start < end {
		mid := (start + end) / 2
		node.left = NewNode(start, mid)
		node.right = NewNode(mid+1, end)
	}
	return node
}

func (node *Node) push() {
	if !node.lazy {
		return
	}

	node.val = (node.end - node.start + 1) * node.tag

	if node.start == node.end {
		return
	}

	node.left.lazy = node.lazy
	node.left.tag = node.tag
	node.right.lazy = node.lazy
	node.right.tag = node.tag
	node.tag = 0
	node.lazy = false
}

func (node *Node) Update(start int, end int, x int) {
	node.push()
	if node.end < start || end < node.start {
		// out of bound
		return
	}
	if start <= node.start && node.end <= end {
		node.tag = x
		node.lazy = true
		node.push()
	} else {
		node.left.Update(start, end, x)
		node.right.Update(start, end, x)
		node.val = node.left.val + node.right.val
	}
}

func (node *Node) Query(start int, end int) int {
	if node.end < start || end < node.start {
		return 0
	}
	node.push()

	if start <= node.start && node.end <= end {
		return node.val
	}

	if node.left == nil {
		return 0
	}

	return node.left.Query(start, end) + node.right.Query(start, end)
}

// pre = prefix_sum([0...k))
func (node *Node) max_right(k int, pre int, v int) int {
	node.push()

	if node.start == node.end {
		if node.val == v {
			return node.start
		}
		return node.start - 1
	}

	node.left.push()

	mid := (node.start + node.end) / 2
	if mid < k {
		return node.right.max_right(k, pre-node.left.val, v)
	}
	if node.left.val-pre == v*(mid+1-k) {
		return node.right.max_right(mid+1, 0, v)
	}

	return node.left.max_right(k, pre, v)
}

func (node *Node) get_answer() int {
	node.push()
	if node.start == node.end {
		if node.val == 1 {
			return node.start
		}
		return node.start - 1
	}

	node.right.push()

	if node.right.val == 0 {
		return node.left.get_answer()
	}

	return node.right.get_answer()
}

func solve(A []int, queries [][]int) []int {
	root := NewNode(0, MAX_A)

	add := func(x int) {
		// x 右边连续1的位置
		y := root.max_right(x, root.Query(0, x-1), 1) + 1
		if x == y {
			root.Update(x, x, 1)
		} else {
			root.Update(x, y-1, 0)
			root.Update(y, y, 1)
		}
	}

	remove := func(x int) {
		y := root.max_right(x, root.Query(0, x-1), 0) + 1
		if x == y {
			root.Update(x, x, 0)
		} else {
			root.Update(x, y-1, 1)
			root.Update(y, y, 0)
		}
	}

	for i := 0; i < len(A); i++ {
		add(A[i])
	}

	ans := make([]int, len(queries))

	for i, cur := range queries {
		k, l := cur[0], cur[1]
		k--
		remove(A[k])
		add(l)
		A[k] = l
		ans[i] = root.get_answer()
	}
	return ans
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

// github.com/EndlessCheng/codeforces-go
const w = bits.UintSize

var b [6253]uint

func flip(l, r int) {
	r++
	maskL, maskR := ^uint(0)<<(l%w), ^uint(0)<<(r%w)
	i := l / w
	if i == r/w {
		b[i] ^= maskL ^ maskR
		return
	}
	b[i] ^= maskL
	for i++; i < r/w; i++ {
		b[i] = ^b[i]
	}
	b[i] ^= ^maskR
}

func next0(p int) int {
	i := p / w
	v := b[i]
	if p%w > 0 {
		v |= ^(^uint(0) << (p % w))
	}
	if ^v != 0 {
		return i*w | bits.TrailingZeros(^v)
	}
	for i++; ; i++ {
		if ^b[i] != 0 {
			return i*w | bits.TrailingZeros(^b[i])
		}
	}
}

func next1(p int) int {
	i := p / w
	v := b[i] & (^uint(0) << (p % w))
	if v != 0 {
		return i*w | bits.TrailingZeros(v)
	}
	for i++; ; i++ {
		if b[i] != 0 {
			return i*w | bits.TrailingZeros(b[i])
		}
	}
}

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

	var n, q, i, v int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		flip(a[i], next0(a[i]))
	}
	for ; q > 0; q-- {
		Fscan(in, &i, &v)
		flip(a[i], next1(a[i]))
		a[i] = v
		flip(v, next0(v))
		for i := len(b) - 1; i >= 0; i-- {
			if b[i] != 0 {
				Fprintln(out, i*w|bits.Len(b[i])-1)
				break
			}
		}
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"os"
)

// github.com/EndlessCheng/codeforces-go
const w = bits.UintSize

var b [6253]uint

func flip(l, r int) {
	r++
	maskL, maskR := ^uint(0)<<(l%w), ^uint(0)<<(r%w)
	i := l / w
	if i == r/w {
		b[i] ^= maskL ^ maskR
		return
	}
	b[i] ^= maskL
	for i++; i < r/w; i++ {
		b[i] = ^b[i]
	}
	b[i] ^= maskR
}

func next0(p int) int {
	i := p / w
	v := b[i]
	if p%w > 0 {
		v |= ^(^uint(0) << (p % w))
	}
	if ^v != 0 {
		return i*w | bits.TrailingZeros(^v)
	}
	for i++; ; i++ {
		if ^b[i] != 0 {
			return i*w | bits.TrailingZeros(^b[i])
		}
	}
}

func next1(p int) int {
	i := p / w
	v := b[i] & (^uint(0) << (p % w))
	if v != 0 {
		return i*w | bits.TrailingZeros(v)
	}
	for i++; ; i++ {
		if b[i] != 0 {
			return i*w | bits.TrailingZeros(b[i])
		}
	}
}

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

	var n, q, i, v int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
		flip(a[i], next0(a[i]))
	}
	for ; q > 0; q-- {
		Fscan(in, &i, &v)
		flip(a[i], next1(a[i]))
		a[i] = v
		flip(v, next0(v))
		for i := len(b) - 1; i >= 0; i-- {
			if b[i] != 0 {
				Fprintln(out, i*w|bits.Len(b[i])-1)
				break
			}
		}
	}
}

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


There is a graph of $$$n$$$ rows and $$$10^6 + 2$$$ columns, where rows are numbered from $$$1$$$ to $$$n$$$ and columns from $$$0$$$ to $$$10^6 + 1$$$:  Let's denote the node in the row $$$i$$$ and column $$$j$$$ by $$$(i, j)$$$.Initially for each $$$i$$$ the $$$i$$$-th row has exactly one obstacle — at node $$$(i, a_i)$$$. You want to move some obstacles so that you can reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph (you can't pass through obstacles). Moving one obstacle to an adjacent by edge free node costs $$$u$$$ or $$$v$$$ coins, as below:  If there is an obstacle in the node $$$(i, j)$$$, you can use $$$u$$$ coins to move it to $$$(i-1, j)$$$ or $$$(i+1, j)$$$, if such node exists and if there is no obstacle in that node currently.  If there is an obstacle in the node $$$(i, j)$$$, you can use $$$v$$$ coins to move it to $$$(i, j-1)$$$ or $$$(i, j+1)$$$, if such node exists and if there is no obstacle in that node currently.  Note that you can't move obstacles outside the grid. For example, you can't move an obstacle from $$$(1,1)$$$ to $$$(0,1)$$$. Refer to the picture above for a better understanding. Now you need to calculate the minimal number of coins you need to spend to be able to reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph without passing through obstacles.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$u$$$ and $$$v$$$ ($$$2 \le n \le 100$$$, $$$1 \le u, v \le 10^9$$$) — the number of rows in the graph and the numbers of coins needed to move vertically and horizontally respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — where $$$a_i$$$ represents that the obstacle in the $$$i$$$-th row is in node $$$(i, a_i)$$$. It's guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^4$$$.

For each test case, output a single integer — the minimal number of coins you need to spend to be able to reach node $$$(n, 10^6+1)$$$ from node $$$(1, 0)$$$ by moving through edges of this graph without passing through obstacles. It can be shown that under the constraints of the problem there is always a way to make such a trip possible.

NoteIn the first sample, two obstacles are at $$$(1, 2)$$$ and $$$(2,2)$$$. You can move the obstacle on $$$(2, 2)$$$ to $$$(2, 3)$$$, then to $$$(1, 3)$$$. The total cost is $$$u+v = 7$$$ coins.  In the second sample, two obstacles are at $$$(1, 3)$$$ and $$$(2,2)$$$. You can move the obstacle on $$$(1, 3)$$$ to $$$(2, 3)$$$. The cost is $$$u = 3$$$ coins.

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, u, v := getI(), getI(), getI()
	a := getInts(n)

	var res int64
	for i := int64(1); i < n; i++ {
		cur := abs(a[i] - a[i-1])
		if cur > res {
			res = cur
		}
	}

	if res > 1 {
		out(0)
	} else if res == 1 {
		out(min(u, v))
	} else {
		out(v + min(u, v))
	}
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		var u, v int64
		_, _ = fmt.Fscan(in, &n, &u, &v)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &a[i])
		}

		firstCheck := true
		for i := 1; i < n; i++ {
			if a[i-1] != a[i] {
				firstCheck = false
			}
		}

		ans := int64(0)

		if firstCheck {
			ans = v
			if v < u {
				ans += v
			} else {
				ans += u
			}
		} else {
			secondCheck := true
			for i := 1; i < n; i++ {
				if !(((a[i] - a[i-1]) <= 1) && ((a[i] - a[i-1]) >= -1)) {
					secondCheck = false
				}
			}
			if secondCheck {
				if v < u {
					ans += v
				} else {
					ans += u
				}
			}
		}
		fmt.Println(ans)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1491B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	var T, n, ud, lr int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &ud, &lr)
		a := make([]int, n)
		d := 0
		for i := range a {
			if Fscan(in, &a[i]); i > 0 && abs(a[i]-a[i-1]) > d {
				d = abs(a[i] - a[i-1])
			}
		}
		if d > 1 {
			Fprintln(out, 0)
		} else if d == 1 {
			Fprintln(out, min(ud, lr))
		} else {
			Fprintln(out, lr+min(ud, lr))
		}
	}
}

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

package main

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

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

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

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

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

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		u := sint64()
		v := sint64()
		a := sint64s(n)
		printf("%d\n", sol(n, u, v, a))
	}
}

func sol(n, u, v int64, a []int64) int64 {
	d := maxDelta(a)
	if d == 0 {
		return min(v+v, u+v)
	}
	if d == 1 {
		return min(u, v)
	}
	if d > 1 {
		return 0
	}
	panic("unexpected count")
}

func maxDelta(a []int64) int64 {
	maxD := int64(0)
	for i := range a {
		if i == 0 {
			continue
		}
		maxD = max(maxD, abs(a[i]-a[i-1]))
	}
	return maxD
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

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

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

package main

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

func min(a int, rest ...int) int {
	for _, v := range rest {
		if v < a {
			a = v
		}
	}
	return a
}

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

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

		tot := math.MaxInt32
		for i := 1; i < n; i++ {
			d := abs(aa[i] - aa[i-1])
			if d >= 2 {
				tot = 0
				break
			} else if d == 1 {
				tot = min(tot, u, v)
			} else {
				tot = min(tot, v+min(u, v))
			}
		}

		fmt.Fprintln(out, tot)
	}
}

package main
import "fmt"
func main() {
	const Inf int = int(^uint(0)  >> 1)
	var tc int
	fmt.Scanln(&tc)
	for t:=0;t < tc;t++ {
		var n int
		var u int
		var v int
		var arr []int
		var minCost int
		minCost = Inf
		fmt.Scanln(&n, &u, &v)
		arr = make([]int,n)
		for i:=0;i < n;i++ {
			if i==n-1{
				fmt.Scanln(&arr[i])
			} else {
				fmt.Scan(&arr[i])
			}
		}
		for i:=1;i < n;i++{
			if abs(arr[i]-arr[i-1]) >= 2 {
				minCost = 0
			} else if abs(arr[i]-arr[i-1]) == 1 {
				minCost = min(minCost, min(u,v))
			} else if arr[i]==arr[i-1] {
				minCost = min(minCost, v+min(u,v))
			}

		}
		fmt.Println(minCost)
	}
}
func min (a int, b int) int {
	if a <= b {
		return a
	} else {
		return b
	}
}
func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

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 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 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
		var u int
		var v int
		fmt.Fscan(input, &n)
		fmt.Fscan(input, &u)
		fmt.Fscan(input, &v)

		// STRING := make([]byte, 0)
		// fmt.Fscan(input, &STRING)
		ARRAY := make([]int, n+1)

		for i := 1; i < n+1; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		tru := 0
		trumax := 0
		for i := 1; i < n; i++ {
			m := MAX(ARRAY[i], ARRAY[i+1]) - MIN(ARRAY[i], ARRAY[i+1])
			if m > 1 {
				trumax = 1
			} else {
				if m == 1 {
					tru = 1
				}
			}

		}

		if trumax == 1 {
			fmt.Println(0)
		} else {
			if tru == 1 {
				fmt.Println(MIN(v, u))
			} else {
				fmt.Println(int64(MIN(v, u)) + int64(v))
			}
		}

	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, u, v := getI(), getI(), getI()
	a := getInts(n)
	movesU := u * 2
	movesV := v * 2
	movesUV := u*2 + v*2
	for i := int64(0); i < n-1; i++ {
		if a[i] != a[i+1] {
			movesU = 1
			if i-2 >= 0 || i+2 < n {
				movesV = 1
			}
		} else {
			if i-2 >= 0 || i+2 < n {
				movesV = min(movesV, 2)
			}
			movesUV = min(movesUV, 1)
		}
	}

	res := nmin(movesU*u, movesV*v, movesUV*u+movesUV*v)
	out(res)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, u, v := getI(), getI(), getI()
	a := getInts(n)
	movesU := u * 2
	movesV := v * 2
	movesUV := u*2 + v*2
	for i := int64(0); i < n-1; i++ {
		if a[i] != a[i+1] {
			movesU = 1
			movesV = 1
			break
		} else {
			if i-2 >= 0 || i+2 < n {
				movesV = min(movesV, 2)
			}
			movesUV = min(movesUV, 1)
		}
	}

	res := nmin(movesU*u, movesV*v, movesUV*u+movesUV*v)
	out(res)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, u, v := getI(), getI(), getI()
	a := getInts(n)
	movesU := u * 2
	movesV := v * 2
	movesUV := u*2 + v*2
	for i := int64(0); i < n-1; i++ {
		if a[i] != a[i+1] {
			movesU = 1
			movesV = 1
			break
		} else {
			if i+2 < n && a[i+2] != a[i+1] {
				movesU = 1
			} else {
				movesV = min(movesU, 2)
				movesUV = min(movesUV, 1)
			}
		}
	}

	res := nmin(movesU*u, movesV*v, movesUV*u+movesUV*v)
	out(res)
}

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

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

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

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func nsort(data ...int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		var u, v int64
		_, _ = fmt.Fscan(in, &n, &u, &v)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &a[i])
		}

		firstCheck := true
		for i := 1; i < n; i++ {
			if a[i-1] != a[i] {
				firstCheck = false
			}
		}

		ans := int64(0)

		if firstCheck {
			ans = v
			if v < u {
				ans += v
			} else {
				ans += u
			}
		} else {
			for i := 1; i < n; i++ {
				if ((a[i] - a[i-1]) <= 1) && ((a[i] - a[i-1]) >= -1) {
					if v < u {
						ans += v
					} else {
						ans += u
					}
				}
			}
		}

		fmt.Println(ans)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1491B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}

	var T, n, ud, lr int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &ud, &lr)
		a := make([]int, n)
		d := 2
		for i := range a {
			if Fscan(in, &a[i]); i > 0 {
				d = min(d, abs(a[i]-a[i-1]))
			}
		}
		if d > 1 {
			Fprintln(out, 0)
		} else if d == 1 {
			Fprintln(out, min(ud, lr))
		} else {
			Fprintln(out, lr+min(ud, lr))
		}
	}
}

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

package main

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

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

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

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

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

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		u := sint64()
		v := sint64()
		a := sint64s(n)
		printf("%d\n", sol(n, u, v, a))
	}
}

func sol(n, u, v int64, a []int64) int64 {
	c := count(a)
	if c == 1 {
		return min(v+v, u+v)
	}
	if count(a) > 2 {
		return 0
	}
	return min(u, v)
}

func count(a []int64) int64 {
	set := map[int64]bool{}
	for i := range a {
		set[a[i]] = true
	}
	return int64(len(set))
}

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

package main

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

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

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

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

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

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		n := sint64()
		u := sint64()
		v := sint64()
		a := sint64s(n)
		printf("%d\n", sol(n, u, v, a))
	}
}

func sol(n, u, v int64, a []int64) int64 {
	if allSame(a) {
		return min(v+v, u+v)
	}
	return min(u, v)
}

func allSame(a []int64) bool {
	tmp := a[0]
	for _, i := range a {
		if i != tmp {
			return false
		}
	}
	return true
}

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


You are given two integers $$$a$$$ and $$$b$$$. Print $$$a+b$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is given as a line of two integers $$$a$$$ and $$$b$$$ ($$$-1000 \le a, b \le 1000$$$).

Print $$$t$$$ integers — the required numbers $$$a+b$$$.

 package main

 import (
         "fmt"
 )

 func main() {

         t := 0
         fmt.Scanf("%d\n", &t)
         for i := 0; i < t; i++ {
             var a,b int
             fmt.Scanf("%d %d\n", &a,&b)
             fmt.Println(a+b)

        }
 }

// Problem statement can be found in
// https://codeforces.com/problemset/problem/1351/A

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for i:=0; i < t ; i++ {
		var a, b int
		fmt.Scan(&a, &b)

		fmt.Println(a+b)
	}
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		fmt.Println(a + b)
	}

}

// https://codeforces.com/contest/1348/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var a, b int
	fmt.Fscan(input, &a, &b)

	fmt.Println(a + b)
}

package main
import ."fmt"
//github.com/EndlessCheng/codeforces-go
func main(){var t,a,b int;for Scan(&t);t>0;t--{Scan(&a,&b);Println(a+b)}}

package main

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

func main() {
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			os.Stdin.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		neg := false
		for ; '0' > b || b > '9'; b = rc() {
			if b == '-' {
				neg = true
			}
		}
		for ; '0' <= b && b <= '9'; b = rc() {
			x = x*10 + int(b&15)
		}
		if neg {
			return -x
		}
		return
	}
	for t := r(); t > 0; t-- {
		Fprintln(out, r()+r())
	}
}

package main

import (
    "fmt"
)

func main() {
    var t int
    fmt.Scanf("%d\n", &t)
    for i := 0; i < t; i++ {
        var a, b int
        fmt.Scanf("%d %d\n", &a, &b)
        fmt.Printf("%d\n", a + b)
    }
}

package main
import "fmt"

func main() {
    var t int;
    fmt.Scan(&t);
    for i := 0; i < t; i++ {
        var a, b int
        fmt.Scan(&a);
        fmt.Scan(&b);
        fmt.Println(a + b);
    }
}

package main

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

var (
	input  io.Reader
	output io.Writer
)

func init() {
	input, output = os.Stdin, os.Stdout
}

func main() {
	var no int
	fmt.Fscan(input, &no)

	for i := 0; i < no; i++ {
		var a, b int
		fmt.Fscan(input, &a, &b)

		fmt.Fprintln(output, solution(a, b))
	}
}

func solution(a, b int) int {
	return a + b
}

package main

import (
	"fmt"
)

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

	for i := 0; i < tcs; i++ {
		var a int
		fmt.Scan(&a)

		var b int
		fmt.Scan(&b)

		fmt.Println(solution(a, b))
	}
}

func solution(a, b int) int {
	return a + b
}

package main

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

func main() {
	var truncator string
	if runtime.GOOS == "windows" {
		truncator = "\r\n"
	} else {
		truncator = "\n"
	}

	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimSuffix(text, truncator)
	testcase, _ := strconv.ParseInt(text, 10, 64)

	var i int64
	for i = 0; i < testcase; i++ {
		input := readInt(2, reader)
		fmt.Println(input[0] + input[1])
	}
}

func readInt(size int, reader *bufio.Reader) []int64 {
	text, _ := reader.ReadString('\n')
	split := strings.Fields(text)
	result := make([]int64, len(split))
	for i := range result {
		result[i], _ = strconv.ParseInt(split[i], 10, 64)
	}
	return result
}

package main
import "fmt"
func main(){
    var n int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        var a, b int
        fmt.Scan(&a, &b)
        fmt.Println(a + b)

    }
}

package main
import (
    "bufio"
    "fmt"
    "os"
)
func main() {
    r := bufio.NewReader(os.Stdin)
    w := bufio.NewWriter(os.Stdout)
    defer w.Flush()

    var n, a, b int
    fmt.Fscan(r, &n)
    for i := 0; i < n; i++ {
        fmt.Fscan(r, &a, &b)
        fmt.Fprintln(w, a + b)
    }
}

package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 0
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}

	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	t := getNextInt(scanner)
	for i := 0; i < t; i++ {
		a := getNextInt(scanner)
		b := getNextInt(scanner)
		fmt.Fprintln(writer, a+b)
	}
}

// Problem statement can be found in
// https://codeforces.com/problemset/problem/1351/A

package main

import "fmt"

func main() {
	var t int

	for i:=0; i < t ; i++ {
		var a, b int
		fmt.Scan(&a, &b)

		fmt.Println(a+b)
	}
}

package main

import "fmt"

func add(x int, y int) int {
	return x + y
}

func main() {
	var t int
	fmt.Scanf("%d", &t)
	for i := 0; i < t; i++ {
		var a, b int
		fmt.Scanf("%d %d", &a, &b)
		fmt.Println(a + b)
	}

}

package main

import (
	"fmt"
)

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

	for i := 0; i < tcs; i++ {
		var a, b int
		fmt.Scanf("%d %d", &a, &b)
		fmt.Println(solution(a, b))
	}
}

func solution(a, b int) int {
	return a + b
}