package main

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

func solveC(n int) {
	const (
		uninited int = iota
		lose
		draw
		win
	)

	edges := make([][]int, n)
	for i := range edges {
		edges[i] = make([]int, n)
	}

	if n%2 == 0 {
		for i := 0; i+1 < n; i += 2 {
			edges[i][i+1] = draw
			edges[i+1][i] = draw
		}
	}

	var walk func(int)
	walk = func(node int) {
		for nextNode := 0; nextNode < n; nextNode++ {
			if edges[node][nextNode] == uninited {
				edges[node][nextNode] = win
				edges[nextNode][node] = lose
				walk(nextNode)
			}
		}
	}

	walk(0)

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			printf("%d ", edges[i][j]-2)
		}
	}
	printf("\n")
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)

	for t := 0; t < T; t++ {
		n := 0
		scan(&n)
		solveC(n)
	}
}

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

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

func sieve() {
	const maxn = 1e7
	var lp [maxn + 1]int64
	var pr []int64

	for i := int64(2); i <= maxn; i++ {
		if lp[i] == 0 {
			lp[i] = i
			pr = append(pr, i)
		}
		for j := 0; j < len(pr) && pr[j] <= lp[i] && i*pr[j] <= maxn; j++ {
			lp[i*pr[j]] = pr[j]
		}
	}
}

package main

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			if n%4 == 1 {
				for i := 1; i < n*(n-1)/4+1; i++ {
					fmt.Println("1 -1 ")
				}

			} else {
				for i := 1; i < (n+2)*(n-3)/4+2; i++ {
					fmt.Println("1 -1 ")
				}
				fmt.Println(1)
			}
		} else {
			ARRAY := make([]int, 0)
			ARRAB := make([]int, 0)
			ARRAY = append(ARRAY, 1)
			ARRAY = append(ARRAY, 1)
			ARRAY = append(ARRAY, 1)
			ARRAY = append(ARRAY, 1)
			ARRAB = append(ARRAB, -1)
			ARRAB = append(ARRAB, -1)
			ARRAB = append(ARRAB, -1)
			ARRAB = append(ARRAB, -1)

			t := int(n / 2)
			oo := (t - 1) * t / 2
			for i := 0; i < t*t; i++ {
				ARRAY = append(ARRAY, 1)
				ARRAB = append(ARRAB, -1)
			}
			for k := t - 1; k > -1; k-- {
				q := ARRAY[:t-1]
				qq := fmt.Sprint(q)
				fmt.Println(qq[1 : len(qq)-1])
				fmt.Println(0)
				q1 := ARRAB[:k]
				qq1 := fmt.Sprint(q1)
				fmt.Println(qq1[1 : len(qq1)-1])
			}
			q := ARRAY[:oo]
			qq := fmt.Sprint(q)
			fmt.Println(qq[1 : len(qq)-1])

		}

	}

}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)

		for i := 0; i < len(res); i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}
func solve(n int) (res []int) {
	res = make([]int, 0, n*(n-1)/2)
	mat := make([][]int, n)

	if n&1 == 1 {
		for i := 0; i < n; i++ {
			mat[i] = make([]int, n)
			for j := i + 1; j < n; j++ {
				if j-i <= n/2 {
					mat[i][j] = 1
				} else {
					mat[i][j] = -1
				}
			}

		}
	} else {
		for i := 0; i < n; i++ {
			mat[i] = make([]int, n)
			for j := i + 1; j < n; j++ {
				if j-i < n/2 {
					mat[i][j] = 1
				} else if j-i == n/2 {
					mat[i][j] = 0
				} else {
					mat[i][j] = -1
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			res = append(res, mat[i][j])
		}
	}
	return
}

package main

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

var out *bufio.Writer

func solve() {
	var n int
	fmt.Scan(&n)

	for i := 0; i < n-1; i++ {
		for j := 0; j < n-1-i; j++ {
			if n%2 == 0 && n/2-1 == j {
				fmt.Fprint(out, "0 ")
				continue
			}
			if j < n/2 {
				fmt.Fprint(out, "1 ")
			} else {
				fmt.Fprint(out, "-1 ")
			}
		}
	}
	fmt.Fprintln(out)
}

func main() {
	out = bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Scan(&t)

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1487C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type nb struct{ to, i int }

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		g := make([][]nb, n)
		m := 0
		for i := 0; i < n; i++ {
			j := i + 1
			if n&1 == 0 && i&1 == 0 {
				j++
				m++
			}
			for ; j < n; j++ {
				g[i] = append(g[i], nb{j, m})
				g[j] = append(g[j], nb{i, m})
				m++
			}
		}

		ans := make([]int, m)
		vis := make([]bool, m)
		pre := 0
		var f func(int)
		f = func(v int) {
			for len(g[v]) > 0 {
				e := g[v][0]
				g[v] = g[v][1:]
				if w, i := e.to, e.i; !vis[i] {
					vis[i] = true
					f(w)
					v := v
					if w == pre {
						v, w = w, v
					}
					if v < w {
						ans[i] = 1
					} else {
						ans[i] = -1
					}
					pre = w
				}
			}
		}
		f(0)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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

package main

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

type bufferedReader struct {
	buf     [4096]byte
	ptr, sz int
	eof     bool
	ended   bool
	in      *os.File
}

func newReader(in *os.File) bufferedReader {
	var tmp [4096]byte
	return bufferedReader{tmp, 0, 0, false, false, in}
}

func (r *bufferedReader) isEof() bool {
	return r.eof
}

func (r *bufferedReader) load() {
	if r.ended {
		r.eof = true
		return
	}
	sz, err := r.in.Read(r.buf[:])
	r.sz = sz
	if sz < 4096 {
		r.ended = true
	}
	if err != nil {
		log.Fatal(err)
	}
	r.ptr = 0
}

func (r *bufferedReader) getChar() byte {
	if r.ptr == r.sz && !r.eof {
		r.load()
	}
	if r.ptr == r.sz || r.eof {
		r.eof = true
		return 0
	}
	r.ptr += 1
	return r.buf[r.ptr-1]
}

func (r *bufferedReader) skipNonIntChars() {
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if (c >= 48 && c <= 57) || (c == 45) {
			r.ptr -= 1
			break
		}
	}
}

func (r *bufferedReader) skipWhitespace() {
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c != ' ' && c != '\n' && c != '\t' && c != '\r' {
			r.ptr -= 1
			break
		}
	}
}

func (r *bufferedReader) readInt() int {
	r.skipNonIntChars()
	var ans int = 0
	var neg bool = false
	fst := r.getChar()
	if fst == 45 {
		neg = true
	} else {
		ans = int(fst) - 48
	}
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c >= 48 && c <= 57 {
			ans = ans*10 + int(c-48)
		} else {
			r.ptr -= 1
			break
		}
	}
	if neg {
		ans = -ans
	}
	return ans
}

func (r *bufferedReader) readString() string {
	r.skipWhitespace()
	sz := 0
	capacity := 2
	s := make([]byte, 2)
	for {
		c := r.getChar()
		if r.eof {
			break
		}
		if c == ' ' || c == '\n' || c == '\t' || c == '\r' {
			r.ptr--
			break
		}
		if sz == capacity {
			capacity <<= 1
			s1 := make([]byte, capacity)
			for i := 0; i < sz; i++ {
				s1[i] = s[i]
			}
			s = s1
		}
		s[sz] = c
		sz++
	}
	return string(s[:sz])
}

func main() {
	var in bufferedReader
	hostname, err := os.Hostname()
	if err != nil {
		log.Fatal(err)
	}
	if strings.HasSuffix(hostname, "lenovo") {
		file, _ := os.Open("input.txt")
		in = newReader(file)
	} else {
		in = newReader(os.Stdin)
	}
	T := in.readInt()
	siegheil := make([]byte, 0)
	for t := 0; t < T; t++ {
		n := in.readInt()
		b := make([][]int, n)
		for i := 0; i < n; i++ {
			b[i] = make([]int, n)
			for j := 0; j < n; j++ {
				b[i][j] = -1
			}
		}
		if n%2 == 1 {
			for i := 0; i < n; i++ {
				j := (i + 1) % n
				for k := 0; k < n/2; k++ {
					b[i][j] = 1
					j = j + 1
					if j == n {
						j = 0
					}
				}
			}
		} else {
			for i := 0; i < n; i++ {
				mid := (i + n/2) % n
				b[i][mid] = 0
				j := (i + 1) % n
				for j != mid {
					b[i][j] = 1
					j = j + 1
					if j == n {
						j = 0
					}
				}
			}
		}
		for i := 0; i < n; i++ {
			for j := i + 1; j < n; j++ {
				s := make([]byte, 0)
				if b[i][j] < 0 {
					siegheil = append(siegheil, '-')
					b[i][j] = -b[i][j]
				}
				for b[i][j] > 0 {
					s = append(s, byte(48+b[i][j]%10))
					b[i][j] /= 10
				}
				if len(s) == 0 {
					s = append(s, '0')
				}
				for k := len(s) - 1; k >= 0; k-- {
					siegheil = append(siegheil, s[k])
				}
				siegheil = append(siegheil, ' ')
			}
		}
		siegheil = append(siegheil, '\n')
	}
	fmt.Printf("%s", siegheil)
}

package main

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

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

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

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

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

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

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

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

func sol(n int64) []int64 {
	ret := []int64{}
	if n&1 == 1 {
		for i := n - 1; i >= 1; i-- {
			curr := int64(1)
			for j := i; j >= 1; j-- {
				ret = append(ret, curr)
				curr *= -1
			}
		}
		return ret
	}
	for i := n - 1; i >= 1; i-- {
		curr := int64(1)
		if i&1 == 0 {
			curr *= -1
		}
		for j := i; j >= 1; j-- {
			if i&1 == 1 && j == i {
				ret = append(ret, 0)
				continue
			}
			ret = append(ret, curr)
			curr *= -1
		}
	}
	return ret
}

package main

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			for i := 1; i < n*(n-1)/2+1; i++ {
				if i%2 == 1 {
					fmt.Println(1)
				} else {
					fmt.Println(-1)
				}
			}
		} else {
			t := int(n / 2)
			for k := t - 1; k > -1; k-- {
				for j := 1; j < t; j++ {
					fmt.Println(1)
				}
				fmt.Println(0)
				for m := 1; m < k+1; m++ {
					fmt.Println(-1)
				}
			}
			for l := 1; l < 2*t-2; l++ {
				fmt.Println(1)
			}
		}

	}

}

package main

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n int
		fmt.Fscan(input, &n)
		if n%2 == 1 {
			for i := 1; i < n*(n-1)/2+1; i++ {
				if i%2 == 1 {
					fmt.Println(1)
				} else {
					fmt.Println(-1)
				}
			}
		} else {
			t := int(n / 2)
			for k := t - 1; k > -1; k-- {
				for j := 1; j < t; j++ {
					fmt.Println(1)
				}
				fmt.Println(0)
				for m := 1; m < k+1; m++ {
					fmt.Println(-1)
				}
			}
			for l := 1; l < 2*t-1; l++ {
				fmt.Println(1)
			}
		}

	}

}

package main

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

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

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--
		n := readNum(reader)
		res := solve(n)

		for i := 0; i < len(res); i++ {
			buf.WriteString(fmt.Sprintf("%d ", res[i]))
		}
		buf.WriteByte('\n')
	}

	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}
func solve(n int) (res []int) {
	res = make([]int, 0, n*(n-1)/2)
	mat := make([][]int, n)

	if n&1 == 1 {
		for i := 0; i < n; i++ {
			mat[i] = make([]int, n)
			for j := 1; j < n; j++ {
				k := (i + j) % n
				if j <= n/2 {
					mat[i][k] = 1
				} else {
					mat[i][k] = -1
				}
			}

		}
	} else {
		for i := 0; i < n; i++ {
			mat[i] = make([]int, n)
			for j := 0; j < (n-2)/2; j++ {
				k := (i + j + 1) % n
				mat[i][k] = 1
			}
			for j := (n - 2) / 2; j < n-2; j++ {
				k := (i + j + 1) % n
				mat[i][k] = -1
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			res = append(res, mat[i][j])
		}
	}
	return
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1487C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type nb struct{ to, i int }

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		g := make([][]nb, n)
		m := 0
		for i := 0; i < n; i++ {
			j := i + 1
			if n&1 == 0 && i&1 == 0 {
				j++
				m++
			}
			for ; j < n; j++ {
				g[i] = append(g[i], nb{j, m})
				g[j] = append(g[j], nb{i, m})
				m++
			}
		}

		ans := make([]int, m)
		vis := make([]bool, m)
		pre := 0
		var f func(int)
		f = func(v int) {
			for len(g[v]) > 0 {
				e := g[v][0]
				g[v] = g[v][1:]
				if w, i := e.to, e.i; !vis[i] {
					vis[i] = true
					f(w)
					if w == pre {
						v, w = w, v
					}
					if v < w {
						ans[i] = 1
					} else {
						ans[i] = -1
					}
					pre = w
				}
			}
		}
		f(0)
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}
}

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


package main

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

type Scanner struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) *Scanner {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	return &Scanner{scanner}
}

func (s *Scanner) Word() string {
	s.Scan()
	return s.Text()
}

func (s *Scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *Scanner) Int64() int64 {
	s.Scan()
	n, _ := strconv.ParseInt(s.Text(), 10, 64)
	return n
}

func (s *Scanner) Words(count int) []string {
	words := make([]string, count)
	for i := range words {
		words[i] = s.Word()
	}
	return words
}

func (s *Scanner) Ints(count int) []int {
	ints := make([]int, count)
	for i := range ints {
		ints[i] = s.Int()
	}
	return ints
}

func (s *Scanner) Int64s(count int) []int64 {
	int64s := make([]int64, count)
	for i := range int64s {
		int64s[i] = s.Int64()
	}
	return int64s
}

type Fenwick struct {
	v []int64
}

func NewFenwick(n int) *Fenwick {
	return &Fenwick{v: make([]int64, n+4)}
}

func (f *Fenwick) Add(pos int) {
	pos++
	for pos < len(f.v) {
		f.v[pos]++
		pos += lsb(pos)
	}
}

func (f *Fenwick) Get(pos int) int64 {
	pos++

	res := int64(0)
	for pos > 0 {
		res += f.v[pos]
		pos -= lsb(pos)
	}
	return res
}

func lsb(num int) int {
	return num & -num
}

type Placer struct {
	row, col  int
	left      int
	leftInRow int
	cols      int
}

func NewPlacer(row, col int, left int, cols int) *Placer {
	leftInRow := cols - col
	if leftInRow > left {
		leftInRow = left
	}

	return &Placer{
		row:       row,
		col:       col,
		left:      left,
		leftInRow: leftInRow,
		cols:      cols,
	}
}

func (p *Placer) Row() int {
	return p.row
}

func (p *Placer) Col() int {
	return p.col + p.leftInRow - 1
}

func (p *Placer) Shift() {
	p.leftInRow -= 1
	p.left -= 1

	if p.leftInRow <= 0 {
		p.row += 1
		p.col = 0
		p.leftInRow = p.left
		if p.leftInRow > p.cols {
			p.leftInRow = p.cols
		}
	}
}

func solve(a []int, rows, cols int) int64 {
	sorted := make([]int, len(a))
	copy(sorted, a)
	sort.Slice(sorted, func(i, j int) bool { return sorted[i] < sorted[j] })

	count := make(map[int]int)
	for _, x := range a {
		count[x]++
	}

	placers := make(map[int]*Placer)
	row, col := 0, 0
	for i := 0; i < len(a); i++ {
		if i == 0 || sorted[i] != sorted[i-1] {
			placers[sorted[i]] = NewPlacer(row, col, count[sorted[i]], cols)
		}

		col += 1
		if col >= cols {
			row++
			col = 0
		}
	}

	occupied := make([]*Fenwick, rows)
	for i := range occupied {
		occupied[i] = NewFenwick(cols + 1)
	}

	res := int64(0)
	for _, x := range a {
		row := placers[x].Row()
		col := placers[x].Col()
		placers[x].Shift()

		res += occupied[row].Get(col)
		occupied[row].Add(col)
	}
	return res
}

func main() {
	stdin := NewWordScanner(os.Stdin)
	tests := stdin.Int()

	for i := 0; i < tests; i++ {
		n, m := stdin.Int(), stdin.Int()
		a := stdin.Ints(n * m)
		fmt.Println(solve(a, n, m))
	}
}

package main

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

type IndexTree struct {
	n            int
	arr          []int
	f            func(i, j int) int
	defaultValue int
}

type Aggregation interface {
	DefaultValue() int
	Aggregate(left, right int) int
}

type MinIndex struct{}

func (m MinIndex) DefaultValue() int { return math.MaxInt32 }
func (m MinIndex) Aggregate(left, right int) int {
	if left < right {
		return left
	} else {
		return right
	}
}

type MaxIndex struct{}

func (m MaxIndex) DefaultValue() int { return math.MinInt32 }
func (m MaxIndex) Aggregate(left, right int) int {
	if left > right {
		return left
	} else {
		return right
	}
}

type SumIndex struct{}

func (m SumIndex) DefaultValue() int             { return 0 }
func (m SumIndex) Aggregate(left, right int) int { return left + right }

func NewIndexTree(n int, a Aggregation) *IndexTree {
	arr := make([]int, n*4)
	for i := 0; i < len(arr); i++ {
		arr[i] = a.DefaultValue()
	}

	return &IndexTree{n, arr, a.Aggregate, a.DefaultValue()}
}

func (i *IndexTree) Add(k, v int) {
	i.traverse(1, 0, i.n, func(node, b, e int) bool {
		if b <= k && e >= k {
			i.arr[node] = i.f(i.arr[node], v)
			return true
		}
		return false
	})
}

func (i *IndexTree) Get(qb, qe int) int {
	res := i.defaultValue
	i.traverse(1, 0, i.n, func(node, b, e int) bool {
		if b >= qb && e <= qe {
			res = i.f(res, i.arr[node])
			return false
		}
		return !(qe < b || qb > e)
	})
	return res
}

func (i *IndexTree) traverse(node int, b, e int, do func(node, b, e int) bool) {
	if !do(node, b, e) {
		return
	}
	m := (b + e) / 2
	if b != e {
		i.traverse(node*2, b, m, do)
		i.traverse(node*2+1, m+1, e, do)
	}
}

type pair struct {
	a, i int
}

func reverse(arr []pair) {
	n := len(arr)
	for i := 0; i < n/2; i++ {
		arr[i], arr[n-i-1] = arr[n-i-1], arr[i]
	}
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 1024*1024)

	var T int

	fmt.Fscanf(r, "%d\n", &T)

	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscanf(r, "%d %d\n", &n, &m)
		arr := make([]pair, n*m)
		for i := 0; i < len(arr); i++ {
			arr[i].i = i
			fmt.Fscanf(r, "%d", &arr[i].a)
		}
		fmt.Fscanf(r, "\n")

		sort.Slice(arr, func(i, j int) bool {
			if arr[i].a != arr[j].a {
				return arr[i].a < arr[j].a
			}
			return arr[i].i < arr[j].i
		})

		b := 0
		for i := 0; i < len(arr); i++ {
			if i == 0 || arr[i].a != arr[i-1].a {
				reverse(arr[b:i])
				b = i
			}
			if i%m == 0 {
				reverse(arr[b:i])
				b = i
			}
		}
		reverse(arr[b : n*m])

		idx := NewIndexTree(n*m+1, SumIndex{})

		res := 0
		//fmt.Println(arr)
		for i, v := range arr {
			if i%m == 0 {
				idx = NewIndexTree(n*m+1, SumIndex{})
			}
			res += idx.Get(0, v.i)
			idx.Add(v.i, 1)
		}

		fmt.Println(res)
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	if x*y == 0 {
		return MAX(x, y)
	} else {
		var l, q int64
		l = MAX(x, y)
		q = MIN(x, y)
		var m int64
		for l*q > 0 {
			a := l % q
			b := l - a
			cc := int64(b / q)
			remain := l - cc*q
			l = MAX(remain, q)
			q = MIN(remain, q)
			if l*q == 0 {
				m = l + q
				break
			}

		}
		return m
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func MODULE(x, y int) int {
	if x > y {
		return x - y
	} else {
		return y - x
	}
}

func BITAND(x, y int64) int64 {
	var ans int64
	begin := x
	sec := y
	var count int64 = 1
	for 1 == 1 {
		if (begin%2)*(sec%2) == 1 {
			ans = ans + count
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}

		} else {
			count = count * 2
			begin = int64(begin / 2)
			sec = int64(sec / 2)
			if begin*sec == 0 {
				break
			}
		}
	}
	return ans
}

func Sum(n, m int) int {
	var ans int

	if n == 1 {
		return 0
	} else {
		for i := 2; i < n; i++ {
			ans = (ans + Sum(i, m)) % m
		}
		for j := 2; j < n+1; j++ {
			ans = (ans + Sum(n/j, m)) % m
		}
		return ans
	}
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {
		var n, m int
		fmt.Fscan(input, &n, &m)
		q := n * m
		type test struct {
			Id    int
			Value int
			QQ    int
		}

		var B []test

		ARRAY := make([]int, q)
		for i := 0; i < q; i++ {
			fmt.Fscan(input, &ARRAY[i])
			var s test
			s.Id = i
			s.Value = ARRAY[i]
			B = append(B, s)

		}
		sort.Slice(B, func(i, j int) bool {
			return (B[i].Value < B[j].Value) || (B[i].Value == B[j].Value && B[i].Id < B[j].Id)
		})

		for i := 0; i < q; i++ {
			B[i].QQ = i / m
		}
		var Ans int

		for l := 0; l < n; l++ {
			for s := l*m + 1; s < (l+1)*m; s++ {
				for p := l * m; p < s; p++ {
					if B[s].Value > B[p].Value && B[s].Id > B[p].Id {
						Ans++
					}
				}
			}
		}

		fmt.Println(Ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)
type Node struct{
	av int
	t int
}
type Nodes []Node
func (a Nodes)Len()int{
	return len(a)
}
func (a Nodes)Less(i, j int)bool{
	if a[i].av<a[j].av{
		return true
	}
	if a[i].av==a[j].av{
		return a[i].t<a[j].t
	}
	return false
}
func (a Nodes)Swap(i, j int){
	a[i],a[j]=a[j],a[i]
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	var t int
	fmt.Fscan(in,&t)
	for u:=1;u<=t;u++{
		var n, m int
		fmt.Fscan(in,&n,&m)
		a := make([]int,n*m)
		l := Nodes{}
		for i:=0;i<n*m;i++{
			fmt.Fscan(in,&a[i])
			l = append(l,Node{a[i],i})
		}
		sort.Sort(l)
		//fmt.Println(l)
		ans := 0
		for i:=0;i<n;i++{
			for j:=0;j<m;j++{
				for k:=0;k<j;k++{
					if l[i*m+j].t>l[i*m+k].t&&l[i*m+j].av!=l[i*m+k].av{
						ans++
					}
				}
			}
		}
		fmt.Fprintln(out,ans)
	}
}


package main

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

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

	input1, _, _ := reader.ReadLine()
	inputList1 := strings.Split(string(input1), " ")
	input2, _, _ := reader.ReadLine()
	inputList2 := strings.Split(string(input2), " ")
	input3, _, _ := reader.ReadLine()
	inputList3 := strings.Split(string(input3), " ")

	busStopCount, _ := strconv.Atoi(string(inputList1[0]))
	vB, _ := strconv.ParseFloat(string(inputList1[1]), 64)
	vS, _ := strconv.ParseFloat(string(inputList1[2]), 64)

	busStops := make([]float64, 0)

	for i := 0; i < len(inputList2); i++ {
		value, _ := strconv.ParseFloat(string(inputList2[i]), 64)

		busStops = append(busStops, value)
	}

	uX, _ := strconv.ParseFloat(string(inputList3[0]), 64)
	uY, _ := strconv.ParseFloat(string(inputList3[1]), 64)

	var busStopValue1,busStopValue2 float64
	busStopNumber := -1
	busStopValue1 = -1
	busStopValue2 = -1

	for i := 0; i < busStopCount; i++ {
		if busStops[i] == 0 {
			continue
		}

		time1 := float64( busStops[i] / vB)
		time2 := math.Sqrt(float64(math.Pow(float64(uX - busStops[i]), 2) + float64(uY * uY))) / vS

		if busStopValue1 == -1 {
			busStopValue1 = time1
			busStopValue2 = time2
			busStopNumber = i
		} else if time1 + time2 < busStopValue1 + busStopValue2 {
			busStopValue1 = time1
			busStopValue2 = time2
			busStopNumber = i
		} else if time1 + time2 == busStopValue1 + busStopValue2 && time2 < busStopValue2 {
			busStopValue1 = time1
			busStopValue2 = time2
			busStopNumber = i
		}
	}

	fmt.Println(busStopNumber + 1)
}

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"math"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	var vb, vs, xu, yu float64

	fmt.Fscanf(reader, "%d %f %f\n", &n, &vb, &vs)
	stop := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%f", &stop[i])
		if i != n-1 {
			fmt.Fscanf(reader, " ")
		} else {
			fmt.Fscanf(reader, "\n")
		}
	}
	fmt.Fscanf(reader, "%f %f", &xu, &yu)
	min := 99999999999.0
	var minStop int
	for i := 1; i < n; i++ {
		t := stop[i]/vb + math.Sqrt((xu-stop[i])*(xu-stop[i])+yu*yu)/vs
		if t < min {
			minStop = i
			min = t
		} else if t == min {
			if math.Abs(xu-stop[minStop]) > math.Abs(xu-stop[i]) {
				minStop = i
				min = t
			}
		}
	}
	fmt.Printf("%d", minStop+1)
}

package main

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

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

	n, vb, vs := readThreeNums(reader)
	X := readNNums(reader, n)
	room := readNNums(reader, 2)

	fmt.Println(solve(n, vb, vs, X, room))
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, vb int, vs int, X []int, exam []int) int {
	time := make([]float64, n)
	v1 := float64(vs)
	v2 := float64(vb)
	var best = math.MaxFloat64
	for i := 0; i < n; i++ {
		t1 := float64(X[i]) / v2
		t2 := distance(exam[0], exam[1], X[i], 0) / v1
		time[i] = t1 + t2
		if i > 0 && time[i] < best {
			best = time[i]
		}
	}
	var pos int

	var dist = math.MaxFloat64
	for i := 0; i < n; i++ {
		if math.Abs(time[i]-best) < 1e-9 {
			tmp := distance(exam[0], exam[1], X[i], 0)
			if tmp < dist {
				dist = tmp
				pos = i
			}
		}
	}

	return pos + 1
}

func distance(a, b, c, d int) float64 {
	dx := float64(c - a)
	dy := float64(d - b)
	return math.Sqrt(dx*dx + dy*dy)
}

package main

import "fmt"
import "math"

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f\n", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		if i+1 == n {
			fmt.Scanf("%f\n", &stops[i])
		} else {
			fmt.Scanf("%f", &stops[i])
		}
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0

	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}

package main

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

func solve() {
	nstops := readInt()
	busvelocity := readInt()
	studentvelocity := readInt()

	stops := make([]int, nstops, nstops)
	for i, _ := range stops {
		stops[i] = readInt()
	}

	// university coordinates
	ux := readInt()
	uy := readInt()

	bestIndex := int(1)
	bestTime, bestDist := time_for(busvelocity, studentvelocity, stops[1], ux, uy)
	for i := 2; i < len(stops); i++ {
		t, d := time_for(busvelocity, studentvelocity, stops[i], ux, uy)
		if t < bestTime || (t == bestTime && d < bestDist) {
			bestTime = t
			bestIndex = i
			bestDist = d
		}
	}
	fmt.Println(bestIndex + 1)
}

func closeEnough(x, y float64) bool {
	return math.Abs(x-y) < 1e6
}

func time_for(ivb, ivs, ix, iux, iuy int) (t, d float64) {
	vb := float64(ivb)
	vs := float64(ivs)
	x := float64(ix)
	ux := float64(iux)
	uy := float64(iuy)

	// time on bus
	t = x / vb

	// distance to school
	d = math.Sqrt((ux-x)*(ux-x) + uy*uy)

	// time running
	t += d / vs
	return

}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

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

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"math"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int
	var vb, vs, xu, yu float64

	fmt.Fscanf(reader, "%d %f %f\n", &n, &vb, &vs)
	stop := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%f", &stop[i])
		if i != n-1 {
			fmt.Fscanf(reader, " ")
		} else {
			fmt.Fscanf(reader, "\n")
		}
	}
	fmt.Fscanf(reader, "%f %f", &xu, &yu)
	min := 99999999999.0
	var minStop int
	for i := 1; i < n; i++ {
		t := stop[i]/vb + math.Sqrt((xu-stop[i])*(xu-stop[i])+yu*yu)/vs
		if t < min {
			minStop = i + 1
			min = t
		}
	}
	fmt.Printf("%d", minStop)
}

package main

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

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

	n, vb, vs := readThreeNums(reader)
	X := readNNums(reader, n)
	room := readNNums(reader, 2)

	fmt.Println(solve(n, vb, vs, X, room))
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, vb int, vs int, X []int, exam []int) int {
	time := make([]float64, n)
	v1 := float64(vs)
	v2 := float64(vb)
	var best = math.MaxFloat64
	var pos int
	for i := 0; i < n; i++ {
		t1 := float64(X[0]) / v1
		t2 := distance(exam[0], exam[1], X[i], 0) / v2
		time[i] = t1 + t2
		if i > 0 && time[i] < best {
			best = time[i]
			pos = i
		}
	}
	return pos + 1
}

func distance(a, b, c, d int) float64 {
	dx := float64(c - a)
	dy := float64(d - b)
	return math.Sqrt(dx*dx + dy*dy)
}

package main

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

func solve() {
	nstops := readInt()
	busvelocity := readInt()
	studentvelocity := readInt()

	stops := make([]int, nstops, nstops)
	for i, _ := range stops {
		stops[i] = readInt()
	}

	// university coordinates
	ux := readInt()
	uy := readInt()

	bestIndex := int(1)
	bestTime := time_for(busvelocity, studentvelocity, stops[1], ux, uy)
	for i := 2; i < len(stops); i++ {
		t := time_for(busvelocity, studentvelocity, stops[i], ux, uy)
		if bestTime > t {
			bestTime = t
			bestIndex = i
		}
	}
	fmt.Println(bestIndex + 1)
}

func time_for(ivb, ivs, ix, iux, iuy int) float64 {
	vb := float64(ivb)
	vs := float64(ivs)
	x := float64(ix)
	ux := float64(iux)
	uy := float64(iuy)

	// time on bus
	t := x / vb
	// time running
	t += math.Sqrt((ux-x)*(ux-x)+uy*uy) / vs
	return t

}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

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

package main

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

func solve() {
	nstops := readInt()
	busvelocity := readInt()
	studentvelocity := readInt()

	stops := make([]int, nstops, nstops)
	for i, _ := range stops {
		stops[i] = readInt()
	}

	// university coordinates
	ux := readInt()
	uy := readInt()

	bestIndex := int(1)
	bestTime, bestDist := time_for(busvelocity, studentvelocity, stops[1], ux, uy)
	for i := 2; i < len(stops); i++ {
		t, d := time_for(busvelocity, studentvelocity, stops[i], ux, uy)
		if t < bestTime || (t == bestTime && d < bestDist) {
			bestTime = t
			bestIndex = i
			bestDist = d
		}
	}
	fmt.Println(bestIndex + 1)
}

func closeEnough(x, y float64) bool {
	return math.Abs(x-y) < 1e6
}

func time_for(ivb, ivs, ix, iux, iuy int) (t, d float64) {
	vb := float64(ivb)
	vs := float64(ivs)
	x := float64(ix)
	ux := float64(iux)
	uy := float64(iuy)

	// time on bus
	t = x / vb

	// distance to school
	d = math.Sqrt((ux-x)*(ux-x) + uy*uy)
	// time running
	t += math.Sqrt(d / vs)
	return

}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

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

package main

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

func solve() {
	nstops := readInt()
	busvelocity := readInt()
	studentvelocity := readInt()

	stops := make([]int, nstops, nstops)
	for i, _ := range stops {
		stops[i] = readInt()
	}

	// university coordinates
	ux := readInt()
	uy := readInt()

	bestIndex := int(1)
	bestTime, bestDist := time_for(busvelocity, studentvelocity, stops[1], ux, uy)
	for i := 2; i < len(stops); i++ {
		t, d := time_for(busvelocity, studentvelocity, stops[i], ux, uy)
		if t < bestTime || (closeEnough(t, bestTime) && d < bestDist) {
			bestTime = t
			bestIndex = i
			bestDist = d
		}
	}
	fmt.Println(bestIndex + 1)
}

func closeEnough(x, y float64) bool {
	return math.Abs(x-y) < 1e6
}

func time_for(ivb, ivs, ix, iux, iuy int) (t, d float64) {
	vb := float64(ivb)
	vs := float64(ivs)
	x := float64(ix)
	ux := float64(iux)
	uy := float64(iuy)

	// time on bus
	t = x / vb

	// distance to school
	d = math.Sqrt((ux-x)*(ux-x) + uy*uy)
	// time running
	t += math.Sqrt(d / vs)
	return

}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

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

package main

import "fmt"
import "math"

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f\n", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%f", &stops[i])
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0
	fmt.Printf("%d %f %f\n%f %f\n", n, vb, vs, xu, yu)
	for i := 0; i < n; i++ {
		fmt.Printf("%f ", stops[i])
	}
	fmt.Println()

	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}

package main

import "fmt"
import "math"

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%f", &stops[i])
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0
	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}

package main

import "fmt"
import "math"

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f\n", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		if i+1 == n {
			fmt.Scanf("%f\n", &stops[i])
		} else {
			fmt.Scanf("%f", &stops[i])
		}
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0
	fmt.Printf("%d %f %f\n%f %f\n", n, vb, vs, xu, yu)
	for i := 0; i < n; i++ {
		fmt.Printf("%f ", stops[i])
	}
	fmt.Println()

	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}

package main

import "fmt"
import "math"

func square(a float64) float64 {
	return a * a
}

func equal(a, b float64) bool {
	return math.Abs(a-b) < 1e-6
}

func main() {
	var n int
	var vb, vs float64
	fmt.Scanf("%d %f %f\n", &n, &vb, &vs)
	var stops = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%f", &stops[i])
	}
	var xu, yu float64
	fmt.Scanf("%f %f", &xu, &yu)
	var best = 1.0e12
	var udist = 0.0
	var res = 0
	for i := 1; i < n; i++ {
		var to = stops[i] / vb
		var du = math.Sqrt(square(xu-stops[i]) + square(yu-0))
		var tu = du / vs
		if to+tu < best {
			best = to + tu
			udist = du
			res = i
		} else if equal(best, to+tu) && du < udist {
			best = to + tu
			udist = du
			res = i
		}
	}
	fmt.Println(res + 1)
}


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

func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n,t int
	fmt.Fscan(in,&n,&t)
	var word string
	fmt.Fscan(in,&word)
	var list [100001]int
	for j:=0;j<n;j++{
		if j==0{
			list[j]= int(word[j]-96)
		} else {
			list[j]+= int(word[j]-96)+list[j-1]
		}
	}
	for i:=0;i<t;i++{
		var l,r int
		fmt.Fscan(in,&l,&r)
		if l == 1 {
			fmt.Fprintln(out,list[r-1])
		} else {
			fmt.Fprintln(out,list[r-1]-list[l-1]+(list[l-1]-list[l-2]))
		}
	}
}

package main

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

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

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

const CNT = 1000

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	var cin [CNT]chan pairInt
	var cout [CNT]chan int
	for i := 0; i < CNT; i++ {
		cin[i] = make(chan pairInt, (q+CNT-1)/CNT)
		cout[i] = make(chan int, (q+CNT-1)/CNT)
		go worker(cin[i], cout[i])
	}
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin[i%CNT] <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout[i%CNT])
	}
	writer.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

const CNT = 100

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	var cin [CNT]chan pairInt
	var cout [CNT]chan int
	for i := 0; i < CNT; i++ {
		cin[i] = make(chan pairInt, (q+CNT-1)/CNT)
		cout[i] = make(chan int, (q+CNT-1)/CNT)
		go worker(cin[i], cout[i])
	}
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin[i%CNT] <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout[i%CNT])
	}
	writer.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

const CNT = 5

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	var cin [CNT]chan pairInt
	var cout [CNT]chan int
	for i := 0; i < CNT; i++ {
		cin[i] = make(chan pairInt, (q+CNT-1)/CNT)
		cout[i] = make(chan int, (q+CNT-1)/CNT)
		go worker(cin[i], cout[i])
	}
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin[i%CNT] <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout[i%CNT])
	}
	writer.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

const CNT = 4

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	var cin [CNT]chan pairInt
	var cout [CNT]chan int
	for i := 0; i < CNT; i++ {
		cin[i] = make(chan pairInt, (q+CNT-1)/CNT)
		cout[i] = make(chan int, (q+CNT-1)/CNT)
		go worker(cin[i], cout[i])
	}
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin[i%CNT] <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout[i%CNT])
	}
	writer.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

const CNT = 3

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	var cin [CNT]chan pairInt
	var cout [CNT]chan int
	for i := 0; i < CNT; i++ {
		cin[i] = make(chan pairInt, (q+CNT-1)/CNT)
		cout[i] = make(chan int, (q+CNT-1)/CNT)
		go worker(cin[i], cout[i])
	}
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin[i%CNT] <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout[i%CNT])
	}
	writer.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

const CNT = 2

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	var cin [CNT]chan pairInt
	var cout [CNT]chan int
	for i := 0; i < CNT; i++ {
		cin[i] = make(chan pairInt, (q+CNT-1)/CNT)
		cout[i] = make(chan int, (q+CNT-1)/CNT)
		go worker(cin[i], cout[i])
	}
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin[i%CNT] <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout[i%CNT])
	}
	writer.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

const CNT = 1

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	var cin [CNT]chan pairInt
	var cout [CNT]chan int

	for i := 0; i < CNT; i++ {
		cin[i] = make(chan pairInt, (q+CNT-1)/CNT)
		cout[i] = make(chan int, (q+CNT-1)/CNT)
		go worker(cin[i], cout[i])
	}

	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin[i%CNT] <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout[i%CNT])
	}
	writer.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	cin1, cout1 := make(chan pairInt, q), make(chan int, q)
	cin2, cout2 := make(chan pairInt, q), make(chan int, q)
	go worker(cin1, cout1)
	go worker(cin2, cout2)
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		if i%2 == 0 {
			cin1 <- pairInt{l: l - 1, r: r}
		} else {
			cin2 <- pairInt{l: l - 1, r: r}
		}
	}
	for i := 0; i < q; i++ {
		if i%2 == 0 {
			printf("%d\n", <-cout1)
		} else {
			printf("%d\n", <-cout2)
		}
	}
	writer.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	cin, cout := make(chan pairInt, q), make(chan int, q)
	go worker(cin, cout)
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout)
	}
	writer.Flush()
}

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

var fsum []int

func f(l, r int) int {
	return fsum[r] - fsum[l]
}

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		printf("%d\n", fsum[r]-fsum[l-1])
	}
	writer.Flush()
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var n, q int
	var s string
	scanf("%d %d\n", &n, &q)
	scanf("%s\n", &s)
	prefix_count := make([][]uint32, n+1)

	for i := range prefix_count {
		prefix_count[i] = make([]uint32, 26)
	}
	for i := 0; i < n; i++ {
		char := s[i]
		for j := range prefix_count[i] {
			prefix_count[i+1][j] = prefix_count[i][j]
		}
		diff := char - 'a'
		prefix_count[i+1][diff]++
	}

	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		ans := uint32(0)
		// fmt.Println(l, r)
		for j := 0; j < 26; j++ {
			ans += (prefix_count[r][j] - prefix_count[l-1][j]) * uint32(j+1)
		}
		printf("%d\n", ans)
	}
	writer.Flush()
}

// link: https://codeforces.com/problemset/problem/1539/B
package main

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

func logic(reader io.Reader, writer io.Writer) {
	charval := map[byte]uint64{}

	var val uint64 = 1
	for c := 'a'; c <= 'z'; c++ {
		charval[byte(c)] = val
		val++
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var songlength, cases int
	fmt.Fscan(in, &songlength)
	fmt.Fscan(in, &cases)

	song := make([]byte, songlength)
	fmt.Fscan(in, &song)

	storage := make([]uint64, songlength+1)
	for i, s := range song {
		storage[i+1] = storage[i] + charval[s]
	}

	for i := 0; i < cases; i++ {
		var start, end int
		fmt.Fscan(in, &start)
		fmt.Fscan(in, &end)

		output := storage[end] - storage[start-1]

		fmt.Fprintln(out, output)
	}
}

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

package main

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

func main() {
	var n, t int
	var s string
	var l, r int
	var a [100000]int
	in := bufio.NewReader(os.Stdin)

	fmt.Fscan(in, &n, &t)
	fmt.Fscan(in, &s)

	for i := 0; i < len(s); i++ {
		a[i] = int(s[i]) - int('a') + 1
		if i > 0 {
			a[i] += a[i-1]
		}
	}

	for i := 0; i < t; i++ {
		fmt.Fscan(in, &l, &r)
		if l > 1 {
			fmt.Println(a[r-1] - a[l-2])
		} else {
			fmt.Println(a[r-1])
		}
	}
}

package main

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

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		var n,q int
		var s string
		//var s1 string

		fmt.Fscan(in , &n,&q,&s)

		ranges := make([][2]int,q)

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

			fmt.Fscan(in, &ranges[i][0], &ranges[i][1])
		}

	str := "abcdefghijklmnopqrstuvwxyz"
	var count int64
	mp := make(map[byte]int)

	for i := 0; i < len(str); i++ {
		mp[str[i]] = i + 1
	}

	prefs := make([]int64, n + 1)
	prefs[0] = int64(mp[s[0]])

	for i := 1; i < n; i++ {
		cur := s[i]

		prefs[i] = prefs[i - 1] + int64(mp[cur])
	}

	for j := 0 ; j < len(ranges) ; j++ {
		start , end := ranges[j][0],ranges[j][1]

		//s1 = s[start-1:end]

		if start == 1 {
			count = prefs[end - 1]
		} else {
			count = prefs[end - 1] - prefs[start - 2]
		}
		fmt.Fprintln(out,count)
	}

	}

	solve()
		}

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

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

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

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

func PrimeFactorization(n int) (pfs map[int]int) {
	pfs = make(map[int]int)

	// Get the number of 2s that divide n
	for n%2 == 0 {
		if _, ok := pfs[2]; ok {
			pfs[2] += 1
		} else {
			pfs[2] = 1
		}
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			if _, ok := pfs[i]; ok {
				pfs[i] += 1
			} else {
				pfs[i] = 1
			}
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs[n] = 1
	}

	return
}

func NumberOfDivisors(n int) int {
	pfs := PrimeFactorization(n)

	num := 1
	for _, exponents := range pfs {
		num *= (exponents + 1)
	}

	return num
}

func KthPrime(x int) (y int) {
	if x == 1 {
		y = 2
	}
	if x == 2 {
		y = 3
	}
	if x > 2 {
		var sum int = 2
		begin := 5
		for sum < x+1 {
			if IsItPrime(begin) == true {
				sum++
			}
			if sum == x {
				y = begin
				break
			} else {
				if begin%6 == 1 {
					begin = begin + 4
				} else {
					begin = begin + 2
				}
			}
		}
	}
	return
}

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	var n, q int
	fmt.Fscan(input, &n)
	fmt.Fscan(input, &q)
	STRING := make([]byte, 0)
	ARRAY := make([]int64, 0)
	ARRAY = append(ARRAY, 0)
	fmt.Fscan(input, &STRING)
	var MM int64
	for i := 0; i < n; i++ {
		MM = MM + int64(STRING[i]) - 96
		ARRAY = append(ARRAY, MM)
	}

	for i := 0; i < q; i++ {
		var l, r int
		fmt.Fscan(input, &l)
		fmt.Fscan(input, &r)
		var q int64
		q = ARRAY[r] - ARRAY[l-1]
		fmt.Println(q)

	}

}

package main

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

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

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

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

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

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

/**
Run solve the problem CF1539B
Date: 23/01/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1539/B
Problem: CF1539B
**/
func (in *CF1539B) Run() {
	n, q := in.NextInt(), in.NextInt()
	arr := make([]int, n+1)
	str := in.NextString()
	for i := 1; i <= n; i++ {
		arr[i] = arr[i-1] + int(str[i-1]-'a')
	}
	var sol strings.Builder
	for ; q > 0; q-- {
		l, r := in.NextInt(), in.NextInt()
		sol.WriteString(fmt.Sprintf("%d\n", arr[r]-arr[l-1]+(r-l)+1))
	}
	fmt.Print(sol.String())
}

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

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

package main

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

var (
	reader     = bufio.NewReader(os.Stdin)
	n, q, l, r int
	s          string
)

func main() {
	fmt.Fscan(reader, &n, &q, &s)
	a := make([]int, n+1)
	for i := 0; i < n; i++ {
		if i == 0 {
			a[i+1] = 1 + int(s[i]-'a')
		} else {
			a[i+1] = a[i] + 1 + int(s[i]-'a')
		}
	}
	for ; q > 0; q-- {
		fmt.Fscan(reader, &l, &r)
		fmt.Println(a[r] - a[l-1])
	}
}

package main

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

func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var n, q int
	var s string
	Fscan(in, &n, &q)
	Fscan(in, &s)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		a[i] = int(s[i-1]-'a') + 1
	}
	for i := 1; i <= n; i++ {
		a[i] += a[i-1]
	}
	for i := 0; i < q; i++ {
		var l, r int
		Fscan(in, &l, &r)
		ans := a[r] - a[l-1]
		Fprintln(out, ans)
	}
}

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

package main
import(
    "os"
    "fmt"
    "io"
    "bufio"
)
var n,q int
var ss string
var pre[100005] int
func main(){
    var cin io.Reader = bufio.NewReader(os.Stdin)
    fmt.Fscan(cin,&n,&q,&ss)
    for i := 0; i<n;i++{
        pre[i]=int(ss[i])-int('a')+1
        if i>0 {
            pre[i]+=pre[i-1]
        }
    }
    for i := 0;i<q;i++{
        var l,r int
        fmt.Fscan(cin,&l,&r)
        if l>1{
            fmt.Println(pre[r-1]-pre[l-2])
        } else {
            fmt.Println(pre[r-1])
        }
    }
}

package main

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

const (
	mx = 2e5 + 10
)

var n, q int
var ss string
var pref [mx]int

func main() {

	var cin io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(cin, &n, &q, &ss)
	for i := 0; i < len(ss); i++ {
		pref[i] = int(ss[i]) - int('a') + 1
		if i > 0 {
			pref[i] += pref[i-1]
		}
	}
	for i := 0; i < q; i++ {
		var l, r int
		fmt.Fscan(cin, &l, &r)
		kurang := 0
		if l > 1 {
			kurang = pref[l-2]
		}
		fmt.Println(pref[r-1] - kurang)
	}
}

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}
func (s *Scanner) Next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}
func (s *Scanner) NextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}
func (s *Scanner) NextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt()
	}
	return res
}
func (s *Scanner) NextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.NextInt64()
	}
	return res
}
func Min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}
func Max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func InitInts1D(n int, val int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = val
	}
	return res
}
func InitInts2D(n, m int, val int) [][]int {
	res := make([][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts1D(m, val)
	}
	return res
}
func InitInts3D(n, m, k int, val int) [][][]int {
	res := make([][][]int, n)
	for i := 0; i < n; i++ {
		res[i] = InitInts2D(m, k, val)
	}
	return res
}

type StepState struct {
	step, dist int
}
type PriorityQueue []*StepState

func (pq PriorityQueue) Len() int { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool {
	if pq[i].step != pq[j].step {
		return pq[i].step < pq[j].step
	}
	return pq[i].dist < pq[j].dist
}
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}
func (pq *PriorityQueue) Push(x interface{}) {
	item := x.(*StepState)
	*pq = append(*pq, item)
}
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	*pq = old[0 : n-1]
	return item
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	N := sc.NextInt()
	Q := sc.NextInt()
	song := sc.Next()

	cnt := InitInts2D(N+1, 26, 0)
	for i, c := range song {
		copy(cnt[i+1], cnt[i])
		cnt[i+1][c-'a']++
	}

	for q := 0; q < Q; q++ {
		l := sc.NextInt()
		r := sc.NextInt()

		ans := 0
		for i := 0; i < 26; i++ {
			ans += (i + 1) * (cnt[r][i] - cnt[l-1][i])
		}
		fmt.Fprintln(wr, ans)
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	var n, q int
	var s string
	fmt.Fscanf(in, "%d %d\n", &n, &q)
	fmt.Fscanf(in, "%s\n", &s)
	var arr = make([]int, n+1)
	for i := 0; i < n; i++ {
		arr[i+1] = arr[i] + (int)(s[i]-'a') + 1
	}
	for i := 1; i <= q; i++ {
		var l, r int
		fmt.Fscanf(in, "%d %d\n", &l, &r)
		l--
		r--
		fmt.Fprintf(out, "%d\n", arr[r+1]-arr[l])
		out.Flush()
	}
}

package main

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

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

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

	var s string
	_, _ = fmt.Fscan(in, &s)

	var count = make(map[rune][]int)
	for i := 'a'; i <= 'z'; i++ {
		count[i] = make([]int, n+1)
	}

	for i := n - 1; i >= 0; i-- {
		for j := 'a'; j <= 'z'; j++ {
			if j == int32(s[i]) {
				count[j][i] = 1 + count[j][i+1]
			} else {
				count[j][i] = count[j][i+1]
			}
		}
	}

	for tc := 0; tc < q; tc++ {
		var l, r int
		_, _ = fmt.Fscan(in, &l, &r)

		l--
		r--

		ans := 0
		for i := 'a'; i <= 'z'; i++ {
			ans += (int(i) - int('a') + 1) * (count[i][l] - count[i][r+1])
		}

		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"os"
	"fmt"

)

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

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

	var s string
	fmt.Fscan(r, &s)

	qu := make([][2]int, q)

	for j := 0; j < q; j ++ {
		fmt.Fscan(r, &qu[j][0], &qu[j][1])
	}

	solve(s, n, qu)
}

func solve(s string, n int, qu [][2]int) {

	w := bufio.NewWriter(os.Stdout)

	str := "abcdefghijklmnopqrstuvwxyz"

	mp := make(map[byte]int)

	for i := 0; i < len(str); i++ {
		mp[str[i]] = i + 1
	}

	//cdfasdasd

	prefs := make([]int64, n + 1)
	prefs[0] = int64(mp[s[0]])

	for i := 1; i < n; i++ {
		cur := s[i]

		prefs[i] = prefs[i - 1] + int64(mp[cur])
	}

	for j := 0; j < len(qu); j++ {
		l, r := qu[j][0], qu[j][1]

		var sum int64

		if l == 1 {
			sum = prefs[r - 1]
		} else {
			sum = prefs[r - 1] - prefs[l - 2]
		}

		fmt.Fprintln(w, sum)
	}

	w.Flush()
}

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

var fsum []int

type pairInt struct {
	l int
	r int
}

func worker(in chan pairInt, out chan int) {
	for val := range in {
		out <- fsum[val.r] - fsum[val.l]
	}
}

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	cin, cout := make(chan pairInt, q), make(chan int, q)
	go worker(cin, cout)
	go worker(cin, cout)
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		cin <- pairInt{l: l - 1, r: r}
	}
	for i := 0; i < q; i++ {
		printf("%d\n", <-cout)
	}
	writer.Flush()
}

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

var fsum []int

func f(l, r int) int {
	return fsum[r] - fsum[l]
}

func main() {
	var n, q int
	scanf("%d %d\n", &n, &q)
	fsum = make([]int, n+1)
	s := make([]byte, n)
	scanf("%s\n", &s)
	for i := 0; i < n; i++ {
		fsum[i+1] += fsum[i] + int(s[i]-'a') + 1
	}
	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		printf("%d\n", fsum[r]-fsum[l-1])
	}
}

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

func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n,t int
	fmt.Fscan(in,&n,&t)
	var word string
	fmt.Fscan(in,&word)
	for i:=0;i<t;i++{
		var l,r int
		fmt.Fscan(in,&l,&r)
		var count byte
		for j:=l-1;j<r;j++{
			count+=word[j]-96
		}
		fmt.Fprintln(out,count)
	}
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var n, q int
	var s string
	scanf("%d %d\n", &n, &q)
	scanf("%s\n", &s)
	prefix_count := make([][]uint32, n+1)

	for i := range prefix_count {
		prefix_count[i] = make([]uint32, 26)
	}
	for i := 0; i < n; i++ {
		char := s[i]
		for j := range prefix_count[i] {
			prefix_count[i+1][j] = prefix_count[i][j]
		}
		diff := char - 'a'
		prefix_count[i+1][diff]++
	}

	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		ans := uint32(0)
		// fmt.Println(l, r)
		for j := 0; j < 26; j++ {
			ans += (prefix_count[r][j] - prefix_count[l-1][j]) * uint32(j+1)
		}
		println(ans)
	}
	writer.Flush()
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var n, q int
	var s string
	scanf("%d %d\n", &n, &q)
	scanf("%s\n", &s)
	prefix_count := make([][]uint32, n+1)

	for i := range prefix_count {
		prefix_count[i] = make([]uint32, 26)
	}
	for i := 0; i < n; i++ {
		char := s[i]
		for j := range prefix_count[i] {
			prefix_count[i+1][j] = prefix_count[i][j]
		}
		diff := char - 'a'
		prefix_count[i+1][diff]++
	}

	for i := 0; i < q; i++ {
		var l, r int
		scanf("%d %d\n", &l, &r)
		ans := uint32(0)
		// fmt.Println(l, r)
		for j := 0; j < 26; j++ {
			ans += (prefix_count[r][j] - prefix_count[l-1][j]) * uint32(j+1)
		}
		println(ans)
	}
}


package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)       // membuat variabel scanner dengan tipe data *Scanner dari package bufio
    scanner.Split(bufio.ScanWords)              // men-set agar scanner membaca per-kata dipisahkan spasi
    var n int                                   // membuat variabel n dengan tipe data int
    var a [100005]int                           // membuat variabel a dengan tipe data array of int dengan ukuran 100005
    fmt.Scan(&n)                                // menerima input n
    for i := 0; i < n; i++ {                    // looping sebanyak n kali
        scanner.Scan()                          // melakukan scan atau pembacaan input (per-kata)
        a[i], _ = strconv.Atoi(scanner.Text())  // ubah hasil input yang berupa string menjadi int dan disimpan di a[i]
    }
    ans, f := 0, false                          // membuat variabel ans tipe int dengan nilai awal 0 dan f tipe bool dengan nilai awal false
    for i := 0; i < n; i++ {                    // looping sebanyak n kali
        if i == a[i] {                          // jika nilai i sama dengan nilai a[i]
            ans++                               // tambahkan nilai ans dengan 1
        } else if (i == a[a[i]]) {              // jika nilai i sama dengan nilai dari a[a[i]] (a ke-a[i])
            f = true                            // maka ubah nilai f menjadi true
        }
    }
    if ans < n {                                // jika nilai ans lebih kecil dari n
        if f { ans += 2 } else { ans++ }        // jika nilai f = true, maka ans ditambah 2. Jika nilai f = false, maka nilai ans ditambah 1
    }
    fmt.Println(ans)                            // mencetak output nilai dari ans
}

package main

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

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

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

    var n int = NextInt()
    pos, a := make([]int, n), make([]int, n)

    for i := 0; i < n; i++ {
        a[i] = NextInt()
        pos[a[i]] = i
    }

    var c int = 0
    for i := 0; i < n; i++ {
        if a[i] == i {
            c++
        }
    }

    if c == n {
        fmt.Fprintln(out, c)
        return
    }

    for i := 0; i < n; i++ {
        if i != a[i] && i == a[a[i]] && a[i] == pos[i]{
            c += 2
            fmt.Fprintln(out, c)
            return
        }
    }

    fmt.Fprintln(out, c + 1)
}

func Next() string{
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func NextInt() int{
    ret, _ := strconv.Atoi(Next())
    return ret
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    var a [100005]int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    ans, f := 0, false
    for i := 0; i < n; i++ {
        if i == a[i] {
            ans++
        } else if (i == a[a[i]]) {
            f = true
        }
    }
    if ans < n {
        if f { ans += 2 } else { ans++ }
    }
    fmt.Println(ans)
}

package main

import (
    "fmt"
)

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

func main() {
    var n, add, ans int
    var a [110000]int
    fmt.Scan(&n)

    ans = 0
    add = 0

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

    for i := 0; i < n;i++ {
        if a[i] != i {
            add = get_max(add, 1)
            if a[a[i]] == i {
                add = get_max(add, 2)
            }
        }
    }

    fmt.Printf("%d\n", ans + add)
}

package main

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

func Readln(r *bufio.Reader) (string) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln)
}

func ReadIntArray(line string) []int {

	numStrings := strings.Split(strings.TrimSpace(string(line)), " ")

	numbers := make([]int, 0)

	for _, v := range numStrings {
		var converted int

		fmt.Sscanf(v, "%d", &converted)
		numbers = append(numbers, converted)
	}

	return numbers
}

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

	Readln(reader)
	line := Readln(reader)
	arr := ReadIntArray(string(line))

	fmt.Println(FixedPoints(arr))
}

func FixedPoints(numbers []int) int {

	pointsCount := 0
	dict := map[int]int{}
	for i := 0; i < len(numbers); i++ {
		if numbers[i] == i {
			pointsCount++
		} else {
			dict[i] = numbers[i]
		}
	}

	for key := range dict {
		if val, ok := dict[dict[key]]; ok && val == key {
			pointsCount += 2
			return pointsCount
		}
	}

	if pointsCount < len(numbers) {
		pointsCount += 1
	}

	return pointsCount
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

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

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

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    a := make([]int, n)
    b := make([]int, n)
    ans := 0
    for i := 0; i < n; i++ {
        a[i] = nextInt()
        if i == a[i] {
            ans++
        } else {
            b[a[i]] = i
        }
    }

    if ans >= n - 2 {
        fmt.Fprintln(out, n);
        return
    } else {
        for i := 0; i < n; i++ {
            if i != a[i] && b[i] == a[i] {
                fmt.Fprintln(out, ans + 2)
                return
            }
        }
    }

    fmt.Fprintln(out, ans + 1)

}

package main

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

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

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

    var n int = NextInt()
    pos, a := make([]int, n), make([]int, n)

    for i := 0; i < n; i++ {
        a[i] = NextInt()
        pos[a[i]] = i
    }

    var c int = 0
    for i := 0; i < n; i++ {
        if a[i] == i {
            c++
        }
    }

    for i := 0; i < n; i++ {
        if i != a[i] && i == a[a[i]] && a[i] == pos[i]{
            c += 2
            fmt.Fprintln(out, c)
            return
        }
    }

    fmt.Fprintln(out, c + 1)
}

func Next() string{
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

func NextInt() int{
    ret, _ := strconv.Atoi(Next())
    return ret
}