Stanley defines the beauty of an array $$$a$$$ of length $$$n$$$, which contains non-negative integers, as follows: $$$$$$\sum\limits_{i = 1}^{n} \left \lfloor \frac{a_{i}}{k} \right \rfloor,$$$$$$ which means that we divide each element by $$$k$$$, round it down, and sum up the resulting values.Stanley told Sam the integer $$$k$$$ and asked him to find an array $$$a$$$ of $$$n$$$ non-negative integers, such that the beauty is equal to $$$b$$$ and the sum of elements is equal to $$$s$$$. Help Sam — find any of the arrays satisfying the conditions above.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains integers $$$n$$$, $$$k$$$, $$$b$$$, $$$s$$$ ($$$1 \leq n \leq 10^{5}$$$, $$$1 \leq k \leq 10^{9}$$$, $$$0 \leq b \leq 10^{9}$$$, $$$0 \leq s \leq 10^{18}$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print $$$-1$$$ if such array $$$a$$$ does not exist. Otherwise print $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_{i} \leq 10^{18}$$$) — the answer.

NoteIn the first, the second, the fifth and the sixth test cases of the example it is possible to show that such array does not exist.In the third testcase of the example $$$a = [0, 0, 19]$$$. The sum of elements in it is equal to 19, the beauty of it is equal to $$$\left ( \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{19}{6} \right \rfloor \right ) = (0 + 0 + 3) = 3$$$.In the fourth testcase of the example $$$a = [0, 3, 3, 3, 29]$$$. The sum of elements in it is equal to $$$38$$$, the beauty of it is equal to $$$(0 + 0 + 0 + 0 + 7) = 7$$$.

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k, b, s int64
		fmt.Fscan(reader, &n, &k, &b, &s)

		if s < b*k || s > b*k+(k-1)*n {
			write(f, "-1\n")
		} else {
			rem := s - b*k
			start := b * k
			if rem > (n-1)*(k-1) {
				start += rem - (n-1)*(k-1)
				rem = (n - 1) * (k - 1)
			}
			write(f, start)

			for i := 1; i < int(n); i++ {
				if rem >= k-1 {
					write(f, " ", k-1)
					rem -= k - 1
				} else if rem > 0 {
					write(f, " ", rem)
					rem = 0
				} else {
					write(f, " ", 0)
				}

			}
			write(f, "\n")
		}

	}
}

package main

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

func main() {
	var t int
	fmt.Scanln(&t)
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	for i := 0; i < t; i++ {
		var x = getIntln(reader)
		var n, k, b, s = x[0], x[1], x[2], x[3]
		s -= k * b
		if s < 0 {
			writer.WriteString("-1\n")
		} else {
			var res = make([]int, n)
			res[0] = k * b
			for j := 0; j < n; j++ {
				var now = min(s, k-1)
				res[j] += now
				s -= now
			}
			if s > 0 {
				writer.WriteString("-1\n")
			} else {
				var resString = fmt.Sprint(res)
				writer.WriteString(resString[1:len(resString)-1] + "\n")
			}
		}
	}
	writer.Flush()
}

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

func getIntln(in *bufio.Reader) []int {
	var x = strings.Split(getString(in), " ")
	var res = make([]int, len(x))
	for k, v := range x {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}

func getString(in *bufio.Reader) string {
	var s, _ = in.ReadString('\n')
	s = strings.TrimSpace(s)
	return s
}

package main

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

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

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

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

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
    n, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
    k, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
    b, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
    s, _ := strconv.Atoi(scanner.Text())

		if s-n*(k-1) <= k*b && k*b <= s {
      sum := k * b
      toPrint := sum
      for i := 0; i < n; i++ {
        next := min(s - sum, k - 1)
        sum += next
        wr.WriteString(strconv.Itoa(toPrint + next)+ " ")
        toPrint = 0
      }
			wr.WriteString("\n")
		} else {
			wr.WriteString(strconv.Itoa(-1) + "\n")
		}
	}
}

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

package main

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

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

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

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

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		b, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		s, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		if s-n*(k-1) <= k*b && k*b <= s {
			if k == 1 {
				wr.WriteString(strconv.FormatInt(b, 10) + " ")
				var i int64
				for i = 0; i < n-1; i++ {
					wr.WriteString(strconv.Itoa(0) + " ")
				}
			} else {
				sm := (s - k*b) / (k - 1)
				sr := (s - k*b) % (k - 1)
				var i int64
				if sm == n {
					wr.WriteString(strconv.FormatInt(k*b+k-1, 10) + " ")
					for i = 0; i < n-1; i++ {
						wr.WriteString(strconv.FormatInt(k-1, 10) + " ")
					}
				} else {
					wr.WriteString(strconv.FormatInt(k*b+sr, 10) + " ")
					for i = 0; i < sm; i++ {
						wr.WriteString(strconv.FormatInt(k-1, 10) + " ")
					}
					for i = 0; i < n-sm-1; i++ {
						wr.WriteString("0 ")
					}
				}
			}
			wr.WriteString("\n")
		} else {
			wr.WriteString(strconv.Itoa(-1) + "\n")
		}
	}
}

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

package main

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

const MOD int64 = 1000000007

var n, k, b, s int64

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var w *bufio.Writer

func main() {

	read := bufio.NewReader(os.Stdin)

	w = bufio.NewWriter(os.Stdout)

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

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &k, &b, &s)

		solve()

		fmt.Fprintln(w)

		w.Flush()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {

	var max int64 = s/k

	vv := (k - 1) * n

	var min int64

	if vv >= s {
		min = 0
	}

	if vv > s {
		min = 0
	} else {

		diffS := s - vv

		r := diffS % k

		if r != 0 {
			diffS += k - r
		}
		min = diffS/k
	}

	if b < min || b > max {
		fmt.Fprint(w, -1)
		return
	}

	rest := s - b * k

	arr := make([]int64, n)

	arr[0] = b * k

	for i := 1; i < int(n); i++ {
		arr[i] = 0
	}

	for i := 0; i < int(n); i++ {
		if rest >= k - 1 {
			arr[i] += (k - 1)
			rest -= (k - 1)
		} else {
			arr[i] += rest
			rest = 0
		}
	}

	for i := 0; i < int(n); i++ {
		fmt.Fprint(w, arr[i], " ")
	}
}

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

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

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

// func min3(a, b, c int) int {
// 	return min(min(a, b), c)
// }

// func maxSquare(a int) int {
// 	tmp := int(math.Sqrt(float64(a)))
// 	if tmp*tmp == a {
// 		return tmp * tmp
// 	} else {
// 		return (tmp + 1) * (tmp + 1)
// 	}
// }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n, k, b, s int64
		fmt.Fscan(in, &n, &k, &b, &s)
		nstart := n
		first := true
		if (s >= (b * k)) && (s <= (k-1)*n+b*k) {
			for i := 0; i < int(nstart); i++ {
				elem := int64(0)
				if first {
					elem += b * k
					first = false
				}
				s -= elem
				s2 := s - (k - 1)
				if (s2 >= 0) && (s2 <= (k-1)*(n-1)) {
					s = s2
					n--
					elem += k - 1
				} else {
					elem += s
					s = 0
				}
				fmt.Fprintf(out, "%d ", elem)
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out, "-1")
		}
	}
}

package main

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

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

	return b
}

func main() {
	// f, _ := os.Open("input.txt")
	var reader = bufio.NewReader(os.Stdin)
	// var reader = bufio.NewReader(f)
	var tests int
	fmt.Fscan(reader, &tests)
	for t := 0; t < tests; t++ {
		var n, k, b int
		var s int64
		fmt.Fscan(reader, &n)
		fmt.Fscan(reader, &k)
		fmt.Fscan(reader, &b)
		fmt.Fscan(reader, &s)
		var result = make([]int64, n)
		var first int64 = int64(k) * int64(b + 1) - 1
		if b == 0 {
			first = int64(k - 1)
		}
		if first > s {
			if s < int64(k) * int64(b) {
				fmt.Println(-1)
				continue
			}
			first = s
		}
		result[0] = first
		s -= first
		for i := 1; i < n; i++ {
			var next int64 = int64(k) - 1
			if s < next {
				next = s
			}

			result[i] = next
			s -= next
		}

		if s > 0 {
			fmt.Println(-1)
			continue
		}

		for i := 0; i < n; i++ {
			fmt.Print(result[i], " ")
		}

		fmt.Println()
	}
}

package main

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

var (
	reader bufio.Reader
	writer bufio.Writer
)

func main() {
	inp, err := os.Open("in.txt")
	if err == nil {
		os.Stdin = inp
		outp, _ := os.Create("out.txt")
		os.Stdout = outp
		defer outp.Close()
		defer inp.Close()
	}
	reader = *bufio.NewReader(os.Stdin)
	writer = *bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	scan(&T)

	for ; T > 0; T-- {
		var n int
		var k, b, s int64
		scan(&n, &k, &b, &s)

		if s < b * k {
			printf("-1\n")
			continue
		}

		arr := make([]int64, n)
		arr[0] = int64(b) * int64(k)
		s -= int64(b) * int64(k)
		for i := 1; i < n; i++ {
			if s >= k - 1 {
				arr[i] = int64(k - 1)
			} else {
				arr[i] = int64(s)
				s = 0
				break
			}
			s -= k - 1
		}

		if s > k - 1 {
			printf("-1\n")
			/*for i := 0; i < n; i++ {
				printf("%v ", arr[i])
			}
			printf("\n")*/
		} else {
			arr[0] += int64(s)
			for i := 0; i < n; i++ {
				printf("%v ", arr[i])
			}
			printf("\n")
		}
	}
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(&reader, a...)
}

func printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(&writer, format, a...)
}

package main

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

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

func qwq() {
	var n, k, b, s int64
	fmt.Fscan(in, &n, &k, &b, &s)
	a := make([]int64, n)
	a[0] = s
	cnt := s / k
	if cnt < b {
		fmt.Fprintln(out, -1)
	} else {
		idx := 1
		for int64(idx) < n && a[0]/k > b {
			a[idx] = k - 1
			a[0] -= a[idx]
			idx++
		}
		if int64(idx) == n && a[0]/k > b {
			fmt.Fprintln(out, -1)
		} else {
			sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
			for _, x := range a {
				fmt.Fprint(out, x, " ")
			}
			fmt.Fprintln(out)
		}
	}
}

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

package main

import (
	"fmt"
)

func can_do(n, k, b, s int64) bool {
	rem := s - b*k
	return rem >= 0 && rem <= n*(k-1)
}

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

	for ; t > 0; t-- {
		var n, k, b, s int64
		fmt.Scanf("%d %d %d %d\n", &n, &k, &b, &s)

		if can_do(n, k, b, s) {
			arr := make([]int64, n)
			arr[0] = b * k

			rem := s - arr[0]
			for i := range arr {
				if rem > k-1 {
					arr[i] += k - 1
					rem -= k - 1
				} else {
					arr[i] += rem
					break
				}
			}

			for i := range arr {
				fmt.Printf("%d ", arr[i])
			}
			fmt.Println()
		} else {
			fmt.Println("-1")
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var TC int
	fmt.Scanf("%d\n", &TC)
	for tc := 0; tc < TC; tc += 1 {
		var k, b, s uint64
		var n int
		fmt.Scanf("%d %d %d %d\n", &n, &k, &b, &s)

		curr_s := s
		out := make([]uint64, n)
		for i := 0; i < n; i += 1 {
			out[i] = 0
		}

		can := true
		for i := 0; i < n; i += 1 {
			if curr_s/k > b {
				if k-1 <= curr_s {
					out[i] = k - 1
					curr_s -= k - 1
				} else {
					can = false
					break
				}
			} else if curr_s/k < b {
				can = false
				break
			} else {
				out[i] = curr_s
				curr_s = 0
				break
			}
		}

		if curr_s > 0 {
			can = false
		}

		if !can {
			fmt.Printf("-1\n")
		} else {
			fmt.Printf("%v", out[0])
			for i := 1; i < n; i += 1 {
				fmt.Printf(" %v", out[i])
			}
			fmt.Printf("\n")
		}
	}
}

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 int
		var k, b, s int64
		fmt.Fscan(in, &n, &k, &b, &s)

		if k*b > s {
			fmt.Fprintln(out, -1)
			continue
		}

		aa := make([]int64, n)
		aa[0] = k * b
		s -= k * b
		for i := 0; i < n; i++ {
			if s == 0 {
				break
			}
			aa[i] += min(k-1, s)
			s -= min(k-1, s)
		}
		if s > 0 {
			fmt.Fprintln(out, -1)
		} else {
			for _, v := range aa {
				fmt.Fprintf(out, "%d ", v)
			}
			fmt.Fprintln(out)
		}
	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k, b, s int64
		fmt.Fscan(reader, &n, &k, &b, &s)
		min_sum := b * k
		if t == 182 {
			fmt.Println("start", n, k, b, s)
		}
		if s < min_sum && min_sum > 0 {
			write(f, "-1\n")
		} else {
			rem := s - min_sum
			if rem > (k-1)*(n-1) && min_sum > 0 || rem > (k-1)*n {
				write(f, "-1\n")
			} else {
				start := 0
				if min_sum > 0 {
					write(f, min_sum)
					start = 1
				}
				for i := start; i < int(n); i++ {
					if rem >= k-1 {
						write(f, " ", k-1)
						rem -= k - 1
					} else if rem > 0 {
						write(f, " ", rem)
						rem = 0
					} else {
						write(f, " ", 0)
					}

				}
				write(f, "\n")
			}
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k, b, s int64
		fmt.Fscan(reader, &n, &k, &b, &s)
		min_sum := b * k

		if s < min_sum && min_sum > 0 {
			write(f, "-1\n")
		} else {
			rem := s - min_sum
			if rem > (k-1)*(n-1) && min_sum > 0 || rem > (k-1)*n {
				write(f, "-1\n")
			} else {
				start := 0
				if min_sum > 0 {
					write(f, min_sum)
					start = 1
				}
				for i := start; i < int(n); i++ {
					if rem >= k-1 {
						write(f, " ", k-1)
						rem -= k - 1
					} else if rem > 0 {
						write(f, " ", rem)
						rem = 0
					} else {
						write(f, " ", 0)
					}

				}
				write(f, "\n")
			}
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k, b, s int64
		fmt.Fscan(reader, &n, &k, &b, &s)
		min_sum := b * k
		if b == 0 {
			for i := 0; i < int(n); i++ {
				write(f, 0)
				if i == int(n-1) {
					write(f, "\n")
				} else {
					write(f, " ")
				}
			}

		} else if s < min_sum {
			write(f, "-1\n")
		} else {
			rem := s - min_sum
			if rem > (k-1)*(n-1) {
				write(f, "-1\n")
			} else {
				write(f, min_sum)
				for i := 1; i < int(n); i++ {
					if rem >= k-1 {
						write(f, " ", k-1)
						rem -= k - 1
					} else if rem > 0 {
						write(f, " ", rem)
						rem = 0
					} else {
						write(f, " ", 0)
					}

				}
				write(f, "\n")
			}
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k, b, s int64
		fmt.Fscan(reader, &n, &k, &b, &s)
		min_sum := b * k
		if t == 136 {
			fmt.Println("start", n, k, b, s)
		}
		if s < min_sum {
			write(f, "-1\n")
		} else {
			rem := s - min_sum
			if rem > (k-1)*(n-1) {
				write(f, "-1\n")
			} else {
				write(f, min_sum)
				for i := 1; i < int(n); i++ {
					if rem >= k-1 {
						write(f, " ", k-1)
						rem -= k - 1
					} else if rem > 0 {
						write(f, " ", rem)
						rem = 0
					} else {
						write(f, " ", 0)
					}

				}
				write(f, "\n")
			}
		}

	}
}

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var n, k, b, s int64
		fmt.Fscan(reader, &n, &k, &b, &s)
		min_sum := b * k
		if s < min_sum {
			write(f, "-1\n")
		} else {
			rem := s - min_sum
			if rem > (k-1)*(n-1) {
				write(f, "-1\n")
			} else {
				write(f, min_sum)
				for i := 1; i < int(n); i++ {
					if rem >= k-1 {
						write(f, " ", k-1)
						rem -= k - 1
					} else if rem > 0 {
						write(f, " ", rem)
						rem = 0
					} else {
						write(f, " ", 0)
					}

				}
				write(f, "\n")
			}
		}

	}
}

package main

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

func main() {
	var t int
	fmt.Scanln(&t)
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	for i := 0; i < t; i++ {
		var x = getIntln(reader)
		var n, k, b, s = x[0], x[1], x[2], x[3]
		if s < 0 {
			writer.WriteString("-1\n")
		} else {
			var res = make([]int, n)
			res[0] = k * b
			s -= k * b
			for j := 0; j < n; j++ {
				res[j] += min(s, k-1)
				s -= res[j]
			}
			if s > 0 {
				writer.WriteString("-1\n")
			} else {
				var resString = fmt.Sprint(res)
				writer.WriteString(resString[1:len(resString)-1] + "\n")
			}
		}
	}
	writer.Flush()
}

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

func getIntln(in *bufio.Reader) []int {
	var x = strings.Split(getString(in), " ")
	var res = make([]int, len(x))
	for k, v := range x {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}

func getString(in *bufio.Reader) string {
	var s, _ = in.ReadString('\n')
	s = strings.TrimSpace(s)
	return s
}

package main

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

func main() {
	var t int
	fmt.Scanln(&t)
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	for i := 0; i < t; i++ {
		var x = getIntln(reader)
		var n, k, b, s = x[0], x[1], x[2], x[3]
		if s < k*b || s > k*b+(k-1)*n {
			writer.WriteString("-1\n")
		} else {
			var res = make([]int, n)
			res[0] = k * b
			s -= k * b
			for j := 1; j < n; j++ {
				res[j] = min(s, k-1)
				s -= res[j]
			}
			if s > 0 {
				writer.WriteString("-1\n")
			} else {
				var resString = fmt.Sprint(res)
				writer.WriteString(resString[1:len(resString)-1] + "\n")
			}
		}
	}
	writer.Flush()
}

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

func getIntln(in *bufio.Reader) []int {
	var x = strings.Split(getString(in), " ")
	var res = make([]int, len(x))
	for k, v := range x {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}

func getString(in *bufio.Reader) string {
	var s, _ = in.ReadString('\n')
	s = strings.TrimSpace(s)
	return s
}

package main

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

func main() {
	var t int
	fmt.Scanln(&t)
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	for i := 0; i < t; i++ {
		var x = getIntln(reader)
		var n, k, b, s = x[0], x[1], x[2], x[3]
		if s < k*b || s > k*b+(k-1)*n {
			writer.WriteString("-1\n")
		} else {
			var res = make([]int, n)
			res[0] = k * b
			var sum = k * b
			for j := 1; j < n; j++ {
				res[j] = min(s-sum, k-1)
				sum += res[j]
			}
			var resString = fmt.Sprint(res)
			writer.WriteString(resString[1:len(resString)-1] + "\n")
		}
	}
	writer.Flush()
}

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

func getIntln(in *bufio.Reader) []int {
	var x = strings.Split(getString(in), " ")
	var res = make([]int, len(x))
	for k, v := range x {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}

func getString(in *bufio.Reader) string {
	var s, _ = in.ReadString('\n')
	s = strings.TrimSpace(s)
	return s
}

package main

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

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

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

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

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		k, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		b, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		scanner.Scan()
		s, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		if s-n*(k-1) <= k*b && k*b <= s {
			if k == 1 {
				wr.WriteString(strconv.FormatInt(b, 10) + " ")
				var i int64
				for i = 0; i < n-1; i++ {
					wr.WriteString(strconv.Itoa(0) + " ")
				}
			} else {
				sm := (s - k*b) / (k - 1)
				sr := (s - k*b) % (k - 1)
				wr.WriteString(strconv.FormatInt(k*b, 10) + " ")
				wr.WriteString(strconv.FormatInt(sr, 10) + " ")
				var i int64
				for i = 0; i < sm; i++ {
					wr.WriteString(strconv.FormatInt(k-1, 10) + " ")
				}
				for i = 0; i < n-sm-2; i++ {
					wr.WriteString(strconv.Itoa(0) + " ")
				}
			}
			wr.WriteString("\n")
		} else {
			wr.WriteString(strconv.Itoa(-1) + "\n")
		}
	}
}

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

package main

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

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

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

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

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		s, _ := strconv.Atoi(scanner.Text())
		if s-n*(k-1) <= k*b && k*b <= s {
			if k == 1 {
				wr.WriteString(strconv.Itoa(b) + " ")
				for i := 0; i < n-1; i++ {
					wr.WriteString(strconv.Itoa(0) + " ")
				}
			} else {
				sm := (s - k*b) / (k - 1)
				sr := (s - k*b) % (k - 1)
				wr.WriteString(strconv.Itoa(k*b+sr) + " ")
				for i := 0; i < sm; i++ {
					wr.WriteString(strconv.Itoa(k-1) + " ")
				}
				for i := 0; i < n-sm-1; i++ {
					wr.WriteString(strconv.Itoa(0) + " ")
				}
			}
			wr.WriteString("\n")
		} else {
			wr.WriteString(strconv.Itoa(-1) + "\n")
		}
	}
}

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

package main

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

const MOD int64 = 1000000007

var n, k, b, s int64

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var w *bufio.Writer

func main() {

	read := bufio.NewReader(os.Stdin)

	w = bufio.NewWriter(os.Stdout)

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

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &k, &b, &s)

		solve()

		fmt.Fprintln(w)

		w.Flush()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {

	var max int64 = s/k

	vv := (k - 1) * n

	var min int64

	if vv >= s {
		min = 0
	}

	diffS := s - vv

	r := diffS % k

	if r != 0 {
		diffS += k - r
	}
	min = diffS/k

	if b < min || b > max {
		fmt.Fprint(w, -1)
		return
	}

	rest := s - b * k

	arr := make([]int64, n)

	arr[0] = b * k

	for i := 1; i < int(n); i++ {
		arr[i] = 0
	}

	for i := 0; i < int(n); i++ {
		if rest >= k - 1 {
			arr[i] += (k - 1)
			rest -= (k - 1)
		} else {
			arr[i] += rest
			rest = 0
		}
	}

	for i := 0; i < int(n); i++ {
		fmt.Fprint(w, arr[i], " ")
	}
}

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

const MOD int64 = 1000000007

var n, k, b, s int64

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var w *bufio.Writer

func main() {

	read := bufio.NewReader(os.Stdin)

	w = bufio.NewWriter(os.Stdout)

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

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &k, &b, &s)

		solve()

		fmt.Fprintln(w)

		w.Flush()
	}
}

type pair struct {
	v int
	idx []int
}

func solve() {
	if s/k < b {
		fmt.Fprint(w, -1)
		return
	}
	// s/k >= Sum(ai/k)

	v := k * b

	if s - v > 0 && n == 1  {
		fmt.Fprint(w, -1)
		return
	}

	if s - v == 0 && n == 1 {
		fmt.Fprint(w, v)
		return
	}

	var d int64

	d = (s - v)/(n - 1)

	if (s - v) % (n - 1) != 0 {
		d++
	}

	if d >= k {
		fmt.Fprint(w, -1)
		return
	}

	fmt.Fprint(w, v, " ")

	rest := s - v

	for i := 0; i < int(n) - 1; i ++ {
		if rest >= k - 1 {
			fmt.Fprint(w, k - 1, " ")
			rest -= (k - 1)
		} else {
			fmt.Fprint(w, rest, " ")
			rest = 0
		}
	}

	//n k b s
	//2 4 7 38
	//
	// 38/4  >=  21/4 + 17/4

	// 38/4   0/4  0/4  0/4  0/4   -> /

	//  7  - 10
	//  6 -  14

}

//IQ = 87

//........105....99...87..87..87..87.87.......87....

//            86

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

package main

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

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

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

// func min3(a, b, c int) int {
// 	return min(min(a, b), c)
// }

// func maxSquare(a int) int {
// 	tmp := int(math.Sqrt(float64(a)))
// 	if tmp*tmp == a {
// 		return tmp * tmp
// 	} else {
// 		return (tmp + 1) * (tmp + 1)
// 	}
// }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n, k, b, s int64
		fmt.Fscan(in, &n, &k, &b, &s)
		nstart := n
		if ((b >= 1) && (s >= b*k) && (s <= (((2*k - 1) * n) + (max(b-n, 0) * k)))) || ((b == 0) && (s <= (k-1)*n)) {
			for i := int64(0); i < nstart; i++ {
				//fmt.Fprintln(out, "!!!!!", n, k, b, s, (2*k-1)+max(b-n, 0)*k)
				if s == 0 {
					fmt.Fprintf(out, "%d ", 0)
					continue
				}
				if b == 0 {
					if s <= k-1 {
						fmt.Fprintf(out, "%d ", s)
						s = 0
						n--
						continue
					} else {
						fmt.Fprintf(out, "%d ", k-1)
						n--
						s -= k - 1
						continue
					}
				}
				if (s >= k*b) && (s <= (2*k-1)+max(b-n, 0)*k) {
					fmt.Fprintf(out, "%d ", s)
					s = 0
					b = 0
					n--
					//continue outer
				} else {
					//fmt.Fprintln(out, "HERE")
					s2 := s - (2*k - 1)
					if (s2 >= (b-1)*k) && (s2 <= (2*k-1)*(n-1)+max(b-n, 0)*k) {
						fmt.Fprintf(out, "%d ", 2*k-1)
						s = s2
						b--
						n--
					} else {
						fmt.Fprintf(out, "%d ", k)
						s -= k
						b--
						n--
					}
					//fmt.Fprintf(out, "%d ", 2*b-1)
				}
				// } else {
				// 	// snew := s - 2*b - 1
				// 	// if !((snew >= b*k) && (snew <= (2*k-1)*(n-1))) {
				// 	// 	s = s - b
				// 	// 	fmt.Fprintf(out, "%d ", b)
				// 	// } else {
				// 	// 	s = s - (2*b - 1)
				// 	// 	fmt.Fprintf(out, "%d ", 2*b-1)
				// 	}
				// }
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out, "-1")
		}
	}
}

package main

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

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

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

// func min3(a, b, c int) int {
// 	return min(min(a, b), c)
// }

// func maxSquare(a int) int {
// 	tmp := int(math.Sqrt(float64(a)))
// 	if tmp*tmp == a {
// 		return tmp * tmp
// 	} else {
// 		return (tmp + 1) * (tmp + 1)
// 	}
// }

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n, k, b, s int64
		fmt.Fscan(in, &n, &k, &b, &s)
		nstart := n
		if (s >= b*k) && (s <= (((2*k - 1) * n) + (max(b-n, 0) * k))) {
			for i := int64(0); i < nstart; i++ {
				//fmt.Fprintln(out, "!!!!!", n, k, b, s)
				if s == 0 {
					fmt.Fprintf(out, "%d ", 0)
					continue
				}
				if (s >= k) && (s <= (2*k-1)*1+max(b-n, 0)*k) {
					fmt.Fprintf(out, "%d ", s)
					s = 0
					b = 0
					n--
					//continue outer
				} else {
					//fmt.Fprintln(out, "HERE")
					s2 := s - (2*k - 1)
					if (s2 >= (b-1)*k) && (s2 <= (2*k-1)*(n-1)+max(b-n, 0)*k) {
						fmt.Fprintf(out, "%d ", 2*k-1)
						s = s2
						b--
						n--
					} else {
						fmt.Fprintf(out, "%d ", k)
						s -= k
						b--
						n--
					}
					//fmt.Fprintf(out, "%d ", 2*b-1)
				}
				// } else {
				// 	// snew := s - 2*b - 1
				// 	// if !((snew >= b*k) && (snew <= (2*k-1)*(n-1))) {
				// 	// 	s = s - b
				// 	// 	fmt.Fprintf(out, "%d ", b)
				// 	// } else {
				// 	// 	s = s - (2*b - 1)
				// 	// 	fmt.Fprintf(out, "%d ", 2*b-1)
				// 	}
				// }
			}
			fmt.Fprintln(out)
		} else {
			fmt.Fprintln(out, "-1")
		}
	}
}

package main

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

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

	return b
}

func main() {
	// f, _ := os.Open("input.txt")
	var reader = bufio.NewReader(os.Stdin)
	// var reader = bufio.NewReader(f)
	var tests int
	fmt.Fscan(reader, &tests)
	for t := 0; t < tests; t++ {
		var n, k, b int
		var s int64
		fmt.Fscan(reader, &n)
		fmt.Fscan(reader, &k)
		fmt.Fscan(reader, &b)
		fmt.Fscan(reader, &s)
		var result = make([]int64, n)
		var first int64 = int64(k + 1) * int64(b) - 1
		if b == 0 {
			first = int64(k - 1)
		}
		if first > s {
			if s < int64(k) * int64(b) {
				fmt.Println(-1)
				continue
			}
			first = s
		}
		result[0] = first
		s -= first
		for i := 1; i < n; i++ {
			var next int64 = int64(k) - 1
			if s < next {
				next = s
			}

			result[i] = next
			s -= next
		}

		if s > 0 {
			fmt.Println(-1)
			continue
		}

		for i := 0; i < n; i++ {
			fmt.Print(result[i], " ")
		}

		fmt.Println()
	}
}

package main

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

var (
	reader bufio.Reader
	writer bufio.Writer
)

func main() {
	inp, err := os.Open("in.txt")
	if err == nil {
		os.Stdin = inp
		outp, _ := os.Create("out.txt")
		os.Stdout = outp
		defer outp.Close()
		defer inp.Close()
	}
	reader = *bufio.NewReader(os.Stdin)
	writer = *bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var T int
	scan(&T)

	for ; T > 0; T-- {
		var n, k, b, s int
		scan(&n, &k, &b, &s)

		if s < b * k {
			printf("-1\n")
			continue
		}

		arr := make([]int64, n)
		arr[0] = int64(b) * int64(k)
		s -= b * k
		for i := 1; i < n; i++ {
			if s >= k - 1 {
				arr[i] = int64(k - 1)
			} else {
				arr[i] = int64(s)
				s = 0
				break
			}
			s -= k - 1
		}

		if s > k - 1 {
			printf("-1\n")
			/*for i := 0; i < n; i++ {
				printf("%v ", arr[i])
			}
			printf("\n")*/
		} else {
			arr[0] += int64(s)
			for i := 0; i < n; i++ {
				printf("%v ", arr[i])
			}
			printf("\n")
		}
	}
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(&reader, a...)
}

func printf(format string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(&writer, format, a...)
}


Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.Vasya needs to collect all these items, however he won't do it by himself. He uses his brand new robot. The robot has two different arms — the left one and the right one. The robot can consecutively perform the following actions:   Take the leftmost item with the left hand and spend wi · l energy units (wi is a weight of the leftmost item, l is some parameter). If the previous action was the same (left-hand), then the robot spends extra Ql energy units;  Take the rightmost item with the right hand and spend wj · r energy units (wj is a weight of the rightmost item, r is some parameter). If the previous action was the same (right-hand), then the robot spends extra Qr energy units; Naturally, Vasya wants to program the robot in a way that the robot spends as little energy as possible. He asked you to solve this problem. Your task is to find the minimum number of energy units robot spends to collect all items.

The first line contains five integers n, l, r, Ql, Qr (1 ≤ n ≤ 105; 1 ≤ l, r ≤ 100; 1 ≤ Ql, Qr ≤ 104). The second line contains n integers w1, w2, ..., wn (1 ≤ wi ≤ 100).

In the single line print a single number — the answer to the problem.

NoteConsider the first sample. As l = r, we can take an item in turns: first from the left side, then from the right one and last item from the left. In total the robot spends 4·42 + 4·99 + 4·3 = 576 energy units.The second sample. The optimal solution is to take one item from the right, then one item from the left and two items from the right. In total the robot spends (2·4) + (7·1) + (2·3) + (2·2 + 9) = 34 energy units.

package main

import "os"
import "bufio"
import "strconv"

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

func main(){
	 var n, l, r, q1, q2 int
	 re := bufio.NewScanner(os.Stdin)
	 re.Split(bufio.ScanWords)
	 w := bufio.NewWriter(os.Stdout)
	 re.Scan()
	 n, _ = strconv.Atoi(re.Text())
	 re.Scan()
	 l, _ = strconv.Atoi(re.Text())
	 re.Scan()
	 r, _ = strconv.Atoi(re.Text())
	 re.Scan()
	 q1, _ = strconv.Atoi(re.Text())
	 re.Scan()
	 q2, _ = strconv.Atoi(re.Text())
	 sum := 0
	 ans := 0
	 a := make([]int, 100010)
	 for i:=1; i<=n; i++ {
		re.Scan()
		a[i], _ = strconv.Atoi(re.Text())
		sum += a[i]
	 }
	 sum *= r
	 ans = sum+(n-1)*q2
	 for i:=1; i<=n; i++ {
		sum = sum-r*a[i]+l*a[i]
		if i<n-i {
			ans = min(ans, sum+(n-i-i-1)*q2)
		} else if i > n-i {
			ans = min(ans, sum+(i-(n-i)-1)*q1)
		} else {
			ans = min(ans, sum)
		}
	 }
	 w.WriteString(strconv.Itoa(ans)+"\n")
	 w.Flush()
}

// 354A
package main

import (
	"fmt"
)

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

func main() {
	var Q, n, l, r, a, b, i, sum int64
	var w, s [100100]int64
	fmt.Scan(&n, &l, &r, &a, &b)
	s[0] = 0
	for i = 1; i <= n; i++ {
		fmt.Scan(&w[i])
		s[i] = s[i-1] + w[i]
	}
	Q = 2000000000
	for i = 0; i <= n; i++ {
		sum = s[i]*l + (s[n]-s[i])*r
		if i > n-i {
			sum += (2*i - n - 1) * a
		}
		if i < n-i {
			sum += (n - 2*i - 1) * b
		}
		Q = min(Q, sum)
	}

	fmt.Print(Q)
}

// 354A-mic
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, l, r, ql, qr int
	var P [100005]int
	fmt.Scan(&n, &l, &r, &ql, &qr)
	for i := 1; i < n+1; i++ {
		fmt.Scan(&P[i])
		P[i] += P[i-1]
	}
	res := 1000000000
	for i := 0; i < n+1; i++ {
		c := l*P[i] + r*(P[n]-P[i])
		r := n - i
		if i > r {
			c += ql * (i - r - 1)
		}
		if i < r {
			c += qr * (r - i - 1)
		}
		res = int(math.Min(float64(res), float64(c)))
	}
	fmt.Println(res)
}

// 354A-mic
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, l, r, ql, qr int
	var P [100005]int
	fmt.Scan(&n, &l, &r, &ql, &qr)
	for i := 1; i < n+1; i++ {
		fmt.Scan(&P[i])
		P[i] += P[i-1]
	}
	res := 1 << 30
	for i := 0; i < n+1; i++ {
		c := l*P[i] + r*(P[n]-P[i])
		r := n - i
		if i > r {
			c += ql * (i - r - 1)
		}
		if i < r {
			c += qr * (r - i - 1)
		}
		res = int(math.Min(float64(res), float64(c)))
	}
	fmt.Println(res)
}

// 354A
package main

import (
	"fmt"
)

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

func main() {
	var n, l, r, a, b int
	var w, s [100100]int
	fmt.Scan(&n, &l, &r, &a, &b)
	s[0] = 0
	for i := 1; i <= n; i++ {
		fmt.Scan(&w[i])
		s[i] = s[i-1] + w[i]
	}
	Q := 200000000
	for i := 0; i <= n; i++ {
		sum := s[i]*l + (s[n]-s[i])*r
		if i > n-i {
			sum += (2*i - n - 1) * a
		}
		if i < n-i {
			sum += (n - 2*i - 1) * b
		}
		Q = min(Q, sum)
	}

	fmt.Print(Q)
}

// 354A
package main

import (
	"fmt"
)

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

func main() {
	var n, l, r, a, b, i, sum int64
	var w, s [100100]int64
	fmt.Scan(&n, &l, &r, &a, &b)
	s[0] = 0
	for i = 1; i <= n; i++ {
		fmt.Scan(&w[i])
		s[i] = s[i-1] + w[i]
	}
	Q := int64(200000000)
	for i = 0; i <= n; i++ {
		sum = s[i]*l + (s[n]-s[i])*r
		if i > n-i {
			sum += (2*i - n - 1) * a
		}
		if i < n-i {
			sum += (n - 2*i - 1) * b
		}
		Q = min(Q, sum)
	}

	fmt.Print(Q)
}


Monocarp has got two strings $$$s$$$ and $$$t$$$ having equal length. Both strings consist of lowercase Latin letters "a" and "b". Monocarp wants to make these two strings $$$s$$$ and $$$t$$$ equal to each other. He can do the following operation any number of times: choose an index $$$pos_1$$$ in the string $$$s$$$, choose an index $$$pos_2$$$ in the string $$$t$$$, and swap $$$s_{pos_1}$$$ with $$$t_{pos_2}$$$.You have to determine the minimum number of operations Monocarp has to perform to make $$$s$$$ and $$$t$$$ equal, and print any optimal sequence of operations — or say that it is impossible to make these strings equal.

The first line contains one integer $$$n$$$ $$$(1 \le n \le 2 \cdot 10^{5})$$$ — the length of $$$s$$$ and $$$t$$$. The second line contains one string $$$s$$$ consisting of $$$n$$$ characters "a" and "b".  The third line contains one string $$$t$$$ consisting of $$$n$$$ characters "a" and "b".

If it is impossible to make these strings equal, print $$$-1$$$. Otherwise, in the first line print $$$k$$$ — the minimum number of operations required to make the strings equal. In each of the next $$$k$$$ lines print two integers — the index in the string $$$s$$$ and the index in the string $$$t$$$ that should be used in the corresponding swap operation.

NoteIn the first example two operations are enough. For example, you can swap the third letter in $$$s$$$ with the third letter in $$$t$$$. Then $$$s = $$$ "abbb", $$$t = $$$ "aaab". Then swap the third letter in $$$s$$$ and the second letter in $$$t$$$. Then both $$$s$$$ and $$$t$$$ are equal to "abab".In the second example it's impossible to make two strings equal.

package main

import (
    "bufio"
    "fmt"
    "os"
)
const(
    mod int = 1e9 + 7
    N = 1e6
)
func main() {
    in := bufio.NewReader(os.Stdin)
    var n int
    var a, b string
    fmt.Fscan(in, &n)
    fmt.Fscan(in, &a)
    fmt.Fscan(in, &b)
    tot := make([][][]int, 2)
    tot[0] = make([][]int, 2)
    tot[1] = make([][]int, 2)
    for i := 0; i < n; i++ {
        if a[i] != b[i] {
            tot[a[i] - 'a'][b[i] - 'a'] = append(tot[a[i] - 'a'][b[i] - 'a'], i + 1)
        }
    }
    if (len(tot[0][1]) + len(tot[1][0])) % 2 != 0 {
        fmt.Println(-1)
        return
    }
    fmt.Println(len(tot[0][1]) / 2 + len(tot[1][0]) / 2 + 2 * (len(tot[0][1]) % 2))
    f := func(b int){
        for len(tot[b][b ^ 1]) >= 2 {
            fmt.Println(tot[b][b ^ 1][0], tot[b][b ^ 1][1])
            tot[b][b ^ 1] = tot[b][b ^ 1][2 : ]
        }
    }
    f(0)
    f(1)
    if len(tot[0][1]) > 0 {
        fmt.Println(tot[0][1][0], tot[0][1][0])
        fmt.Println(tot[0][1][0], tot[1][0][0])
    }
}

package main

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

func main() {

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

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

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

	var s1, s2 string
	fmt.Fscanf(reader, "%s\n", &s1)
	fmt.Fscanf(reader, "%s\n", &s2)

	a := make([]int, 0)
	b := make([]int, 0)

	var r int

	for i := 0; i < n; i++ {
		if s1[i] != s2[i] {
			if s1[i] == 'a' {
				r++
			}
			if s2[i] == 'a' {
				r++
			}
			if s1[i] == 'a' {
				a = append(a, i)
			} else {
				b = append(b, i)
			}
		}
	}

	if r % 2 == 1 || (2 * n - r) % 2 == 1 {
		fmt.Fprintf(writer,"-1\n")
	} else {
		if len(a) % 2 == 1 && len(b) % 2 == 1 {
			fmt.Fprintf(writer, "%d\n", (len(a) + len(b)) / 2 + 1)
		} else {
			fmt.Fprintf(writer, "%d\n", (len(a) + len(b)) / 2)
		}

		for len(a) > 1 {
			fmt.Fprintf(writer, "%d %d\n", a[0] + 1, a[1] + 1)
			a = a[2:]
		}

		for len(b) > 1 {
			fmt.Fprintf(writer, "%d %d\n", b[0] + 1, b[1] + 1)
			b = b[2:]
		}

		if len(a) > 0 {
			fmt.Fprintf(writer, "%d %d\n", a[0] + 1, a[0] + 1)
			fmt.Fprintf(writer, "%d %d\n", a[0] + 1, b[0] + 1)
		}

	}

	writer.Flush()
}


You are given four distinct integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$. Timur and three other people are running a marathon. The value $$$a$$$ is the distance that Timur has run and $$$b$$$, $$$c$$$, $$$d$$$ correspond to the distances the other three participants ran. Output the number of participants in front of Timur.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of each test case consists of four distinct integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0 \leq a, b, c, d \leq 10^4$$$).

For each test case, output a single integer — the number of participants in front of Timur.

NoteFor the first test case, there are $$$2$$$ people in front of Timur, specifically the participants who ran distances of $$$3$$$ and $$$4$$$. The other participant is not in front of Timur because he ran a shorter distance than Timur.For the second test case, no one is in front of Timur, since he ran a distance of $$$10000$$$ while all others ran a distance of $$$0$$$, $$$1$$$, and $$$2$$$ respectively.For the third test case, only the second person is in front of Timur, who ran a total distance of $$$600$$$ while Timur ran a distance of $$$500$$$.

package main

import "fmt"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)

	for i:=0;i<t;i++{
	    fmt.Scan(&a)
    	fmt.Scan(&b)
    	fmt.Scan(&c)
    	fmt.Scan(&d)
	    x:=0
		if b > a {
			x++
		}

		if c > a {
			x++
		}

		if d > a {
			x++
		}
		fmt.Println(x)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int
	fmt.Scan(&t)
	i := 0
	// reader := bufio.NewReader(os.Stdin)
	for i < t {
		guys := make([]int, 4)
		fmt.Scan(&guys[0])
		fmt.Scan(&guys[1])
		fmt.Scan(&guys[2])
		fmt.Scan(&guys[3])
		ans := 0
		// timur, _ := strconv.Atoi(guys[0])
		j := 1
		for j < len(guys) {
			// otherguy, _ := strconv.Atoi(guys[j])
			//fmt.Println(guys[j], " - ", otherguy)
			if guys[j] > guys[0] {
				ans++
			}
			j++
		}
		fmt.Println(ans)
		i++
	}
}

package main

import "fmt"

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

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

		if a < b {
			count++
		}

		if a < c {
			count++
		}

		if a < d {
			count++
		}

		fmt.Println(count)
	}
}

package main

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

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

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

}

func solve() {
	//in := bufio.NewReader(os.Stdin)
	//out := bufio.NewWriter(os.Stdout)
	var a, b int
	fmt.Fscan(in, &a)
	var c int = 0
	for i := 0; i < 3; i++ {
		fmt.Fscan(in, &b)
		if b > a {
			c++
		}
	}
	fmt.Fprintln(out, c)

}

package main

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

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

	for t, _ := strconv.Atoi(getString(reader)); t > 0; t-- {
		var a = getIntln(reader)
		var result int

		for i := 1; i < 4; i++ {
			if a[0] < a[i] {
				result++
			}
		}

		writer.WriteString(strconv.Itoa(result) + "\n")
	}

	writer.Flush()
}

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

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}

package main

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

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

func solve() string {
	var a, b, c, d int
	fmt.Fscan(in, &a, &b, &c, &d)
	var res int64

	if b > a {
		res++
	}
	if c > a {
		res++
	}
	if d > a {
		res++
	}

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

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

import (
	"fmt"
)

func main() {
	var (
		t int
		a int
		b int
		c int
		d int
		n int
	)
	fmt.Scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		n = 0
		fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
		if b > a {
			n++
		}
		if c > a {
			n++
		}
		if d > a {
			n++
		}
		fmt.Println(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() {
	a := nextInt()
	b := nextInt()
	c := nextInt()
	d := nextInt()

	ans := 0
	if b > a {
		ans++
	}
	if c > a {
		ans++
	}
	if d > a {
		ans++
	}

	out(ans, "\n")
}

package main
import (
	"fmt"
)
func main() {
	var n int
	fmt.Scan(&n)
	for i:=0;i<n;i++{
		var a,tally int
		fmt.Scan(&a)
		for j:=0;j<3;j++{
			var x int
			fmt.Scan(&x)
			if x > a {
				tally++
			}
		}
		fmt.Println(tally)
	}
}

package main

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

func solve(r *bufio.Reader) {
	var a, b, c, d int
	fmt.Fscan(r, &a, &b, &c, &d)
	xd := 0
	if b > a {
		xd++
	}
	if c > a {
		xd++
	}
	if d > a {
		xd++
	}
	fmt.Println(xd)
}
func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		solve(r)
	}
}

package main

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

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

	var t int
	var a [4]int

	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a[0], &a[1], &a[2], &a[3])
		cnt := 0

		for _, v := range a {
			if v > a[0] {
				cnt++
			}
		}

		fmt.Fprintln(out, cnt)
	}

}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	a      []int
)

func solve(a []int) int {
	var f int
	for i := 1; i < 4; i++ {
		if a[i] > a[0] {
			f++
		}
	}
	return f
}

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

package main

import "fmt"

func test() {
	var a, b, c, d int

	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	ans := 0
	if a < b {
		ans += 1
	}

	if a < c {
		ans += 1
	}

	if a < d {
		ans += 1
	}

	fmt.Println(ans)
}

func main() {
	test_case := 0

	fmt.Scan(&test_case)

	for i := 0; i < test_case; i++ {
		test()
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)

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

func readLine() []string {
	line, _ := in.ReadString('\n')
	line = strings.ReplaceAll(line, "\r", "")
	line = strings.ReplaceAll(line, "\n", "")
	values := strings.Split(line, " ")
	return values
}

func readArrInt() []int {
	line := readLine()
	res := make([]int, 0, 0)
	for i := range line {
		var x, _ = strconv.Atoi(line[i])
		res = append(res, x)
	}
	return res
}

func main() {
	test := readInt()
	for ; 0 < test; test-- {
		var a = readArrInt()
		res := 0
		for i := 0; i < 4; i++ {
			if a[0] < a[i] {
				res++
			}
		}
		fmt.Printf("%d\n", res)
	}
}

package main

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

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

func main() {
	defer writer.Flush()

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

	cmp := func(u, v int) int {
		if u < v {
			return 1
		}
		return 0
	}

	for ; Q > 0; Q-- {
		var a, b, c, d int
		fmt.Fscan(reader, &a, &b, &c, &d)
		var ans int = 0
		ans += cmp(a, b) + cmp(a, c) + cmp(a, d)
		fmt.Fprintf(writer, "%d\n", ans)
	}
}

package main

import "fmt"

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

package main

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

var (
	reader *bufio.Reader = bufio.NewReader(os.Stdin)
	writer *bufio.Writer = bufio.NewWriter(os.Stdout)
	debug                = fmt.Println
)

func solve() {
	var a, b, c, d int
	scanf("%d %d %d %d\n", &a, &b, &c, &d)
	place := 0

	if b > a {
		place++
	}
	if c > a {
		place++
	}
	if d > a {
		place++
	}
	printf("%v\n", place)
}

func main() {
	defer writer.Flush()
	var cases int

	scanf("%d\n", &cases)
	// cases = 1

	for c := 0; c < cases; c++ {
		solve()
	}
}

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

func IntArray(size int) []int {
	arr := make([]int, size)
	for i := 0; i < size; i++ {
		scanf("%d", &arr[i])
	}
	scanf("\n")
	return arr
}

func Max(args ...int) int {
	m := args[0]
	for i := range args {
		if args[i] > m {
			m = args[i]
		}
	}
	return m
}

func Min(args ...int) int {
	m := args[0]
	for i := range args {
		if args[i] < m {
			m = args[i]
		}
	}
	return m
}

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)
	distances := make([]int, 4)
	for i := 0; i < t; i++ {
		fmt.Fscan(cin, &distances[0], &distances[1], &distances[2], &distances[3])
		ans := 0
		for j := 1; j <= 3; j++ {
			if distances[j] > distances[0] {
				ans += 1
			}
		}
		fmt.Printf("%d\n", ans)
	}
}

package main

import "fmt"

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

package main

import "fmt"

func main() {
	var n, a, b, c, d int
	var ans [10005]int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b, &c, &d)
		if a < b {
			ans[i]++
		}
		if a < c {
			ans[i]++
		}
		if a < d {
			ans[i]++
		}
	}
	for i := 0; i < n; i++ {
		fmt.Println(ans[i])
	}
}

package main

import "fmt"

func main() {
	var t int
	_, err := fmt.Scanf("%d\n", &t)
	//fmt.Println(t, err)
	if err != nil {
		return
	}
	for t > 0 {
		solve1692a()
		t--
	}
}

func solve1692a() {
	var a, b, c, d int
	_, err := fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
	if err != nil {
		return
	}
	cnt := 0
	if b > a {
		cnt = cnt + 1
	}
	if c > a {
		cnt = cnt + 1
	}
	if d > a {
		cnt = cnt + 1
	}
	fmt.Println(cnt)
}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1692A
Date: 17/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1692/A
Problem: CF1692A
**/
func (in *CF1692A) Run() {
	for t := in.NextInt(); t > 0; t-- {
		a, b, c, d := in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt()

		ans := 0
		if a < b {
			ans++
		}
		if a < c {
			ans++
		}
		if a < d {
			ans++
		}
		fmt.Println(ans)

	}
}

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

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

package main

import (
	"fmt"
)

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

	for t != 0 {

		var arr [4]int

		for i := 0; i < 4; i++ {
			fmt.Scan(&arr[i])
		}

		trumpCard := arr[0]
		count := 0

		for i := 1; i < 4; i++ {
			if arr[i] > trumpCard {
				count++
				continue
			}
		}
		fmt.Println(count)
		count = 0
		t-- // updater
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
)
var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)
func slove() {
	var a,b,c,d int
	fmt.Fscan(r,&a,&b)
	fmt.Fscan(r,&c,&d)
	an := 0
	if b > a {
		an++
	}
	if c > a {
		an++
	}
	if d > a {
		an++
	}
	fmt.Fprintln(w,an)

}

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

package main

import "fmt"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		ans := 0
		n, _ := fmt.Scan(&a, &b, &c, &d)
		if n == 0 {
			break
		}
		if c > a {
			ans++
		}
		if b > a {
			ans++
		}
		if d > a {
			ans++
		}
		fmt.Println(ans)
	}
}

package main

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

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

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

func rw(r io.Reader, w io.Writer) {
	var t int
	var n int
	n = 4
	var a = make([]int, n)
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &a[i])
		}
		w1 := do(a)
		fmt.Fprintln(w, w1)
	}
}

func do(a []int) int {
	c := 0
	for i := 1; i < 4; i++ {
		if a[i] > a[0] {
			c++
		}
	}
	return c
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n,a,b,c,d int
	ans := 0

	fmt.Fscan(in, &n)

	// bitsがn個の要素の各パターンを表す
	for i := 0;i < n;i++ {
		fmt.Fscan(in, &a,&b,&c,&d)
		if a < b{
			ans++
		}
		if a < c{
			ans++
		}
		if a < d{
			ans++
		}
		fmt.Println(ans)
		ans = 0
	}
}

package main

import (
	"fmt"
)

func solve() {
	var a int
	fmt.Scan(&a)
	counter := 0
	for i := 0; i < 3; i++ {
		var x int
		fmt.Scan(&x)
		if x > a {
			counter++
		}
	}

	fmt.Println(counter)
}

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

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

		var ans int
		if a < b {
			ans++
		}
		if a < c {
			ans++
		}
		if a < d {
			ans++
		}
		fmt.Fprintln(out, ans)
	}
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	n := 4
	d := make([]int, n)

	for i := range d {
		scanf("%d", &d[i])
	}
	scanf("\n")

	a := d[0]
	d = d[1:]

	cnt := 0

	for _, dist := range d {
		if dist > a {
			cnt++
		}
	}

	fmt.Fprintln(writer, cnt)
}

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

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

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

const maxUint = ^uint(0)

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

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

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

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

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

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for c := 0; c < testCases; c++ {
		var a, b, c, d int
		Fscan(in, &a, &b, &c, &d)
		cnt := 0
		if b > a {
			cnt++
		}
		if c > a {
			cnt++
		}
		if d > a {
			cnt++
		}

		Fprintln(out, cnt)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func sol() {
	r := 0
	a, b, c, d := ri(), ri(), ri(), ri()
	if a < b {
		r += 1
	}
	if a < c {
		r += 1
	}
	if a < d {
		r += 1
	}
	myio.Println(r)
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		sol()
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var a, b, c ,d int
	fmt.Fscan(r, &a, &b)
	fmt.Fscan(r, &c, &d)
	cnt := 0
	if b > a {
		cnt++
	}
	if c > a {
		cnt++
	}
	if d > a {
		cnt++
	}
	fmt.Fprintln(w, cnt)
}

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

package main

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

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {

		a := make([]int, 4)
		for i := range a {
			Fscan(in, &a[i])
		}
		c:=0
		for i := 1; i < 4; i++ {
			if a[i]>a[0] {
				c++
			}
		}
		Fprintln(out, c)
	}

	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"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	for i:=0;i<t;i++{
	    x:=0
		if b > a {
			x++
		}

		if c > a {
			x++
		}

		if d > a {
			x++
		}
		fmt.Println(x)
	}
}

package main

import "fmt"

func main() {
	var t, a, b, c, d int
	fmt.Scan(&t)
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	x := 0
	for i:=0;i<t;i++{
		if b > a {
			x++
		}

		if c > a {
			x++
		}

		if d > a {
			x++
		}
	}
	fmt.Println(x)
}

package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&d)

	x := 0

	if b > a {
		x++
	}

	if c > a {
		x++
	}

	if d > a {
		x++
	}

	fmt.Println(x)
}

package main

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

func main() {
	var t int
	fmt.Scan(&t)
	i := 0
	reader := bufio.NewReader(os.Stdin)
	reader.ReadString('\n')
	for i < t {
		text, err := reader.ReadString('\n')
		if err != nil {
			panic(err)
		}
		guys := strings.Split(strings.Trim(text, "\n"), " ")
		ans := 0
		timur, _ := strconv.Atoi(guys[0])
		j := 1
		for j < len(guys) {
			otherguy, _ := strconv.Atoi(guys[j])
			//fmt.Println(guys[j], " - ", otherguy)
			if otherguy > timur {
				ans++
			}
			j++
		}
		fmt.Println(ans)
		i++
	}
}

package main

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

func main() {
	var t int
	fmt.Scan(&t)
	i := 0
	reader := bufio.NewReader(os.Stdin)
	for i < t {
		text, err := reader.ReadString('\n')
		if err != nil {
			panic(err)
		}
		guys := strings.Split(strings.Trim(text, "\n"), " ")
		ans := 0
		timur, _ := strconv.Atoi(guys[0])
		j := 1
		for j < len(guys) {
			otherguy, _ := strconv.Atoi(guys[j])
			//fmt.Println(guys[j], " - ", otherguy)
			if otherguy > timur {
				ans++
			}
			j++
		}
		fmt.Println(ans)
		i++
	}
}

package main

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

func main() {
	var t int
	fmt.Scan(&t)
	i := 0
	reader := bufio.NewReader(os.Stdin)
	for i < t {
		text, err := reader.ReadString('\n')
		if err != nil {
			panic(err)
		}
		guys := strings.Split(text, " ")
		ans := 0
		timur, _ := strconv.Atoi(guys[0])
		j := 1
		for j < len(guys) {
			otherguy, _ := strconv.Atoi(guys[j])
			if otherguy > timur {
				ans++
			}
			j++
		}
		fmt.Println(ans)
		i++
	}
}

package main

import "fmt"

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

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

		if a < b {
			count++
		}

		if a < c {
			count++
		}

		if a < d {
			count++
		}

		fmt.Println(count)
	}
}

package main

import "fmt"

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

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

		if a < b {
			count++
		}

		if a < c {
			count++
		}

		if a < d {
			count++
		}

		fmt.Println(count)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var l int
	fmt.Fscan(in, &l)
	for l > 0 {
		solve()
		l--
	}
}

func solve() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var a, b int

	fmt.Fscan(in, &a)
	var c int = 0
	for i := 0; i < 3; i++ {
		fmt.Fscan(in, &b)
		if b > a {
			c++
		}
	}
	fmt.Fprintln(out, c)

}

package main

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

func main() {
	var l int
	fmt.Scan(&l)
	for l > 0 {
		solve()
		l--
	}
}

func solve() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var a, b int

	fmt.Fscan(in, &a)
	var c int = 0
	for i := 0; i < 3; i++ {
		fmt.Fscan(in, &b)
		if b > a {
			c++
		}
	}
	fmt.Fprintln(out, c)

}

package main

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

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

	for t, _ := strconv.Atoi(getString(reader)); t > 0; t-- {
		var a = getIntln(reader)
		var result int

		for i := 1; i < 4; i++ {
			if a[0] < a[i] {
				result++
			}
		}

		writer.WriteString(strconv.Itoa(result))
	}

	writer.Flush()
}

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

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k], _ = strconv.Atoi(v)
	}
	return res
}


You are given two integers $$$n$$$ and $$$m$$$. You have to construct the array $$$a$$$ of length $$$n$$$ consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly $$$m$$$ and the value $$$\sum\limits_{i=1}^{n-1} |a_i - a_{i+1}|$$$ is the maximum possible. Recall that $$$|x|$$$ is the absolute value of $$$x$$$.In other words, you have to maximize the sum of absolute differences between adjacent (consecutive) elements. For example, if the array $$$a=[1, 3, 2, 5, 5, 0]$$$ then the value above for this array is $$$|1-3| + |3-2| + |2-5| + |5-5| + |5-0| = 2 + 1 + 3 + 0 + 5 = 11$$$. Note that this example doesn't show the optimal answer but it shows how the required value for some array is calculated.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$) — the length of the array and its sum correspondingly.

For each test case, print the answer — the maximum possible value of $$$\sum\limits_{i=1}^{n-1} |a_i - a_{i+1}|$$$ for the array $$$a$$$ consisting of $$$n$$$ non-negative integers with the sum $$$m$$$.

NoteIn the first test case of the example, the only possible array is $$$[100]$$$ and the answer is obviously $$$0$$$.In the second test case of the example, one of the possible arrays is $$$[2, 0]$$$ and the answer is $$$|2-0| = 2$$$.In the third test case of the example, one of the possible arrays is $$$[0, 2, 0, 3, 0]$$$ and the answer is $$$|0-2| + |2-0| + |0-3| + |3-0| = 10$$$.

package main

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

func main() {
	for t := readInt(); t > 0; t-- {
		n, m := readInt2()
		switch n {
		case 1:
			fmt.Println(0)
		case 2:
			fmt.Println(m)
		default:
			fmt.Println(2 * m)
		}
	}
}

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

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

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

func readInt() (int) {
	a := readInts()
	return a[0]
}

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

package main

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

func main() {
	var n, m, t int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &m)
		if n > 2 {
			fmt.Println(m * 2)
		} else if n == 1 {
			fmt.Println(0)
		} else {
			fmt.Println(m)
		}
	}
}

package main

import (
	"fmt"
)

func solve() {
	var n, m int

	fmt.Scan(&n, &m)
	if n == 1 {
		fmt.Println(0)
	} else if n == 2 {
		fmt.Println(m)
	} else {
		fmt.Println(2 * m)
	}

}

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

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-- {
		var n, m int64
		fmt.Fscan(in, &n, &m)
		if n == 1 {
			fmt.Fprintln(out, 0)
		} else if n == 2 {
			fmt.Fprintln(out, m)
		} else {
			fmt.Fprintln(out, m*2)
		}
	}
}

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

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var n, m int
	fmt.Fscan(input, &n, &m)
	if n == 1 {
		fmt.Println(0)
	} else if n == 2 {
		fmt.Println(m)
	} else {
		fmt.Println(m * 2)
	}
}

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 main() {
    defer writer.Flush()
    var t, n, m int
    scanf("%d\n", &t)
    for i := 0; i < t; i++ {
        defer writer.Flush()
        scanf("%d %d\n", &n, &m)
        if n > 2 {
            printf("%d\n", m * 2)
        } else if n == 1 {
            printf("%d\n", 0)
        } else {
            printf("%d\n", m)
        }
    }
}

package main

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

func main()  {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		nms := scanner.Text()

		parts := strings.Fields(nms)

		n, err := strconv.Atoi(parts[0])

		if err != nil {
			panic(err)
		}

		m, err := strconv.Atoi(parts[1])

		if err != nil {
			panic(err)
		}

		res := solve(n, m)

		fmt.Println(res)
	}
}

func solve(n, m int) int  {
	if n == 1 {
		return 0
	}
	if n == 2 {
		return m
	}
	return 2 * m
}

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

package main

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

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

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		if n == 1 {
			Fprintln(out, 0)
		} else if n == 2 {
			Fprintln(out, m)
		} else {
			Fprintln(out, 2*m)
		}
	}
}

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		if n >= 3 {
			P(m << 1)
		} else if n == 2 {
			P(m)
		} else {
			P(0)
		}
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

import (
	"fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n,m int
		fmt.Scan(&n);
		fmt.Scan(&m);
		if n == 1{
			fmt.Println(0)
		}else if n==2{
			fmt.Println(m)
		}else{
			fmt.Println(m*2)
		}
	}

}

// https://serhatgiydiren.github.io

package main

import "fmt"

func solve(test_id int) {
 var n,m,res int
	fmt.Scan(&n,&m)
 if n == 1 {
  res = 0
 } else if n == 2 {
  res = m
 } else {
  res = 2 * m
 }
 fmt.Println(res)
}

func solve_cases() {
 t := 1
 fmt.Scan(&t)
 for i := 0 ; i < t ; i++ {
  solve(i)
 }
}

func main() {
 solve_cases()
}

package main

import "fmt"

func main() {
	var t, n, m int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		fmt.Scan(&n, &m)
		if n == 1 {
			fmt.Println(0)
		} else if n == 2 {
			fmt.Println(m)
		} else {
			fmt.Println(2 * m)
		}
	}
}

package main

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

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

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

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

		if n == 1 {
			fmt.Fprintln(w, 0)
		} else if n == 2 {
			fmt.Fprintln(w, m)
		} else {
			fmt.Fprintln(w, m*2)
		}
	}
}

package main

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

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

	var t int
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		var n, m int
		fmt.Fscan(reader, &n, &m)
		if n == 1 {
			fmt.Fprintln(writer, 0)
		} else if n == 2 {
			fmt.Fprintln(writer, m)
		} else {
			fmt.Fprintln(writer, m*2)
		}
	}
}

package main

import (
	"fmt"
	"strings"
)

type pair struct {
	n int
	m int
}

// https://codeforces.com/problemset/problem/1353/A
// комментарий к решению
func taskSolution(in []pair) string {
	ans := make([]int, len(in))
	for i := 0; i < len(in); i += 1 {
		n, m := in[i].n, in[i].m
		switch n {
		case 1:
			ans[i] = 0
		case 2:
			ans[i] = m
		default:
			ans[i] = 2 * m
		}
	}
	res := fmt.Sprint(ans)
	return strings.Replace(res[1:len(res)-1], " ", "\n", len(ans)-1)
}

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

	in := make([]pair, 0, t)
	for i := 0; i < t; i += 1 {
		var n, m int
		if _, err := fmt.Scan(&n, &m); err != nil {
			panic(err)
		}
		in = append(in, pair{n: n, m: m})
	}

	fmt.Println(taskSolution(in))
}

package main

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

func main() {
	var t int
	var n, k int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &k)
		a := make([]int, n)
		b := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &a[j])
		}
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &b[j])
		}
		sort.Slice(a, func(i, j int) bool {
			return a[i] > a[j]
		})
		sort.Slice(b, func(i, j int) bool {
			return b[i] > b[j]
		})
		sum := 0
		ai := 0
		bi := 0
		for j := 0; j < n; j++ {
			if a[ai] >= b[bi] || k == 0 {
				sum += a[ai]
				ai++
			} else {
				sum += b[bi]
				bi++
				k--
			}
		}
		fmt.Println(sum)
	}
}

package main

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

func main()  {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		nms := scanner.Text()

		parts := strings.Fields(nms)

		n, err := strconv.Atoi(parts[0])

		if err != nil {
			panic(err)
		}

		m, err := strconv.Atoi(parts[1])

		if err != nil {
			panic(err)
		}

		solve(n, m)
	}
}

func solve(n, m int) int  {
	if n <= 2 {
		return m
	}
	return 2 * m
}

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

package main

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

func main()  {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		nms := scanner.Text()

		parts := strings.Fields(nms)

		n, err := strconv.Atoi(parts[0])

		if err != nil {
			panic(err)
		}

		m, err := strconv.Atoi(parts[1])

		if err != nil {
			panic(err)
		}

		res := solve(n, m)

		fmt.Println(res)
	}
}

func solve(n, m int) int  {
	if n <= 2 {
		return m
	}
	return 2 * m
}

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

package main

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

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, m := ScanInt(), ScanInt()
		if n >= 3 {
			P(m << 1)
		} else {
			P(m)
		}
	}

	close(O)
	oWg.Wait()
}

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

var O chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var P func(a ...interface{}) (n int, err error)

func init() {
	P = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	O = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range O {
			writer.WriteString(line + "\n")
		}
	}()
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanInt() int     { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt()
	}
	return arr
}
func ScanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		arr[i] = ScanInt64()
	}
	return arr
}

/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}


Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left.There were $$$n$$$ classes of that subject during the semester and on $$$i$$$-th class professor mentioned some non-negative integer $$$a_i$$$ to the students. It turned out, the exam was to tell the whole sequence back to the professor. Sounds easy enough for those who attended every class, doesn't it?Obviously Mishka didn't attend any classes. However, professor left some clues on the values of $$$a$$$ to help out students like Mishka:   $$$a$$$ was sorted in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$);  $$$n$$$ was even;  the following sequence $$$b$$$, consisting of $$$\frac n 2$$$ elements, was formed and given out to students: $$$b_i = a_i + a_{n - i + 1}$$$. Professor also mentioned that any sequence $$$a$$$, which produces sequence $$$b$$$ with the presented technique, will be acceptable.Help Mishka to pass that last exam. Restore any sorted sequence $$$a$$$ of non-negative integers, which produces sequence $$$b$$$ with the presented technique. It is guaranteed that there exists at least one correct sequence $$$a$$$, which produces the given sequence $$$b$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of sequence $$$a$$$. $$$n$$$ is always even. The second line contains $$$\frac n 2$$$ integers $$$b_1, b_2, \dots, b_{\frac n 2}$$$ ($$$0 \le b_i \le 10^{18}$$$) — sequence $$$b$$$, where $$$b_i = a_i + a_{n - i + 1}$$$. It is guaranteed that there exists at least one correct sequence $$$a$$$, which produces the given sequence $$$b$$$.

Print $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^{18}$$$) in a single line. $$$a_1 \le a_2 \le \dots \le a_n$$$ should be satisfied. $$$b_i = a_i + a_{n - i + 1}$$$ should be satisfied for all valid $$$i$$$.

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(stdin, &n)

    var mx func (int64, int64) int64
    mx = func (i, j int64) int64 {
        if i > j {
            return i
        } else {
            return j
        }
    }

    var B = make([]int64, n / 2)
    var A = make([]int64, n)
    for i := 0; i * 2 < n; i++ {
        var j = n-i-1
        fmt.Fscan(stdin, &B[i])
        A[j] = B[i]

        if i > 0 {
            for A[i] < A[i-1] || A[j] > A[j+1] {
                // fmt.Println(A[i], A[i-1], A[j], A[j+1])
                var tmp = mx (A[i-1]-A[i], A[j]-A[j+1])
                A[i] += tmp
                A[j] -= tmp
                break
            }
        }
    }

    for _, num := range(A) {
        fmt.Print(num, " ")
    }
    fmt.Println()

}

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(stdin, &n)

    var mx func (int64, int64) int64
    mx = func (i, j int64) int64 {
        if i > j {
            return i
        } else {
            return j
        }
    }

    var A = make([]int64, n)
    for i := 0; i * 2 < n; i++ {
        var j = n-i-1
        fmt.Fscan(stdin, &A[j])

        if i > 0 {
            for A[i] < A[i-1] || A[j] > A[j+1] {
                // fmt.Println(A[i], A[i-1], A[j], A[j+1])
                var tmp = mx (A[i-1]-A[i], A[j]-A[j+1])
                A[i] += tmp
                A[j] -= tmp
                break
            }
        }
    }

    for _, num := range(A) {
        fmt.Print(num, " ")
    }
    fmt.Println()

}

package main

import (
	"bufio"
	//"bytes"
	"fmt"
	"math"
	"os"
	//"strconv"
)

func main() {
	var n int
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	for _, err := fmt.Fscan(stdin, &n); err == nil; _, err = fmt.Fscan(stdin, &n) {
		b := make([]int64, n/2)
		for i := 0; i < n/2; i++ {
			fmt.Fscan(stdin, &b[i])
		}
		var start int64 = 0
		var end int64 = math.MaxInt64
		a := make([]int64, n)
		for i := 0; i < n/2; i++ {
			if start + end > b[i] {
				end = b[i] - start
			} else {
				start = b[i] - end
			}
			a[i] = start
			a[n - 1 - i] = end
		}
		for i, val := range a {
			if i > 0 {
				stdout.WriteByte(' ')
			}
			fmt.Fprintf(stdout, "%d", val)
		}
		stdout.WriteByte('\n')
		stdout.Flush()
		/*
		var buffer bytes.Buffer
		for i, val := range a {
			if i > 0 {
				buffer.WriteByte(' ')
			}
			buffer.WriteString(strconv.FormatInt(val, 10))
		}
		buffer.WriteByte('\n')
		os.Stdout.Write(buffer.Bytes())
		*/
	}
}

package main

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

func main(){
	buf := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buf, "%d\n", &n)
	mat := make([]int64,n)
	var st int = 0
	var end int = n-1
	for i:=1;i <= n/2;i++{
		var v int64
		fmt.Fscanf(buf, "%d", &v)
		if i == 1{
			mat[st] = 0
			mat[end] = v
			st++
			end--
			continue
		}
		//fmt.Printf("%d %d %d\n",v,mat[st-1],mat[end+1])
		if v <=mat[st-1]+mat[end+1]{
			mat[st] = mat[st-1]
			mat[end]=v-mat[st]

		}else{
			mat[end] = mat[end+1]
			mat[st] = v-mat[end]
		}
		st++
		end--
	}
	for i:=0;i < n;i++{
		if i > 0{
			fmt.Printf(" ")
		}
		fmt.Printf("%d",mat[i])

	}
	fmt.Printf("\n")

}

package main

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

func main() {
	buffer := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscanf(buffer, "%d\n", &n)
	a := make([]int64, n + 1)
	b := make([]int64, n / 2 + 1)
	for i := 1; i <= n / 2; i++ {
		fmt.Fscanf(buffer, "%d", &b[i])
	}
	var t int64
	a[1] = 0
	a[n] = b[1] - a[1]
	for i := 2; i <= n/ 2; i++ {
		a[i] = a[i - 1]
		a[n + 1 - i] = b[i] - a[i]
		t = a[n + 1 - i] - a[n + 2 - i]
		if t > 0 {
			a[i] += t
			a[n + 1 - i] -= t
		}
	}
	for i:= 1; i <= n; i++ { fmt.Printf("%d ", a[i])}
}

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(stdin, &n)

    var mx func (int64, int64) int64
    mx = func (i, j int64) int64 {
        if i > j {
            return i
        } else {
            return j
        }
    }

    var A = make([]int64, n)
    for i := 0; i * 2 < n; i++ {
        var j = n-i-1
        fmt.Fscan(stdin, &A[j])

        if i > 0 {
            for A[i] < A[i-1] || A[j] > A[j+1] {
                // fmt.Println(A[i], A[i-1], A[j], A[j+1])
                var tmp = mx (A[i-1]-A[i], A[j]-A[j+1])
                A[i] += tmp
                A[j] -= tmp
                break
            }
        }
    }

    stdout := bufio.NewWriter(os.Stdout)

    for _, num := range(A) {
        fmt.Fprint(stdout, num)
        stdout.WriteByte(' ')
    }
    stdout.WriteByte('\n')
    stdout.Flush()

}

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)
    var n int
    fmt.Fscan(stdin, &n)

    var mx func (int, int) int
    mx = func (i, j int) int {
        if i > j {
            return i
        } else {
            return j
        }
    }

    var B = make([]int, n / 2)
    var A = make([]int, n)
    for i := 0; i * 2 < n; i++ {
        var j = n-i-1
        fmt.Fscan(stdin, &B[i])
        A[j] = B[i]

        if i > 0 {
            for A[i] < A[i-1] || A[j] > A[j+1] {
                // fmt.Println(A[i], A[i-1], A[j], A[j+1])
                var tmp = mx (A[i-1]-A[i], A[j]-A[j+1])
                A[i] += tmp
                A[j] -= tmp
                break
            }
        }
    }

    for _, num := range(A) {
        fmt.Print(num, " ")
    }
    fmt.Println()

}

package main

import "fmt"

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

func main() {
	var n int

	fmt.Scanf("%d\n", &n)
	var a []int = make([]int, n)
	var b []int = make([]int, n/2)

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

	var x, y = 0, b[0]
	for i, num := range(b) {
	    y = min(y, num)
	    x = num - y

	    a[n-i-1] = y
	    a[i] = x
	}

	for _, num := range(a) {
	    fmt.Print(num, " ")
	}
	fmt.Println()
}

package main

import (
	"bufio"
	//"bytes"
	"fmt"
	"math"
	"os"
	//"strconv"
)

func main() {
	var n int
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	for _, err := fmt.Fscan(stdin, &n); err == nil; _, err = fmt.Fscan(stdin, &n) {
		b := make([]int64, n/2)
		for i := 0; i < n/2; i++ {
			fmt.Fscan(stdin, &b[i])
		}
		var start int64 = 0
		var end int64 = math.MaxInt64
		a := make([]int64, n)
		for i := 0; i < n/2; i++ {
			if start + end > b[i] {
				end = b[i] - start
			} else {
				start = b[i] - end
			}
			a[i] = start
			a[n - 1 - i] = end
		}
		for i, val := range a {
			if i > 0 {
				fmt.Fprint(stdout, ' ')
			}
			fmt.Fprint(stdout, val)
		}
		fmt.Fprint(stdout, '\n')
		/*
		var buffer bytes.Buffer
		for i, val := range a {
			if i > 0 {
				buffer.WriteByte(' ')
			}
			buffer.WriteString(strconv.FormatInt(val, 10))
		}
		buffer.WriteByte('\n')
		os.Stdout.Write(buffer.Bytes())
		*/
	}
}

package main

import "fmt"

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

func main() {
	var n int

	fmt.Scanf("%d\n", &n)
	var a []int = make([]int, n)
	var b []int = make([]int, n/2)

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

	var x, y = 0, b[0]
	for i, num := range(b) {
	    y = min(y, num)

	    if num - y < x {
	        y = num - x
	    } else {
	        x = num - y
	    }

	    a[n-i-1] = y
	    a[i] = x
	}

	for _, num := range(a) {
	    fmt.Print(num, " ")
	}
	fmt.Println()
}