You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.You must paint a fence which consists of $$$10^{100}$$$ planks in two colors in the following way (suppose planks are numbered from left to right from $$$0$$$):   if the index of the plank is divisible by $$$r$$$ (such planks have indices $$$0$$$, $$$r$$$, $$$2r$$$ and so on) then you must paint it red;  if the index of the plank is divisible by $$$b$$$ (such planks have indices $$$0$$$, $$$b$$$, $$$2b$$$ and so on) then you must paint it blue;  if the index is divisible both by $$$r$$$ and $$$b$$$ you can choose the color to paint the plank;  otherwise, you don't need to paint the plank at all (and it is forbidden to spent paint on it). Furthermore, the Government added one additional restriction to make your punishment worse. Let's list all painted planks of the fence in ascending order: if there are $$$k$$$ consecutive planks with the same color in this list, then the Government will state that you failed the labor and execute you immediately. If you don't paint the fence according to the four aforementioned conditions, you will also be executed.The question is: will you be able to accomplish the labor (the time is not important) or the execution is unavoidable and you need to escape at all costs.

The first line contains single integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of test cases. The next $$$T$$$ lines contain descriptions of test cases — one per line. Each test case contains three integers $$$r$$$, $$$b$$$, $$$k$$$ ($$$1 \le r, b \le 10^9$$$, $$$2 \le k \le 10^9$$$) — the corresponding coefficients.

Print $$$T$$$ words — one per line. For each test case print REBEL (case insensitive) if the execution is unavoidable or OBEY (case insensitive) otherwise.

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

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

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

	return string(res)
}

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

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

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

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

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

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

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

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

var t int
var r, b, k int64

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		r, b, k = ReadInt64_3()

		solve()
	}
}

const obey = "OBEY"
const rebel = "REBEL"

func solve() {
	l, s := int64(0), int64(0)
	if r > b {
		l, s = r, b
	} else {
		l, s = b, r
	}

	// m := (l-2)/s + 1

	gcd := Gcd(l, s)
	x := gcd
	m := (l-1-x)/s + 1
	// fmt.Println(m)
	if m < k {
		fmt.Println(obey)
	} else {
		fmt.Println(rebel)
	}
}

// func solve() {
// 	l, s := int64(0), int64(0)
// 	if r > b {
// 		l, s = r, b
// 	} else {
// 		l, s = b, r
// 	}

// 	// m := (l - 1) / s

// 	// if m < k {
// 	// 	fmt.Println("OBEY")
// 	// } else {
// 	// 	fmt.Println("REBEL")
// 	// }

// 	lcm := Lcm(l, s)
// 	ll := lcm / l
// 	ss := lcm / s
// 	if ll-1 == 0 {
// 		fmt.Println("OBEY")
// 		return
// 	}

// 	tmp := (ss - 1) / (ll - 1)
// 	if tmp < k {
// 		fmt.Println("OBEY")
// 	} else {
// 		fmt.Println("REBEL")
// 	}
// }

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

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

	return a
}

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

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

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

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

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

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

	return string(res)
}

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

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

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

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

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

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

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

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

var t int
var r, b, k int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		r, b, k = ReadInt3()

		solve()
	}
}

const obey = "OBEY"
const rebel = "REBEL"

func solve() {
	if r < b {
		r, b = b, r
	}

	g := Gcd(r, b)
	m := (r-1-g)/b + 1
	if m < k {
		fmt.Println(obey)
	} else {
		fmt.Println(rebel)
	}
}

// func solve() {
// 	l, s := int64(0), int64(0)
// 	if r > b {
// 		l, s = r, b
// 	} else {
// 		l, s = b, r
// 	}

// 	// m := (l - 1) / s

// 	// if m < k {
// 	// 	fmt.Println("OBEY")
// 	// } else {
// 	// 	fmt.Println("REBEL")
// 	// }

// 	lcm := Lcm(l, s)
// 	ll := lcm / l
// 	ss := lcm / s
// 	if ll-1 == 0 {
// 		fmt.Println("OBEY")
// 		return
// 	}

// 	tmp := (ss - 1) / (ll - 1)
// 	if tmp < k {
// 		fmt.Println("OBEY")
// 	} else {
// 		fmt.Println("REBEL")
// 	}
// }

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

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

	return a
}

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

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

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

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

import (
	"fmt"
	"os"
)

func gcd(x, y int64) int64 {
	if y == 0 {
		return x
	} else {
		return gcd(y, x%y)
	}
}

func main() {
	var n int
	fmt.Fscanln(os.Stdin, &n)
	for i := 0; i < n; i++ {
		var a, b, c int64
		fmt.Fscanln(os.Stdin, &a, &b, &c)
		if a < b {
			a, b = b, a
		}
		//fmt.Println(a, b, c, gcd(a, b))
		if a == b || gcd(a, b)+(c-1)*b >= a {
			fmt.Println("OBEY")
		} else {
			fmt.Println(("REBEL"))
		}
	}
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	Fscan(in, &t)
	for case_ := 0; case_ < t; case_++ {
		if solveCase(in, out) {
			Fprintln(out, "OBEY")
		} else {
			Fprintln(out, "REBEL")
		}
	}
}

func solveCase(in io.Reader, out io.Writer) bool {
	calcGCD := func(a, b int64) int64 {
		for b != 0 {
			a, b = b, a%b
		}
		return a
	}
	//calcLCM := func(a, b int64) int64 {
	//	return a / calcGCD(a, b) * b
	//}

	var a, b, k int64
	Fscan(in, &a, &b, &k)
	if a > b {
		a, b = b, a
	}
	gcd := calcGCD(a, b)
	a /= gcd
	b /= gcd
	if a == b {
		return true
	}
	if b%a == 0 {
		return b/a <= k
	}

	beforeB := b / a * a
	next := beforeB + a
	if next%b == a-1 {
		return b/a <= k-1
	}
	return b/a+1 <= k-1
}

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

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 ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		x, y, z := 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &x, &y, &z)
		// x <= y
		x, y = maxmin(x, y)
		gcdn := gcd(x, y)
		x /= gcdn
		y /= gcdn
		need := int64(x)*int64(z-1) + int64(1)
		real := int64(y - 1)
		if need <= real {
			fmt.Fprintf(out, "REBEL\n")
		} else {
			fmt.Fprintf(out, "OBEY\n")
		}
	}
	return
}

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

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

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 gcd(a,b int)int{
	if b==0{
		return a
	}
	return gcd(b,a%b)
}

func main(){
	defer writer.Flush()
	var T int
	scanf("%d\n",&T)
	for cas:=1;cas<=T;cas++{
		var r,b,k int
		scanf("%d %d %d\n",&r,&b,&k)
		g:=gcd(r,b)
		r/=g
		b/=g
		if(r>b){
			t:=r
			r=b
			b=t
		}
		if (b+r-2)/r>=k {
			printf("REBEL\n")
		}else{
			printf("OBEY\n")
		}
	}
}

package main

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

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

	return s
}

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

	if e == 0 {
		return 1
	}

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

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

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

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

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

	return a
}

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

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

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

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

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

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

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

	return string(res)
}

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

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

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

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

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

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

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

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

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

var t int
var r, b, k int

func main() {
	t = ReadInt()

	for tc := 0; tc < t; tc++ {
		r, b, k = ReadInt3()

		solve()
	}
}

func solve() {
	l, s := 0, 0
	if r > b {
		l, s = r, b
	} else {
		l, s = b, r
	}

	m := (l - 1) / s

	if m < k {
		fmt.Println("OBEY")
	} else {
		fmt.Println("REBEL")
	}
}

/*
- MODは最後にとりましたか？
- ループを抜けた後も処理が必要じゃありませんか？
- 和・積・あまりを求められたらint64が必要ではありませんか？
*/

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

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var t int
	Fscan(in, &t)
	for case_ := 0; case_ < t; case_++ {
		if solveCase(in, out) {
			Fprintln(out, "OBEY")
		} else {
			Fprintln(out, "REBEL")
		}
	}
}

func solveCase(in io.Reader, out io.Writer) bool {
	//calcGCD := func(a, b int64) int64 {
	//	for b != 0 {
	//		a, b = b, a%b
	//	}
	//	return a
	//}
	//calcLCM := func(a, b int64) int64 {
	//	return a / calcGCD(a, b) * b
	//}

	var a, b, k int64
	Fscan(in, &a, &b, &k)
	if a > b {
		a, b = b, a
	}
	if a == b {
		return true
	}
	if b%a==0 {
		return b/a<=k
	}

	beforeB := b / a * a
	next := beforeB + a
	if next%b == a-1 {
		return b/a <= k-1
	}
	return b/a+1 <= k-1
}

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

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 ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}

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 gcd(a,b int)int{
	if b==0{
		return a
	}
	return gcd(b,a%b)
}

func swap(a,b *int){
	t:=a
	a=b
	b=t
}

func main(){
	defer writer.Flush()
	var T int
	scanf("%d\n",&T)
	for cas:=1;cas<=T;cas++{
		var r,b,k int
		scanf("%d %d %d\n",&r,&b,&k)
		g:=gcd(r,b)
		r/=g
		b/=g
		if(r>b){
			swap(&r,&b)
		}
		if (b+r-2)/r>=k {
			printf("REBEL\n")
		}else{
			printf("OBEY\n")
		}
	}
}

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 gcd(a,b int)int{
	if b==0{
		return a
	}
	return gcd(b,a%b)
}

func swap(a,b *int){
	t:=a
	a=b
	b=t
}

func main(){
	defer writer.Flush()
	var T int
	scanf("%d\n",&T)
	for cas:=1;cas<=T;cas++{
		var r,b,k int
		scanf("%d %d %d\n",&r,&b,&k)
		g:=gcd(r,b)
		r/=g
		b/=g
		if(r>b){
			swap(&r,&b)
		}
		if b/r>=k {
			printf("REBEL\n")
		}else{
			printf("OBEY\n")
		}
	}
}

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 gcd(a,b int)int{
	if b==0{
		return a
	}
	return gcd(b,a%b)
}

func swap(a,b *int){
	t:=a
	a=b
	b=t
}

func main(){
	defer writer.Flush()
	var T int
	scanf("%d\n",&T)
	for cas:=1;cas<=T;cas++{
		var r,b,k int
		scanf("%d %d %d\n",&r,&b,&k)
		g:=gcd(r,b)
		r/=g
		b/=g
		if(r>b){
			swap(&r,&b)
		}
		if (b-1)/r>=k {
			printf("REBEL\n")
		}else{
			printf("OBEY\n")
		}
	}
}


There are $$$n$$$ boxes with different quantities of candies in each of them. The $$$i$$$-th box has $$$a_i$$$ candies inside.You also have $$$n$$$ friends that you want to give the candies to, so you decided to give each friend a box of candies. But, you don't want any friends to get upset so you decided to eat some (possibly none) candies from each box so that all boxes have the same quantity of candies in them. Note that you may eat a different number of candies from different boxes and you cannot add candies to any of the boxes.What's the minimum total number of candies you have to eat to satisfy the requirements?

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 50$$$) — the number of boxes you have. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^7$$$) — the quantity of candies in each box.

For each test case, print a single integer denoting the minimum number of candies you have to eat to satisfy the requirements.

NoteFor the first test case, you can eat $$$1$$$ candy from the second box, $$$2$$$ candies from the third box, $$$3$$$ candies from the fourth box and $$$4$$$ candies from the fifth box. Now the boxes have $$$[1, 1, 1, 1, 1]$$$ candies in them and you ate $$$0 + 1 + 2 + 3 + 4 = 10$$$ candies in total so the answer is $$$10$$$.For the second test case, the best answer is obtained by making all boxes contain $$$5$$$ candies in them, thus eating $$$995 + 995 + 0 + 995 + 995 + 995 = 4975$$$ candies in total.

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Fscan(in,&n)
		var list []int = make([]int,n)
		var smallest int = 999999999999
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
			if list[j] < smallest {
				smallest=list[j]
			}
		}
		counter:=0
		for j:=0;j<n;j++{
			counter+=list[j]-smallest
		}
		fmt.Println(counter)
	}
}

package main

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

func main() {
	var (
		t  int
		n  int
		as []string
		a  []int
	)
	fmt.Scanf("%d\n", &t)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < t; i++ {
		sum := 0
		min := 10000000
		a = nil
		scanner.Scan()
		n, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		as = strings.Split(scanner.Text(), " ")
		for j := 0; j < n; j++ {
			temp, _ := strconv.Atoi(as[j])
			if temp < min {
				min = temp
			}
			a = append(a, temp)
		}
		for j := 0; j < n; j++ {
			sum = sum + a[j] - min
		}
		fmt.Println(sum)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func main() {
	var t, n, a int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var sum int64 = 0
		m := 1000000000
		fmt.Fscan(in, &n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a)
			sum += int64(a)
			if a < m {
				m = a
			}
		}
		fmt.Println(sum - int64(n)*int64(m))
	}
}

package main
import (
    "fmt"
    "os"
    "bufio"
)
func main() {
    r := bufio.NewReader(os.Stdin)

    var t int
    fmt.Fscan(r, &t)
    for _i:=0;_i<t;_i++ {
        var n int
        fmt.Fscan(r, &n)
        sum,min := 0,int(1e9)
        for i:=0;i<n;i++ {
            var a int
            fmt.Fscan(r, &a)
            sum+=a
            if min>a {
                min=a
            }
        }
        fmt.Println(sum-min*n)
    }
}

package main

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

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

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

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

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

func nextInt64() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	defer wr.Flush()
	sc.Buffer(make([]byte, 0), 1000000009)
	sc.Split(bufio.ScanWords)

	t := nextInt()
	for i := 0; i < t; i++ {
		solve()
	}
}

func solve() {
	n := nextInt()
	a := make([]int, n)
	sum := 0
	min_v := 1000000009
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		sum += a[i]
		if a[i] < min_v {
			min_v = a[i]
		}
	}

	ans := sum - min_v*n
	out(ans, "\n")
}

package main

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

const maxEl = 3000

func solve() {
	n := get()
	a := geta(n)
	x := min(a...)
	count := L(0)
	for _, y := range a {
		count += L(y - x)
	}
	put64ln(count)
}

const (
	once       = false
	maxBufSize = 10000000
)

var (
	splitFunc = bufio.ScanWords
)

func main() {
	in = bufio.NewScanner(bufio.NewReader(os.Stdin))
	in.Split(splitFunc)
	in.Buffer(make([]byte, maxBufSize), maxBufSize)

	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	if once {
		solve()
		return
	}

	t := get()
	for t > 0 {
		solve()
		t--
	}
}

var (
	in  *bufio.Scanner
	out *bufio.Writer
)

func get() int {
	x, _ := strconv.Atoi(gets())
	return x
}

func geta(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get()
	}
	return a
}

func geta1(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = get() - 1
	}
	return a
}

func get64() int64 {
	x, _ := strconv.ParseInt(gets(), 10, 64)
	return x
}

func get64a(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64()
	}
	return a
}

func get64a1(n int) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = get64() - 1
	}
	return a
}

func getf() float64 {
	x, _ := strconv.ParseFloat(gets(), 64)
	return x
}

func getfa(n int) []float64 {
	a := make([]float64, n)
	for i := range a {
		a[i] = getf()
	}
	return a
}

func gets() string {
	scan()
	return in.Text()
}

func scanN(n int) {
	for n > 0 {
		scan()
		n--
	}
}

func scan() {
	in.Scan()
}

func putc(c rune) {
	out.WriteRune(c)
}

func line() {
	putc('\n')
}

func space() {
	putc(' ')
}

func put(x int) {
	out.WriteString(strconv.Itoa(x))
}

func putln(i int) {
	put(i)
	line()
}

func puta(a []int) {
	for _, v := range a {
		put(v)
		space()
	}
	line()
}

func put64(x int64) {
	out.WriteString(strconv.FormatInt(x, 10))
}

func put64ln(x int64) {
	put64(x)
	line()
}

func put64a(a []int64) {
	for _, v := range a {
		put64(v)
		space()
	}
	line()
}

func puts(s string) {
	out.WriteString(s)
}

func putsln(s string) {
	puts(s)
	line()
}

func yn(y bool) {
	if y {
		yes()
		return
	}
	no()
}

func yes() {
	puts("YES\n")
}

func no() {
	puts("NO\n")
}

func putf(x float64) {
	out.WriteString(strconv.FormatFloat(x, 'f', -1, 64))
}

func putfln(x float64) {
	putf(x)
	line()
}

func putfa(a []float64) {
	for _, v := range a {
		putf(v)
		space()
	}
	line()
}

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

func abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func absf(x float64) float64 {
	return math.Abs(x)
}

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

func max(xs ...int) int {
	r := xs[0]
	for _, x := range xs[1:] {
		r = max1(r, x)
	}
	return r
}

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

func max64(xs ...int64) int64 {
	r := xs[0]
	for _, x := range xs[1:] {
		r = max64_1(r, x)
	}
	return r
}

func maxf1(x float64, y float64) float64 {
	return math.Max(x, y)
}

func maxf(xs ...float64) float64 {
	r := xs[0]
	for _, x := range xs[1:] {
		r = maxf1(r, x)
	}
	return r
}

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

func min(xs ...int) int {
	r := xs[0]
	for _, x := range xs[1:] {
		r = min1(r, x)
	}
	return r
}

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

func min64(xs ...int64) int64 {
	r := xs[0]
	for _, x := range xs[1:] {
		r = min64_1(r, x)
	}
	return r
}

func minf1(x float64, y float64) float64 {
	return math.Min(x, y)
}

func minf(xs ...float64) float64 {
	r := xs[0]
	for _, x := range xs[1:] {
		r = minf1(r, x)
	}
	return r
}

func L(i int) int64 {
	return int64(i)
}

func F(i int) float64 {
	return float64(i)
}

func ints(n int, val int) (a []int) {
	a = make([]int, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func int64s(n int, val int64) (a []int64) {
	a = make([]int64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

func floats(n int, val float64) (a []float64) {
	a = make([]float64, n)
	if val == 0 {
		return
	}
	for i := range a {
		a[i] = val
	}
	return
}

package main

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

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

	n := readInt(in)
	for i := 0; i < n; i++ {
		solution(in, out)
	}
}

func solution(in *bufio.Reader, out *bufio.Writer) {
	readInt(in)
	arr := readArrInt(in)
	// find minimum value in arr
	min := arr[0]
	for _, v := range arr {
		if v < min {
			min = v
		}
	}

	sum := 0
	for _, v := range arr {
		sum += v - min
	}

	out.WriteString(strconv.Itoa(sum) + "\n")

}

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 {
	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 (
	"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, x, sum, min int = 0, 0, 0, 1e7
	scan(&n)

	for i := 0; i < n; i++ {
		scan(&x)
		sum += x
		if min > x {
			min = x
		}
	}
	printf("%d\n", sum-min*n)
}
func main() {
	defer out.Flush()
	n := 0
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

const (
	MaxInt32 = 1 << 31 - 1
)

func main(){
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	for t > 0 {
		var n int
		fmt.Fscan(cin, &n)
		a := make([]int, n)
		min := MaxInt32
		for i := 0; i < n; i++ {
			fmt.Fscan(cin, &a[i])
			if a[i] < min {
				min = a[i]
			}
		}
		ans := 0
		for _, v := range a {
			ans += v - min
		}
		fmt.Println(ans)
		 t -= 1
	}
}

package main

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

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

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

func main() {
	defer out.Flush()

	var tc int
	fmt.Fscan(in, &tc)
	for ; tc > 0; tc-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		x := int(2e9)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
			x = min(x, a[j])
		}
		ans := 0
		for _, k := range a {
			ans += k - x
		}
		fmt.Println(ans)
	} //fim do loop de test cases
} // fim main

package main

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

func main_edu_128_A() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n int
		Fscan(in, &n)
		var total, candy int
		var min = int(1e9)
		for i := 0; i < n; i++ {
			Fscan(in, &candy)
			total += candy
			if min > candy {
				min = candy
			}
		}
		Fprintln(out, total-n*min)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() {
	main_edu_128_A()
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1676B
Date: 12/05/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1676/B
Problem: CF1676B
**/
func (in *CF1676B) Run() {
	for t := in.NextInt(); t > 0; t-- {
		n := in.NextInt()
		min := 999999999
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			val := in.NextInt()
			arr[i] = val
			if val < min {
				min = val
			}
		}
		ans := 0

		for i := 0; i < n; i++ {
			ans += arr[i] - min
		}
		fmt.Println(ans)
	}

}

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

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

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 min(v []int) int {
	var m int
	for i, e := range v {
		if i == 0 || e < m {
			m = e
		}
	}
	return m
}

func main() {
	defer writer.Flush()

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

	for i := 0; i < t; i++ {
		scanf("%d\n", &n)
		tab := make([]int, n)
		for j := 0; j < n; j++ {
			scanf("%d", &tab[j])
		}
		scanf("\n")
		min_v := min(tab)
		sum_v := 0
		for _, v := range tab {
			sum_v += v - min_v
		}
		printf("%d\n", sum_v)
	}
}

package main

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

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

	var T int
	for fmt.Fscan(in, &T); T > 0; T-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		min := func(x, y int) int {
			if x < y {
				return x
			}
			return y
		}
		var mn int = 1e7 + 1
		for i := 0;i < n; i++ {
			fmt.Fscan(in, &a[i])
			mn = min(mn, a[i])
		}
		ans := 0
		for _, v := range a {
			ans += v - mn
		}
		fmt.Fprintln(out, ans)
	}
}

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

package main

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

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

func solve(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		a := make([]int, n)
		s := 0
		mn := math.MaxInt
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
			if a[i] < mn {
				mn = a[i]
			}
			s += a[i]
		}
		fmt.Fprintln(out, s-(n*mn))
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	for fmt.Fscan(in, &t); t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}
		min := arr[0]
		for _, v := range arr {
			if v < min {
				min = v
			}
		}
		sum := 0
		for _, v := range arr {
			sum += v - min
		}
		fmt.Fprintln(out, sum)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	testCases, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < testCases; i++ {
		scanner.Scan()
		scanner.Scan()
		nums := strings.Split(scanner.Text(), " ")
		numsInts := make([]int, len(nums))
		minimum := math.MaxInt
		for idx := 0; idx < len(nums); idx++ {
			n, _ := strconv.Atoi(nums[idx])
			numsInts[idx] = n
			if n < minimum {
				minimum = n
			}
		}

		total := 0
		for idx := 0; idx < len(numsInts); idx++ {
			total += numsInts[idx] - minimum
		}
		fmt.Println(total)
	}
}

package main

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

func main() {
	var (
		t int
	)

	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d\n", &t)

	for t > 0 {
		t--

		text, _ := reader.ReadString('\n')
		ninps := strings.Fields(text)
		n, _ := strconv.Atoi(ninps[0])

		x := make([]int, n)
		smallest := math.MaxInt32

                text, _ = reader.ReadString('\n')
		ninps = strings.Fields(text)
		for i, val := range ninps {
			x[i], _ = strconv.Atoi(val)
			if x[i] < smallest {
				smallest = x[i]
			}
		}

		cnt := 0
		for i := 0; i < n; i++ {
			if x[i] - smallest != 0 {
				cnt += (x[i]-smallest)
			}
		}
		fmt.Println(cnt)
	}
}

package main

import (
	"bufio"
	"flag"
	"fmt"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"strings"
	"sort"
)

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	in := bufio.NewReader(os.Stdin)
	testCases := readInt(in)

	for i := 0; i < testCases; i++ {
		friendsCount := readInt(in)
		friends := readInts(in)
		sort.Ints(friends)
		result := 0
		for i := 1; i < friendsCount; i++ {
			result += (friends[i]-friends[0])
		}

		fmt.Println(result)
	}
}

func stringToInts(s string) []int {
	result := []int{}
	for _, r := range s {
		val, _ := strconv.Atoi(string(r))
		result = append(result, val)
	}

	return result
}

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 readStr(in *bufio.Reader) string {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return nStr
}

func readStrToInts(in *bufio.Reader) []int {
	nStr, _ := in.ReadString('\n')
	nStr = strings.ReplaceAll(nStr, "\r", "")
	nStr = strings.ReplaceAll(nStr, "\n", "")
	return stringToInts(nStr)
}

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 readInts(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 readInt64s(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"
	"bufio"
	"os"
)

func main(){
	//var v []int = make([] int, 200000)
	var t int
	Reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(Reader, &t)
	for ;t>0; t--{
		var n int
		fmt.Fscan(Reader, &n)
		arr := make([]int, n)
		sum := int64(0)
		mi:=100000000
		for i:=0;i<n;i++{
			fmt.Fscan(Reader, &arr[i])
			if arr[i] < mi{
				mi = arr[i]
			}
			sum += int64(arr[i])
		}
		fmt.Println(sum - int64(mi) * int64(n))
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var N,T,Q,sum,min int

	fmt.Fscan(in, &N)
	//m := make([]int,N)
	//num := make(map[int]int)
	for i := 0;i < N;i++{
		min = 100000000
		sum = 0
		fmt.Fscan(in, &T)
		for j := 0;j < T;j++{
			fmt.Fscan(in, &Q)
			sum += Q
			if min > Q{
				min = Q
			}
		}
		fmt.Println(sum - min*T)
	}
}

package main

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

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

func B(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	for k := 0; k < t; k++ {
		n := 0
		mi := uint64(10e9)
		ans := uint64(0)
		fmt.Fscan(in, &n)
		a := make([]uint64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
			mi = min(mi, a[i])
		}
		for i := 0; i < n; i++ {
			ans += a[i] - mi
		}
		fmt.Fprintln(out, ans)
	}
}

func min(i, j uint64) uint64 {
	if i < j {
		return i
	}
	return j
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)
func slove() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	m := int(1e8)
	sum := 0
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
		if nums[i] < m {
			m = nums[i]
		}
		sum += nums[i]
	}
	fmt.Fprintln(w, sum-m*n)
}

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

package main

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

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

func b1676(_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)
		ans := 0
		mi := 1 << 30
		row := []int{}
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			if x < mi {
				mi = x
			}
			row = append(row, x)
		}
		for _, v := range row {
			ans += v - mi
		}

		Fprintln(out, ans)
	}
}

package main

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

//goland:noinspection GoUnusedFunction
func min(a int, nums ...int) int {
	min := a

	for _, num := range nums {
		if num < min {
			min = num
		}
	}
	return min
}

//goland:noinspection GoUnusedFunction
func max(a int, nums ...int) int {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func maxFloat(a float64, nums ...float64) float64 {
	max := a

	for _, num := range nums {
		if num > max {
			max = num
		}
	}
	return max
}

//goland:noinspection GoUnusedFunction
func fprintlnArr(w io.Writer, arr []int) {
	for _, val := range arr {
		fmt.Fprint(w, val, " ")
	}
	fmt.Fprintln(w)
}

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

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

		arr := make([]int, n)
		minNum := math.MaxInt
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
			minNum = min(minNum, arr[i])
		}
		sum := 0
		for i := 0; i < n; i++ {
			sum += arr[i] - minNum
		}

		fmt.Fprintln(out, sum)
	}
}

package main

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

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

func solve() string {
	var n int
	fmt.Fscan(in, &n)
	var values = make([]int, n)
	var min = 10000001
	for i := range values {
		fmt.Fscan(in, &values[i])
		if values[i] < min {
			min = values[i]
		}
	}

	var res int64
	for i := range values {
		res += int64(values[i] - min)
	}

	return strconv.FormatInt(res, 10)
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

package main

import (
	"bufio"
	"fmt"
	"math"
	"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 int64
		fmt.Fscan(in, &n)

		var sum int64
		min := int64(math.MaxInt64)
		for i := int64(0); i < n; i++ {
			var v int64
			fmt.Fscan(in, &v)

			sum += v
			if v < min {
				min = v
			}
		}

		fmt.Fprintln(out, sum-(min*n))
	}
}

package main

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

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

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		mi := int(1e9)
		for _, v := range a {
			if v < mi {
				mi = v
			}
		}
		s := 0
		for _, v := range a {
			s+=v-mi
		}
		Fprintln(out, s)
	}

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

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

}

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var list []int = make([]int,n)
		var smallest int = 999999999999
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
			if list[j] < smallest {
				smallest=list[j]
			}
		}
		counter:=0
		for j:=0;j<n;j++{
			counter+=list[j]-smallest
		}
		fmt.Println(counter)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	var t int
	var in = bufio.NewReader(os.Stdin)
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var list []int
		var smallest int = 999999999999
		for j:=0;j<n;j++{
			var holder int
			fmt.Fscan(in,&holder)
			list = append(list,holder)
			if holder < smallest {
				smallest=holder
			}
		}
		counter:=0
		for j:=0;j<n;j++{
			counter+=list[j]-smallest
		}
		fmt.Println(counter)
	}
}

package main

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

func main() {
	var (
		t  int
		n  int
		as []string
		a  []int
	)
	fmt.Scanf("%d\n", &t)
	scanner := bufio.NewScanner(os.Stdin)
	for i := 0; i < t; i++ {
		sum := 0
		min := 10000000
		a = nil
		scanner.Scan()
		n, _ = strconv.Atoi(scanner.Text())
		scanner.Scan()
		as = strings.Split(scanner.Text(), " ")
		for j := 0; j < n; j++ {
			temp, _ := strconv.Atoi(as[j])
			if temp < min {
				min = temp
			}
			a = append(a, temp)
		}
		for j := 0; j < n; j++ {
			sum = sum + a[j] - min
		}
		println(sum)
	}
}


Tyndex is again well ahead of the rivals! The reaction to the release of Zoozle Chrome browser was the release of a new browser Tyndex.Brome!The popularity of the new browser is growing daily. And the secret is not even the Tyndex.Bar installed (the Tyndex.Bar automatically fills the glass with the finest 1664 cognac after you buy Tyndex.Bottles and insert in into a USB port). It is highly popular due to the well-thought interaction with the user.Let us take, for example, the system of automatic address correction. Have you entered codehorses instead of codeforces? The gloomy Zoozle Chrome will sadly say that the address does not exist. Tyndex.Brome at the same time will automatically find the closest address and sent you there. That's brilliant!How does this splendid function work? That's simple! For each potential address a function of the F error is calculated by the following rules:  for every letter ci from the potential address c the closest position j of the letter ci in the address (s) entered by the user is found. The absolute difference |i - j| of these positions is added to F. So for every i (1 ≤ i ≤ |c|) the position j is chosen such, that ci = sj, and |i - j| is minimal possible.  if no such letter ci exists in the address entered by the user, then the length of the potential address |c| is added to F. After the values of the error function have been calculated for all the potential addresses the most suitable one is found. To understand the special features of the above described method better, it is recommended to realize the algorithm of calculating the F function for an address given by the user and some set of potential addresses. Good luck!

The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 105). They are the number of potential addresses and the length of the address entered by the user. The next line contains k lowercase Latin letters. They are the address entered by the user (s). Each next i-th (1 ≤ i ≤ n) line contains a non-empty sequence of lowercase Latin letters. They are the potential address. It is guaranteed that the total length of all the lines does not exceed 2·105.

On each n line of the output file print a single number: the value of the error function when the current potential address is chosen. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).

9 9
vkontakte
vcontacte
vkontrakte
vkollapse
vkrokodile
vtopke
vkapuste
vpechke
vk
vcodeforcese

package main

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

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

  line, _ := reader.ReadString('\n')
  var n, k int
  fmt.Sscanf(line, "%d %d", &n, &k)
  line, _ = reader.ReadString('\n')
  given := strings.TrimSpace(line)
  m := len(given)

  contains := make([]bool, 26)
  distance := make([][]int, 26)
  for i := range contains {
    ch := 'a' + byte(i)
    positions := []int{}
    for pos := range given {
      if given[pos] == ch {
        positions = append(positions, pos)
      }
    }
    if len(positions) == 0 {
      continue
    }
    contains[i] = true
    distance[i] = make([]int, m)
    for j := 1; j < len(positions); j++ {
      a, b := positions[j - 1], positions[j]
      mid := (a + b) / 2
      for k := a; k <= mid; k++ {
        distance[i][k] = k - a
      }
      for k := mid + 1; k <= b; k++ {
        distance[i][k] = b - k
      }
    }
    for k := positions[0] - 1; k >= 0; k-- {
      distance[i][k] = distance[i][k + 1] + 1
    }
    for k := positions[len(positions) - 1] + 1; k < m; k++ {
      distance[i][k] = distance[i][k - 1] + 1
    }
  }

  for i := 0; i < n; i++ {
    line, _ = reader.ReadString('\n')
    candidate := strings.TrimSpace(line)
    error := int64(0)

    for pos, ch := range candidate {
      c := int(ch - 'a')
      delta := 0
      if !contains[c] {
        delta = len(candidate)
      } else {
        extend := 0
        if pos >= m {
          extend = pos - m + 1
          pos = m - 1
        }
        delta = distance[c][pos] + extend
      }
      error += int64(delta)
    }

    writer.WriteString(fmt.Sprintf("%d\n", error))
  }

}


The only difference between the easy and the hard versions is the maximum value of $$$k$$$.You are given an infinite sequence of form "112123123412345$$$\dots$$$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $$$1$$$ to $$$1$$$, the second one — from $$$1$$$ to $$$2$$$, the third one — from $$$1$$$ to $$$3$$$, $$$\dots$$$, the $$$i$$$-th block consists of all numbers from $$$1$$$ to $$$i$$$. So the first $$$56$$$ elements of the sequence are "11212312341234512345612345671234567812345678912345678910". Elements of the sequence are numbered from one. For example, the $$$1$$$-st element of the sequence is $$$1$$$, the $$$3$$$-rd element of the sequence is $$$2$$$, the $$$20$$$-th element of the sequence is $$$5$$$, the $$$38$$$-th element is $$$2$$$, the $$$56$$$-th element of the sequence is $$$0$$$.Your task is to answer $$$q$$$ independent queries. In the $$$i$$$-th query you are given one integer $$$k_i$$$. Calculate the digit at the position $$$k_i$$$ of the sequence.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. The $$$i$$$-th of the following $$$q$$$ lines contains one integer $$$k_i$$$ $$$(1 \le k_i \le 10^9)$$$ — the description of the corresponding query.

Print $$$q$$$ lines. In the $$$i$$$-th line print one digit $$$x_i$$$ $$$(0 \le x_i \le 9)$$$ — the answer to the query $$$i$$$, i.e. $$$x_i$$$ should be equal to the element at the position $$$k_i$$$ of the sequence.

NoteAnswers on queries from the first example are described in the problem statement.

package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)
var input *bufio.Reader

// binary search to find subarray
func find(arr []int64, target int64) int {
    low := 0
    high := len(arr) - 1

    for low<high {
        mid := (high + low) / 2

        if arr[mid] < target {
            low = mid + 1
        } else {
            high = mid
        }
    }
    // get the index of the subarray
    return low
}

// Codeforce 1177B
func solve1177b(target int64){
    var (
        total int64
        numbers int64
        digits int64
        start int64
        totalNumbers int64
        count int64
        Num int64
        d int64
        numString string
        i int64
    )
    numbers = 9
    totalNumbers = 0

    for i=1; i<13 ; i++ {
        total += i*numbers
        if total >= target {
            digits = i
            break
        }
        totalNumbers += numbers
        start = total
        numbers *= 10
    }
    //fmt.Println(target,start,digits,totalNumbers)
    // find number
    count = (target - start) / digits
    if (target - start) % digits != 0 {
        count += 1
    }
    Num = totalNumbers + count
    // find the specific digit in Num
    d = (target - start) % digits
    if d==0 {
        d = digits
    }
    numString = strconv.FormatInt(Num, 10)
    fmt.Printf("%c\n", []rune(numString)[d-1])
}

func solve(arr []int64) {
    var (
        target int64
        idx int
        diff int64
    )
    fmt.Fscanf(input, "%d\n", &target)
    idx = find(arr,target)

    diff = target - arr[idx-1]
    solve1177b(diff)
}

func main () {
    input = bufio.NewReader(os.Stdin)
    var (
        T int
        s int64
        total int64
    )
    fmt.Fscanf(input, "%d\n", &T)
    arr := make([]int64, 50000)
    for i:=1; i<50000 ; i++ {
        if i<=9 {
            s += 1
        } else if i>=10 && i<=99 {
            s += 2
        } else if i>=100 && i<=999 {
            s += 3
        } else if i>=1000 && i<=9999 {
            s += 4
        } else if i>=10000 {
            s += 5
        }
        total += s
        arr[i] = total
    }
    for i:=0; i<T; i++ {
        solve(arr)
    }
}