There are $$$n$$$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value $$$x$$$ eats a slime with a value $$$y$$$, the eaten slime disappears, and the value of the remaining slime changes to $$$x - y$$$.The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime.

The first line of the input contains an integer $$$n$$$ ($$$1 \le n \le 500\,000$$$) denoting the number of slimes. The next line contains $$$n$$$ integers $$$a_i$$$ ($$$-10^9 \le a_i \le 10^9$$$), where $$$a_i$$$ is the value of $$$i$$$-th slime.

Print an only integer — the maximum possible value of the last slime.

NoteIn the first example, a possible way of getting the last slime with value $$$4$$$ is:  Second slime eats the third slime, the row now contains slimes $$$2, -1, 1$$$ Second slime eats the third slime, the row now contains slimes $$$2, -2$$$ First slime eats the second slime, the row now contains $$$4$$$ In the second example, the first slime can keep eating slimes to its right to end up with a value of $$$4$$$.

package main

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

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...) }

var db bool = false
const maxn int = 5*1e5

var n int
var a [maxn+2]int64

var LPM [maxn+2]int64 //left_pos_min
var LPS [maxn+2]int64 //left_pos_sum
var LNS [maxn+2]int64 //left_neg_sum

var RPM [maxn+2]int64 //right_pos_min
var RPS [maxn+2]int64 //right_pos_sum
var RNS [maxn+2]int64 //right_neg_sum

var ans, tans, lans, rans int64
var pos_min int64

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

    pos_min = 1e9+1

    for i := 1; i <= n; i++ {
        scanf("%d", &a[i])
        LPS[i], LNS[i] = LPS[i-1], LNS[i-1]
        if a[i] >= 0 {
            LPS[i] = LPS[i-1] + a[i]
            if a[i] < pos_min {
                pos_min = a[i]
            }
            LPM[i] = pos_min
        } else {
            LNS[i] = LNS[i-1] + a[i]
        }
    }

    pos_min = 1e9+1

    for i := n; i >= 1; i-- {
        RPS[i], RNS[i] = RPS[i+1], RNS[i+1]
        if a[i] >= 0 {
            RPS[i] = RPS[i+1] + a[i]
            if a[i] < pos_min {
                pos_min = a[i]
            }
            RPM[i] = pos_min
        } else {
            RNS[i] = RNS[i+1] + a[i]
        }
    }

    ans = -1 << 63
    for i := 1; i <= n; i++ {
        tans = a[i]
        lans, rans = 0, 0
        if i > 1 {
            //there is a possibility we can get some improvement from the LEFT portion
            if LNS[i-1] < 0 {
                //there was at least one neg num
                lans = -LNS[i-1] + LPS[i-1]
            } else {
                //all nums on the left are non-negative
                if i == 2 {
                    //there is only one num on the left and that num is non-negative
                    lans = -LPM[i-1]
                } else {
                    //there are only non-negative numbers[many] on the left
                    lans = LPS[i-1] - 2*LPM[i-1]
                }
            }
        }
        if i < n {
            //there is a possibility we can get some improvement from the RIGHT portion
            if RNS[i+1] < 0 {
                //there was at least one neg num
                rans = -RNS[i+1] + RPS[i+1]
            } else {
                //all nums are non-negative
                if i == n-1 {
                    //there is only one num on the right and that num is non-negative
                    rans = -RPM[i+1]
                } else {
                    //there are only non-negative numbers[many] on the right
                    rans = RPS[i+1] - 2*RPM[i+1]
                }
            }
        }
        tans += (lans + rans)
        if tans > ans {
            ans = tans
        }
    }
    printf("%d", ans)
}

package main

import."fmt"
import"bufio"
import"os"
import."sort"

func main(){
	in:=bufio.NewReader(os.Stdin)
	var n int
	Fscan(in,&n)
	a:=make([]int,n)
	for i:=0;i<n;i++{
		Fscan(in,&a[i])
	}

	if n==1{
		Print(a[0])
		return
	}
	Ints(a)
	pos:=-1
	for i:=0;i<n;i++{
		if a[i]>=0{
			pos=i
			break
		}
	}
	ans:=int64(0)
	if pos==-1||pos==n-1{
		ans=int64(a[n-1])
		for i:=0;i<n-1;i++{
			ans-=int64(a[i])
		}
	}else if pos==0{
		ans=int64(a[0])
		for i:=1;i<n-1;i++{
			ans-=int64(a[i])
		}
		ans=int64(a[n-1])-ans
	}else{
		ans=int64(a[pos-1])
		for i:=pos;i<n-1;i++{
			ans-=int64(a[i])
		}
		ans=int64(a[n-1])-ans
		for i:=0;i<pos-1;i++{
			ans-=int64(a[i])
		}
	}
	Print(ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	Fscan(in, &n)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		Fscan(in, &arr[i])
	}
	if n == 1 {
		Print(arr[0])
		return
	}
	sort.Ints(arr)
	ans := int64(arr[n-1] - arr[0])
	for i := 1; i < n-1; i++ {
		a := arr[i]
		if a < 0 {
			a = -a
		}
		ans += int64(a)
	}
	Print(ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str := strings.Fields(s)
	num, err := strconv.Atoi(str[0])
	if err != nil {
		log.Fatal(err)
	}
	s, err = in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str = strings.Fields(s)
	vals := make([]int, 0, num)
	//flag: 2(complex), 1(positive), -1(negative)
	flag := 0
	for _, v := range str {
		temp, err := strconv.Atoi(v)
		if err != nil {
			log.Fatal(err)
			continue
		}
		vals = append(vals, temp)
		if flag == 0 {
			if temp > 0 {
				flag = 1
			} else {
				flag = -1
			}
			continue
		} else if flag == 2 {
			continue
		} else {
			if flag*temp < 0 {
				flag = 2
			}
		}
	}
	out := bufio.NewWriter(os.Stdout)
	if num == 1 {
		fmt.Fprint(out, vals[0])
	} else if num == 2 {
		fmt.Fprint(out, int(math.Abs(float64(vals[0]-vals[1]))))
	} else {
		if flag == 0 {
			fmt.Fprint(out, 0)
		} else if flag == 1 {
			var sum int64
			min := vals[0]
			for _, v := range vals {
				sum += int64(v)
				if min > v {
					min = v
				}
			}
			fmt.Fprint(out, sum-int64(2*min))
		} else if flag == -1 {
			var sum int64
			max := vals[0]
			for _, v := range vals {
				sum += int64(v)
				if max < v {
					max = v
				}
			}
			fmt.Fprint(out, int64(2*max)-sum)
		} else {
			var sum int64
			for _, v := range vals {
				sum += int64(math.Abs(float64(v)))
			}
			fmt.Fprint(out, sum)
		}
	}
	out.Flush()
}

package main

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

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...) }

const maxn int = 5*1e5

var n int
var a [maxn+2]int64

var LPM [maxn+2]int64 //left_pos_min
var LPS [maxn+2]int64 //left_pos_sum
var LNS [maxn+2]int64 //left_neg_sum

var RPM [maxn+2]int64 //right_pos_min
var RPS [maxn+2]int64 //right_pos_sum
var RNS [maxn+2]int64 //right_neg_sum

var ans, tans, lans, rans int64
var pos_min int64

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

    pos_min = 1e9+1
    //LPS[0] = 0
    //LNS[0] = 0
    //LPM[0] = pos_min

    for i := 1; i <= n; i++ {
        scanf("%d", &a[i])
        if a[i] >= 0 {
            LPS[i] = LPS[i-1] + a[i]
            if a[i] < pos_min {
                pos_min = a[i]
            }
            LPM[i] = pos_min
        } else {
            LNS[i] = LNS[i-1] + a[i]
        }
    }

    pos_min = 1e9+1
    //RPS[0] = 0
    //RNS[0] = 0
    //RPM[0] = pos_min

    for i := n; i >= 1; i-- {
        if a[i] >= 0 {
            RPS[i] = RPS[i+1] + a[i]
            if a[i] < pos_min {
                pos_min = a[i]
            }
            RPM[i] = pos_min
        } else {
            RNS[i] = RNS[i+1] + a[i]
        }
    }

    ans = -1 << 63
    for i := 1; i <= n; i++ {
        tans = a[i]
        lans, rans = 0, 0
        if i > 1 {
            //there is a possibility we can get some improvement from the LEFT portion
            if LNS[i-1] < 0 {
                //there was at least one neg num
                lans = -LNS[i-1] + LPS[i-1]
            } else {
                //all nums on the left are non-negative
                if i == 2 {
                    //there is only one num on the left and that num is non-negative
                    lans = -LPM[i-1]
                } else {
                    //there are only non-negative numbers[many] on the left
                    lans = LPS[i-1] - 2*LPM[i-1]
                }
            }
        }
        if i < n {
            //there is a possibility we can get some improvement from the RIGHT portion
            if RNS[i+1] < 0 {
                //there was at least one neg num
                rans = -RNS[i+1] + RPS[i+1]
            } else {
                //all nums are non-negative
                if i == n-1 {
                    //there is only one num on the right and that num is non-negative
                    rans = -RPM[i+1]
                } else {
                    //there are only non-negative numbers[many] on the right
                    rans = RPS[i+1] - 2*RPM[i+1]
                }
            }
        }
        tans += (lans + rans)
        if tans > ans {
            ans = tans
        }
    }
    printf("%d", ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str := strings.Fields(s)
	num, err := strconv.Atoi(str[0])
	if err != nil {
		log.Fatal(err)
	}
	s, err = in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str = strings.Fields(s)
	vals := make([]int, 0, num)
	var sum int64
	min, max := 0, 0
	for _, v := range str {
		temp, err := strconv.Atoi(v)
		if err != nil {
			log.Fatal(err)
			continue
		}
		vals = append(vals, temp)
		sum += int64(math.Abs(float64(temp)))
		if min > temp {
			min = temp
		}
		if max < temp {
			max = temp
		}
	}
	if min > 0 {
		sum -= int64(min * 2)
	}
	if max < 0 {
		sum += int64(max * 2)
	}
	out := bufio.NewWriter(os.Stdout)
	fmt.Fprint(out, sum)
	out.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str := strings.Fields(s)
	num, err := strconv.Atoi(str[0])
	if err != nil {
		log.Fatal(err)
	}
	s, err = in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str = strings.Fields(s)
	vals := make([]int, 0, num)
	//flag: 2(complex), 1(positive), -1(negative)
	flag := 0
	for _, v := range str {
		temp, err := strconv.Atoi(v)
		if err != nil {
			log.Fatal(err)
			continue
		}
		vals = append(vals, temp)
		if flag == 0 {
			if temp > 0 {
				flag = 1
			} else {
				flag = -1
			}
			continue
		} else if flag == 2 {
			continue
		} else {
			if flag*temp < 0 {
				flag = 2
			}
		}
	}
	out := bufio.NewWriter(os.Stdout)
	if num == 1 {
		fmt.Fprint(out, vals[0])
	} else if num == 2 {
		fmt.Fprint(out, int(math.Abs(float64(vals[0]-vals[1]))))
	} else {
		if flag == 0 {
			fmt.Fprint(out, 0)
		} else if flag == 1 {
			sum, min := 0, vals[0]
			for _, v := range vals {
				sum += v
				if min > v {
					min = v
				}
			}
			fmt.Fprint(out, sum-2*min)
		} else if flag == -1 {
			sum, max := 0, vals[0]
			for _, v := range vals {
				sum += v
				if max < v {
					max = v
				}
			}
			fmt.Fprint(out, 2*max-sum)
		} else {
			sum := 0
			for _, v := range vals {
				sum += int(math.Abs(float64(v)))
			}
			fmt.Fprint(out, sum)
		}
	}
	out.Flush()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str := strings.Fields(s)
	num, err := strconv.Atoi(str[0])
	if err != nil {
		log.Fatal(err)
	}
	s, err = in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str = strings.Fields(s)
	vals := make([]int, 0, num)
	var sum int64
	min, max := 0, 0
	for _, v := range str {
		temp, err := strconv.Atoi(v)
		if err != nil {
			log.Fatal(err)
			continue
		}
		vals = append(vals, temp)
		sum += int64(math.Abs(float64(temp)))
		if min > temp {
			min = temp
		}
		if max < temp {
			max = temp
		}
	}
	if min > 0 {
		sum -= int64(min * 2)
	}else if max < 0 {
		sum += int64(max * 2)
	}
	out := bufio.NewWriter(os.Stdout)
	fmt.Fprint(out, sum)
	out.Flush()
	//
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	s, err := in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str := strings.Fields(s)
	num, err := strconv.Atoi(str[0])
	if err != nil {
		log.Fatal(err)
	}
	s, err = in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str = strings.Fields(s)
	vals := make([]int, 0, num)
	var sum int64
	min, max := 0, 0
	for _, v := range str {
		temp, err := strconv.Atoi(v)
		if err != nil {
			log.Fatal(err)
			continue
		}
		vals = append(vals, temp)
		sum += int64(math.Abs(float64(temp)))
		if min > temp {
			min = temp
		}
		if max < temp {
			max = temp
		}
	}
	if min > 0 {
		sum -= int64(min * 2)
	}else if max < 0 {
		sum += int64(max * 2)
	}
	out := bufio.NewWriter(os.Stdout)
	fmt.Fprint(out, sum)
	out.Flush()
}


You are given two strings $$$s$$$ and $$$t$$$ both of length $$$n$$$ and both consisting of lowercase Latin letters.In one move, you can choose any length $$$len$$$ from $$$1$$$ to $$$n$$$ and perform the following operation:   Choose any contiguous substring of the string $$$s$$$ of length $$$len$$$ and reverse it;  at the same time choose any contiguous substring of the string $$$t$$$ of length $$$len$$$ and reverse it as well. Note that during one move you reverse exactly one substring of the string $$$s$$$ and exactly one substring of the string $$$t$$$.Also note that borders of substrings you reverse in $$$s$$$ and in $$$t$$$ can be different, the only restriction is that you reverse the substrings of equal length. For example, if $$$len=3$$$ and $$$n=5$$$, you can reverse $$$s[1 \dots 3]$$$ and $$$t[3 \dots 5]$$$, $$$s[2 \dots 4]$$$ and $$$t[2 \dots 4]$$$, but not $$$s[1 \dots 3]$$$ and $$$t[1 \dots 2]$$$.Your task is to say if it is possible to make strings $$$s$$$ and $$$t$$$ equal after some (possibly, empty) sequence of moves.You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of test cases. Then $$$q$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of $$$s$$$ and $$$t$$$. The second line of the test case contains one string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. The third line of the test case contains one string $$$t$$$ consisting of $$$n$$$ lowercase Latin letters. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum n \le 2 \cdot 10^5$$$).

For each test case, print the answer on it — "YES" (without quotes) if it is possible to make strings $$$s$$$ and $$$t$$$ equal after some (possibly, empty) sequence of moves and "NO" otherwise.

4
4
abcd
abdc
5
ababa
baaba
4
asdf
asdg
4
abcd
badc

package main

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

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

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

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

func areEqual(s, t []byte) bool {
	if len(s) != len(t) {
		panic("slice neq")
	}
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			return false
		}
	}
	return true
}

func hasDup(s []byte) bool {
	for i := 1; i < len(s); i++ {
		if s[i-1] == s[i] {
			return true
		}
	}
	return false
}

func calParity(s []byte) bool {
	par := false
	for i := 0; i < len(s); i++ {
		for j := i + 1; j < len(s); j++ {
			if s[i] > s[j] {
				par = !par
			}
		}
	}
	return par
}

func solve(n int, s, t []byte) bool {
	sc := append([]byte{}, s...)
	tc := append([]byte{}, t...)
	sort.Slice(sc, func(i, j int) bool {
		return sc[i] < sc[j]
	})
	sort.Slice(tc, func(i, j int) bool {
		return tc[i] < tc[j]
	})
	if !areEqual(sc, tc) {
		return false
	}
	if hasDup(sc) {
		return true
	}
	return calParity(s) == calParity(t)
}

func main() {
	defer writer.Flush()
	var q int
	Scanf("%d\n", &q)
	for i := 0; i < q; i++ {
		var n int
		var s, t []byte
		Scanf("%d\n%s\n%s\n", &n, &s, &t)
		if solve(n, s, t) {
			Printf("YES\n")
		} else {
			Printf("NO\n")
		}
	}
}

package main

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

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

	var T, n int
	var s, t []byte
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n, &s, &t)
		same := false
		cnt := [26]int{}
		for _, b := range s {
			if cnt[b-'a']++; cnt[b-'a'] > 1 {
				same = true
			}
		}
		for _, b := range t {
			cnt[b-'a']--
		}
		if cnt != [26]int{} {
			Fprintln(out, "NO")
		} else if same {
			Fprintln(out, "YES")
		} else {
			c := 0
			for i, b := range s {
				for _, b2 := range s[:i] {
					if b2 > b {
						c ^= 1
					}
				}
			}
			for i, b := range t {
				for _, b2 := range t[:i] {
					if b2 > b {
						c ^= 1
					}
				}
			}
			if c > 0 {
				Fprintln(out, "NO")
			} else {
				Fprintln(out, "YES")
			}
		}
	}
}

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

package main

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

func check(x, y []byte, n int) bool {
	for ; n > 2; n-- {
		if x[n-1] == y[n-1] {
			continue
		}

		for i := 0; i < n; i++ {
			if x[i] == y[n-1] {
				if (n-1-i)%2 > 0 {
					y[0], y[1] = y[1], y[0]
				}

				for j := i + 1; j < n; j++ {
					x[j-1] = x[j]
				}

				break
			}
		}
	}

	for i := 0; i < n; i++ {
		if x[i] != y[i] {
			return false
		}
	}

	return true
}

func main() {

	reader := bufio.NewReader(os.Stdin)
	var n, p int

	fmt.Fscanf(reader, "%d\n", &p)
	for ; p > 0; p-- {
		var s1, s2 string
		fmt.Fscanf(reader, "%d\n%s\n%s\n", &n, &s1, &s2)

		var a1, a2 [27]int
		for i := 0; i < n; i++ {
			a1[s1[i]-'a']++
			a2[s2[i]-'a']++
		}

		ok := 1 // 0:NO  2:YES  1:possibly
		for i := 0; i < 27; i++ {
			if a1[i] != a2[i] {
				ok = 0
				break
			} else if a1[i] > 1 {
				ok = 2
			}
		}

		if ok == 0 {
			fmt.Println("NO")
			continue
		}

		if ok == 2 {
			fmt.Println("YES")
			continue
		}

		if check([]byte(s1), []byte(s2), n) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}


The Fair Nut found a string $$$s$$$. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences $$$p_1, p_2, \ldots, p_k$$$, such that:   For each $$$i$$$ ($$$1 \leq i \leq k$$$), $$$s_{p_i} =$$$ 'a'.  For each $$$i$$$ ($$$1 \leq i < k$$$), there is such $$$j$$$ that $$$p_i < j < p_{i + 1}$$$ and $$$s_j =$$$ 'b'. The Nut is upset because he doesn't know how to find the number. Help him.This number should be calculated modulo $$$10^9 + 7$$$.

The first line contains the string $$$s$$$ ($$$1 \leq |s| \leq 10^5$$$) consisting of lowercase Latin letters.

In a single line print the answer to the problem — the number of such sequences $$$p_1, p_2, \ldots, p_k$$$ modulo $$$10^9 + 7$$$.

package main

import (
	"fmt"

)
var n int
const maxn int = 100005
var nxt [maxn] int
var dp  [maxn] int
const mod int = 1000*1000*1000 + 7
var s string
func solve(ind int) int {

	if ind == n {
		return 1
	}

	if dp[ind] != -1 {
		return dp[ind]
	}

	ret := 0

	if s[ind] == 'a' {
		ret += solve(nxt[ind])
		ret %= mod
	}

	ret += solve(ind + 1)

	ret %= mod
	dp[ind] = ret

	return dp[ind]
}
func main() {

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

	lst := n
	for i := n - 1 ; i >= 0 ; i-- {
		dp[i] = -1
		nxt[i] = lst;

		if s[i] == 'b' {
			lst = i
		}

	}
	fmt.Println((solve(0) - 1 + mod) % mod);

}

// 1. Only care about a and b.
// 2. Can break the input into a groups.
// 3. Can only care about the very next group.
package main

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

type i64 int64

var (
	ascA   = "a"[0]
	ascB   = "b"[0]
	modulo = i64(1e9) + 7
)

func main() {
	s := ""
	reader := bufio.NewReaderSize(os.Stdin, int(1e5))
	fmt.Fscanf(reader, "%s", &s)
	b, width := make([]bool, len(s)), 0
	for i := 0; i < len(s); i++ {
		if s[i] == ascA || s[i] == ascB {
			b[width], width = s[i] == ascA, width+1
		}
	}

	aGroup := []int{}
	for i := 0; i < width; i++ {
		count := 0
		for (i < width) && b[i] {
			count, i = count+1, i+1
		}
		if count > 0 {
			aGroup = append(aGroup, count)
		}
	}

	if len(aGroup) == 0 {
		fmt.Println(0)
		os.Exit(0)
	}

	sum := i64(aGroup[0])
	for i := 1; i < len(aGroup); i++ {
		sum = (sum + i64(aGroup[i]) + sum*i64(aGroup[i])) % modulo
	}
	fmt.Println(sum)
}

// 1. Only care about a and b
// 2. Can generate the disjoint group, start calc from the last group(which can get the "answer" for itself).
package main

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

type i64 int64

var (
	ascA   = "a"[0]
	ascB   = "b"[0]
	modulo = i64(1e9) + 7
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	s := scanner.Text()
	b, width := make([]bool, len(s)), 0
	for i := 0; i < len(s); i++ {
		if s[i] == ascA || s[i] == ascB {
			b[width], width = s[i] == ascA, width+1
		}
	}

	aGroup := []i64{}
	for i := 0; i < width; i++ {
		count := 0
		for (i < width) && b[i] {
			count, i = count+1, i+1
		}
		if count > 0 {
			aGroup = append(aGroup, i64(count))
		}
	}

	if len(aGroup) == 0 {
		fmt.Println(0)
		os.Exit(0)
	}

	pointer := len(aGroup) - 1
	prev := map[int]i64{1: aGroup[pointer], 0: 1}

	for pointer > 0 {
		maxSeqLen := len(prev) + 1
		pointer--
		oldPrev := prev[0]
		for i := 1; i <= maxSeqLen; i++ {
			prev[i], oldPrev = (aGroup[pointer]*oldPrev+prev[i])%modulo, prev[i]
		}
	}

	sum := i64(0)
	for _, v := range prev {
		sum = (sum + v) % modulo
	}

	fmt.Println(sum - 1)
}


Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.

The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers ti, xi, yi (1 ≤ ti ≤ 2; xi, yi ≥ 0; xi + yi = 10). If ti = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers xi, yi represent the result of executing this command, that is, xi packets reached the corresponding server successfully and yi packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.

NoteConsider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.

// A. System Administrator
/*
Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers x and y (x + y = 10; x, y ≥ 0). These numbers mean that x packets successfully reached the corresponding server through the network and y packets were lost.

Today Polycarpus has performed overall n ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network.

Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results.

Input
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of commands Polycarpus has fulfilled. Each of the following n lines contains three integers — the description of the commands. The i-th of these lines contains three space-separated integers t i, x i, y i (1 ≤ t i ≤ 2; x i, y i ≥ 0; x i + y i = 10). If t i = 1, then the i-th command is "ping a", otherwise the i-th command is "ping b". Numbers x i, y i represent the result of executing this command, that is, x i packets reached the corresponding server successfully and y i packets were lost.

It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command.

Output
In the first line print string "LIVE" (without the quotes) if server a is "alive", otherwise print "DEAD" (without the quotes).

In the second line print the state of server b in the similar format.

Examples
Input
2
1 5 5
2 6 4

Output
LIVE
LIVE

Input
3
1 0 10
2 0 10
1 10 0

Output
LIVE
DEAD

Note
Consider the first test case. There 10 packets were sent to server a, 5 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall there were 10 packets sent to server b, 6 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network.

Consider the second test case. There were overall 20 packages sent to server a, 10 of them reached it. Therefore, at least half of all packets sent to this server successfully reached it through the network. Overall 10 packets were sent to server b, 0 of them reached it. Therefore, less than half of all packets sent to this server successfully reached it through the network.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

	x1, y1, x2, y2 := 0, 0, 0, 0
	for ; n > 0; n-- {
		input2, _ := reader.ReadString('\n')
		arr := strings.Split(strings.TrimSpace(input2), " ")

		t, _ := strconv.Atoi(arr[0])
		a, _ := strconv.Atoi(arr[1])
		b, _ := strconv.Atoi(arr[2])

		if t == 1 {
			x1 += a
			y1 += b
		} else {
			x2 += a
			y2 += b
		}
	}

	if x1 >= y1 {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")
	}
	if x2 >= y2 {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	aPass := 0
	aOk := 0
	bPass := 0
	bOk := 0
	for i := 0; i < n; i++ {
		var a, b, c int
		fmt.Scanf("%d %d %d\n", &a, &b, &c)
		if a == 1 {
			aPass += 5
			aOk += b
		} else {
			bPass += 5
			bOk += b
		}
	}
	if aOk >= aPass {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")
	}
	if bOk >= bPass {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")
	}
}

package main
import (
	"fmt"
	//"bufio"
	//"os"
	//"strconv"
)

func main() {
	var n,k,i int
	fmt.Scan(&n)
	x:=make([]int,5)
	y:=make([]int,5)
	for i=1;i<=n;i++ {
		fmt.Scan(&k,&x[0],&y[0])
		x[k]+=x[0]
		y[k]+=y[0]
	}
	for i=1;i<=2;i++ {
		if x[i]>=y[i] {
			fmt.Println("LIVE")
		} else {
			fmt.Println("DEAD")
		}
	}

}

package main

import (
	"fmt"
)

func main() {

	var (
		i, n, t, x, y int32
		dat           [2][2]int32
	)

	fmt.Scan(&n)
	for i = 0; i < n; i++ {
		fmt.Scan(&t)
		fmt.Scan(&x)
		fmt.Scan(&y)
		dat[t-1][0] += x
		dat[t-1][1] += (x + y)

	}

	if 2*dat[0][0] >= dat[0][1] {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")

	}

	if 2*dat[1][0] >= dat[1][1] {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")

	}

}

package main

import "fmt"

func main() {
    var n,t,x,y int
    var cntx,cnty [2]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&t,&x,&y)
        cntx[t-1] += x
        cnty[t-1] += y
    }
    for i := 0; i < 2; i++ {
        if cntx[i] >= (cntx[i]+cnty[i])/2 {
            fmt.Println("LIVE")
        } else {
            fmt.Println("DEAD")
        }
    }
}

package main
import "fmt"
func main() {
	var n, t, a, b int
	fmt.Scan(&n)
	x,y := 0,0
	for i:=0; i<n; i++ {
		fmt.Scan(&t, &a, &b)
		if t==1 {
			x += a-b
		} else {
			y += a-b
		}
	}
	if x>=0 {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")
	}
	if y>=0 {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")
	}
}

package main
import "fmt"
func main() {
	var n, t, a, b int
	fmt.Scan(&n)
	v := []int{0,0,0}
	for i:=0; i<n; i++ {
		fmt.Scan(&t, &a, &b)
		v[t] += a-b
	}
	for i:=1; i < 3; i++ {
		if v[i]>=0 {
			fmt.Println("LIVE")
		} else {
			fmt.Println("DEAD")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var request, requestA, requestB int
	fmt.Scan(&request)

	servers := make(map[int]int)
	for i:=0; i<request; i++ {
		var requestName, requestSuccess, requestFail int
		fmt.Scan(&requestName, &requestSuccess, &requestFail)

		if requestName == 1 {
			requestA += requestSuccess
		} else {
			requestB += requestSuccess
		}

		servers[requestName] ++
	}

	if servers[1] * 5 <= requestA {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")
	}

	if servers[2] * 5 <= requestB {
		fmt.Println("LIVE")
	} else {
		fmt.Println("DEAD")
	}

}

// 245A-mic
package main

import (
    "fmt"
)

func main() {
    var n, pinga, pingb, t, prece, plost, a, b int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        fmt.Scan(&t, &prece, &plost)
        if t == 1 {
            pinga += prece
            a++
        } else {
            pingb += prece
            b++
        }
    }
    if pinga >= (a*10)/2 {
        fmt.Println("LIVE")
    } else {
        fmt.Println("DEAD")
    }
    if pingb >= (b*10)/2 {
        fmt.Println("LIVE")
    } else {
        fmt.Println("DEAD")
    }
}

package main

import (
	"fmt"
)

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

	servers := make(map[int]int)
	for i:=0; i<request; i++ {
		var requestName, requestSuccess, requestFail int
		fmt.Scan(&requestName, &requestSuccess, &requestFail)

		if requestSuccess >= 5 {
			servers[requestName] ++
		}
	}

	for i := 1; i <= 2; i++ {
		if servers[i] > 0 {
			fmt.Println("LIVE")
		} else {
			fmt.Println("DEAD")
		}
	}
}


Misha and Grisha are funny boys, so they like to use new underground. The underground has n stations connected with n - 1 routes so that each route connects two stations, and it is possible to reach every station from any other.The boys decided to have fun and came up with a plan. Namely, in some day in the morning Misha will ride the underground from station s to station f by the shortest path, and will draw with aerosol an ugly text "Misha was here" on every station he will pass through (including s and f). After that on the same day at evening Grisha will ride from station t to station f by the shortest path and will count stations with Misha's text. After that at night the underground workers will wash the texts out, because the underground should be clean. The boys have already chosen three stations a, b and c for each of several following days, one of them should be station s on that day, another should be station f, and the remaining should be station t. They became interested how they should choose these stations s, f, t so that the number Grisha will count is as large as possible. They asked you for help.

The first line contains two integers n and q (2 ≤ n ≤ 105, 1 ≤ q ≤ 105) — the number of stations and the number of days. The second line contains n - 1 integers p2, p3, ..., pn (1 ≤ pi ≤ n). The integer pi means that there is a route between stations pi and i. It is guaranteed that it's possible to reach every station from any other. The next q lines contains three integers a, b and c each (1 ≤ a, b, c ≤ n) — the ids of stations chosen by boys for some day. Note that some of these ids could be same.

Print q lines. In the i-th of these lines print the maximum possible number Grisha can get counting when the stations s, t and f are chosen optimally from the three stations on the i-th day.

NoteIn the first example on the first day if s = 1, f = 2, t = 3, Misha would go on the route 1  2, and Grisha would go on the route 3  1  2. He would see the text at the stations 1 and 2. On the second day, if s = 3, f = 2, t = 3, both boys would go on the route 3  1  2. Grisha would see the text at 3 stations.In the second examle if s = 1, f = 3, t = 2, Misha would go on the route 1  2  3, and Grisha would go on the route 2  3 and would see the text at both stations.

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol832D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}
	maxs := func(vals ...int) int {
		ans := vals[0]
		for _, val := range vals[1:] {
			if val > ans {
				ans = val
			}
		}
		return ans
	}

	n, q := read(), read()
	g := make([][]int, n)
	for v := 1; v < n; v++ {
		w := read() - 1
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
	}

	vs := make([]int, 0, 2*n-1)
	pos := make([]int, n)
	depths := make([]int, 0, 2*n-1)
	dis := make([]int, n)
	var dfs func(v, fa, d int)
	dfs = func(v, fa, d int) {
		pos[v] = len(vs)
		vs = append(vs, v)
		depths = append(depths, d)
		dis[v] = d
		for _, w := range g[v] {
			if w != fa {
				dfs(w, v, d+1)
				vs = append(vs, v)
				depths = append(depths, d)
			}
		}
	}
	dfs(0, -1, 0)

	type pair struct{ v, i int }
	var st [][18]pair
	stInit := func(a []int) {
		n := len(a)
		st = make([][18]pair, n)
		for i := range st {
			st[i][0] = pair{a[i], i}
		}
		for j := uint(1); 1<<j <= n; j++ {
			for i := 0; i+(1<<j)-1 < n; i++ {
				st0, st1 := st[i][j-1], st[i+(1<<(j-1))][j-1]
				if st0.v < st1.v {
					st[i][j] = st0
				} else {
					st[i][j] = st1
				}
			}
		}
	}
	stQuery := func(l, r int) int {
		k := uint(bits.Len(uint(r-l+1)) - 1)
		st0, st1 := st[l][k], st[r-(1<<k)+1][k]
		if st0.v < st1.v {
			return st0.i
		}
		return st1.i
	}
	lca := func(v, w int) int {
		pv, pw := pos[v], pos[w]
		if pv > pw {
			pv, pw = pw, pv
		}
		return vs[stQuery(pv, pw)]
	}
	calcDis := func(v, w int) int {
		return dis[v] + dis[w] - 2*dis[lca(v, w)]
	}

	stInit(depths)
	for ; q > 0; q-- {
		a, b, c := read()-1, read()-1, read()-1
		v := lca(a, b) ^ lca(a, c) ^ lca(b, c)
		Fprintln(out, 1+maxs(calcDis(v, a), calcDis(v, b), calcDis(v, c)))
	}
}

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


Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form:  You are given two positive integers $$$u$$$ and $$$v$$$, find any pair of integers (not necessarily positive) $$$x$$$, $$$y$$$, such that: $$$$$$\frac{x}{u} + \frac{y}{v} = \frac{x + y}{u + v}.$$$$$$  The solution $$$x = 0$$$, $$$y = 0$$$ is forbidden, so you should find any solution with $$$(x, y) \neq (0, 0)$$$. Please help Ivan to solve some equations of this form.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The next lines contain descriptions of test cases. The only line of each test case contains two integers $$$u$$$ and $$$v$$$ ($$$1 \leq u, v \leq 10^9$$$) — the parameters of the equation.

For each test case print two integers $$$x$$$, $$$y$$$ — a possible solution to the equation. It should be satisfied that $$$-10^{18} \leq x, y \leq 10^{18}$$$ and $$$(x, y) \neq (0, 0)$$$. We can show that an answer always exists. If there are multiple possible solutions you can print any.

package main

import "fmt"

func main() {
  var t int
  fmt.Scanf("%d\n", &t)
  for ; t > 0; t-- {
    var u, v int64
    fmt.Scanf("%d %d\n", &u, &v)
    x := -u*u;
    y := v*v;
    fmt.Printf("%d %d\n", x, y)
  }
}

package main

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

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

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

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscanln(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var u,v int64
    fmt.Fscanln(input, &u, &v)

    // xv(u + v) + yu(u + v) = xuv + yuv
    // xvu + xv^2 + yu^2 + yuv = xuv + yuv
    // xv^2 + yu^2 = 0
    // lcm(v^2, u^2) - it's wrong because integer overflow
    // unstead answer is
    fmt.Fprintln(output, u*u, -v*v)
    //assert((u + v) * (x * v  + y * u) == x * u * v + y * u * v)
}

package main

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

/*

 */

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

	bld := strings.Builder{}

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

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

		x := u * u

		y := -v * v

		fmt.Fprintf(&bld, "%d %d\n", x, y)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//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)
}

//goland:noinspection GoUnusedFunction
func digitAt(num, pos int64) int64 {
	rem := num % int64(math.Pow(10, float64(pos)))
	return rem / int64(math.Pow(10, float64(pos-1)))
}

package main

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

func main() {
	reader := bReader(os.Stdin)
	writer := bWriter(os.Stdout)

	t := readInt(reader)

	for t > 0 {
		u, v := readTwoInt64(reader)
		fmt.Fprintln(writer, -u*u, v*v)

		t--
	}

	writer.Flush()
}

func bReader(stdin *os.File) *bufio.Reader {
	return bufio.NewReaderSize(stdin, 16*1024*1024)
}

func bWriter(stdout *os.File) *bufio.Writer {
	return bufio.NewWriterSize(stdout, 16*1024*1024)
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

func readInt(reader *bufio.Reader) int {
	return int(readInt64(reader))
}

func readInt64(reader *bufio.Reader) int64 {
	value, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)

	return value
}

func readString(reader *bufio.Reader) string {
	return readLine(reader)
}

func readArrayString(reader *bufio.Reader) []string {
	return strings.Split(strings.TrimSpace(readLine(reader)), " ")
}

func readArrayInt(reader *bufio.Reader) []int {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := int(arItemTemp)
		ar = append(ar, arItem)
	}

	return ar
}

func readArrayInt64(reader *bufio.Reader) []int64 {
	arTemp := strings.Split(strings.TrimSpace(readLine(reader)), " ")
	n := len(arTemp)

	var ar []int64

	for i := 0; i < n; i++ {
		arItemTemp, err := strconv.ParseInt(arTemp[i], 10, 64)
		checkError(err)
		arItem := arItemTemp
		ar = append(ar, arItem)
	}

	return ar
}

func readTwoInt(reader *bufio.Reader) (int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1]
}

func readTwoInt64(reader *bufio.Reader) (int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1]
}

func readThreeInt(reader *bufio.Reader) (int, int, int) {
	ar := readArrayInt(reader)
	return ar[0], ar[1], ar[2]
}

func readThreeInt64(reader *bufio.Reader) (int64, int64, int64) {
	ar := readArrayInt64(reader)
	return ar[0], ar[1], ar[2]
}

package main

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

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

func (in *CF15884A) 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 *CF15884A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF15884A
Date: 8/11/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1584/A
Problem: CF15884A
**/
func (in *CF15884A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		u, v := in.NextInt64(), in.NextInt64()
		fmt.Println(-(u * u), v*v)
	}
}

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

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

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N := 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		u, v := int64(0), int64(0)
		fmt.Fscan(f, &u, &v)
		fmt.Fprintln(w, -(u * u), (v * v))
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, u, v int
)

func solve(u, v int) string {
	var (
		x = int64(u) * int64(u)
		y = -int64(v) * int64(v)
	)
	return fmt.Sprint(x, y)
}

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

package main

import "fmt"

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

	for i := 1; i <= t; i++ {
		var u, v int64
		fmt.Scanln(&u, &v)
		fmt.Println(u*u, -v*v)
	}
}

package main

import "fmt"

func main() {
  var t int
  fmt.Scanf("%d", &t)
  for ; t > 0; t-- {
    var u, v int64
    fmt.Scanf("%d %d\n", &u, &v)
    x := -u*u;
    y := v*v;
    fmt.Printf("%d %d\n", x, y)
  }
}

package main

import "fmt"

func main() {
  var t int
  fmt.Scanf("%d", &t)
  for ; t > 0; t-- {
    var u, v int64
    fmt.Scanf("%d %d", &u, &v)
    x := -u*u;
    y := v*v;
    fmt.Printf("%d %d\n", x, y)
  }
}

package main

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

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

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

func main() {
    defer output.Flush()
    //solve()
    //return
	var t int64
	fmt.Fscanln(input, &t)
    for t > 0 {
        t--
        solve()
    }
}

func solve() {
    var u,v int64
    fmt.Fscanln(input, &u, &v)

    // xv(u + v) + yu(u + v) = xuv + yuv
    // xvu + xv^2 + yu^2 + yuv = xuv + yuv
    // xv^2 + yu^2 = 0
    // lcm(v^2, u^2)
    lc := lcm(v*v, u*u)
    x, y := lc / (v * v), -lc / (u * u)
    fmt.Fprintln(output, x, y)
 //   assert((u + v) * (x * v  + y * u) == x * u * v + y * u * v)
}

func lcm(a, b int64) int64 {
    return a*b / gcd(a, b)
}
func gcd(a, b int64) int64 {
    if b == 0 { return a }
    return gcd(b, a % b)
}

package main

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

/*

 */

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

	bld := strings.Builder{}

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

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

		x := u * u

		y := -x * v * v / (u * u)

		fmt.Fprintf(&bld, "%d %d\n", x, y)
	}

	printf("%s", bld.String())
}

const maxUint = ^uint(0)

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

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

//goland:noinspection GoUnusedType
type pair struct {
	fst int
	snd int
}

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

//goland:noinspection GoUnusedFunction
func printf(f string, a ...interface{}) {
	if _, err := fmt.Fprintf(writer, f, a...); err != nil {
		panic(err)
	}
}

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(x, y int) int {
	if x > y {
		return x
	}
	return y
}

//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)
}

//goland:noinspection GoUnusedFunction
func digitAt(num, pos int64) int64 {
	rem := num % int64(math.Pow(10, float64(pos)))
	return rem / int64(math.Pow(10, float64(pos-1)))
}


One day, Vogons wanted to build a new hyperspace highway through a distant system with $$$n$$$ planets. The $$$i$$$-th planet is on the orbit $$$a_i$$$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be destructed.Vogons have two machines to do that.  The first machine in one operation can destroy any planet at cost of $$$1$$$ Triganic Pu.  The second machine in one operation can destroy all planets on a single orbit in this system at the cost of $$$c$$$ Triganic Pus. Vogons can use each machine as many times as they want.Vogons are very greedy, so they want to destroy all planets with minimum amount of money spent. Can you help them to know the minimum cost of this project?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then the test cases follow. Each test case consists of two lines. The first line contains two integers $$$n$$$ and $$$c$$$ ($$$1 \le n, c \le 100$$$) — the number of planets and the cost of the second machine usage. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the orbit of the $$$i$$$-th planet.

For each test case print a single integer — the minimum cost of destroying all planets.

NoteIn the first test case, the cost of using both machines is the same, so you can always use the second one and destroy all planets in orbit $$$1$$$, all planets in orbit $$$2$$$, all planets in orbit $$$4$$$, all planets in orbit $$$5$$$.In the second test case, it is advantageous to use the second machine for $$$2$$$ Triganic Pus to destroy all the planets in orbit $$$2$$$, then destroy the remaining two planets using the first machine.In the third test case, you can use the first machine twice or the second machine once.In the fourth test case, it is advantageous to use the first machine twice.

package main

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

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

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

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

			aa[v]++
		}

		var tot int64
		for _, v := range aa {
			if v > 0 {
				tot += min(int64(v), int64(c))
			}
		}

		fmt.Fprintln(out, tot)
	}
}

package main

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

func main() {
	var t, n, c, buffer, counter, sum int
	var mass []int
	fmt.Fscan(os.Stdin, &t)
	for i := 0; i < t; i++ {
		sum = 0
		fmt.Fscan(os.Stdin, &n)
		fmt.Fscan(os.Stdin, &c)
		for j := 0; j < n; j++ {
			fmt.Fscan(os.Stdin, &buffer)
			mass = append(mass, buffer)
		}
		sort.Ints(mass)
		counter = 1
		for j := 0; j < n-1; j++ {
			if mass[j] != mass[j+1] {
				if counter > c {
					sum = sum + c
				} else {
					sum = sum + counter
				}
				counter = 1
			} else {
				counter++
			}
		}
		if counter > c {
			sum = sum + c
		} else {
			sum = sum + counter
		}
		//fmt.Println(mass)
		fmt.Println(sum)
		sum = 0
		mass = nil
	}
}

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,c int
		fmt.Fscan(in,&n,&c)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		mapper:= make(map[int]int)
		for j:=0;j<n;j++{
			mapper[list[j]]++
		}
		var sum int
		for _,value := range mapper {
			if value < c {
				sum+=value
			} else {
				sum+=c
			}
		}
		fmt.Fprintln(out,sum)
	}
}

package main

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

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

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

func solve(n, c int, a []int) int {
	o := make([]int, 101)
	for _, x := range a {
		o[x]++
	}
	r := 0
	for _, k := range o {
		r += min(c, k)
	}
	return r
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &c)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, c, a))
	}
}

package main

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

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

func (in *CF1730A) 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 *CF1730A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1730A
Date: 1/10/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1730/A
Problem: CF1730A
**/
func (in *CF1730A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n, c := in.NextInt(), in.NextInt()
		arr := make([]int, 101)
		for i := 0; i < n; i++ {
			arr[in.NextInt()]++
		}
		cost := 0
		for i := 0; i < len(arr); i++ {
			if arr[i] > 0 {
				if arr[i] > c {
					cost += c
				} else {
					cost += arr[i]
				}
			}
		}
		fmt.Println(cost)

	}
}

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

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

package main

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

func main() {
	var T, n, c, temp, cost int

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

	for fmt.Fscan(r, &T); T > 0; T-- {
		fmt.Fscan(r, &n, &c)
		a := make([]int, 101)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &temp)
			a[temp]++
		}

		cost = 0
		for i := 0; i < 101; i++ {
			if a[i] < c {
				cost += a[i]
			} else {
				cost += c
			}
		}

		fmt.Fprintln(w, cost)
	}
}

package main

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

func main() {
	defer writer.Flush()
	var t int
	scanws(&t)
	for t > 0 {
		solve()
		t--
	}
}

func solve() {
	var n, c, v, tot int
	fMap := make(map[int]int)
	scanws(&n, &c)
	for n > 0 {
		scanws(&v)
		fMap[v]++
		n--
	}
	for _, freq := range fMap {
		tot += MinInt(freq, c)
	}
	printf("%d\n", tot)
}

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

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 scanws(a ...interface{}) { fmt.Fscan(reader, a...) }

package main

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

func main() {

	var t int

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

	fmt.Fscan(in, &t)

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

		fff := make(map[int]int)

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

			fff[temp]++
		}

		o := solve(&fff, c)
		fmt.Fprintln(out, o)
	}
}

func solve(ff *map[int]int, c int) int {

	tc := 0

	for _, t1 := range *ff {
		if t1 > c {
			tc += c
		} else {
			tc += t1
		}
	}
	return tc
}

package main

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

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

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

	var T int
	var n int
	var c int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &c)
		r := make([]int, 101)
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			r[x]++
		}
		ans :=0
		for _, v := range r {
			if v < c {
				ans += v
			} else {
				ans += c
			}
		}

		Fprintln(out, ans)
	}
}

package main

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

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

func main() {
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		var n, c, num int
		fmt.Fscan(in, &n, &c)
		mmid := make(map[int]int)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &num)
			if val, ok := mmid[num]; ok {
				mmid[num] = val + 1
			} else {
				mmid[num] = 1
			}
		}
		res := 0
		for _, val := range mmid {
			if val >= c {
				res += c
			} else {
				res += val
			}
		}
		fmt.Fprintln(out, res)
	}
}

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...)
}

func solve() {
	var n, c int
	scan(&n, &c)
	a := make([]int, n)
	f := make([]int, 101)
	for i := 0; i < n; i++ {
		scan(&a[i])
		f[a[i]]++
	}
	result := 0
	for i := 0; i <= 100; i++ {
		if f[i] > 0 {
			cost := f[i]
			if cost > c {
				cost = c
			}
			result += cost
		}
	}
	printf("%d\n", result)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

const cf = true

func solve() {
	var n, c, num int
	fmt.Fscan(in, &n, &c)
	cnt := make([]int, 101)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &num)
		cnt[num]++
	}
	ans := 0
	for _, item := range cnt {
		ans += min(item, c)
	}
	fmt.Fprintln(out, ans)
}

func main() {
	defer out.Flush()
	t := 1
	fmt.Fscan(in, &t)
	for ; t > 0; t-- {
		solve()
	}
}

func ConvertInt(val string, base, toBase int) (string, error) {
	i, err := strconv.ParseInt(val, base, 64)
	if err != nil {
		return "", err
	}
	return strconv.FormatInt(i, toBase), nil
}

type set[T Ordered] struct {
	itms map[T]struct{}
}

func (s *set[T]) init() {
	if s.itms == nil {
		s.itms = make(map[T]struct{})
	}
}

func (s *set[T]) add(item T) *set[T] {
	s.init()
	s.itms[item] = exists
	return s
}

func (s *set[T]) remove(item T) *set[T] {
	s.init()
	delete(s.itms, item)
	return s
}

func (s *set[T]) has(item T) bool {
	s.init()
	_, c := s.itms[item]
	return c
}

func (s *set[T]) sortedItems() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	sort.Slice(items, func(i, j int) bool {
		return items[i] < items[j]
	})
	return items
}

func (s *set[T]) items() []T {
	s.init()
	items := make([]T, 0, s.size())
	for item := range s.itms {
		items = append(items, item)
	}
	return items
}

func (s *set[T]) size() int {
	s.init()
	return len(s.itms)
}

var exists = struct{}{}

const MaxUint = ^uint(0)
const MinUint = 0
const MaxInt = int(MaxUint >> 1)
const MinInt = -MaxInt - 1

func reverseStr(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

type Float interface {
	~float32 | ~float64
}

type Integer interface {
	Signed | Unsigned
}

type Signed interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64
}

type Unsigned interface {
	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}

type Ordered interface {
	Integer | Float | ~string
}

func abs[T Signed](x T) T {
	if x < 0 {
		return -x
	}
	return x
}

func min[T Ordered](x, y T) T {
	if x < y {
		return x
	}
	return y
}

func max[T Ordered](x, y T) T {
	if x > y {
		return x
	}
	return y
}

var (
	in  = getReader()
	out = getWriter()
)

func getReader() *bufio.Reader {
	if cf {
		return bufio.NewReader(os.Stdin)
	} else {
		in, _ := os.Open("input.txt")
		return bufio.NewReader(in)
	}
}

func getWriter() *bufio.Writer {
	if cf {
		return bufio.NewWriter(os.Stdout)
	} else {
		out, _ := os.Create("output.txt")
		return bufio.NewWriter(out)
	}
}

package main

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

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

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

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

			aa[v]++
		}

		var tot int64
		for _, v := range aa {
			if v == 1 {
				tot++
			} else if v > 1 {
				tot += int64(c)
			}
		}

		fmt.Fprintln(out, min(int64(n), tot))
	}
}

package main

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

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

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

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

			aa[v]++
		}

		var tot int
		for _, v := range aa {
			if v == 1 {
				tot++
			} else if v > 1 {
				tot += c
			}
		}

		fmt.Fprintln(out, min(n, tot))
	}
}

package main

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

func main() {
	var t, n, c, buffer, counter, sum int
	var mass []int
	fmt.Fscan(os.Stdin, &t)
	for i := 0; i < t; i++ {
		sum = 0
		fmt.Fscan(os.Stdin, &n)
		fmt.Fscan(os.Stdin, &c)
		for j := 0; j < n; j++ {
			fmt.Fscan(os.Stdin, &buffer)
			mass = append(mass, buffer)
		}
		sort.Ints(mass)
		counter = 1
		for j := 0; j < n-1; j++ {
			if mass[j] != mass[j+1] {
				if counter > c {
					sum = sum + c
				} else {
					sum = sum + counter
				}
				counter = 1
			} else {
				counter++
			}
		}
		if counter > c {
			sum = sum + c
		} else {
			sum = sum + counter
		}
		fmt.Println(mass)
		fmt.Println(sum)
		sum = 0
		mass = nil
	}
}


Little boy Igor wants to become a traveller. At first, he decided to visit all the cities of his motherland — Uzhlyandia.It is widely known that Uzhlyandia has n cities connected with m bidirectional roads. Also, there are no two roads in the country that connect the same pair of cities, but roads starting and ending in the same city can exist. Igor wants to plan his journey beforehand. Boy thinks a path is good if the path goes over m - 2 roads twice, and over the other 2 exactly once. The good path can start and finish in any city of Uzhlyandia.Now he wants to know how many different good paths are in Uzhlyandia. Two paths are considered different if the sets of roads the paths goes over exactly once differ. Help Igor — calculate the number of good paths.

The first line contains two integers n, m (1 ≤ n, m ≤ 106) — the number of cities and roads in Uzhlyandia, respectively. Each of the next m lines contains two integers u and v (1 ≤ u, v ≤ n) that mean that there is road between cities u and v. It is guaranteed that no road will be given in the input twice. That also means that for every city there is no more than one road that connects the city to itself.

Print out the only integer — the number of good paths in Uzhlyandia.

NoteIn first sample test case the good paths are:   2 → 1 → 3 → 1 → 4 → 1 → 5,  2 → 1 → 3 → 1 → 5 → 1 → 4,  2 → 1 → 4 → 1 → 5 → 1 → 3,  3 → 1 → 2 → 1 → 4 → 1 → 5,  3 → 1 → 2 → 1 → 5 → 1 → 4,  4 → 1 → 2 → 1 → 3 → 1 → 5. There are good paths that are same with displayed above, because the sets of roads they pass over once are same:   2 → 1 → 4 → 1 → 3 → 1 → 5,  2 → 1 → 5 → 1 → 3 → 1 → 4,  2 → 1 → 5 → 1 → 4 → 1 → 3,  3 → 1 → 4 → 1 → 2 → 1 → 5,  3 → 1 → 5 → 1 → 2 → 1 → 4,  4 → 1 → 3 → 1 → 2 → 1 → 5,  and all the paths in the other direction. Thus, the answer is 6.In the second test case, Igor simply can not walk by all the roads.In the third case, Igor walks once over every road.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF788B(_r io.Reader, out io.Writer) {
	buf := make([]byte, 4096)
	_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, m := r(), r()
	fa := make([]int, n)
	for i := range fa {
		fa[i] = i
	}
	var f func(int) int
	f = func(x int) int {
		if fa[x] != x {
			fa[x] = f(fa[x])
		}
		return fa[x]
	}
	cnt := int64(0)
	d := make([]int, n)
	vis := make([]bool, n)
	for i := 0; i < m; i++ {
		v, w := r()-1, r()-1
		if fv, fw := f(v), f(w); fv != fw {
			fa[fv] = fw
			n--
		}
		if v == w {
			cnt++
		} else {
			d[v]++
			d[w]++
		}
		vis[v] = true
		vis[w] = true
	}
	for _, b := range vis {
		if !b {
			n--
		}
	}
	if n > 1 {
		Fprint(out, 0)
		return
	}
	ans := cnt*(int64(m)-cnt) + cnt*(cnt-1)/2
	for _, c := range d {
		ans += int64(c) * int64(c-1) / 2
	}
	Fprint(out, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF788B(_r io.Reader, out io.Writer) {
	buf := make([]byte, 4096)
	_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, m := r(), r()
	fa := make([]int, n)
	for i := range fa {
		fa[i] = i
	}
	var f func(int) int
	f = func(x int) int {
		if fa[x] != x {
			fa[x] = f(fa[x])
		}
		return fa[x]
	}
	cnt := int64(0)
	d := make([]int, n)
	for i := 0; i < m; i++ {
		v, w := r()-1, r()-1
		if fv, fw := f(v), f(w); fv != fw {
			fa[fv] = fw
			n--
		}
		if v == w {
			cnt++
		} else {
			d[v]++
			d[w]++
		}
	}
	if n > 1 {
		Fprint(out, 0)
		return
	}
	ans := cnt*(int64(m)-cnt) + cnt*(cnt-1)/2
	for _, c := range d {
		ans += int64(c) * int64(c-1) / 2
	}
	Fprint(out, ans)
}

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


Monocarp has forgotten the password to his mobile phone. The password consists of $$$4$$$ digits from $$$0$$$ to $$$9$$$ (note that it can start with the digit $$$0$$$).Monocarp remembers that his password had exactly two different digits, and each of these digits appeared exactly two times in the password. Monocarp also remembers some digits which were definitely not used in the password.You have to calculate the number of different sequences of $$$4$$$ digits that could be the password for Monocarp's mobile phone (i. e. these sequences should meet all constraints on Monocarp's password).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 8$$$) — the number of digits for which Monocarp remembers that they were not used in the password. The second line contains $$$n$$$ different integers $$$a_1, a_2, \dots a_n$$$ ($$$0 \le a_i \le 9$$$) representing the digits that were not used in the password. Note that the digits $$$a_1, a_2, \dots, a_n$$$ are given in ascending order.

For each testcase, print one integer — the number of different $$$4$$$-digit sequences that meet the constraints.

NoteIn the first example, all possible passwords are: "3377", "3737", "3773", "7337", "7373", "7733".

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 n int
		fmt.Fscan(in,&n)
		for j:=0;j<n;j++{
			var x int
			fmt.Fscan(in,&x)
		}
		fmt.Fprintln(out,Cumsum(10-n-1)*6)
	}
}
func Cumsum(x int) int {
	sum:=0
	for j:=1;j<=x;j++{
		sum+=j
	}
	return sum
}

package main

import (
	"fmt"
)

func processSet() {
	nValues := 0
	dummy := 0
	fmt.Scan(&nValues)
	n := 10 - nValues - 1
	for nValues > 0 {
		fmt.Scan(&dummy)
		nValues--
	}

	fmt.Println((n + n*n) / 2 * 6)
}

func main() {

	var nSets = 0
	fmt.Scan(&nSets)
	for nSets > 0 {
		processSet()

		nSets--
	}

}

package main

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

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

func (in *CF1743A) 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 *CF1743A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1743A
Date: 10/18/2022
User: wotan
URL: https://codeforces.com/problemset/problem/1743/A
Problem: CF1743A
**/
func (in *CF1743A) Run() {

	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		for i := 0; i < n; i++ {
			in.NextInt()
		}

		sol := fib(10-n-1) * 6
		fmt.Println(sol)

	}

}

func fib(n int) int {
	if n <= 1 {
		return 1
	}
	return n + fib(n-1)
}

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

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

package main

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

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

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

		d := 10 - n - 1
		fmt.Fprintln(out, 6*d*(d+1)/2)
	}
}

package main

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

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

func solve() {
    var n, x int
    Fscan(in, &n)
    for i := 0; i < n; i++ {
        Fscan(in, &x)
    }

    n = 10 - n;
    Fprintln(out, n * (n - 1) *3);
}

func main() {
    var T int
    Fscan(in, &T)
    for ; T > 0; T-- {
        solve()
    }
    out.Flush()
}

package main

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

var reader = bufio.NewReader(os.Stdin)

const N = 52

var n, m int
var (
	a, g, q [N]int
)

func main() {
	var t int

	fmt.Fscan(reader, &t)

	for t > 0 {
		t--
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		invalid := make(map[int]int, 0)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
			invalid[a[i]] = 2
		}
		ans := 0
		var dfs func(u int)
		used := map[int]int{}
		dfs = func(u int) {
			if u == 3 {
				if len(used) == 2 {
					ans++
				}
				return
			}
			for i := 0; i <= 9; i++ {
				if invalid[i] == 0 {
					used[i]++
					dfs(u + 1)
					used[i]--
					if used[i] == 0 {
						delete(used, i)
					}
				}
			}
		}
		dfs(0)
		fmt.Println(ans)
	}
}

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

/*
	A template for Go on codeforces.com
	Author: Yakov, frvr.ru
*/

package main

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

func main() {
	t := readInt()
	for j := 0; j < t; j++ {
		n := readInt()
		var arr []int
		arr1 := make([]int, 10)
		arr = readInts()
		for i := 0; i < n; i++ {
			arr1[arr[i]] = 1
		}
		//fmt.Printf("arr1====>%v\n", arr1)
		cnt := 0
		for i := 0; i < 10; i++ {
			for j := i + 1; j < 10; j++ {
				if arr1[i] == 1 || arr1[j] == 1 {
					continue
				}
				cnt += 6
			}
		}
		writeLine(cnt)
	}
}

/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */
/* ~~~~~~~~~~ */

var in = bufio.NewReader(os.Stdin)

type float = float32
type double = float64
type long = int64
type ulong = uint64

func typeOf(arg interface{}) string {
	switch reflect.TypeOf(arg).Kind() {
	case reflect.Int:
		return "int"
	case reflect.Int8:
		return "int8"
	case reflect.Int16:
		return "int16"
	case reflect.Int32:
		return "int32"
	case reflect.Int64:
		return "int64"
	case reflect.Uint:
		return "uint"
	case reflect.Uint8:
		return "uint8"
	case reflect.Uint16:
		return "uint16"
	case reflect.Uint32:
		return "uint32"
	case reflect.Uint64:
		return "uint64"
	case reflect.Float32:
		return "float32"
	case reflect.Float64:
		return "float64"
	case reflect.Complex64:
		return "complex64"
	case reflect.Complex128:
		return "complex128"
	case reflect.Bool:
		return "bool"
	case reflect.String:
		return "string"
	case reflect.Chan:
		return "chan"
	case reflect.Ptr:
		return "ptr"
	case reflect.Uintptr:
		return "uintptr"
	case reflect.UnsafePointer:
		return "unsafeptr"
	case reflect.Interface:
		return "interface"
	case reflect.Array:
		return "array"
	case reflect.Slice:
		return "slice"
	case reflect.Map:
		return "map"
	case reflect.Struct:
		return "struct"
	case reflect.Func:
		return "func"
	case reflect.Invalid:
		return "invalid"
	default:
		return "nil"
	}
}

/* ~~~~~~~~~~ */

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}

func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float32(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

/* ~~~~~~~~~~ */

// Too much overhead with universal method using interface{}, wait for the generics,
// but for now — just don't look at the redundancy of the code after that commentary :)

func readBools() []bool {
	strs := readStrings()
	arr := make([]bool, len(strs))
	for i, s := range strs {
		arr[i] = readBool(s)
	}
	return arr
}
func readBytes() []byte {
	strs := readStrings()
	arr := make([]byte, len(strs))
	for i, s := range strs {
		arr[i] = readByte(s)
	}
	return arr
}
func readDoubles() []double {
	strs := readStrings()
	arr := make([]double, len(strs))
	for i, s := range strs {
		arr[i] = readDouble(s)
	}
	return arr
}
func readFloats() []float {
	strs := readStrings()
	arr := make([]float, len(strs))
	for i, s := range strs {
		arr[i] = readFloat(s)
	}
	return arr
}
func readInts() []int {
	strs := readStrings()
	arr := make([]int, len(strs))
	for i, s := range strs {
		arr[i] = readInt(s)
	}
	return arr
}
func readLongs() []long {
	strs := readStrings()
	arr := make([]long, len(strs))
	for i, s := range strs {
		arr[i] = readLong(s)
	}
	return arr
}
func readULongs() []ulong {
	strs := readStrings()
	arr := make([]ulong, len(strs))
	for i, s := range strs {
		arr[i] = readULong(s)
	}
	return arr
}

/* ~~~~~~~~~~ */

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLine(arg ...interface{})             { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

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 debug(a ...interface{}) {
	for _, e := range a {
		printf("%v ", e)
	}
	printf("\n")
	writer.Flush()
}

func solve() {
	var n int
	scanf("%d\n", &n)
	excluded := make([]bool, 10)
	for i:=0; i<n; i++ {
		var num int
		scanf("%d ", &num)
		excluded[num] = true
	}
	scanf("\n")

	var res int = 0
	for num:=0; num<10000; num++ {
		isIncluded := true
		curNum := num

		count := make([]int, 10)
		for i:=0; i<4; i++ {
			count[curNum%10]++
			curNum /= 10
		}

		for number:=0; number<10; number++ {
			if count[number] == 0 {
				continue
			}
			if count[number] != 2 || excluded[number] {
				isIncluded = false
				break
			}
		}
		if isIncluded {
			res++
		}
	}

	printf("%d\n", res)
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		solve()
	}
}

package main

import (
	"fmt"
)

func main() {
	var num int
	fmt.Scan(&num)
	for t := 0; t < num; t++ {
		var n int
		fmt.Scan(&n)
		var numArr []int
		for i := 0; i < n; i++ {
			var num3 int
			fmt.Scan(&num3)
			numArr = append(numArr, num3)
		}
		var res int
		res = A(numArr)
		fmt.Println(res)
	}

}
func A(arr []int) int {
	var num int
	count := 1
	num = 10 - len(arr)
	count = num * (num - 1)
	count = (count / 2) * 6

	return count

}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Scan(&n)

		arr := make([]int, 0)
		for i := 0; i < n; i++ {
			var x int
			fmt.Scan(&x)
			arr = append(arr, x)
		}

		res := 0
		for i := 0; i <= 9; i++ {
			for j := i + 1; j <= 9; j++ {
				flag := true
				for k := 0; k < n; k++ {
					if i == arr[k] || j == arr[k] {
						flag = false
						break
					}
				}
				if flag {
					res += 2 * 3
				}
			}
		}

		fmt.Println(res)
	}
}

package main

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

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

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

	var T int
	var n int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)

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

		ans := (10 - n) * (10 - n - 1) / 2 * 6

		Fprintln(out, ans)
	}
}

package main

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

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

	res := make([]int, 11)
	for i := range res {
		res[i] = 3*i*(i-1)
	}

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

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

		for i := 0; i < n; i++ { fmt.Fscan(r, &temp) }
		fmt.Fprintln(w, res[10-n])
	}

}