Petya once wrote a sad love song and shared it to Vasya. The song is a string consisting of lowercase English letters. Vasya made up $$$q$$$ questions about this song. Each question is about a subsegment of the song starting from the $$$l$$$-th letter to the $$$r$$$-th letter. Vasya considers a substring made up from characters on this segment and repeats each letter in the subsegment $$$k$$$ times, where $$$k$$$ is the index of the corresponding letter in the alphabet. For example, if the question is about the substring "abbcb", then Vasya repeats letter 'a' once, each of the letters 'b' twice, letter 'c" three times, so that the resulting string is "abbbbcccbb", its length is $$$10$$$. Vasya is interested about the length of the resulting string.Help Petya find the length of each string obtained by Vasya.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1\leq n\leq 100\,000$$$, $$$1\leq q \leq 100\,000$$$) — the length of the song and the number of questions.  The second line contains one string $$$s$$$ — the song, consisting of $$$n$$$ lowercase letters of English letters. Vasya's questions are contained in the next $$$q$$$ lines. Each line contains two integers $$$l$$$ and $$$r$$$ ($$$1 \leq l \leq r \leq n$$$) — the bounds of the question.

Print $$$q$$$ lines: for each question print the length of the string obtained by Vasya.

NoteIn the first example Vasya is interested in three questions. In the first question Vasya considers the substring "aba", that transforms to "abba", so the answer is equal to $$$4$$$. In the second question Vasya considers "baca", that transforms to "bbaccca", so the answer is $$$7$$$. In the third question Vasya considers the string "abacaba",that transforms to "abbacccabba" of length $$$11$$$.

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

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


A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, sequence [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] are not.A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer i is a fixed point of permutation a0, a1, ..., an - 1 if and only if ai = i. For example, permutation [0, 2, 1] has 1 fixed point and permutation [0, 1, 2] has 3 fixed points.You are given permutation a. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.

The first line contains a single integer n (1 ≤ n ≤ 105). The second line contains n integers a0, a1, ..., an - 1 — the given permutation.

Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.

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"
    "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"
)

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
}


You are given an array $$$a_1, a_2, \dots, a_n$$$ and an array $$$b_1, b_2, \dots, b_n$$$.For one operation you can sort in non-decreasing order any subarray $$$a[l \dots r]$$$ of the array $$$a$$$.For example, if $$$a = [4, 2, 2, 1, 3, 1]$$$ and you choose subbarray $$$a[2 \dots 5]$$$, then the array turns into $$$[4, 1, 2, 2, 3, 1]$$$. You are asked to determine whether it is possible to obtain the array $$$b$$$ by applying this operation any number of times (possibly zero) to the array $$$a$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 3 \cdot 10^5$$$) — the number of queries. The first line of each query contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$). The second line of each query contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$). The third line of each query contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le n$$$). It is guaranteed that $$$\sum n \le 3 \cdot 10^5$$$ over all queries in a test.

For each query print YES (in any letter case) if it is possible to obtain an array $$$b$$$ and NO (in any letter case) otherwise.

NoteIn first test case the can sort subarray $$$a_1 \dots a_5$$$, then $$$a$$$ will turn into $$$[1, 1, 4, 4, 7, 5, 6]$$$, and then sort subarray $$$a_5 \dots a_6$$$.

package main

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

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

type node struct{ l, r, v int }
type seg []node

func (t seg) maintain(o int) { t[o].v = min(t[o<<1].v, t[o<<1|1].v) }
func (t seg) build(o, l, r int) {
	t[o] = node{l, r, 1e9}
	if l == r {
		return
	}
	m := (l + r) >> 1
	t.build(o<<1, l, m)
	t.build(o<<1|1, m+1, r)
}
func (t seg) update(o, i, v int) {
	if t[o].l == t[o].r {
		t[o].v = v
		return
	}
	if i <= (t[o].l+t[o].r)>>1 {
		t.update(o<<1, i, v)
	} else {
		t.update(o<<1|1, i, v)
	}
	t.maintain(o)
}
func (t seg) query(o, l, r int) int {
	if l <= t[o].l && t[o].r <= r {
		return t[o].v
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if l > m {
		return t.query(o<<1|1, l, r)
	}
	return min(t.query(o<<1, l, r), t.query(o<<1|1, l, r))
}

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

	var T, n, v int
o:
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		t := make(seg, 4*n)
		t.build(1, 1, n)
		pos := make([][]int, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &v)
			if pos[v] == nil {
				t.update(1, v, i)
			}
			pos[v] = append(pos[v], i)
		}
		for ; n > 0; n-- {
			Fscan(in, &v)
			if len(pos[v]) == 0 || t.query(1, 1, v) < pos[v][0] {
				for n--; n > 0; n-- {
					Fscan(in, &v)
				}
				Fprintln(out, "NO")
				continue o
			}
			pos[v] = pos[v][1:]
			p := int(1e9)
			if len(pos[v]) > 0 {
				p = pos[v][0]
			}
			t.update(1, v, p)
		}
		Fprintln(out, "YES")
	}
}

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