Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones.Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length n - 2 as a result.Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number.

First line of the input contains a single integer n (1 ≤ n ≤ 2·105), the length of the string that Andreid has. The second line contains the string of length n consisting only from zeros and ones.

Output the minimum length of the string that may remain after applying the described operations several times.

NoteIn the first sample test it is possible to change the string like the following: .In the second sample test it is possible to change the string like the following: .In the third sample test it is possible to change the string like the following: .

package main

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

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

func main() {
	defer out.Flush()

	in.ReadLine()
	var cnt rune = 0
	for {
		i, ok := in.ReadByte()
		if ok != nil {
			break;
		}
		switch i {
		case '0':
			cnt++
		case '1':
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

// codeforce 556A.go
package main

import (
	"fmt"
	"os"
)

func main() {
	var l int
	var str string
	//fin, _ := os.Open("in.txt")
	//fmt.Fscanf(fin, "%d %s", &l, &str)
	fmt.Fscanf(os.Stdin, "%d %s", &l, &str)
	//fmt.Println(l, str)
	rt := make([]int, l+5)
	j := 0
	var p int
	rt[0] = int(str[0]) - '0'
	for i := 1; i < l; i++ {
		p = int(str[i]) - '0'
		if j < 0 {
			j++
			rt[j] = p
		} else if rt[j]+p == 1 {
			j--
		} else {
			j++
			rt[j] = p
		}
	}
	fmt.Printf("%d\n", j+1)
}

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	var n, cnt0, cnt1 int
	var s string

	scan(&n, &s)

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			cnt0++
		} else {
			cnt1++
		}
	}

	if cnt0 > cnt1 {
		cnt0 = cnt1
	}

	println(len(s) - cnt0*2)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import "fmt"

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

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

    n0 := 0
    n1 := 0
    for i := 0; i < n; i++ {
        if s[i] == '0' {
            n0++
        } else {
            n1++
        }
    }

    fmt.Println(n - 2*min(n0, n1))
}

package main

import (
    "fmt"
    "math"
)

func main(){
    var n int
    var str string
    fmt.Scanf("%d %s", &n, &str)
    zero := 0.0
    one := 0.0

    for _, v := range(str) {
        if v == '1' {
            one += 1
        } else {
            zero += 1
        }
    }

    fmt.Printf("%d\n", int(math.Abs(zero - one)))
}

package main

import (
	"fmt"
	"math"
)

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

	countOnes := 0
	countZeros := 0
	for i := 0; i < len(str); i++ {
		if str[i] == '1' {
			countOnes++
		} else {
			countZeros++
		}
	}

	fmt.Printf("%d\n", int(math.Abs(float64(countOnes-countZeros))))

}

package main

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

func main() {
	var n int
	fmt.Scanf("%d \n", &n)
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	result := strings.Count(s, "1") - strings.Count(s, "0")
	if result < 0 {
		result = -result
	}
	fmt.Print(result)
}

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 getLine() string {
	s, _ := reader.ReadString('\n')
	for len(s) > 0 && (s[len(s)-1] == '\n' || s[len(s)-1] == '\r') {
		s = s[:len(s)-1]
	}
	return s
}

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

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

	s := getLine()
	ss := []rune(s)
	var c0 int
	var c1 int
	for i := 0; i < len(ss); i++ {
		if ss[i] == '0' {
			c0++
		} else {
			c1++
		}
	}
	var c int
	if c1 > c0 {
		c = c1 - c0
	} else {
		c = c0 - c1
	}
	printf("%d\n", c)
}

package main

import (
	"fmt"
	"math"
)

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

	one := 0
	zero := 0

	for i := 0; i < len(s); i++ {
		if s[i] == '1' {
			one++;
		}else{
			zero++;
		}
	}

	fmt.Println(math.Abs(float64(one - zero)))
}

package main

import (
	"fmt"
)

func main() {
	var (
		n   int
		A   [200001]int
		top = -1
		str string
	)
	fmt.Scanf("%d\n%s\n", &n, &str)
	for i := 0; i < n; i++ {
		if top == -1 || A[top] == int(str[i]) {
			top++
			A[top] = int(str[i])
		} else {
			top--
		}
	}
	fmt.Println(top + 1)
}

package main

import (
	"container/list"
	"fmt"
)

func main() {
	var n int
	var line string
	var c, t byte
	fmt.Scan(&n)
	fmt.Scan(&line)

	lst := list.New()
	for i := 0; i < len(line); i++ {
		c = line[i]
		if lst.Len() == 0 {
			lst.PushBack(c)
		} else {
			t = lst.Back().Value.(byte)
			if t != c {
				lst.Remove(lst.Back())
			} else {
				lst.PushBack(c)
			}
		}
	}

	fmt.Println(lst.Len())
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	_, _ = fmt.Scan(&len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	fmt.Printf("%d\n", len - int(math.Min(ones, zeroes)))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	in.ReadString('\n')
	s, err := in.ReadString('\n')
	if err != nil {
		log.Fatal(err)
	}
	str := strings.Fields(s)
	res := 0
	for _, v := range str[0] {
		if v == '1' {
			res++
		} else {
			res--
		}
	}
	res = int(math.Abs(float64(res)))
	out := bufio.NewWriter(os.Stdout)
	fmt.Fprint(out, res)
	out.Flush()
}

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n int
var s string

func main() {
	fmt.Fscan(reader, &n, &s)
	var a, b int
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			a++
		} else {
			b++
		}
	}
	fmt.Println(math.Abs(float64(a - b)))
}

package main

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

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

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

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

func main() {
	var T int
	var S string

	scanf("%d \n", &T)
	scanf("%s \n", &S)

	// for strings.Contains(S, "01") || strings.Contains(S, "10") {
	// 	S = strings.ReplaceAll(S, "01", "")
	// 	S = strings.ReplaceAll(S, "10", "")
	// }

	A := strings.Split(S, "")
	M := map[string]float64{}
	for _, v := range A {
		if _, ok := M[v]; !ok {
			M[v] = 1.0
		}else {
			M[v] = M[v] + 1.0
		}
	}

	fmt.Println(math.Abs(M["1"] - M["0"]))
}

package main

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

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

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)
	var n, cnt int
	var s string
	scan(&n, &s)

	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			cnt--
		} else {
			cnt++
		}
	}
	println(Abs(int64(cnt)))

}

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

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import "fmt"
import "math"

func main() {
	var n int
	var s string
	var zero, one int
	fmt.Scan(&n)
	fmt.Scan(&s)
	for i := 0; i < n; i++ {
		if s[i] == '0' {
			zero++
		}
		if s[i] == '1' {
			one++
		}
	}
	fmt.Println(int(math.Abs(float64(zero - one))))
}

package main

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

var in *bufio.Scanner = bufio.NewScanner(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	in.Scan()
	in.Scan()
	var cnt rune = 0
	for _, i := range in.Text() {
		if i == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

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

func main() {
	defer out.Flush()

	in.ReadLine()
	var cnt rune = 0
	a := make([]byte, 200100)
	for i, _ := in.Read(a); i > 0; i-- {
		switch a[i - 1] {
		case '0':
			cnt++
		case '1':
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

var in *bufio.Scanner = bufio.NewScanner(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

type Tuple struct{ x, y, z interface{} }

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	in.Scan()
	in.Scan()
	cnt := int32(0)
	for _, i := range in.Text() {
		if i == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

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

func main() {
	defer out.Flush()

	in.ReadLine()

	var cnt rune = 0
	a, _, _ := in.ReadLine()
	for _, i := range a {
		if i == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

var in *bufio.Scanner = bufio.NewScanner(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

type Tuple struct{ x, y, z interface{} }

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	in.Scan()
	in.Scan()
	cnt := 0
	for _, i := range in.Text() {
		if i == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

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

func main() {
	defer out.Flush()

	in.ReadLine()
	var cnt rune = 0
	a := make([]byte, 200100)
	for i, _ := in.Read(a); i > 0; i-- {
		if a[i-1] == '0' {
			cnt++
		} else {
			cnt--
		}
	}
	if cnt < 0 {
		fmt.Println(-cnt)
	} else {
		fmt.Println(cnt)
	}
}

package main

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

func main() {
	var len int // Size of the string
	var str string // Input string

	_, _ = fmt.Scan(&len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
	bufio.NewWriter(os.Stdout).Flush()
}

package main

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

func main() {
	var len int // Size of the string
	var str string // Input string

	reader := bufio.NewReader(os.Stdin)
	in, _, _ := reader.ReadLine()
	len,_ = strconv.Atoi(string(in))
	in, _, _ = reader.ReadLine()
	str = string(in)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scanf("%d\n%s", &len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scan(&len)
	fmt.Scan(&str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scanf("%d %s", &len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

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

func main() {
	var len int // Size of the string
	var str string // Input string

	reader := bufio.NewReader(os.Stdin)
	in, _, _ := reader.ReadLine()
	len,_ = strconv.Atoi(string(in))
	in, _, _ = reader.ReadLine()
	str = string(in)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	print(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	_, _ = fmt.Scan(&len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scanf("%d", &len)
	fmt.Scanf("%s", &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var len int // Size of the string
	var str string // Input string

	fmt.Scanf("%d\n%s\n", &len, &str)

	ones := float64(2*strings.Count(str, "1"))
	zeroes := float64(2*strings.Count(str, "0"))

	println(len - int(math.Min(ones, zeroes)))
}

package main

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

var inf int = 0x3f3f3f3f
var reader *bufio.Reader

func init() {
	stdin := os.Stdin
	// stdin, _ = os.Open("1.in")
	reader = bufio.NewReaderSize(stdin, 1<<20)
}

var n int
var s string

func main() {
	fmt.Fscan(reader, &n, &s)
	var a, b []int
	for i := 0; i < n; i++ {
		if s[i] == '1' {
			a = append(a, i)
		} else {
			b = append(b, i)
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sort.Sort(sort.IntSlice(b))
	ans := 0
	for i := len(b) - 1; i >= 0; i-- {
		for {
			if len(a) == 0 {
				break
			}
			if b[i] < a[0] {
				a = a[1:len(a)]
			} else {
				a = a[1:len(a)]
				ans++
				break
			}
		}
	}
	fmt.Println(n - 2*ans)
}


Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i (i > 0) has height hi. The goal of the game is to reach n-th pylon, and the only move the player can do is to jump from the current pylon (let's denote its number as k) to the next one (its number will be k + 1). When the player have made such a move, its energy increases by hk - hk + 1 (if this value is negative the player loses energy). The player must have non-negative amount of energy at any moment of the time. Initially Caisa stand at 0 pylon and has 0 energy. The game provides a special opportunity: one can pay a single dollar and increase the height of anyone pylon by one. Caisa may use that opportunity several times, but he doesn't want to spend too much money. What is the minimal amount of money he must paid to reach the goal of the game?

The first line contains integer n (1 ≤ n ≤ 105). The next line contains n integers h1, h2, ..., hn (1  ≤  hi  ≤  105) representing the heights of the pylons.

Print a single number representing the minimum number of dollars paid by Caisa.

NoteIn the first sample he can pay 4 dollars and increase the height of pylon with number 0 by 4 units. Then he can safely pass to the last pylon.

package main

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

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

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	money, energy := 0, 0
	preHeight, currentHeight := nextInt(), 0
	money += preHeight
	difHeight := 0
			// println(money, energy, preHeight, currentHeight)
	for i := 1; i < n; i++ {
		currentHeight = nextInt()

		if currentHeight <= preHeight {
			energy += preHeight - currentHeight
		} else {
			difHeight = currentHeight - preHeight

			if energy >= difHeight {
				energy = energy - difHeight
			} else {
				money += difHeight - energy
				energy = 0
			}
		}
			// println(money, energy, preHeight, currentHeight)

		preHeight = currentHeight
	}

	println(money)
}

func next() string {
	if !scanner.Scan() {
		panic("Scan error")
	}
	return scanner.Text()
}

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

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

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

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

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

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"runtime/pprof"
	"strconv"
	"time"
	"unicode/utf8"
	"math/rand"
)

// ******************************** CODE STARTS ********************************

const (
)

var (
)

func solve() {
	n := readInt()
	min := 0
	value := 0
	x0 := 0
	for i := 0; i < n; i++ {
		x1 := readInt()
		value += x0 - x1
		min = minInt(min, value)
		x0 = x1
	}
	if min < 0 {
		printInt(-min)
	} else {
		printInt(0)
	}
	printLine()
}
// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	dbg := flag.Bool("dbg", false, "Equals true, if run is in debug mode.")
	opt := flag.Bool("opt", false, "Equals true, if run is in optimized mode.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *opt || *dbg {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
		if *dbg {
			cpuprofile, _ := os.Create("/home/outside/coding/workspace/go/io/cpuprofile.txt")
			pprof.StartCPUProfile(cpuprofile)
			defer cpuprofile.Close()
			defer pprof.StopCPUProfile()
		}
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	rand.Seed(int64(time.Now().Nanosecond()))
	solve()
}

// Read.

func readString() string {
	scanner.Scan()
	ans := scanner.Text()
	return ans
}

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

func readInt64() int64 {
	ans, _ := strconv.ParseInt(readString(), 10, 64)
	return ans
}

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	return p[j].a < p[i].a
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

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

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

func absInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

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

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

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a < b {
		return a
	} else {
		return b
	}
}

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(reader, &n)
	var height = make([]int, n)
	var res = 0
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &height[i])
		if res < height[i] {
			res = height[i]
		}
	}
	fmt.Println(res)
}

package main

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

// import bufio, os, strconv
var sc *bufio.Scanner

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

func nextInt() int {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	if !sc.Scan() {
		panic("could not scan the reader")
	}
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

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

func main() {
	scInit()
	n := nextInt()
	z := 0
	for i := 0; i < n; i++ {
		z = max(z, nextInt())
	}
	fmt.Println(z)
}

package main

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

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

func ReadInt32() int {
    scanner.Scan()
    ans, _ := strconv.Atoi(scanner.Text())
    return ans
}

func main() {
    defer writer.Flush()
    scanner.Split(bufio.ScanWords)

    var n, h1, h2 int
    n = ReadInt32()
    power := 0
    ans := 0
    h1 = 0
    for i := 0; i < n; i++ {
        h2 = ReadInt32()
        power += h1 - h2
        if power < 0 {
            ans += power
            power = 0
        }
        h1 = h2
    }

    fmt.Println(-ans)
}


We guessed some integer number $$$x$$$. You are given a list of almost all its divisors. Almost all means that there are all divisors except $$$1$$$ and $$$x$$$ in the list.Your task is to find the minimum possible integer $$$x$$$ that can be the guessed number, or say that the input data is contradictory and it is impossible to find such number.You have to answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 25$$$) — the number of queries. Then $$$t$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 300$$$) — the number of divisors in the list. The second line of the query contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$2 \le d_i \le 10^6$$$), where $$$d_i$$$ is the $$$i$$$-th divisor of the guessed number. It is guaranteed that all values $$$d_i$$$ are distinct.

For each query print the answer to it. If the input data in the query is contradictory and it is impossible to find such number $$$x$$$ that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible $$$x$$$.

/*
URL:
https://codeforces.com/problemset/problem/1165/D
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n int
	D []int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		D = ReadInt64Slice(n)

		solve()
	}
}

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

	ans := D[0] * D[len(D)-1]
	for i := 1; i <= n/2; i++ {
		if ans != D[i]*D[n-1-i] {
			fmt.Println(-1)
			return
		}
	}

	C := divisor(ans)
	sort.Slice(C, func(i, j int) bool { return C[i] < C[j] })

	if len(C) != len(D) {
		fmt.Println(-1)
		return
	}
	for i := 0; i < len(C); i++ {
		if C[i] != D[i] {
			fmt.Println(-1)
			return
		}
	}

	fmt.Println(ans)
}

// 約数の列挙: O(sqrt(n))
func divisor(n int64) []int64 {
	res := []int64{}

	for i := int64(2); i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i != (n / i) {
				res = append(res, (n / i))
			}
		}
	}

	return res
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1165D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mx int = 1e6
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	divisors := func(n int64, a []int) bool {
		ds := []int{}
		for d := int64(2); d*d <= n; d++ {
			if n%d == 0 {
				if d > 1e6 {
					return false
				}
				ds = append(ds, int(d))
				if d*d < n {
					if n/d > 1e6 {
						return false
					}
					ds = append(ds, int(n/d))
				}
				if len(ds) > len(a) {
					return false
				}
			}
		}
		if len(ds) < len(a) {
			return false
		}
		sort.Ints(ds)
		sort.Ints(a)
		for i, v := range ds {
			if v != a[i] {
				return false
			}
		}
		return true
	}

	var t, n int
o:
	for Fscan(in, &t); t > 0; t-- {
		ps := map[int]int8{}
		minP := int(1e9)
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			for v := a[i]; v > 1; {
				p := lpf[v]
				e := int8(1)
				for v /= p; lpf[v] == p; v /= p {
					e++
				}
				if e > ps[p] {
					ps[p] = e
				}
				if p < minP {
					minP = p
				}
			}
		}
		ans := int64(1)
		for p, e := range ps {
			for ; e > 0; e-- {
				ans *= int64(p)
				if ans > 1e12 {
					Fprintln(out, -1)
					continue o
				}
			}
		}
		for _, v := range a {
			if int64(v) == ans {
				ans *= int64(minP)
				if ans > 1e12 {
					Fprintln(out, -1)
					continue o
				}
				break
			}
		}
		if !divisors(ans, a) {
			ans = -1
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1165D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	divisors := func(n int64, a []int) bool {
		res := []int{}
		for d := int64(2); d*d <= n; d++ {
			if n%d == 0 {
				res = append(res, int(d))
				if d*d < n {
					res = append(res, int(n/d))
				}
			}
		}
		sort.Ints(res)
		if len(res) != len(a) {
			return false
		}
		for i, v := range res {
			if v != a[i] {
				return false
			}
		}
		return true
	}

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		sort.Ints(a)
		ans := int64(a[0]) * int64(a[n-1])
		if !divisors(ans, a) {
			ans = -1
		}
		Fprintln(out, ans)
	}
}

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

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/1165/D

package main

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

func getFactors(x int64) []int64 {
	factors := []int64{}
	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			factors = append(factors, i)
			if i*i != x {
				factors = append(factors, x/i)
			}
		}
	}
	return factors
}

func eq(a []int64, b []int64) bool {
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			return false
		}
	}
	return true
}

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

func Solve(n int, d []int64) int64 {
	sortInt64(d)
	x := d[0] * d[n-1]
	factors := getFactors(x)
	sortInt64(factors)
	if eq(d, factors) {
		return x
	}
	return -1
}

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

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscanf(reader, "%d\n", &n)
		d := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(reader, "%d", &d[i])
		}
		fmt.Fscanf(reader, "\n")
		fmt.Fprintf(writer, "%d\n", Solve(n, d))
	}
}

/*
URL:
https://codeforces.com/problemset/problem/1165/D
*/

package main

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

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

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

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

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

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

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

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n int
	D []int64
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt()
		D = ReadInt64Slice(n)

		solve()
	}
}

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

	ans := D[0] * D[len(D)-1]
	for i := 1; i <= n/2; i++ {
		if ans != D[i]*D[n-1-i] {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}

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

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

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1165D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mx int = 1e6
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}
	divisors := func(n int64) (res []int) {
		for d := int64(2); d*d <= n; d++ {
			if n%d == 0 {
				if d > 1e6 {
					return nil
				}
				res = append(res, int(d))
				if d*d < n {
					if n/d > 1e6 {
						return nil
					}
					res = append(res, int(n/d))
				}
			}
		}
		return
	}

	var t, n int
o:
	for Fscan(in, &t); t > 0; t-- {
		ps := map[int]int8{}
		minP := int(1e9)
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			for v := a[i]; v > 1; {
				p := lpf[v]
				e := int8(1)
				for v /= p; lpf[v] == p; v /= p {
					e++
				}
				if e > ps[p] {
					ps[p] = e
				}
				if p < minP {
					minP = p
				}
			}
		}
		ans := int64(1)
		for p, e := range ps {
			for ; e > 0; e-- {
				ans *= int64(p)
				if ans > 1e12 {
					Fprintln(out, -1)
					continue o
				}
			}
		}
		for _, v := range a {
			if int64(v) == ans {
				ans *= int64(minP)
				if ans > 1e12 {
					Fprintln(out, -1)
					continue o
				}
				break
			}
		}
		if d := divisors(ans); d == nil || len(d) != len(a) {
			Fprintln(out, -1)
		} else {
			sort.Ints(d)
			sort.Ints(a)
			for i, v := range d {
				if v != a[i] {
					Fprintln(out, -1)
					continue o
				}
			}
		}
		Fprintln(out, ans)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1165D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mx int = 1e6
	lpf := [mx + 1]int{1: 1}
	for i := 2; i <= mx; i++ {
		if lpf[i] == 0 {
			for j := i; j <= mx; j += i {
				if lpf[j] == 0 {
					lpf[j] = i
				}
			}
		}
	}

	var t, n int
	for Fscan(in, &t); t > 0; t-- {
		ps := map[int]int8{}
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			for v := a[i]; v > 1; {
				p := lpf[v]
				e := int8(1)
				for v /= p; lpf[v] == p; v /= p {
					e++
				}
				if e > ps[p] {
					ps[p] = e
				}
			}
		}
		ans := int64(1)
		for p, e := range ps {
			for ; e > 0; e-- {
				ans *= int64(p)
			}
		}
		for _, v := range a {
			if int64(v) == ans {
				ans *= 2
				break
			}
		}
		Fprintln(out, ans)
	}
}

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


The store sells $$$n$$$ items, the price of the $$$i$$$-th item is $$$p_i$$$. The store's management is going to hold a promotion: if a customer purchases at least $$$x$$$ items, $$$y$$$ cheapest of them are free.The management has not yet decided on the exact values of $$$x$$$ and $$$y$$$. Therefore, they ask you to process $$$q$$$ queries: for the given values of $$$x$$$ and $$$y$$$, determine the maximum total value of items received for free, if a customer makes one purchase.Note that all queries are independent; they don't affect the store's stock.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the number of items in the store and the number of queries, respectively. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le 10^6$$$), where $$$p_i$$$ — the price of the $$$i$$$-th item. The following $$$q$$$ lines contain two integers $$$x_i$$$ and $$$y_i$$$ each ($$$1 \le y_i \le x_i \le n$$$) — the values of the parameters $$$x$$$ and $$$y$$$ in the $$$i$$$-th query.

For each query, print a single integer — the maximum total value of items received for free for one purchase.

NoteIn the first query, a customer can buy three items worth $$$5, 3, 5$$$, the two cheapest of them are $$$3 + 5 = 8$$$.In the second query, a customer can buy two items worth $$$5$$$ and $$$5$$$, the cheapest of them is $$$5$$$.In the third query, a customer has to buy all the items to receive the three cheapest of them for free; their total price is $$$1 + 2 + 3 = 6$$$.

package main

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

func main() {
	var n, q int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &q)
	a := make([]int, n)
	total := make([]int64, n+1)

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

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

	for i := 0; i < n; i++ {
		total[i+1] = total[i] + int64(a[i])
	}

	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		fmt.Println(total[x] - total[x-y])
	}
}

package main

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

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

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

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

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

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

/**
gopherbots resolvi en 218ms
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	sum := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = int64(in.NextInt())
	}

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

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

	//var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		fmt.Println(sum[n-x+y]-sum[n-x])
		//ans.WriteString(fmt.Sprintf("%d\n", sum[n-x+y]-sum[n-x]))
	}

	//fmt.Print(ans.String())
}

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

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

package main

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

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

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

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

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

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

/**
gopherbots resolvi en 218ms
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	sum := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = int64(in.NextInt())
	}

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

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

	var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		ans.WriteString(fmt.Sprintf("%d\n", sum[n-x+y]-sum[n-x]))
	}

	fmt.Print(ans.String())
}

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

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

package main

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

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

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

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

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

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

/**
gopherbots resolvi en 218ms
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	sum := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = in.NextInt64()
	}

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

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

	var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		ans.WriteString(fmt.Sprintf("%d\n", sum[n-x+y]-sum[n-x]))
	}

	fmt.Print(ans.String())
}

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

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

package main

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

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

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

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

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

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

/**
gopherbots resolvi en 218ms
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = in.NextInt()
	}
	sort.Ints(arr)
	sum := make([]int64, n+1)
	for i := 0; i < n; i++ {
		if i == 0 {
			sum[i+1] = int64(arr[i])
		} else {
			sum[i+1] = sum[i] + int64(arr[i])
		}
	}

	var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		ans.WriteString(fmt.Sprintf("%d\n", sum[n-x+y]-sum[n-x]))
	}

	fmt.Print(ans.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = in.NextInt()
	}
	sort.Ints(arr)
	sum := make([]int64, n+1)
	for i := 0; i < n; i++ {
		if i == 0 {
			sum[i+1] = int64(arr[i])
		} else {
			sum[i+1] = sum[i] + int64(arr[i])
		}
	}

	var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		if x < n {
			ans.WriteString(fmt.Sprintf("%d\n", sum[n-x+y]-sum[n-x]))
		} else {
			ans.WriteString(fmt.Sprintf("%d\n", sum[y]))
		}

	}

	fmt.Print(ans.String())
}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, q int
	fmt.Fscan(in, &n, &q)
	p := make([]int64, n)
	for i := range p {
		fmt.Fscan(in, &p[i])
	}
	sort.Slice(p, func(i, j int) bool { return p[i] > p[j] })
	s := make([]int64, n+1)
	for i := 1; i <= n; i++ {
		s[i] = s[i-1] + p[i-1]
	}
	for t := 0; t < q; t++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		fmt.Fprintln(out, s[x]-s[x-y])
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
var tc = 1
var DEBUG = os.Getenv("DEBUG") != ""

func solve() {}

func main() {
	// var T int
	// scan(&T)
	// for ; T > 0; T-- {
	// 	solve()
	// 	tc++
	// }
	var n, q int
	scan(&n, &q)
	a := make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	sort.Ints(a)
	for i := 1; i < n; i++ {
		a[i] += a[i-1]
	}
	for i := 0; i < q; i++ {
		var x, y int
		scan(&x, &y)

		ret := a[n-x+y-1]
		if n-x-1 >= 0 {
			ret -= a[n-x-1]
		}
		printf("%d\n", ret)

		tc++
	}

}

func yn(b bool) string      { return map[bool]string{true: "YES", false: "NO"}[b] }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }
func printf(format string, a ...interface{}) {
	if DEBUG {
		format = fmt.Sprintf("Test #%d: %s", tc, format)
	}
	fmt.Printf(format, a...)
}

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

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

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

// 00
package main

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

func main() {
	var n, q int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n, &q)
	p := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &p[i])
	}
	sort.Slice(p, func(i, j int) bool { return p[i] < p[j] })

	for i := 1; i < n; i++ {
		p[i] += p[i-1]
	}
	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)
		ans := p[n-x+y-1]
		if n-x-1 >= 0 {
			ans -= p[n-x-1]
		}
		fmt.Println(ans)
		// add
	}
}

// 00
package main

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

func main() {
	var n, q int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n, &q)
	p := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &p[i])
	}
	sort.Slice(p, func(i, j int) bool { return p[i] < p[j] })

	for i := 1; i < n; i++ {
		p[i] += p[i-1]
	}
	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)
		ans := p[n-x+y-1]
		if n-x-1 >= 0 {
			ans -= p[n-x-1]
		}
		fmt.Println(ans)
	}
}

package main

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

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 n, q, l int
	fmt.Fscan(in, &n, &q)
	arr := make([]int, n)
	for l < n {
		fmt.Fscan(in, &arr[l])
		l++
	}
	l = n - 2
	der := make([]int64, n)
	sort.Ints(arr)
	der[n-1] = int64(arr[n-1])
	for l >= 0 {
		der[l] = der[l+1] + int64(arr[l])
		l--
	}
	//fmt.Println(der)
	//fmt.Println(arr)
	var b, c int
	for i := 0; i < q; {
		fmt.Fscan(in, &b, &c)
		if b == c {
			fmt.Fprintln(out, der[n-b])
		} else {
			fmt.Fprintln(out, der[n-b]-der[n-b+c])
		}
		i++
	}

}

package main

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

const maxTokenSize = 262144 * 10

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, maxTokenSize), maxTokenSize)
	scanner.Scan()

	in := strings.Split(scanner.Text(), " ")
	//maxProducts, _ := strconv.Atoi(in[0])
	c, _ := strconv.Atoi(in[1])

	scanner.Scan()
	sub := strings.Split(scanner.Text(), " ")

	var sums []int64
	for _, s := range sub {
		ss, _ := strconv.ParseInt(s, 10, 64)
		sums = append(sums, ss)
	}

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

	var sum int64
	for i, v := range sums {
		sum += v
		sums[i] = sum
	}

	for i := 0; i < c; i++ {
		scanner.Scan()
		sub := strings.Split(scanner.Text(), " ")

		x, _ := strconv.Atoi(sub[0])
		y, _ := strconv.Atoi(sub[1])

		if x == y {
			fmt.Println(sums[x - 1])
		} else {
			fmt.Println(sums[x-1] - sums[x-y-1])
		}
	}
}

package main

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

/*

5 3
1 2 3 5  5
1 3 6 11 16

*/

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

	p := make([]int64, n)

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

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

	psa := make([]int64, n)

	for i := range p {
		psa[i] = p[i]

		if i != 0 {
			psa[i] += psa[i-1]
		}
	}

	for i := 0; i < q; i++ {
		var x, y int
		scanf("%d %d\n", &x, &y)

		l := n - x
		r := n - x + y - 1

		s := psa[r] - psa[l] + p[l]
		fmt.Fprintln(writer, s)
	}
}

//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 ...int64) (sum int64) {
	for _, num := range nums {
		sum += int64(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"
	"sort"
)

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

	var n, q int
	fmt.Fscan(in, &n, &q)

	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	sort.Slice(a, func(i, j int) bool {
		return a[i] > a[j]
	})

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

		fmt.Fprintln(out, m[x]-m[x-y])
	}
}

package main

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

var (
	reader     = bufio.NewReader(os.Stdin)
	n, q, x, y int
	p, sum     []int64
)

func solve(x, y int) int64 {
	return sum[x] - sum[x-y]
}

func main() {
	fmt.Fscan(reader, &n, &q)
	p, sum = make([]int64, n), make([]int64, n+1)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &p[i])
	}
	sort.Slice(p, func(i, j int) bool {
		return p[i] > p[j]
	})
	for i := 1; i < n+1; i++ {
		sum[i] = sum[i-1] + p[i-1]
	}
	for i := 0; i < q; i++ {
		fmt.Fscan(reader, &x, &y)
		fmt.Println(solve(x, y))
	}
}

package main

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

func A3() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	//Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, x, y, q int
		Fscan(in, &n, &q)
		arr, sum := make([]int, n), make([]int64, n+1)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
		}
		sort.Ints(arr)
		for i := 1; i <= n; i++ {
			sum[i] = sum[i-1] + int64(arr[i-1])
		}
		for i := 0; i < q; i++ {
			Fscan(in, &x, &y)
			Fprintln(out, sum[(n-x+y)]-sum[n-x])
		}
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A3() }

package main

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

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

func main() {
	defer w.Flush()
	var n, q int
	fmt.Fscan(r, &n, &q)
	nums := make([]int, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	sort.Slice(nums, func(i, j int) bool {
		return nums[i] > nums[j]
	})
	pre := make([]int64, n+1)
	for i:=0;i<n;i++ {
		pre[i+1] = pre[i] + int64(nums[i])
	}
	for qq:=1;qq<=q;qq++ {
		var x, y int
		fmt.Fscan(r, &x, &y)
		fmt.Fprintln(w, pre[x] - pre[x-y])
	}
}

package main

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

func main() {
	var n, q int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &q)
	a := make([]int, n)
	total := make([]int, n+1)

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

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

	for i := 0; i < n; i++ {
		total[i+1] = total[i] + a[i]
	}

	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		fmt.Println(total[x] - total[x-y])
	}
}

package main

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

func main() {
	var n, q int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &q)
	a := make([]int, n)
	total := make([]int, n+1)

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

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

	for i := 0; i < n; i++ {
		total[i+1] = total[i] + a[i]
	}

	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		fmt.Fprintln(os.Stdout, total[x]-total[x-y])
	}
}

package main

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

func main() {
	var n, q int
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n, &q)
	a := make([]int, n)
	total := make([]int, n+1)

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

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

	for i := 0; i < n; i++ {
		total[i+1] = total[i] + a[i]
	}

	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		fmt.Fprintln(out, total[x]-total[x-y])
	}
}

package main

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

func main() {
	var n, q int
	fmt.Scanln(&n, &q)
	a := make([]int, n)
	total := make([]int, n+1)
	in := bufio.NewReader(os.Stdin)

	for i := 0; i < n; i++ {
		fmt.Scan(in, &a[i])
	}
	fmt.Scanln(in)

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

	for i := 0; i < n; i++ {
		total[i+1] = total[i] + a[i]
	}

	for i := 0; i < q; i++ {
		var x, y int
		fmt.Scanln(in, &x, &y)
		fmt.Println(total[x] - total[x-y])
	}
}

package main

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

func main() {
	var n, q int
	fmt.Scanln(&n, &q)
	a := make([]int, n)
	total := make([]int, n+1)
	in := bufio.NewReader(os.Stdin)

	for i := 0; i < n; i++ {
		fmt.Scan(in, &a[i])
	}
	fmt.Scanln(in)

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

	for i := 0; i < n; i++ {
		total[i+1] = total[i] + a[i]
	}

	for i := 0; i < q; i++ {
		var x, y int
		fmt.Scanln(in, &x, &y)
		fmt.Println(in, total[x]-total[x-y])
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, q int
	fmt.Scanln(&n, &q)
	a := make([]int, n)
	total := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	fmt.Scanln()

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

	total[0] = a[0]
	for i := 1; i < n; i++ {
		total[i] = total[i-1] + a[i]
	}

	fmt.Println("->", total)

	for i := 0; i < q; i++ {
		var x, y int
		fmt.Scanln(&x, &y)
		if x == y {
			fmt.Println(total[x-1])
		} else {
			fmt.Println(total[x-1] - total[x-y-1])
		}

	}
}

package main

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

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

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

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

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

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

/**
gopherbots resolvi en 218ms
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = in.NextInt()
	}
	sort.Ints(arr)
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		if i == 0 {
			sum[i+1] = arr[i]
		} else {
			sum[i+1] = sum[i] + arr[i]
		}
	}

	var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		ans.WriteString(fmt.Sprintf("%d\n", sum[n-x+y]-sum[n-x]))
	}

	fmt.Print(ans.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = in.NextInt()
	}
	sort.Ints(arr)
	sum := make([]int64, n+1)
	for i := 0; i < n; i++ {
		if i == 0 {
			sum[i+1] = int64(arr[i])
		} else {
			sum[i+1] = sum[i] + int64(arr[i])
		}
	}

	var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		if x < n {
			if x == y {
				ans.WriteString(fmt.Sprintf("%d\n", sum[n]-sum[n-y]))
			} else if y == 1{
				ans.WriteString(fmt.Sprintf("%d\n", sum[n-x+y]-sum[n-x]))
			} else {
				ans.WriteString(fmt.Sprintf("%d\n", sum[n]-(sum[n-x+y]-sum[n-x])))
			}
		} else {
			ans.WriteString(fmt.Sprintf("%d\n", sum[y]))
		}

	}

	fmt.Print(ans.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = in.NextInt()
	}
	sort.Ints(arr)
	sum := make([]int64, n+1)
	for i := 0; i < n; i++ {
		if i == 0 {
			sum[i+1] = int64(arr[i])
		} else {
			sum[i+1] = sum[i] + int64(arr[i])
		}
	}

	var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		if x < n {
			if x == y {
				ans.WriteString(fmt.Sprintf("%d\n", sum[n]-sum[n-y]))
			} else {
				ans.WriteString(fmt.Sprintf("%d\n", sum[n]-(sum[n-x+y]-sum[n-x])))
			}
		} else {
			ans.WriteString(fmt.Sprintf("%d\n", sum[y]))
		}

	}

	fmt.Print(ans.String())
}

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

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

package main

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

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

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

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

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

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

/**
Run solve the problem CF1697B
Date: 27/06/22
User: pepradere
URL:  https://codeforces.com/problemset/problem/1697/B
Problem: CF1697B
**/
func (in *CF1697B) Run() {
	n, q := in.NextInt(), in.NextInt()
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = in.NextInt()
	}
	sort.Ints(arr)
	sum := make([]int, n+1)
	for i := 0; i < n; i++ {
		if i == 0 {
			sum[i+1] = arr[i]
		} else {
			sum[i+1] = sum[i] + arr[i]
		}
	}

	var ans strings.Builder
	for i := 0; i < q; i++ {
		x, y := in.NextInt(), in.NextInt()
		if x < n {
			if x == y {
				ans.WriteString(fmt.Sprintf("%d\n", sum[n]-sum[n-y]))
			} else {
				ans.WriteString(fmt.Sprintf("%d\n", sum[n]-(sum[n-x+y]-sum[n-x])))
			}
		} else {
			ans.WriteString(fmt.Sprintf("%d\n", sum[y]))
		}

	}

	fmt.Print(ans.String())
}

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

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

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		line := scanner.Text()
		item_queries := strings.Split(line, " ")

		iq := make([]int, len(item_queries))
		for i := range iq {
			iq[i], _ = strconv.Atoi(item_queries[i])
		}

		if scanner.Scan() {
			line := scanner.Text()
			numbers := strings.Split(line, " ")
			numb := make([]int, len(numbers))
			for i := range numb {
				numb[i], _ = strconv.Atoi(numbers[i])
			}

			sort.Ints(numb)
			iteration := iq[1]

			for i := 0; i < iteration; i++ {
				if scanner.Scan() {
					line := scanner.Text()
					queries := strings.Split(line, " ")
					q := make([]int, len(queries))
					for z := range q {
						q[z], _ = strconv.Atoi(queries[z])
					}

					max := numb[len(numb)-q[0]:]

					min := max[:q[1]]

					var m int
					for _, minus := range min {
						m = m + minus
					}
					fmt.Println(m)
				}
			}
		}
	}
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		line := scanner.Text()
		item_queries := strings.Split(line, " ")

		iq := make([]int, len(item_queries))
		for i := range iq {
			iq[i], _ = strconv.Atoi(item_queries[i])
		}

		if scanner.Scan() {
			line := scanner.Text()
			numbers := strings.Split(line, " ")
			numb := make([]int, len(numbers))
			for i := range numb {
				numb[i], _ = strconv.Atoi(numbers[i])
			}

			sort.Sort(sort.Reverse(sort.IntSlice(numb)))
			iteration := iq[1]
			m := numb[0]
			var l []int
			l = append(l, m)
			for i := 0; i < len(numb)-1; i++ {
				m = l[i] + numb[i+1]
				l = append(l, m)
			}
			for i := 0; i < iteration; i++ {
				if scanner.Scan() {
					line := scanner.Text()
					queries := strings.Split(line, " ")
					q := make([]int, len(queries))
					for z := range q {
						q[z], _ = strconv.Atoi(queries[z])
					}

					t := (q[0] - q[1]) - 1
					if t >= 0 {
						fmt.Println(l[q[0]-1] - l[t])
					} else {
						fmt.Println(l[q[0]-1])
					}
				}
			}
		}
	}
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 64*1024)
	scanner.Buffer(buf, 1024*1024)
	if scanner.Scan() {
		line := scanner.Text()
		item_queries := strings.Split(line, " ")

		iq := make([]int, len(item_queries))
		for i := range iq {
			iq[i], _ = strconv.Atoi(item_queries[i])
		}

		if scanner.Scan() {
			line := scanner.Text()
			numbers := strings.Split(line, " ")
			numb := make([]int, len(numbers))
			for i := range numb {
				numb[i], _ = strconv.Atoi(numbers[i])
			}

			sort.Sort(sort.Reverse(sort.IntSlice(numb)))
			iteration := iq[1]
			m := numb[0]
			var l []int
			l = append(l, m)
			for i := 0; i < len(numb)-1; i++ {
				m = l[i] + numb[i+1]
				l = append(l, m)
			}
			for i := 0; i < iteration; i++ {
				if scanner.Scan() {
					line := scanner.Text()
					queries := strings.Split(line, " ")
					q := make([]int, len(queries))
					for i := range q {
						q[i], _ = strconv.Atoi(queries[i])
					}

					t := (q[0] - q[1]) - 1
					if t >= 0 {
						fmt.Println(l[q[0]-1] - l[t])
					} else {
						fmt.Println(l[q[0]-1])
					}
				}
			}
		}
	}
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		line := scanner.Text()
		item_queries := strings.Split(line, " ")

		iq := make([]int, len(item_queries))
		for i := range iq {
			iq[i], _ = strconv.Atoi(item_queries[i])
		}

		if scanner.Scan() {
			line := scanner.Text()
			numbers := strings.Split(line, " ")
			numb := make([]int, len(numbers))
			for i := range numb {
				numb[i], _ = strconv.Atoi(numbers[i])
			}

			sort.Sort(sort.Reverse(sort.IntSlice(numb)))
			iteration := iq[1]
			m := numb[0]
			var l []int
			l = append(l, m)
			for i := 0; i < len(numb)-1; i++ {
				m = l[i] + numb[i+1]
				l = append(l, m)
			}
			for i := 0; i < iteration; i++ {
				if scanner.Scan() {
					line := scanner.Text()
					queries := strings.Split(line, " ")
					q := make([]int, len(queries))
					for i := range q {
						q[i], _ = strconv.Atoi(queries[i])
					}

					t := (q[0] - q[1]) - 1
					if t >= 0 {
						fmt.Println(l[q[0]-1] - l[t])
					} else {
						fmt.Println(l[q[0]-1])
					}
				}
			}
		}
	}
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		line := scanner.Text()
		item_queries := strings.Split(line, " ")

		iq := make([]int, len(item_queries))
		for i := range iq {
			iq[i], _ = strconv.Atoi(item_queries[i])
		}

		if scanner.Scan() {
			line := scanner.Text()
			numbers := strings.Split(line, " ")
			numb := make([]int, len(numbers))
			for i := range numb {
				numb[i], _ = strconv.Atoi(numbers[i])
			}

			sort.Sort(sort.Reverse(sort.IntSlice(numb)))
			fmt.Println(numb)
			iteration := iq[1]
			m := numb[0]
			var l []int
			l = append(l, m)
			for i := 0; i < len(numb)-1; i++ {
				m = l[i] + numb[i+1]
				l = append(l, m)
			}
			for i := 0; i < iteration; i++ {
				if scanner.Scan() {
					line := scanner.Text()
					queries := strings.Split(line, " ")
					q := make([]int, len(queries))
					for i := range q {
						q[i], _ = strconv.Atoi(queries[i])
					}

					t := (q[0] - q[1]) - 1
					if t >= 0 {
						fmt.Println(l[q[0]-1] - l[t])
					} else {
						fmt.Println(l[q[0]-1])
					}
				}
			}
		}
	}
}

package main

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

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	if scanner.Scan() {
		line := scanner.Text()
		item_queries := strings.Split(line, " ")

		iq := make([]int, len(item_queries))
		for i := range iq {
			iq[i], _ = strconv.Atoi(item_queries[i])
		}

		if scanner.Scan() {
			line := scanner.Text()
			numbers := strings.Split(line, " ")
			numb := make([]int, len(numbers))
			for i := range numb {
				numb[i], _ = strconv.Atoi(numbers[i])
			}

			sort.Sort(sort.Reverse(sort.IntSlice(numb)))
			fmt.Println(numb)
			iteration := iq[1]
			m := numb[0]
			var l []int
			l = append(l, m)
			for i := 0; i < len(numb)-1; i++ {
				m = l[i] + numb[i+1]
				l = append(l, m)
			}
			for i := 0; i < iteration; i++ {
				if scanner.Scan() {
					line := scanner.Text()
					queries := strings.Split(line, " ")
					q := make([]int, len(queries))
					for i := range q {
						q[i], _ = strconv.Atoi(queries[i])
					}

					t := (q[0] - q[1]) - 1
					if t >= 0 {
						fmt.Println("réponse", l[q[0]-1]-l[t])
					} else {
						fmt.Println("réponseé", l[q[0]-1])
					}
				}
			}
		}
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
var tc = 1
var DEBUG = os.Getenv("DEBUG") != ""

func solve() {}

func main() {
	// var T int
	// scan(&T)
	// for ; T > 0; T-- {
	// 	solve()
	// 	tc++
	// }
	var n, q int
	scan(&n, &q)
	a := make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	sort.Slice(a, func(i, j int) bool { return a[i] < a[j] })
	for i := 1; i < n; i++ {
		a[i] += a[i-1]
	}
	for i := 0; i < q; i++ {
		var x, y int
		scan(&x, &y)

		ret := a[n-x+y-1]
		if n-x-1 > 0 {
			ret -= a[n-x-1]
		}
		printf("%d\n", ret)

		tc++
	}

}

func yn(b bool) string      { return map[bool]string{true: "YES", false: "NO"}[b] }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }
func printf(format string, a ...interface{}) {
	if DEBUG {
		format = fmt.Sprintf("Test #%d: %s", tc, format)
	}
	fmt.Printf(format, a...)
}

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

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

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

package main

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

var in = bufio.NewReader(os.Stdin)
var tc = 1
var DEBUG = os.Getenv("DEBUG") != ""

func solve() {}

func main() {
	// var T int
	// scan(&T)
	// for ; T > 0; T-- {
	// 	solve()
	// 	tc++
	// }
	var n, q int
	scan(&n, &q)
	a := make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	sort.Ints(a)
	for i := 1; i < n; i++ {
		a[i] += a[i-1]
	}
	for i := 0; i < q; i++ {
		var x, y int
		scan(&x, &y)

		ret := a[n-x+y-1]
		if n-x-1 > 0 {
			ret -= a[n-x-1]
		}
		printf("%d\n", ret)

		tc++
	}

}

func yn(b bool) string      { return map[bool]string{true: "YES", false: "NO"}[b] }
func scan(a ...interface{}) { fmt.Fscan(in, a...) }
func printf(format string, a ...interface{}) {
	if DEBUG {
		format = fmt.Sprintf("Test #%d: %s", tc, format)
	}
	fmt.Printf(format, a...)
}

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

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

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

// 00
package main

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

func main() {
	var n, q int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n, &q)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &p[i])
	}
	//sort.Slice(p, func(i, j int) bool { return p[i] < p[j] })
	sort.Ints(p)
	for i := 1; i < n; i++ {
		p[i] += p[i-1]
	}
	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)
		ans := p[n-x+y-1]
		if n-x-1 >= 0 {
			ans -= p[n-x-1]
		}
		fmt.Println(ans)
	}
}

// 00
package main

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

func main() {
	var n, q int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n, &q)
	p := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &p[i])
	}
	sort.Slice(p, func(i, j int) bool { return p[i] < p[j] })

	for i := 1; i < n; i++ {
		p[i] += p[i-1]
	}
	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)
		ans := p[n-x+y-1]
		if n-x-1 > 0 {
			ans -= p[n-x-1]
		}
		fmt.Println(ans)
	}
}

// 00
package main

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

func main() {
	var n, q int
	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &n, &q)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &p[i])
	}
	sort.Ints(p)
	for i := 1; i < n; i++ {
		p[i] += p[i-1]
	}
	for i := 0; i < q; i++ {
		var x, y int
		fmt.Fscan(reader, &x, &y)
		ans := p[n-x+y-1]
		if n-x-1 > 0 {
			ans -= p[n-x-1]
		}
		fmt.Println(ans)
	}
}

package main

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

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 n, q, l int
	fmt.Fscan(in, &n, &q)
	arr := make([]int, n)
	for l < n {
		fmt.Fscan(in, &arr[l])
		l++
	}
	l = n - 2
	der := make([]int, n)
	sort.Ints(arr)
	der[n-1] = arr[n-1]
	for l >= 0 {
		der[l] = der[l+1] + arr[l]
		l--
	}
	//fmt.Println(der)
	//fmt.Println(arr)
	var b, c int
	for i := 0; i < q; {
		fmt.Fscan(in, &b, &c)
		if b == c {
			fmt.Fprintln(out, der[n-b])
		} else {
			fmt.Fprintln(out, der[n-b]-der[n-b+c])
		}
		i++
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n, q int
	fmt.Fscan(in, &n, &q)
	p := make([]int, n)
	for i := range p {
		fmt.Fscan(in, &p[i])
	}
	sort.Slice(p, func(i, j int) bool { return p[i] > p[j] })
	s := make([]int, n+1)
	for i := 1; i <= n; i++ {
		s[i] = s[i-1] + p[i-1]
	}
	for t := 0; t < q; t++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		fmt.Fprintln(out, s[x]-s[x-y])
	}
}